@stryke/path 0.18.0 → 0.18.2

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.
@@ -29,7 +29,7 @@ function stripStars(e) {
29
29
  if (!e || e.length === 0) return ".";
30
30
  e = correctPath(e);
31
31
  let t = !1;
32
- return e.split("/").reduce((r, n) => n?.trim() ? t || n.includes("*") ? (t = !0, r) : r + (r.length > 0 ? `/${n}` : n) : r, "");
32
+ return e.split("/").reduce((r, n) => n?.trim() ? t || n.includes("*") ? (t = !0, r) : r + (r ? `/${n}` : n) : r, "");
33
33
  }
34
34
  function normalizeString(e, t) {
35
35
  let r = "",
@@ -1 +1 @@
1
- import{cwd as m}from"./cwd";import{isAbsolutePath as u}from"./is-type";import{joinPaths as g}from"./join-paths";import{DRIVE_LETTER_REGEX as d,DRIVE_LETTER_START_REGEX as E,UNC_REGEX as x}from"./regex";import{slash as f}from"./slash";export function normalizeWindowsPath(e=""){return e&&f(e).replace(E,t=>t.toUpperCase())}export function correctPath(e){if(!e||e.length===0)return".";e=normalizeWindowsPath(e);const t=e.match(x),r=u(e),n=e.endsWith("/");return e=normalizeString(e,!r),e.length===0?r?"/":n?"./":".":(n&&(e+="/"),d.test(e)&&(e+="/"),t?r?`//${e}`:`//./${e}`:!e.startsWith("/")&&r&&!d.test(e)?`/${e}`:e)}export function stripStars(e){if(!e||e.length===0)return".";e=correctPath(e);let t=!1;return e.split("/").reduce((r,n)=>n?.trim()?t||n.includes("*")?(t=!0,r):r+(r.length>0?`/${n}`:n):r,"")}export function normalizeString(e,t){let r="",n=0,l=-1,s=0,o=null;for(let i=0;i<=e.length;++i){if(i<e.length)o=e[i];else{if(o==="/")break;o="/"}if(o==="/"){if(!(l===i-1||s===1))if(s===2){if(r.length<2||n!==2||r[r.length-1]!=="."||r[r.length-2]!=="."){if(r.length>2){const c=r.lastIndexOf("/");c===-1?(r="",n=0):(r=r.slice(0,c),n=r.length-1-r.lastIndexOf("/")),l=i,s=0;continue}else if(r.length>0){r="",n=0,l=i,s=0;continue}}t&&(r+=r.length>0?"/..":"..",n=2)}else r.length>0?r+=`/${e.slice(l+1,i)}`:r=e.slice(l+1,i),n=i-l-1;l=i,s=0}else o==="."&&s!==-1?++s:s=-1}return r}export function toAbsolutePath(e,t){return u(e)?e:f(normalizeString(g(t||process.cwd(),e),!0))}export function toRelativePath(e,t=m()){return!e||e.length===0?".":(u(e)?e=f(normalizeString(e,!0)):e=f(normalizeString(g(t,e),!0)),e.startsWith("./")?e.slice(2):e)}
1
+ import{cwd as m}from"./cwd";import{isAbsolutePath as u}from"./is-type";import{joinPaths as g}from"./join-paths";import{DRIVE_LETTER_REGEX as d,DRIVE_LETTER_START_REGEX as E,UNC_REGEX as x}from"./regex";import{slash as f}from"./slash";export function normalizeWindowsPath(e=""){return e&&f(e).replace(E,t=>t.toUpperCase())}export function correctPath(e){if(!e||e.length===0)return".";e=normalizeWindowsPath(e);const t=e.match(x),r=u(e),n=e.endsWith("/");return e=normalizeString(e,!r),e.length===0?r?"/":n?"./":".":(n&&(e+="/"),d.test(e)&&(e+="/"),t?r?`//${e}`:`//./${e}`:!e.startsWith("/")&&r&&!d.test(e)?`/${e}`:e)}export function stripStars(e){if(!e||e.length===0)return".";e=correctPath(e);let t=!1;return e.split("/").reduce((r,n)=>n?.trim()?t||n.includes("*")?(t=!0,r):r+(r?`/${n}`:n):r,"")}export function normalizeString(e,t){let r="",n=0,l=-1,s=0,o=null;for(let i=0;i<=e.length;++i){if(i<e.length)o=e[i];else{if(o==="/")break;o="/"}if(o==="/"){if(!(l===i-1||s===1))if(s===2){if(r.length<2||n!==2||r[r.length-1]!=="."||r[r.length-2]!=="."){if(r.length>2){const c=r.lastIndexOf("/");c===-1?(r="",n=0):(r=r.slice(0,c),n=r.length-1-r.lastIndexOf("/")),l=i,s=0;continue}else if(r.length>0){r="",n=0,l=i,s=0;continue}}t&&(r+=r.length>0?"/..":"..",n=2)}else r.length>0?r+=`/${e.slice(l+1,i)}`:r=e.slice(l+1,i),n=i-l-1;l=i,s=0}else o==="."&&s!==-1?++s:s=-1}return r}export function toAbsolutePath(e,t){return u(e)?e:f(normalizeString(g(t||process.cwd(),e),!0))}export function toRelativePath(e,t=m()){return!e||e.length===0?".":(u(e)?e=f(normalizeString(e,!0)):e=f(normalizeString(g(t,e),!0)),e.startsWith("./")?e.slice(2):e)}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ var _correctPath = require("./correct-path.cjs");
4
+ describe("stripStars", () => {
5
+ it("stripStars - single star", () => {
6
+ const t = (0, _correctPath.stripStars)("hello/*");
7
+ expect(t).toBe("hello");
8
+ }), it("stripStars - multiple stars", () => {
9
+ const t = (0, _correctPath.stripStars)("hello/**/*");
10
+ expect(t).toBe("hello");
11
+ });
12
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ import{stripStars as s}from"./correct-path";describe("stripStars",()=>{it("stripStars - single star",()=>{const t=s("hello/*");expect(t).toBe("hello")}),it("stripStars - multiple stars",()=>{const t=s("hello/**/*");expect(t).toBe("hello")})});
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.isParentPath = isParentPath;
7
7
  var _slash = require("./slash.cjs");
8
- function isParentPath(a, n) {
9
- const r = (0, _slash.slash)(a.replace(/\\/g, "/").replace(/\/$/, "")),
10
- e = (0, _slash.slash)(n.replace(/\\/g, "/").replace(/\/$/, ""));
11
- return r !== e && r.startsWith(`${e}/`);
8
+ function isParentPath(l, c) {
9
+ const e = (0, _slash.slash)(l.replace(/\/+/g, "/").replace(/\/+$/, "")),
10
+ r = (0, _slash.slash)(c.replace(/\/+/g, "/").replace(/\/+$/, ""));
11
+ return e.replace(/^\/+/g, "").replace(/\/+$/g, "") !== r.replace(/^\/+/g, "").replace(/\/+$/g, "") && e.replace(/^\/+/g, "").replace(/\/+$/g, "").startsWith(r.replace(/^\/+/g, "").replace(/\/+$/g, ""));
12
12
  }
@@ -1 +1 @@
1
- import{slash as t}from"./slash";export function isParentPath(a,n){const r=t(a.replace(/\\/g,"/").replace(/\/$/,"")),e=t(n.replace(/\\/g,"/").replace(/\/$/,""));return r!==e&&r.startsWith(`${e}/`)}
1
+ import{slash as a}from"./slash";export function isParentPath(l,c){const e=a(l.replace(/\/+/g,"/").replace(/\/+$/,"")),r=a(c.replace(/\/+/g,"/").replace(/\/+$/,""));return e.replace(/^\/+/g,"").replace(/\/+$/g,"")!==r.replace(/^\/+/g,"").replace(/\/+$/g,"")&&e.replace(/^\/+/g,"").replace(/\/+$/g,"").startsWith(r.replace(/^\/+/g,"").replace(/\/+$/g,""))}
package/dist/replace.cjs CHANGED
@@ -10,9 +10,9 @@ var _cwd = require("./cwd.cjs");
10
10
  var _filePathFns = require("./file-path-fns.cjs");
11
11
  var _isParentPath = require("./is-parent-path.cjs");
12
12
  var _slash = require("./slash.cjs");
13
- function replacePath(r, i = (0, _cwd.cwd)()) {
14
- return (0, _correctPath.correctPath)((0, _isParentPath.isParentPath)(r, i) ? (0, _slash.slash)(r).replace((0, _slash.slash)(i), "").replace(/^\//, "") : r);
13
+ function replacePath(r, e = (0, _cwd.cwd)()) {
14
+ return (0, _correctPath.correctPath)((0, _isParentPath.isParentPath)(r, e) ? (0, _slash.slash)(r).replace(/^\/+/g, "").replace(/\/+$/g, "").replace((0, _slash.slash)(e).replace(/^\/+/g, "").replace(/\/+$/g, ""), "") : r);
15
15
  }
16
- function replaceExtension(r, i = "") {
17
- return (0, _correctPath.correctPath)(r.replace(!i || i.includes(".") ? (0, _filePathFns.findFileDotExtensionSafe)(r) : (0, _filePathFns.findFileExtensionSafe)(r), i));
16
+ function replaceExtension(r, e = "") {
17
+ return (0, _correctPath.correctPath)(r.replace(!e || e.includes(".") ? (0, _filePathFns.findFileDotExtensionSafe)(r) : (0, _filePathFns.findFileExtensionSafe)(r), e));
18
18
  }
package/dist/replace.mjs CHANGED
@@ -1 +1 @@
1
- import{correctPath as o}from"./correct-path";import{cwd as e}from"./cwd";import{findFileDotExtensionSafe as t,findFileExtensionSafe as s}from"./file-path-fns";import{isParentPath as f}from"./is-parent-path";import{slash as n}from"./slash";export function replacePath(r,i=e()){return o(f(r,i)?n(r).replace(n(i),"").replace(/^\//,""):r)}export function replaceExtension(r,i=""){return o(r.replace(!i||i.includes(".")?t(r):s(r),i))}
1
+ import{correctPath as i}from"./correct-path";import{cwd as n}from"./cwd";import{findFileDotExtensionSafe as t,findFileExtensionSafe as s}from"./file-path-fns";import{isParentPath as f}from"./is-parent-path";import{slash as o}from"./slash";export function replacePath(r,e=n()){return i(f(r,e)?o(r).replace(/^\/+/g,"").replace(/\/+$/g,"").replace(o(e).replace(/^\/+/g,"").replace(/\/+$/g,""),""):r)}export function replaceExtension(r,e=""){return i(r.replace(!e||e.includes(".")?t(r):s(r),e))}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/path",
3
- "version": "0.18.0",
3
+ "version": "0.18.2",
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": {
@@ -10,6 +10,7 @@
10
10
  },
11
11
  "private": false,
12
12
  "devDependencies": {
13
+ "@storm-software/testing-tools": "^1.119.14",
13
14
  "@stryke/convert": "^0.6.0",
14
15
  "@stryke/type-checks": "^0.3.10",
15
16
  "@stryke/types": "^0.10.0"
@@ -238,6 +239,20 @@
238
239
  "default": "./dist/correct-path.mjs"
239
240
  }
240
241
  },
242
+ "./correct-path.spec": {
243
+ "import": {
244
+ "types": "./dist/correct-path.spec.d.ts",
245
+ "default": "./dist/correct-path.spec.mjs"
246
+ },
247
+ "require": {
248
+ "types": "./dist/correct-path.spec.d.ts",
249
+ "default": "./dist/correct-path.spec.cjs"
250
+ },
251
+ "default": {
252
+ "types": "./dist/correct-path.spec.d.ts",
253
+ "default": "./dist/correct-path.spec.mjs"
254
+ }
255
+ },
241
256
  "./asset-extensions": {
242
257
  "import": {
243
258
  "types": "./dist/asset-extensions.d.ts",
@@ -279,5 +294,5 @@
279
294
  "main": "./dist/index.cjs",
280
295
  "module": "./dist/index.mjs",
281
296
  "types": "./dist/index.d.ts",
282
- "gitHead": "04107da5bbf439fe7e705783009e18fc5080a4fe"
297
+ "gitHead": "b72f1ffff997334f9986d1dea1124e720cf71ff4"
283
298
  }