@stryke/path 0.1.4 → 0.3.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
@@ -1,4 +1,47 @@
1
1
  <!-- START header -->
2
+ <!-- prettier-ignore-start -->
3
+ <!-- markdownlint-disable -->
4
+
5
+
6
+ <div align="center"><img src="https://pub-761b436209f44a4d886487c917806c08.r2.dev/storm-banner.gif" width="100%" alt="Storm Software" /></div>
7
+ <br />
8
+
9
+ <div align="center">
10
+ <b>
11
+ <a href="https://stormsoftware.com" target="_blank">Website</a> •
12
+ <a href="https://github.com/storm-software/stryke" target="_blank">GitHub</a> •
13
+ <a href="https://discord.gg/MQ6YVzakM5">Discord</a> • <a href="https://stormsoftware.com/projects/stryke/docs" target="_blank">Docs</a> • <a href="https://stormsoftware.com/contact" target="_blank">Contact</a> •
14
+ <a href="https://github.com/storm-software/stryke/issues/new?assignees=&labels=bug&template=bug-report.yml&title=Bug Report%3A+">Report a Bug</a>
15
+ </b>
16
+ </div>
17
+
18
+ <br />
19
+ This package is part of Storm Software's **🌩️ Stryke** monorepo. Stryke packages TypeScript utility packages with shared functionality common to many Storm Software applications.
20
+
21
+ <br />
22
+
23
+ <h3 align="center">💻 Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3><br />
24
+
25
+ [![Version](https://img.shields.io/badge/version-0.1.4-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/stryke/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
26
+
27
+ > [!IMPORTANT] This repository, and the apps, libraries, and tools contained
28
+ > within, is still in it's initial development phase. As a result, bugs and
29
+ > issues are expected with it's usage. When the main development phase
30
+ > completes, a proper release will be performed, the packages will be availible
31
+ > through NPM (and other distributions), and this message will be removed.
32
+ > However, in the meantime, please feel free to report any issues you may come
33
+ > across.
34
+
35
+ <div align="center">
36
+ <b>Be sure to ⭐ this repository on <a href="https://github.com/storm-software/stryke" target="_blank">GitHub</a> so you can keep up to date on any daily progress!</b>
37
+ </div>
38
+
39
+ <br />
40
+
41
+
42
+ <!-- markdownlint-restore -->
43
+ <!-- prettier-ignore-end -->
44
+
2
45
  <!-- END header -->
3
46
 
4
47
  # Stryke - Path Utilities
@@ -7,6 +50,24 @@ A package containing various utilities that expand the functionality of
7
50
  NodeJs&#39;s \`path\` module
8
51
 
9
52
  <!-- START doctoc -->
53
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
54
+
55
+ ## Table of Contents
56
+
57
+ - [Installing](#installing)
58
+ - [Reduced Package Size](#reduced-package-size)
59
+ - [Development](#development)
60
+ - [Building](#building)
61
+ - [Running unit tests](#running-unit-tests)
62
+ - [Linting](#linting)
63
+ - [Storm Workspaces](#storm-workspaces)
64
+ - [Roadmap](#roadmap)
65
+ - [Support](#support)
66
+ - [License](#license)
67
+ - [Changelog](#changelog)
68
+ - [Contributing](#contributing)
69
+ - [Contributors](#contributors)
70
+
10
71
  <!-- END doctoc -->
11
72
 
12
73
  ## Installing
@@ -60,4 +121,173 @@ Run `nx test path` to execute the unit tests via [Jest](https://jestjs.io).
60
121
  Run `nx lint path` to run [ESLint](https://eslint.org/) on the package.
61
122
 
62
123
  <!-- START footer -->
124
+ <!-- prettier-ignore-start -->
125
+ <!-- markdownlint-disable -->
126
+
127
+
128
+ ## Storm Workspaces
129
+
130
+ Storm workspaces are built using
131
+ <a href="https://nx.dev/" target="_blank">Nx</a>, a set of extensible dev tools
132
+ for monorepos, which helps you develop like Google, Facebook, and Microsoft.
133
+ Building on top of Nx, the Open System provides a set of tools and patterns that
134
+ help you scale your monorepo to many teams while keeping the codebase
135
+ maintainable.
136
+
137
+ <div align="right">[ <a href="#table-of-contents">Back to top ▲</a> ]</div>
138
+ <br />
139
+
140
+ ## Roadmap
141
+
142
+ See the [open issues](https://github.com/storm-software/stryke/issues) for a
143
+ list of proposed features (and known issues).
144
+
145
+ - [Top Feature Requests](https://github.com/storm-software/stryke/issues?q=label%3Aenhancement+is%3Aopen+sort%3Areactions-%2B1-desc)
146
+ (Add your votes using the 👍 reaction)
147
+ - [Top Bugs](https://github.com/storm-software/stryke/issues?q=is%3Aissue+is%3Aopen+label%3Abug+sort%3Areactions-%2B1-desc)
148
+ (Add your votes using the 👍 reaction)
149
+ - [Newest Bugs](https://github.com/storm-software/stryke/issues?q=is%3Aopen+is%3Aissue+label%3Abug)
150
+
151
+ <div align="right">[ <a href="#table-of-contents">Back to top ▲</a> ]</div>
152
+ <br />
153
+
154
+ ## Support
155
+
156
+ Reach out to the maintainer at one of the following places:
157
+
158
+ - [Contact](https://stormsoftware.com/contact)
159
+ - [GitHub discussions](https://github.com/storm-software/stryke/discussions)
160
+ - <support@stormsoftware.com>
161
+
162
+ <div align="right">[ <a href="#table-of-contents">Back to top ▲</a> ]</div>
163
+ <br />
164
+
165
+ ## License
166
+
167
+ This project is licensed under the **Apache License 2.0**. Feel free to edit and
168
+ distribute this template as you like.
169
+
170
+ See [LICENSE](LICENSE) for more information.
171
+
172
+ <div align="right">[ <a href="#table-of-contents">Back to top ▲</a> ]</div>
173
+ <br />
174
+
175
+ ## Changelog
176
+
177
+ This project adheres to
178
+ [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Every release, along
179
+ with the migration instructions, is documented in the [CHANGELOG](CHANGELOG.md)
180
+ file
181
+
182
+ <div align="right">[ <a href="#table-of-contents">Back to top ▲</a> ]</div>
183
+ <br />
184
+
185
+ ## Contributing
186
+
187
+ First off, thanks for taking the time to contribute! Contributions are what
188
+ makes the open-source community such an amazing place to learn, inspire, and
189
+ create. Any contributions you make will benefit everybody else and are **greatly
190
+ appreciated**.
191
+
192
+ Please try to create bug reports that are:
193
+
194
+ - _Reproducible._ Include steps to reproduce the problem.
195
+ - _Specific._ Include as much detail as possible: which version, what
196
+ environment, etc.
197
+ - _Unique._ Do not duplicate existing opened issues.
198
+ - _Scoped to a Single Bug._ One bug per report.
199
+
200
+ Please adhere to this project's [code of conduct](.github/CODE_OF_CONDUCT.md).
201
+
202
+ You can use
203
+ [markdownlint-cli](https://github.com/storm-software/stryke/markdownlint-cli) to
204
+ check for common markdown style inconsistency.
205
+
206
+ <div align="right">[ <a href="#table-of-contents">Back to top ▲</a> ]</div>
207
+ <br />
208
+
209
+ ## Contributors
210
+
211
+ Thanks goes to these wonderful people
212
+ ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
213
+
214
+ <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
215
+
216
+ <table>
217
+ <tbody>
218
+ <tr>
219
+ <td align="center" valign="top" width="14.28%"><a href="http://www.sullypat.com/"><img src="https://avatars.githubusercontent.com/u/99053093?v=4?s=100" width="100px;" alt="Patrick Sullivan"/><br /><sub><b>Patrick Sullivan</b></sub></a><br /><a href="#design-sullivanpj" title="Design">🎨</a> <a href="https://github.com/storm-software/stryke/commits?author=sullivanpj" title="Code">💻</a> <a href="#tool-sullivanpj" title="Tools">🔧</a> <a href="https://github.com/storm-software/stryke/commits?author=sullivanpj" title="Documentation">📖</a> <a href="https://github.com/storm-software/stryke/commits?author=sullivanpj" title="Tests">⚠️</a></td>
220
+ <td align="center" valign="top" width="14.28%"><a href="https://tylerbenning.com/"><img src="https://avatars.githubusercontent.com/u/7265547?v=4?s=100" width="100px;" alt="Tyler Benning"/><br /><sub><b>Tyler Benning</b></sub></a><br /><a href="#design-tbenning" title="Design">🎨</a></td>
221
+ <td align="center" valign="top" width="14.28%"><a href="http://stormsoftware.com"><img src="https://avatars.githubusercontent.com/u/149802440?v=4?s=100" width="100px;" alt="Stormie"/><br /><sub><b>Stormie</b></sub></a><br /><a href="#maintenance-stormie-bot" title="Maintenance">🚧</a></td>
222
+ </tr>
223
+ </tbody>
224
+ <tfoot>
225
+ <tr>
226
+ <td align="center" size="13px" colspan="7">
227
+ <img src="https://raw.githubusercontent.com/all-contributors/all-contributors-cli/1b8533af435da9854653492b1327a23a4dbd0a10/assets/logo-small.svg" alt="All Contributors">
228
+ <a href="https://all-contributors.js.org/docs/en/bot/usage">Add your contributions</a>
229
+ </img>
230
+ </td>
231
+ </tr>
232
+ </tfoot>
233
+ </table>
234
+
235
+ <!-- ALL-CONTRIBUTORS-LIST:END -->
236
+
237
+ This project follows the
238
+ [all-contributors](https://github.com/all-contributors/all-contributors)
239
+ specification. Contributions of any kind welcome!
240
+
241
+ <div align="right">[ <a href="#table-of-contents">Back to top ▲</a> ]</div>
242
+ <br />
243
+
244
+ <hr />
245
+ <br />
246
+
247
+ <div align="center">
248
+ <img src="https://pub-761b436209f44a4d886487c917806c08.r2.dev/logo-banner.png" width="100%" alt="Storm Software" />
249
+ </div>
250
+ <br />
251
+
252
+ <div align="center">
253
+ <a href="https://stormsoftware.com" target="_blank">Website</a> • <a href="https://stormsoftware.com/contact" target="_blank">Contact</a> • <a href="https://linkedin.com/in/patrick-sullivan-865526b0" target="_blank">LinkedIn</a> • <a href="https://medium.com/@pat.joseph.sullivan" target="_blank">Medium</a> • <a href="https://github.com/storm-software" target="_blank">GitHub</a> • <a href="https://keybase.io/sullivanp" target="_blank">OpenPGP Key</a>
254
+ </div>
255
+
256
+ <div align="center">
257
+ <b>Fingerprint:</b> 1BD2 7192 7770 2549 F4C9 F238 E6AD C420 DA5C 4C2D
258
+ </div>
259
+ <br />
260
+
261
+ Storm Software is an open source software development organization and creator
262
+ of Acidic, StormStack and StormCloud.
263
+
264
+ Our mission is to make software development more accessible. Our ideal future is
265
+ one where anyone can create software without years of prior development
266
+ experience serving as a barrier to entry. We hope to achieve this via LLMs,
267
+ Generative AI, and intuitive, high-level data modeling/programming languages.
268
+
269
+ Join us on [Discord](https://discord.gg/MQ6YVzakM5) to chat with the team,
270
+ receive release notifications, ask questions, and get involved.
271
+
272
+ If this sounds interesting, and you would like to help us in creating the next
273
+ generation of development tools, please reach out on our
274
+ [website](https://stormsoftware.com/contact) or join our
275
+ [Slack channel](https://join.slack.com/t/storm-software/shared_invite/zt-2gsmk04hs-i6yhK_r6urq0dkZYAwq2pA)!
276
+
277
+ <br />
278
+
279
+ <div align="center"><a href="https://stormsoftware.com" target="_blank"><img src="https://pub-761b436209f44a4d886487c917806c08.r2.dev/icon-fill.png" alt="Storm Software" width="200px"/></a></div>
280
+ <br />
281
+ <div align="center"><a href="https://stormsoftware.com" target="_blank"><img src="https://pub-761b436209f44a4d886487c917806c08.r2.dev/visit-us-text.svg" alt="Visit us at stormsoftware.com" height="90px"/></a></div>
282
+
283
+ <br />
284
+
285
+ <div align="right">[ <a href="#table-of-contents">Back to top ▲</a> ]</div>
286
+ <br />
287
+ <br />
288
+
289
+
290
+ <!-- markdownlint-restore -->
291
+ <!-- prettier-ignore-end -->
292
+
63
293
  <!-- END footer -->
@@ -4,15 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.win32 = exports.posix = exports.delimiter = void 0;
7
- const delimiter = exports.delimiter = globalThis.process?.platform === "win32" ? ";" : ":";
8
- const n = {
7
+ const delimiter = exports.delimiter = process?.platform === "win32" ? ";" : ":";
8
+ const o = {
9
9
  posix: void 0,
10
10
  win32: void 0
11
11
  },
12
- o = (t = delimiter) => new Proxy({}, {
12
+ n = (t = delimiter) => new Proxy({}, {
13
13
  get(i, e) {
14
- return e === "delimiter" ? t : e === "posix" ? posix : e === "win32" ? win32 : n[e];
14
+ return e === "delimiter" ? t : e === "posix" ? posix : e === "win32" ? win32 : o[e];
15
15
  }
16
16
  });
17
- const posix = exports.posix = o(":"),
18
- win32 = exports.win32 = o(";");
17
+ const posix = exports.posix = n(":"),
18
+ win32 = exports.win32 = n(";");
@@ -1,10 +1,8 @@
1
- type NodePath = typeof import("node:path");
2
1
  /**
3
2
  * The platform-specific file delimiter.
4
3
  *
5
4
  * Equals to `";"` in windows and `":"` in all other platforms.
6
5
  */
7
6
  export declare const delimiter: ";" | ":";
8
- export declare const posix: NodePath["posix"];
9
- export declare const win32: NodePath["win32"];
10
- export {};
7
+ export declare const posix: import("path").PlatformPath;
8
+ export declare const win32: import("path").PlatformPath;
@@ -1 +1 @@
1
- export const delimiter=globalThis.process?.platform==="win32"?";":":";const n={posix:void 0,win32:void 0},o=(t=delimiter)=>new Proxy({},{get(i,e){return e==="delimiter"?t:e==="posix"?posix:e==="win32"?win32:n[e]}});export const posix=o(":"),win32=o(";");
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(";");
@@ -7,6 +7,6 @@ exports.existsSync = exports.exists = void 0;
7
7
  var _nodeFs = require("node:fs");
8
8
  var _promises = require("node:fs/promises");
9
9
  const existsSync = s => (0, _nodeFs.existsSync)(s),
10
- exists = s => (0, _promises.access)(s, _promises.constants.F_OK).then(() => !0).catch(() => !1);
10
+ exists = async s => (0, _promises.access)(s, _promises.constants.F_OK).then(() => !0).catch(() => !1);
11
11
  exports.exists = exists;
12
12
  exports.existsSync = existsSync;
@@ -1 +1 @@
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=s=>e(s,n.F_OK).then(()=>!0).catch(()=>!1);
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);
@@ -25,7 +25,7 @@ function findFileName(t, {
25
25
  withExtension: r
26
26
  } = {}) {
27
27
  const n = (0, _normalizePath.normalizeWindowsPath)(t)?.split(t?.includes(_normalizePath.sep) ? _normalizePath.sep : t?.includes("/") ? "/" : "\\")?.pop() ?? "";
28
- return e === !0 && !n.includes(".") ? _base.EMPTY_STRING : r === !1 && n.includes(".") ? n.split(".").shift() ?? _base.EMPTY_STRING : n;
28
+ return e === !0 && !n.includes(".") ? _base.EMPTY_STRING : r === !1 && n.includes(".") ? n.split(".").shift() || _base.EMPTY_STRING : n;
29
29
  }
30
30
  function findFilePath(t) {
31
31
  const e = (0, _normalizePath.normalizeWindowsPath)(t);
@@ -34,8 +34,8 @@ function findFilePath(t) {
34
34
  }), "");
35
35
  }
36
36
  function findFolderName(t) {
37
- let e = findFilePath(t).split("/"),
38
- r = "";
37
+ const e = findFilePath(t).split("/");
38
+ let r = "";
39
39
  for (let n = e.length - 1; n >= 0; n--) {
40
40
  const i = e[n];
41
41
  if (i) {
@@ -62,7 +62,7 @@ function resolvePath(t, e = (0, _getWorkspaceRoot.getWorkspaceRoot)()) {
62
62
  i = !1;
63
63
  for (let o = r.length - 1; o >= -1 && !i; o--) {
64
64
  const s = o >= 0 ? r[o] : e;
65
- !s || s.length === 0 || (n = `${s}/${n}`, i = (0, _isFile.isAbsolutePath)(s));
65
+ !s || s.length === 0 || (n = (0, _joinPaths.joinPaths)(s, n), i = (0, _isFile.isAbsolutePath)(s));
66
66
  }
67
67
  return n = (0, _normalizePath.normalizeString)(n, !i), i && !(0, _isFile.isAbsolutePath)(n) ? `/${n}` : n.length > 0 ? n : ".";
68
68
  }
@@ -70,8 +70,8 @@ function resolvePaths(...t) {
70
70
  return resolvePath((0, _joinPaths.joinPaths)(...t.map(e => (0, _normalizePath.normalizeWindowsPath)(e))));
71
71
  }
72
72
  function relativePath(t, e) {
73
- const r = resolvePath(t).replace(/^\/([A-Za-z]:)?$/, "$1").split("/"),
74
- n = resolvePath(e).replace(/^\/([A-Za-z]:)?$/, "$1").split("/");
73
+ const r = resolvePath(t).replace(/^\/([A-Z]:)?$/i, "$1").split("/"),
74
+ n = resolvePath(e).replace(/^\/([A-Z]:)?$/i, "$1").split("/");
75
75
  if (n[0][1] === ":" && r[0][1] === ":" && r[0] !== n[0]) return n.join("/");
76
76
  const i = [...r];
77
77
  for (const o of i) {
@@ -84,10 +84,10 @@ function relativeToWorkspaceRoot(t) {
84
84
  return relativePath(t, (0, _getWorkspaceRoot.getWorkspaceRoot)());
85
85
  }
86
86
  function parsePath(t) {
87
- const e = /^[/\\]|^[a-zA-Z]:[/\\]/.exec(t)?.[0]?.replace(/\\/g, "/") || "",
87
+ const e = /^[/\\]|^[a-z]:[/\\]/i.exec(t)?.[0]?.replace(/\\/g, "/") || "",
88
88
  r = (0, _normalizePath.normalizeWindowsPath)(t),
89
89
  n = r.replace(/\/$/, "").split("/").slice(0, -1);
90
- n.length === 1 && /^[A-Za-z]:$/.test(n[0]) && (n[0] += "/");
90
+ n.length === 1 && /^[A-Z]:$/i.test(n[0]) && (n[0] += "/");
91
91
  const i = findFolderName(r),
92
92
  o = n.join("/") || ((0, _isFile.isAbsolutePath)(t) ? "/" : "."),
93
93
  s = findFileExtension(t);
@@ -1,4 +1,4 @@
1
- export type FindFileNameOptions = {
1
+ export interface FindFileNameOptions {
2
2
  /**
3
3
  * Require the file extension to be present in the file name.
4
4
  *
@@ -11,13 +11,15 @@ export type FindFileNameOptions = {
11
11
  * @defaultValue true
12
12
  */
13
13
  withExtension?: boolean;
14
- };
14
+ }
15
15
  /**
16
16
  * Find the file name from a file path.
17
17
  *
18
18
  * @example
19
+ * ```ts
19
20
  * const fileName = findFileName("C:\\Users\\user\\Documents\\file.txt");
20
21
  * // fileName = "file.txt"
22
+ * ```
21
23
  *
22
24
  * @param filePath - The file path to process
23
25
  * @param options - The options to use when processing the file name
@@ -28,8 +30,10 @@ export declare function findFileName(filePath: string, { requireExtension, withE
28
30
  * Find the full file path's directories from a file path.
29
31
  *
30
32
  * @example
33
+ * ```ts
31
34
  * const folderPath = findFilePath("C:\\Users\\user\\Documents\\file.txt");
32
35
  * // folderPath = "C:\\Users\\user\\Documents"
36
+ * ```
33
37
  *
34
38
  * @param filePath - The file path to process
35
39
  * @returns The full file path's directories
@@ -1 +1 @@
1
- import{EMPTY_STRING as a}from"@stryke/types/utility-types/base";import{getWorkspaceRoot as u}from"../workspace/get-workspace-root";import{isAbsolutePath as c}from"./is-file";import{joinPaths as p}from"./join-paths";import{normalizeString as g,normalizeWindowsPath as l,sep as f}from"./normalize-path";export function findFileName(t,{requireExtension:e,withExtension:r}={}){const n=l(t)?.split(t?.includes(f)?f:t?.includes("/")?"/":"\\")?.pop()??"";return e===!0&&!n.includes(".")?a:r===!1&&n.includes(".")?n.split(".").shift()??a:n}export function findFilePath(t){const e=l(t);return e.replace(findFileName(e,{requireExtension:!0}),"")}export function findFolderName(t){let e=findFilePath(t).split("/"),r="";for(let n=e.length-1;n>=0;n--){const i=e[n];if(i){r=i;break}}return r??a}export function findFileExtension(t){if(t==="..")return"";const e=/.(\.[^./]+|\.)$/.exec(l(t));return e&&e[1]||a}export function hasFileName(t){return!!findFileName(t)}export function hasFilePath(t){return!!findFilePath(t)}export function resolvePath(t,e=u()){const r=l(t).split("/");let n="",i=!1;for(let o=r.length-1;o>=-1&&!i;o--){const s=o>=0?r[o]:e;!s||s.length===0||(n=`${s}/${n}`,i=c(s))}return n=g(n,!i),i&&!c(n)?`/${n}`:n.length>0?n:"."}export function resolvePaths(...t){return resolvePath(p(...t.map(e=>l(e))))}export function relativePath(t,e){const r=resolvePath(t).replace(/^\/([A-Za-z]:)?$/,"$1").split("/"),n=resolvePath(e).replace(/^\/([A-Za-z]:)?$/,"$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 relativeToWorkspaceRoot(t){return relativePath(t,u())}export function parsePath(t){const e=/^[/\\]|^[a-zA-Z]:[/\\]/.exec(t)?.[0]?.replace(/\\/g,"/")||"",r=l(t),n=r.replace(/\/$/,"").split("/").slice(0,-1);n.length===1&&/^[A-Za-z]:$/.test(n[0])&&(n[0]+="/");const i=findFolderName(r),o=n.join("/")||(c(t)?"/":"."),s=findFileExtension(t);return{root:e,dir:o,base:i,ext:s,name:i.slice(0,i.length-s.length)}}export function renameFile(t,e){const r=parsePath(t);return p(r.dir,e.includes(".")?e:e+r.ext)}
1
+ import{EMPTY_STRING as a}from"@stryke/types/utility-types/base";import{getWorkspaceRoot as f}from"../workspace/get-workspace-root";import{isAbsolutePath as c}from"./is-file";import{joinPaths as u}from"./join-paths";import{normalizeString as g,normalizeWindowsPath as l,sep as p}from"./normalize-path";export function findFileName(t,{requireExtension:e,withExtension:r}={}){const n=l(t)?.split(t?.includes(p)?p:t?.includes("/")?"/":"\\")?.pop()??"";return e===!0&&!n.includes(".")?a:r===!1&&n.includes(".")?n.split(".").shift()||a:n}export function findFilePath(t){const e=l(t);return e.replace(findFileName(e,{requireExtension:!0}),"")}export function findFolderName(t){const e=findFilePath(t).split("/");let r="";for(let n=e.length-1;n>=0;n--){const i=e[n];if(i){r=i;break}}return r??a}export function findFileExtension(t){if(t==="..")return"";const e=/.(\.[^./]+|\.)$/.exec(l(t));return e&&e[1]||a}export function hasFileName(t){return!!findFileName(t)}export function hasFilePath(t){return!!findFilePath(t)}export function resolvePath(t,e=f()){const r=l(t).split("/");let n="",i=!1;for(let o=r.length-1;o>=-1&&!i;o--){const s=o>=0?r[o]:e;!s||s.length===0||(n=u(s,n),i=c(s))}return n=g(n,!i),i&&!c(n)?`/${n}`:n.length>0?n:"."}export function resolvePaths(...t){return resolvePath(u(...t.map(e=>l(e))))}export function relativePath(t,e){const r=resolvePath(t).replace(/^\/([A-Z]:)?$/i,"$1").split("/"),n=resolvePath(e).replace(/^\/([A-Z]:)?$/i,"$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 relativeToWorkspaceRoot(t){return relativePath(t,f())}export function parsePath(t){const e=/^[/\\]|^[a-z]:[/\\]/i.exec(t)?.[0]?.replace(/\\/g,"/")||"",r=l(t),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(t)?"/":"."),s=findFileExtension(t);return{root:e,dir:o,base:i,ext:s,name:i.slice(0,i.length-s.length)}}export function renameFile(t,e){const r=parsePath(t);return u(r.dir,e.includes(".")?e:e+r.ext)}
@@ -33,5 +33,5 @@ function isRelativePath(r) {
33
33
  return r === "." || r === ".." || r.startsWith("./") || r.startsWith("../");
34
34
  }
35
35
  function isAbsolutePath(r) {
36
- return !/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/.test(r);
36
+ return !/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i.test(r);
37
37
  }
@@ -1 +1 @@
1
- import{lstatSync as n,statSync as e}from"node:fs";import{joinPaths as t}from"./join-paths";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 isRelativePath(r){return r==="."||r===".."||r.startsWith("./")||r.startsWith("../")}export function isAbsolutePath(r){return!/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/.test(r)}
1
+ import{lstatSync as n,statSync as e}from"node:fs";import{joinPaths as t}from"./join-paths";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 isRelativePath(r){return r==="."||r===".."||r.startsWith("./")||r.startsWith("../")}export function isAbsolutePath(r){return!/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i.test(r)}
@@ -7,16 +7,20 @@ exports.normalizePath = normalizePath;
7
7
  exports.normalizeString = normalizeString;
8
8
  exports.normalizeWindowsPath = normalizeWindowsPath;
9
9
  exports.sep = void 0;
10
+ exports.slash = slash;
10
11
  var _isFile = require("./is-file.cjs");
12
+ function slash(e) {
13
+ return e.replace(/\\/g, "/");
14
+ }
11
15
  function normalizeWindowsPath(e = "") {
12
- return e && e.replace(/\\/g, "/").replace(/^[A-Za-z]:\//, s => s.toUpperCase());
16
+ return e && e.replace(/\\/g, "/").replace(/^[A-Z]:\//i, s => s.toUpperCase());
13
17
  }
14
18
  const sep = exports.sep = "/";
15
19
  function normalizeString(e, s) {
16
20
  let n = "",
17
21
  t = 0,
18
- r = -1,
19
- i = 0,
22
+ i = -1,
23
+ r = 0,
20
24
  o = null;
21
25
  for (let l = 0; l <= e.length; ++l) {
22
26
  if (l < e.length) o = e[l];else {
@@ -24,21 +28,21 @@ function normalizeString(e, s) {
24
28
  o = "/";
25
29
  }
26
30
  if (o === "/") {
27
- if (!(r === l - 1 || i === 1)) if (i === 2) {
31
+ if (!(i === l - 1 || r === 1)) if (r === 2) {
28
32
  if (n.length < 2 || t !== 2 || n.at(-1) !== "." || n.at(-2) !== ".") {
29
33
  if (n.length > 2) {
30
34
  const f = n.lastIndexOf("/");
31
- f === -1 ? (n = "", t = 0) : (n = n.slice(0, f), t = n.length - 1 - n.lastIndexOf("/")), r = l, i = 0;
35
+ f === -1 ? (n = "", t = 0) : (n = n.slice(0, f), t = n.length - 1 - n.lastIndexOf("/")), i = l, r = 0;
32
36
  continue;
33
37
  } else if (n.length > 0) {
34
- n = "", t = 0, r = l, i = 0;
38
+ n = "", t = 0, i = l, r = 0;
35
39
  continue;
36
40
  }
37
41
  }
38
42
  s && (n += n.length > 0 ? "/.." : "..", t = 2);
39
- } else n.length > 0 ? n += `/${e.slice(r + 1, l)}` : n = e.slice(r + 1, l), t = l - r - 1;
40
- r = l, i = 0;
41
- } else o === "." && i !== -1 ? ++i : i = -1;
43
+ } else n.length > 0 ? n += `/${e.slice(i + 1, l)}` : n = e.slice(i + 1, l), t = l - i - 1;
44
+ i = l, r = 0;
45
+ } else o === "." && r !== -1 ? ++r : r = -1;
42
46
  }
43
47
  return n;
44
48
  }
@@ -48,5 +52,5 @@ function normalizePath(e) {
48
52
  const s = e.match(/^[/\\]{2}/),
49
53
  n = (0, _isFile.isAbsolutePath)(e),
50
54
  t = e.at(-1) === "/";
51
- return e = normalizeString(e, !n), e.length === 0 ? n ? "/" : t ? "./" : "." : (t && (e += "/"), /^[A-Za-z]:$/.test(e) && (e += "/"), s ? n ? `//${e}` : `//./${e}` : n && !(0, _isFile.isAbsolutePath)(e) ? `/${e}` : e);
55
+ return e = normalizeString(e, !n), e.length === 0 ? n ? "/" : t ? "./" : "." : (t && (e += "/"), /^[A-Z]:$/i.test(e) && (e += "/"), s ? n ? `//${e}` : `//./${e}` : n && !(0, _isFile.isAbsolutePath)(e) ? `/${e}` : e);
52
56
  }
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Replace backslash to slash
3
+ *
4
+ * @param str - The string to replace
5
+ * @returns The string with replaced backslashes
6
+ */
7
+ export declare function slash(str: string): string;
1
8
  export declare function normalizeWindowsPath(input?: string): string;
2
9
  /**
3
10
  * Constant for path separator.
@@ -1 +1 @@
1
- import{isAbsolutePath as g}from"./is-file";export function normalizeWindowsPath(e=""){return e&&e.replace(/\\/g,"/").replace(/^[A-Za-z]:\//,s=>s.toUpperCase())}export const sep="/";export function normalizeString(e,s){let n="",t=0,r=-1,i=0,o=null;for(let l=0;l<=e.length;++l){if(l<e.length)o=e[l];else{if(o==="/")break;o="/"}if(o==="/"){if(!(r===l-1||i===1))if(i===2){if(n.length<2||t!==2||n.at(-1)!=="."||n.at(-2)!=="."){if(n.length>2){const f=n.lastIndexOf("/");f===-1?(n="",t=0):(n=n.slice(0,f),t=n.length-1-n.lastIndexOf("/")),r=l,i=0;continue}else if(n.length>0){n="",t=0,r=l,i=0;continue}}s&&(n+=n.length>0?"/..":"..",t=2)}else n.length>0?n+=`/${e.slice(r+1,l)}`:n=e.slice(r+1,l),t=l-r-1;r=l,i=0}else o==="."&&i!==-1?++i:i=-1}return n}export function normalizePath(e){if(!e||e.length===0)return".";e=normalizeWindowsPath(e);const s=e.match(/^[/\\]{2}/),n=g(e),t=e.at(-1)==="/";return e=normalizeString(e,!n),e.length===0?n?"/":t?"./":".":(t&&(e+="/"),/^[A-Za-z]:$/.test(e)&&(e+="/"),s?n?`//${e}`:`//./${e}`:n&&!g(e)?`/${e}`:e)}
1
+ import{isAbsolutePath as g}from"./is-file";export function slash(e){return e.replace(/\\/g,"/")}export function normalizeWindowsPath(e=""){return e&&e.replace(/\\/g,"/").replace(/^[A-Z]:\//i,s=>s.toUpperCase())}export const sep="/";export function normalizeString(e,s){let n="",t=0,i=-1,r=0,o=null;for(let l=0;l<=e.length;++l){if(l<e.length)o=e[l];else{if(o==="/")break;o="/"}if(o==="/"){if(!(i===l-1||r===1))if(r===2){if(n.length<2||t!==2||n.at(-1)!=="."||n.at(-2)!=="."){if(n.length>2){const f=n.lastIndexOf("/");f===-1?(n="",t=0):(n=n.slice(0,f),t=n.length-1-n.lastIndexOf("/")),i=l,r=0;continue}else if(n.length>0){n="",t=0,i=l,r=0;continue}}s&&(n+=n.length>0?"/..":"..",t=2)}else n.length>0?n+=`/${e.slice(i+1,l)}`:n=e.slice(i+1,l),t=l-i-1;i=l,r=0}else o==="."&&r!==-1?++r:r=-1}return n}export function normalizePath(e){if(!e||e.length===0)return".";e=normalizeWindowsPath(e);const s=e.match(/^[/\\]{2}/),n=g(e),t=e.at(-1)==="/";return e=normalizeString(e,!n),e.length===0?n?"/":t?"./":".":(t&&(e+="/"),/^[A-Z]:$/i.test(e)&&(e+="/"),s?n?`//${e}`:`//./${e}`:n&&!g(e)?`/${e}`:e)}
@@ -8,20 +8,20 @@ var _configTools = require("@storm-software/config-tools");
8
8
  var _packageManager = require("@stryke/types/utility-types/package-manager");
9
9
  var _getParentPath = require("../utilities/get-parent-path.cjs");
10
10
  var _isRootDir = require("../utilities/is-root-dir.cjs");
11
- const getWorkspaceRoot = (e = process.cwd()) => {
11
+ const getWorkspaceRoot = (r = process.cwd()) => {
12
12
  if (process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH) return process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH;
13
- const r = (0, _configTools.findWorkspaceRootSafe)(e);
14
- if (r) return r;
15
- let o = (0, _getParentPath.getParentPath)([_packageManager.PackageManagerLockFiles.NPM, _packageManager.PackageManagerLockFiles.YARN, _packageManager.PackageManagerLockFiles.PNPM, _packageManager.PackageManagerLockFiles.BUN, "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"], e);
13
+ const t = (0, _configTools.findWorkspaceRootSafe)(r);
14
+ if (t) return t;
15
+ let o = (0, _getParentPath.getParentPath)([_packageManager.PackageManagerLockFiles.NPM, _packageManager.PackageManagerLockFiles.YARN, _packageManager.PackageManagerLockFiles.PNPM, _packageManager.PackageManagerLockFiles.BUN, "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"], r);
16
16
  if (o) return o;
17
- for (o = e; o && !(0, _isRootDir.isSystemRoot)(o);) if (o = (0, _getParentPath.getParentPath)("storm.json", o, {
17
+ for (o = r; o && !(0, _isRootDir.isSystemRoot)(o);) if (o = (0, _getParentPath.getParentPath)("storm.json", o, {
18
18
  skipCwd: !0
19
19
  }), o) return o;
20
- return e;
20
+ return r;
21
21
  },
22
- getProjectRoot = (e = process.cwd()) => {
23
- let r = (0, _getParentPath.getParentPath)(["project.json", "package.json", ".storm"], e);
24
- return r || e;
22
+ getProjectRoot = (r = process.cwd()) => {
23
+ const t = (0, _getParentPath.getParentPath)(["project.json", "package.json", ".storm"], r);
24
+ return t || r;
25
25
  };
26
26
  exports.getProjectRoot = getProjectRoot;
27
27
  exports.getWorkspaceRoot = getWorkspaceRoot;
@@ -1 +1 @@
1
- import{findWorkspaceRootSafe as c}from"@storm-software/config-tools";import{PackageManagerLockFiles as t}from"@stryke/types/utility-types/package-manager";import{getParentPath as s}from"../utilities/get-parent-path";import{isSystemRoot as n}from"../utilities/is-root-dir";export const getWorkspaceRoot=(e=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 r=c(e);if(r)return r;let o=s([t.NPM,t.YARN,t.PNPM,t.BUN,"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"],e);if(o)return o;for(o=e;o&&!n(o);)if(o=s("storm.json",o,{skipCwd:!0}),o)return o;return e},getProjectRoot=(e=process.cwd())=>{let r=s(["project.json","package.json",".storm"],e);return r||e};
1
+ import{findWorkspaceRootSafe as c}from"@storm-software/config-tools";import{PackageManagerLockFiles as e}from"@stryke/types/utility-types/package-manager";import{getParentPath as s}from"../utilities/get-parent-path";import{isSystemRoot as n}from"../utilities/is-root-dir";export const getWorkspaceRoot=(r=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=c(r);if(t)return t;let o=s([e.NPM,e.YARN,e.PNPM,e.BUN,"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"],r);if(o)return o;for(o=r;o&&!n(o);)if(o=s("storm.json",o,{skipCwd:!0}),o)return o;return r},getProjectRoot=(r=process.cwd())=>{const t=s(["project.json","package.json",".storm"],r);return t||r};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/path",
3
- "version": "0.1.4",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "description": "A package containing various utilities that expand the functionality of NodeJs's `path` module",
6
6
  "repository": {
@@ -12,7 +12,7 @@
12
12
  "dependencies": {
13
13
  "@storm-software/config-tools": "latest",
14
14
  "mlly": "1.7.4",
15
- "@stryke/types": ">=0.2.1"
15
+ "@stryke/types": ">=0.5.0"
16
16
  },
17
17
  "devDependencies": { "@types/node": "^22.13.1" },
18
18
  "publishConfig": { "access": "public" },
@@ -110,6 +110,34 @@
110
110
  "default": "./dist/workspace/asset-extensions.mjs"
111
111
  }
112
112
  },
113
+ "./resolve/resolve": {
114
+ "import": {
115
+ "types": "./dist/resolve/resolve.d.ts",
116
+ "default": "./dist/resolve/resolve.mjs"
117
+ },
118
+ "require": {
119
+ "types": "./dist/resolve/resolve.d.ts",
120
+ "default": "./dist/resolve/resolve.cjs"
121
+ },
122
+ "default": {
123
+ "types": "./dist/resolve/resolve.d.ts",
124
+ "default": "./dist/resolve/resolve.mjs"
125
+ }
126
+ },
127
+ "./resolve/index": {
128
+ "import": {
129
+ "types": "./dist/resolve/index.d.ts",
130
+ "default": "./dist/resolve/index.mjs"
131
+ },
132
+ "require": {
133
+ "types": "./dist/resolve/index.d.ts",
134
+ "default": "./dist/resolve/index.cjs"
135
+ },
136
+ "default": {
137
+ "types": "./dist/resolve/index.d.ts",
138
+ "default": "./dist/resolve/index.mjs"
139
+ }
140
+ },
113
141
  "./utilities/normalize-path": {
114
142
  "import": {
115
143
  "types": "./dist/utilities/normalize-path.d.ts",
@@ -236,34 +264,6 @@
236
264
  "default": "./dist/utilities/delimiter.mjs"
237
265
  }
238
266
  },
239
- "./resolve/resolve": {
240
- "import": {
241
- "types": "./dist/resolve/resolve.d.ts",
242
- "default": "./dist/resolve/resolve.mjs"
243
- },
244
- "require": {
245
- "types": "./dist/resolve/resolve.d.ts",
246
- "default": "./dist/resolve/resolve.cjs"
247
- },
248
- "default": {
249
- "types": "./dist/resolve/resolve.d.ts",
250
- "default": "./dist/resolve/resolve.mjs"
251
- }
252
- },
253
- "./resolve/index": {
254
- "import": {
255
- "types": "./dist/resolve/index.d.ts",
256
- "default": "./dist/resolve/index.mjs"
257
- },
258
- "require": {
259
- "types": "./dist/resolve/index.d.ts",
260
- "default": "./dist/resolve/index.cjs"
261
- },
262
- "default": {
263
- "types": "./dist/resolve/index.d.ts",
264
- "default": "./dist/resolve/index.mjs"
265
- }
266
- },
267
267
  ".": {
268
268
  "import": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" },
269
269
  "require": {
@@ -286,20 +286,6 @@
286
286
  "default": "./dist/workspace/index.mjs"
287
287
  }
288
288
  },
289
- "./utilities": {
290
- "import": {
291
- "types": "./dist/utilities/index.d.ts",
292
- "default": "./dist/utilities/index.mjs"
293
- },
294
- "require": {
295
- "types": "./dist/utilities/index.d.ts",
296
- "default": "./dist/utilities/index.cjs"
297
- },
298
- "default": {
299
- "types": "./dist/utilities/index.d.ts",
300
- "default": "./dist/utilities/index.mjs"
301
- }
302
- },
303
289
  "./resolve": {
304
290
  "import": {
305
291
  "types": "./dist/resolve/index.d.ts",
@@ -314,6 +300,20 @@
314
300
  "default": "./dist/resolve/index.mjs"
315
301
  }
316
302
  },
303
+ "./utilities": {
304
+ "import": {
305
+ "types": "./dist/utilities/index.d.ts",
306
+ "default": "./dist/utilities/index.mjs"
307
+ },
308
+ "require": {
309
+ "types": "./dist/utilities/index.d.ts",
310
+ "default": "./dist/utilities/index.cjs"
311
+ },
312
+ "default": {
313
+ "types": "./dist/utilities/index.d.ts",
314
+ "default": "./dist/utilities/index.mjs"
315
+ }
316
+ },
317
317
  "./package.json": "./package.json"
318
318
  },
319
319
  "main": "./dist/index.cjs",