@stryke/path 0.10.2 → 0.12.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/file-path-fns.d.ts +4 -2
- package/dist/index.cjs +11 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +1 -1
- package/dist/is-parent-path.cjs +12 -0
- package/dist/is-parent-path.d.ts +22 -0
- package/dist/is-parent-path.mjs +1 -0
- package/dist/replace.cjs +3 -2
- package/dist/replace.d.ts +4 -4
- package/dist/replace.mjs +1 -1
- package/package.json +16 -2
package/dist/file-path-fns.d.ts
CHANGED
|
@@ -29,6 +29,9 @@ export declare function findFileName(filePath: string, options?: FindFileNameOpt
|
|
|
29
29
|
/**
|
|
30
30
|
* Find the full file path's directories from a file path.
|
|
31
31
|
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* The functionality of this method is similar to the {@link path.dirname} function in Node's path module.
|
|
34
|
+
*
|
|
32
35
|
* @example
|
|
33
36
|
* ```ts
|
|
34
37
|
* const folderPath = findFilePath("C:\\Users\\user\\Documents\\file.txt");
|
|
@@ -43,9 +46,8 @@ export declare function findFilePath(filePath: string): string;
|
|
|
43
46
|
* Find the top most folder containing the file from a file path.
|
|
44
47
|
*
|
|
45
48
|
* @remarks
|
|
46
|
-
* If you're looking for the full path of the folder (for example: `C:\\Users\\user\\Documents` instead of just `Documents`) containing the file, use {@link findFilePath} instead.
|
|
47
|
-
*
|
|
48
49
|
* The functionality of this method is similar to the {@link path.basename} function in Node's path module.
|
|
50
|
+
* If you're looking for the full path of the folder (for example: `C:\\Users\\user\\Documents` instead of just `Documents`) containing the file, use {@link findFilePath} instead.
|
|
49
51
|
*
|
|
50
52
|
* @example
|
|
51
53
|
* const folderPath = findFolderName("C:\\Users\\user\\Documents\\file.txt");
|
package/dist/index.cjs
CHANGED
|
@@ -91,6 +91,17 @@ Object.keys(_isFile).forEach(function (key) {
|
|
|
91
91
|
}
|
|
92
92
|
});
|
|
93
93
|
});
|
|
94
|
+
var _isParentPath = require("./is-parent-path.cjs");
|
|
95
|
+
Object.keys(_isParentPath).forEach(function (key) {
|
|
96
|
+
if (key === "default" || key === "__esModule") return;
|
|
97
|
+
if (key in exports && exports[key] === _isParentPath[key]) return;
|
|
98
|
+
Object.defineProperty(exports, key, {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function () {
|
|
101
|
+
return _isParentPath[key];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
94
105
|
var _isRootDir = require("./is-root-dir.cjs");
|
|
95
106
|
Object.keys(_isRootDir).forEach(function (key) {
|
|
96
107
|
if (key === "default" || key === "__esModule") return;
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export * from "./file-path-fns";
|
|
|
14
14
|
export * from "./get-parent-path";
|
|
15
15
|
export * from "./get-workspace-root";
|
|
16
16
|
export * from "./is-file";
|
|
17
|
+
export * from "./is-parent-path";
|
|
17
18
|
export * from "./is-root-dir";
|
|
18
19
|
export * from "./join-paths";
|
|
19
20
|
export * from "./regex";
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./asset-extensions";export*from"./correct-path";export*from"./delimiter";export*from"./exists";export*from"./file-path-fns";export*from"./get-parent-path";export*from"./get-workspace-root";export*from"./is-file";export*from"./is-root-dir";export*from"./join-paths";export*from"./regex";export*from"./replace";export*from"./resolve";export*from"./slash";
|
|
1
|
+
export*from"./asset-extensions";export*from"./correct-path";export*from"./delimiter";export*from"./exists";export*from"./file-path-fns";export*from"./get-parent-path";export*from"./get-workspace-root";export*from"./is-file";export*from"./is-parent-path";export*from"./is-root-dir";export*from"./join-paths";export*from"./regex";export*from"./replace";export*from"./resolve";export*from"./slash";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isParentPath = isParentPath;
|
|
7
|
+
var _slash = require("./slash.cjs");
|
|
8
|
+
function isParentPath(a, n) {
|
|
9
|
+
const r = (0, _slash.slash)(a.replace(/\\/g, "/").replace(/\/$/, "")),
|
|
10
|
+
e = (0, _slash.slash)(n.replace(/\\/g, "/").replace(/\/$/, ""));
|
|
11
|
+
return r !== e && r.startsWith(`${e}/`);
|
|
12
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a given path is a parent of another path.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* isParentPath("/home/user/project/src/index.ts", "/home/user/project/src");
|
|
7
|
+
* // returns true
|
|
8
|
+
* isParentPath("/home/user/project/src/index.ts", "/home/user/project");
|
|
9
|
+
* // returns true
|
|
10
|
+
* isParentPath("/home/user/project/src/index.ts", "/home/user/project/src/other");
|
|
11
|
+
* // returns false
|
|
12
|
+
* isParentPath("/home/user/project/src/index.ts", "/home/user/other");
|
|
13
|
+
* // returns false
|
|
14
|
+
* isParentPath("/home/user/project/src/index.ts", "/home/user/project/src/index.ts");
|
|
15
|
+
* // returns false
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param childPath - The path to check if it is a child of the parent path.
|
|
19
|
+
* @param parentPath - The path to check if it is a parent of the child path.
|
|
20
|
+
* @returns `true` if `childPath` is a child of `parentPath`, otherwise `false`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function isParentPath(childPath: string, parentPath: string): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{slash as t}from"./slash";export function isParentPath(a,n){const r=t(a.replace(/\\/g,"/").replace(/\/$/,"")),e=t(n.replace(/\\/g,"/").replace(/\/$/,""));return r!==e&&r.startsWith(`${e}/`)}
|
package/dist/replace.cjs
CHANGED
|
@@ -4,7 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.replacePath = replacePath;
|
|
7
|
+
var _isParentPath = require("./is-parent-path.cjs");
|
|
7
8
|
var _slash = require("./slash.cjs");
|
|
8
|
-
function replacePath(
|
|
9
|
-
return (0, _slash.slash)(
|
|
9
|
+
function replacePath(r, e = process.cwd()) {
|
|
10
|
+
return (0, _isParentPath.isParentPath)(r, e) ? (0, _slash.slash)(r).replace((0, _slash.slash)(e), "").replace(/^\//, "") : r;
|
|
10
11
|
}
|
package/dist/replace.d.ts
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* // returns "src/index.ts"
|
|
8
8
|
* ```
|
|
9
9
|
*
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
12
|
-
* @returns The {@link
|
|
10
|
+
* @param childPath - The child path to replace the {@link parentPath} substring from
|
|
11
|
+
* @param parentPath - The parent path to remove from the {@link childPath} parameter
|
|
12
|
+
* @returns The {@link childPath} with the {@link parentPath} path removed
|
|
13
13
|
*/
|
|
14
|
-
export declare function replacePath(
|
|
14
|
+
export declare function replacePath(childPath: string, parentPath?: string): string;
|
package/dist/replace.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{slash as
|
|
1
|
+
import{isParentPath as o}from"./is-parent-path";import{slash as s}from"./slash";export function replacePath(r,e=process.cwd()){return o(r,e)?s(r).replace(s(e),"").replace(/^\//,""):r}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/path",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.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": {
|
|
@@ -127,6 +127,20 @@
|
|
|
127
127
|
"default": "./dist/is-root-dir.mjs"
|
|
128
128
|
}
|
|
129
129
|
},
|
|
130
|
+
"./is-parent-path": {
|
|
131
|
+
"import": {
|
|
132
|
+
"types": "./dist/is-parent-path.d.ts",
|
|
133
|
+
"default": "./dist/is-parent-path.mjs"
|
|
134
|
+
},
|
|
135
|
+
"require": {
|
|
136
|
+
"types": "./dist/is-parent-path.d.ts",
|
|
137
|
+
"default": "./dist/is-parent-path.cjs"
|
|
138
|
+
},
|
|
139
|
+
"default": {
|
|
140
|
+
"types": "./dist/is-parent-path.d.ts",
|
|
141
|
+
"default": "./dist/is-parent-path.mjs"
|
|
142
|
+
}
|
|
143
|
+
},
|
|
130
144
|
"./is-file": {
|
|
131
145
|
"import": {
|
|
132
146
|
"types": "./dist/is-file.d.ts",
|
|
@@ -260,5 +274,5 @@
|
|
|
260
274
|
"main": "./dist/index.cjs",
|
|
261
275
|
"module": "./dist/index.mjs",
|
|
262
276
|
"types": "./dist/index.d.ts",
|
|
263
|
-
"gitHead": "
|
|
277
|
+
"gitHead": "763abdbc096331d500df3ebb7a7e4387335c0d62"
|
|
264
278
|
}
|