@stryke/path 0.19.4 → 0.21.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/dist/is-type.cjs CHANGED
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.isAbsolute = isAbsolute;
7
7
  exports.isAbsolutePath = isAbsolutePath;
8
+ exports.isNpmScopedPackage = isNpmScopedPackage;
9
+ exports.isNpmScopedPackagePath = isNpmScopedPackagePath;
8
10
  exports.isRelative = isRelative;
9
11
  exports.isRelativePath = isRelativePath;
10
12
  var _regex = require("./regex.cjs");
@@ -20,4 +22,10 @@ function isRelativePath(t) {
20
22
  }
21
23
  function isRelative(t) {
22
24
  return isRelativePath(t);
25
+ }
26
+ function isNpmScopedPackagePath(t) {
27
+ return _regex.NPM_SCOPED_PACKAGE_REGEX.test((0, _slash.slash)(t));
28
+ }
29
+ function isNpmScopedPackage(t) {
30
+ return isNpmScopedPackagePath(t);
23
31
  }
package/dist/is-type.d.ts CHANGED
@@ -32,3 +32,37 @@ export declare function isRelativePath(path: string): boolean;
32
32
  * @returns An indicator specifying if the path is a relative path
33
33
  */
34
34
  export declare function isRelative(path: string): boolean;
35
+ /**
36
+ * Check if the path is a npm package path.
37
+ *
38
+ * @remarks
39
+ * This only checks if the path matches the npm namespace scoped package naming convention such as `@scope/package-name`. This is an alias for {@link isNpmScopedPackage}.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * isNpmScopedPackage("@stryke/path"); // returns true
44
+ * isNpmScopedPackage("lodash"); // returns false
45
+ * isNpmNamespacePackage("./src/index.ts"); // returns false
46
+ * ```
47
+ *
48
+ * @param path - The path to check
49
+ * @returns An indicator specifying if the path is a npm package path
50
+ */
51
+ export declare function isNpmScopedPackagePath(path: string): boolean;
52
+ /**
53
+ * Check if the path is a npm package path.
54
+ *
55
+ * @remarks
56
+ * This only checks if the path matches the npm namespace scoped package naming convention such as `@scope/package-name`. This is an alias for {@link isNpmScopedPackagePath}.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * isNpmScopedPackagePath("@stryke/path"); // returns true
61
+ * isNpmScopedPackagePath("lodash"); // returns false
62
+ * isNpmScopedPackagePath("./src/index.ts"); // returns false
63
+ * ```
64
+ *
65
+ * @param path - The path to check
66
+ * @returns An indicator specifying if the path is a npm package path
67
+ */
68
+ export declare function isNpmScopedPackage(path: string): boolean;
package/dist/is-type.mjs CHANGED
@@ -1 +1 @@
1
- import{ABSOLUTE_PATH_REGEX as o}from"./regex";import{slash as n}from"./slash";export function isAbsolutePath(t){return o.test(n(t))}export function isAbsolute(t){return isAbsolutePath(t)}export function isRelativePath(t){return!isAbsolutePath(t)}export function isRelative(t){return isRelativePath(t)}
1
+ import{ABSOLUTE_PATH_REGEX as e,NPM_SCOPED_PACKAGE_REGEX as n}from"./regex";import{slash as o}from"./slash";export function isAbsolutePath(t){return e.test(o(t))}export function isAbsolute(t){return isAbsolutePath(t)}export function isRelativePath(t){return!isAbsolutePath(t)}export function isRelative(t){return isRelativePath(t)}export function isNpmScopedPackagePath(t){return n.test(o(t))}export function isNpmScopedPackage(t){return isNpmScopedPackagePath(t)}
package/dist/regex.cjs CHANGED
@@ -3,10 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.UNC_REGEX = exports.ROOT_FOLDER_REGEX = exports.FILE_EXTENSION_REGEX = exports.DRIVE_LETTER_START_REGEX = exports.DRIVE_LETTER_REGEX = exports.ABSOLUTE_PATH_REGEX = void 0;
6
+ exports.UNC_REGEX = exports.ROOT_FOLDER_REGEX = exports.PACKAGE_PATH_REGEX = exports.NPM_SCOPED_PACKAGE_REGEX = exports.FILE_EXTENSION_REGEX = exports.DRIVE_LETTER_START_REGEX = exports.DRIVE_LETTER_REGEX = exports.ABSOLUTE_PATH_REGEX = void 0;
7
7
  const DRIVE_LETTER_START_REGEX = exports.DRIVE_LETTER_START_REGEX = /^[A-Z]:\//i,
8
8
  DRIVE_LETTER_REGEX = exports.DRIVE_LETTER_REGEX = /^[A-Z]:$/i,
9
9
  UNC_REGEX = exports.UNC_REGEX = /^[/\\]{2}/,
10
10
  ABSOLUTE_PATH_REGEX = exports.ABSOLUTE_PATH_REGEX = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^~[/\\]|^[A-Z]:[/\\]/i,
11
11
  ROOT_FOLDER_REGEX = exports.ROOT_FOLDER_REGEX = /^\/([A-Z]:)?$/i,
12
- FILE_EXTENSION_REGEX = exports.FILE_EXTENSION_REGEX = /\.[0-9a-z]+$/i;
12
+ FILE_EXTENSION_REGEX = exports.FILE_EXTENSION_REGEX = /\.[0-9a-z]+$/i,
13
+ PACKAGE_PATH_REGEX = exports.PACKAGE_PATH_REGEX = /^@\w+\/.*$/,
14
+ NPM_SCOPED_PACKAGE_REGEX = exports.NPM_SCOPED_PACKAGE_REGEX = /^(?:@[\w-]+\/)?[\w-]+$/;
package/dist/regex.d.ts CHANGED
@@ -4,3 +4,5 @@ export declare const UNC_REGEX: RegExp;
4
4
  export declare const ABSOLUTE_PATH_REGEX: RegExp;
5
5
  export declare const ROOT_FOLDER_REGEX: RegExp;
6
6
  export declare const FILE_EXTENSION_REGEX: RegExp;
7
+ export declare const PACKAGE_PATH_REGEX: RegExp;
8
+ export declare const NPM_SCOPED_PACKAGE_REGEX: RegExp;
package/dist/regex.mjs CHANGED
@@ -1 +1 @@
1
- export const DRIVE_LETTER_START_REGEX=/^[A-Z]:\//i,DRIVE_LETTER_REGEX=/^[A-Z]:$/i,UNC_REGEX=/^[/\\]{2}/,ABSOLUTE_PATH_REGEX=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^~[/\\]|^[A-Z]:[/\\]/i,ROOT_FOLDER_REGEX=/^\/([A-Z]:)?$/i,FILE_EXTENSION_REGEX=/\.[0-9a-z]+$/i;
1
+ export const DRIVE_LETTER_START_REGEX=/^[A-Z]:\//i,DRIVE_LETTER_REGEX=/^[A-Z]:$/i,UNC_REGEX=/^[/\\]{2}/,ABSOLUTE_PATH_REGEX=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^~[/\\]|^[A-Z]:[/\\]/i,ROOT_FOLDER_REGEX=/^\/([A-Z]:)?$/i,FILE_EXTENSION_REGEX=/\.[0-9a-z]+$/i,PACKAGE_PATH_REGEX=/^@\w+\/.*$/,NPM_SCOPED_PACKAGE_REGEX=/^(?:@[\w-]+\/)?[\w-]+$/;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/path",
3
- "version": "0.19.4",
3
+ "version": "0.21.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.4",
15
- "@stryke/type-checks": "^0.3.14",
16
- "@stryke/types": "^0.10.4"
14
+ "@stryke/convert": "^0.6.6",
15
+ "@stryke/type-checks": "^0.3.16",
16
+ "@stryke/types": "^0.10.6"
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": "201972005e4b1291d431d46e3fb49764f44690c5"
283
+ "gitHead": "fc3f6e2179191455ef4c9a8e7be4294a77228b07"
284
284
  }