@stryke/path 0.12.4 → 0.13.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/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,7 @@ 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 _isType = require("./is-type.cjs");
12
12
  var _joinPaths = require("./join-paths.cjs");
13
13
  var _regex = require("./regex.cjs");
14
14
  var _slash = require("./slash.cjs");
@@ -19,7 +19,7 @@ function correctPath(e) {
19
19
  if (!e || e.length === 0) return ".";
20
20
  e = normalizeWindowsPath(e);
21
21
  const n = e.match(_regex.UNC_REGEX),
22
- r = (0, _isFile.isAbsolutePath)(e),
22
+ r = (0, _isType.isAbsolutePath)(e),
23
23
  i = e.endsWith("/");
24
24
  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
25
  }
@@ -54,8 +54,8 @@ function normalizeString(e, n) {
54
54
  return r;
55
55
  }
56
56
  function toAbsolutePath(e, n) {
57
- return (0, _isFile.isAbsolutePath)(e) ? e : (0, _slash.slash)(normalizeString((0, _joinPaths.joinPaths)(n || process.cwd(), e), !0));
57
+ return (0, _isType.isAbsolutePath)(e) ? e : (0, _slash.slash)(normalizeString((0, _joinPaths.joinPaths)(n || process.cwd(), e), !0));
58
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
+ 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);
61
61
  }
@@ -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{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)}
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.currentDir = currentDir;
6
7
  exports.findFileExtension = findFileExtension;
7
8
  exports.findFileExtensionSafe = findFileExtensionSafe;
8
9
  exports.findFileName = findFileName;
@@ -13,43 +14,44 @@ exports.hasFileName = hasFileName;
13
14
  exports.hasFilePath = hasFilePath;
14
15
  exports.hasFolderName = hasFolderName;
15
16
  exports.parsePath = parsePath;
17
+ exports.relative = relative;
16
18
  exports.relativePath = relativePath;
17
- exports.relativeToWorkspaceRoot = relativeToWorkspaceRoot;
19
+ exports.relativeToCurrentDir = relativeToCurrentDir;
18
20
  exports.renameFile = renameFile;
21
+ exports.resolve = resolve;
19
22
  exports.resolvePath = resolvePath;
20
23
  exports.resolvePaths = resolvePaths;
21
24
  var _base = require("@stryke/types/base");
22
- var _nodePath = require("node:path");
23
25
  var _correctPath = require("./correct-path.cjs");
24
- var _getWorkspaceRoot = require("./get-workspace-root.cjs");
25
- var _isFile = require("./is-file.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,66 @@ 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 = currentDir()) {
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] : currentDir();
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 currentDir() {
100
+ return typeof process < "u" && typeof process.cwd == "function" ? process.cwd().replace(/\\/g, "/") : "/";
101
+ }
102
+ function relative(e, t) {
103
+ const r = resolve(e).replace(_regex.ROOT_FOLDER_REGEX, "$1").split("/"),
104
+ n = resolve(t).replace(_regex.ROOT_FOLDER_REGEX, "$1").split("/");
105
+ if (n[0][1] === ":" && r[0][1] === ":" && r[0] !== n[0]) return n.join("/");
106
+ const i = [...r];
107
+ for (const o of i) {
108
+ if (n[0] !== o) break;
109
+ r.shift(), n.shift();
110
+ }
111
+ return [...r.map(() => ".."), ...n].join("/");
112
+ }
113
+ function relativePath(e, t, r = !1) {
114
+ return relative(r !== !0 ? e.replace(/\/$/, "") : e, r !== !0 ? t.replace(/\/$/, "") : t);
89
115
  }
90
- function relativeToWorkspaceRoot(e) {
91
- return relativePath(e, (0, _getWorkspaceRoot.getWorkspaceRoot)());
116
+ function relativeToCurrentDir(e) {
117
+ return relativePath(e, currentDir());
92
118
  }
93
119
  function parsePath(e) {
94
120
  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);
121
+ r = (0, _correctPath.normalizeWindowsPath)(e),
122
+ n = r.replace(/\/$/, "").split("/").slice(0, -1);
123
+ n.length === 1 && /^[A-Z]:$/i.test(n[0]) && (n[0] += "/");
124
+ const i = findFolderName(r),
125
+ o = n.join("/") || ((0, _isType.isAbsolutePath)(e) ? "/" : "."),
126
+ s = findFileExtensionSafe(e);
101
127
  return {
102
128
  root: t,
103
- dir: s,
129
+ dir: o,
104
130
  base: i,
105
- ext: o,
106
- name: i.slice(0, i.length - o.length)
131
+ ext: s,
132
+ name: i.slice(0, i.length - s.length)
107
133
  };
108
134
  }
109
135
  function renameFile(e, t) {
110
- const n = parsePath(e);
111
- return (0, _joinPaths.joinPaths)(n.dir, t.includes(".") ? t : t + n.ext);
136
+ const r = parsePath(e);
137
+ return (0, _joinPaths.joinPaths)(r.dir, t.includes(".") ? t : t + r.ext);
112
138
  }
@@ -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,23 @@ 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 current working directory.
130
+ *
131
+ * @returns The current working directory or '/' if it cannot be determined
132
+ */
133
+ export declare function currentDir(): string;
134
+ /**
135
+ * Get the relative path from one file to another.
136
+ *
137
+ * @remarks
138
+ * This function is similar to the `path.relative` function in Node's path module.
139
+ *
140
+ * @param from - The base path to start from
141
+ * @param to - The target path to resolve relative to the base path
142
+ * @returns The relative path from the base path to the target path
143
+ */
144
+ export declare function relative(from: string, to: string): string;
127
145
  /**
128
146
  * Get the relative path from one file to another.
129
147
  *
@@ -142,7 +160,7 @@ export declare function relativePath(from: string, to: string, withEndSlash?: bo
142
160
  * @param filePath - The file path to process
143
161
  * @returns The resolved file path
144
162
  */
145
- export declare function relativeToWorkspaceRoot(filePath: string): string;
163
+ export declare function relativeToCurrentDir(filePath: string): string;
146
164
  /**
147
165
  * Check if the path is a relative path.
148
166
  *
@@ -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 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)}
package/dist/index.cjs CHANGED
@@ -36,17 +36,6 @@ Object.keys(_delimiter).forEach(function (key) {
36
36
  }
37
37
  });
38
38
  });
39
- var _exists = require("./exists.cjs");
40
- Object.keys(_exists).forEach(function (key) {
41
- if (key === "default" || key === "__esModule") return;
42
- if (key in exports && exports[key] === _exists[key]) return;
43
- Object.defineProperty(exports, key, {
44
- enumerable: true,
45
- get: function () {
46
- return _exists[key];
47
- }
48
- });
49
- });
50
39
  var _filePathFns = require("./file-path-fns.cjs");
51
40
  Object.keys(_filePathFns).forEach(function (key) {
52
41
  if (key === "default" || key === "__esModule") return;
@@ -69,17 +58,6 @@ Object.keys(_getParentPath).forEach(function (key) {
69
58
  }
70
59
  });
71
60
  });
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
61
  var _isFile = require("./is-file.cjs");
84
62
  Object.keys(_isFile).forEach(function (key) {
85
63
  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
@@ -9,15 +9,12 @@
9
9
  export * from "./asset-extensions";
10
10
  export * from "./correct-path";
11
11
  export * from "./delimiter";
12
- export * from "./exists";
13
12
  export * from "./file-path-fns";
14
13
  export * from "./get-parent-path";
15
- export * from "./get-workspace-root";
16
14
  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"./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";
package/dist/is-file.cjs CHANGED
@@ -3,16 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.isAbsolutePath = isAbsolutePath;
7
6
  exports.isDirectory = isDirectory;
8
7
  exports.isDirectorySymlink = void 0;
9
8
  exports.isFile = isFile;
10
9
  exports.isFileSymlink = void 0;
11
- exports.isRelativePath = isRelativePath;
12
10
  var _nodeFs = require("node:fs");
13
11
  var _joinPaths = require("./join-paths.cjs");
14
- var _regex = require("./regex.cjs");
15
- var _slash = require("./slash.cjs");
16
12
  function isFile(r, o) {
17
13
  return !!(0, _nodeFs.statSync)(o ? (0, _joinPaths.joinPaths)(o, r) : r, {
18
14
  throwIfNoEntry: !1
@@ -30,10 +26,4 @@ const isFileSymlink = (r, o) => !!(0, _nodeFs.lstatSync)(o ? (0, _joinPaths.join
30
26
  throwIfNoEntry: !1
31
27
  })?.isDirectory();
32
28
  exports.isDirectorySymlink = isDirectorySymlink;
33
- exports.isFileSymlink = isFileSymlink;
34
- function isAbsolutePath(r) {
35
- return _regex.ABSOLUTE_PATH_REGEX.test((0, _slash.slash)(r));
36
- }
37
- function isRelativePath(r) {
38
- return !isAbsolutePath(r);
39
- }
29
+ exports.isFileSymlink = isFileSymlink;
package/dist/is-file.d.ts CHANGED
@@ -30,17 +30,3 @@ export declare const isFileSymlink: (path: string, additionalPath?: string) => b
30
30
  * @returns An indicator specifying if the path is a directory
31
31
  */
32
32
  export declare const isDirectorySymlink: (path: string, additionalPath?: string) => boolean;
33
- /**
34
- * Check if the path is an absolute path.
35
- *
36
- * @param path - The path to check
37
- * @returns An indicator specifying if the path is an absolute path
38
- */
39
- export declare function isAbsolutePath(path: string): boolean;
40
- /**
41
- * Check if the path is a relative path.
42
- *
43
- * @param path - The path to check
44
- * @returns An indicator specifying if the path is a relative path
45
- */
46
- export declare function isRelativePath(path: string): boolean;
package/dist/is-file.mjs CHANGED
@@ -1 +1 @@
1
- import{lstatSync as n,statSync as e}from"node:fs";import{joinPaths as t}from"./join-paths";import{ABSOLUTE_PATH_REGEX as s}from"./regex";import{slash as i}from"./slash";export function isFile(r,o){return!!e(o?t(o,r):r,{throwIfNoEntry:!1})?.isFile()}export function isDirectory(r,o){return!!e(o?t(o,r):r,{throwIfNoEntry:!1})?.isDirectory()}export const isFileSymlink=(r,o)=>!!n(o?t(o,r):r,{throwIfNoEntry:!1})?.isFile(),isDirectorySymlink=(r,o)=>!!n(o?t(o,r):r,{throwIfNoEntry:!1})?.isDirectory();export function isAbsolutePath(r){return s.test(i(r))}export function isRelativePath(r){return!isAbsolutePath(r)}
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();
@@ -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)}
@@ -3,62 +3,56 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.joinPaths = void 0;
7
- const g = /^[A-Z]:\//i;
8
- function u(e = "") {
9
- return e && e.replace(/\\/g, "/").replace(g, t => t.toUpperCase());
6
+ exports.joinPaths = joinPaths;
7
+ var _isType = require("./is-type.cjs");
8
+ var _regex = require("./regex.cjs");
9
+ function m(n = "") {
10
+ return n && n.replace(/\\/g, "/").replace(_regex.DRIVE_LETTER_START_REGEX, t => t.toUpperCase());
11
+ }
12
+ function R(n) {
13
+ if (!n || n.length === 0) return ".";
14
+ n = m(n);
15
+ const t = n.match(_regex.UNC_REGEX),
16
+ e = (0, _isType.isAbsolute)(n),
17
+ l = n[n.length - 1] === "/";
18
+ return n = a(n, !e), n.length === 0 ? e ? "/" : l ? "./" : "." : (l && (n += "/"), _regex.DRIVE_LETTER_REGEX.test(n) && (n += "/"), t ? e ? `//${n}` : `//./${n}` : e && !(0, _isType.isAbsolute)(n) ? `/${n}` : n);
10
19
  }
11
- const E = /^[/\\]{2}/,
12
- _ = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i,
13
- a = /^[A-Z]:$/i,
14
- c = function (e) {
15
- return _.test(e);
16
- },
17
- h = function (e) {
18
- if (!e || e.length === 0) return ".";
19
- e = u(e);
20
- const t = e.match(E),
21
- n = c(e),
22
- s = e[e.length - 1] === "/";
23
- return e = R(e, !n), e.length === 0 ? n ? "/" : s ? "./" : "." : (s && (e += "/"), a.test(e) && (e += "/"), t ? n ? `//${e}` : `//./${e}` : n && !c(e) ? `/${e}` : e);
24
- };
25
- const joinPaths = function (...e) {
20
+ function joinPaths(...n) {
26
21
  let t = "";
27
- for (const n of e) if (n) if (t.length > 0) {
28
- const s = t[t.length - 1] === "/",
29
- i = n[0] === "/";
30
- s && i ? t += n.slice(1) : t += s || i ? n : `/${n}`;
31
- } else t += n;
32
- return h(t);
33
- };
34
- exports.joinPaths = joinPaths;
35
- function R(e, t) {
36
- let n = "",
37
- s = 0,
38
- i = -1,
39
- o = 0,
40
- r = null;
41
- for (let l = 0; l <= e.length; ++l) {
42
- if (l < e.length) r = e[l];else {
43
- if (r === "/") break;
44
- r = "/";
22
+ for (const e of n) if (e) if (t.length > 0) {
23
+ const l = t[t.length - 1] === "/",
24
+ s = e[0] === "/";
25
+ l && s ? t += e.slice(1) : t += l || s ? e : `/${e}`;
26
+ } else t += e;
27
+ return R(t);
28
+ }
29
+ function a(n, t) {
30
+ let e = "",
31
+ l = 0,
32
+ s = -1,
33
+ r = 0,
34
+ o = null;
35
+ for (let i = 0; i <= n.length; ++i) {
36
+ if (i < n.length) o = n[i];else {
37
+ if (o === "/") break;
38
+ o = "/";
45
39
  }
46
- if (r === "/") {
47
- if (!(i === l - 1 || o === 1)) if (o === 2) {
48
- if (n.length < 2 || s !== 2 || n[n.length - 1] !== "." || n[n.length - 2] !== ".") {
49
- if (n.length > 2) {
50
- const f = n.lastIndexOf("/");
51
- f === -1 ? (n = "", s = 0) : (n = n.slice(0, f), s = n.length - 1 - n.lastIndexOf("/")), i = l, o = 0;
40
+ if (o === "/") {
41
+ if (!(s === i - 1 || r === 1)) if (r === 2) {
42
+ if (e.length < 2 || l !== 2 || e[e.length - 1] !== "." || e[e.length - 2] !== ".") {
43
+ if (e.length > 2) {
44
+ const f = e.lastIndexOf("/");
45
+ f === -1 ? (e = "", l = 0) : (e = e.slice(0, f), l = e.length - 1 - e.lastIndexOf("/")), s = i, r = 0;
52
46
  continue;
53
- } else if (n.length > 0) {
54
- n = "", s = 0, i = l, o = 0;
47
+ } else if (e.length > 0) {
48
+ e = "", l = 0, s = i, r = 0;
55
49
  continue;
56
50
  }
57
51
  }
58
- t && (n += n.length > 0 ? "/.." : "..", s = 2);
59
- } else n.length > 0 ? n += `/${e.slice(i + 1, l)}` : n = e.slice(i + 1, l), s = l - i - 1;
60
- i = l, o = 0;
61
- } else r === "." && o !== -1 ? ++o : o = -1;
52
+ t && (e += e.length > 0 ? "/.." : "..", l = 2);
53
+ } else e.length > 0 ? e += `/${n.slice(s + 1, i)}` : e = n.slice(s + 1, i), l = i - s - 1;
54
+ s = i, r = 0;
55
+ } else o === "." && r !== -1 ? ++r : r = -1;
62
56
  }
63
- return n;
57
+ return e;
64
58
  }
@@ -1,4 +1,3 @@
1
- import type path from "node:path";
2
1
  /**
3
2
  * Joins all given path segments together using the platform-specific separator as a delimiter.
4
3
  * The resulting path is normalized to remove any redundant or unnecessary segments.
@@ -6,4 +5,4 @@ import type path from "node:path";
6
5
  * @param segments - The path segments to join.
7
6
  * @returns The joined and normalized path string.
8
7
  */
9
- export declare const joinPaths: typeof path.join;
8
+ export declare function joinPaths(...segments: string[]): string;
@@ -1 +1 @@
1
- const g=/^[A-Z]:\//i;function u(e=""){return e&&e.replace(/\\/g,"/").replace(g,t=>t.toUpperCase())}const E=/^[/\\]{2}/,_=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i,a=/^[A-Z]:$/i,c=function(e){return _.test(e)},h=function(e){if(!e||e.length===0)return".";e=u(e);const t=e.match(E),n=c(e),s=e[e.length-1]==="/";return e=R(e,!n),e.length===0?n?"/":s?"./":".":(s&&(e+="/"),a.test(e)&&(e+="/"),t?n?`//${e}`:`//./${e}`:n&&!c(e)?`/${e}`:e)};export const joinPaths=function(...e){let t="";for(const n of e)if(n)if(t.length>0){const s=t[t.length-1]==="/",i=n[0]==="/";s&&i?t+=n.slice(1):t+=s||i?n:`/${n}`}else t+=n;return h(t)};function R(e,t){let n="",s=0,i=-1,o=0,r=null;for(let l=0;l<=e.length;++l){if(l<e.length)r=e[l];else{if(r==="/")break;r="/"}if(r==="/"){if(!(i===l-1||o===1))if(o===2){if(n.length<2||s!==2||n[n.length-1]!=="."||n[n.length-2]!=="."){if(n.length>2){const f=n.lastIndexOf("/");f===-1?(n="",s=0):(n=n.slice(0,f),s=n.length-1-n.lastIndexOf("/")),i=l,o=0;continue}else if(n.length>0){n="",s=0,i=l,o=0;continue}}t&&(n+=n.length>0?"/..":"..",s=2)}else n.length>0?n+=`/${e.slice(i+1,l)}`:n=e.slice(i+1,l),s=l-i-1;i=l,o=0}else r==="."&&o!==-1?++o:o=-1}return n}
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}
package/dist/regex.cjs CHANGED
@@ -3,8 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.UNC_REGEX = exports.DRIVE_LETTER_START_REGEX = exports.DRIVE_LETTER_REGEX = exports.ABSOLUTE_PATH_REGEX = void 0;
6
+ exports.UNC_REGEX = exports.ROOT_FOLDER_REGEX = exports.DRIVE_LETTER_START_REGEX = exports.DRIVE_LETTER_REGEX = exports.ABSOLUTE_PATH_REGEX = void 0;
7
7
  const DRIVE_LETTER_START_REGEX = exports.DRIVE_LETTER_START_REGEX = /^[A-Z]:\//i,
8
8
  DRIVE_LETTER_REGEX = exports.DRIVE_LETTER_REGEX = /^[A-Z]:$/i,
9
9
  UNC_REGEX = exports.UNC_REGEX = /^[/\\]{2}/,
10
- ABSOLUTE_PATH_REGEX = exports.ABSOLUTE_PATH_REGEX = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^~[/\\]|^[A-Z]:[/\\]/i;
10
+ ABSOLUTE_PATH_REGEX = exports.ABSOLUTE_PATH_REGEX = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^~[/\\]|^[A-Z]:[/\\]/i,
11
+ ROOT_FOLDER_REGEX = exports.ROOT_FOLDER_REGEX = /^\/([A-Z]:)?$/i;
package/dist/regex.d.ts CHANGED
@@ -2,3 +2,4 @@ export declare const DRIVE_LETTER_START_REGEX: RegExp;
2
2
  export declare const DRIVE_LETTER_REGEX: RegExp;
3
3
  export declare const UNC_REGEX: RegExp;
4
4
  export declare const ABSOLUTE_PATH_REGEX: RegExp;
5
+ export declare const ROOT_FOLDER_REGEX: RegExp;
package/dist/regex.mjs CHANGED
@@ -1 +1 @@
1
- export const DRIVE_LETTER_START_REGEX=/^[A-Z]:\//i,DRIVE_LETTER_REGEX=/^[A-Z]:$/i,UNC_REGEX=/^[/\\]{2}/,ABSOLUTE_PATH_REGEX=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^~[/\\]|^[A-Z]:[/\\]/i;
1
+ export const DRIVE_LETTER_START_REGEX=/^[A-Z]:\//i,DRIVE_LETTER_REGEX=/^[A-Z]:$/i,UNC_REGEX=/^[/\\]{2}/,ABSOLUTE_PATH_REGEX=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^~[/\\]|^[A-Z]:[/\\]/i,ROOT_FOLDER_REGEX=/^\/([A-Z]:)?$/i;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/path",
3
- "version": "0.12.4",
3
+ "version": "0.13.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": {
@@ -9,9 +9,9 @@
9
9
  "directory": "packages/path"
10
10
  },
11
11
  "private": false,
12
- "dependencies": { "@storm-software/config-tools": "latest", "mlly": "1.7.4" },
13
- "devDependencies": { "@stryke/types": "^0.8.9", "@types/node": "^22.14.0" },
12
+ "devDependencies": { "@stryke/types": "^0.8.9" },
14
13
  "publishConfig": { "access": "public" },
14
+ "dependencies": {},
15
15
  "sideEffects": false,
16
16
  "files": ["dist/**/*"],
17
17
  "homepage": "https://stormsoftware.com",
@@ -63,20 +63,6 @@
63
63
  },
64
64
  "default": { "types": "./dist/slash.d.ts", "default": "./dist/slash.mjs" }
65
65
  },
66
- "./resolve": {
67
- "import": {
68
- "types": "./dist/resolve.d.ts",
69
- "default": "./dist/resolve.mjs"
70
- },
71
- "require": {
72
- "types": "./dist/resolve.d.ts",
73
- "default": "./dist/resolve.cjs"
74
- },
75
- "default": {
76
- "types": "./dist/resolve.d.ts",
77
- "default": "./dist/resolve.mjs"
78
- }
79
- },
80
66
  "./replace": {
81
67
  "import": {
82
68
  "types": "./dist/replace.d.ts",
@@ -113,6 +99,20 @@
113
99
  "default": "./dist/join-paths.mjs"
114
100
  }
115
101
  },
102
+ "./is-type": {
103
+ "import": {
104
+ "types": "./dist/is-type.d.ts",
105
+ "default": "./dist/is-type.mjs"
106
+ },
107
+ "require": {
108
+ "types": "./dist/is-type.d.ts",
109
+ "default": "./dist/is-type.cjs"
110
+ },
111
+ "default": {
112
+ "types": "./dist/is-type.d.ts",
113
+ "default": "./dist/is-type.mjs"
114
+ }
115
+ },
116
116
  "./is-root-dir": {
117
117
  "import": {
118
118
  "types": "./dist/is-root-dir.d.ts",
@@ -163,20 +163,6 @@
163
163
  },
164
164
  "default": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" }
165
165
  },
166
- "./get-workspace-root": {
167
- "import": {
168
- "types": "./dist/get-workspace-root.d.ts",
169
- "default": "./dist/get-workspace-root.mjs"
170
- },
171
- "require": {
172
- "types": "./dist/get-workspace-root.d.ts",
173
- "default": "./dist/get-workspace-root.cjs"
174
- },
175
- "default": {
176
- "types": "./dist/get-workspace-root.d.ts",
177
- "default": "./dist/get-workspace-root.mjs"
178
- }
179
- },
180
166
  "./get-parent-path": {
181
167
  "import": {
182
168
  "types": "./dist/get-parent-path.d.ts",
@@ -205,20 +191,6 @@
205
191
  "default": "./dist/file-path-fns.mjs"
206
192
  }
207
193
  },
208
- "./exists": {
209
- "import": {
210
- "types": "./dist/exists.d.ts",
211
- "default": "./dist/exists.mjs"
212
- },
213
- "require": {
214
- "types": "./dist/exists.d.ts",
215
- "default": "./dist/exists.cjs"
216
- },
217
- "default": {
218
- "types": "./dist/exists.d.ts",
219
- "default": "./dist/exists.mjs"
220
- }
221
- },
222
194
  "./delimiter": {
223
195
  "import": {
224
196
  "types": "./dist/delimiter.d.ts",
@@ -274,5 +246,5 @@
274
246
  "main": "./dist/index.cjs",
275
247
  "module": "./dist/index.mjs",
276
248
  "types": "./dist/index.d.ts",
277
- "gitHead": "ceb7bf70391cec255b1f5a976f054611707d245f"
249
+ "gitHead": "dc317cbe47e06f3b3f7887b9176087c3de488853"
278
250
  }
package/dist/exists.cjs DELETED
@@ -1,12 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.existsSync = exports.exists = void 0;
7
- var _nodeFs = require("node:fs");
8
- var _promises = require("node:fs/promises");
9
- const existsSync = s => (0, _nodeFs.existsSync)(s),
10
- exists = async s => (0, _promises.access)(s, _promises.constants.F_OK).then(() => !0).catch(() => !1);
11
- exports.exists = exists;
12
- exports.existsSync = existsSync;
package/dist/exists.d.ts DELETED
@@ -1,14 +0,0 @@
1
- /**
2
- * Check if a file exists
3
- *
4
- * @param filePath - The file path to check
5
- * @returns An indicator specifying if the file exists
6
- */
7
- export declare const existsSync: (filePath: string) => boolean;
8
- /**
9
- * Check if a file exists
10
- *
11
- * @param filePath - The file path to check
12
- * @returns An indicator specifying if the file exists
13
- */
14
- export declare const exists: (filePath: string) => Promise<boolean>;
package/dist/exists.mjs DELETED
@@ -1 +0,0 @@
1
- import{existsSync as t}from"node:fs";import{access as e,constants as n}from"node:fs/promises";export const existsSync=s=>t(s),exists=async s=>e(s,n.F_OK).then(()=>!0).catch(()=>!1);
@@ -1,38 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.WORKSPACE_ROOT_CONTENT = exports.PROJECT_ROOT_CONTENT = void 0;
7
- exports.getProjectRoot = getProjectRoot;
8
- exports.getWorkspaceRoot = getWorkspaceRoot;
9
- exports.isProjectRoot = isProjectRoot;
10
- exports.isWorkspaceRoot = isWorkspaceRoot;
11
- var _configTools = require("@storm-software/config-tools");
12
- var _getParentPath = require("./get-parent-path.cjs");
13
- var _isRootDir = require("./is-root-dir.cjs");
14
- const WORKSPACE_ROOT_CONTENT = exports.WORKSPACE_ROOT_CONTENT = ["package-lock.json", "yarn.lock", "pnpm-lock.yaml", "bun.lock", "nx.json", "knip.json", "pnpm-workspace.yaml", "LICENSE", ".all-contributorsrc", ".whitesource", "syncpack.config.js", "syncpack.json", "socket.yaml", "lefthook.yaml", ".npmrc", ".log4brains.yml", ".huskyrc", ".husky", ".lintstagedrc", ".commitlintrc", "lefthook.yml", ".github", ".nx", ".vscode", "patches"],
15
- PROJECT_ROOT_CONTENT = exports.PROJECT_ROOT_CONTENT = ["project.json", "package.json", ".storm"];
16
- function getWorkspaceRoot(o = process.cwd()) {
17
- if (process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH) return process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH;
18
- const t = (0, _configTools.findWorkspaceRootSafe)(o);
19
- if (t) return t;
20
- let r = (0, _getParentPath.getParentPath)(WORKSPACE_ROOT_CONTENT, o);
21
- if (r) return r;
22
- for (r = o; r && !(0, _isRootDir.isSystemRoot)(r);) if (r = (0, _getParentPath.getParentPath)("storm-workspace.json", r, {
23
- skipCwd: !0
24
- }), r) return r;
25
- return o;
26
- }
27
- function isWorkspaceRoot(o = process.cwd()) {
28
- const t = getWorkspaceRoot(o);
29
- return t ? t === o : !1;
30
- }
31
- function getProjectRoot(o = process.cwd()) {
32
- const t = (0, _getParentPath.getParentPath)(PROJECT_ROOT_CONTENT, o);
33
- return t || o;
34
- }
35
- function isProjectRoot(o = process.cwd()) {
36
- const t = getProjectRoot(o);
37
- return t ? t === o : !1;
38
- }
@@ -1,30 +0,0 @@
1
- export declare const WORKSPACE_ROOT_CONTENT: string[];
2
- export declare const PROJECT_ROOT_CONTENT: string[];
3
- /**
4
- * Get the workspace root path
5
- *
6
- * @param dir - A directory to start the search from
7
- * @returns The workspace root path
8
- */
9
- export declare function getWorkspaceRoot(dir?: string): string;
10
- /**
11
- * Check if the given directory is the workspace root
12
- *
13
- * @param dir - A directory to check
14
- * @returns True if the directory is the workspace root, false otherwise
15
- */
16
- export declare function isWorkspaceRoot(dir?: string): boolean;
17
- /**
18
- * Get the project root path
19
- *
20
- * @param dir - A directory to start the search from
21
- * @returns The project root path
22
- */
23
- export declare function getProjectRoot(dir?: string): string;
24
- /**
25
- * Check if the given directory is the project root
26
- *
27
- * @param dir - A directory to check
28
- * @returns True if the directory is the project root, false otherwise
29
- */
30
- export declare function isProjectRoot(dir?: string): boolean;
@@ -1 +0,0 @@
1
- import{findWorkspaceRootSafe as e}from"@storm-software/config-tools";import{getParentPath as s}from"./get-parent-path";import{isSystemRoot as n}from"./is-root-dir";export const WORKSPACE_ROOT_CONTENT=["package-lock.json","yarn.lock","pnpm-lock.yaml","bun.lock","nx.json","knip.json","pnpm-workspace.yaml","LICENSE",".all-contributorsrc",".whitesource","syncpack.config.js","syncpack.json","socket.yaml","lefthook.yaml",".npmrc",".log4brains.yml",".huskyrc",".husky",".lintstagedrc",".commitlintrc","lefthook.yml",".github",".nx",".vscode","patches"],PROJECT_ROOT_CONTENT=["project.json","package.json",".storm"];export function getWorkspaceRoot(o=process.cwd()){if(process.env.STORM_WORKSPACE_ROOT||process.env.NX_WORKSPACE_ROOT_PATH)return process.env.STORM_WORKSPACE_ROOT||process.env.NX_WORKSPACE_ROOT_PATH;const t=e(o);if(t)return t;let r=s(WORKSPACE_ROOT_CONTENT,o);if(r)return r;for(r=o;r&&!n(r);)if(r=s("storm-workspace.json",r,{skipCwd:!0}),r)return r;return o}export function isWorkspaceRoot(o=process.cwd()){const t=getWorkspaceRoot(o);return t?t===o:!1}export function getProjectRoot(o=process.cwd()){const t=s(PROJECT_ROOT_CONTENT,o);return t||o}export function isProjectRoot(o=process.cwd()){const t=getProjectRoot(o);return t?t===o:!1}
package/dist/resolve.cjs DELETED
@@ -1,59 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.importModule = importModule;
7
- exports.resolve = resolve;
8
- exports.resolvePackage = resolvePackage;
9
- exports.resolvePackageSync = resolvePackageSync;
10
- exports.resolveSafe = resolveSafe;
11
- exports.resolveSafeSync = resolveSafeSync;
12
- exports.resolveSync = resolveSync;
13
- var _mlly = require("mlly");
14
- var _correctPath = require("./correct-path.cjs");
15
- var _filePathFns = require("./file-path-fns.cjs");
16
- var _getWorkspaceRoot = require("./get-workspace-root.cjs");
17
- var _joinPaths = require("./join-paths.cjs");
18
- async function resolve(r, e = {}) {
19
- const t = e.paths ?? [];
20
- t.length === 0 && t.push(process.cwd());
21
- const n = (0, _getWorkspaceRoot.getWorkspaceRoot)();
22
- return t.includes(n) || t.push(n), (0, _correctPath.correctPath)(await (0, _mlly.resolvePath)(r, {
23
- url: t
24
- }));
25
- }
26
- function resolveSync(r, e = {}) {
27
- const t = e.paths ?? [];
28
- t.length === 0 && t.push(process.cwd());
29
- const n = (0, _getWorkspaceRoot.getWorkspaceRoot)();
30
- return t.includes(n) || t.push(n), (0, _correctPath.correctPath)((0, _mlly.resolvePathSync)(r, {
31
- url: e.paths
32
- }));
33
- }
34
- async function resolveSafe(r, e = {}) {
35
- try {
36
- return await resolve(r, e);
37
- } catch {
38
- return;
39
- }
40
- }
41
- function resolveSafeSync(r, e = {}) {
42
- try {
43
- return resolveSync(r, e);
44
- } catch {
45
- return;
46
- }
47
- }
48
- async function importModule(r) {
49
- const e = await Promise.resolve(`${r}`).then(s => require(s));
50
- return e && (0, _mlly.interopDefault)(e);
51
- }
52
- async function resolvePackage(r, e = {}) {
53
- let t = await resolveSafe((0, _joinPaths.joinPaths)(r, "package.json"), e);
54
- return t || (t = await resolveSafe((0, _joinPaths.joinPaths)(r, "index.js"), e), t || (t = await resolveSafe(r, e))), t ? (0, _filePathFns.findFilePath)(t) : void 0;
55
- }
56
- function resolvePackageSync(r, e = {}) {
57
- let t = resolveSafeSync((0, _joinPaths.joinPaths)(r, "package.json"), e);
58
- return t || (t = resolveSafeSync((0, _joinPaths.joinPaths)(r, "index.js"), e), t || (t = resolveSafeSync(r, e))), t ? (0, _filePathFns.findFilePath)(t) : void 0;
59
- }
package/dist/resolve.d.ts DELETED
@@ -1,71 +0,0 @@
1
- import type { Platform } from "@stryke/types/system";
2
- export interface PackageResolvingOptions {
3
- /**
4
- * Paths to resolve the package from
5
- */
6
- paths?: string[];
7
- /**
8
- * Resolve path as linux (stand-in for unix/posix) or win32
9
- */
10
- platform?: Platform;
11
- }
12
- /**
13
- * Resolve the path to a specified module
14
- *
15
- * @param path - The path to the module
16
- * @param options - The options to use when resolving the module
17
- * @returns A promise for the path to the module
18
- */
19
- export declare function resolve(path: string, options?: PackageResolvingOptions): Promise<string>;
20
- /**
21
- * Resolve the path to a specified module
22
- *
23
- * @param path - The path to the module
24
- * @param options - The options to use when resolving the module
25
- * @returns The path to the module or undefined
26
- */
27
- export declare function resolveSync(path: string, options?: PackageResolvingOptions): string;
28
- /**
29
- * Resolve the path to a specified module with error handling
30
- *
31
- * @param name - The name of the module
32
- * @param options - The options to use when resolving the module
33
- * @returns A promise for the path to the module
34
- */
35
- export declare function resolveSafe(name: string, options?: PackageResolvingOptions): Promise<string | undefined>;
36
- /**
37
- * Resolve the path to a specified module with error handling
38
- *
39
- * @param name - The name of the module
40
- * @param options - The options to use when resolving the module
41
- * @returns The path to the module or undefined
42
- */
43
- export declare function resolveSafeSync(name: string, options?: PackageResolvingOptions): string | undefined;
44
- /**
45
- * Import a module from a specified path
46
- *
47
- * @param path - The path to the module
48
- * @returns The module
49
- */
50
- export declare function importModule<T = any>(path: string): Promise<T>;
51
- /**
52
- * Resolve the path to a specified package asynchronously
53
- *
54
- * @remarks
55
- * This path points to the root of the package, which is usually the directory containing the `package.json` file. Please note: this path does not include the `package.json` file itself.
56
- *
57
- * @param name - The name of the module
58
- * @returns A promise for the module or undefined
59
- */
60
- export declare function resolvePackage(name: string, options?: PackageResolvingOptions): Promise<string | undefined>;
61
- /**
62
- * Resolve the path to a specified package synchronously
63
- *
64
- * @remarks
65
- * This path points to the root of the package, which is usually the directory containing the `package.json` file. Please note: this path does not include the `package.json` file itself.
66
- *
67
- * @param name - The name of the module
68
- * @param options - The options to use when resolving the module
69
- * @returns The module or undefined
70
- */
71
- export declare function resolvePackageSync(name: string, options?: PackageResolvingOptions): string | undefined;
package/dist/resolve.mjs DELETED
@@ -1 +0,0 @@
1
- import{interopDefault as c,resolvePath as p,resolvePathSync as f}from"mlly";import{correctPath as s}from"./correct-path";import{findFilePath as i}from"./file-path-fns";import{getWorkspaceRoot as a}from"./get-workspace-root";import{joinPaths as o}from"./join-paths";export async function resolve(r,e={}){const t=e.paths??[];t.length===0&&t.push(process.cwd());const n=a();return t.includes(n)||t.push(n),s(await p(r,{url:t}))}export function resolveSync(r,e={}){const t=e.paths??[];t.length===0&&t.push(process.cwd());const n=a();return t.includes(n)||t.push(n),s(f(r,{url:e.paths}))}export async function resolveSafe(r,e={}){try{return await resolve(r,e)}catch{return}}export function resolveSafeSync(r,e={}){try{return resolveSync(r,e)}catch{return}}export async function importModule(r){const e=await import(r);return e&&c(e)}export async function resolvePackage(r,e={}){let t=await resolveSafe(o(r,"package.json"),e);return t||(t=await resolveSafe(o(r,"index.js"),e),t||(t=await resolveSafe(r,e))),t?i(t):void 0}export function resolvePackageSync(r,e={}){let t=resolveSafeSync(o(r,"package.json"),e);return t||(t=resolveSafeSync(o(r,"index.js"),e),t||(t=resolveSafeSync(r,e))),t?i(t):void 0}