@stryke/path 0.15.5 → 0.17.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/dist/index.cjs CHANGED
@@ -69,17 +69,6 @@ Object.keys(_filePathFns).forEach(function (key) {
69
69
  }
70
70
  });
71
71
  });
72
- var _getParentPath = require("./get-parent-path.cjs");
73
- Object.keys(_getParentPath).forEach(function (key) {
74
- if (key === "default" || key === "__esModule") return;
75
- if (key in exports && exports[key] === _getParentPath[key]) return;
76
- Object.defineProperty(exports, key, {
77
- enumerable: true,
78
- get: function () {
79
- return _getParentPath[key];
80
- }
81
- });
82
- });
83
72
  var _isParentPath = require("./is-parent-path.cjs");
84
73
  Object.keys(_isParentPath).forEach(function (key) {
85
74
  if (key === "default" || key === "__esModule") return;
@@ -135,6 +124,17 @@ Object.keys(_replace).forEach(function (key) {
135
124
  }
136
125
  });
137
126
  });
127
+ var _resolveParentPath = require("./resolve-parent-path.cjs");
128
+ Object.keys(_resolveParentPath).forEach(function (key) {
129
+ if (key === "default" || key === "__esModule") return;
130
+ if (key in exports && exports[key] === _resolveParentPath[key]) return;
131
+ Object.defineProperty(exports, key, {
132
+ enumerable: true,
133
+ get: function () {
134
+ return _resolveParentPath[key];
135
+ }
136
+ });
137
+ });
138
138
  var _slash = require("./slash.cjs");
139
139
  Object.keys(_slash).forEach(function (key) {
140
140
  if (key === "default" || key === "__esModule") return;
package/dist/index.d.ts CHANGED
@@ -12,10 +12,10 @@ export * from "./correct-path";
12
12
  export * from "./cwd";
13
13
  export * from "./delimiter";
14
14
  export * from "./file-path-fns";
15
- export * from "./get-parent-path";
16
15
  export * from "./is-parent-path";
17
16
  export * from "./is-root-dir";
18
17
  export * from "./join-paths";
19
18
  export * from "./regex";
20
19
  export * from "./replace";
20
+ export * from "./resolve-parent-path";
21
21
  export * from "./slash";
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export*from"./append";export*from"./asset-extensions";export*from"./correct-path";export*from"./cwd";export*from"./delimiter";export*from"./file-path-fns";export*from"./get-parent-path";export*from"./is-parent-path";export*from"./is-root-dir";export*from"./join-paths";export*from"./regex";export*from"./replace";export*from"./slash";
1
+ export*from"./append";export*from"./asset-extensions";export*from"./correct-path";export*from"./cwd";export*from"./delimiter";export*from"./file-path-fns";export*from"./is-parent-path";export*from"./is-root-dir";export*from"./join-paths";export*from"./regex";export*from"./replace";export*from"./resolve-parent-path";export*from"./slash";
package/dist/replace.cjs CHANGED
@@ -3,10 +3,15 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.replaceExtension = replaceExtension;
6
7
  exports.replacePath = replacePath;
7
8
  var _cwd = require("./cwd.cjs");
9
+ var _filePathFns = require("./file-path-fns.cjs");
8
10
  var _isParentPath = require("./is-parent-path.cjs");
9
11
  var _slash = require("./slash.cjs");
10
- function replacePath(r, e = (0, _cwd.cwd)()) {
11
- return (0, _isParentPath.isParentPath)(r, e) ? (0, _slash.slash)(r).replace((0, _slash.slash)(e), "").replace(/^\//, "") : r;
12
+ function replacePath(r, i = (0, _cwd.cwd)()) {
13
+ return (0, _isParentPath.isParentPath)(r, i) ? (0, _slash.slash)(r).replace((0, _slash.slash)(i), "").replace(/^\//, "") : r;
14
+ }
15
+ function replaceExtension(r, i = "") {
16
+ return r.replace(!i || i.includes(".") ? (0, _filePathFns.findFileDotExtensionSafe)(r) : (0, _filePathFns.findFileExtensionSafe)(r), i);
12
17
  }
package/dist/replace.d.ts CHANGED
@@ -12,3 +12,19 @@
12
12
  * @returns The {@link childPath} with the {@link parentPath} path removed
13
13
  */
14
14
  export declare function replacePath(childPath: string, parentPath?: string): string;
15
+ /**
16
+ * Replace the extension of a given path with the provided value.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * replaceExtension("/home/user/project/src/index.ts", ".js");
21
+ * // returns "/home/user/project/src/index.js"
22
+ * replaceExtension("/home/user/project/src/index.ts");
23
+ * // returns "/home/user/project/src/index"
24
+ * ```
25
+ *
26
+ * @param path - The path that will have its current extension replaced
27
+ * @param replacement - The value (or an empty string) to replace the current extension with
28
+ * @returns The path with the replaced extension
29
+ */
30
+ export declare function replaceExtension(path: string, replacement?: string): string;
package/dist/replace.mjs CHANGED
@@ -1 +1 @@
1
- import{cwd as t}from"./cwd";import{isParentPath as i}from"./is-parent-path";import{slash as o}from"./slash";export function replacePath(r,e=t()){return i(r,e)?o(r).replace(o(e),"").replace(/^\//,""):r}
1
+ import{cwd as e}from"./cwd";import{findFileDotExtensionSafe as o,findFileExtensionSafe as t}from"./file-path-fns";import{isParentPath as s}from"./is-parent-path";import{slash as n}from"./slash";export function replacePath(r,i=e()){return s(r,i)?n(r).replace(n(i),"").replace(/^\//,""):r}export function replaceExtension(r,i=""){return r.replace(!i||i.includes(".")?o(r):t(r),i)}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.resolveParentPath = void 0;
7
+ var _joinPaths = require("./join-paths.cjs");
8
+ const resolveParentPath = (e, n = 1) => {
9
+ let r = e.replaceAll(/\/+$/g, "");
10
+ for (let t = 0; t < n; t++) r = (0, _joinPaths.joinPaths)(r, "..");
11
+ return r;
12
+ };
13
+ exports.resolveParentPath = resolveParentPath;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Resolve the parent path of the provided path.
3
+ *
4
+ * @param path - The path to resolve.
5
+ * @param count - The number of parent directories to traverse.
6
+ * @returns The parent path of the provided path.
7
+ */
8
+ export declare const resolveParentPath: (path: string, count?: number) => string;
@@ -0,0 +1 @@
1
+ import{joinPaths as o}from"./join-paths";export const resolveParentPath=(e,n=1)=>{let r=e.replaceAll(/\/+$/g,"");for(let t=0;t<n;t++)r=o(r,"..");return r};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/path",
3
- "version": "0.15.5",
3
+ "version": "0.17.0",
4
4
  "type": "module",
5
5
  "description": "A package containing various utilities that expand the functionality of NodeJs's built-in `path` module",
6
6
  "repository": {
@@ -10,6 +10,7 @@
10
10
  },
11
11
  "private": false,
12
12
  "devDependencies": {
13
+ "@stryke/convert": "^0.6.0",
13
14
  "@stryke/type-checks": "^0.3.10",
14
15
  "@stryke/types": "^0.10.0"
15
16
  },
@@ -66,6 +67,20 @@
66
67
  },
67
68
  "default": { "types": "./dist/slash.d.ts", "default": "./dist/slash.mjs" }
68
69
  },
70
+ "./resolve-parent-path": {
71
+ "import": {
72
+ "types": "./dist/resolve-parent-path.d.ts",
73
+ "default": "./dist/resolve-parent-path.mjs"
74
+ },
75
+ "require": {
76
+ "types": "./dist/resolve-parent-path.d.ts",
77
+ "default": "./dist/resolve-parent-path.cjs"
78
+ },
79
+ "default": {
80
+ "types": "./dist/resolve-parent-path.d.ts",
81
+ "default": "./dist/resolve-parent-path.mjs"
82
+ }
83
+ },
69
84
  "./replace": {
70
85
  "import": {
71
86
  "types": "./dist/replace.d.ts",
@@ -171,20 +186,6 @@
171
186
  },
172
187
  "default": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" }
173
188
  },
174
- "./get-parent-path": {
175
- "import": {
176
- "types": "./dist/get-parent-path.d.ts",
177
- "default": "./dist/get-parent-path.mjs"
178
- },
179
- "require": {
180
- "types": "./dist/get-parent-path.d.ts",
181
- "default": "./dist/get-parent-path.cjs"
182
- },
183
- "default": {
184
- "types": "./dist/get-parent-path.d.ts",
185
- "default": "./dist/get-parent-path.mjs"
186
- }
187
- },
188
189
  "./find": {
189
190
  "import": { "types": "./dist/find.d.ts", "default": "./dist/find.mjs" },
190
191
  "require": { "types": "./dist/find.d.ts", "default": "./dist/find.cjs" },
@@ -278,5 +279,5 @@
278
279
  "main": "./dist/index.cjs",
279
280
  "module": "./dist/index.mjs",
280
281
  "types": "./dist/index.d.ts",
281
- "gitHead": "6a9aee3710da08beb510066d00f66d7863102cd2"
282
+ "gitHead": "b7c19085be057c7a239682d125c26a6e468c8b9d"
282
283
  }
@@ -1,29 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.resolveParentPath = exports.getParentPath = void 0;
7
- var _cwd = require("./cwd.cjs");
8
- var _joinPaths = require("./join-paths.cjs");
9
- const resolveParentPath = (r, n = 1) => {
10
- let t = r.replaceAll(/\/+$/g, "");
11
- for (let i = 0; i < n; i++) t = (0, _joinPaths.joinPaths)(t, "..");
12
- return t;
13
- },
14
- getParentPath = (r, n = (0, _cwd.cwd)(), t = {}) => {
15
- const i = t?.ignoreCase ?? !0,
16
- p = t?.skipCwd ?? !1;
17
- let e = n;
18
- p && (e = resolveParentPath(n));
19
- let o = Array.isArray(r) ? r : [r];
20
- for (i && (o = o.map(a => a.toLowerCase()));;) {
21
- const a = o.find(f => (0, _joinPaths.joinPaths)(e, f));
22
- if (a) return (0, _joinPaths.joinPaths)(e, a);
23
- const l = resolveParentPath(e);
24
- if (l === e) return;
25
- e = l;
26
- }
27
- };
28
- exports.getParentPath = getParentPath;
29
- exports.resolveParentPath = resolveParentPath;
@@ -1,39 +0,0 @@
1
- /**
2
- * Resolve the parent path of the provided path.
3
- *
4
- * @param path - The path to resolve.
5
- * @param count - The number of parent directories to traverse.
6
- * @returns The parent path of the provided path.
7
- */
8
- export declare const resolveParentPath: (path: string, count?: number) => string;
9
- /**
10
- * Options for the `getParentPath` function.
11
- */
12
- export interface GetParentPathOptions {
13
- /**
14
- * Whether to ignore the case of the file names when checking for existence.
15
- *
16
- * @defaultValue true
17
- */
18
- ignoreCase: boolean;
19
- /**
20
- * Whether to skip the current working directory when checking for the file.
21
- *
22
- * @defaultValue false
23
- */
24
- skipCwd: boolean;
25
- /**
26
- * The type of target to look for.
27
- *
28
- * @defaultValue "both"
29
- */
30
- targetType: "file" | "directory" | "both";
31
- }
32
- /**
33
- * Get the first parent path that has a file or directory with the provided name.
34
- *
35
- * @param name - The name (or names) of the file to look for in the parent paths.
36
- * @param cwd - The current working directory.
37
- * @returns The first parent path that exists.
38
- */
39
- export declare const getParentPath: (name: string | string[], cwd?: string, options?: Partial<GetParentPathOptions>) => string | undefined;
@@ -1 +0,0 @@
1
- import{cwd as g}from"./cwd";import{joinPaths as s}from"./join-paths";export const resolveParentPath=(r,n=1)=>{let t=r.replaceAll(/\/+$/g,"");for(let i=0;i<n;i++)t=s(t,"..");return t},getParentPath=(r,n=g(),t={})=>{const i=t?.ignoreCase??!0,p=t?.skipCwd??!1;let e=n;p&&(e=resolveParentPath(n));let o=Array.isArray(r)?r:[r];for(i&&(o=o.map(a=>a.toLowerCase()));;){const a=o.find(f=>s(e,f));if(a)return s(e,a);const l=resolveParentPath(e);if(l===e)return;e=l}};