@stryke/path 0.12.5 → 0.13.1

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.
Files changed (45) hide show
  1. package/README.md +17 -14
  2. package/dist/correct-path.cjs +8 -7
  3. package/dist/correct-path.mjs +1 -1
  4. package/dist/cwd.cjs +9 -0
  5. package/dist/cwd.d.ts +9 -0
  6. package/dist/cwd.mjs +1 -0
  7. package/dist/delimiter.cjs +6 -6
  8. package/dist/delimiter.d.ts +12 -2
  9. package/dist/delimiter.mjs +1 -1
  10. package/dist/file-path-fns.cjs +59 -36
  11. package/dist/file-path-fns.d.ts +13 -1
  12. package/dist/file-path-fns.mjs +1 -1
  13. package/dist/get-parent-path.cjs +14 -15
  14. package/dist/get-parent-path.d.ts +1 -1
  15. package/dist/get-parent-path.mjs +1 -1
  16. package/dist/index.cjs +8 -41
  17. package/dist/index.d.ts +1 -4
  18. package/dist/index.mjs +1 -1
  19. package/dist/is-root-dir.cjs +4 -3
  20. package/dist/is-root-dir.d.ts +1 -1
  21. package/dist/is-root-dir.mjs +1 -1
  22. package/dist/is-type.cjs +23 -0
  23. package/dist/is-type.d.ts +34 -0
  24. package/dist/is-type.mjs +1 -0
  25. package/dist/join-paths.cjs +44 -50
  26. package/dist/join-paths.d.ts +1 -2
  27. package/dist/join-paths.mjs +1 -1
  28. package/dist/regex.cjs +3 -2
  29. package/dist/regex.d.ts +1 -0
  30. package/dist/regex.mjs +1 -1
  31. package/dist/replace.cjs +2 -1
  32. package/dist/replace.mjs +1 -1
  33. package/package.json +23 -60
  34. package/dist/exists.cjs +0 -12
  35. package/dist/exists.d.ts +0 -14
  36. package/dist/exists.mjs +0 -1
  37. package/dist/get-workspace-root.cjs +0 -38
  38. package/dist/get-workspace-root.d.ts +0 -30
  39. package/dist/get-workspace-root.mjs +0 -1
  40. package/dist/is-file.cjs +0 -39
  41. package/dist/is-file.d.ts +0 -46
  42. package/dist/is-file.mjs +0 -1
  43. package/dist/resolve.cjs +0 -59
  44. package/dist/resolve.d.ts +0 -71
  45. package/dist/resolve.mjs +0 -1
package/README.md CHANGED
@@ -42,26 +42,29 @@ This package is part of Storm Software's **đŸŒŠī¸ Stryke** monorepo. Stryke pac
42
42
  # Stryke - Path Helpers
43
43
 
44
44
  A package containing various utilities that expand the functionality of NodeJs's
45
- built-in \`path\` module
45
+ built-in \`path\` module; however, it is platform neutral and can be used in both
46
+ NodeJs and browser environments.
46
47
 
47
48
  <!-- START doctoc -->
48
49
  <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
49
50
 
50
51
  ## Table of Contents
51
52
 
52
- - [Installing](#installing)
53
- - [Reduced Package Size](#reduced-package-size)
54
- - [Development](#development)
55
- - [Building](#building)
56
- - [Running unit tests](#running-unit-tests)
57
- - [Linting](#linting)
58
- - [Storm Workspaces](#storm-workspaces)
59
- - [Roadmap](#roadmap)
60
- - [Support](#support)
61
- - [License](#license)
62
- - [Changelog](#changelog)
63
- - [Contributing](#contributing)
64
- - [Contributors](#contributors)
53
+ - [Stryke - Path Helpers](#stryke---path-helpers)
54
+ - [Table of Contents](#table-of-contents)
55
+ - [Installing](#installing)
56
+ - [Reduced Package Size](#reduced-package-size)
57
+ - [Development](#development)
58
+ - [Building](#building)
59
+ - [Running unit tests](#running-unit-tests)
60
+ - [Linting](#linting)
61
+ - [Storm Workspaces](#storm-workspaces)
62
+ - [Roadmap](#roadmap)
63
+ - [Support](#support)
64
+ - [License](#license)
65
+ - [Changelog](#changelog)
66
+ - [Contributing](#contributing)
67
+ - [Contributors](#contributors)
65
68
 
66
69
  <!-- END doctoc -->
67
70
 
@@ -8,7 +8,8 @@ exports.normalizeString = normalizeString;
8
8
  exports.normalizeWindowsPath = normalizeWindowsPath;
9
9
  exports.toAbsolutePath = toAbsolutePath;
10
10
  exports.toRelativePath = toRelativePath;
11
- var _isFile = require("./is-file.cjs");
11
+ var _cwd = require("./cwd.cjs");
12
+ var _isType = require("./is-type.cjs");
12
13
  var _joinPaths = require("./join-paths.cjs");
13
14
  var _regex = require("./regex.cjs");
14
15
  var _slash = require("./slash.cjs");
@@ -19,7 +20,7 @@ function correctPath(e) {
19
20
  if (!e || e.length === 0) return ".";
20
21
  e = normalizeWindowsPath(e);
21
22
  const n = e.match(_regex.UNC_REGEX),
22
- r = (0, _isFile.isAbsolutePath)(e),
23
+ r = (0, _isType.isAbsolutePath)(e),
23
24
  i = e.endsWith("/");
24
25
  return e = normalizeString(e, !r), e.length === 0 ? r ? "/" : i ? "./" : "." : (i && (e += "/"), _regex.DRIVE_LETTER_REGEX.test(e) && (e += "/"), n ? r ? `//${e}` : `//./${e}` : !e.startsWith("/") && r && !_regex.DRIVE_LETTER_REGEX.test(e) ? `/${e}` : e);
25
26
  }
@@ -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;
@@ -54,8 +55,8 @@ function normalizeString(e, n) {
54
55
  return r;
55
56
  }
56
57
  function toAbsolutePath(e, n) {
57
- return (0, _isFile.isAbsolutePath)(e) ? e : (0, _slash.slash)(normalizeString((0, _joinPaths.joinPaths)(n || process.cwd(), e), !0));
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, _isFile.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-file";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(";");
@@ -13,43 +13,45 @@ exports.hasFileName = hasFileName;
13
13
  exports.hasFilePath = hasFilePath;
14
14
  exports.hasFolderName = hasFolderName;
15
15
  exports.parsePath = parsePath;
16
+ exports.relative = relative;
16
17
  exports.relativePath = relativePath;
17
- exports.relativeToWorkspaceRoot = relativeToWorkspaceRoot;
18
+ exports.relativeToCurrentDir = relativeToCurrentDir;
18
19
  exports.renameFile = renameFile;
20
+ exports.resolve = resolve;
19
21
  exports.resolvePath = resolvePath;
20
22
  exports.resolvePaths = resolvePaths;
21
23
  var _base = require("@stryke/types/base");
22
- var _nodePath = require("node:path");
23
24
  var _correctPath = require("./correct-path.cjs");
24
- var _getWorkspaceRoot = require("./get-workspace-root.cjs");
25
- var _isFile = require("./is-file.cjs");
25
+ var _cwd = require("./cwd.cjs");
26
+ var _isType = require("./is-type.cjs");
26
27
  var _joinPaths = require("./join-paths.cjs");
28
+ var _regex = require("./regex.cjs");
27
29
  function findFileName(e, t = {}) {
28
30
  const {
29
- requireExtension: n = !1,
30
- withExtension: r = !0
31
+ requireExtension: r = !1,
32
+ withExtension: n = !0
31
33
  } = t,
32
34
  i = (0, _correctPath.normalizeWindowsPath)(e)?.split(e?.includes("\\") ? "\\" : "/")?.pop() ?? "";
33
- return n === !0 && !i.includes(".") ? _base.EMPTY_STRING : r === !1 && i.includes(".") ? i.substring(0, i.lastIndexOf(".")) || _base.EMPTY_STRING : i;
35
+ return r === !0 && !i.includes(".") ? _base.EMPTY_STRING : n === !1 && i.includes(".") ? i.substring(0, i.lastIndexOf(".")) || _base.EMPTY_STRING : i;
34
36
  }
35
37
  function findFilePath(e) {
36
38
  const t = (0, _correctPath.normalizeWindowsPath)(e),
37
- n = t.replace(findFileName(t, {
39
+ r = t.replace(findFileName(t, {
38
40
  requireExtension: !0
39
41
  }), "");
40
- return n === "/" ? n : n.replace(/\/$/, "");
42
+ return r === "/" ? r : r.replace(/\/$/, "");
41
43
  }
42
44
  function findFolderName(e) {
43
45
  const t = findFilePath(e).split("/");
44
- let n = "";
45
- for (let r = t.length - 1; r >= 0; r--) {
46
- const i = t[r];
46
+ let r = "";
47
+ for (let n = t.length - 1; n >= 0; n--) {
48
+ const i = t[n];
47
49
  if (i) {
48
- n = i;
50
+ r = i;
49
51
  break;
50
52
  }
51
53
  }
52
- return n ?? _base.EMPTY_STRING;
54
+ return r ?? _base.EMPTY_STRING;
53
55
  }
54
56
  function findFileExtension(e) {
55
57
  if (e.endsWith(".") || e.endsWith("/")) return;
@@ -71,42 +73,63 @@ function hasFolderName(e) {
71
73
  function hasFileExtension(e) {
72
74
  return !!findFileExtension(e);
73
75
  }
74
- function resolvePath(e, t = (0, _getWorkspaceRoot.getWorkspaceRoot)()) {
75
- const n = (0, _correctPath.normalizeWindowsPath)(e).split("/");
76
- let r = "",
76
+ function resolvePath(e, t = (0, _cwd.cwd)()) {
77
+ const r = (0, _correctPath.normalizeWindowsPath)(e).split("/");
78
+ let n = "",
77
79
  i = !1;
78
- for (let s = n.length - 1; s >= -1 && !i; s--) {
79
- const o = s >= 0 ? n[s] : t;
80
- !o || o.length === 0 || (r = (0, _joinPaths.joinPaths)(o, r), i = (0, _isFile.isAbsolutePath)(o));
80
+ for (let o = r.length - 1; o >= -1 && !i; o--) {
81
+ const s = o >= 0 ? r[o] : t;
82
+ !s || s.length === 0 || (n = (0, _joinPaths.joinPaths)(s, n), i = (0, _isType.isAbsolutePath)(s));
81
83
  }
82
- return r = (0, _correctPath.normalizeString)(r, !i), i && !(0, _isFile.isAbsolutePath)(r) ? `/${r}` : r.length > 0 ? r : ".";
84
+ return n = (0, _correctPath.normalizeString)(n, !i), i && !(0, _isType.isAbsolutePath)(n) ? `/${n}` : n.length > 0 ? n : ".";
85
+ }
86
+ function resolve(...e) {
87
+ e = e.map(n => (0, _correctPath.normalizeWindowsPath)(n));
88
+ let t = "",
89
+ r = !1;
90
+ for (let n = e.length - 1; n >= -1 && !r; n--) {
91
+ const i = n >= 0 ? e[n] : (0, _cwd.cwd)();
92
+ !i || i.length === 0 || (t = `${i}/${t}`, r = (0, _isType.isAbsolute)(i));
93
+ }
94
+ return t = (0, _correctPath.normalizeString)(t, !r), r && !(0, _isType.isAbsolute)(t) ? `/${t}` : t.length > 0 ? t : ".";
83
95
  }
84
96
  function resolvePaths(...e) {
85
97
  return resolvePath((0, _joinPaths.joinPaths)(...e.map(t => (0, _correctPath.normalizeWindowsPath)(t))));
86
98
  }
87
- function relativePath(e, t, n = !1) {
88
- return (0, _nodePath.relative)(n !== !0 ? e.replace(/\/$/, "") : e, n !== !0 ? t.replace(/\/$/, "") : t);
99
+ function relative(e, t) {
100
+ const r = resolve(e).replace(_regex.ROOT_FOLDER_REGEX, "$1").split("/"),
101
+ n = resolve(t).replace(_regex.ROOT_FOLDER_REGEX, "$1").split("/");
102
+ if (n[0][1] === ":" && r[0][1] === ":" && r[0] !== n[0]) return n.join("/");
103
+ const i = [...r];
104
+ for (const o of i) {
105
+ if (n[0] !== o) break;
106
+ r.shift(), n.shift();
107
+ }
108
+ return [...r.map(() => ".."), ...n].join("/");
109
+ }
110
+ function relativePath(e, t, r = !1) {
111
+ return relative(r !== !0 ? e.replace(/\/$/, "") : e, r !== !0 ? t.replace(/\/$/, "") : t);
89
112
  }
90
- function relativeToWorkspaceRoot(e) {
91
- return relativePath(e, (0, _getWorkspaceRoot.getWorkspaceRoot)());
113
+ function relativeToCurrentDir(e) {
114
+ return relativePath(e, (0, _cwd.cwd)());
92
115
  }
93
116
  function parsePath(e) {
94
117
  const t = /^[/\\]|^[a-z]:[/\\]/i.exec(e)?.[0]?.replace(/\\/g, "/") || "",
95
- n = (0, _correctPath.normalizeWindowsPath)(e),
96
- r = n.replace(/\/$/, "").split("/").slice(0, -1);
97
- r.length === 1 && /^[A-Z]:$/i.test(r[0]) && (r[0] += "/");
98
- const i = findFolderName(n),
99
- s = r.join("/") || ((0, _isFile.isAbsolutePath)(e) ? "/" : "."),
100
- o = findFileExtensionSafe(e);
118
+ r = (0, _correctPath.normalizeWindowsPath)(e),
119
+ n = r.replace(/\/$/, "").split("/").slice(0, -1);
120
+ n.length === 1 && /^[A-Z]:$/i.test(n[0]) && (n[0] += "/");
121
+ const i = findFolderName(r),
122
+ o = n.join("/") || ((0, _isType.isAbsolutePath)(e) ? "/" : "."),
123
+ s = findFileExtensionSafe(e);
101
124
  return {
102
125
  root: t,
103
- dir: s,
126
+ dir: o,
104
127
  base: i,
105
- ext: o,
106
- name: i.slice(0, i.length - o.length)
128
+ ext: s,
129
+ name: i.slice(0, i.length - s.length)
107
130
  };
108
131
  }
109
132
  function renameFile(e, t) {
110
- const n = parsePath(e);
111
- return (0, _joinPaths.joinPaths)(n.dir, t.includes(".") ? t : t + n.ext);
133
+ const r = parsePath(e);
134
+ return (0, _joinPaths.joinPaths)(r.dir, t.includes(".") ? t : t + r.ext);
112
135
  }
@@ -117,6 +117,7 @@ export declare function hasFileExtension(filePath: string): boolean;
117
117
  * @returns The resolved path
118
118
  */
119
119
  export declare function resolvePath(path: string, cwd?: string): string;
120
+ export declare function resolve(...paths: string[]): string;
120
121
  /**
121
122
  * Resolve the file path to an absolute path.
122
123
  *
@@ -124,6 +125,17 @@ export declare function resolvePath(path: string, cwd?: string): string;
124
125
  * @returns The resolved path
125
126
  */
126
127
  export declare function resolvePaths(...paths: string[]): string;
128
+ /**
129
+ * Get the relative path from one file to another.
130
+ *
131
+ * @remarks
132
+ * This function is similar to the `path.relative` function in Node's path module.
133
+ *
134
+ * @param from - The base path to start from
135
+ * @param to - The target path to resolve relative to the base path
136
+ * @returns The relative path from the base path to the target path
137
+ */
138
+ export declare function relative(from: string, to: string): string;
127
139
  /**
128
140
  * Get the relative path from one file to another.
129
141
  *
@@ -142,7 +154,7 @@ export declare function relativePath(from: string, to: string, withEndSlash?: bo
142
154
  * @param filePath - The file path to process
143
155
  * @returns The resolved file path
144
156
  */
145
- export declare function relativeToWorkspaceRoot(filePath: string): string;
157
+ export declare function relativeToCurrentDir(filePath: string): string;
146
158
  /**
147
159
  * Check if the path is a relative path.
148
160
  *
@@ -1 +1 @@
1
- import{EMPTY_STRING as a}from"@stryke/types/base";import{relative as p}from"node:path";import{normalizeString as g,normalizeWindowsPath as l}from"./correct-path";import{getWorkspaceRoot as f}from"./get-workspace-root";import{isAbsolutePath as u}from"./is-file";import{joinPaths as c}from"./join-paths";export function findFileName(e,t={}){const{requireExtension:n=!1,withExtension:r=!0}=t,i=l(e)?.split(e?.includes("\\")?"\\":"/")?.pop()??"";return n===!0&&!i.includes(".")?a:r===!1&&i.includes(".")?i.substring(0,i.lastIndexOf("."))||a:i}export function findFilePath(e){const t=l(e),n=t.replace(findFileName(t,{requireExtension:!0}),"");return n==="/"?n:n.replace(/\/$/,"")}export function findFolderName(e){const t=findFilePath(e).split("/");let n="";for(let r=t.length-1;r>=0;r--){const i=t[r];if(i){n=i;break}}return n??a}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=f()){const n=l(e).split("/");let r="",i=!1;for(let s=n.length-1;s>=-1&&!i;s--){const o=s>=0?n[s]:t;!o||o.length===0||(r=c(o,r),i=u(o))}return r=g(r,!i),i&&!u(r)?`/${r}`:r.length>0?r:"."}export function resolvePaths(...e){return resolvePath(c(...e.map(t=>l(t))))}export function relativePath(e,t,n=!1){return p(n!==!0?e.replace(/\/$/,""):e,n!==!0?t.replace(/\/$/,""):t)}export function relativeToWorkspaceRoot(e){return relativePath(e,f())}export function parsePath(e){const t=/^[/\\]|^[a-z]:[/\\]/i.exec(e)?.[0]?.replace(/\\/g,"/")||"",n=l(e),r=n.replace(/\/$/,"").split("/").slice(0,-1);r.length===1&&/^[A-Z]:$/i.test(r[0])&&(r[0]+="/");const i=findFolderName(n),s=r.join("/")||(u(e)?"/":"."),o=findFileExtensionSafe(e);return{root:t,dir:s,base:i,ext:o,name:i.slice(0,i.length-o.length)}}export function renameFile(e,t){const n=parsePath(e);return c(n.dir,t.includes(".")?t:t+n.ext)}
1
+ 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{ROOT_FOLDER_REGEX as d}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=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(d,"$1").split("/"),n=resolve(t).replace(d,"$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)}
@@ -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
@@ -25,25 +25,25 @@ Object.keys(_correctPath).forEach(function (key) {
25
25
  }
26
26
  });
27
27
  });
28
- var _delimiter = require("./delimiter.cjs");
29
- Object.keys(_delimiter).forEach(function (key) {
28
+ var _cwd = require("./cwd.cjs");
29
+ Object.keys(_cwd).forEach(function (key) {
30
30
  if (key === "default" || key === "__esModule") return;
31
- if (key in exports && exports[key] === _delimiter[key]) return;
31
+ if (key in exports && exports[key] === _cwd[key]) return;
32
32
  Object.defineProperty(exports, key, {
33
33
  enumerable: true,
34
34
  get: function () {
35
- return _delimiter[key];
35
+ return _cwd[key];
36
36
  }
37
37
  });
38
38
  });
39
- var _exists = require("./exists.cjs");
40
- Object.keys(_exists).forEach(function (key) {
39
+ var _delimiter = require("./delimiter.cjs");
40
+ Object.keys(_delimiter).forEach(function (key) {
41
41
  if (key === "default" || key === "__esModule") return;
42
- if (key in exports && exports[key] === _exists[key]) return;
42
+ if (key in exports && exports[key] === _delimiter[key]) return;
43
43
  Object.defineProperty(exports, key, {
44
44
  enumerable: true,
45
45
  get: function () {
46
- return _exists[key];
46
+ return _delimiter[key];
47
47
  }
48
48
  });
49
49
  });
@@ -69,28 +69,6 @@ Object.keys(_getParentPath).forEach(function (key) {
69
69
  }
70
70
  });
71
71
  });
72
- var _getWorkspaceRoot = require("./get-workspace-root.cjs");
73
- Object.keys(_getWorkspaceRoot).forEach(function (key) {
74
- if (key === "default" || key === "__esModule") return;
75
- if (key in exports && exports[key] === _getWorkspaceRoot[key]) return;
76
- Object.defineProperty(exports, key, {
77
- enumerable: true,
78
- get: function () {
79
- return _getWorkspaceRoot[key];
80
- }
81
- });
82
- });
83
- var _isFile = require("./is-file.cjs");
84
- Object.keys(_isFile).forEach(function (key) {
85
- if (key === "default" || key === "__esModule") return;
86
- if (key in exports && exports[key] === _isFile[key]) return;
87
- Object.defineProperty(exports, key, {
88
- enumerable: true,
89
- get: function () {
90
- return _isFile[key];
91
- }
92
- });
93
- });
94
72
  var _isParentPath = require("./is-parent-path.cjs");
95
73
  Object.keys(_isParentPath).forEach(function (key) {
96
74
  if (key === "default" || key === "__esModule") return;
@@ -146,17 +124,6 @@ Object.keys(_replace).forEach(function (key) {
146
124
  }
147
125
  });
148
126
  });
149
- var _resolve = require("./resolve.cjs");
150
- Object.keys(_resolve).forEach(function (key) {
151
- if (key === "default" || key === "__esModule") return;
152
- if (key in exports && exports[key] === _resolve[key]) return;
153
- Object.defineProperty(exports, key, {
154
- enumerable: true,
155
- get: function () {
156
- return _resolve[key];
157
- }
158
- });
159
- });
160
127
  var _slash = require("./slash.cjs");
161
128
  Object.keys(_slash).forEach(function (key) {
162
129
  if (key === "default" || key === "__esModule") return;
package/dist/index.d.ts CHANGED
@@ -8,16 +8,13 @@
8
8
  */
9
9
  export * from "./asset-extensions";
10
10
  export * from "./correct-path";
11
+ export * from "./cwd";
11
12
  export * from "./delimiter";
12
- export * from "./exists";
13
13
  export * from "./file-path-fns";
14
14
  export * from "./get-parent-path";
15
- export * from "./get-workspace-root";
16
- export * from "./is-file";
17
15
  export * from "./is-parent-path";
18
16
  export * from "./is-root-dir";
19
17
  export * from "./join-paths";
20
18
  export * from "./regex";
21
19
  export * from "./replace";
22
- export * from "./resolve";
23
20
  export * from "./slash";
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-parent-path";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"./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.isSystemRoot = void 0;
7
- const isSystemRoot = o => o === "/" || o === "c:\\" || o === "C:\\";
8
- exports.isSystemRoot = isSystemRoot;
6
+ exports.isSystemRoot = isSystemRoot;
7
+ function isSystemRoot(o) {
8
+ return o === "/" || o === "c:\\" || o === "C:\\";
9
+ }
@@ -4,4 +4,4 @@
4
4
  * @param dir - The directory to check.
5
5
  * @returns Returns true if the directory is the root directory.
6
6
  */
7
- export declare const isSystemRoot: (dir: string) => boolean;
7
+ export declare function isSystemRoot(dir: string): boolean;
@@ -1 +1 @@
1
- export const isSystemRoot=o=>o==="/"||o==="c:\\"||o==="C:\\";
1
+ export function isSystemRoot(o){return o==="/"||o==="c:\\"||o==="C:\\"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isAbsolute = isAbsolute;
7
+ exports.isAbsolutePath = isAbsolutePath;
8
+ exports.isRelative = isRelative;
9
+ exports.isRelativePath = isRelativePath;
10
+ var _regex = require("./regex.cjs");
11
+ var _slash = require("./slash.cjs");
12
+ function isAbsolutePath(t) {
13
+ return _regex.ABSOLUTE_PATH_REGEX.test((0, _slash.slash)(t));
14
+ }
15
+ function isAbsolute(t) {
16
+ return isAbsolutePath(t);
17
+ }
18
+ function isRelativePath(t) {
19
+ return !isAbsolutePath(t);
20
+ }
21
+ function isRelative(t) {
22
+ return isRelativePath(t);
23
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Check if the path is an absolute path.
3
+ *
4
+ * @param path - The path to check
5
+ * @returns An indicator specifying if the path is an absolute path
6
+ */
7
+ export declare function isAbsolutePath(path: string): boolean;
8
+ /**
9
+ * Check if the path is an absolute path.
10
+ *
11
+ * @remarks
12
+ * This is an alias for {@link isAbsolutePath}.
13
+ *
14
+ * @param path - The path to check
15
+ * @returns An indicator specifying if the path is an absolute path
16
+ */
17
+ export declare function isAbsolute(path: string): boolean;
18
+ /**
19
+ * Check if the path is a relative path.
20
+ *
21
+ * @param path - The path to check
22
+ * @returns An indicator specifying if the path is a relative path
23
+ */
24
+ export declare function isRelativePath(path: string): boolean;
25
+ /**
26
+ * Check if the path is a relative path.
27
+ *
28
+ * @remarks
29
+ * This is an alias for {@link isRelativePath}.
30
+ *
31
+ * @param path - The path to check
32
+ * @returns An indicator specifying if the path is a relative path
33
+ */
34
+ export declare function isRelative(path: string): boolean;
@@ -0,0 +1 @@
1
+ import{ABSOLUTE_PATH_REGEX as o}from"./regex";import{slash as n}from"./slash";export function isAbsolutePath(t){return o.test(n(t))}export function isAbsolute(t){return isAbsolutePath(t)}export function isRelativePath(t){return!isAbsolutePath(t)}export function isRelative(t){return isRelativePath(t)}