diff options
author | Nick Van Doorn <vandoorn.nick@gmail.com> | 2019-03-04 02:04:19 -0800 |
---|---|---|
committer | Nick Van Doorn <vandoorn.nick@gmail.com> | 2019-03-04 02:04:19 -0800 |
commit | c52b773fd9033878cce3deb36e289ce73034f99e (patch) | |
tree | 8477adc05608ee7fbddff5d8ca6914f4dbdf7ba4 | |
parent | 844cab6dfbee846219e3964545742469e9525940 (diff) |
Use path library
-rw-r--r-- | core/src/database.ts | 23 |
1 files changed, 1 insertions, 22 deletions
diff --git a/core/src/database.ts b/core/src/database.ts index 6bd7c46..b5711e1 100644 --- a/core/src/database.ts +++ b/core/src/database.ts @@ -7,28 +7,7 @@ import { NaiveError, NaiveErrorCode as e } from '../../lib/error.model' import { ChangeHandlers } from './change-handlers.model' import { last, getKey } from '../../lib/util' - -/** - * Split path using "/" as a delimiter - */ -const splitPath = (path: string): string[] => path.split('/').filter(k => k) - -/** - * Identify if a path is a root node - */ -const isRootNode = (path: string): boolean => path === '/' || path === '' - -/** - * Check if path1 matches path2, - * if not, check if its a subpath - * - * https://stackoverflow.com/questions/37521893/determine-if-a-path-is-subdirectory-of-another-in-node-js - */ -const isChildOrMatch = (child: string, parent: string) => { - if (child === parent || parent === '/') return true - const parentTokens = parent.split('/').filter((i: string) => i.length) - return parentTokens.every((t, i) => child.split('/')[i] === t) -} +import { isRootNode, splitPath, isChildOrMatch } from '../../lib/path' const write = promisify(writeFile) const read = promisify(readFile) |