@bemoje/path 1.1.0 → 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.
Files changed (65) hide show
  1. package/lib/index.cjs +169 -105
  2. package/lib/index.d.cts +149 -16
  3. package/lib/index.d.ts +149 -16
  4. package/lib/index.js +153 -15
  5. package/package.json +95 -155
  6. package/lib/lib/cwd.cjs +0 -16
  7. package/lib/lib/cwd.d.cts +0 -11
  8. package/lib/lib/cwd.d.ts +0 -11
  9. package/lib/lib/cwd.js +0 -9
  10. package/lib/lib/dirnameDeep.cjs +0 -17
  11. package/lib/lib/dirnameDeep.d.cts +0 -9
  12. package/lib/lib/dirnameDeep.d.ts +0 -9
  13. package/lib/lib/dirnameDeep.js +0 -10
  14. package/lib/lib/hasBasename.cjs +0 -18
  15. package/lib/lib/hasBasename.d.cts +0 -8
  16. package/lib/lib/hasBasename.d.ts +0 -8
  17. package/lib/lib/hasBasename.js +0 -11
  18. package/lib/lib/hasExtname.cjs +0 -37
  19. package/lib/lib/hasExtname.d.cts +0 -15
  20. package/lib/lib/hasExtname.d.ts +0 -15
  21. package/lib/lib/hasExtname.js +0 -34
  22. package/lib/lib/hasParentDirname.cjs +0 -10
  23. package/lib/lib/hasParentDirname.d.cts +0 -6
  24. package/lib/lib/hasParentDirname.d.ts +0 -6
  25. package/lib/lib/hasParentDirname.js +0 -8
  26. package/lib/lib/isDotFile.cjs +0 -10
  27. package/lib/lib/isDotFile.d.cts +0 -8
  28. package/lib/lib/isDotFile.d.ts +0 -8
  29. package/lib/lib/isDotFile.js +0 -8
  30. package/lib/lib/isExtValid.cjs +0 -10
  31. package/lib/lib/isExtValid.d.cts +0 -13
  32. package/lib/lib/isExtValid.d.ts +0 -13
  33. package/lib/lib/isExtValid.js +0 -8
  34. package/lib/lib/isRelative.cjs +0 -16
  35. package/lib/lib/isRelative.d.cts +0 -6
  36. package/lib/lib/isRelative.d.ts +0 -6
  37. package/lib/lib/isRelative.js +0 -9
  38. package/lib/lib/isUnc.cjs +0 -10
  39. package/lib/lib/isUnc.d.cts +0 -8
  40. package/lib/lib/isUnc.d.ts +0 -8
  41. package/lib/lib/isUnc.js +0 -8
  42. package/lib/lib/isValidWin32.cjs +0 -27
  43. package/lib/lib/isValidWin32.d.cts +0 -11
  44. package/lib/lib/isValidWin32.d.ts +0 -11
  45. package/lib/lib/isValidWin32.js +0 -25
  46. package/lib/lib/prefixFilename.cjs +0 -18
  47. package/lib/lib/prefixFilename.d.cts +0 -11
  48. package/lib/lib/prefixFilename.d.ts +0 -11
  49. package/lib/lib/prefixFilename.js +0 -11
  50. package/lib/lib/root.cjs +0 -16
  51. package/lib/lib/root.d.cts +0 -6
  52. package/lib/lib/root.d.ts +0 -6
  53. package/lib/lib/root.js +0 -9
  54. package/lib/lib/suffixFilename.cjs +0 -18
  55. package/lib/lib/suffixFilename.d.cts +0 -11
  56. package/lib/lib/suffixFilename.d.ts +0 -11
  57. package/lib/lib/suffixFilename.js +0 -11
  58. package/lib/lib/toCwdRelative.cjs +0 -16
  59. package/lib/lib/toCwdRelative.d.cts +0 -8
  60. package/lib/lib/toCwdRelative.d.ts +0 -8
  61. package/lib/lib/toCwdRelative.js +0 -9
  62. package/lib/lib/toWin32.cjs +0 -10
  63. package/lib/lib/toWin32.d.cts +0 -6
  64. package/lib/lib/toWin32.d.ts +0 -6
  65. package/lib/lib/toWin32.js +0 -8
package/lib/index.cjs CHANGED
@@ -1,110 +1,174 @@
1
1
  'use strict';
2
2
 
3
- var cwd = require('./lib/cwd');
4
- var dirnameDeep = require('./lib/dirnameDeep');
5
- var hasBasename = require('./lib/hasBasename');
6
- var hasExtname = require('./lib/hasExtname');
7
- var hasParentDirname = require('./lib/hasParentDirname');
8
- var isDotFile = require('./lib/isDotFile');
9
- var isExtValid = require('./lib/isExtValid');
10
- var isRelative = require('./lib/isRelative');
11
- var isUnc = require('./lib/isUnc');
12
- var isValidWin32 = require('./lib/isValidWin32');
13
- var prefixFilename = require('./lib/prefixFilename');
14
- var root = require('./lib/root');
15
- var suffixFilename = require('./lib/suffixFilename');
16
- var toCwdRelative = require('./lib/toCwdRelative');
17
- var toWin32 = require('./lib/toWin32');
3
+ var upath4 = require('upath');
4
+ var path = require('path');
18
5
 
6
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
19
7
 
8
+ var upath4__default = /*#__PURE__*/_interopDefault(upath4);
9
+ var path__default = /*#__PURE__*/_interopDefault(path);
20
10
 
21
- Object.keys(cwd).forEach(function (k) {
22
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
23
- enumerable: true,
24
- get: function () { return cwd[k]; }
25
- });
26
- });
27
- Object.keys(dirnameDeep).forEach(function (k) {
28
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
29
- enumerable: true,
30
- get: function () { return dirnameDeep[k]; }
31
- });
32
- });
33
- Object.keys(hasBasename).forEach(function (k) {
34
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
35
- enumerable: true,
36
- get: function () { return hasBasename[k]; }
37
- });
38
- });
39
- Object.keys(hasExtname).forEach(function (k) {
40
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
41
- enumerable: true,
42
- get: function () { return hasExtname[k]; }
43
- });
44
- });
45
- Object.keys(hasParentDirname).forEach(function (k) {
46
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
47
- enumerable: true,
48
- get: function () { return hasParentDirname[k]; }
49
- });
50
- });
51
- Object.keys(isDotFile).forEach(function (k) {
52
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
53
- enumerable: true,
54
- get: function () { return isDotFile[k]; }
55
- });
56
- });
57
- Object.keys(isExtValid).forEach(function (k) {
58
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
59
- enumerable: true,
60
- get: function () { return isExtValid[k]; }
61
- });
62
- });
63
- Object.keys(isRelative).forEach(function (k) {
64
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
65
- enumerable: true,
66
- get: function () { return isRelative[k]; }
67
- });
68
- });
69
- Object.keys(isUnc).forEach(function (k) {
70
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
71
- enumerable: true,
72
- get: function () { return isUnc[k]; }
73
- });
74
- });
75
- Object.keys(isValidWin32).forEach(function (k) {
76
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
77
- enumerable: true,
78
- get: function () { return isValidWin32[k]; }
79
- });
80
- });
81
- Object.keys(prefixFilename).forEach(function (k) {
82
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
83
- enumerable: true,
84
- get: function () { return prefixFilename[k]; }
85
- });
86
- });
87
- Object.keys(root).forEach(function (k) {
88
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
89
- enumerable: true,
90
- get: function () { return root[k]; }
91
- });
92
- });
93
- Object.keys(suffixFilename).forEach(function (k) {
94
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
95
- enumerable: true,
96
- get: function () { return suffixFilename[k]; }
97
- });
98
- });
99
- Object.keys(toCwdRelative).forEach(function (k) {
100
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
101
- enumerable: true,
102
- get: function () { return toCwdRelative[k]; }
103
- });
104
- });
105
- Object.keys(toWin32).forEach(function (k) {
106
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
107
- enumerable: true,
108
- get: function () { return toWin32[k]; }
109
- });
110
- });
11
+ var __defProp = Object.defineProperty;
12
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
13
+ function cwd(...p) {
14
+ return upath4__default.default.joinSafe(process.cwd(), ...p);
15
+ }
16
+ __name(cwd, "cwd");
17
+ function dirnameDeep(p, depth) {
18
+ const parent = upath4__default.default.dirname(p);
19
+ return depth && depth > 1 ? dirnameDeep(parent, depth - 1) : parent;
20
+ }
21
+ __name(dirnameDeep, "dirnameDeep");
22
+ function hasBasename(tsFilepath, basenames) {
23
+ return [
24
+ basenames
25
+ ].flat(2).includes(upath4__default.default.basename(tsFilepath));
26
+ }
27
+ __name(hasBasename, "hasBasename");
28
+
29
+ // ../fn/src/setNameAndLength.ts
30
+ function setNameAndLength(source, target, lengthDelta = 0) {
31
+ return Object.defineProperties(target, {
32
+ name: {
33
+ configurable: true,
34
+ value: source.name
35
+ },
36
+ length: {
37
+ configurable: true,
38
+ value: source.length + lengthDelta
39
+ }
40
+ });
41
+ }
42
+ __name(setNameAndLength, "setNameAndLength");
43
+
44
+ // ../fn/src/bindArg.ts
45
+ function bindArg(fn, boundArgIndex, boundArgValue) {
46
+ return setNameAndLength(fn, (...args) => {
47
+ return fn(...args.slice(0, boundArgIndex), boundArgValue, ...args.slice(boundArgIndex));
48
+ }, -1);
49
+ }
50
+ __name(bindArg, "bindArg");
51
+
52
+ // src/lib/hasExtname.ts
53
+ function hasExtname(tsFilepath, extnames) {
54
+ return new RegExp(`[.](${[
55
+ extnames
56
+ ].flat(2).join("|")})$`).test(tsFilepath);
57
+ }
58
+ __name(hasExtname, "hasExtname");
59
+ hasExtname.js = bindArg(hasExtname, 1, [
60
+ "js",
61
+ "mjs",
62
+ "jsx",
63
+ "cjs"
64
+ ]);
65
+ hasExtname.json = bindArg(hasExtname, 1, [
66
+ "json",
67
+ "jsonc"
68
+ ]);
69
+ hasExtname.yaml = bindArg(hasExtname, 1, [
70
+ "yaml",
71
+ "yml"
72
+ ]);
73
+ hasExtname.markdown = bindArg(hasExtname, 1, [
74
+ "md",
75
+ "markdown"
76
+ ]);
77
+ hasExtname.ts = bindArg(hasExtname, 1, [
78
+ "ts",
79
+ "mts",
80
+ "tsx"
81
+ ]);
82
+
83
+ // src/lib/hasParentDirname.ts
84
+ function hasParentDirname(fspath, name) {
85
+ return new RegExp(`(^|[/\\\\])${name}[/\\\\]`).test(fspath);
86
+ }
87
+ __name(hasParentDirname, "hasParentDirname");
88
+
89
+ // src/lib/isDotFile.ts
90
+ function isDotFile(filepath) {
91
+ return /(?:^|[/\\])(\.(?!\.)[^/\\]+)$/.test(filepath);
92
+ }
93
+ __name(isDotFile, "isDotFile");
94
+
95
+ // src/lib/isExtValid.ts
96
+ function isExtValid(ext) {
97
+ return !!ext && ext !== "." && !/["*:<>?|]/.test(ext);
98
+ }
99
+ __name(isExtValid, "isExtValid");
100
+ function isRelative(p) {
101
+ return !path__default.default.isAbsolute(p);
102
+ }
103
+ __name(isRelative, "isRelative");
104
+
105
+ // src/lib/isUnc.ts
106
+ function isUnc(filepath) {
107
+ return /^[/\\]{2,}[^/\\]+[/\\]+[^/\\]+/.test(filepath);
108
+ }
109
+ __name(isUnc, "isUnc");
110
+
111
+ // src/lib/isValidWin32.ts
112
+ function isValidWin32(path2, options) {
113
+ if (path2.length === 0) {
114
+ return false;
115
+ }
116
+ if (path2.includes("/") && path2.includes("\\")) {
117
+ return false;
118
+ }
119
+ const maxLength = (options && options.extendedMaxLength ? 32767 : 260) - 12;
120
+ if (path2.length > maxLength) {
121
+ return false;
122
+ }
123
+ const noDriveLetter = /^\w:(\\|\/)/g.test(path2) ? path2.substring(2) : path2;
124
+ if (/["*:<>?|]/g.test(noDriveLetter)) {
125
+ return false;
126
+ }
127
+ if (/(\\|\/)(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])((\\|\/)|$)/g.test(path2)) {
128
+ return false;
129
+ }
130
+ return true;
131
+ }
132
+ __name(isValidWin32, "isValidWin32");
133
+ function prefixFilename(filePath, prefix) {
134
+ const ext = upath4__default.default.extname(filePath);
135
+ const fileNameWithoutExt = upath4__default.default.basename(filePath, ext);
136
+ return upath4__default.default.joinSafe(upath4__default.default.dirname(filePath), prefix + fileNameWithoutExt + ext);
137
+ }
138
+ __name(prefixFilename, "prefixFilename");
139
+ function root(p) {
140
+ return upath4__default.default.parse(p).root;
141
+ }
142
+ __name(root, "root");
143
+ function suffixFilename(filePath, suffix) {
144
+ const split = upath4__default.default.basename(filePath).split(".");
145
+ split[0] += suffix;
146
+ return upath4__default.default.joinSafe(upath4__default.default.dirname(filePath), split.join("."));
147
+ }
148
+ __name(suffixFilename, "suffixFilename");
149
+ function toCwdRelative(p) {
150
+ return upath4__default.default.relative(process.cwd(), p);
151
+ }
152
+ __name(toCwdRelative, "toCwdRelative");
153
+
154
+ // src/lib/toWin32.ts
155
+ function toWin32(p) {
156
+ return p.replaceAll("/", "\\");
157
+ }
158
+ __name(toWin32, "toWin32");
159
+
160
+ exports.cwd = cwd;
161
+ exports.dirnameDeep = dirnameDeep;
162
+ exports.hasBasename = hasBasename;
163
+ exports.hasExtname = hasExtname;
164
+ exports.hasParentDirname = hasParentDirname;
165
+ exports.isDotFile = isDotFile;
166
+ exports.isExtValid = isExtValid;
167
+ exports.isRelative = isRelative;
168
+ exports.isUnc = isUnc;
169
+ exports.isValidWin32 = isValidWin32;
170
+ exports.prefixFilename = prefixFilename;
171
+ exports.root = root;
172
+ exports.suffixFilename = suffixFilename;
173
+ exports.toCwdRelative = toCwdRelative;
174
+ exports.toWin32 = toWin32;
package/lib/index.d.cts CHANGED
@@ -1,16 +1,149 @@
1
- export { cwd } from './lib/cwd.cjs';
2
- export { dirnameDeep } from './lib/dirnameDeep.cjs';
3
- export { hasBasename } from './lib/hasBasename.cjs';
4
- export { hasExtname } from './lib/hasExtname.cjs';
5
- export { hasParentDirname } from './lib/hasParentDirname.cjs';
6
- export { isDotFile } from './lib/isDotFile.cjs';
7
- export { isExtValid } from './lib/isExtValid.cjs';
8
- export { isRelative } from './lib/isRelative.cjs';
9
- export { isUnc } from './lib/isUnc.cjs';
10
- export { isValidWin32 } from './lib/isValidWin32.cjs';
11
- export { prefixFilename } from './lib/prefixFilename.cjs';
12
- export { root } from './lib/root.cjs';
13
- export { suffixFilename } from './lib/suffixFilename.cjs';
14
- export { toCwdRelative } from './lib/toCwdRelative.cjs';
15
- export { toWin32 } from './lib/toWin32.cjs';
16
- import './arrayable.d-1twOP8Y1.cjs';
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
- export { cwd } from './lib/cwd.js';
2
- export { dirnameDeep } from './lib/dirnameDeep.js';
3
- export { hasBasename } from './lib/hasBasename.js';
4
- export { hasExtname } from './lib/hasExtname.js';
5
- export { hasParentDirname } from './lib/hasParentDirname.js';
6
- export { isDotFile } from './lib/isDotFile.js';
7
- export { isExtValid } from './lib/isExtValid.js';
8
- export { isRelative } from './lib/isRelative.js';
9
- export { isUnc } from './lib/isUnc.js';
10
- export { isValidWin32 } from './lib/isValidWin32.js';
11
- export { prefixFilename } from './lib/prefixFilename.js';
12
- export { root } from './lib/root.js';
13
- export { suffixFilename } from './lib/suffixFilename.js';
14
- export { toCwdRelative } from './lib/toCwdRelative.js';
15
- export { toWin32 } from './lib/toWin32.js';
16
- import './arrayable.d-1twOP8Y1.js';
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 };