@stryke/path 0.6.1 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,20 +8,20 @@ var _filePathFns = require("./file-path-fns.cjs");
8
8
  var _isFile = require("./is-file.cjs");
9
9
  var _joinPaths = require("./join-paths.cjs");
10
10
  const resolveParentPath = (r, i = 1) => {
11
- let t = r;
11
+ let t = r.replaceAll(/\/+$/g, "");
12
12
  for (let o = 0; o < i; o++) t = (0, _filePathFns.resolvePaths)(t, "..");
13
13
  return t;
14
14
  },
15
15
  getParentPath = (r, i, t) => {
16
16
  const o = t?.ignoreCase ?? !0,
17
- l = t?.skipCwd ?? !1,
17
+ g = t?.skipCwd ?? !1,
18
18
  n = t?.targetType ?? "both";
19
19
  let e = i;
20
- l && (e = resolveParentPath(i));
21
- let a = Array.isArray(r) ? r : [r];
22
- for (o && (a = a.map(s => s.toLowerCase()));;) {
23
- const s = a.find(g => (0, _isFile.isFile)((0, _joinPaths.joinPaths)(e, g)) && (n === "file" || n === "both") || (0, _isFile.isDirectory)((0, _joinPaths.joinPaths)(e, g)) && (n === "directory" || n === "both"));
24
- if (s) return (0, _joinPaths.joinPaths)(e, s);
20
+ g && (e = resolveParentPath(i));
21
+ let s = Array.isArray(r) ? r : [r];
22
+ for (o && (s = s.map(a => a.toLowerCase()));;) {
23
+ const a = s.find(f => (0, _isFile.isFile)((0, _joinPaths.joinPaths)(e, f)) && (n === "file" || n === "both") || (0, _isFile.isDirectory)((0, _joinPaths.joinPaths)(e, f)) && (n === "directory" || n === "both"));
24
+ if (a) return (0, _joinPaths.joinPaths)(e, a);
25
25
  const p = resolveParentPath(e);
26
26
  if (p === e) return;
27
27
  e = p;
@@ -1 +1 @@
1
- import{resolvePaths as h}from"./file-path-fns";import{isDirectory as P,isFile as c}from"./is-file";import{joinPaths as f}from"./join-paths";export const resolveParentPath=(r,i=1)=>{let t=r;for(let o=0;o<i;o++)t=h(t,"..");return t},getParentPath=(r,i,t)=>{const o=t?.ignoreCase??!0,l=t?.skipCwd??!1,n=t?.targetType??"both";let e=i;l&&(e=resolveParentPath(i));let a=Array.isArray(r)?r:[r];for(o&&(a=a.map(s=>s.toLowerCase()));;){const s=a.find(g=>c(f(e,g))&&(n==="file"||n==="both")||P(f(e,g))&&(n==="directory"||n==="both"));if(s)return f(e,s);const p=resolveParentPath(e);if(p===e)return;e=p}};
1
+ import{resolvePaths as h}from"./file-path-fns";import{isDirectory as P,isFile as c}from"./is-file";import{joinPaths as l}from"./join-paths";export const resolveParentPath=(r,i=1)=>{let t=r.replaceAll(/\/+$/g,"");for(let o=0;o<i;o++)t=h(t,"..");return t},getParentPath=(r,i,t)=>{const o=t?.ignoreCase??!0,g=t?.skipCwd??!1,n=t?.targetType??"both";let e=i;g&&(e=resolveParentPath(i));let s=Array.isArray(r)?r:[r];for(o&&(s=s.map(a=>a.toLowerCase()));;){const a=s.find(f=>c(l(e,f))&&(n==="file"||n==="both")||P(l(e,f))&&(n==="directory"||n==="both"));if(a)return l(e,a);const p=resolveParentPath(e);if(p===e)return;e=p}};
package/dist/index.cjs CHANGED
@@ -124,6 +124,17 @@ Object.keys(_regex).forEach(function (key) {
124
124
  }
125
125
  });
126
126
  });
127
+ var _replace = require("./replace.cjs");
128
+ Object.keys(_replace).forEach(function (key) {
129
+ if (key === "default" || key === "__esModule") return;
130
+ if (key in exports && exports[key] === _replace[key]) return;
131
+ Object.defineProperty(exports, key, {
132
+ enumerable: true,
133
+ get: function () {
134
+ return _replace[key];
135
+ }
136
+ });
137
+ });
127
138
  var _resolve = require("./resolve.cjs");
128
139
  Object.keys(_resolve).forEach(function (key) {
129
140
  if (key === "default" || key === "__esModule") return;
package/dist/index.d.ts CHANGED
@@ -17,5 +17,6 @@ export * from "./is-file";
17
17
  export * from "./is-root-dir";
18
18
  export * from "./join-paths";
19
19
  export * from "./regex";
20
+ export * from "./replace";
20
21
  export * from "./resolve";
21
22
  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-root-dir";export*from"./join-paths";export*from"./regex";export*from"./resolve";export*from"./slash";
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-root-dir";export*from"./join-paths";export*from"./regex";export*from"./replace";export*from"./resolve";export*from"./slash";
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.replacePath = replacePath;
7
+ var _slash = require("./slash.cjs");
8
+ function replacePath(e, t = process.cwd()) {
9
+ return (0, _slash.slash)(e).replace((0, _slash.slash)(t), "").replace(/^\//, "");
10
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Replace the base path from the beginning of the given path.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * replacePath("/home/user/project/src/index.ts", "/home/user/project");
7
+ * // returns "src/index.ts"
8
+ * ```
9
+ *
10
+ * @param path - The path string to replace a substring from
11
+ * @param base - The base path to remove from the beginning of the {@link path}
12
+ * @returns The {@link path} with the {@link base} path removed
13
+ */
14
+ export declare function replacePath(path: string, base?: string): string;
@@ -0,0 +1 @@
1
+ import{slash as r}from"./slash";export function replacePath(e,t=process.cwd()){return r(e).replace(r(t),"").replace(/^\//,"")}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/path",
3
- "version": "0.6.1",
3
+ "version": "0.7.1",
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": {
@@ -77,6 +77,20 @@
77
77
  "default": "./dist/resolve.mjs"
78
78
  }
79
79
  },
80
+ "./replace": {
81
+ "import": {
82
+ "types": "./dist/replace.d.ts",
83
+ "default": "./dist/replace.mjs"
84
+ },
85
+ "require": {
86
+ "types": "./dist/replace.d.ts",
87
+ "default": "./dist/replace.cjs"
88
+ },
89
+ "default": {
90
+ "types": "./dist/replace.d.ts",
91
+ "default": "./dist/replace.mjs"
92
+ }
93
+ },
80
94
  "./regex": {
81
95
  "import": { "types": "./dist/regex.d.ts", "default": "./dist/regex.mjs" },
82
96
  "require": {