@zokugun/fs-path 0.1.0 → 0.2.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.
- package/README.md +11 -16
- package/lib/cjs/absolute.d.cts +2 -2
- package/lib/cjs/index.cjs +10 -8
- package/lib/cjs/index.d.cts +8 -7
- package/lib/cjs/is-in-dir.d.cts +2 -2
- package/lib/cjs/is-in-dirs.d.cts +2 -2
- package/lib/cjs/is-safe-path.d.cts +2 -2
- package/lib/cjs/is-safe-segment.d.cts +2 -2
- package/lib/cjs/join.d.cts +2 -2
- package/lib/cjs/leaf-ext.cjs +31 -0
- package/lib/cjs/leaf-ext.d.cts +3 -0
- package/lib/cjs/leaf-name.cjs +33 -0
- package/lib/cjs/leaf-name.d.cts +3 -0
- package/lib/cjs/parent-name.cjs +14 -0
- package/lib/cjs/parent-name.d.cts +3 -0
- package/lib/cjs/{parent.cjs → parent-path.cjs} +4 -4
- package/lib/cjs/parent-path.d.cts +3 -0
- package/lib/cjs/platform.cjs +10 -7
- package/lib/cjs/resolve.d.cts +2 -2
- package/lib/cjs/sanitize.d.cts +2 -2
- package/lib/cjs/types.d.cts +6 -6
- package/lib/cjs/untildify.d.cts +2 -2
- package/lib/esm/absolute.d.mts +2 -2
- package/lib/esm/index.d.mts +8 -7
- package/lib/esm/index.mjs +6 -5
- package/lib/esm/is-in-dir.d.mts +2 -2
- package/lib/esm/is-in-dirs.d.mts +2 -2
- package/lib/esm/is-safe-path.d.mts +2 -2
- package/lib/esm/is-safe-segment.d.mts +2 -2
- package/lib/esm/join.d.mts +2 -2
- package/lib/esm/leaf-ext.d.mts +3 -0
- package/lib/esm/leaf-ext.mjs +28 -0
- package/lib/esm/leaf-name.d.mts +3 -0
- package/lib/esm/leaf-name.mjs +30 -0
- package/lib/esm/parent-name.d.mts +3 -0
- package/lib/esm/parent-name.mjs +11 -0
- package/lib/esm/parent-path.d.mts +3 -0
- package/lib/esm/{parent.mjs → parent-path.mjs} +3 -3
- package/lib/esm/platform.mjs +14 -11
- package/lib/esm/resolve.d.mts +2 -2
- package/lib/esm/sanitize.d.mts +2 -2
- package/lib/esm/types.d.mts +6 -6
- package/lib/esm/untildify.d.mts +2 -2
- package/package.json +1 -1
- package/lib/cjs/dir.cjs +0 -6
- package/lib/cjs/dir.d.cts +0 -3
- package/lib/cjs/parent.d.cts +0 -3
- package/lib/esm/dir.d.mts +0 -3
- package/lib/esm/dir.mjs +0 -3
- package/lib/esm/parent.d.mts +0 -3
package/README.md
CHANGED
|
@@ -44,19 +44,19 @@ This example expands the current user's home directory, joins paths safely, and
|
|
|
44
44
|
API reference
|
|
45
45
|
-------------
|
|
46
46
|
|
|
47
|
-
- `absolute(...paths: string[]): string`:
|
|
48
|
-
- `dir(path: string): string`: Return the directory portion of `path` (empty string when the result is `.`).
|
|
49
|
-
- `extension(path: string): string`: Return the file extension (same as `path.extname`).
|
|
47
|
+
- `absolute(...paths: string[]): string`: Returns a normalized absolute path.
|
|
50
48
|
- `isAbsolute(path: string): boolean`: Return `true` when `path` is absolute for the current platform.
|
|
51
49
|
- `isInDir(path: string, parent: string): boolean`: Return `true` when `path` is equal to or contained within `parent`.
|
|
52
50
|
- `isInDirs(path: string, parents: string[]): boolean`: Return `true` when `path` is equal to or contained within in one of the `parents`.
|
|
53
51
|
- `isSafePath(path: string, options?): boolean`: Return `true` when `path` is considered safe for use (guards against suspicious segments such as `..` when appropriate for the platform).
|
|
54
52
|
- `isSafeSegment(segment: string, target?: Target | 'auto'): boolean`: Return `true` when a single path segment is safe (doesn't contain path separators or traversal sequences).
|
|
55
|
-
- `join(...paths: string[]): string`: Join path segments
|
|
56
|
-
- `
|
|
53
|
+
- `join(...paths: string[]): string`: Join path segments.
|
|
54
|
+
- `leafExt(path: string, length?: number): string`: Return the extensions.
|
|
55
|
+
- `leafName(path: string, extension?: number | string): string`: Return the basename of `path` with/without the extensions.
|
|
57
56
|
- `matchesGlob?(path: string, pattern: string): boolean`: Optional platform-provided glob matcher when available.
|
|
58
57
|
- `normalize(path: string): string`: Normalize the path (same as `path.normalize`).
|
|
59
|
-
- `
|
|
58
|
+
- `parentName(path: string): string`: Return the parent name of `path`.
|
|
59
|
+
- `parentPath(path: string): string`: Return the parent directory of `path`.
|
|
60
60
|
- `relative(from: string, to: string): string`: Compute the relative path from `from` to `to`.
|
|
61
61
|
- `resolve(...paths: string[]): string`: Resolve path segments to an absolute path. Supports tilde expansion:
|
|
62
62
|
- `~` expands to the current user's home directory.
|
|
@@ -73,8 +73,6 @@ export type PlatformPath = {
|
|
|
73
73
|
readonly posix: PlatformPath;
|
|
74
74
|
readonly win32: PlatformPath;
|
|
75
75
|
absolute: (...paths: string[]) => string;
|
|
76
|
-
dir: (path: string) => string;
|
|
77
|
-
extension: (path: string) => string;
|
|
78
76
|
isAbsolute: (path: string) => boolean;
|
|
79
77
|
isInDir(path: string, parent: string): boolean;
|
|
80
78
|
isInDirs(path: string, parents: string[]): boolean;
|
|
@@ -85,10 +83,12 @@ export type PlatformPath = {
|
|
|
85
83
|
}) => boolean;
|
|
86
84
|
isSafeSegment: (segment: string, target?: Target | 'auto') => boolean;
|
|
87
85
|
join: (...paths: string[]) => string;
|
|
88
|
-
|
|
86
|
+
leafExt: (path: string, length?: number) => string;
|
|
87
|
+
leafName: (path: string, extension?: number | string) => string;
|
|
89
88
|
matchesGlob?: (path: string, pattern: string) => boolean;
|
|
90
89
|
normalize: (path: string) => string;
|
|
91
|
-
|
|
90
|
+
parentName: (path: string) => string;
|
|
91
|
+
parentPath: (path: string) => string;
|
|
92
92
|
relative: (from: string, to: string) => string;
|
|
93
93
|
resolve: (...paths: string[]) => string;
|
|
94
94
|
sanitize(path: string, options?: {
|
|
@@ -106,15 +106,10 @@ Comparison with Node's `path`
|
|
|
106
106
|
|
|
107
107
|
This library intentionally mirrors many of Node's `path` APIs but provides small ergonomic differences and extra features where useful:
|
|
108
108
|
|
|
109
|
-
- `absolute(...paths)`: resolves using the runtime platform and always returns a normalized absolute path.
|
|
110
|
-
- `dir(path)`: returns `path.parse(path).dir` (similar to `path.dirname`, kept for API symmetry).
|
|
111
|
-
- `extension(path)`: alias of `path.extname`.
|
|
112
109
|
- `join(...paths)`: wraps `path.join`. Returns `''` instead of `.` when the joined result is the current directory.
|
|
113
110
|
- `isAbsolute(path)`, `normalize(path)`, `relative(from, to)`: direct mappings to `path.isAbsolute`, `path.normalize`, and `path.relative` respectively.
|
|
114
|
-
- `
|
|
115
|
-
- `parent(file)`: wraps `path.dirname`. Returns `''` instead of `.` for consistency with `join`.
|
|
111
|
+
- `parentPath(file)`: wraps `path.dirname`. Returns `''` instead of `.` for consistency with `join`.
|
|
116
112
|
- `resolve(...paths)`: wraps `path.resolve` but adds tilde expansion (`~` and `~username`) before resolving.
|
|
117
|
-
- `untildify(path)`: purely handles `~` expansion; no direct equivalent in Node core.
|
|
118
113
|
- `delimiter`: same value as `path.delimiter` on the current platform.
|
|
119
114
|
- `separator`: same value as `path.sep` on the current platform.
|
|
120
115
|
|
package/lib/cjs/absolute.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type opath from 'node:path';
|
|
2
2
|
import { type PlatformPath } from './types.cjs';
|
|
3
|
-
export declare function absolute(nodePath:
|
|
3
|
+
export declare function absolute(nodePath: opath.PlatformPath, localPath: PlatformPath): (...paths: string[]) => string;
|
package/lib/cjs/index.cjs
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.win32 = exports.untildify = exports.separator = exports.sanitize = exports.resolve = exports.relative = exports.posix = exports.isSafeSegment = exports.isSafePath = exports.isInDirs = exports.isInDir = exports.
|
|
3
|
+
exports.win32 = exports.untildify = exports.separator = exports.sanitize = exports.resolve = exports.relative = exports.posix = exports.isSafeSegment = exports.isSafePath = exports.isInDirs = exports.isInDir = exports.parentPath = exports.parentName = exports.normalize = exports.matchesGlob = exports.leafName = exports.leafExt = exports.join = exports.isAbsolute = exports.delimiter = exports.absolute = void 0;
|
|
4
4
|
const platform_js_1 = require("./platform.cjs");
|
|
5
|
-
const { absolute, delimiter,
|
|
5
|
+
const { absolute, delimiter, isAbsolute, join, leafExt, leafName, matchesGlob, normalize, parentName, parentPath, isInDir, isInDirs, isSafePath, isSafeSegment, posix, relative, resolve, sanitize, separator, untildify, win32, } = platform_js_1.DEFAULT_PLATFORM;
|
|
6
6
|
exports.absolute = absolute;
|
|
7
7
|
exports.delimiter = delimiter;
|
|
8
|
-
exports.extension = extension;
|
|
9
8
|
exports.isAbsolute = isAbsolute;
|
|
10
9
|
exports.join = join;
|
|
11
|
-
exports.
|
|
10
|
+
exports.leafExt = leafExt;
|
|
11
|
+
exports.leafName = leafName;
|
|
12
12
|
exports.matchesGlob = matchesGlob;
|
|
13
13
|
exports.normalize = normalize;
|
|
14
|
-
exports.
|
|
14
|
+
exports.parentName = parentName;
|
|
15
|
+
exports.parentPath = parentPath;
|
|
15
16
|
exports.isInDir = isInDir;
|
|
16
17
|
exports.isInDirs = isInDirs;
|
|
17
18
|
exports.isSafePath = isSafePath;
|
|
@@ -29,13 +30,14 @@ exports.default = {
|
|
|
29
30
|
PlatformPath: undefined,
|
|
30
31
|
absolute,
|
|
31
32
|
delimiter,
|
|
32
|
-
extension,
|
|
33
33
|
isAbsolute,
|
|
34
34
|
join,
|
|
35
|
-
|
|
35
|
+
leafExt,
|
|
36
|
+
leafName,
|
|
36
37
|
matchesGlob,
|
|
37
38
|
normalize,
|
|
38
|
-
|
|
39
|
+
parentName,
|
|
40
|
+
parentPath,
|
|
39
41
|
isInDir,
|
|
40
42
|
isInDirs,
|
|
41
43
|
isSafePath,
|
package/lib/cjs/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type PlatformPath } from './types.cjs';
|
|
2
|
-
declare const absolute: (...paths: string[]) => string, delimiter: ";" | ":",
|
|
2
|
+
declare const absolute: (...paths: string[]) => string, delimiter: ";" | ":", isAbsolute: (path: string) => boolean, join: (...paths: string[]) => string, leafExt: (path: string, length?: number) => string, leafName: (path: string, extension?: number | string) => string, matchesGlob: ((path: string, pattern: string) => boolean) | undefined, normalize: (path: string) => string, parentName: (path: string) => string, parentPath: (path: string) => string, isInDir: (path: string, dir: string) => boolean, isInDirs: (path: string, directories: string[]) => boolean, isSafePath: (path: string, options?: {
|
|
3
3
|
parent?: string | null;
|
|
4
4
|
parents?: string | string[] | null;
|
|
5
5
|
target?: Target | "auto";
|
|
@@ -9,22 +9,23 @@ declare const absolute: (...paths: string[]) => string, delimiter: ";" | ":", ex
|
|
|
9
9
|
replacement?: string | null;
|
|
10
10
|
target?: Target | "auto";
|
|
11
11
|
}) => DResult<string>, separator: "\\" | "/", untildify: (path: string) => string, win32: PlatformPath;
|
|
12
|
-
export { type PlatformPath, absolute, delimiter,
|
|
12
|
+
export { type PlatformPath, absolute, delimiter, isAbsolute, join, leafExt, leafName, matchesGlob, normalize, parentName, parentPath, isInDir, isInDirs, isSafePath, isSafeSegment, posix, relative, resolve, sanitize, separator, untildify, win32, };
|
|
13
13
|
import { type Target } from "@zokugun/fs-path-sanitize";
|
|
14
14
|
import { type DResult } from "@zokugun/xtry/result";
|
|
15
15
|
declare const _default: {
|
|
16
16
|
PlatformPath: PlatformPath;
|
|
17
17
|
absolute: (...paths: string[]) => string;
|
|
18
18
|
delimiter: ";" | ":";
|
|
19
|
-
extension: (path: string) => string;
|
|
20
19
|
isAbsolute: (path: string) => boolean;
|
|
21
20
|
join: (...paths: string[]) => string;
|
|
22
|
-
|
|
21
|
+
leafExt: (path: string, length?: number) => string;
|
|
22
|
+
leafName: (path: string, extension?: number | string) => string;
|
|
23
23
|
matchesGlob: ((path: string, pattern: string) => boolean) | undefined;
|
|
24
24
|
normalize: (path: string) => string;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
parentName: (path: string) => string;
|
|
26
|
+
parentPath: (path: string) => string;
|
|
27
|
+
isInDir: (path: string, dir: string) => boolean;
|
|
28
|
+
isInDirs: (path: string, directories: string[]) => boolean;
|
|
28
29
|
isSafePath: (path: string, options?: {
|
|
29
30
|
parent?: string | null;
|
|
30
31
|
parents?: string | string[] | null;
|
package/lib/cjs/is-in-dir.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type opath from 'node:path';
|
|
2
2
|
import { type PlatformPath } from './types.cjs';
|
|
3
|
-
export declare function isInDir(_nodePath:
|
|
3
|
+
export declare function isInDir(_nodePath: opath.PlatformPath, localPath: PlatformPath): (path: string, parent: string) => boolean;
|
package/lib/cjs/is-in-dirs.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type opath from 'node:path';
|
|
2
2
|
import { type PlatformPath } from './types.cjs';
|
|
3
|
-
export declare function isInDirs(_nodePath:
|
|
3
|
+
export declare function isInDirs(_nodePath: opath.PlatformPath, localPath: PlatformPath): (path: string, parents: string[]) => boolean;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type opath from 'node:path';
|
|
2
2
|
import { type Target } from '@zokugun/fs-path-sanitize';
|
|
3
3
|
import { type PlatformPath } from './types.cjs';
|
|
4
|
-
export declare function isSafePath(_nodePath:
|
|
4
|
+
export declare function isSafePath(_nodePath: opath.PlatformPath, localPath: PlatformPath): (path: string, options?: {
|
|
5
5
|
parent?: string | null;
|
|
6
6
|
parents?: string | string[] | null;
|
|
7
7
|
target?: Target | 'auto';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type opath from 'node:path';
|
|
2
2
|
import { type Target } from '@zokugun/fs-path-sanitize';
|
|
3
3
|
import { type PlatformPath } from './types.cjs';
|
|
4
|
-
export declare function isSafeSegment(_nodePath:
|
|
4
|
+
export declare function isSafeSegment(_nodePath: opath.PlatformPath, localPath: PlatformPath): (segment: string, target?: Target | 'auto') => boolean;
|
package/lib/cjs/join.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type opath from 'path';
|
|
2
2
|
import { type PlatformPath } from './types.cjs';
|
|
3
|
-
export declare function join(nodePath:
|
|
3
|
+
export declare function join(nodePath: opath.PlatformPath, _localPath: PlatformPath): (...paths: string[]) => string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.leafExt = leafExt;
|
|
4
|
+
const is_it_type_1 = require("@zokugun/is-it-type");
|
|
5
|
+
// eslint-disable-next-line unicorn/prevent-abbreviations
|
|
6
|
+
function leafExt(nodePath, _localPath) {
|
|
7
|
+
return (path, length) => {
|
|
8
|
+
if ((0, is_it_type_1.isUndefined)(length)) {
|
|
9
|
+
return nodePath.extname(path);
|
|
10
|
+
}
|
|
11
|
+
const name = nodePath.basename(path);
|
|
12
|
+
if (name.length === 0 || name.startsWith('.')) {
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
if (length <= 0) {
|
|
16
|
+
const index = name.indexOf('.');
|
|
17
|
+
return index === -1 ? '' : name.slice(index);
|
|
18
|
+
}
|
|
19
|
+
else if (length === 1) {
|
|
20
|
+
const index = name.lastIndexOf('.');
|
|
21
|
+
return index === -1 ? '' : name.slice(index);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const parts = name.split('.');
|
|
25
|
+
if (parts.length === 1) {
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
return '.' + parts.slice(parts.length <= length ? 1 : -length).join('.');
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.leafName = leafName;
|
|
4
|
+
const is_it_type_1 = require("@zokugun/is-it-type");
|
|
5
|
+
function leafName(nodePath, _localPath) {
|
|
6
|
+
return (path, extension) => {
|
|
7
|
+
if ((0, is_it_type_1.isUndefined)(extension)) {
|
|
8
|
+
return nodePath.basename(path);
|
|
9
|
+
}
|
|
10
|
+
if ((0, is_it_type_1.isString)(extension)) {
|
|
11
|
+
return nodePath.basename(path, extension);
|
|
12
|
+
}
|
|
13
|
+
const name = nodePath.basename(path);
|
|
14
|
+
if (name.length === 0 || name.startsWith('.')) {
|
|
15
|
+
return name;
|
|
16
|
+
}
|
|
17
|
+
if (extension <= 0) {
|
|
18
|
+
const index = name.indexOf('.');
|
|
19
|
+
return index === -1 ? name : name.slice(0, index);
|
|
20
|
+
}
|
|
21
|
+
else if (extension === 1) {
|
|
22
|
+
const index = name.lastIndexOf('.');
|
|
23
|
+
return index === -1 ? name : name.slice(0, index);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
const parts = name.split('.');
|
|
27
|
+
if (parts.length <= extension) {
|
|
28
|
+
return parts[0];
|
|
29
|
+
}
|
|
30
|
+
return parts.slice(0, -extension).join('.');
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parentName = parentName;
|
|
4
|
+
function parentName(nodePath, _localPath) {
|
|
5
|
+
return (path) => {
|
|
6
|
+
const parent = nodePath.dirname(path);
|
|
7
|
+
if (parent === '.') {
|
|
8
|
+
return '';
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
return nodePath.basename(parent);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
function
|
|
5
|
-
return (
|
|
6
|
-
const parent = nodePath.dirname(
|
|
3
|
+
exports.parentPath = parentPath;
|
|
4
|
+
function parentPath(nodePath, _localPath) {
|
|
5
|
+
return (path) => {
|
|
6
|
+
const parent = nodePath.dirname(path);
|
|
7
7
|
if (parent === '.') {
|
|
8
8
|
return '';
|
|
9
9
|
}
|
package/lib/cjs/platform.cjs
CHANGED
|
@@ -6,37 +6,40 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.DEFAULT_PLATFORM = void 0;
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
8
|
const absolute_js_1 = require("./absolute.cjs");
|
|
9
|
-
const dir_js_1 = require("./dir.cjs");
|
|
10
9
|
const is_in_dir_js_1 = require("./is-in-dir.cjs");
|
|
11
10
|
// eslint-disable-next-line unicorn/prevent-abbreviations
|
|
12
11
|
const is_in_dirs_js_1 = require("./is-in-dirs.cjs");
|
|
13
12
|
const is_safe_path_js_1 = require("./is-safe-path.cjs");
|
|
14
13
|
const is_safe_segment_js_1 = require("./is-safe-segment.cjs");
|
|
15
14
|
const join_js_1 = require("./join.cjs");
|
|
16
|
-
|
|
15
|
+
// eslint-disable-next-line unicorn/prevent-abbreviations
|
|
16
|
+
const leaf_ext_js_1 = require("./leaf-ext.cjs");
|
|
17
|
+
const leaf_name_js_1 = require("./leaf-name.cjs");
|
|
18
|
+
const parent_name_js_1 = require("./parent-name.cjs");
|
|
19
|
+
const parent_path_js_1 = require("./parent-path.cjs");
|
|
17
20
|
const resolve_js_1 = require("./resolve.cjs");
|
|
18
21
|
const sanitize_js_1 = require("./sanitize.cjs");
|
|
19
22
|
const untildify_js_1 = require("./untildify.cjs");
|
|
20
23
|
function buildPlatform(path) {
|
|
21
|
-
const {
|
|
24
|
+
const { delimiter, isAbsolute, normalize, relative, sep: separator, } = path;
|
|
22
25
|
const result = {
|
|
23
26
|
delimiter,
|
|
24
27
|
separator,
|
|
25
|
-
extension,
|
|
26
28
|
isAbsolute,
|
|
27
|
-
leaf,
|
|
28
29
|
matchesGlob: path.matchesGlob ?? undefined,
|
|
29
30
|
normalize,
|
|
30
31
|
relative,
|
|
31
32
|
};
|
|
32
33
|
result.absolute = (0, absolute_js_1.absolute)(path, result);
|
|
33
|
-
result.dir = (0, dir_js_1.dir)(path, result);
|
|
34
34
|
result.isInDir = (0, is_in_dir_js_1.isInDir)(path, result);
|
|
35
35
|
result.isInDirs = (0, is_in_dirs_js_1.isInDirs)(path, result);
|
|
36
36
|
result.isSafePath = (0, is_safe_path_js_1.isSafePath)(path, result);
|
|
37
37
|
result.isSafeSegment = (0, is_safe_segment_js_1.isSafeSegment)(path, result);
|
|
38
38
|
result.join = (0, join_js_1.join)(path, result);
|
|
39
|
-
result.
|
|
39
|
+
result.leafExt = (0, leaf_ext_js_1.leafExt)(path, result);
|
|
40
|
+
result.leafName = (0, leaf_name_js_1.leafName)(path, result);
|
|
41
|
+
result.parentName = (0, parent_name_js_1.parentName)(path, result);
|
|
42
|
+
result.parentPath = (0, parent_path_js_1.parentPath)(path, result);
|
|
40
43
|
result.resolve = (0, resolve_js_1.resolve)(path, result);
|
|
41
44
|
result.sanitize = (0, sanitize_js_1.sanitize)(path, result);
|
|
42
45
|
result.untildify = (0, untildify_js_1.untildify)(path, result);
|
package/lib/cjs/resolve.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type opath from 'node:path';
|
|
2
2
|
import { type PlatformPath } from './types.cjs';
|
|
3
|
-
export declare function resolve(nodePath:
|
|
3
|
+
export declare function resolve(nodePath: opath.PlatformPath, _localPath: PlatformPath): (...paths: string[]) => string;
|
package/lib/cjs/sanitize.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type opath from 'node:path';
|
|
2
2
|
import { type Target } from '@zokugun/fs-path-sanitize';
|
|
3
3
|
import { type DResult } from '@zokugun/xtry';
|
|
4
4
|
import { type PlatformPath } from './types.cjs';
|
|
5
|
-
export declare function sanitize(_nodePath:
|
|
5
|
+
export declare function sanitize(_nodePath: opath.PlatformPath, localPath: PlatformPath): (path: string, options?: {
|
|
6
6
|
parent?: string | null;
|
|
7
7
|
parents?: string | string[] | null;
|
|
8
8
|
replacement?: string | null;
|
package/lib/cjs/types.d.cts
CHANGED
|
@@ -6,11 +6,9 @@ export type PlatformPath = {
|
|
|
6
6
|
readonly posix: PlatformPath;
|
|
7
7
|
readonly win32: PlatformPath;
|
|
8
8
|
absolute: (...paths: string[]) => string;
|
|
9
|
-
dir: (path: string) => string;
|
|
10
|
-
extension: (path: string) => string;
|
|
11
9
|
isAbsolute: (path: string) => boolean;
|
|
12
|
-
isInDir: (
|
|
13
|
-
isInDirs: (
|
|
10
|
+
isInDir: (path: string, dir: string) => boolean;
|
|
11
|
+
isInDirs: (path: string, directories: string[]) => boolean;
|
|
14
12
|
isSafePath: (path: string, options?: {
|
|
15
13
|
parent?: string | null;
|
|
16
14
|
parents?: string | string[] | null;
|
|
@@ -18,10 +16,12 @@ export type PlatformPath = {
|
|
|
18
16
|
}) => boolean;
|
|
19
17
|
isSafeSegment: (segment: string, target?: Target | 'auto') => boolean;
|
|
20
18
|
join: (...paths: string[]) => string;
|
|
21
|
-
|
|
19
|
+
leafExt: (path: string, length?: number) => string;
|
|
20
|
+
leafName: (path: string, extension?: number | string) => string;
|
|
22
21
|
matchesGlob?: (path: string, pattern: string) => boolean;
|
|
23
22
|
normalize: (path: string) => string;
|
|
24
|
-
|
|
23
|
+
parentName: (path: string) => string;
|
|
24
|
+
parentPath: (path: string) => string;
|
|
25
25
|
relative: (from: string, to: string) => string;
|
|
26
26
|
resolve: (...paths: string[]) => string;
|
|
27
27
|
sanitize: (path: string, options?: {
|
package/lib/cjs/untildify.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type opath from 'node:path';
|
|
2
2
|
import { type PlatformPath } from './types.cjs';
|
|
3
|
-
export declare function untildify(_nodePath:
|
|
3
|
+
export declare function untildify(_nodePath: opath.PlatformPath, _localPath: PlatformPath): (path: string) => string;
|
package/lib/esm/absolute.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type opath from 'node:path';
|
|
2
2
|
import { type PlatformPath } from './types.mjs';
|
|
3
|
-
export declare function absolute(nodePath:
|
|
3
|
+
export declare function absolute(nodePath: opath.PlatformPath, localPath: PlatformPath): (...paths: string[]) => string;
|
package/lib/esm/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type PlatformPath } from './types.mjs';
|
|
2
|
-
declare const absolute: (...paths: string[]) => string, delimiter: ";" | ":",
|
|
2
|
+
declare const absolute: (...paths: string[]) => string, delimiter: ";" | ":", isAbsolute: (path: string) => boolean, join: (...paths: string[]) => string, leafExt: (path: string, length?: number) => string, leafName: (path: string, extension?: number | string) => string, matchesGlob: ((path: string, pattern: string) => boolean) | undefined, normalize: (path: string) => string, parentName: (path: string) => string, parentPath: (path: string) => string, isInDir: (path: string, dir: string) => boolean, isInDirs: (path: string, directories: string[]) => boolean, isSafePath: (path: string, options?: {
|
|
3
3
|
parent?: string | null;
|
|
4
4
|
parents?: string | string[] | null;
|
|
5
5
|
target?: Target | "auto";
|
|
@@ -9,22 +9,23 @@ declare const absolute: (...paths: string[]) => string, delimiter: ";" | ":", ex
|
|
|
9
9
|
replacement?: string | null;
|
|
10
10
|
target?: Target | "auto";
|
|
11
11
|
}) => DResult<string>, separator: "\\" | "/", untildify: (path: string) => string, win32: PlatformPath;
|
|
12
|
-
export { type PlatformPath, absolute, delimiter,
|
|
12
|
+
export { type PlatformPath, absolute, delimiter, isAbsolute, join, leafExt, leafName, matchesGlob, normalize, parentName, parentPath, isInDir, isInDirs, isSafePath, isSafeSegment, posix, relative, resolve, sanitize, separator, untildify, win32, };
|
|
13
13
|
import { type Target } from "@zokugun/fs-path-sanitize";
|
|
14
14
|
import { type DResult } from "@zokugun/xtry";
|
|
15
15
|
declare const _default: {
|
|
16
16
|
PlatformPath: PlatformPath;
|
|
17
17
|
absolute: (...paths: string[]) => string;
|
|
18
18
|
delimiter: ";" | ":";
|
|
19
|
-
extension: (path: string) => string;
|
|
20
19
|
isAbsolute: (path: string) => boolean;
|
|
21
20
|
join: (...paths: string[]) => string;
|
|
22
|
-
|
|
21
|
+
leafExt: (path: string, length?: number) => string;
|
|
22
|
+
leafName: (path: string, extension?: number | string) => string;
|
|
23
23
|
matchesGlob: ((path: string, pattern: string) => boolean) | undefined;
|
|
24
24
|
normalize: (path: string) => string;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
parentName: (path: string) => string;
|
|
26
|
+
parentPath: (path: string) => string;
|
|
27
|
+
isInDir: (path: string, dir: string) => boolean;
|
|
28
|
+
isInDirs: (path: string, directories: string[]) => boolean;
|
|
28
29
|
isSafePath: (path: string, options?: {
|
|
29
30
|
parent?: string | null;
|
|
30
31
|
parents?: string | string[] | null;
|
package/lib/esm/index.mjs
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { DEFAULT_PLATFORM } from './platform.mjs';
|
|
2
|
-
const { absolute, delimiter,
|
|
2
|
+
const { absolute, delimiter, isAbsolute, join, leafExt, leafName, matchesGlob, normalize, parentName, parentPath, isInDir, isInDirs, isSafePath, isSafeSegment, posix, relative, resolve, sanitize, separator, untildify, win32, } = DEFAULT_PLATFORM;
|
|
3
3
|
/* eslint-disable unicorn/prefer-export-from */
|
|
4
|
-
export { absolute, delimiter,
|
|
4
|
+
export { absolute, delimiter, isAbsolute, join, leafExt, leafName, matchesGlob, normalize, parentName, parentPath, isInDir, isInDirs, isSafePath, isSafeSegment, posix, relative, resolve, sanitize, separator, untildify, win32, };
|
|
5
5
|
/* eslint-enable unicorn/prefer-export-from */
|
|
6
6
|
// eslint-disable-next-line import/no-anonymous-default-export
|
|
7
7
|
export default {
|
|
8
8
|
PlatformPath: undefined,
|
|
9
9
|
absolute,
|
|
10
10
|
delimiter,
|
|
11
|
-
extension,
|
|
12
11
|
isAbsolute,
|
|
13
12
|
join,
|
|
14
|
-
|
|
13
|
+
leafExt,
|
|
14
|
+
leafName,
|
|
15
15
|
matchesGlob,
|
|
16
16
|
normalize,
|
|
17
|
-
|
|
17
|
+
parentName,
|
|
18
|
+
parentPath,
|
|
18
19
|
isInDir,
|
|
19
20
|
isInDirs,
|
|
20
21
|
isSafePath,
|
package/lib/esm/is-in-dir.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type opath from 'node:path';
|
|
2
2
|
import { type PlatformPath } from './types.mjs';
|
|
3
|
-
export declare function isInDir(_nodePath:
|
|
3
|
+
export declare function isInDir(_nodePath: opath.PlatformPath, localPath: PlatformPath): (path: string, parent: string) => boolean;
|
package/lib/esm/is-in-dirs.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type opath from 'node:path';
|
|
2
2
|
import { type PlatformPath } from './types.mjs';
|
|
3
|
-
export declare function isInDirs(_nodePath:
|
|
3
|
+
export declare function isInDirs(_nodePath: opath.PlatformPath, localPath: PlatformPath): (path: string, parents: string[]) => boolean;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type opath from 'node:path';
|
|
2
2
|
import { type Target } from '@zokugun/fs-path-sanitize';
|
|
3
3
|
import { type PlatformPath } from './types.mjs';
|
|
4
|
-
export declare function isSafePath(_nodePath:
|
|
4
|
+
export declare function isSafePath(_nodePath: opath.PlatformPath, localPath: PlatformPath): (path: string, options?: {
|
|
5
5
|
parent?: string | null;
|
|
6
6
|
parents?: string | string[] | null;
|
|
7
7
|
target?: Target | 'auto';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type opath from 'node:path';
|
|
2
2
|
import { type Target } from '@zokugun/fs-path-sanitize';
|
|
3
3
|
import { type PlatformPath } from './types.mjs';
|
|
4
|
-
export declare function isSafeSegment(_nodePath:
|
|
4
|
+
export declare function isSafeSegment(_nodePath: opath.PlatformPath, localPath: PlatformPath): (segment: string, target?: Target | 'auto') => boolean;
|
package/lib/esm/join.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type opath from 'path';
|
|
2
2
|
import { type PlatformPath } from './types.mjs';
|
|
3
|
-
export declare function join(nodePath:
|
|
3
|
+
export declare function join(nodePath: opath.PlatformPath, _localPath: PlatformPath): (...paths: string[]) => string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isUndefined } from '@zokugun/is-it-type';
|
|
2
|
+
// eslint-disable-next-line unicorn/prevent-abbreviations
|
|
3
|
+
export function leafExt(nodePath, _localPath) {
|
|
4
|
+
return (path, length) => {
|
|
5
|
+
if (isUndefined(length)) {
|
|
6
|
+
return nodePath.extname(path);
|
|
7
|
+
}
|
|
8
|
+
const name = nodePath.basename(path);
|
|
9
|
+
if (name.length === 0 || name.startsWith('.')) {
|
|
10
|
+
return '';
|
|
11
|
+
}
|
|
12
|
+
if (length <= 0) {
|
|
13
|
+
const index = name.indexOf('.');
|
|
14
|
+
return index === -1 ? '' : name.slice(index);
|
|
15
|
+
}
|
|
16
|
+
else if (length === 1) {
|
|
17
|
+
const index = name.lastIndexOf('.');
|
|
18
|
+
return index === -1 ? '' : name.slice(index);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
const parts = name.split('.');
|
|
22
|
+
if (parts.length === 1) {
|
|
23
|
+
return '';
|
|
24
|
+
}
|
|
25
|
+
return '.' + parts.slice(parts.length <= length ? 1 : -length).join('.');
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { isString, isUndefined } from '@zokugun/is-it-type';
|
|
2
|
+
export function leafName(nodePath, _localPath) {
|
|
3
|
+
return (path, extension) => {
|
|
4
|
+
if (isUndefined(extension)) {
|
|
5
|
+
return nodePath.basename(path);
|
|
6
|
+
}
|
|
7
|
+
if (isString(extension)) {
|
|
8
|
+
return nodePath.basename(path, extension);
|
|
9
|
+
}
|
|
10
|
+
const name = nodePath.basename(path);
|
|
11
|
+
if (name.length === 0 || name.startsWith('.')) {
|
|
12
|
+
return name;
|
|
13
|
+
}
|
|
14
|
+
if (extension <= 0) {
|
|
15
|
+
const index = name.indexOf('.');
|
|
16
|
+
return index === -1 ? name : name.slice(0, index);
|
|
17
|
+
}
|
|
18
|
+
else if (extension === 1) {
|
|
19
|
+
const index = name.lastIndexOf('.');
|
|
20
|
+
return index === -1 ? name : name.slice(0, index);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
const parts = name.split('.');
|
|
24
|
+
if (parts.length <= extension) {
|
|
25
|
+
return parts[0];
|
|
26
|
+
}
|
|
27
|
+
return parts.slice(0, -extension).join('.');
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export function
|
|
2
|
-
return (
|
|
3
|
-
const parent = nodePath.dirname(
|
|
1
|
+
export function parentPath(nodePath, _localPath) {
|
|
2
|
+
return (path) => {
|
|
3
|
+
const parent = nodePath.dirname(path);
|
|
4
4
|
if (parent === '.') {
|
|
5
5
|
return '';
|
|
6
6
|
}
|
package/lib/esm/platform.mjs
CHANGED
|
@@ -1,43 +1,46 @@
|
|
|
1
|
-
import
|
|
1
|
+
import opath from 'node:path';
|
|
2
2
|
import { absolute } from './absolute.mjs';
|
|
3
|
-
import { dir } from './dir.mjs';
|
|
4
3
|
import { isInDir } from './is-in-dir.mjs';
|
|
5
4
|
// eslint-disable-next-line unicorn/prevent-abbreviations
|
|
6
5
|
import { isInDirs } from './is-in-dirs.mjs';
|
|
7
6
|
import { isSafePath } from './is-safe-path.mjs';
|
|
8
7
|
import { isSafeSegment } from './is-safe-segment.mjs';
|
|
9
8
|
import { join } from './join.mjs';
|
|
10
|
-
|
|
9
|
+
// eslint-disable-next-line unicorn/prevent-abbreviations
|
|
10
|
+
import { leafExt } from './leaf-ext.mjs';
|
|
11
|
+
import { leafName } from './leaf-name.mjs';
|
|
12
|
+
import { parentName } from './parent-name.mjs';
|
|
13
|
+
import { parentPath } from './parent-path.mjs';
|
|
11
14
|
import { resolve } from './resolve.mjs';
|
|
12
15
|
import { sanitize } from './sanitize.mjs';
|
|
13
16
|
import { untildify } from './untildify.mjs';
|
|
14
17
|
function buildPlatform(path) {
|
|
15
|
-
const {
|
|
18
|
+
const { delimiter, isAbsolute, normalize, relative, sep: separator, } = path;
|
|
16
19
|
const result = {
|
|
17
20
|
delimiter,
|
|
18
21
|
separator,
|
|
19
|
-
extension,
|
|
20
22
|
isAbsolute,
|
|
21
|
-
leaf,
|
|
22
23
|
matchesGlob: path.matchesGlob ?? undefined,
|
|
23
24
|
normalize,
|
|
24
25
|
relative,
|
|
25
26
|
};
|
|
26
27
|
result.absolute = absolute(path, result);
|
|
27
|
-
result.dir = dir(path, result);
|
|
28
28
|
result.isInDir = isInDir(path, result);
|
|
29
29
|
result.isInDirs = isInDirs(path, result);
|
|
30
30
|
result.isSafePath = isSafePath(path, result);
|
|
31
31
|
result.isSafeSegment = isSafeSegment(path, result);
|
|
32
32
|
result.join = join(path, result);
|
|
33
|
-
result.
|
|
33
|
+
result.leafExt = leafExt(path, result);
|
|
34
|
+
result.leafName = leafName(path, result);
|
|
35
|
+
result.parentName = parentName(path, result);
|
|
36
|
+
result.parentPath = parentPath(path, result);
|
|
34
37
|
result.resolve = resolve(path, result);
|
|
35
38
|
result.sanitize = sanitize(path, result);
|
|
36
39
|
result.untildify = untildify(path, result);
|
|
37
40
|
return result;
|
|
38
41
|
}
|
|
39
|
-
const POSIX_PLATFORM = buildPlatform(
|
|
40
|
-
const WIN32_PLATFORM = buildPlatform(
|
|
42
|
+
const POSIX_PLATFORM = buildPlatform(opath.posix);
|
|
43
|
+
const WIN32_PLATFORM = buildPlatform(opath.win32);
|
|
41
44
|
Object.defineProperties(POSIX_PLATFORM, {
|
|
42
45
|
posix: {
|
|
43
46
|
value: POSIX_PLATFORM,
|
|
@@ -58,4 +61,4 @@ Object.defineProperties(WIN32_PLATFORM, {
|
|
|
58
61
|
writable: false,
|
|
59
62
|
},
|
|
60
63
|
});
|
|
61
|
-
export const DEFAULT_PLATFORM = (
|
|
64
|
+
export const DEFAULT_PLATFORM = (opath === opath.posix ? POSIX_PLATFORM : WIN32_PLATFORM);
|
package/lib/esm/resolve.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type opath from 'node:path';
|
|
2
2
|
import { type PlatformPath } from './types.mjs';
|
|
3
|
-
export declare function resolve(nodePath:
|
|
3
|
+
export declare function resolve(nodePath: opath.PlatformPath, _localPath: PlatformPath): (...paths: string[]) => string;
|
package/lib/esm/sanitize.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type opath from 'node:path';
|
|
2
2
|
import { type Target } from '@zokugun/fs-path-sanitize';
|
|
3
3
|
import { type DResult } from '@zokugun/xtry';
|
|
4
4
|
import { type PlatformPath } from './types.mjs';
|
|
5
|
-
export declare function sanitize(_nodePath:
|
|
5
|
+
export declare function sanitize(_nodePath: opath.PlatformPath, localPath: PlatformPath): (path: string, options?: {
|
|
6
6
|
parent?: string | null;
|
|
7
7
|
parents?: string | string[] | null;
|
|
8
8
|
replacement?: string | null;
|
package/lib/esm/types.d.mts
CHANGED
|
@@ -6,11 +6,9 @@ export type PlatformPath = {
|
|
|
6
6
|
readonly posix: PlatformPath;
|
|
7
7
|
readonly win32: PlatformPath;
|
|
8
8
|
absolute: (...paths: string[]) => string;
|
|
9
|
-
dir: (path: string) => string;
|
|
10
|
-
extension: (path: string) => string;
|
|
11
9
|
isAbsolute: (path: string) => boolean;
|
|
12
|
-
isInDir: (
|
|
13
|
-
isInDirs: (
|
|
10
|
+
isInDir: (path: string, dir: string) => boolean;
|
|
11
|
+
isInDirs: (path: string, directories: string[]) => boolean;
|
|
14
12
|
isSafePath: (path: string, options?: {
|
|
15
13
|
parent?: string | null;
|
|
16
14
|
parents?: string | string[] | null;
|
|
@@ -18,10 +16,12 @@ export type PlatformPath = {
|
|
|
18
16
|
}) => boolean;
|
|
19
17
|
isSafeSegment: (segment: string, target?: Target | 'auto') => boolean;
|
|
20
18
|
join: (...paths: string[]) => string;
|
|
21
|
-
|
|
19
|
+
leafExt: (path: string, length?: number) => string;
|
|
20
|
+
leafName: (path: string, extension?: number | string) => string;
|
|
22
21
|
matchesGlob?: (path: string, pattern: string) => boolean;
|
|
23
22
|
normalize: (path: string) => string;
|
|
24
|
-
|
|
23
|
+
parentName: (path: string) => string;
|
|
24
|
+
parentPath: (path: string) => string;
|
|
25
25
|
relative: (from: string, to: string) => string;
|
|
26
26
|
resolve: (...paths: string[]) => string;
|
|
27
27
|
sanitize: (path: string, options?: {
|
package/lib/esm/untildify.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type opath from 'node:path';
|
|
2
2
|
import { type PlatformPath } from './types.mjs';
|
|
3
|
-
export declare function untildify(_nodePath:
|
|
3
|
+
export declare function untildify(_nodePath: opath.PlatformPath, _localPath: PlatformPath): (path: string) => string;
|
package/package.json
CHANGED
package/lib/cjs/dir.cjs
DELETED
package/lib/cjs/dir.d.cts
DELETED
package/lib/cjs/parent.d.cts
DELETED
package/lib/esm/dir.d.mts
DELETED
package/lib/esm/dir.mjs
DELETED
package/lib/esm/parent.d.mts
DELETED