@stryke/path 0.7.1 → 0.7.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.
@@ -23,29 +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: i = !1,
26
+ requireExtension: r = !1,
27
27
  withExtension: n = !0
28
28
  } = e,
29
- r = (0, _correctPath.normalizeWindowsPath)(t)?.split(t?.includes("\\") ? "\\" : "/")?.pop() ?? "";
30
- return i === !0 && !r.includes(".") ? _base.EMPTY_STRING : n === !1 && r.includes(".") ? r.split(".").slice(-1).join(".") || _base.EMPTY_STRING : r;
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;
31
31
  }
32
32
  function findFilePath(t) {
33
- const e = (0, _correctPath.normalizeWindowsPath)(t);
34
- return e.replace(findFileName(e, {
35
- requireExtension: !0
36
- }), "");
33
+ const e = (0, _correctPath.normalizeWindowsPath)(t),
34
+ r = e.replace(findFileName(e, {
35
+ requireExtension: !0
36
+ }), "");
37
+ return r === "/" ? r : r.replace(/\/$/, "");
37
38
  }
38
39
  function findFolderName(t) {
39
40
  const e = findFilePath(t).split("/");
40
- let i = "";
41
+ let r = "";
41
42
  for (let n = e.length - 1; n >= 0; n--) {
42
- const r = e[n];
43
- if (r) {
44
- i = r;
43
+ const i = e[n];
44
+ if (i) {
45
+ r = i;
45
46
  break;
46
47
  }
47
48
  }
48
- return i ?? _base.EMPTY_STRING;
49
+ return r ?? _base.EMPTY_STRING;
49
50
  }
50
51
  function findFileExtension(t) {
51
52
  if (t === "..") return "";
@@ -59,14 +60,14 @@ function hasFilePath(t) {
59
60
  return !!findFilePath(t);
60
61
  }
61
62
  function resolvePath(t, e = (0, _getWorkspaceRoot.getWorkspaceRoot)()) {
62
- const i = (0, _correctPath.normalizeWindowsPath)(t).split("/");
63
+ const r = (0, _correctPath.normalizeWindowsPath)(t).split("/");
63
64
  let n = "",
64
- r = !1;
65
- for (let s = i.length - 1; s >= -1 && !r; s--) {
66
- const o = s >= 0 ? i[s] : e;
67
- !o || o.length === 0 || (n = (0, _joinPaths.joinPaths)(o, n), r = (0, _isFile.isAbsolutePath)(o));
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));
68
69
  }
69
- return n = (0, _correctPath.normalizeString)(n, !r), r && !(0, _isFile.isAbsolutePath)(n) ? `/${n}` : n.length > 0 ? n : ".";
70
+ return n = (0, _correctPath.normalizeString)(n, !i), i && !(0, _isFile.isAbsolutePath)(n) ? `/${n}` : n.length > 0 ? n : ".";
70
71
  }
71
72
  function resolvePaths(...t) {
72
73
  return resolvePath((0, _joinPaths.joinPaths)(...t.map(e => (0, _correctPath.normalizeWindowsPath)(e))));
@@ -79,21 +80,21 @@ function relativeToWorkspaceRoot(t) {
79
80
  }
80
81
  function parsePath(t) {
81
82
  const e = /^[/\\]|^[a-z]:[/\\]/i.exec(t)?.[0]?.replace(/\\/g, "/") || "",
82
- i = (0, _correctPath.normalizeWindowsPath)(t),
83
- n = i.replace(/\/$/, "").split("/").slice(0, -1);
83
+ r = (0, _correctPath.normalizeWindowsPath)(t),
84
+ n = r.replace(/\/$/, "").split("/").slice(0, -1);
84
85
  n.length === 1 && /^[A-Z]:$/i.test(n[0]) && (n[0] += "/");
85
- const r = findFolderName(i),
86
+ const i = findFolderName(r),
86
87
  s = n.join("/") || ((0, _isFile.isAbsolutePath)(t) ? "/" : "."),
87
88
  o = findFileExtension(t);
88
89
  return {
89
90
  root: e,
90
91
  dir: s,
91
- base: r,
92
+ base: i,
92
93
  ext: o,
93
- name: r.slice(0, r.length - o.length)
94
+ name: i.slice(0, i.length - o.length)
94
95
  };
95
96
  }
96
97
  function renameFile(t, e) {
97
- const i = parsePath(t);
98
- return (0, _joinPaths.joinPaths)(i.dir, e.includes(".") ? e : e + i.ext);
98
+ const r = parsePath(t);
99
+ return (0, _joinPaths.joinPaths)(r.dir, e.includes(".") ? e : e + r.ext);
99
100
  }
@@ -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:i=!1,withExtension:n=!0}=e,r=l(t)?.split(t?.includes("\\")?"\\":"/")?.pop()??"";return i===!0&&!r.includes(".")?a:n===!1&&r.includes(".")?r.split(".").slice(-1).join(".")||a:r}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 i="";for(let n=e.length-1;n>=0;n--){const r=e[n];if(r){i=r;break}}return i??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 i=l(t).split("/");let n="",r=!1;for(let s=i.length-1;s>=-1&&!r;s--){const o=s>=0?i[s]:e;!o||o.length===0||(n=u(o,n),r=c(o))}return n=g(n,!r),r&&!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,"/")||"",i=l(t),n=i.replace(/\/$/,"").split("/").slice(0,-1);n.length===1&&/^[A-Z]:$/i.test(n[0])&&(n[0]+="/");const r=findFolderName(i),s=n.join("/")||(c(t)?"/":"."),o=findFileExtension(t);return{root:e,dir:s,base:r,ext:o,name:r.slice(0,r.length-o.length)}}export function renameFile(t,e){const i=parsePath(t);return u(i.dir,e.includes(".")?e:e+i.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: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)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/path",
3
- "version": "0.7.1",
3
+ "version": "0.7.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": {