@bemoje/path 1.0.1 → 1.1.0

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.
Files changed (67) hide show
  1. package/lib/index.cjs +110 -0
  2. package/lib/index.d.cts +16 -0
  3. package/lib/index.d.ts +16 -0
  4. package/lib/index.js +15 -0
  5. package/lib/lib/cwd.cjs +16 -0
  6. package/lib/lib/cwd.d.cts +11 -0
  7. package/lib/lib/cwd.d.ts +11 -0
  8. package/lib/lib/cwd.js +9 -0
  9. package/lib/lib/dirnameDeep.cjs +17 -0
  10. package/lib/lib/dirnameDeep.d.cts +9 -0
  11. package/lib/lib/dirnameDeep.d.ts +9 -0
  12. package/lib/lib/dirnameDeep.js +10 -0
  13. package/lib/lib/hasBasename.cjs +18 -0
  14. package/lib/lib/hasBasename.d.cts +8 -0
  15. package/lib/lib/hasBasename.d.ts +8 -0
  16. package/lib/lib/hasBasename.js +11 -0
  17. package/lib/lib/hasExtname.cjs +37 -0
  18. package/lib/lib/hasExtname.d.cts +15 -0
  19. package/lib/lib/hasExtname.d.ts +15 -0
  20. package/lib/lib/hasExtname.js +34 -0
  21. package/lib/lib/hasParentDirname.cjs +10 -0
  22. package/lib/lib/hasParentDirname.d.cts +6 -0
  23. package/lib/lib/hasParentDirname.d.ts +6 -0
  24. package/lib/lib/hasParentDirname.js +8 -0
  25. package/lib/lib/isDotFile.cjs +10 -0
  26. package/lib/lib/isDotFile.d.cts +8 -0
  27. package/lib/lib/isDotFile.d.ts +8 -0
  28. package/lib/lib/isDotFile.js +8 -0
  29. package/lib/lib/isExtValid.cjs +10 -0
  30. package/lib/lib/isExtValid.d.cts +13 -0
  31. package/lib/lib/isExtValid.d.ts +13 -0
  32. package/lib/lib/isExtValid.js +8 -0
  33. package/lib/lib/isRelative.cjs +16 -0
  34. package/lib/lib/isRelative.d.cts +6 -0
  35. package/lib/lib/isRelative.d.ts +6 -0
  36. package/lib/lib/isRelative.js +9 -0
  37. package/lib/lib/isUnc.cjs +10 -0
  38. package/lib/lib/isUnc.d.cts +8 -0
  39. package/lib/lib/isUnc.d.ts +8 -0
  40. package/lib/lib/isUnc.js +8 -0
  41. package/lib/lib/isValidWin32.cjs +27 -0
  42. package/lib/lib/isValidWin32.d.cts +11 -0
  43. package/lib/lib/isValidWin32.d.ts +11 -0
  44. package/lib/lib/isValidWin32.js +25 -0
  45. package/lib/lib/prefixFilename.cjs +18 -0
  46. package/lib/lib/prefixFilename.d.cts +11 -0
  47. package/lib/lib/prefixFilename.d.ts +11 -0
  48. package/lib/lib/prefixFilename.js +11 -0
  49. package/lib/lib/root.cjs +16 -0
  50. package/lib/lib/root.d.cts +6 -0
  51. package/lib/lib/root.d.ts +6 -0
  52. package/lib/lib/root.js +9 -0
  53. package/lib/lib/suffixFilename.cjs +18 -0
  54. package/lib/lib/suffixFilename.d.cts +11 -0
  55. package/lib/lib/suffixFilename.d.ts +11 -0
  56. package/lib/lib/suffixFilename.js +11 -0
  57. package/lib/lib/toCwdRelative.cjs +16 -0
  58. package/lib/lib/toCwdRelative.d.cts +8 -0
  59. package/lib/lib/toCwdRelative.d.ts +8 -0
  60. package/lib/lib/toCwdRelative.js +9 -0
  61. package/lib/lib/toWin32.cjs +10 -0
  62. package/lib/lib/toWin32.d.cts +6 -0
  63. package/lib/lib/toWin32.d.ts +6 -0
  64. package/lib/lib/toWin32.js +8 -0
  65. package/package.json +249 -19
  66. package/index.d.ts +0 -121
  67. package/index.mjs +0 -153
package/index.d.ts DELETED
@@ -1,121 +0,0 @@
1
- import { Arrayable } from 'type-fest';
2
-
3
- /**
4
- * Join paths starting from process.cwd()
5
- *
6
- * @example ```ts
7
- * // equivalent to:
8
- * path.join(process.cwd(), ...p)
9
- * ```
10
- */
11
- declare function cwd(...p: string[]): string;
12
-
13
- /**
14
- * Returns the absolute path of the parent directory of the given path.
15
- * @param p the path
16
- * @param depth how many times to get the parent directory
17
- * @example dirnameDeep('a/b/c/d', 2) => 'a/b'
18
- */
19
- declare function dirnameDeep(p: string, depth?: number): string;
20
-
21
- /**
22
- * Checks if a file path has any of the specified basenames.
23
- */
24
- declare function hasBasename(tsFilepath: string, basenames: Arrayable<string>): boolean;
25
-
26
- /**
27
- * Checks if a file path has any of the specified file extensions.
28
- */
29
- declare function hasExtname(tsFilepath: string, extnames: Arrayable<string>): boolean;
30
- declare namespace hasExtname {
31
- var js: (tsFilepath: string) => boolean;
32
- var json: (tsFilepath: string) => boolean;
33
- var yaml: (tsFilepath: string) => boolean;
34
- var markdown: (tsFilepath: string) => boolean;
35
- var ts: (tsFilepath: string) => boolean;
36
- }
37
-
38
- /**
39
- * Whether fspath is a subpath of a parent directory with the given name.
40
- */
41
- declare function hasParentDirname(fspath: string, name: string): boolean;
42
-
43
- /**
44
- * Determines if a given filepath is a dotfile.
45
- * @param filepath - The filepath to evaluate.
46
- * @returns A boolean indicating whether the filepath is a dotfile.
47
- */
48
- declare function isDotFile(filepath: string): boolean;
49
-
50
- /**
51
- * Check if a file extension is valid.
52
- *
53
- * Invalid:
54
- * - empty string
55
- * - single dot: "."
56
- * - illegal characters: <>"|?*:
57
- *
58
- * @param ext - The file extension to check.
59
- */
60
- declare function isExtValid(ext: string): boolean;
61
-
62
- /**
63
- * Whether a path is a relative string, ie. not absolute.
64
- */
65
- declare function isRelative(p: string): boolean;
66
-
67
- /**
68
- * Determines if a given filepath is a UNC path.
69
- * @param filepath - The filepath to evaluate.
70
- * @returns A boolean indicating whether the filepath is a UNC path.
71
- */
72
- declare function isUnc(filepath: string): boolean;
73
-
74
- /**
75
- * Check whether a provided windows filesystem path string is valid according to:
76
- * https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
77
- * @param path The path to validate.
78
- * @throws If the path is invalid and the `assert` option is true.
79
- */
80
- declare function isValidWin32(path: string, options?: {
81
- extendedMaxLength?: boolean;
82
- }): boolean;
83
-
84
- /**
85
- * Append string to the beginning of the filename.
86
- *
87
- * @example ```ts
88
- * path.fileNameWithPrefix('path/to/file-name.ext', 'new-')
89
- * // => path/to/new-file-name.ext
90
- * ```
91
- */
92
- declare function prefixFilename(filePath: string, prefix: string): string;
93
-
94
- /**
95
- * Returns the root directory of a given path.
96
- */
97
- declare function root(p: string): string;
98
-
99
- /**
100
- * Append string to the end of the filename.
101
- *
102
- * @example ```ts
103
- * path.suffixFilename('path/to/file-name.ext', '-old')
104
- * // => path/to/file-name-old.ext
105
- * ```
106
- */
107
- declare function suffixFilename(filePath: string, suffix: string): string;
108
-
109
- /**
110
- * Solve the relative path from the process.cwd() path to the {p} path.
111
- * At times we have two absolute paths, and we need to derive the relative path from one to the other.
112
- * This is actually the reverse transform of path.resolve.
113
- */
114
- declare function toCwdRelative(p: string): string;
115
-
116
- /**
117
- * Ensures win32 backslashes are used instead of forward slashes.
118
- */
119
- declare function toWin32(p: string): string;
120
-
121
- export { cwd, dirnameDeep, hasBasename, hasExtname, hasParentDirname, isDotFile, isExtValid, isRelative, isUnc, isValidWin32, prefixFilename, root, suffixFilename, toCwdRelative, toWin32 };
package/index.mjs DELETED
@@ -1,153 +0,0 @@
1
- import upath4 from 'upath';
2
- import path from 'path';
3
-
4
- var __defProp = Object.defineProperty;
5
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
- function cwd(...p) {
7
- return upath4.joinSafe(process.cwd(), ...p);
8
- }
9
- __name(cwd, "cwd");
10
- function dirnameDeep(p, depth) {
11
- const parent = upath4.dirname(p);
12
- return depth && depth > 1 ? dirnameDeep(parent, depth - 1) : parent;
13
- }
14
- __name(dirnameDeep, "dirnameDeep");
15
- function hasBasename(tsFilepath, basenames) {
16
- return [
17
- basenames
18
- ].flat(2).includes(upath4.basename(tsFilepath));
19
- }
20
- __name(hasBasename, "hasBasename");
21
-
22
- // ../fn/src/setNameAndLength.ts
23
- function setNameAndLength(source, target, lengthDelta = 0) {
24
- return Object.defineProperties(target, {
25
- name: {
26
- configurable: true,
27
- value: source.name
28
- },
29
- length: {
30
- configurable: true,
31
- value: source.length + lengthDelta
32
- }
33
- });
34
- }
35
- __name(setNameAndLength, "setNameAndLength");
36
-
37
- // ../fn/src/bindArg.ts
38
- function bindArg(fn, boundArgIndex, boundArgValue) {
39
- return setNameAndLength(fn, (...args) => {
40
- return fn(...args.slice(0, boundArgIndex), boundArgValue, ...args.slice(boundArgIndex));
41
- }, -1);
42
- }
43
- __name(bindArg, "bindArg");
44
-
45
- // src/lib/hasExtname.ts
46
- function hasExtname(tsFilepath, extnames) {
47
- return new RegExp(`[.](${[
48
- extnames
49
- ].flat(2).join("|")})$`).test(tsFilepath);
50
- }
51
- __name(hasExtname, "hasExtname");
52
- hasExtname.js = bindArg(hasExtname, 1, [
53
- "js",
54
- "mjs",
55
- "jsx",
56
- "cjs"
57
- ]);
58
- hasExtname.json = bindArg(hasExtname, 1, [
59
- "json",
60
- "jsonc"
61
- ]);
62
- hasExtname.yaml = bindArg(hasExtname, 1, [
63
- "yaml",
64
- "yml"
65
- ]);
66
- hasExtname.markdown = bindArg(hasExtname, 1, [
67
- "md",
68
- "markdown"
69
- ]);
70
- hasExtname.ts = bindArg(hasExtname, 1, [
71
- "ts",
72
- "mts",
73
- "tsx"
74
- ]);
75
-
76
- // src/lib/hasParentDirname.ts
77
- function hasParentDirname(fspath, name) {
78
- return new RegExp(`(^|[/\\\\])${name}[/\\\\]`).test(fspath);
79
- }
80
- __name(hasParentDirname, "hasParentDirname");
81
-
82
- // src/lib/isDotFile.ts
83
- function isDotFile(filepath) {
84
- return /(?:^|[/\\])(\.(?!\.)[^/\\]+)$/.test(filepath);
85
- }
86
- __name(isDotFile, "isDotFile");
87
-
88
- // src/lib/isExtValid.ts
89
- function isExtValid(ext) {
90
- return !!ext && ext !== "." && !/["*:<>?|]/.test(ext);
91
- }
92
- __name(isExtValid, "isExtValid");
93
- function isRelative(p) {
94
- return !path.isAbsolute(p);
95
- }
96
- __name(isRelative, "isRelative");
97
-
98
- // src/lib/isUnc.ts
99
- function isUnc(filepath) {
100
- return /^[/\\]{2,}[^/\\]+[/\\]+[^/\\]+/.test(filepath);
101
- }
102
- __name(isUnc, "isUnc");
103
-
104
- // src/lib/isValidWin32.ts
105
- function isValidWin32(path2, options) {
106
- if (path2.length === 0) {
107
- return false;
108
- }
109
- if (path2.includes("/") && path2.includes("\\")) {
110
- return false;
111
- }
112
- const maxLength = (options && options.extendedMaxLength ? 32767 : 260) - 12;
113
- if (path2.length > maxLength) {
114
- return false;
115
- }
116
- const noDriveLetter = /^\w:(\\|\/)/g.test(path2) ? path2.substring(2) : path2;
117
- if (/["*:<>?|]/g.test(noDriveLetter)) {
118
- return false;
119
- }
120
- if (/(\\|\/)(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])((\\|\/)|$)/g.test(path2)) {
121
- return false;
122
- }
123
- return true;
124
- }
125
- __name(isValidWin32, "isValidWin32");
126
- function prefixFilename(filePath, prefix) {
127
- const ext = upath4.extname(filePath);
128
- const fileNameWithoutExt = upath4.basename(filePath, ext);
129
- return upath4.joinSafe(upath4.dirname(filePath), prefix + fileNameWithoutExt + ext);
130
- }
131
- __name(prefixFilename, "prefixFilename");
132
- function root(p) {
133
- return upath4.parse(p).root;
134
- }
135
- __name(root, "root");
136
- function suffixFilename(filePath, suffix) {
137
- const split = upath4.basename(filePath).split(".");
138
- split[0] += suffix;
139
- return upath4.joinSafe(upath4.dirname(filePath), split.join("."));
140
- }
141
- __name(suffixFilename, "suffixFilename");
142
- function toCwdRelative(p) {
143
- return upath4.relative(process.cwd(), p);
144
- }
145
- __name(toCwdRelative, "toCwdRelative");
146
-
147
- // src/lib/toWin32.ts
148
- function toWin32(p) {
149
- return p.replaceAll("/", "\\");
150
- }
151
- __name(toWin32, "toWin32");
152
-
153
- export { cwd, dirnameDeep, hasBasename, hasExtname, hasParentDirname, isDotFile, isExtValid, isRelative, isUnc, isValidWin32, prefixFilename, root, suffixFilename, toCwdRelative, toWin32 };