From 1701d5aa860eb3599610dc7edad1f8ee96da1dec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Sat, 27 Apr 2019 11:44:37 +0200 Subject: [PATCH] [REM] utils: remove findInTree and htmlTrim They were not used and are not in the scope of this project. --- src/utils.ts | 40 ---------------------------------------- tests/utils.test.ts | 29 ----------------------------- 2 files changed, 69 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 0c0e2f11..d8cf5570 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -13,20 +13,6 @@ export function escape(str: string | number | undefined): string { .replace(/`/g, "`"); } -/** - * Remove trailing and leading spaces - */ -export function htmlTrim(s: string): string { - let result = s.replace(/(^\s+|\s+$)/g, ""); - if (s[0] === " ") { - result = " " + result; - } - if (result !== " " && s[s.length - 1] === " ") { - result = result + " "; - } - return result; -} - export type HashFn = (args: any[]) => string; export function memoize R>( @@ -79,32 +65,6 @@ export function debounce( }; } -interface Tree { - children: T[]; -} - -/** - * Find a node in a tree. - * - * This will traverse the tree (depth first) and return the first child that - * matches the predicate, if any - */ -export function findInTree>( - tree: T, - predicate: (t: T) => boolean -): T | null { - if (predicate(tree)) { - return tree; - } - for (let child of tree.children) { - let match = findInTree(child, predicate); - if (match) { - return match; - } - } - return null; -} - export function patch(C: any, patchName: string, patch: any) { const proto = C.prototype; if (!proto.__patches) { diff --git a/tests/utils.test.ts b/tests/utils.test.ts index 4afa573d..294e094b 100644 --- a/tests/utils.test.ts +++ b/tests/utils.test.ts @@ -1,9 +1,7 @@ import { escape, - htmlTrim, memoize, debounce, - findInTree, patch, unpatch } from "../src/utils"; @@ -20,20 +18,6 @@ describe("escape", () => { }); }); -describe("htmlTrim", () => { - test("basic use", () => { - expect(htmlTrim("abc")).toBe("abc"); - expect(htmlTrim(" abc")).toBe(" abc"); - expect(htmlTrim("abc ")).toBe("abc "); - expect(htmlTrim(" abc ")).toBe(" abc "); - expect(htmlTrim("abc\n ")).toBe("abc "); - expect(htmlTrim("\n ")).toBe(" "); - expect(htmlTrim(" \n ")).toBe(" "); - expect(htmlTrim(" ")).toBe(" "); - expect(htmlTrim("")).toBe(""); - }); -}); - describe("memoize", () => { test("return correct value", () => { const f = memoize((a, b) => a + b); @@ -71,19 +55,6 @@ describe("debounce", () => { }); }); -describe("findInTree", () => { - test("can find stuff in tree", () => { - let tree = { - id: 1, - children: [{ id: 2, children: [] }, { id: 3, key: "hello", children: [] }] - }; - const match1 = findInTree(tree, t => t.id === 3); - expect((match1).key).toBe("hello"); - const match2 = findInTree(tree, t => t.id === 4); - expect(match2).toBe(null); - }); -}); - describe("patch/unpatch", () => { test("can monkey patch a class", () => { class Test {