@stryke/path 0.4.2 → 0.4.3

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
@@ -46,8 +46,8 @@ This package is part of Storm Software's **đŸŒŠī¸ Stryke** monorepo. Stryke pac
46
46
 
47
47
  # Stryke - Path Helpers
48
48
 
49
- A package containing various utilities that expand the functionality of
50
- NodeJs's built-in \`path\` module
49
+ A package containing various utilities that expand the functionality of NodeJs's
50
+ built-in \`path\` module
51
51
 
52
52
  <!-- START doctoc -->
53
53
  <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
@@ -4,14 +4,61 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.joinPaths = void 0;
7
- var _correctPath = require("./correct-path.cjs");
8
- const joinPaths = (...i) => {
7
+ const g = /^[A-Z]:\//i;
8
+ function u(e = "") {
9
+ return e && e.replace(/\\/g, "/").replace(g, t => t.toUpperCase());
10
+ }
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) {
9
26
  let t = "";
10
- for (const o of i) if (o) if (t.length > 0) {
11
- const e = t[t.length - 1] === "/",
12
- n = o[0] === "/";
13
- e && n ? t += o.slice(1) : t += e || n ? o : `/${o}`;
14
- } else t += o;
15
- return (0, _correctPath.correctPath)(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);
16
33
  };
17
- exports.joinPaths = joinPaths;
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 = "/";
45
+ }
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;
52
+ continue;
53
+ } else if (n.length > 0) {
54
+ n = "", s = 0, i = l, o = 0;
55
+ continue;
56
+ }
57
+ }
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;
62
+ }
63
+ return n;
64
+ }
@@ -1,11 +1,9 @@
1
1
  import type path from "node:path";
2
2
  /**
3
- * Join multiple path segments together, resolving '.' and '..' segments, and normalizing the resulting path.
4
- *
5
- * @remarks
6
- * This helper utility performs string joining similar to the `node:path` module's `join` function, and then normalizes the resulting path.
3
+ * Joins all given path segments together using the platform-specific separator as a delimiter.
4
+ * The resulting path is normalized to remove any redundant or unnecessary segments.
7
5
  *
8
6
  * @param segments - The path segments to join.
9
- * @returns The joined path string.
7
+ * @returns The joined and normalized path string.
10
8
  */
11
9
  export declare const joinPaths: typeof path.join;
@@ -1 +1 @@
1
- import{correctPath as h}from"./correct-path";export const joinPaths=(...i)=>{let t="";for(const o of i)if(o)if(t.length>0){const e=t[t.length-1]==="/",n=o[0]==="/";e&&n?t+=o.slice(1):t+=e||n?o:`/${o}`}else t+=o;return h(t)};
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}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/path",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
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": {
@@ -12,12 +12,9 @@
12
12
  "dependencies": {
13
13
  "@storm-software/config-tools": "latest",
14
14
  "mlly": "1.7.4",
15
- "@stryke/types": ">=0.6.1"
16
- },
17
- "devDependencies": {
18
- "@stryke/types": "workspace:*",
19
- "@types/node": "^22.13.1"
15
+ "@stryke/types": ">=0.6.2"
20
16
  },
17
+ "devDependencies": { "@stryke/types": "0.6.2", "@types/node": "^22.13.1" },
21
18
  "publishConfig": { "access": "public" },
22
19
  "sideEffects": false,
23
20
  "files": ["dist/**/*"],