@stryke/path 0.13.0 → 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.
@@ -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
+ }
@@ -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;
@@ -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)}
@@ -8,6 +8,7 @@ exports.normalizeString = normalizeString;
8
8
  exports.normalizeWindowsPath = normalizeWindowsPath;
9
9
  exports.toAbsolutePath = toAbsolutePath;
10
10
  exports.toRelativePath = toRelativePath;
11
+ var _cwd = require("./cwd.cjs");
11
12
  var _isType = require("./is-type.cjs");
12
13
  var _joinPaths = require("./join-paths.cjs");
13
14
  var _regex = require("./regex.cjs");
@@ -38,8 +39,8 @@ function normalizeString(e, n) {
38
39
  if (!(l === t - 1 || s === 1)) if (s === 2) {
39
40
  if (r.length < 2 || i !== 2 || r[r.length - 1] !== "." || r[r.length - 2] !== ".") {
40
41
  if (r.length > 2) {
41
- const u = r.lastIndexOf("/");
42
- u === -1 ? (r = "", i = 0) : (r = r.slice(0, u), i = r.length - 1 - r.lastIndexOf("/")), l = t, s = 0;
42
+ const g = r.lastIndexOf("/");
43
+ g === -1 ? (r = "", i = 0) : (r = r.slice(0, g), i = r.length - 1 - r.lastIndexOf("/")), l = t, s = 0;
43
44
  continue;
44
45
  } else if (r.length > 0) {
45
46
  r = "", i = 0, l = t, s = 0;
@@ -56,6 +57,6 @@ function normalizeString(e, n) {
56
57
  function toAbsolutePath(e, n) {
57
58
  return (0, _isType.isAbsolutePath)(e) ? e : (0, _slash.slash)(normalizeString((0, _joinPaths.joinPaths)(n || process.cwd(), e), !0));
58
59
  }
59
- function toRelativePath(e, n) {
60
- return !e || e.length === 0 ? "." : ((0, _isType.isAbsolutePath)(e) ? e = (0, _slash.slash)(normalizeString(e, !0)) : e = (0, _slash.slash)(normalizeString((0, _joinPaths.joinPaths)(n || process.cwd(), e), !0)), e.startsWith("./") ? e.slice(2) : e);
60
+ function toRelativePath(e, n = (0, _cwd.cwd)()) {
61
+ return !e || e.length === 0 ? "." : ((0, _isType.isAbsolutePath)(e) ? e = (0, _slash.slash)(normalizeString(e, !0)) : e = (0, _slash.slash)(normalizeString((0, _joinPaths.joinPaths)(n, e), !0)), e.startsWith("./") ? e.slice(2) : e);
61
62
  }
@@ -1 +1 @@
1
- import{isAbsolutePath as g}from"./is-type";import{joinPaths as c}from"./join-paths";import{DRIVE_LETTER_REGEX as m,DRIVE_LETTER_START_REGEX as E,UNC_REGEX as d}from"./regex";import{slash as f}from"./slash";export function normalizeWindowsPath(e=""){return e&&f(e).replace(E,n=>n.toUpperCase())}export function correctPath(e){if(!e||e.length===0)return".";e=normalizeWindowsPath(e);const n=e.match(d),r=g(e),i=e.endsWith("/");return e=normalizeString(e,!r),e.length===0?r?"/":i?"./":".":(i&&(e+="/"),m.test(e)&&(e+="/"),n?r?`//${e}`:`//./${e}`:!e.startsWith("/")&&r&&!m.test(e)?`/${e}`:e)}export function normalizeString(e,n){let r="",i=0,l=-1,s=0,o=null;for(let t=0;t<=e.length;++t){if(t<e.length)o=e[t];else{if(o==="/")break;o="/"}if(o==="/"){if(!(l===t-1||s===1))if(s===2){if(r.length<2||i!==2||r[r.length-1]!=="."||r[r.length-2]!=="."){if(r.length>2){const u=r.lastIndexOf("/");u===-1?(r="",i=0):(r=r.slice(0,u),i=r.length-1-r.lastIndexOf("/")),l=t,s=0;continue}else if(r.length>0){r="",i=0,l=t,s=0;continue}}n&&(r+=r.length>0?"/..":"..",i=2)}else r.length>0?r+=`/${e.slice(l+1,t)}`:r=e.slice(l+1,t),i=t-l-1;l=t,s=0}else o==="."&&s!==-1?++s:s=-1}return r}export function toAbsolutePath(e,n){return g(e)?e:f(normalizeString(c(n||process.cwd(),e),!0))}export function toRelativePath(e,n){return!e||e.length===0?".":(g(e)?e=f(normalizeString(e,!0)):e=f(normalizeString(c(n||process.cwd(),e),!0)),e.startsWith("./")?e.slice(2):e)}
1
+ import{cwd as E}from"./cwd";import{isAbsolutePath as u}from"./is-type";import{joinPaths as c}from"./join-paths";import{DRIVE_LETTER_REGEX as m,DRIVE_LETTER_START_REGEX as d,UNC_REGEX as x}from"./regex";import{slash as f}from"./slash";export function normalizeWindowsPath(e=""){return e&&f(e).replace(d,n=>n.toUpperCase())}export function correctPath(e){if(!e||e.length===0)return".";e=normalizeWindowsPath(e);const n=e.match(x),r=u(e),i=e.endsWith("/");return e=normalizeString(e,!r),e.length===0?r?"/":i?"./":".":(i&&(e+="/"),m.test(e)&&(e+="/"),n?r?`//${e}`:`//./${e}`:!e.startsWith("/")&&r&&!m.test(e)?`/${e}`:e)}export function normalizeString(e,n){let r="",i=0,l=-1,s=0,o=null;for(let t=0;t<=e.length;++t){if(t<e.length)o=e[t];else{if(o==="/")break;o="/"}if(o==="/"){if(!(l===t-1||s===1))if(s===2){if(r.length<2||i!==2||r[r.length-1]!=="."||r[r.length-2]!=="."){if(r.length>2){const g=r.lastIndexOf("/");g===-1?(r="",i=0):(r=r.slice(0,g),i=r.length-1-r.lastIndexOf("/")),l=t,s=0;continue}else if(r.length>0){r="",i=0,l=t,s=0;continue}}n&&(r+=r.length>0?"/..":"..",i=2)}else r.length>0?r+=`/${e.slice(l+1,t)}`:r=e.slice(l+1,t),i=t-l-1;l=t,s=0}else o==="."&&s!==-1?++s:s=-1}return r}export function toAbsolutePath(e,n){return u(e)?e:f(normalizeString(c(n||process.cwd(),e),!0))}export function toRelativePath(e,n=E()){return!e||e.length===0?".":(u(e)?e=f(normalizeString(e,!0)):e=f(normalizeString(c(n,e),!0)),e.startsWith("./")?e.slice(2):e)}
package/dist/cwd.cjs ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.cwd = cwd;
7
+ function cwd() {
8
+ return typeof process < "u" && typeof process.cwd == "function" ? process.cwd().replace(/\\/g, "/") : "/";
9
+ }
package/dist/cwd.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Get the current working directory.
3
+ *
4
+ * @remarks
5
+ * This function attempts to retrieve the current working directory using `process.cwd()`.
6
+ *
7
+ * @returns The current working directory or '/' if it cannot be determined
8
+ */
9
+ export declare function cwd(): string;
package/dist/cwd.mjs ADDED
@@ -0,0 +1 @@
1
+ export function cwd(){return typeof process<"u"&&typeof process.cwd=="function"?process.cwd().replace(/\\/g,"/"):"/"}
@@ -5,14 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.win32 = exports.posix = exports.delimiter = void 0;
7
7
  const delimiter = exports.delimiter = process?.platform === "win32" ? ";" : ":";
8
- const o = {
8
+ const i = {
9
9
  posix: void 0,
10
10
  win32: void 0
11
11
  },
12
- n = (t = delimiter) => new Proxy({}, {
13
- get(i, e) {
14
- return e === "delimiter" ? t : e === "posix" ? posix : e === "win32" ? win32 : o[e];
12
+ e = (t = delimiter) => new Proxy({}, {
13
+ get(o, n) {
14
+ return n === "delimiter" ? t : n === "posix" ? posix : n === "win32" ? win32 : i[n];
15
15
  }
16
16
  });
17
- const posix = exports.posix = n(":"),
18
- win32 = exports.win32 = n(";");
17
+ const posix = exports.posix = e(":"),
18
+ win32 = exports.win32 = e(";");
@@ -4,5 +4,15 @@
4
4
  * Equals to `";"` in windows and `":"` in all other platforms.
5
5
  */
6
6
  export declare const delimiter: ";" | ":";
7
- export declare const posix: import("path").PlatformPath;
8
- export declare const win32: import("path").PlatformPath;
7
+ export declare const posix: {
8
+ posix: any;
9
+ win32: any;
10
+ } & {
11
+ delimiter: ";" | ":";
12
+ };
13
+ export declare const win32: {
14
+ posix: any;
15
+ win32: any;
16
+ } & {
17
+ delimiter: ";" | ":";
18
+ };
@@ -1 +1 @@
1
- export const delimiter=process?.platform==="win32"?";":":";const o={posix:void 0,win32:void 0},n=(t=delimiter)=>new Proxy({},{get(i,e){return e==="delimiter"?t:e==="posix"?posix:e==="win32"?win32:o[e]}});export const posix=n(":"),win32=n(";");
1
+ export const delimiter=process?.platform==="win32"?";":":";const i={posix:void 0,win32:void 0},e=(t=delimiter)=>new Proxy({},{get(o,n){return n==="delimiter"?t:n==="posix"?posix:n==="win32"?win32:i[n]}});export const posix=e(":"),win32=e(";");
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.currentDir = currentDir;
6
+ exports.dirname = exports.basename = void 0;
7
7
  exports.findFileExtension = findFileExtension;
8
8
  exports.findFileExtensionSafe = findFileExtensionSafe;
9
9
  exports.findFileName = findFileName;
@@ -23,6 +23,7 @@ exports.resolvePath = resolvePath;
23
23
  exports.resolvePaths = resolvePaths;
24
24
  var _base = require("@stryke/types/base");
25
25
  var _correctPath = require("./correct-path.cjs");
26
+ var _cwd = require("./cwd.cjs");
26
27
  var _isType = require("./is-type.cjs");
27
28
  var _joinPaths = require("./join-paths.cjs");
28
29
  var _regex = require("./regex.cjs");
@@ -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));
@@ -73,7 +76,7 @@ function hasFolderName(e) {
73
76
  function hasFileExtension(e) {
74
77
  return !!findFileExtension(e);
75
78
  }
76
- function resolvePath(e, t = currentDir()) {
79
+ function resolvePath(e, t = (0, _cwd.cwd)()) {
77
80
  const r = (0, _correctPath.normalizeWindowsPath)(e).split("/");
78
81
  let n = "",
79
82
  i = !1;
@@ -88,7 +91,7 @@ function resolve(...e) {
88
91
  let t = "",
89
92
  r = !1;
90
93
  for (let n = e.length - 1; n >= -1 && !r; n--) {
91
- const i = n >= 0 ? e[n] : currentDir();
94
+ const i = n >= 0 ? e[n] : (0, _cwd.cwd)();
92
95
  !i || i.length === 0 || (t = `${i}/${t}`, r = (0, _isType.isAbsolute)(i));
93
96
  }
94
97
  return t = (0, _correctPath.normalizeString)(t, !r), r && !(0, _isType.isAbsolute)(t) ? `/${t}` : t.length > 0 ? t : ".";
@@ -96,9 +99,6 @@ function resolve(...e) {
96
99
  function resolvePaths(...e) {
97
100
  return resolvePath((0, _joinPaths.joinPaths)(...e.map(t => (0, _correctPath.normalizeWindowsPath)(t))));
98
101
  }
99
- function currentDir() {
100
- return typeof process < "u" && typeof process.cwd == "function" ? process.cwd().replace(/\\/g, "/") : "/";
101
- }
102
102
  function relative(e, t) {
103
103
  const r = resolve(e).replace(_regex.ROOT_FOLDER_REGEX, "$1").split("/"),
104
104
  n = resolve(t).replace(_regex.ROOT_FOLDER_REGEX, "$1").split("/");
@@ -114,7 +114,7 @@ function relativePath(e, t, r = !1) {
114
114
  return relative(r !== !0 ? e.replace(/\/$/, "") : e, r !== !0 ? t.replace(/\/$/, "") : t);
115
115
  }
116
116
  function relativeToCurrentDir(e) {
117
- return relativePath(e, currentDir());
117
+ return relativePath(e, (0, _cwd.cwd)());
118
118
  }
119
119
  function parsePath(e) {
120
120
  const t = /^[/\\]|^[a-z]:[/\\]/i.exec(e)?.[0]?.replace(/\\/g, "/") || "",
@@ -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
  *
@@ -125,12 +127,6 @@ export declare function resolve(...paths: string[]): string;
125
127
  * @returns The resolved path
126
128
  */
127
129
  export declare function resolvePaths(...paths: string[]): string;
128
- /**
129
- * Get the current working directory.
130
- *
131
- * @returns The current working directory or '/' if it cannot be determined
132
- */
133
- export declare function currentDir(): string;
134
130
  /**
135
131
  * Get the relative path from one file to another.
136
132
  *
@@ -1 +1 @@
1
- import{EMPTY_STRING as u}from"@stryke/types/base";import{normalizeString as f,normalizeWindowsPath as l}from"./correct-path";import{isAbsolute as p,isAbsolutePath as c}from"./is-type";import{joinPaths as a}from"./join-paths";import{ROOT_FOLDER_REGEX as g}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.substring(0,i.lastIndexOf("."))||u:i}export function findFilePath(e){const t=l(e),r=t.replace(findFileName(t,{requireExtension:!0}),"");return r==="/"?r:r.replace(/\/$/,"")}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 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)??u}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=currentDir()){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=a(s,n),i=c(s))}return n=f(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]:currentDir();!i||i.length===0||(t=`${i}/${t}`,r=p(i))}return t=f(t,!r),r&&!p(t)?`/${t}`:t.length>0?t:"."}export function resolvePaths(...e){return resolvePath(a(...e.map(t=>l(t))))}export function currentDir(){return typeof process<"u"&&typeof process.cwd=="function"?process.cwd().replace(/\\/g,"/"):"/"}export function relative(e,t){const r=resolve(e).replace(g,"$1").split("/"),n=resolve(t).replace(g,"$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,currentDir())}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 a(r.dir,t.includes(".")?t:t+r.ext)}
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)}
@@ -4,26 +4,25 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.resolveParentPath = exports.getParentPath = void 0;
7
- var _isFile = require("./is-file.cjs");
7
+ var _cwd = require("./cwd.cjs");
8
8
  var _joinPaths = require("./join-paths.cjs");
9
- const resolveParentPath = (r, i = 1) => {
9
+ const resolveParentPath = (r, n = 1) => {
10
10
  let t = r.replaceAll(/\/+$/g, "");
11
- for (let n = 0; n < i; n++) t = (0, _joinPaths.joinPaths)(t, "..");
11
+ for (let i = 0; i < n; i++) t = (0, _joinPaths.joinPaths)(t, "..");
12
12
  return t;
13
13
  },
14
- getParentPath = (r, i, t) => {
15
- const n = t?.ignoreCase ?? !0,
16
- f = t?.skipCwd ?? !1,
17
- o = t?.targetType ?? "both";
18
- let e = i;
19
- f && (e = resolveParentPath(i));
20
- let l = Array.isArray(r) ? r : [r];
21
- for (n && (l = l.map(a => a.toLowerCase()));;) {
22
- const a = l.find(p => (0, _isFile.isFile)((0, _joinPaths.joinPaths)(e, p)) && (o === "file" || o === "both") || (0, _isFile.isDirectory)((0, _joinPaths.joinPaths)(e, p)) && (o === "directory" || o === "both"));
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));
23
22
  if (a) return (0, _joinPaths.joinPaths)(e, a);
24
- const g = resolveParentPath(e);
25
- if (g === e) return;
26
- e = g;
23
+ const l = resolveParentPath(e);
24
+ if (l === e) return;
25
+ e = l;
27
26
  }
28
27
  };
29
28
  exports.getParentPath = getParentPath;
@@ -36,4 +36,4 @@ export interface GetParentPathOptions {
36
36
  * @param cwd - The current working directory.
37
37
  * @returns The first parent path that exists.
38
38
  */
39
- export declare const getParentPath: (name: string | string[], cwd: string, options?: Partial<GetParentPathOptions>) => string | undefined;
39
+ export declare const getParentPath: (name: string | string[], cwd?: string, options?: Partial<GetParentPathOptions>) => string | undefined;
@@ -1 +1 @@
1
- import{isDirectory as c,isFile as h}from"./is-file";import{joinPaths as s}from"./join-paths";export const resolveParentPath=(r,i=1)=>{let t=r.replaceAll(/\/+$/g,"");for(let n=0;n<i;n++)t=s(t,"..");return t},getParentPath=(r,i,t)=>{const n=t?.ignoreCase??!0,f=t?.skipCwd??!1,o=t?.targetType??"both";let e=i;f&&(e=resolveParentPath(i));let l=Array.isArray(r)?r:[r];for(n&&(l=l.map(a=>a.toLowerCase()));;){const a=l.find(p=>h(s(e,p))&&(o==="file"||o==="both")||c(s(e,p))&&(o==="directory"||o==="both"));if(a)return s(e,a);const g=resolveParentPath(e);if(g===e)return;e=g}};
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}};
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;
@@ -25,6 +36,17 @@ Object.keys(_correctPath).forEach(function (key) {
25
36
  }
26
37
  });
27
38
  });
39
+ var _cwd = require("./cwd.cjs");
40
+ Object.keys(_cwd).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (key in exports && exports[key] === _cwd[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _cwd[key];
47
+ }
48
+ });
49
+ });
28
50
  var _delimiter = require("./delimiter.cjs");
29
51
  Object.keys(_delimiter).forEach(function (key) {
30
52
  if (key === "default" || key === "__esModule") return;
@@ -58,17 +80,6 @@ Object.keys(_getParentPath).forEach(function (key) {
58
80
  }
59
81
  });
60
82
  });
61
- var _isFile = require("./is-file.cjs");
62
- Object.keys(_isFile).forEach(function (key) {
63
- if (key === "default" || key === "__esModule") return;
64
- if (key in exports && exports[key] === _isFile[key]) return;
65
- Object.defineProperty(exports, key, {
66
- enumerable: true,
67
- get: function () {
68
- return _isFile[key];
69
- }
70
- });
71
- });
72
83
  var _isParentPath = require("./is-parent-path.cjs");
73
84
  Object.keys(_isParentPath).forEach(function (key) {
74
85
  if (key === "default" || key === "__esModule") return;
package/dist/index.d.ts CHANGED
@@ -6,12 +6,13 @@
6
6
  *
7
7
  * @packageDocumentation
8
8
  */
9
+ export * from "./append";
9
10
  export * from "./asset-extensions";
10
11
  export * from "./correct-path";
12
+ export * from "./cwd";
11
13
  export * from "./delimiter";
12
14
  export * from "./file-path-fns";
13
15
  export * from "./get-parent-path";
14
- export * from "./is-file";
15
16
  export * from "./is-parent-path";
16
17
  export * from "./is-root-dir";
17
18
  export * from "./join-paths";
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export*from"./asset-extensions";export*from"./correct-path";export*from"./delimiter";export*from"./file-path-fns";export*from"./get-parent-path";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"./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";
@@ -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,
@@ -6,3 +6,4 @@
6
6
  * @returns The joined and normalized path string.
7
7
  */
8
8
  export declare function joinPaths(...segments: string[]): string;
9
+ export declare const join: typeof joinPaths;
@@ -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/dist/replace.cjs CHANGED
@@ -4,8 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.replacePath = replacePath;
7
+ var _cwd = require("./cwd.cjs");
7
8
  var _isParentPath = require("./is-parent-path.cjs");
8
9
  var _slash = require("./slash.cjs");
9
- function replacePath(r, e = process.cwd()) {
10
+ function replacePath(r, e = (0, _cwd.cwd)()) {
10
11
  return (0, _isParentPath.isParentPath)(r, e) ? (0, _slash.slash)(r).replace((0, _slash.slash)(e), "").replace(/^\//, "") : r;
11
12
  }
package/dist/replace.mjs CHANGED
@@ -1 +1 @@
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}
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}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/path",
3
- "version": "0.13.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": {
@@ -141,20 +141,6 @@
141
141
  "default": "./dist/is-parent-path.mjs"
142
142
  }
143
143
  },
144
- "./is-file": {
145
- "import": {
146
- "types": "./dist/is-file.d.ts",
147
- "default": "./dist/is-file.mjs"
148
- },
149
- "require": {
150
- "types": "./dist/is-file.d.ts",
151
- "default": "./dist/is-file.cjs"
152
- },
153
- "default": {
154
- "types": "./dist/is-file.d.ts",
155
- "default": "./dist/is-file.mjs"
156
- }
157
- },
158
144
  "./index": {
159
145
  "import": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" },
160
146
  "require": {
@@ -205,6 +191,11 @@
205
191
  "default": "./dist/delimiter.mjs"
206
192
  }
207
193
  },
194
+ "./cwd": {
195
+ "import": { "types": "./dist/cwd.d.ts", "default": "./dist/cwd.mjs" },
196
+ "require": { "types": "./dist/cwd.d.ts", "default": "./dist/cwd.cjs" },
197
+ "default": { "types": "./dist/cwd.d.ts", "default": "./dist/cwd.mjs" }
198
+ },
208
199
  "./correct-path": {
209
200
  "import": {
210
201
  "types": "./dist/correct-path.d.ts",
@@ -233,6 +224,20 @@
233
224
  "default": "./dist/asset-extensions.mjs"
234
225
  }
235
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
+ },
236
241
  ".": {
237
242
  "import": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" },
238
243
  "require": {
@@ -246,5 +251,5 @@
246
251
  "main": "./dist/index.cjs",
247
252
  "module": "./dist/index.mjs",
248
253
  "types": "./dist/index.d.ts",
249
- "gitHead": "dc317cbe47e06f3b3f7887b9176087c3de488853"
254
+ "gitHead": "4cae447b5b6f7d1f4df93639090da46230f3b539"
250
255
  }
package/dist/is-file.cjs DELETED
@@ -1,29 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isDirectory = isDirectory;
7
- exports.isDirectorySymlink = void 0;
8
- exports.isFile = isFile;
9
- exports.isFileSymlink = void 0;
10
- var _nodeFs = require("node:fs");
11
- var _joinPaths = require("./join-paths.cjs");
12
- function isFile(r, o) {
13
- return !!(0, _nodeFs.statSync)(o ? (0, _joinPaths.joinPaths)(o, r) : r, {
14
- throwIfNoEntry: !1
15
- })?.isFile();
16
- }
17
- function isDirectory(r, o) {
18
- return !!(0, _nodeFs.statSync)(o ? (0, _joinPaths.joinPaths)(o, r) : r, {
19
- throwIfNoEntry: !1
20
- })?.isDirectory();
21
- }
22
- const isFileSymlink = (r, o) => !!(0, _nodeFs.lstatSync)(o ? (0, _joinPaths.joinPaths)(o, r) : r, {
23
- throwIfNoEntry: !1
24
- })?.isFile(),
25
- isDirectorySymlink = (r, o) => !!(0, _nodeFs.lstatSync)(o ? (0, _joinPaths.joinPaths)(o, r) : r, {
26
- throwIfNoEntry: !1
27
- })?.isDirectory();
28
- exports.isDirectorySymlink = isDirectorySymlink;
29
- exports.isFileSymlink = isFileSymlink;
package/dist/is-file.d.ts DELETED
@@ -1,32 +0,0 @@
1
- /**
2
- * Check if the given path is a file.
3
- *
4
- * @param path - The location to check
5
- * @param additionalPath - An optional additional path to add to the start of the path
6
- * @returns An indicator specifying if the path is a file
7
- */
8
- export declare function isFile(path: string, additionalPath?: string): boolean;
9
- /**
10
- * Check if the given path is a directory.
11
- *
12
- * @param path - The location to check
13
- * @param additionalPath - An optional additional path to add to the start of the path
14
- * @returns An indicator specifying if the path is a directory
15
- */
16
- export declare function isDirectory(path: string, additionalPath?: string): boolean;
17
- /**
18
- * Check if the given path is a file . Does not dereference symbolic links.
19
- *
20
- * @param path - The location to check
21
- * @param additionalPath - An optional additional path to add to the start of the path
22
- * @returns An indicator specifying if the path is a file
23
- */
24
- export declare const isFileSymlink: (path: string, additionalPath?: string) => boolean;
25
- /**
26
- * Check if the given path is a directory. Does not dereference symbolic links.
27
- *
28
- * @param path - The location to check
29
- * @param additionalPath - An optional additional path to add to the start of the path
30
- * @returns An indicator specifying if the path is a directory
31
- */
32
- export declare const isDirectorySymlink: (path: string, additionalPath?: string) => boolean;
package/dist/is-file.mjs DELETED
@@ -1 +0,0 @@
1
- import{lstatSync as e,statSync as t}from"node:fs";import{joinPaths as n}from"./join-paths";export function isFile(r,o){return!!t(o?n(o,r):r,{throwIfNoEntry:!1})?.isFile()}export function isDirectory(r,o){return!!t(o?n(o,r):r,{throwIfNoEntry:!1})?.isDirectory()}export const isFileSymlink=(r,o)=>!!e(o?n(o,r):r,{throwIfNoEntry:!1})?.isFile(),isDirectorySymlink=(r,o)=>!!e(o?n(o,r):r,{throwIfNoEntry:!1})?.isDirectory();