diff options
Diffstat (limited to 'fs/utils.ts')
| -rw-r--r-- | fs/utils.ts | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/fs/utils.ts b/fs/utils.ts new file mode 100644 index 000000000..dd7ee5fa4 --- /dev/null +++ b/fs/utils.ts @@ -0,0 +1,23 @@ +import * as path from "./path/mod.ts"; + +/** + * Test whether or not `dest` is a sub-directory of `src` + * @param src src file path + * @param dest dest file path + * @param sep path separator + */ +export function isSubdir( + src: string, + dest: string, + sep: string = path.sep +): boolean { + if (src === dest) { + return false; + } + const srcArray = src.split(sep); + const destArray = dest.split(sep); + + return srcArray.reduce((acc, current, i) => { + return acc && destArray[i] === current; + }, true); +} |
