@bemoje/path 1.1.1 → 1.1.2
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/lib/index.d.cts +149 -16
- package/lib/index.d.ts +149 -16
- package/package.json +95 -155
- package/lib/lib/cwd.cjs +0 -16
- package/lib/lib/cwd.d.cts +0 -11
- package/lib/lib/cwd.d.ts +0 -11
- package/lib/lib/cwd.js +0 -10
- package/lib/lib/dirnameDeep.cjs +0 -17
- package/lib/lib/dirnameDeep.d.cts +0 -9
- package/lib/lib/dirnameDeep.d.ts +0 -9
- package/lib/lib/dirnameDeep.js +0 -11
- package/lib/lib/hasBasename.cjs +0 -18
- package/lib/lib/hasBasename.d.cts +0 -8
- package/lib/lib/hasBasename.d.ts +0 -8
- package/lib/lib/hasBasename.js +0 -12
- package/lib/lib/hasExtname.cjs +0 -60
- package/lib/lib/hasExtname.d.cts +0 -15
- package/lib/lib/hasExtname.d.ts +0 -15
- package/lib/lib/hasExtname.js +0 -58
- package/lib/lib/hasParentDirname.cjs +0 -12
- package/lib/lib/hasParentDirname.d.cts +0 -6
- package/lib/lib/hasParentDirname.d.ts +0 -6
- package/lib/lib/hasParentDirname.js +0 -10
- package/lib/lib/isDotFile.cjs +0 -12
- package/lib/lib/isDotFile.d.cts +0 -8
- package/lib/lib/isDotFile.d.ts +0 -8
- package/lib/lib/isDotFile.js +0 -10
- package/lib/lib/isExtValid.cjs +0 -12
- package/lib/lib/isExtValid.d.cts +0 -13
- package/lib/lib/isExtValid.d.ts +0 -13
- package/lib/lib/isExtValid.js +0 -10
- package/lib/lib/isRelative.cjs +0 -16
- package/lib/lib/isRelative.d.cts +0 -6
- package/lib/lib/isRelative.d.ts +0 -6
- package/lib/lib/isRelative.js +0 -10
- package/lib/lib/isUnc.cjs +0 -12
- package/lib/lib/isUnc.d.cts +0 -8
- package/lib/lib/isUnc.d.ts +0 -8
- package/lib/lib/isUnc.js +0 -10
- package/lib/lib/isValidWin32.cjs +0 -29
- package/lib/lib/isValidWin32.d.cts +0 -11
- package/lib/lib/isValidWin32.d.ts +0 -11
- package/lib/lib/isValidWin32.js +0 -27
- package/lib/lib/prefixFilename.cjs +0 -18
- package/lib/lib/prefixFilename.d.cts +0 -11
- package/lib/lib/prefixFilename.d.ts +0 -11
- package/lib/lib/prefixFilename.js +0 -12
- package/lib/lib/root.cjs +0 -16
- package/lib/lib/root.d.cts +0 -6
- package/lib/lib/root.d.ts +0 -6
- package/lib/lib/root.js +0 -10
- package/lib/lib/suffixFilename.cjs +0 -18
- package/lib/lib/suffixFilename.d.cts +0 -11
- package/lib/lib/suffixFilename.d.ts +0 -11
- package/lib/lib/suffixFilename.js +0 -12
- package/lib/lib/toCwdRelative.cjs +0 -16
- package/lib/lib/toCwdRelative.d.cts +0 -8
- package/lib/lib/toCwdRelative.d.ts +0 -8
- package/lib/lib/toCwdRelative.js +0 -10
- package/lib/lib/toWin32.cjs +0 -12
- package/lib/lib/toWin32.d.cts +0 -6
- package/lib/lib/toWin32.d.ts +0 -6
- package/lib/lib/toWin32.js +0 -10
package/lib/index.d.cts
CHANGED
|
@@ -1,16 +1,149 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Join paths starting from process.cwd()
|
|
3
|
+
*
|
|
4
|
+
* @example ```ts
|
|
5
|
+
* // equivalent to:
|
|
6
|
+
* path.join(process.cwd(), ...p)
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
declare function cwd(...p: string[]): string;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Returns the absolute path of the parent directory of the given path.
|
|
13
|
+
* @param p the path
|
|
14
|
+
* @param depth how many times to get the parent directory
|
|
15
|
+
* @example dirnameDeep('a/b/c/d', 2) => 'a/b'
|
|
16
|
+
*/
|
|
17
|
+
declare function dirnameDeep(p: string, depth?: number): string;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
Create a type that represents either the value or an array of the value.
|
|
21
|
+
|
|
22
|
+
@see {@link Promisable}
|
|
23
|
+
|
|
24
|
+
@example
|
|
25
|
+
```
|
|
26
|
+
import type {Arrayable} from 'type-fest';
|
|
27
|
+
|
|
28
|
+
function bundle(input: string, output: Arrayable<string>) {
|
|
29
|
+
const outputList = Array.isArray(output) ? output : [output];
|
|
30
|
+
|
|
31
|
+
// …
|
|
32
|
+
|
|
33
|
+
for (const output of outputList) {
|
|
34
|
+
console.log(`write ${input} to: ${output}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
bundle('src/index.js', 'dist/index.js');
|
|
39
|
+
bundle('src/index.js', ['dist/index.cjs', 'dist/index.mjs']);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
@category Array
|
|
43
|
+
*/
|
|
44
|
+
type Arrayable<T> =
|
|
45
|
+
T
|
|
46
|
+
// TODO: Use `readonly T[]` when this issue is resolved: https://github.com/microsoft/TypeScript/issues/17002
|
|
47
|
+
| T[];
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Checks if a file path has any of the specified basenames.
|
|
51
|
+
*/
|
|
52
|
+
declare function hasBasename(tsFilepath: string, basenames: Arrayable<string>): boolean;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Checks if a file path has any of the specified file extensions.
|
|
56
|
+
*/
|
|
57
|
+
declare function hasExtname(tsFilepath: string, extnames: Arrayable<string>): boolean;
|
|
58
|
+
declare namespace hasExtname {
|
|
59
|
+
var js: (tsFilepath: string) => boolean;
|
|
60
|
+
var json: (tsFilepath: string) => boolean;
|
|
61
|
+
var yaml: (tsFilepath: string) => boolean;
|
|
62
|
+
var markdown: (tsFilepath: string) => boolean;
|
|
63
|
+
var ts: (tsFilepath: string) => boolean;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Whether fspath is a subpath of a parent directory with the given name.
|
|
68
|
+
*/
|
|
69
|
+
declare function hasParentDirname(fspath: string, name: string): boolean;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Determines if a given filepath is a dotfile.
|
|
73
|
+
* @param filepath - The filepath to evaluate.
|
|
74
|
+
* @returns A boolean indicating whether the filepath is a dotfile.
|
|
75
|
+
*/
|
|
76
|
+
declare function isDotFile(filepath: string): boolean;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Check if a file extension is valid.
|
|
80
|
+
*
|
|
81
|
+
* Invalid:
|
|
82
|
+
* - empty string
|
|
83
|
+
* - single dot: "."
|
|
84
|
+
* - illegal characters: <>"|?*:
|
|
85
|
+
*
|
|
86
|
+
* @param ext - The file extension to check.
|
|
87
|
+
*/
|
|
88
|
+
declare function isExtValid(ext: string): boolean;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Whether a path is a relative string, ie. not absolute.
|
|
92
|
+
*/
|
|
93
|
+
declare function isRelative(p: string): boolean;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Determines if a given filepath is a UNC path.
|
|
97
|
+
* @param filepath - The filepath to evaluate.
|
|
98
|
+
* @returns A boolean indicating whether the filepath is a UNC path.
|
|
99
|
+
*/
|
|
100
|
+
declare function isUnc(filepath: string): boolean;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Check whether a provided windows filesystem path string is valid according to:
|
|
104
|
+
* https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
|
|
105
|
+
* @param path The path to validate.
|
|
106
|
+
* @throws If the path is invalid and the `assert` option is true.
|
|
107
|
+
*/
|
|
108
|
+
declare function isValidWin32(path: string, options?: {
|
|
109
|
+
extendedMaxLength?: boolean;
|
|
110
|
+
}): boolean;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Append string to the beginning of the filename.
|
|
114
|
+
*
|
|
115
|
+
* @example ```ts
|
|
116
|
+
* path.fileNameWithPrefix('path/to/file-name.ext', 'new-')
|
|
117
|
+
* // => path/to/new-file-name.ext
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
declare function prefixFilename(filePath: string, prefix: string): string;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Returns the root directory of a given path.
|
|
124
|
+
*/
|
|
125
|
+
declare function root(p: string): string;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Append string to the end of the filename.
|
|
129
|
+
*
|
|
130
|
+
* @example ```ts
|
|
131
|
+
* path.suffixFilename('path/to/file-name.ext', '-old')
|
|
132
|
+
* // => path/to/file-name-old.ext
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
declare function suffixFilename(filePath: string, suffix: string): string;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Solve the relative path from the process.cwd() path to the {p} path.
|
|
139
|
+
* At times we have two absolute paths, and we need to derive the relative path from one to the other.
|
|
140
|
+
* This is actually the reverse transform of path.resolve.
|
|
141
|
+
*/
|
|
142
|
+
declare function toCwdRelative(p: string): string;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Ensures win32 backslashes are used instead of forward slashes.
|
|
146
|
+
*/
|
|
147
|
+
declare function toWin32(p: string): string;
|
|
148
|
+
|
|
149
|
+
export { cwd, dirnameDeep, hasBasename, hasExtname, hasParentDirname, isDotFile, isExtValid, isRelative, isUnc, isValidWin32, prefixFilename, root, suffixFilename, toCwdRelative, toWin32 };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,16 +1,149 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Join paths starting from process.cwd()
|
|
3
|
+
*
|
|
4
|
+
* @example ```ts
|
|
5
|
+
* // equivalent to:
|
|
6
|
+
* path.join(process.cwd(), ...p)
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
declare function cwd(...p: string[]): string;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Returns the absolute path of the parent directory of the given path.
|
|
13
|
+
* @param p the path
|
|
14
|
+
* @param depth how many times to get the parent directory
|
|
15
|
+
* @example dirnameDeep('a/b/c/d', 2) => 'a/b'
|
|
16
|
+
*/
|
|
17
|
+
declare function dirnameDeep(p: string, depth?: number): string;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
Create a type that represents either the value or an array of the value.
|
|
21
|
+
|
|
22
|
+
@see {@link Promisable}
|
|
23
|
+
|
|
24
|
+
@example
|
|
25
|
+
```
|
|
26
|
+
import type {Arrayable} from 'type-fest';
|
|
27
|
+
|
|
28
|
+
function bundle(input: string, output: Arrayable<string>) {
|
|
29
|
+
const outputList = Array.isArray(output) ? output : [output];
|
|
30
|
+
|
|
31
|
+
// …
|
|
32
|
+
|
|
33
|
+
for (const output of outputList) {
|
|
34
|
+
console.log(`write ${input} to: ${output}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
bundle('src/index.js', 'dist/index.js');
|
|
39
|
+
bundle('src/index.js', ['dist/index.cjs', 'dist/index.mjs']);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
@category Array
|
|
43
|
+
*/
|
|
44
|
+
type Arrayable<T> =
|
|
45
|
+
T
|
|
46
|
+
// TODO: Use `readonly T[]` when this issue is resolved: https://github.com/microsoft/TypeScript/issues/17002
|
|
47
|
+
| T[];
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Checks if a file path has any of the specified basenames.
|
|
51
|
+
*/
|
|
52
|
+
declare function hasBasename(tsFilepath: string, basenames: Arrayable<string>): boolean;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Checks if a file path has any of the specified file extensions.
|
|
56
|
+
*/
|
|
57
|
+
declare function hasExtname(tsFilepath: string, extnames: Arrayable<string>): boolean;
|
|
58
|
+
declare namespace hasExtname {
|
|
59
|
+
var js: (tsFilepath: string) => boolean;
|
|
60
|
+
var json: (tsFilepath: string) => boolean;
|
|
61
|
+
var yaml: (tsFilepath: string) => boolean;
|
|
62
|
+
var markdown: (tsFilepath: string) => boolean;
|
|
63
|
+
var ts: (tsFilepath: string) => boolean;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Whether fspath is a subpath of a parent directory with the given name.
|
|
68
|
+
*/
|
|
69
|
+
declare function hasParentDirname(fspath: string, name: string): boolean;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Determines if a given filepath is a dotfile.
|
|
73
|
+
* @param filepath - The filepath to evaluate.
|
|
74
|
+
* @returns A boolean indicating whether the filepath is a dotfile.
|
|
75
|
+
*/
|
|
76
|
+
declare function isDotFile(filepath: string): boolean;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Check if a file extension is valid.
|
|
80
|
+
*
|
|
81
|
+
* Invalid:
|
|
82
|
+
* - empty string
|
|
83
|
+
* - single dot: "."
|
|
84
|
+
* - illegal characters: <>"|?*:
|
|
85
|
+
*
|
|
86
|
+
* @param ext - The file extension to check.
|
|
87
|
+
*/
|
|
88
|
+
declare function isExtValid(ext: string): boolean;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Whether a path is a relative string, ie. not absolute.
|
|
92
|
+
*/
|
|
93
|
+
declare function isRelative(p: string): boolean;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Determines if a given filepath is a UNC path.
|
|
97
|
+
* @param filepath - The filepath to evaluate.
|
|
98
|
+
* @returns A boolean indicating whether the filepath is a UNC path.
|
|
99
|
+
*/
|
|
100
|
+
declare function isUnc(filepath: string): boolean;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Check whether a provided windows filesystem path string is valid according to:
|
|
104
|
+
* https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
|
|
105
|
+
* @param path The path to validate.
|
|
106
|
+
* @throws If the path is invalid and the `assert` option is true.
|
|
107
|
+
*/
|
|
108
|
+
declare function isValidWin32(path: string, options?: {
|
|
109
|
+
extendedMaxLength?: boolean;
|
|
110
|
+
}): boolean;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Append string to the beginning of the filename.
|
|
114
|
+
*
|
|
115
|
+
* @example ```ts
|
|
116
|
+
* path.fileNameWithPrefix('path/to/file-name.ext', 'new-')
|
|
117
|
+
* // => path/to/new-file-name.ext
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
declare function prefixFilename(filePath: string, prefix: string): string;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Returns the root directory of a given path.
|
|
124
|
+
*/
|
|
125
|
+
declare function root(p: string): string;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Append string to the end of the filename.
|
|
129
|
+
*
|
|
130
|
+
* @example ```ts
|
|
131
|
+
* path.suffixFilename('path/to/file-name.ext', '-old')
|
|
132
|
+
* // => path/to/file-name-old.ext
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
declare function suffixFilename(filePath: string, suffix: string): string;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Solve the relative path from the process.cwd() path to the {p} path.
|
|
139
|
+
* At times we have two absolute paths, and we need to derive the relative path from one to the other.
|
|
140
|
+
* This is actually the reverse transform of path.resolve.
|
|
141
|
+
*/
|
|
142
|
+
declare function toCwdRelative(p: string): string;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Ensures win32 backslashes are used instead of forward slashes.
|
|
146
|
+
*/
|
|
147
|
+
declare function toWin32(p: string): string;
|
|
148
|
+
|
|
149
|
+
export { cwd, dirnameDeep, hasBasename, hasExtname, hasParentDirname, isDotFile, isExtValid, isRelative, isUnc, isValidWin32, prefixFilename, root, suffixFilename, toCwdRelative, toWin32 };
|