diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9c24f81 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +* text eol=lf + +*.png binary +*.jpg binary +*.gif binary \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7e6882b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "files.eol": "\n" +} diff --git a/src/api/queue.ts b/src/api/queue.ts index a495f51..694137f 100644 --- a/src/api/queue.ts +++ b/src/api/queue.ts @@ -1,20 +1,20 @@ -import { WalkerState } from "../types"; - -type OnQueueEmptyCallback = (error: Error | null, output: WalkerState) => void; -/** - * This is a custom stateless queue to track concurrent async fs calls. - * It increments a counter whenever a call is queued and decrements it - * as soon as it completes. When the counter hits 0, it calls onQueueEmpty. - */ -export class Queue { - private count: number = 0; - constructor(private readonly onQueueEmpty: OnQueueEmptyCallback) {} - - enqueue() { - this.count++; - } - - dequeue(error: Error | null, output: WalkerState) { - if (--this.count <= 0 || error) this.onQueueEmpty(error, output); - } -} +import { WalkerState } from "../types"; + +type OnQueueEmptyCallback = (error: Error | null, output: WalkerState) => void; +/** + * This is a custom stateless queue to track concurrent async fs calls. + * It increments a counter whenever a call is queued and decrements it + * as soon as it completes. When the counter hits 0, it calls onQueueEmpty. + */ +export class Queue { + private count: number = 0; + constructor(private readonly onQueueEmpty: OnQueueEmptyCallback) {} + + enqueue() { + this.count++; + } + + dequeue(error: Error | null, output: WalkerState) { + if (--this.count <= 0 || error) this.onQueueEmpty(error, output); + } +} diff --git a/src/utils.ts b/src/utils.ts index 460dde6..5d19814 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,43 +1,43 @@ -import { sep, normalize, resolve } from "path"; -import { PathSeparator } from "./types"; - -export function cleanPath(path: string) { - let normalized = normalize(path); - - // we have to remove the last path separator - // to account for / root path - if (normalized.length > 1 && normalized[normalized.length - 1] === sep) - normalized = normalized.substring(0, normalized.length - 1); - - return normalized; -} - -const SLASHES_REGEX = /[\\/]/g; -export function convertSlashes(path: string, separator: PathSeparator) { - return path.replace(SLASHES_REGEX, separator); -} - -export function normalizePath( - path: string, - options: { - resolvePaths?: boolean; - normalizePath?: boolean; - pathSeparator: PathSeparator; - } -) { - const { resolvePaths, normalizePath, pathSeparator } = options; - const pathNeedsCleaning = - (process.platform === "win32" && path.includes("/")) || - path.startsWith("."); - - if (resolvePaths) path = resolve(path); - if (normalizePath || pathNeedsCleaning) path = cleanPath(path); - - if (path === ".") return ""; - - const needsSeperator = path[path.length - 1] !== pathSeparator; - return convertSlashes( - needsSeperator ? path + pathSeparator : path, - pathSeparator - ); -} +import { sep, normalize, resolve } from "path"; +import { PathSeparator } from "./types"; + +export function cleanPath(path: string) { + let normalized = normalize(path); + + // we have to remove the last path separator + // to account for / root path + if (normalized.length > 1 && normalized[normalized.length - 1] === sep) + normalized = normalized.substring(0, normalized.length - 1); + + return normalized; +} + +const SLASHES_REGEX = /[\\/]/g; +export function convertSlashes(path: string, separator: PathSeparator) { + return path.replace(SLASHES_REGEX, separator); +} + +export function normalizePath( + path: string, + options: { + resolvePaths?: boolean; + normalizePath?: boolean; + pathSeparator: PathSeparator; + } +) { + const { resolvePaths, normalizePath, pathSeparator } = options; + const pathNeedsCleaning = + (process.platform === "win32" && path.includes("/")) || + path.startsWith("."); + + if (resolvePaths) path = resolve(path); + if (normalizePath || pathNeedsCleaning) path = cleanPath(path); + + if (path === ".") return ""; + + const needsSeperator = path[path.length - 1] !== pathSeparator; + return convertSlashes( + needsSeperator ? path + pathSeparator : path, + pathSeparator + ); +}