@zokugun/fs-path 0.2.2 → 0.3.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 (60) hide show
  1. package/README.md +38 -8
  2. package/lib/cjs/ext/add.cjs +15 -0
  3. package/lib/cjs/ext/add.d.cts +1 -0
  4. package/lib/cjs/ext/calculateDepth.cjs +12 -0
  5. package/lib/cjs/ext/calculateDepth.d.cts +1 -0
  6. package/lib/cjs/ext/ensure.cjs +23 -0
  7. package/lib/cjs/ext/ensure.d.cts +3 -0
  8. package/lib/cjs/{leaf-ext.cjs → ext/get.cjs} +2 -3
  9. package/lib/cjs/ext/get.d.cts +3 -0
  10. package/lib/cjs/ext/index.cjs +19 -0
  11. package/lib/cjs/ext/index.d.cts +3 -0
  12. package/lib/cjs/ext/isMatching.cjs +9 -0
  13. package/lib/cjs/ext/isMatching.d.cts +1 -0
  14. package/lib/cjs/ext/normalizeIgnore.cjs +23 -0
  15. package/lib/cjs/ext/normalizeIgnore.d.cts +4 -0
  16. package/lib/cjs/ext/remove.cjs +20 -0
  17. package/lib/cjs/ext/remove.d.cts +3 -0
  18. package/lib/cjs/ext/replace.cjs +16 -0
  19. package/lib/cjs/ext/replace.d.cts +3 -0
  20. package/lib/cjs/ext/trim.cjs +27 -0
  21. package/lib/cjs/ext/trim.d.cts +3 -0
  22. package/lib/cjs/index.cjs +4 -2
  23. package/lib/cjs/index.d.cts +18 -2
  24. package/lib/cjs/join.d.cts +1 -1
  25. package/lib/cjs/leaf-name.d.cts +1 -1
  26. package/lib/cjs/normalize.cjs +29 -0
  27. package/lib/cjs/normalize.d.cts +3 -0
  28. package/lib/cjs/platform.cjs +7 -6
  29. package/lib/cjs/types.d.cts +13 -0
  30. package/lib/esm/ext/add.d.mts +1 -0
  31. package/lib/esm/ext/add.mjs +12 -0
  32. package/lib/esm/ext/calculateDepth.d.mts +1 -0
  33. package/lib/esm/ext/calculateDepth.mjs +9 -0
  34. package/lib/esm/ext/ensure.d.mts +3 -0
  35. package/lib/esm/ext/ensure.mjs +20 -0
  36. package/lib/esm/ext/get.d.mts +3 -0
  37. package/lib/esm/{leaf-ext.mjs → ext/get.mjs} +1 -2
  38. package/lib/esm/ext/index.d.mts +3 -0
  39. package/lib/esm/ext/index.mjs +16 -0
  40. package/lib/esm/ext/isMatching.d.mts +1 -0
  41. package/lib/esm/ext/isMatching.mjs +6 -0
  42. package/lib/esm/ext/normalizeIgnore.d.mts +4 -0
  43. package/lib/esm/ext/normalizeIgnore.mjs +20 -0
  44. package/lib/esm/ext/remove.d.mts +3 -0
  45. package/lib/esm/ext/remove.mjs +17 -0
  46. package/lib/esm/ext/replace.d.mts +3 -0
  47. package/lib/esm/ext/replace.mjs +13 -0
  48. package/lib/esm/ext/trim.d.mts +3 -0
  49. package/lib/esm/ext/trim.mjs +24 -0
  50. package/lib/esm/index.d.mts +18 -2
  51. package/lib/esm/index.mjs +3 -2
  52. package/lib/esm/join.d.mts +1 -1
  53. package/lib/esm/leaf-name.d.mts +1 -1
  54. package/lib/esm/normalize.d.mts +3 -0
  55. package/lib/esm/normalize.mjs +26 -0
  56. package/lib/esm/platform.mjs +7 -6
  57. package/lib/esm/types.d.mts +13 -0
  58. package/package.json +2 -2
  59. package/lib/cjs/leaf-ext.d.cts +0 -3
  60. package/lib/esm/leaf-ext.d.mts +0 -3
package/README.md CHANGED
@@ -1,11 +1,13 @@
1
1
  [@zokugun/fs-path](https://github.com/zokugun/node-fs-path)
2
2
  ===========================================================
3
3
 
4
- [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
5
- [![NPM Version](https://img.shields.io/npm/v/@zokugun/fs-path.svg?colorB=green)](https://www.npmjs.com/package/@zokugun/fs-path)
6
- [![Donation](https://img.shields.io/badge/donate-ko--fi-green)](https://ko-fi.com/daiyam)
7
- [![Donation](https://img.shields.io/badge/donate-liberapay-green)](https://liberapay.com/daiyam/donate)
8
- [![Donation](https://img.shields.io/badge/donate-paypal-green)](https://paypal.me/daiyam99)
4
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue)](./LICENSE)
5
+ [![NPM Version](https://img.shields.io/npm/v/@zokugun/fs-path?color=brightgreen)](https://www.npmjs.com/package/@zokugun/fs-path)
6
+ [![NodeJS Version](https://img.shields.io/badge/node.js-%3E%3D%2018.20-green)](#requirements)
7
+ [![Modules](https://img.shields.io/badge/modules-ESM%20%7C%20CJS-green)](#requirements)
8
+ [![Ko-fi](https://img.shields.io/badge/Ko--fi-f87171?logo=kofi&logoColor=white)](https://ko-fi.com/daiyam)
9
+ [![Liberapay](https://img.shields.io/badge/Liberapay-facc15?logo=liberapay&logoColor=black)](https://liberapay.com/daiyam/donate)
10
+ [![PayPal](https://img.shields.io/badge/PayPal-5277C3?logo=paypal&logoColor=white)](https://paypal.me/daiyam99)
9
11
 
10
12
  > Compact set of path utilities that complement Node's builtin `path` module.
11
13
 
@@ -15,7 +17,7 @@ Features
15
17
  - Tilde expansion: expand `~` to the current user's home directory with `untildify`.
16
18
  - Safe joining and resolving: helpers that avoid common pitfalls when composing paths.
17
19
  - Useful utilities: retrieve parent paths, absolute normalization, and platform-aware helpers.
18
- - Small package with ESM and CJS builds
20
+ - Extension helpers: add, ensure, get, remove, replace, or trim file extensions.
19
21
 
20
22
  Installation
21
23
  ------------
@@ -24,6 +26,12 @@ Installation
24
26
  npm add @zokugun/fs-path
25
27
  ```
26
28
 
29
+ Requirements
30
+ ------------
31
+
32
+ - **Node.js**: `v18.20` or higher
33
+ - **Modules**: ECMAScript Modules (`ESM`) or CommonJS (`CJS`)
34
+
27
35
  Quick Start
28
36
  -----------
29
37
 
@@ -51,10 +59,17 @@ API reference
51
59
  - `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).
52
60
  - `isSafeSegment(segment: string, target?: Target | 'auto'): boolean`: Return `true` when a single path segment is safe (doesn't contain path separators or traversal sequences).
53
61
  - `join(...paths: string[]): string`: Join path segments.
62
+ - `ext`: File-extension helpers:
63
+ - `ext.add(path: string, ext: string): string`: Append an extension, adding a leading dot when needed.
64
+ - `ext.ensure(path: string, ext: string, options?: ExtOptions): string`: Append the extension unless the path already has a matching extension.
65
+ - `ext.get(path: string, depth?: number): string`: Get the extension; `depth` selects multiple suffixes (for example, `2` returns `.tar.gz`).
66
+ - `ext.remove(path: string, ext: string): string`: Remove the matching trailing extension.
67
+ - `ext.replace(path: string, ext: string, options?: ExtOptions): string`: Trim a matching extension, then append the given extension.
68
+ - `ext.trim(path: string, options?: ExtOptions): string`: Remove a matching extension from the path.
54
69
  - `leafExt(path: string, length?: number): string`: Return the extensions.
55
70
  - `leafName(path: string, extension?: number | string): string`: Return the basename of `path` with/without the extensions.
56
71
  - `matchesGlob?(path: string, pattern: string): boolean`: Optional platform-provided glob matcher when available.
57
- - `normalize(path: string): string`: Normalize the path (same as `path.normalize`).
72
+ - `normalize(path: string): string`: Normalize a path using the current platform's path rules.
58
73
  - `parentName(path: string): string`: Return the parent name of `path`.
59
74
  - `parentPath(path: string): string`: Return the parent directory of `path`.
60
75
  - `relative(from: string, to: string): string`: Compute the relative path from `from` to `to`.
@@ -67,12 +82,26 @@ API reference
67
82
  - `separator`: Platform-specific character (`\`/`/`).
68
83
 
69
84
  ```ts
85
+ export type ExtOptions = {
86
+ depth?: number;
87
+ ignore?: string[];
88
+ maxLength?: number;
89
+ };
90
+
70
91
  export type PlatformPath = {
71
92
  readonly delimiter: ';' | ':';
72
93
  readonly separator: '\\' | '/';
73
94
  readonly posix: PlatformPath;
74
95
  readonly win32: PlatformPath;
75
96
  absolute: (...paths: string[]) => string;
97
+ ext: {
98
+ add(path: string, ext: string): string;
99
+ ensure(path: string, ext: string, options?: ExtOptions): string;
100
+ get(path: string, depth?: number): string;
101
+ remove(path: string, ext: string): string;
102
+ replace(path: string, ext: string, options?: ExtOptions): string;
103
+ trim(path: string, options?: ExtOptions): string;
104
+ };
76
105
  isAbsolute: (path: string) => boolean;
77
106
  isInDir(path: string, parent: string): boolean;
78
107
  isInDirs(path: string, parents: string[]): boolean;
@@ -107,7 +136,8 @@ Comparison with Node's `path`
107
136
  This library intentionally mirrors many of Node's `path` APIs but provides small ergonomic differences and extra features where useful:
108
137
 
109
138
  - `join(...paths)`: wraps `path.join`. Returns `''` instead of `.` when the joined result is the current directory.
110
- - `isAbsolute(path)`, `normalize(path)`, `relative(from, to)`: direct mappings to `path.isAbsolute`, `path.normalize`, and `path.relative` respectively.
139
+ - `isAbsolute(path)` and `relative(from, to)`: direct mappings to `path.isAbsolute` and `path.relative`.
140
+ - `normalize(path)`: uses the current platform's path rules; on POSIX, backslashes are also treated as separators.
111
141
  - `parentPath(file)`: wraps `path.dirname`. Returns `''` instead of `.` for consistency with `join`.
112
142
  - `resolve(...paths)`: wraps `path.resolve` but adds tilde expansion (`~` and `~username`) before resolving.
113
143
  - `delimiter`: same value as `path.delimiter` on the current platform.
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.add = add;
4
+ function add(path, ext) {
5
+ const trim = ext.trim();
6
+ if (trim.length === 0) {
7
+ return path;
8
+ }
9
+ if (trim[0] !== '.') {
10
+ return path + '.' + trim;
11
+ }
12
+ else {
13
+ return path + ext;
14
+ }
15
+ }
@@ -0,0 +1 @@
1
+ export declare function add(path: string, ext: string): string;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculateDepth = calculateDepth;
4
+ function calculateDepth(ext) {
5
+ let depth = 0;
6
+ for (let i = 0; i < ext.length; i++) {
7
+ if (ext[i] === '.') {
8
+ depth += 1;
9
+ }
10
+ }
11
+ return depth;
12
+ }
@@ -0,0 +1 @@
1
+ export declare function calculateDepth(ext: string): number;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensure = ensure;
4
+ const isMatching_js_1 = require("./isMatching.cjs");
5
+ const normalizeIgnore_js_1 = require("./normalizeIgnore.cjs");
6
+ function ensure(_nodePath, localPath) {
7
+ return (path, ext, options = {}) => {
8
+ ext = ext.trim();
9
+ if (ext.length === 0) {
10
+ return path;
11
+ }
12
+ if (ext[0] !== '.') {
13
+ ext = '.' + ext;
14
+ }
15
+ const { maxLength } = options;
16
+ const { ignore, depth } = (0, normalizeIgnore_js_1.normalizeIgnore)(options.ignore, options.depth);
17
+ const old = localPath.ext.get(path, depth);
18
+ if (old.length > 0 && (0, isMatching_js_1.isMatching)(old, ignore, maxLength)) {
19
+ return path;
20
+ }
21
+ return path + ext;
22
+ };
23
+ }
@@ -0,0 +1,3 @@
1
+ import type path from 'node:path';
2
+ import type { ExtOptions, PlatformPath } from '../types.cjs';
3
+ export declare function ensure(_nodePath: path.PlatformPath, localPath: PlatformPath): (path: string, ext: string, options?: ExtOptions) => string;
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.leafExt = leafExt;
3
+ exports.get = get;
4
4
  const is_it_type_1 = require("@zokugun/is-it-type");
5
- // eslint-disable-next-line unicorn/prevent-abbreviations
6
- function leafExt(nodePath, _localPath) {
5
+ function get(nodePath, _localPath) {
7
6
  return (path, length) => {
8
7
  if ((0, is_it_type_1.isUndefined)(length)) {
9
8
  return nodePath.extname(path);
@@ -0,0 +1,3 @@
1
+ import type path from 'node:path';
2
+ import type { PlatformPath } from '../types.cjs';
3
+ export declare function get(nodePath: path.PlatformPath, _localPath: PlatformPath): (path: string, length?: number) => string;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildExt = buildExt;
4
+ const add_js_1 = require("./add.cjs");
5
+ const ensure_js_1 = require("./ensure.cjs");
6
+ const get_js_1 = require("./get.cjs");
7
+ const remove_js_1 = require("./remove.cjs");
8
+ const replace_js_1 = require("./replace.cjs");
9
+ const trim_js_1 = require("./trim.cjs");
10
+ function buildExt(nodePath, localPath) {
11
+ return {
12
+ add: add_js_1.add,
13
+ ensure: (0, ensure_js_1.ensure)(nodePath, localPath),
14
+ get: (0, get_js_1.get)(nodePath, localPath),
15
+ remove: (0, remove_js_1.remove)(nodePath, localPath),
16
+ replace: (0, replace_js_1.replace)(nodePath, localPath),
17
+ trim: (0, trim_js_1.trim)(nodePath, localPath),
18
+ };
19
+ }
@@ -0,0 +1,3 @@
1
+ import type path from 'node:path';
2
+ import type { PlatformPath } from '../types.cjs';
3
+ export declare function buildExt(nodePath: path.PlatformPath, localPath: PlatformPath): PlatformPath['ext'];
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isMatching = isMatching;
4
+ function isMatching(ext, ignore, maxLength) {
5
+ if (maxLength && ext.length > maxLength) {
6
+ return false;
7
+ }
8
+ return !ignore.includes(ext);
9
+ }
@@ -0,0 +1 @@
1
+ export declare function isMatching(ext: string, ignore: string[], maxLength: number | undefined): boolean;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeIgnore = normalizeIgnore;
4
+ const calculateDepth_js_1 = require("./calculateDepth.cjs");
5
+ function normalizeIgnore(option, depth) {
6
+ if (!option) {
7
+ return { depth, ignore: [] };
8
+ }
9
+ const ignore = [];
10
+ depth ??= 1;
11
+ for (let ext of option) {
12
+ ext = ext.trim();
13
+ if (ext.length === 0) {
14
+ continue;
15
+ }
16
+ if (ext[0] !== '.') {
17
+ ignore.push('.' + ext);
18
+ }
19
+ ignore.push(ext);
20
+ depth = Math.max(depth, (0, calculateDepth_js_1.calculateDepth)(ext));
21
+ }
22
+ return { depth, ignore };
23
+ }
@@ -0,0 +1,4 @@
1
+ export declare function normalizeIgnore(option: string[] | undefined, depth: number | undefined): {
2
+ depth: number | undefined;
3
+ ignore: string[];
4
+ };
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.remove = remove;
4
+ const calculateDepth_js_1 = require("./calculateDepth.cjs");
5
+ function remove(_nodePath, localPath) {
6
+ return (path, ext) => {
7
+ ext = ext.trim();
8
+ if (ext.length === 0) {
9
+ return path;
10
+ }
11
+ if (ext[0] !== '.') {
12
+ ext = '.' + ext;
13
+ }
14
+ const depth = (0, calculateDepth_js_1.calculateDepth)(ext);
15
+ if (localPath.ext.get(path, depth) === ext) {
16
+ return path.slice(0, path.length - ext.length);
17
+ }
18
+ return path;
19
+ };
20
+ }
@@ -0,0 +1,3 @@
1
+ import type path from 'node:path';
2
+ import type { PlatformPath } from '../types.cjs';
3
+ export declare function remove(_nodePath: path.PlatformPath, localPath: PlatformPath): (path: string, ext: string) => string;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.replace = replace;
4
+ function replace(_nodePath, localPath) {
5
+ return (path, ext, options = {}) => {
6
+ ext = ext.trim();
7
+ if (ext.length === 0) {
8
+ return path;
9
+ }
10
+ if (ext[0] !== '.') {
11
+ ext = '.' + ext;
12
+ }
13
+ const trimmed = localPath.ext.trim(path, options);
14
+ return trimmed + ext;
15
+ };
16
+ }
@@ -0,0 +1,3 @@
1
+ import type path from 'node:path';
2
+ import type { ExtOptions, PlatformPath } from '../types.cjs';
3
+ export declare function replace(_nodePath: path.PlatformPath, localPath: PlatformPath): (path: string, ext: string, options?: ExtOptions) => string;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.trim = trim;
4
+ const isMatching_js_1 = require("./isMatching.cjs");
5
+ const normalizeIgnore_js_1 = require("./normalizeIgnore.cjs");
6
+ function trim(_nodePath, localPath) {
7
+ return (path, options = {}) => {
8
+ const { maxLength } = options;
9
+ let { ignore, depth } = (0, normalizeIgnore_js_1.normalizeIgnore)(options.ignore, options.depth);
10
+ if (depth && maxLength) {
11
+ while (depth > 0) {
12
+ const ext = localPath.ext.get(path, depth);
13
+ if ((0, isMatching_js_1.isMatching)(ext, ignore, maxLength)) {
14
+ return path.slice(0, path.length - ext.length);
15
+ }
16
+ depth -= 1;
17
+ }
18
+ }
19
+ else {
20
+ const ext = localPath.ext.get(path, depth);
21
+ if ((0, isMatching_js_1.isMatching)(ext, ignore, maxLength)) {
22
+ return path.slice(0, path.length - ext.length);
23
+ }
24
+ }
25
+ return path;
26
+ };
27
+ }
@@ -0,0 +1,3 @@
1
+ import type path from 'node:path';
2
+ import type { ExtOptions, PlatformPath } from '../types.cjs';
3
+ export declare function trim(_nodePath: path.PlatformPath, localPath: PlatformPath): (path: string, options?: ExtOptions) => string;
package/lib/cjs/index.cjs CHANGED
@@ -1,9 +1,10 @@
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.parentPath = exports.parentName = exports.normalize = exports.matchesGlob = exports.leafName = exports.leafExt = exports.join = exports.isAbsolute = exports.delimiter = exports.absolute = void 0;
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.ext = exports.delimiter = exports.absolute = void 0;
4
4
  const platform_js_1 = require("./platform.cjs");
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;
5
+ const { absolute, ext, 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
+ exports.ext = ext;
7
8
  exports.delimiter = delimiter;
8
9
  exports.isAbsolute = isAbsolute;
9
10
  exports.join = join;
@@ -30,6 +31,7 @@ exports.default = {
30
31
  PlatformPath: undefined,
31
32
  absolute,
32
33
  delimiter,
34
+ ext,
33
35
  isAbsolute,
34
36
  join,
35
37
  leafExt,
@@ -1,5 +1,12 @@
1
1
  import { type PlatformPath } from './types.cjs';
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?: {
2
+ declare const absolute: (...paths: string[]) => string, ext: {
3
+ add: (path: string, ext: string) => string;
4
+ ensure: (path: string, ext: string, options?: ExtOptions) => string;
5
+ get: (path: string, depth?: number) => string;
6
+ remove: (path: string, ext: string) => string;
7
+ replace: (path: string, ext: string, options?: ExtOptions) => string;
8
+ trim: (path: string, options?: ExtOptions) => string;
9
+ }, 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
10
  parent?: string | null;
4
11
  parents?: string | string[] | null;
5
12
  target?: Target | "auto";
@@ -9,13 +16,22 @@ declare const absolute: (...paths: string[]) => string, delimiter: ";" | ":", is
9
16
  replacement?: string | null;
10
17
  target?: Target | "auto";
11
18
  }) => DResult<string>, separator: "\\" | "/", untildify: (path: string) => string, win32: PlatformPath;
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, };
19
+ export { type PlatformPath, absolute, delimiter, ext, isAbsolute, join, leafExt, leafName, matchesGlob, normalize, parentName, parentPath, isInDir, isInDirs, isSafePath, isSafeSegment, posix, relative, resolve, sanitize, separator, untildify, win32, };
20
+ import { type ExtOptions } from "./types.cjs";
13
21
  import { type Target } from "@zokugun/fs-path-sanitize";
14
22
  import { type DResult } from "@zokugun/xtry/result";
15
23
  declare const _default: {
16
24
  PlatformPath: PlatformPath;
17
25
  absolute: (...paths: string[]) => string;
18
26
  delimiter: ";" | ":";
27
+ ext: {
28
+ add: (path: string, ext: string) => string;
29
+ ensure: (path: string, ext: string, options?: ExtOptions) => string;
30
+ get: (path: string, depth?: number) => string;
31
+ remove: (path: string, ext: string) => string;
32
+ replace: (path: string, ext: string, options?: ExtOptions) => string;
33
+ trim: (path: string, options?: ExtOptions) => string;
34
+ };
19
35
  isAbsolute: (path: string) => boolean;
20
36
  join: (...paths: string[]) => string;
21
37
  leafExt: (path: string, length?: number) => string;
@@ -1,3 +1,3 @@
1
- import type opath from 'path';
1
+ import type opath from 'node:path';
2
2
  import { type PlatformPath } from './types.cjs';
3
3
  export declare function join(nodePath: opath.PlatformPath, _localPath: PlatformPath): (...paths: string[]) => string;
@@ -1,3 +1,3 @@
1
1
  import type path from 'node:path';
2
- import { type PlatformPath } from './types.cjs';
2
+ import type { PlatformPath } from './types.cjs';
3
3
  export declare function leafName(nodePath: path.PlatformPath, _localPath: PlatformPath): (path: string, extension?: number | string) => string;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalize = normalize;
4
+ function normalize(nodePath, localPath) {
5
+ if (localPath.separator === '\\') {
6
+ return nodePath.win32.normalize;
7
+ }
8
+ return (path) => {
9
+ let normalized = nodePath.posix.normalize(path);
10
+ if (!normalized.includes('\\')) {
11
+ return normalized;
12
+ }
13
+ if (normalized === '\\') {
14
+ return '/';
15
+ }
16
+ if (normalized.length <= 1) {
17
+ return normalized;
18
+ }
19
+ let prefix = '';
20
+ if (normalized.length > 4 && normalized[0] === '\\' && normalized[1] === '\\' && normalized[3] === '\\') {
21
+ const ch = normalized[2];
22
+ if ((ch === '?' || ch === '.')) {
23
+ normalized = normalized.slice(2);
24
+ prefix = '//';
25
+ }
26
+ }
27
+ return prefix + normalized.split(/[/\\]+/).join('/');
28
+ };
29
+ }
@@ -0,0 +1,3 @@
1
+ import type opath from 'node:path';
2
+ import { type PlatformPath } from './types.cjs';
3
+ export declare function normalize(nodePath: opath.PlatformPath, localPath: PlatformPath): (path: string) => string;
@@ -6,38 +6,39 @@ 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 index_js_1 = require("./ext/index.cjs");
9
10
  const is_in_dir_js_1 = require("./is-in-dir.cjs");
10
- // eslint-disable-next-line unicorn/prevent-abbreviations
11
11
  const is_in_dirs_js_1 = require("./is-in-dirs.cjs");
12
12
  const is_safe_path_js_1 = require("./is-safe-path.cjs");
13
13
  const is_safe_segment_js_1 = require("./is-safe-segment.cjs");
14
14
  const join_js_1 = require("./join.cjs");
15
- // eslint-disable-next-line unicorn/prevent-abbreviations
16
- const leaf_ext_js_1 = require("./leaf-ext.cjs");
17
15
  const leaf_name_js_1 = require("./leaf-name.cjs");
16
+ const normalize_js_1 = require("./normalize.cjs");
18
17
  const parent_name_js_1 = require("./parent-name.cjs");
19
18
  const parent_path_js_1 = require("./parent-path.cjs");
20
19
  const resolve_js_1 = require("./resolve.cjs");
21
20
  const sanitize_js_1 = require("./sanitize.cjs");
22
21
  const untildify_js_1 = require("./untildify.cjs");
23
22
  function buildPlatform(path) {
24
- const { delimiter, isAbsolute, normalize, relative, sep: separator, } = path;
23
+ const { delimiter, isAbsolute, relative, sep: separator, } = path;
25
24
  const result = {
26
25
  delimiter,
27
26
  separator,
28
27
  isAbsolute,
29
28
  matchesGlob: path.matchesGlob ?? undefined,
30
- normalize,
31
29
  relative,
32
30
  };
31
+ const ext = (0, index_js_1.buildExt)(path, result);
33
32
  result.absolute = (0, absolute_js_1.absolute)(path, result);
33
+ result.ext = ext;
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.leafExt = (0, leaf_ext_js_1.leafExt)(path, result);
39
+ result.leafExt = ext.get;
40
40
  result.leafName = (0, leaf_name_js_1.leafName)(path, result);
41
+ result.normalize = (0, normalize_js_1.normalize)(path, result);
41
42
  result.parentName = (0, parent_name_js_1.parentName)(path, result);
42
43
  result.parentPath = (0, parent_path_js_1.parentPath)(path, result);
43
44
  result.resolve = (0, resolve_js_1.resolve)(path, result);
@@ -1,11 +1,24 @@
1
1
  import { type Target } from '@zokugun/fs-path-sanitize';
2
2
  import { type DResult } from '@zokugun/xtry';
3
+ export type ExtOptions = {
4
+ depth?: number;
5
+ ignore?: string[];
6
+ maxLength?: number;
7
+ };
3
8
  export type PlatformPath = {
4
9
  readonly delimiter: ';' | ':';
5
10
  readonly separator: '\\' | '/';
6
11
  readonly posix: PlatformPath;
7
12
  readonly win32: PlatformPath;
8
13
  absolute: (...paths: string[]) => string;
14
+ ext: {
15
+ add: (path: string, ext: string) => string;
16
+ ensure: (path: string, ext: string, options?: ExtOptions) => string;
17
+ get: (path: string, depth?: number) => string;
18
+ remove: (path: string, ext: string) => string;
19
+ replace: (path: string, ext: string, options?: ExtOptions) => string;
20
+ trim: (path: string, options?: ExtOptions) => string;
21
+ };
9
22
  isAbsolute: (path: string) => boolean;
10
23
  isInDir: (path: string, dir: string) => boolean;
11
24
  isInDirs: (path: string, directories: string[]) => boolean;
@@ -0,0 +1 @@
1
+ export declare function add(path: string, ext: string): string;
@@ -0,0 +1,12 @@
1
+ export function add(path, ext) {
2
+ const trim = ext.trim();
3
+ if (trim.length === 0) {
4
+ return path;
5
+ }
6
+ if (trim[0] !== '.') {
7
+ return path + '.' + trim;
8
+ }
9
+ else {
10
+ return path + ext;
11
+ }
12
+ }
@@ -0,0 +1 @@
1
+ export declare function calculateDepth(ext: string): number;
@@ -0,0 +1,9 @@
1
+ export function calculateDepth(ext) {
2
+ let depth = 0;
3
+ for (let i = 0; i < ext.length; i++) {
4
+ if (ext[i] === '.') {
5
+ depth += 1;
6
+ }
7
+ }
8
+ return depth;
9
+ }
@@ -0,0 +1,3 @@
1
+ import type path from 'node:path';
2
+ import type { ExtOptions, PlatformPath } from '../types.mjs';
3
+ export declare function ensure(_nodePath: path.PlatformPath, localPath: PlatformPath): (path: string, ext: string, options?: ExtOptions) => string;
@@ -0,0 +1,20 @@
1
+ import { isMatching } from './isMatching.mjs';
2
+ import { normalizeIgnore } from './normalizeIgnore.mjs';
3
+ export function ensure(_nodePath, localPath) {
4
+ return (path, ext, options = {}) => {
5
+ ext = ext.trim();
6
+ if (ext.length === 0) {
7
+ return path;
8
+ }
9
+ if (ext[0] !== '.') {
10
+ ext = '.' + ext;
11
+ }
12
+ const { maxLength } = options;
13
+ const { ignore, depth } = normalizeIgnore(options.ignore, options.depth);
14
+ const old = localPath.ext.get(path, depth);
15
+ if (old.length > 0 && isMatching(old, ignore, maxLength)) {
16
+ return path;
17
+ }
18
+ return path + ext;
19
+ };
20
+ }
@@ -0,0 +1,3 @@
1
+ import type path from 'node:path';
2
+ import type { PlatformPath } from '../types.mjs';
3
+ export declare function get(nodePath: path.PlatformPath, _localPath: PlatformPath): (path: string, length?: number) => string;
@@ -1,6 +1,5 @@
1
1
  import { isUndefined } from '@zokugun/is-it-type';
2
- // eslint-disable-next-line unicorn/prevent-abbreviations
3
- export function leafExt(nodePath, _localPath) {
2
+ export function get(nodePath, _localPath) {
4
3
  return (path, length) => {
5
4
  if (isUndefined(length)) {
6
5
  return nodePath.extname(path);
@@ -0,0 +1,3 @@
1
+ import type path from 'node:path';
2
+ import type { PlatformPath } from '../types.mjs';
3
+ export declare function buildExt(nodePath: path.PlatformPath, localPath: PlatformPath): PlatformPath['ext'];
@@ -0,0 +1,16 @@
1
+ import { add } from './add.mjs';
2
+ import { ensure } from './ensure.mjs';
3
+ import { get } from './get.mjs';
4
+ import { remove } from './remove.mjs';
5
+ import { replace } from './replace.mjs';
6
+ import { trim } from './trim.mjs';
7
+ export function buildExt(nodePath, localPath) {
8
+ return {
9
+ add,
10
+ ensure: ensure(nodePath, localPath),
11
+ get: get(nodePath, localPath),
12
+ remove: remove(nodePath, localPath),
13
+ replace: replace(nodePath, localPath),
14
+ trim: trim(nodePath, localPath),
15
+ };
16
+ }
@@ -0,0 +1 @@
1
+ export declare function isMatching(ext: string, ignore: string[], maxLength: number | undefined): boolean;
@@ -0,0 +1,6 @@
1
+ export function isMatching(ext, ignore, maxLength) {
2
+ if (maxLength && ext.length > maxLength) {
3
+ return false;
4
+ }
5
+ return !ignore.includes(ext);
6
+ }
@@ -0,0 +1,4 @@
1
+ export declare function normalizeIgnore(option: string[] | undefined, depth: number | undefined): {
2
+ depth: number | undefined;
3
+ ignore: string[];
4
+ };
@@ -0,0 +1,20 @@
1
+ import { calculateDepth } from './calculateDepth.mjs';
2
+ export function normalizeIgnore(option, depth) {
3
+ if (!option) {
4
+ return { depth, ignore: [] };
5
+ }
6
+ const ignore = [];
7
+ depth ??= 1;
8
+ for (let ext of option) {
9
+ ext = ext.trim();
10
+ if (ext.length === 0) {
11
+ continue;
12
+ }
13
+ if (ext[0] !== '.') {
14
+ ignore.push('.' + ext);
15
+ }
16
+ ignore.push(ext);
17
+ depth = Math.max(depth, calculateDepth(ext));
18
+ }
19
+ return { depth, ignore };
20
+ }
@@ -0,0 +1,3 @@
1
+ import type path from 'node:path';
2
+ import type { PlatformPath } from '../types.mjs';
3
+ export declare function remove(_nodePath: path.PlatformPath, localPath: PlatformPath): (path: string, ext: string) => string;
@@ -0,0 +1,17 @@
1
+ import { calculateDepth } from './calculateDepth.mjs';
2
+ export function remove(_nodePath, localPath) {
3
+ return (path, ext) => {
4
+ ext = ext.trim();
5
+ if (ext.length === 0) {
6
+ return path;
7
+ }
8
+ if (ext[0] !== '.') {
9
+ ext = '.' + ext;
10
+ }
11
+ const depth = calculateDepth(ext);
12
+ if (localPath.ext.get(path, depth) === ext) {
13
+ return path.slice(0, path.length - ext.length);
14
+ }
15
+ return path;
16
+ };
17
+ }
@@ -0,0 +1,3 @@
1
+ import type path from 'node:path';
2
+ import type { ExtOptions, PlatformPath } from '../types.mjs';
3
+ export declare function replace(_nodePath: path.PlatformPath, localPath: PlatformPath): (path: string, ext: string, options?: ExtOptions) => string;
@@ -0,0 +1,13 @@
1
+ export function replace(_nodePath, localPath) {
2
+ return (path, ext, options = {}) => {
3
+ ext = ext.trim();
4
+ if (ext.length === 0) {
5
+ return path;
6
+ }
7
+ if (ext[0] !== '.') {
8
+ ext = '.' + ext;
9
+ }
10
+ const trimmed = localPath.ext.trim(path, options);
11
+ return trimmed + ext;
12
+ };
13
+ }
@@ -0,0 +1,3 @@
1
+ import type path from 'node:path';
2
+ import type { ExtOptions, PlatformPath } from '../types.mjs';
3
+ export declare function trim(_nodePath: path.PlatformPath, localPath: PlatformPath): (path: string, options?: ExtOptions) => string;
@@ -0,0 +1,24 @@
1
+ import { isMatching } from './isMatching.mjs';
2
+ import { normalizeIgnore } from './normalizeIgnore.mjs';
3
+ export function trim(_nodePath, localPath) {
4
+ return (path, options = {}) => {
5
+ const { maxLength } = options;
6
+ let { ignore, depth } = normalizeIgnore(options.ignore, options.depth);
7
+ if (depth && maxLength) {
8
+ while (depth > 0) {
9
+ const ext = localPath.ext.get(path, depth);
10
+ if (isMatching(ext, ignore, maxLength)) {
11
+ return path.slice(0, path.length - ext.length);
12
+ }
13
+ depth -= 1;
14
+ }
15
+ }
16
+ else {
17
+ const ext = localPath.ext.get(path, depth);
18
+ if (isMatching(ext, ignore, maxLength)) {
19
+ return path.slice(0, path.length - ext.length);
20
+ }
21
+ }
22
+ return path;
23
+ };
24
+ }
@@ -1,5 +1,12 @@
1
1
  import { type PlatformPath } from './types.mjs';
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?: {
2
+ declare const absolute: (...paths: string[]) => string, ext: {
3
+ add: (path: string, ext: string) => string;
4
+ ensure: (path: string, ext: string, options?: ExtOptions) => string;
5
+ get: (path: string, depth?: number) => string;
6
+ remove: (path: string, ext: string) => string;
7
+ replace: (path: string, ext: string, options?: ExtOptions) => string;
8
+ trim: (path: string, options?: ExtOptions) => string;
9
+ }, 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
10
  parent?: string | null;
4
11
  parents?: string | string[] | null;
5
12
  target?: Target | "auto";
@@ -9,13 +16,22 @@ declare const absolute: (...paths: string[]) => string, delimiter: ";" | ":", is
9
16
  replacement?: string | null;
10
17
  target?: Target | "auto";
11
18
  }) => DResult<string>, separator: "\\" | "/", untildify: (path: string) => string, win32: PlatformPath;
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, };
19
+ export { type PlatformPath, absolute, delimiter, ext, isAbsolute, join, leafExt, leafName, matchesGlob, normalize, parentName, parentPath, isInDir, isInDirs, isSafePath, isSafeSegment, posix, relative, resolve, sanitize, separator, untildify, win32, };
20
+ import { type ExtOptions } from "./types.mjs";
13
21
  import { type Target } from "@zokugun/fs-path-sanitize";
14
22
  import { type DResult } from "@zokugun/xtry";
15
23
  declare const _default: {
16
24
  PlatformPath: PlatformPath;
17
25
  absolute: (...paths: string[]) => string;
18
26
  delimiter: ";" | ":";
27
+ ext: {
28
+ add: (path: string, ext: string) => string;
29
+ ensure: (path: string, ext: string, options?: ExtOptions) => string;
30
+ get: (path: string, depth?: number) => string;
31
+ remove: (path: string, ext: string) => string;
32
+ replace: (path: string, ext: string, options?: ExtOptions) => string;
33
+ trim: (path: string, options?: ExtOptions) => string;
34
+ };
19
35
  isAbsolute: (path: string) => boolean;
20
36
  join: (...paths: string[]) => string;
21
37
  leafExt: (path: string, length?: number) => string;
package/lib/esm/index.mjs CHANGED
@@ -1,13 +1,14 @@
1
1
  import { DEFAULT_PLATFORM } from './platform.mjs';
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;
2
+ const { absolute, ext, 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, isAbsolute, join, leafExt, leafName, matchesGlob, normalize, parentName, parentPath, isInDir, isInDirs, isSafePath, isSafeSegment, posix, relative, resolve, sanitize, separator, untildify, win32, };
4
+ export { absolute, delimiter, ext, 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
+ ext,
11
12
  isAbsolute,
12
13
  join,
13
14
  leafExt,
@@ -1,3 +1,3 @@
1
- import type opath from 'path';
1
+ import type opath from 'node:path';
2
2
  import { type PlatformPath } from './types.mjs';
3
3
  export declare function join(nodePath: opath.PlatformPath, _localPath: PlatformPath): (...paths: string[]) => string;
@@ -1,3 +1,3 @@
1
1
  import type path from 'node:path';
2
- import { type PlatformPath } from './types.mjs';
2
+ import type { PlatformPath } from './types.mjs';
3
3
  export declare function leafName(nodePath: path.PlatformPath, _localPath: PlatformPath): (path: string, extension?: number | string) => string;
@@ -0,0 +1,3 @@
1
+ import type opath from 'node:path';
2
+ import { type PlatformPath } from './types.mjs';
3
+ export declare function normalize(nodePath: opath.PlatformPath, localPath: PlatformPath): (path: string) => string;
@@ -0,0 +1,26 @@
1
+ export function normalize(nodePath, localPath) {
2
+ if (localPath.separator === '\\') {
3
+ return nodePath.win32.normalize;
4
+ }
5
+ return (path) => {
6
+ let normalized = nodePath.posix.normalize(path);
7
+ if (!normalized.includes('\\')) {
8
+ return normalized;
9
+ }
10
+ if (normalized === '\\') {
11
+ return '/';
12
+ }
13
+ if (normalized.length <= 1) {
14
+ return normalized;
15
+ }
16
+ let prefix = '';
17
+ if (normalized.length > 4 && normalized[0] === '\\' && normalized[1] === '\\' && normalized[3] === '\\') {
18
+ const ch = normalized[2];
19
+ if ((ch === '?' || ch === '.')) {
20
+ normalized = normalized.slice(2);
21
+ prefix = '//';
22
+ }
23
+ }
24
+ return prefix + normalized.split(/[/\\]+/).join('/');
25
+ };
26
+ }
@@ -1,37 +1,38 @@
1
1
  import opath from 'node:path';
2
2
  import { absolute } from './absolute.mjs';
3
+ import { buildExt } from './ext/index.mjs';
3
4
  import { isInDir } from './is-in-dir.mjs';
4
- // eslint-disable-next-line unicorn/prevent-abbreviations
5
5
  import { isInDirs } from './is-in-dirs.mjs';
6
6
  import { isSafePath } from './is-safe-path.mjs';
7
7
  import { isSafeSegment } from './is-safe-segment.mjs';
8
8
  import { join } from './join.mjs';
9
- // eslint-disable-next-line unicorn/prevent-abbreviations
10
- import { leafExt } from './leaf-ext.mjs';
11
9
  import { leafName } from './leaf-name.mjs';
10
+ import { normalize } from './normalize.mjs';
12
11
  import { parentName } from './parent-name.mjs';
13
12
  import { parentPath } from './parent-path.mjs';
14
13
  import { resolve } from './resolve.mjs';
15
14
  import { sanitize } from './sanitize.mjs';
16
15
  import { untildify } from './untildify.mjs';
17
16
  function buildPlatform(path) {
18
- const { delimiter, isAbsolute, normalize, relative, sep: separator, } = path;
17
+ const { delimiter, isAbsolute, relative, sep: separator, } = path;
19
18
  const result = {
20
19
  delimiter,
21
20
  separator,
22
21
  isAbsolute,
23
22
  matchesGlob: path.matchesGlob ?? undefined,
24
- normalize,
25
23
  relative,
26
24
  };
25
+ const ext = buildExt(path, result);
27
26
  result.absolute = absolute(path, result);
27
+ result.ext = ext;
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.leafExt = leafExt(path, result);
33
+ result.leafExt = ext.get;
34
34
  result.leafName = leafName(path, result);
35
+ result.normalize = normalize(path, result);
35
36
  result.parentName = parentName(path, result);
36
37
  result.parentPath = parentPath(path, result);
37
38
  result.resolve = resolve(path, result);
@@ -1,11 +1,24 @@
1
1
  import { type Target } from '@zokugun/fs-path-sanitize';
2
2
  import { type DResult } from '@zokugun/xtry';
3
+ export type ExtOptions = {
4
+ depth?: number;
5
+ ignore?: string[];
6
+ maxLength?: number;
7
+ };
3
8
  export type PlatformPath = {
4
9
  readonly delimiter: ';' | ':';
5
10
  readonly separator: '\\' | '/';
6
11
  readonly posix: PlatformPath;
7
12
  readonly win32: PlatformPath;
8
13
  absolute: (...paths: string[]) => string;
14
+ ext: {
15
+ add: (path: string, ext: string) => string;
16
+ ensure: (path: string, ext: string, options?: ExtOptions) => string;
17
+ get: (path: string, depth?: number) => string;
18
+ remove: (path: string, ext: string) => string;
19
+ replace: (path: string, ext: string, options?: ExtOptions) => string;
20
+ trim: (path: string, options?: ExtOptions) => string;
21
+ };
9
22
  isAbsolute: (path: string) => boolean;
10
23
  isInDir: (path: string, dir: string) => boolean;
11
24
  isInDirs: (path: string, directories: string[]) => boolean;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zokugun/fs-path",
3
3
  "description": "Path utilities complementing the builtin path module",
4
- "version": "0.2.2",
4
+ "version": "0.3.0",
5
5
  "author": {
6
6
  "name": "Baptiste Augrain",
7
7
  "email": "daiyam@zokugun.org"
@@ -47,7 +47,7 @@
47
47
  "watch:test": "tsc-watch -p test"
48
48
  },
49
49
  "dependencies": {
50
- "@zokugun/fs-path-sanitize": "0.2.1",
50
+ "@zokugun/fs-path-sanitize": "0.2.2",
51
51
  "@zokugun/is-it-type": "0.8.1",
52
52
  "@zokugun/xtry": "0.12.2"
53
53
  },
@@ -1,3 +0,0 @@
1
- import type path from 'node:path';
2
- import { type PlatformPath } from './types.cjs';
3
- export declare function leafExt(nodePath: path.PlatformPath, _localPath: PlatformPath): (path: string, length?: number) => string;
@@ -1,3 +0,0 @@
1
- import type path from 'node:path';
2
- import { type PlatformPath } from './types.mjs';
3
- export declare function leafExt(nodePath: path.PlatformPath, _localPath: PlatformPath): (path: string, length?: number) => string;