@stryke/path 0.19.3 → 0.20.0

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/dist/append.cjs CHANGED
@@ -4,12 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.append = void 0;
7
+ exports.appendExtension = appendExtension;
7
8
  exports.appendPath = appendPath;
8
9
  var _cwd = require("./cwd.cjs");
9
10
  var _isParentPath = require("./is-parent-path.cjs");
10
11
  var _joinPaths = require("./join-paths.cjs");
11
12
  var _slash = require("./slash.cjs");
12
- function appendPath(r, o = (0, _cwd.cwd)()) {
13
- return (0, _slash.slash)((0, _isParentPath.isParentPath)(r, o) ? r : (0, _joinPaths.joinPaths)(o, r));
13
+ function appendPath(r, n = (0, _cwd.cwd)()) {
14
+ return (0, _slash.slash)((0, _isParentPath.isParentPath)(r, n) ? r : (0, _joinPaths.joinPaths)(n, r));
14
15
  }
15
- const append = exports.append = appendPath;
16
+ const append = exports.append = appendPath;
17
+ function appendExtension(r, n) {
18
+ return `${r}.${n.replace(/^\./, "")}`;
19
+ }
package/dist/append.d.ts CHANGED
@@ -16,3 +16,19 @@
16
16
  */
17
17
  export declare function appendPath(childPath: string, parentPath?: string): string;
18
18
  export declare const append: typeof appendPath;
19
+ /**
20
+ * Append the extension to the given path.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * appendExtension("/home/user/project/src/index", ".ts");
25
+ * // returns "/home/user/project/src/index.ts"
26
+ * appendExtension("/home/user/project/src/index.ts", ".js");
27
+ * // returns "/home/user/project/src/index.ts.js"
28
+ * ```
29
+ *
30
+ * @param path - The path to append the extension to.
31
+ * @param extension - The extension to append.
32
+ * @returns The path with the appended extension.
33
+ */
34
+ export declare function appendExtension(path: string, extension: string): string;
package/dist/append.mjs CHANGED
@@ -1 +1 @@
1
- import{cwd as t}from"./cwd";import{isParentPath as n}from"./is-parent-path";import{joinPaths as p}from"./join-paths";import{slash as i}from"./slash";export function appendPath(r,o=t()){return i(n(r,o)?r:p(o,r))}export const append=appendPath;
1
+ import{cwd as t}from"./cwd";import{isParentPath as o}from"./is-parent-path";import{joinPaths as i}from"./join-paths";import{slash as p}from"./slash";export function appendPath(r,n=t()){return p(o(r,n)?r:i(n,r))}export const append=appendPath;export function appendExtension(r,n){return`${r}.${n.replace(/^\./,"")}`}
@@ -10,31 +10,32 @@ exports.stripStars = stripStars;
10
10
  exports.toAbsolutePath = toAbsolutePath;
11
11
  exports.toRelativePath = toRelativePath;
12
12
  exports.withTrailingSlash = withTrailingSlash;
13
+ var _append = require("./append.cjs");
13
14
  var _cwd = require("./cwd.cjs");
14
15
  var _isType = require("./is-type.cjs");
15
16
  var _joinPaths = require("./join-paths.cjs");
16
17
  var _regex = require("./regex.cjs");
17
18
  var _slash = require("./slash.cjs");
18
19
  function normalizeWindowsPath(e = "") {
19
- return e && (0, _slash.slash)(e).replace(_regex.DRIVE_LETTER_START_REGEX, n => n.toUpperCase());
20
+ return e && (0, _slash.slash)(e).replace(_regex.DRIVE_LETTER_START_REGEX, t => t.toUpperCase());
20
21
  }
21
22
  function correctPath(e) {
22
23
  if (!e || e.length === 0) return ".";
23
24
  e = normalizeWindowsPath(e);
24
- const n = e.match(_regex.UNC_REGEX),
25
+ const t = e.match(_regex.UNC_REGEX),
25
26
  r = (0, _isType.isAbsolutePath)(e),
26
- t = e.endsWith("/");
27
- return e = normalizeString(e, !r), e.length === 0 ? r ? "/" : t ? "./" : "." : (t && (e += "/"), _regex.DRIVE_LETTER_REGEX.test(e) && (e += "/"), n ? r ? `//${e}` : `//./${e}` : !e.startsWith("/") && r && !_regex.DRIVE_LETTER_REGEX.test(e) ? `/${e}` : e);
27
+ n = e.endsWith("/");
28
+ return e = normalizeString(e, !r), e.length === 0 ? r ? "/" : n ? "./" : "." : (n && (e += "/"), _regex.DRIVE_LETTER_REGEX.test(e) && (e += "/"), t ? r ? `//${e}` : `//./${e}` : !e.startsWith("/") && r && !_regex.DRIVE_LETTER_REGEX.test(e) ? `/${e}` : e);
28
29
  }
29
30
  function stripStars(e) {
30
31
  if (!e || e.length === 0) return ".";
31
32
  e = correctPath(e);
32
- let n = !1;
33
- return e.split("/").reduce((r, t) => t?.trim() ? n || t.includes("*") ? (n = !0, r) : r + (r ? `/${t}` : t) : r, "");
33
+ let t = !1;
34
+ return e.split("/").reduce((r, n) => n?.trim() ? t || n.includes("*") ? (t = !0, r) : r + (r ? `/${n}` : n) : r, "");
34
35
  }
35
- function normalizeString(e, n) {
36
+ function normalizeString(e, t) {
36
37
  let r = "",
37
- t = 0,
38
+ n = 0,
38
39
  l = -1,
39
40
  s = 0,
40
41
  o = null;
@@ -45,30 +46,30 @@ function normalizeString(e, n) {
45
46
  }
46
47
  if (o === "/") {
47
48
  if (!(l === i - 1 || s === 1)) if (s === 2) {
48
- if (r.length < 2 || t !== 2 || r[r.length - 1] !== "." || r[r.length - 2] !== ".") {
49
+ if (r.length < 2 || n !== 2 || r[r.length - 1] !== "." || r[r.length - 2] !== ".") {
49
50
  if (r.length > 2) {
50
51
  const c = r.lastIndexOf("/");
51
- c === -1 ? (r = "", t = 0) : (r = r.slice(0, c), t = r.length - 1 - r.lastIndexOf("/")), l = i, s = 0;
52
+ c === -1 ? (r = "", n = 0) : (r = r.slice(0, c), n = r.length - 1 - r.lastIndexOf("/")), l = i, s = 0;
52
53
  continue;
53
54
  } else if (r.length > 0) {
54
- r = "", t = 0, l = i, s = 0;
55
+ r = "", n = 0, l = i, s = 0;
55
56
  continue;
56
57
  }
57
58
  }
58
- n && (r += r.length > 0 ? "/.." : "..", t = 2);
59
- } else r.length > 0 ? r += `/${e.slice(l + 1, i)}` : r = e.slice(l + 1, i), t = i - l - 1;
59
+ t && (r += r.length > 0 ? "/.." : "..", n = 2);
60
+ } else r.length > 0 ? r += `/${e.slice(l + 1, i)}` : r = e.slice(l + 1, i), n = i - l - 1;
60
61
  l = i, s = 0;
61
62
  } else o === "." && s !== -1 ? ++s : s = -1;
62
63
  }
63
64
  return r;
64
65
  }
65
- function toAbsolutePath(e, n) {
66
- return (0, _isType.isAbsolutePath)(e) ? e : (0, _slash.slash)(normalizeString((0, _joinPaths.joinPaths)(n || process.cwd(), e), !0));
66
+ function toAbsolutePath(e, t = (0, _cwd.cwd)()) {
67
+ return (0, _isType.isAbsolutePath)(e) ? e : (0, _slash.slash)(normalizeString((0, _append.appendPath)(e, t), !0));
67
68
  }
68
- function toRelativePath(e, n = (0, _cwd.cwd)()) {
69
- return !e || e.length === 0 ? "." : ((0, _isType.isAbsolutePath)(e) ? e = (0, _slash.slash)(normalizeString(e, !0)) : e = (0, _slash.slash)(normalizeString((0, _joinPaths.joinPaths)(n, e), !0)), e.startsWith("./") ? e.slice(2) : e);
69
+ function toRelativePath(e, t = (0, _cwd.cwd)()) {
70
+ return !e || e.length === 0 ? "." : ((0, _isType.isAbsolutePath)(e) ? e = (0, _slash.slash)(normalizeString(e, !0)) : e = (0, _slash.slash)(normalizeString((0, _joinPaths.joinPaths)(t, e), !0)), e.startsWith("./") ? e.slice(2) : e);
70
71
  }
71
72
  function withTrailingSlash(e) {
72
- const n = correctPath(e);
73
- return n.endsWith("/") ? n : `${n}/`;
73
+ const t = correctPath(e);
74
+ return t.endsWith("/") ? t : `${t}/`;
74
75
  }
@@ -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,n=>n.toUpperCase())}export function correctPath(e){if(!e||e.length===0)return".";e=normalizeWindowsPath(e);const n=e.match(x),r=u(e),t=e.endsWith("/");return e=normalizeString(e,!r),e.length===0?r?"/":t?"./":".":(t&&(e+="/"),d.test(e)&&(e+="/"),n?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 n=!1;return e.split("/").reduce((r,t)=>t?.trim()?n||t.includes("*")?(n=!0,r):r+(r?`/${t}`:t):r,"")}export function normalizeString(e,n){let r="",t=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||t!==2||r[r.length-1]!=="."||r[r.length-2]!=="."){if(r.length>2){const c=r.lastIndexOf("/");c===-1?(r="",t=0):(r=r.slice(0,c),t=r.length-1-r.lastIndexOf("/")),l=i,s=0;continue}else if(r.length>0){r="",t=0,l=i,s=0;continue}}n&&(r+=r.length>0?"/..":"..",t=2)}else r.length>0?r+=`/${e.slice(l+1,i)}`:r=e.slice(l+1,i),t=i-l-1;l=i,s=0}else o==="."&&s!==-1?++s:s=-1}return r}export function toAbsolutePath(e,n){return u(e)?e:f(normalizeString(g(n||process.cwd(),e),!0))}export function toRelativePath(e,n=m()){return!e||e.length===0?".":(u(e)?e=f(normalizeString(e,!0)):e=f(normalizeString(g(n,e),!0)),e.startsWith("./")?e.slice(2):e)}export function withTrailingSlash(e){const n=correctPath(e);return n.endsWith("/")?n:`${n}/`}
1
+ import{appendPath as d}from"./append";import{cwd as g}from"./cwd";import{isAbsolutePath as u}from"./is-type";import{joinPaths as E}from"./join-paths";import{DRIVE_LETTER_REGEX as m,DRIVE_LETTER_START_REGEX as x,UNC_REGEX as P}from"./regex";import{slash as f}from"./slash";export function normalizeWindowsPath(e=""){return e&&f(e).replace(x,t=>t.toUpperCase())}export function correctPath(e){if(!e||e.length===0)return".";e=normalizeWindowsPath(e);const t=e.match(P),r=u(e),n=e.endsWith("/");return e=normalizeString(e,!r),e.length===0?r?"/":n?"./":".":(n&&(e+="/"),m.test(e)&&(e+="/"),t?r?`//${e}`:`//./${e}`:!e.startsWith("/")&&r&&!m.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=g()){return u(e)?e:f(normalizeString(d(e,t),!0))}export function toRelativePath(e,t=g()){return!e||e.length===0?".":(u(e)?e=f(normalizeString(e,!0)):e=f(normalizeString(E(t,e),!0)),e.startsWith("./")?e.slice(2):e)}export function withTrailingSlash(e){const t=correctPath(e);return t.endsWith("/")?t:`${t}/`}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/path",
3
- "version": "0.19.3",
3
+ "version": "0.20.0",
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": {
@@ -11,9 +11,9 @@
11
11
  "private": false,
12
12
  "devDependencies": {
13
13
  "@storm-software/testing-tools": "^1.119.48",
14
- "@stryke/convert": "^0.6.3",
15
- "@stryke/type-checks": "^0.3.13",
16
- "@stryke/types": "^0.10.3"
14
+ "@stryke/convert": "^0.6.5",
15
+ "@stryke/type-checks": "^0.3.15",
16
+ "@stryke/types": "^0.10.5"
17
17
  },
18
18
  "publishConfig": { "access": "public" },
19
19
  "dependencies": {},
@@ -280,5 +280,5 @@
280
280
  "main": "./dist/index.cjs",
281
281
  "module": "./dist/index.mjs",
282
282
  "types": "./dist/index.d.ts",
283
- "gitHead": "f96193e785d85704cdc3d2a8c9894766631d7388"
283
+ "gitHead": "2c99ef0e654a63299ca75104ec2e8a46d65997cc"
284
284
  }