@stryke/path 0.18.2 → 0.18.4
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 +1 -1
- package/dist/append.mjs +1 -1
- package/dist/file-path-fns.cjs +2 -2
- package/dist/file-path-fns.mjs +1 -1
- package/dist/is-parent-path.cjs +4 -4
- package/dist/is-parent-path.mjs +1 -1
- package/dist/replace.cjs +4 -4
- package/dist/replace.mjs +1 -1
- package/dist/slash.cjs +6 -0
- package/dist/slash.d.ts +7 -0
- package/dist/slash.mjs +1 -1
- package/package.json +2 -2
package/dist/append.cjs
CHANGED
|
@@ -10,6 +10,6 @@ var _isParentPath = require("./is-parent-path.cjs");
|
|
|
10
10
|
var _joinPaths = require("./join-paths.cjs");
|
|
11
11
|
var _slash = require("./slash.cjs");
|
|
12
12
|
function appendPath(r, o = (0, _cwd.cwd)()) {
|
|
13
|
-
return (0, _slash.
|
|
13
|
+
return (0, _slash.formatSlash)((0, _isParentPath.isParentPath)(r, o) ? r : (0, _joinPaths.joinPaths)(o, r));
|
|
14
14
|
}
|
|
15
15
|
const append = exports.append = appendPath;
|
package/dist/append.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{cwd as t}from"./cwd";import{isParentPath as n}from"./is-parent-path";import{joinPaths as
|
|
1
|
+
import{cwd as t}from"./cwd";import{isParentPath as n}from"./is-parent-path";import{joinPaths as m}from"./join-paths";import{formatSlash as p}from"./slash";export function appendPath(r,o=t()){return p(n(r,o)?r:m(o,r))}export const append=appendPath;
|
package/dist/file-path-fns.cjs
CHANGED
|
@@ -23,7 +23,7 @@ exports.renameFile = renameFile;
|
|
|
23
23
|
exports.resolve = resolve;
|
|
24
24
|
exports.resolvePath = resolvePath;
|
|
25
25
|
exports.resolvePaths = resolvePaths;
|
|
26
|
-
var
|
|
26
|
+
var _isSetString = require("@stryke/type-checks/is-set-string");
|
|
27
27
|
var _base = require("@stryke/types/base");
|
|
28
28
|
var _correctPath = require("./correct-path.cjs");
|
|
29
29
|
var _cwd = require("./cwd.cjs");
|
|
@@ -62,7 +62,7 @@ const basename = exports.basename = findFolderName;
|
|
|
62
62
|
function findFileExtension(e) {
|
|
63
63
|
if (e.endsWith(".") || e.endsWith("/")) return;
|
|
64
64
|
const t = _regex.FILE_EXTENSION_REGEX.exec((0, _correctPath.normalizeWindowsPath)(e));
|
|
65
|
-
return t && t.length > 0 && (0,
|
|
65
|
+
return t && t.length > 0 && (0, _isSetString.isSetString)(t[0]) ? t[0].replace(".", "") : void 0;
|
|
66
66
|
}
|
|
67
67
|
const extname = exports.extname = findFileExtension;
|
|
68
68
|
function findFileDotExtension(e) {
|
package/dist/file-path-fns.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isSetString as d}from"@stryke/type-checks";import{EMPTY_STRING as u}from"@stryke/types/base";import{normalizeString as g,normalizeWindowsPath as l}from"./correct-path";import{cwd as a}from"./cwd";import{isAbsolute as p,isAbsolutePath as c}from"./is-type";import{joinPaths as f}from"./join-paths";import{FILE_EXTENSION_REGEX as m,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(".")?u:n===!1&&i.includes(".")?i.replace(`.${findFileExtension(i)??""}`,"")||u: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??u}export const basename=findFolderName;export function findFileExtension(e){if(e.endsWith(".")||e.endsWith("/"))return;const t=m.exec(l(e));return t&&t.length>0&&d(t[0])?t[0].replace(".",""):void 0}export const extname=findFileExtension;export function findFileDotExtension(e){const t=findFileExtension(e);return t?`.${t}`:void 0}export function findFileExtensionSafe(e){return findFileExtension(e)??u}export function findFileDotExtensionSafe(e){const t=findFileExtension(e);return t?`.${t}`:""}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=a()){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]:a();!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,a())}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)}
|
|
1
|
+
import{isSetString as d}from"@stryke/type-checks/is-set-string";import{EMPTY_STRING as u}from"@stryke/types/base";import{normalizeString as g,normalizeWindowsPath as l}from"./correct-path";import{cwd as a}from"./cwd";import{isAbsolute as p,isAbsolutePath as c}from"./is-type";import{joinPaths as f}from"./join-paths";import{FILE_EXTENSION_REGEX as m,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(".")?u:n===!1&&i.includes(".")?i.replace(`.${findFileExtension(i)??""}`,"")||u: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??u}export const basename=findFolderName;export function findFileExtension(e){if(e.endsWith(".")||e.endsWith("/"))return;const t=m.exec(l(e));return t&&t.length>0&&d(t[0])?t[0].replace(".",""):void 0}export const extname=findFileExtension;export function findFileDotExtension(e){const t=findFileExtension(e);return t?`.${t}`:void 0}export function findFileExtensionSafe(e){return findFileExtension(e)??u}export function findFileDotExtensionSafe(e){const t=findFileExtension(e);return t?`.${t}`:""}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=a()){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]:a();!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,a())}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/is-parent-path.cjs
CHANGED
|
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.isParentPath = isParentPath;
|
|
7
7
|
var _slash = require("./slash.cjs");
|
|
8
|
-
function isParentPath(
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
return
|
|
8
|
+
function isParentPath(o, a) {
|
|
9
|
+
const r = (0, _slash.formatSlash)(o),
|
|
10
|
+
n = (0, _slash.formatSlash)(a);
|
|
11
|
+
return (0, _slash.formatSlash)(r) !== (0, _slash.formatSlash)(n) && (0, _slash.formatSlash)(r).startsWith((0, _slash.formatSlash)(n));
|
|
12
12
|
}
|
package/dist/is-parent-path.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{formatSlash as t}from"./slash";export function isParentPath(o,a){const r=t(o),n=t(a);return t(r)!==t(n)&&t(r).startsWith(t(n))}
|
package/dist/replace.cjs
CHANGED
|
@@ -10,9 +10,9 @@ var _cwd = require("./cwd.cjs");
|
|
|
10
10
|
var _filePathFns = require("./file-path-fns.cjs");
|
|
11
11
|
var _isParentPath = require("./is-parent-path.cjs");
|
|
12
12
|
var _slash = require("./slash.cjs");
|
|
13
|
-
function replacePath(r,
|
|
14
|
-
return (0, _correctPath.correctPath)((0, _isParentPath.isParentPath)(r,
|
|
13
|
+
function replacePath(r, o = (0, _cwd.cwd)()) {
|
|
14
|
+
return (0, _slash.formatSlash)((0, _correctPath.correctPath)((0, _isParentPath.isParentPath)(r, o) ? (0, _slash.formatSlash)(r).replace((0, _slash.formatSlash)(o), "").replace(/^\/+/g, "") : r));
|
|
15
15
|
}
|
|
16
|
-
function replaceExtension(r,
|
|
17
|
-
return (0, _correctPath.correctPath)(r.replace(!
|
|
16
|
+
function replaceExtension(r, o = "") {
|
|
17
|
+
return (0, _correctPath.correctPath)(r.replace(!o || o.includes(".") ? (0, _filePathFns.findFileDotExtensionSafe)(r) : (0, _filePathFns.findFileExtensionSafe)(r), o));
|
|
18
18
|
}
|
package/dist/replace.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{correctPath as
|
|
1
|
+
import{correctPath as n}from"./correct-path";import{cwd as t}from"./cwd";import{findFileDotExtensionSafe as e,findFileExtensionSafe as f}from"./file-path-fns";import{isParentPath as s}from"./is-parent-path";import{formatSlash as i}from"./slash";export function replacePath(r,o=t()){return i(n(s(r,o)?i(r).replace(i(o),"").replace(/^\/+/g,""):r))}export function replaceExtension(r,o=""){return n(r.replace(!o||o.includes(".")?e(r):f(r),o))}
|
package/dist/slash.cjs
CHANGED
|
@@ -3,7 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.formatSlash = formatSlash;
|
|
6
7
|
exports.slash = slash;
|
|
8
|
+
var _isType = require("./is-type.cjs");
|
|
7
9
|
function slash(r) {
|
|
8
10
|
return r.startsWith("\\\\?\\") ? r : r.replace(/\\/g, "/");
|
|
11
|
+
}
|
|
12
|
+
function formatSlash(r) {
|
|
13
|
+
const t = slash(r);
|
|
14
|
+
return (0, _isType.isAbsolutePath)(t) ? t.replace(/\/+$/g, "") : t.replace(/^\.\//g, "").replace(/\/+$/g, "");
|
|
9
15
|
}
|
package/dist/slash.d.ts
CHANGED
|
@@ -5,3 +5,10 @@
|
|
|
5
5
|
* @returns The string with replaced backslashes
|
|
6
6
|
*/
|
|
7
7
|
export declare function slash(path: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Replace backslash to slash and remove unneeded leading and trailing slashes
|
|
10
|
+
*
|
|
11
|
+
* @param path - The string to replace
|
|
12
|
+
* @returns The string with replaced backslashes
|
|
13
|
+
*/
|
|
14
|
+
export declare function formatSlash(path: string): string;
|
package/dist/slash.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export function slash(r){return r.startsWith("\\\\?\\")?r:r.replace(/\\/g,"/")}
|
|
1
|
+
import{isAbsolutePath as e}from"./is-type";export function slash(r){return r.startsWith("\\\\?\\")?r:r.replace(/\\/g,"/")}export function formatSlash(r){const t=slash(r);return e(t)?t.replace(/\/+$/g,""):t.replace(/^\.\//g,"").replace(/\/+$/g,"")}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/path",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.4",
|
|
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": {
|
|
@@ -294,5 +294,5 @@
|
|
|
294
294
|
"main": "./dist/index.cjs",
|
|
295
295
|
"module": "./dist/index.mjs",
|
|
296
296
|
"types": "./dist/index.d.ts",
|
|
297
|
-
"gitHead": "
|
|
297
|
+
"gitHead": "39c2e3311f9f1246241a55748436981aa65e3ced"
|
|
298
298
|
}
|