@bemoje/path 2.0.1 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/index.cjs +2 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.cts +4 -2
- package/lib/index.d.ts +4 -2
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ Cross-platform path utilities extending upath with validation, manipulation, and
|
|
|
14
14
|
- **hasExtname**: Checks if a file path has any of the specified file extensions.
|
|
15
15
|
- **hasParentDirname**: Whether fspath is a subpath of a parent directory with the given name.
|
|
16
16
|
- **isDotFile**: Determines if a given filepath is a dotfile.
|
|
17
|
-
- **isExtValid**: Check if a file extension is valid. Invalid: - empty string - single dot: "." - illegal characters: <>"
|
|
17
|
+
- **isExtValid**: Check if a file extension is valid. Invalid: - empty string - single dot: "." - illegal characters: <>"|?*:
|
|
18
18
|
- **isRelative**: Whether a path is a relative string, ie. not absolute.
|
|
19
19
|
- **isUnc**: Determines if a given filepath is a UNC path.
|
|
20
20
|
- **isValidWin32**.aspx
|
package/lib/index.cjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/cwd.ts","../../src/lib/dirnameDeep.ts","../../src/lib/hasBasename.ts","../../../fn/src/setNameAndLength.ts","../../../fn/src/bindArg.ts","../../src/lib/hasExtname.ts","../../src/lib/hasParentDirname.ts","../../src/lib/isDotFile.ts","../../src/lib/isExtValid.ts","../../src/lib/isRelative.ts","../../src/lib/isUnc.ts","../../src/lib/isValidWin32.ts","../../src/lib/prefixFilename.ts","../../src/lib/root.ts","../../src/lib/suffixFilename.ts","../../src/lib/toCwdRelative.ts","../../src/lib/toWin32.ts"],"names":["cwd","p","upath","joinSafe","process","dirnameDeep","depth","parent","dirname","hasBasename","tsFilepath","basenames","flat","includes","basename","setNameAndLength","source","target","lengthDelta","Object","defineProperties","name","configurable","value","length","bindArg","fn","boundArgIndex","boundArgValue","args","slice","hasExtname","extnames","RegExp","join","test","js","json","yaml","markdown","ts","hasParentDirname","fspath","isDotFile","filepath","isExtValid","ext","isRelative","path","isAbsolute","isUnc","isValidWin32","options","maxLength","extendedMaxLength","noDriveLetter","substring","prefixFilename","filePath","prefix","extname","fileNameWithoutExt","root","parse","suffixFilename","suffix","split","toCwdRelative","relative","toWin32","replaceAll"],"mappings":";;;;;;;;;;;;AAUO,SAASA,OAAOC,CAAAA,EAAW;AAChC,EAAA,OAAOC,wBAAMC,QAAAA,CAASC,OAAAA,CAAQJ,GAAAA,EAAG,EAAA,GAAOC,CAAAA,CAAAA;AAC1C;AAFgBD,MAAAA,CAAAA,GAAAA,EAAAA,KAAAA,CAAAA;ACFT,SAASK,WAAAA,CAAYJ,GAAWK,KAAAA,EAAc;AACnD,EAAA,MAAMC,MAAAA,GAASL,uBAAAA,CAAMM,OAAAA,CAAQP,CAAAA,CAAAA;AAC7B,EAAA,OAAOK,SAASA,KAAAA,GAAQ,CAAA,GAAID,YAAYE,MAAAA,EAAQD,KAAAA,GAAQ,CAAA,CAAA,GAAKC,MAAAA;AAC/D;AAHgBF,MAAAA,CAAAA,WAAAA,EAAAA,aAAAA,CAAAA;ACFT,SAASI,WAAAA,CAAYC,YAAoBC,SAAAA,EAA4B;AAC1E,EAAA,OAAO;AAACA,IAAAA;AAAWC,GAAAA,CAAAA,IAAAA,CAAK,CAAA,CAAA,CAAGC,QAAAA,CAASX,uBAAAA,CAAMY,QAAAA,CAASJ,UAAAA,CAAAA,CAAAA;AACrD;AAFgBD,MAAAA,CAAAA,WAAAA,EAAAA,aAAAA,CAAAA;;;ACDT,SAASM,gBAAAA,CAGdC,MAAAA,EAAWC,MAAAA,EAAWC,WAAAA,GAAc,CAAA,EAAC;AACrC,EAAA,OAAOC,MAAAA,CAAOC,iBAAiBH,MAAAA,EAAQ;IACrCI,IAAAA,EAAM;MAAEC,YAAAA,E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AAA,CAAAA;AAC/E;AAJgBW,MAAAA,CAAAA,cAAAA,EAAAA,gBAAAA,CAAAA;ACLT,SAASK,KAAK7D,CAAAA,EAAS;AAC5B,EAAA,OAAOC,uBAAAA,CAAM6D,KAAAA,CAAM9D,CAAAA,CAAAA,CAAG6D,IAAAA;AACxB;AAFgBA,MAAAA,CAAAA,IAAAA,EAAAA,MAAAA,CAAAA;ACKT,SAASE,cAAAA,CAAeN,UAAkBO,MAAAA,EAAc;AAC7D,EAAA,MAAMC,QAAQhE,uBAAAA,CAAMY,QAAAA,CAAS4C,QAAAA,CAAAA,CAAUQ,MAAM,GAAA,CAAA;AAC7CA,EAAAA,KAAAA,CAAM,CAAA,CAAA,IAAMD,MAAAA;AACZ,EAAA,OAAO/D,uBAAAA,CAAMC,SAASD,uBAAAA,CAAMM,OAAAA,CAAQkD,QAAAA,CAAAA,EAAWQ,KAAAA,CAAMhC,IAAAA,CAAK,GAAA,CAAA,CAAA;AAC5D;AAJgB8B,MAAAA,CAAAA,cAAAA,EAAAA,gBAAAA,CAAAA;ACHT,SAASG,cAAclE,CAAAA,EAAS;AACrC,EAAA,OAAOC,uBAAAA,CAAMkE,QAAAA,CAAShE,OAAAA,CAAQJ,GAAAA,IAAOC,CAAAA,CAAAA;AACvC;AAFgBkE,MAAAA,CAAAA,aAAAA,EAAAA,eAAAA,CAAAA;;;ACJT,SAASE,QAAQpE,CAAAA,EAAS;AAC/B,EAAA,OAAOA,CAAAA,CAAEqE,UAAAA,CAAW,GAAA,EAAK,IAAA,CAAA;AAC3B;AAFgBD,MAAAA,CAAAA,OAAAA,EAAAA,SAAAA,CAAAA","file":"index.cjs","sourcesContent":["import upath from 'upath'\n\n/**\n * Join paths starting from process.cwd()\n *\n * @example ```ts\n * // equivalent to:\n * path.join(process.cwd(), ...p)\n * ```\n */\nexport function cwd(...p: string[]) {\n return upath.joinSafe(process.cwd(), ...p)\n}\n","import upath from 'upath'\n\n/**\n * Returns the absolute path of the parent directory of the given path.\n * @param p the path\n * @param depth how many times to get the parent directory\n * @example dirnameDeep('a/b/c/d', 2) => 'a/b'\n */\nexport function dirnameDeep(p: string, depth?: number): string {\n const parent = upath.dirname(p)\n return depth && depth > 1 ? dirnameDeep(parent, depth - 1) : parent\n}\n","import type { Arrayable } from 'type-fest'\nimport upath from 'upath'\n\n/**\n * Checks if a file path has any of the specified basenames.\n */\nexport function hasBasename(tsFilepath: string, basenames: Arrayable<string>): boolean {\n return [basenames].flat(2).includes(upath.basename(tsFilepath))\n}\n","import type { Any } from '@mono/types'\n\n/**\n * Preserves the name and length of a function or class constructor\n */\nexport function setNameAndLength<\n S extends ((...args: Any[]) => Any) | (new (...args: Any[]) => Any),\n F extends ((...args: Any[]) => Any) | (new (...args: Any[]) => Any),\n>(source: S, target: F, lengthDelta = 0): F {\n return Object.defineProperties(target, {\n name: { configurable: true, value: source.name }, //\n length: { configurable: true, value: source.length + lengthDelta },\n })\n}\n","import type { ParametersWithout } from '@mono/types'\nimport { setNameAndLength } from './setNameAndLength'\n\n/**\n * Binds a specified argument to the provided function, returning a new function that requires\n * only the remaining arguments at call time.\n */\nexport function bindArg<\n Ret extends (...args: ParametersWithout<T, Index>) => ReturnType<T>,\n Index extends number = number,\n Value = unknown,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends (...args: any[]) => any = (...args: any[]) => any,\n>(fn: T, boundArgIndex: Index, boundArgValue: Value) {\n return setNameAndLength(\n fn,\n (...args: ParametersWithout<T, Index>) =>\n fn(...args.slice(0, boundArgIndex), boundArgValue, ...args.slice(boundArgIndex)),\n -1\n ) as Ret\n}\n","import type { Arrayable } from 'type-fest'\nimport { bindArg } from '@mono/fn'\n\n/**\n * Checks if a file path has any of the specified file extensions.\n */\nexport function hasExtname(tsFilepath: string, extnames: Arrayable<string>): boolean {\n return new RegExp(`[.](${[extnames].flat(2).join('|')})$`).test(tsFilepath)\n}\n\nhasExtname.js = bindArg(hasExtname, 1, ['js', 'mjs', 'jsx', 'cjs'])\nhasExtname.json = bindArg(hasExtname, 1, ['json', 'jsonc'])\nhasExtname.yaml = bindArg(hasExtname, 1, ['yaml', 'yml'])\nhasExtname.markdown = bindArg(hasExtname, 1, ['md', 'markdown'])\nhasExtname.ts = bindArg(hasExtname, 1, ['ts', 'mts', 'tsx'])\n","/**\n * Whether fspath is a subpath of a parent directory with the given name.\n */\nexport function hasParentDirname(fspath: string, name: string) {\n return new RegExp(`(^|[/\\\\\\\\])${name}[/\\\\\\\\]`).test(fspath)\n}\n","/**\n * Determines if a given filepath is a dotfile.\n * @param filepath - The filepath to evaluate.\n * @returns A boolean indicating whether the filepath is a dotfile.\n */\nexport function isDotFile(filepath: string): boolean {\n return /(?:^|[/\\\\])(\\.(?!\\.)[^/\\\\]+)$/.test(filepath)\n}\n","/**\n * Check if a file extension is valid.\n *\n * Invalid:\n * - empty string\n * - single dot: \".\"\n * - illegal characters: <>\"|?*:\n *\n * @param ext - The file extension to check.\n */\nexport function isExtValid(ext: string): boolean {\n return !!ext && ext !== '.' && !/[\"*:<>?|]/.test(ext)\n}\n","import path from 'path'\n\n/**\n * Whether a path is a relative string, ie. not absolute.\n */\nexport function isRelative(p: string) {\n return !path.isAbsolute(p)\n}\n","/**\n * Determines if a given filepath is a UNC path.\n * @param filepath - The filepath to evaluate.\n * @returns A boolean indicating whether the filepath is a UNC path.\n */\nexport function isUnc(filepath: string): boolean {\n return /^[/\\\\]{2,}[^/\\\\]+[/\\\\]+[^/\\\\]+/.test(filepath)\n}\n","/**\n * Check whether a provided windows filesystem path string is valid according to:\n * https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx\n * @param path The path to validate.\n * @throws If the path is invalid and the `assert` option is true.\n */\nexport function isValidWin32(path: string, options?: { extendedMaxLength?: boolean }): boolean {\n if (path.length === 0) {\n return false\n }\n if (path.includes('/') && path.includes('\\\\')) {\n return false\n }\n const maxLength = (options && options.extendedMaxLength ? 32_767 : 260) - 12\n if (path.length > maxLength) {\n return false\n }\n const noDriveLetter = /^\\w:(\\\\|\\/)/g.test(path) ? path.substring(2) : path\n if (/[\"*:<>?|]/g.test(noDriveLetter)) {\n return false\n }\n if (/(\\\\|\\/)(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])((\\\\|\\/)|$)/g.test(path)) {\n return false\n }\n return true\n}\n","import upath from 'upath'\n\n/**\n * Append string to the beginning of the filename.\n *\n * @example ```ts\n * path.fileNameWithPrefix('path/to/file-name.ext', 'new-')\n * // => path/to/new-file-name.ext\n * ```\n */\nexport function prefixFilename(filePath: string, prefix: string) {\n const ext = upath.extname(filePath)\n const fileNameWithoutExt = upath.basename(filePath, ext)\n return upath.joinSafe(upath.dirname(filePath), prefix + fileNameWithoutExt + ext)\n}\n","import upath from 'upath'\n\n/**\n * Returns the root directory of a given path.\n */\nexport function root(p: string) {\n return upath.parse(p).root\n}\n","import upath from 'upath'\n\n/**\n * Append string to the end of the filename.\n *\n * @example ```ts\n * path.suffixFilename('path/to/file-name.ext', '-old')\n * // => path/to/file-name-old.ext\n * ```\n */\nexport function suffixFilename(filePath: string, suffix: string) {\n const split = upath.basename(filePath).split('.')\n split[0] += suffix\n return upath.joinSafe(upath.dirname(filePath), split.join('.'))\n}\n","import upath from 'upath'\n\n/**\n * Solve the relative path from the process.cwd() path to the {p} path.\n * At times we have two absolute paths, and we need to derive the relative path from one to the other.\n * This is actually the reverse transform of path.resolve.\n */\nexport function toCwdRelative(p: string) {\n return upath.relative(process.cwd(), p)\n}\n","/**\n * Ensures win32 backslashes are used instead of forward slashes.\n */\nexport function toWin32(p: string) {\n return p.replaceAll('/', '\\\\')\n}\n"]}
|
package/lib/index.d.cts
CHANGED
|
@@ -16,6 +16,8 @@ declare function cwd(...p: string[]): string;
|
|
|
16
16
|
*/
|
|
17
17
|
declare function dirnameDeep(p: string, depth?: number): string;
|
|
18
18
|
|
|
19
|
+
// For `@link`
|
|
20
|
+
|
|
19
21
|
/**
|
|
20
22
|
Create a type that represents either the value or an array of the value.
|
|
21
23
|
|
|
@@ -30,8 +32,8 @@ function bundle(input: string, output: Arrayable<string>) {
|
|
|
30
32
|
|
|
31
33
|
// …
|
|
32
34
|
|
|
33
|
-
for (const
|
|
34
|
-
console.log(`write ${input} to: ${
|
|
35
|
+
for (const outputPath of outputList) {
|
|
36
|
+
console.log(`write ${input} to: ${outputPath}`);
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
|
package/lib/index.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ declare function cwd(...p: string[]): string;
|
|
|
16
16
|
*/
|
|
17
17
|
declare function dirnameDeep(p: string, depth?: number): string;
|
|
18
18
|
|
|
19
|
+
// For `@link`
|
|
20
|
+
|
|
19
21
|
/**
|
|
20
22
|
Create a type that represents either the value or an array of the value.
|
|
21
23
|
|
|
@@ -30,8 +32,8 @@ function bundle(input: string, output: Arrayable<string>) {
|
|
|
30
32
|
|
|
31
33
|
// …
|
|
32
34
|
|
|
33
|
-
for (const
|
|
34
|
-
console.log(`write ${input} to: ${
|
|
35
|
+
for (const outputPath of outputList) {
|
|
36
|
+
console.log(`write ${input} to: ${outputPath}`);
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
|
package/lib/index.js
CHANGED
|
@@ -149,3 +149,5 @@ function toWin32(p) {
|
|
|
149
149
|
__name(toWin32, "toWin32");
|
|
150
150
|
|
|
151
151
|
export { cwd, dirnameDeep, hasBasename, hasExtname, hasParentDirname, isDotFile, isExtValid, isRelative, isUnc, isValidWin32, prefixFilename, root, suffixFilename, toCwdRelative, toWin32 };
|
|
152
|
+
//# sourceMappingURL=index.js.map
|
|
153
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/cwd.ts","../../src/lib/dirnameDeep.ts","../../src/lib/hasBasename.ts","../../../fn/src/setNameAndLength.ts","../../../fn/src/bindArg.ts","../../src/lib/hasExtname.ts","../../src/lib/hasParentDirname.ts","../../src/lib/isDotFile.ts","../../src/lib/isExtValid.ts","../../src/lib/isRelative.ts","../../src/lib/isUnc.ts","../../src/lib/isValidWin32.ts","../../src/lib/prefixFilename.ts","../../src/lib/root.ts","../../src/lib/suffixFilename.ts","../../src/lib/toCwdRelative.ts","../../src/lib/toWin32.ts"],"names":["cwd","p","upath","joinSafe","process","dirnameDeep","depth","parent","dirname","hasBasename","tsFilepath","basenames","flat","includes","basename","setNameAndLength","source","target","lengthDelta","Object","defineProperties","name","configurable","value","length","bindArg","fn","boundArgIndex","boundArgValue","args","slice","hasExtname","extnames","RegExp","join","test","js","json","yaml","markdown","ts","hasParentDirname","fspath","isDotFile","filepath","isExtValid","ext","isRelative","path","isAbsolute","isUnc","isValidWin32","options","maxLength","extendedMaxLength","noDriveLetter","substring","prefixFilename","filePath","prefix","extname","fileNameWithoutExt","root","parse","suffixFilename","suffix","split","toCwdRelative","relative","toWin32","replaceAll"],"mappings":";;;;;AAUO,SAASA,OAAOC,CAAAA,EAAW;AAChC,EAAA,OAAOC,OAAMC,QAAAA,CAASC,OAAAA,CAAQJ,GAAAA,EAAG,EAAA,GAAOC,CAAAA,CAAAA;AAC1C;AAFgBD,MAAAA,CAAAA,GAAAA,EAAAA,KAAAA,CAAAA;ACFT,SAASK,WAAAA,CAAYJ,GAAWK,KAAAA,EAAc;AACnD,EAAA,MAAMC,MAAAA,GAASL,MAAAA,CAAMM,OAAAA,CAAQP,CAAAA,CAAAA;AAC7B,EAAA,OAAOK,SAASA,KAAAA,GAAQ,CAAA,GAAID,YAAYE,MAAAA,EAAQD,KAAAA,GAAQ,CAAA,CAAA,GAAKC,MAAAA;AAC/D;AAHgBF,MAAAA,CAAAA,WAAAA,EAAAA,aAAAA,CAAAA;ACFT,SAASI,WAAAA,CAAYC,YAAoBC,SAAAA,EAA4B;AAC1E,EAAA,OAAO;AAACA,IAAAA;AAAWC,GAAAA,CAAAA,IAAAA,CAAK,CAAA,CAAA,CAAGC,QAAAA,CAASX,MAAAA,CAAMY,QAAA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AAA,OAAAA,EAAAA,SAAAA,CAAAA","file":"index.js","sourcesContent":["import upath from 'upath'\n\n/**\n * Join paths starting from process.cwd()\n *\n * @example ```ts\n * // equivalent to:\n * path.join(process.cwd(), ...p)\n * ```\n */\nexport function cwd(...p: string[]) {\n return upath.joinSafe(process.cwd(), ...p)\n}\n","import upath from 'upath'\n\n/**\n * Returns the absolute path of the parent directory of the given path.\n * @param p the path\n * @param depth how many times to get the parent directory\n * @example dirnameDeep('a/b/c/d', 2) => 'a/b'\n */\nexport function dirnameDeep(p: string, depth?: number): string {\n const parent = upath.dirname(p)\n return depth && depth > 1 ? dirnameDeep(parent, depth - 1) : parent\n}\n","import type { Arrayable } from 'type-fest'\nimport upath from 'upath'\n\n/**\n * Checks if a file path has any of the specified basenames.\n */\nexport function hasBasename(tsFilepath: string, basenames: Arrayable<string>): boolean {\n return [basenames].flat(2).includes(upath.basename(tsFilepath))\n}\n","import type { Any } from '@mono/types'\n\n/**\n * Preserves the name and length of a function or class constructor\n */\nexport function setNameAndLength<\n S extends ((...args: Any[]) => Any) | (new (...args: Any[]) => Any),\n F extends ((...args: Any[]) => Any) | (new (...args: Any[]) => Any),\n>(source: S, target: F, lengthDelta = 0): F {\n return Object.defineProperties(target, {\n name: { configurable: true, value: source.name }, //\n length: { configurable: true, value: source.length + lengthDelta },\n })\n}\n","import type { ParametersWithout } from '@mono/types'\nimport { setNameAndLength } from './setNameAndLength'\n\n/**\n * Binds a specified argument to the provided function, returning a new function that requires\n * only the remaining arguments at call time.\n */\nexport function bindArg<\n Ret extends (...args: ParametersWithout<T, Index>) => ReturnType<T>,\n Index extends number = number,\n Value = unknown,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends (...args: any[]) => any = (...args: any[]) => any,\n>(fn: T, boundArgIndex: Index, boundArgValue: Value) {\n return setNameAndLength(\n fn,\n (...args: ParametersWithout<T, Index>) =>\n fn(...args.slice(0, boundArgIndex), boundArgValue, ...args.slice(boundArgIndex)),\n -1\n ) as Ret\n}\n","import type { Arrayable } from 'type-fest'\nimport { bindArg } from '@mono/fn'\n\n/**\n * Checks if a file path has any of the specified file extensions.\n */\nexport function hasExtname(tsFilepath: string, extnames: Arrayable<string>): boolean {\n return new RegExp(`[.](${[extnames].flat(2).join('|')})$`).test(tsFilepath)\n}\n\nhasExtname.js = bindArg(hasExtname, 1, ['js', 'mjs', 'jsx', 'cjs'])\nhasExtname.json = bindArg(hasExtname, 1, ['json', 'jsonc'])\nhasExtname.yaml = bindArg(hasExtname, 1, ['yaml', 'yml'])\nhasExtname.markdown = bindArg(hasExtname, 1, ['md', 'markdown'])\nhasExtname.ts = bindArg(hasExtname, 1, ['ts', 'mts', 'tsx'])\n","/**\n * Whether fspath is a subpath of a parent directory with the given name.\n */\nexport function hasParentDirname(fspath: string, name: string) {\n return new RegExp(`(^|[/\\\\\\\\])${name}[/\\\\\\\\]`).test(fspath)\n}\n","/**\n * Determines if a given filepath is a dotfile.\n * @param filepath - The filepath to evaluate.\n * @returns A boolean indicating whether the filepath is a dotfile.\n */\nexport function isDotFile(filepath: string): boolean {\n return /(?:^|[/\\\\])(\\.(?!\\.)[^/\\\\]+)$/.test(filepath)\n}\n","/**\n * Check if a file extension is valid.\n *\n * Invalid:\n * - empty string\n * - single dot: \".\"\n * - illegal characters: <>\"|?*:\n *\n * @param ext - The file extension to check.\n */\nexport function isExtValid(ext: string): boolean {\n return !!ext && ext !== '.' && !/[\"*:<>?|]/.test(ext)\n}\n","import path from 'path'\n\n/**\n * Whether a path is a relative string, ie. not absolute.\n */\nexport function isRelative(p: string) {\n return !path.isAbsolute(p)\n}\n","/**\n * Determines if a given filepath is a UNC path.\n * @param filepath - The filepath to evaluate.\n * @returns A boolean indicating whether the filepath is a UNC path.\n */\nexport function isUnc(filepath: string): boolean {\n return /^[/\\\\]{2,}[^/\\\\]+[/\\\\]+[^/\\\\]+/.test(filepath)\n}\n","/**\n * Check whether a provided windows filesystem path string is valid according to:\n * https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx\n * @param path The path to validate.\n * @throws If the path is invalid and the `assert` option is true.\n */\nexport function isValidWin32(path: string, options?: { extendedMaxLength?: boolean }): boolean {\n if (path.length === 0) {\n return false\n }\n if (path.includes('/') && path.includes('\\\\')) {\n return false\n }\n const maxLength = (options && options.extendedMaxLength ? 32_767 : 260) - 12\n if (path.length > maxLength) {\n return false\n }\n const noDriveLetter = /^\\w:(\\\\|\\/)/g.test(path) ? path.substring(2) : path\n if (/[\"*:<>?|]/g.test(noDriveLetter)) {\n return false\n }\n if (/(\\\\|\\/)(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])((\\\\|\\/)|$)/g.test(path)) {\n return false\n }\n return true\n}\n","import upath from 'upath'\n\n/**\n * Append string to the beginning of the filename.\n *\n * @example ```ts\n * path.fileNameWithPrefix('path/to/file-name.ext', 'new-')\n * // => path/to/new-file-name.ext\n * ```\n */\nexport function prefixFilename(filePath: string, prefix: string) {\n const ext = upath.extname(filePath)\n const fileNameWithoutExt = upath.basename(filePath, ext)\n return upath.joinSafe(upath.dirname(filePath), prefix + fileNameWithoutExt + ext)\n}\n","import upath from 'upath'\n\n/**\n * Returns the root directory of a given path.\n */\nexport function root(p: string) {\n return upath.parse(p).root\n}\n","import upath from 'upath'\n\n/**\n * Append string to the end of the filename.\n *\n * @example ```ts\n * path.suffixFilename('path/to/file-name.ext', '-old')\n * // => path/to/file-name-old.ext\n * ```\n */\nexport function suffixFilename(filePath: string, suffix: string) {\n const split = upath.basename(filePath).split('.')\n split[0] += suffix\n return upath.joinSafe(upath.dirname(filePath), split.join('.'))\n}\n","import upath from 'upath'\n\n/**\n * Solve the relative path from the process.cwd() path to the {p} path.\n * At times we have two absolute paths, and we need to derive the relative path from one to the other.\n * This is actually the reverse transform of path.resolve.\n */\nexport function toCwdRelative(p: string) {\n return upath.relative(process.cwd(), p)\n}\n","/**\n * Ensures win32 backslashes are used instead of forward slashes.\n */\nexport function toWin32(p: string) {\n return p.replaceAll('/', '\\\\')\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bemoje/path",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "Cross-platform path utilities extending upath with validation, manipulation, and inspection helpers.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"upath": "^
|
|
11
|
+
"upath": "^3.0.8"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
14
14
|
"path",
|
|
@@ -27,7 +27,9 @@
|
|
|
27
27
|
"./lib/index.js",
|
|
28
28
|
"./lib/index.d.ts",
|
|
29
29
|
"./lib/index.cjs",
|
|
30
|
-
"./lib/index.d.cts"
|
|
30
|
+
"./lib/index.d.cts",
|
|
31
|
+
"./lib/index.js.map",
|
|
32
|
+
"./lib/index.cjs.map"
|
|
31
33
|
],
|
|
32
34
|
"exports": {
|
|
33
35
|
".": {
|