@stryke/path 0.13.1 → 0.14.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/append.cjs +13 -0
- package/dist/append.d.ts +14 -0
- package/dist/append.mjs +1 -0
- package/dist/file-path-fns.cjs +3 -0
- package/dist/file-path-fns.d.ts +2 -0
- package/dist/file-path-fns.mjs +1 -1
- package/dist/index.cjs +11 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +1 -1
- package/dist/join-paths.cjs +2 -0
- package/dist/join-paths.d.ts +1 -0
- package/dist/join-paths.mjs +1 -1
- package/package.json +16 -2
package/dist/append.cjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.appendPath = appendPath;
|
|
7
|
+
var _cwd = require("./cwd.cjs");
|
|
8
|
+
var _isParentPath = require("./is-parent-path.cjs");
|
|
9
|
+
var _joinPaths = require("./join-paths.cjs");
|
|
10
|
+
var _slash = require("./slash.cjs");
|
|
11
|
+
function appendPath(r, o = (0, _cwd.cwd)()) {
|
|
12
|
+
return (0, _slash.slash)((0, _isParentPath.isParentPath)(r, o) ? (0, _joinPaths.joinPaths)(r, o) : r);
|
|
13
|
+
}
|
package/dist/append.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Append the base path from the beginning of the given path.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* appendPath("/home/user/project/src/index.ts", "/home/user/project");
|
|
7
|
+
* // returns "src/index.ts"
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* @param childPath - The child path to append to the {@link parentPath}
|
|
11
|
+
* @param parentPath - The parent path to add the {@link childPath} to
|
|
12
|
+
* @returns The {@link parentPath} with the {@link childPath} appended
|
|
13
|
+
*/
|
|
14
|
+
export declare function appendPath(childPath: string, parentPath?: string): string;
|
package/dist/append.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{cwd as t}from"./cwd";import{isParentPath as i}from"./is-parent-path";import{joinPaths as m}from"./join-paths";import{slash as n}from"./slash";export function appendPath(r,o=t()){return n(i(r,o)?m(r,o):r)}
|
package/dist/file-path-fns.cjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.dirname = exports.basename = void 0;
|
|
6
7
|
exports.findFileExtension = findFileExtension;
|
|
7
8
|
exports.findFileExtensionSafe = findFileExtensionSafe;
|
|
8
9
|
exports.findFileName = findFileName;
|
|
@@ -41,6 +42,7 @@ function findFilePath(e) {
|
|
|
41
42
|
}), "");
|
|
42
43
|
return r === "/" ? r : r.replace(/\/$/, "");
|
|
43
44
|
}
|
|
45
|
+
const dirname = exports.dirname = findFilePath;
|
|
44
46
|
function findFolderName(e) {
|
|
45
47
|
const t = findFilePath(e).split("/");
|
|
46
48
|
let r = "";
|
|
@@ -53,6 +55,7 @@ function findFolderName(e) {
|
|
|
53
55
|
}
|
|
54
56
|
return r ?? _base.EMPTY_STRING;
|
|
55
57
|
}
|
|
58
|
+
const basename = exports.basename = findFolderName;
|
|
56
59
|
function findFileExtension(e) {
|
|
57
60
|
if (e.endsWith(".") || e.endsWith("/")) return;
|
|
58
61
|
const t = /.(\.[^./]+|\.)$/.exec((0, _correctPath.normalizeWindowsPath)(e));
|
package/dist/file-path-fns.d.ts
CHANGED
|
@@ -42,6 +42,7 @@ export declare function findFileName(filePath: string, options?: FindFileNameOpt
|
|
|
42
42
|
* @returns The full file path's directories
|
|
43
43
|
*/
|
|
44
44
|
export declare function findFilePath(filePath: string): string;
|
|
45
|
+
export declare const dirname: typeof findFilePath;
|
|
45
46
|
/**
|
|
46
47
|
* Find the top most folder containing the file from a file path.
|
|
47
48
|
*
|
|
@@ -57,6 +58,7 @@ export declare function findFilePath(filePath: string): string;
|
|
|
57
58
|
* @returns The folder containing the file
|
|
58
59
|
*/
|
|
59
60
|
export declare function findFolderName(filePath: string): string;
|
|
61
|
+
export declare const basename: typeof findFolderName;
|
|
60
62
|
/**
|
|
61
63
|
* Find the file extension from a file path.
|
|
62
64
|
*
|
package/dist/file-path-fns.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EMPTY_STRING as
|
|
1
|
+
import{EMPTY_STRING as a}from"@stryke/types/base";import{normalizeString as g,normalizeWindowsPath as l}from"./correct-path";import{cwd as u}from"./cwd";import{isAbsolute as p,isAbsolutePath as c}from"./is-type";import{joinPaths as f}from"./join-paths";import{ROOT_FOLDER_REGEX as x}from"./regex";export function findFileName(e,t={}){const{requireExtension:r=!1,withExtension:n=!0}=t,i=l(e)?.split(e?.includes("\\")?"\\":"/")?.pop()??"";return r===!0&&!i.includes(".")?a:n===!1&&i.includes(".")?i.substring(0,i.lastIndexOf("."))||a:i}export function findFilePath(e){const t=l(e),r=t.replace(findFileName(t,{requireExtension:!0}),"");return r==="/"?r:r.replace(/\/$/,"")}export const dirname=findFilePath;export function findFolderName(e){const t=findFilePath(e).split("/");let r="";for(let n=t.length-1;n>=0;n--){const i=t[n];if(i){r=i;break}}return r??a}export const basename=findFolderName;export function findFileExtension(e){if(e.endsWith(".")||e.endsWith("/"))return;const t=/.(\.[^./]+|\.)$/.exec(l(e));return t&&t[1]||void 0}export function findFileExtensionSafe(e){return findFileExtension(e)??a}export function hasFileName(e){return!!findFileName(e)}export function hasFilePath(e){return!!findFilePath(e)}export function hasFolderName(e){return!!findFolderName(e)}export function hasFileExtension(e){return!!findFileExtension(e)}export function resolvePath(e,t=u()){const r=l(e).split("/");let n="",i=!1;for(let o=r.length-1;o>=-1&&!i;o--){const s=o>=0?r[o]:t;!s||s.length===0||(n=f(s,n),i=c(s))}return n=g(n,!i),i&&!c(n)?`/${n}`:n.length>0?n:"."}export function resolve(...e){e=e.map(n=>l(n));let t="",r=!1;for(let n=e.length-1;n>=-1&&!r;n--){const i=n>=0?e[n]:u();!i||i.length===0||(t=`${i}/${t}`,r=p(i))}return t=g(t,!r),r&&!p(t)?`/${t}`:t.length>0?t:"."}export function resolvePaths(...e){return resolvePath(f(...e.map(t=>l(t))))}export function relative(e,t){const r=resolve(e).replace(x,"$1").split("/"),n=resolve(t).replace(x,"$1").split("/");if(n[0][1]===":"&&r[0][1]===":"&&r[0]!==n[0])return n.join("/");const i=[...r];for(const o of i){if(n[0]!==o)break;r.shift(),n.shift()}return[...r.map(()=>".."),...n].join("/")}export function relativePath(e,t,r=!1){return relative(r!==!0?e.replace(/\/$/,""):e,r!==!0?t.replace(/\/$/,""):t)}export function relativeToCurrentDir(e){return relativePath(e,u())}export function parsePath(e){const t=/^[/\\]|^[a-z]:[/\\]/i.exec(e)?.[0]?.replace(/\\/g,"/")||"",r=l(e),n=r.replace(/\/$/,"").split("/").slice(0,-1);n.length===1&&/^[A-Z]:$/i.test(n[0])&&(n[0]+="/");const i=findFolderName(r),o=n.join("/")||(c(e)?"/":"."),s=findFileExtensionSafe(e);return{root:t,dir:o,base:i,ext:s,name:i.slice(0,i.length-s.length)}}export function renameFile(e,t){const r=parsePath(e);return f(r.dir,t.includes(".")?t:t+r.ext)}
|
package/dist/index.cjs
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _append = require("./append.cjs");
|
|
7
|
+
Object.keys(_append).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _append[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _append[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
6
17
|
var _assetExtensions = require("./asset-extensions.cjs");
|
|
7
18
|
Object.keys(_assetExtensions).forEach(function (key) {
|
|
8
19
|
if (key === "default" || key === "__esModule") return;
|
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
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"./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";
|
package/dist/join-paths.cjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.join = void 0;
|
|
6
7
|
exports.joinPaths = joinPaths;
|
|
7
8
|
var _isType = require("./is-type.cjs");
|
|
8
9
|
var _regex = require("./regex.cjs");
|
|
@@ -26,6 +27,7 @@ function joinPaths(...n) {
|
|
|
26
27
|
} else t += e;
|
|
27
28
|
return R(t);
|
|
28
29
|
}
|
|
30
|
+
const join = exports.join = joinPaths;
|
|
29
31
|
function a(n, t) {
|
|
30
32
|
let e = "",
|
|
31
33
|
l = 0,
|
package/dist/join-paths.d.ts
CHANGED
package/dist/join-paths.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isAbsolute as g}from"./is-type";import{DRIVE_LETTER_REGEX as c,DRIVE_LETTER_START_REGEX as u,UNC_REGEX as E}from"./regex";function m(n=""){return n&&n.replace(/\\/g,"/").replace(u,t=>t.toUpperCase())}function R(n){if(!n||n.length===0)return".";n=m(n);const t=n.match(E),e=g(n),l=n[n.length-1]==="/";return n=a(n,!e),n.length===0?e?"/":l?"./":".":(l&&(n+="/"),c.test(n)&&(n+="/"),t?e?`//${n}`:`//./${n}`:e&&!g(n)?`/${n}`:n)}export function joinPaths(...n){let t="";for(const e of n)if(e)if(t.length>0){const l=t[t.length-1]==="/",s=e[0]==="/";l&&s?t+=e.slice(1):t+=l||s?e:`/${e}`}else t+=e;return R(t)}function a(n,t){let e="",l=0,s=-1,r=0,o=null;for(let i=0;i<=n.length;++i){if(i<n.length)o=n[i];else{if(o==="/")break;o="/"}if(o==="/"){if(!(s===i-1||r===1))if(r===2){if(e.length<2||l!==2||e[e.length-1]!=="."||e[e.length-2]!=="."){if(e.length>2){const f=e.lastIndexOf("/");f===-1?(e="",l=0):(e=e.slice(0,f),l=e.length-1-e.lastIndexOf("/")),s=i,r=0;continue}else if(e.length>0){e="",l=0,s=i,r=0;continue}}t&&(e+=e.length>0?"/..":"..",l=2)}else e.length>0?e+=`/${n.slice(s+1,i)}`:e=n.slice(s+1,i),l=i-s-1;s=i,r=0}else o==="."&&r!==-1?++r:r=-1}return e}
|
|
1
|
+
import{isAbsolute as g}from"./is-type";import{DRIVE_LETTER_REGEX as c,DRIVE_LETTER_START_REGEX as u,UNC_REGEX as E}from"./regex";function m(n=""){return n&&n.replace(/\\/g,"/").replace(u,t=>t.toUpperCase())}function R(n){if(!n||n.length===0)return".";n=m(n);const t=n.match(E),e=g(n),l=n[n.length-1]==="/";return n=a(n,!e),n.length===0?e?"/":l?"./":".":(l&&(n+="/"),c.test(n)&&(n+="/"),t?e?`//${n}`:`//./${n}`:e&&!g(n)?`/${n}`:n)}export function joinPaths(...n){let t="";for(const e of n)if(e)if(t.length>0){const l=t[t.length-1]==="/",s=e[0]==="/";l&&s?t+=e.slice(1):t+=l||s?e:`/${e}`}else t+=e;return R(t)}export const join=joinPaths;function a(n,t){let e="",l=0,s=-1,r=0,o=null;for(let i=0;i<=n.length;++i){if(i<n.length)o=n[i];else{if(o==="/")break;o="/"}if(o==="/"){if(!(s===i-1||r===1))if(r===2){if(e.length<2||l!==2||e[e.length-1]!=="."||e[e.length-2]!=="."){if(e.length>2){const f=e.lastIndexOf("/");f===-1?(e="",l=0):(e=e.slice(0,f),l=e.length-1-e.lastIndexOf("/")),s=i,r=0;continue}else if(e.length>0){e="",l=0,s=i,r=0;continue}}t&&(e+=e.length>0?"/..":"..",l=2)}else e.length>0?e+=`/${n.slice(s+1,i)}`:e=n.slice(s+1,i),l=i-s-1;s=i,r=0}else o==="."&&r!==-1?++r:r=-1}return e}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/path",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.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": {
|
|
@@ -224,6 +224,20 @@
|
|
|
224
224
|
"default": "./dist/asset-extensions.mjs"
|
|
225
225
|
}
|
|
226
226
|
},
|
|
227
|
+
"./append": {
|
|
228
|
+
"import": {
|
|
229
|
+
"types": "./dist/append.d.ts",
|
|
230
|
+
"default": "./dist/append.mjs"
|
|
231
|
+
},
|
|
232
|
+
"require": {
|
|
233
|
+
"types": "./dist/append.d.ts",
|
|
234
|
+
"default": "./dist/append.cjs"
|
|
235
|
+
},
|
|
236
|
+
"default": {
|
|
237
|
+
"types": "./dist/append.d.ts",
|
|
238
|
+
"default": "./dist/append.mjs"
|
|
239
|
+
}
|
|
240
|
+
},
|
|
227
241
|
".": {
|
|
228
242
|
"import": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" },
|
|
229
243
|
"require": {
|
|
@@ -237,5 +251,5 @@
|
|
|
237
251
|
"main": "./dist/index.cjs",
|
|
238
252
|
"module": "./dist/index.mjs",
|
|
239
253
|
"types": "./dist/index.d.ts",
|
|
240
|
-
"gitHead": "
|
|
254
|
+
"gitHead": "4cae447b5b6f7d1f4df93639090da46230f3b539"
|
|
241
255
|
}
|