@stryke/path 0.7.3 → 0.7.5

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.
@@ -23,30 +23,30 @@ var _isFile = require("./is-file.cjs");
23
23
  var _joinPaths = require("./join-paths.cjs");
24
24
  function findFileName(t, e = {}) {
25
25
  const {
26
- requireExtension: r = !1,
27
- withExtension: n = !0
26
+ requireExtension: n = !1,
27
+ withExtension: r = !0
28
28
  } = e,
29
29
  i = (0, _correctPath.normalizeWindowsPath)(t)?.split(t?.includes("\\") ? "\\" : "/")?.pop() ?? "";
30
- return r === !0 && !i.includes(".") ? _base.EMPTY_STRING : n === !1 && i.includes(".") ? i.split(".").slice(-1).join(".") || _base.EMPTY_STRING : i;
30
+ return n === !0 && !i.includes(".") ? _base.EMPTY_STRING : r === !1 && i.includes(".") ? i.substring(0, i.lastIndexOf(".")) || _base.EMPTY_STRING : i;
31
31
  }
32
32
  function findFilePath(t) {
33
33
  const e = (0, _correctPath.normalizeWindowsPath)(t),
34
- r = e.replace(findFileName(e, {
34
+ n = e.replace(findFileName(e, {
35
35
  requireExtension: !0
36
36
  }), "");
37
- return r === "/" ? r : r.replace(/\/$/, "");
37
+ return n === "/" ? n : n.replace(/\/$/, "");
38
38
  }
39
39
  function findFolderName(t) {
40
40
  const e = findFilePath(t).split("/");
41
- let r = "";
42
- for (let n = e.length - 1; n >= 0; n--) {
43
- const i = e[n];
41
+ let n = "";
42
+ for (let r = e.length - 1; r >= 0; r--) {
43
+ const i = e[r];
44
44
  if (i) {
45
- r = i;
45
+ n = i;
46
46
  break;
47
47
  }
48
48
  }
49
- return r ?? _base.EMPTY_STRING;
49
+ return n ?? _base.EMPTY_STRING;
50
50
  }
51
51
  function findFileExtension(t) {
52
52
  if (t === "..") return "";
@@ -60,31 +60,31 @@ function hasFilePath(t) {
60
60
  return !!findFilePath(t);
61
61
  }
62
62
  function resolvePath(t, e = (0, _getWorkspaceRoot.getWorkspaceRoot)()) {
63
- const r = (0, _correctPath.normalizeWindowsPath)(t).split("/");
64
- let n = "",
63
+ const n = (0, _correctPath.normalizeWindowsPath)(t).split("/");
64
+ let r = "",
65
65
  i = !1;
66
- for (let s = r.length - 1; s >= -1 && !i; s--) {
67
- const o = s >= 0 ? r[s] : e;
68
- !o || o.length === 0 || (n = (0, _joinPaths.joinPaths)(o, n), i = (0, _isFile.isAbsolutePath)(o));
66
+ for (let s = n.length - 1; s >= -1 && !i; s--) {
67
+ const o = s >= 0 ? n[s] : e;
68
+ !o || o.length === 0 || (r = (0, _joinPaths.joinPaths)(o, r), i = (0, _isFile.isAbsolutePath)(o));
69
69
  }
70
- return n = (0, _correctPath.normalizeString)(n, !i), i && !(0, _isFile.isAbsolutePath)(n) ? `/${n}` : n.length > 0 ? n : ".";
70
+ return r = (0, _correctPath.normalizeString)(r, !i), i && !(0, _isFile.isAbsolutePath)(r) ? `/${r}` : r.length > 0 ? r : ".";
71
71
  }
72
72
  function resolvePaths(...t) {
73
73
  return resolvePath((0, _joinPaths.joinPaths)(...t.map(e => (0, _correctPath.normalizeWindowsPath)(e))));
74
74
  }
75
- function relativePath(t, e) {
76
- return (0, _nodePath.relative)(t.replace(/\/$/, ""), e.replace(/\/$/, ""));
75
+ function relativePath(t, e, n = !1) {
76
+ return (0, _nodePath.relative)(n !== !0 ? t.replace(/\/$/, "") : t, n !== !0 ? e.replace(/\/$/, "") : e);
77
77
  }
78
78
  function relativeToWorkspaceRoot(t) {
79
79
  return relativePath(t, (0, _getWorkspaceRoot.getWorkspaceRoot)());
80
80
  }
81
81
  function parsePath(t) {
82
82
  const e = /^[/\\]|^[a-z]:[/\\]/i.exec(t)?.[0]?.replace(/\\/g, "/") || "",
83
- r = (0, _correctPath.normalizeWindowsPath)(t),
84
- n = r.replace(/\/$/, "").split("/").slice(0, -1);
85
- n.length === 1 && /^[A-Z]:$/i.test(n[0]) && (n[0] += "/");
86
- const i = findFolderName(r),
87
- s = n.join("/") || ((0, _isFile.isAbsolutePath)(t) ? "/" : "."),
83
+ n = (0, _correctPath.normalizeWindowsPath)(t),
84
+ r = n.replace(/\/$/, "").split("/").slice(0, -1);
85
+ r.length === 1 && /^[A-Z]:$/i.test(r[0]) && (r[0] += "/");
86
+ const i = findFolderName(n),
87
+ s = r.join("/") || ((0, _isFile.isAbsolutePath)(t) ? "/" : "."),
88
88
  o = findFileExtension(t);
89
89
  return {
90
90
  root: e,
@@ -95,6 +95,6 @@ function parsePath(t) {
95
95
  };
96
96
  }
97
97
  function renameFile(t, e) {
98
- const r = parsePath(t);
99
- return (0, _joinPaths.joinPaths)(r.dir, e.includes(".") ? e : e + r.ext);
98
+ const n = parsePath(t);
99
+ return (0, _joinPaths.joinPaths)(n.dir, e.includes(".") ? e : e + n.ext);
100
100
  }
@@ -96,8 +96,13 @@ export declare function resolvePaths(...paths: string[]): string;
96
96
  *
97
97
  * @remarks
98
98
  * This function wraps the `path.relative` function in Node's path module.
99
+ *
100
+ * @param from - The base path to start from
101
+ * @param to - The target path to resolve relative to the base path
102
+ * @param withEndSlash - Whether to include a trailing slash at the end of the path
103
+ * @returns The relative path from the base path to the target path
99
104
  */
100
- export declare function relativePath(from: string, to: string): string;
105
+ export declare function relativePath(from: string, to: string, withEndSlash?: boolean): string;
101
106
  /**
102
107
  * Find the file path relative to the workspace root path.
103
108
  *
@@ -1 +1 @@
1
- import{EMPTY_STRING as a}from"@stryke/types/base";import{relative as f}from"node:path";import{normalizeString as g,normalizeWindowsPath as l}from"./correct-path";import{getWorkspaceRoot as p}from"./get-workspace-root";import{isAbsolutePath as c}from"./is-file";import{joinPaths as u}from"./join-paths";export function findFileName(t,e={}){const{requireExtension:r=!1,withExtension:n=!0}=e,i=l(t)?.split(t?.includes("\\")?"\\":"/")?.pop()??"";return r===!0&&!i.includes(".")?a:n===!1&&i.includes(".")?i.split(".").slice(-1).join(".")||a:i}export function findFilePath(t){const e=l(t),r=e.replace(findFileName(e,{requireExtension:!0}),"");return r==="/"?r:r.replace(/\/$/,"")}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=p()){const r=l(t).split("/");let n="",i=!1;for(let s=r.length-1;s>=-1&&!i;s--){const o=s>=0?r[s]:e;!o||o.length===0||(n=u(o,n),i=c(o))}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){return f(t.replace(/\/$/,""),e.replace(/\/$/,""))}export function relativeToWorkspaceRoot(t){return relativePath(t,p())}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),s=n.join("/")||(c(t)?"/":"."),o=findFileExtension(t);return{root:e,dir:s,base:i,ext:o,name:i.slice(0,i.length-o.length)}}export function renameFile(t,e){const r=parsePath(t);return u(r.dir,e.includes(".")?e:e+r.ext)}
1
+ import{EMPTY_STRING as a}from"@stryke/types/base";import{relative as f}from"node:path";import{normalizeString as g,normalizeWindowsPath as l}from"./correct-path";import{getWorkspaceRoot as p}from"./get-workspace-root";import{isAbsolutePath as c}from"./is-file";import{joinPaths as u}from"./join-paths";export function findFileName(t,e={}){const{requireExtension:n=!1,withExtension:r=!0}=e,i=l(t)?.split(t?.includes("\\")?"\\":"/")?.pop()??"";return n===!0&&!i.includes(".")?a:r===!1&&i.includes(".")?i.substring(0,i.lastIndexOf("."))||a:i}export function findFilePath(t){const e=l(t),n=e.replace(findFileName(e,{requireExtension:!0}),"");return n==="/"?n:n.replace(/\/$/,"")}export function findFolderName(t){const e=findFilePath(t).split("/");let n="";for(let r=e.length-1;r>=0;r--){const i=e[r];if(i){n=i;break}}return n??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=p()){const n=l(t).split("/");let r="",i=!1;for(let s=n.length-1;s>=-1&&!i;s--){const o=s>=0?n[s]:e;!o||o.length===0||(r=u(o,r),i=c(o))}return r=g(r,!i),i&&!c(r)?`/${r}`:r.length>0?r:"."}export function resolvePaths(...t){return resolvePath(u(...t.map(e=>l(e))))}export function relativePath(t,e,n=!1){return f(n!==!0?t.replace(/\/$/,""):t,n!==!0?e.replace(/\/$/,""):e)}export function relativeToWorkspaceRoot(t){return relativePath(t,p())}export function parsePath(t){const e=/^[/\\]|^[a-z]:[/\\]/i.exec(t)?.[0]?.replace(/\\/g,"/")||"",n=l(t),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("/")||(c(t)?"/":"."),o=findFileExtension(t);return{root:e,dir:s,base:i,ext:o,name:i.slice(0,i.length-o.length)}}export function renameFile(t,e){const n=parsePath(t);return u(n.dir,e.includes(".")?e:e+n.ext)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/path",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
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": {