@stryke/path 0.18.3 → 0.18.4

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,7 +23,7 @@ exports.renameFile = renameFile;
23
23
  exports.resolve = resolve;
24
24
  exports.resolvePath = resolvePath;
25
25
  exports.resolvePaths = resolvePaths;
26
- var _typeChecks = require("@stryke/type-checks");
26
+ var _isSetString = require("@stryke/type-checks/is-set-string");
27
27
  var _base = require("@stryke/types/base");
28
28
  var _correctPath = require("./correct-path.cjs");
29
29
  var _cwd = require("./cwd.cjs");
@@ -62,7 +62,7 @@ const basename = exports.basename = findFolderName;
62
62
  function findFileExtension(e) {
63
63
  if (e.endsWith(".") || e.endsWith("/")) return;
64
64
  const t = _regex.FILE_EXTENSION_REGEX.exec((0, _correctPath.normalizeWindowsPath)(e));
65
- return t && t.length > 0 && (0, _typeChecks.isSetString)(t[0]) ? t[0].replace(".", "") : void 0;
65
+ return t && t.length > 0 && (0, _isSetString.isSetString)(t[0]) ? t[0].replace(".", "") : void 0;
66
66
  }
67
67
  const extname = exports.extname = findFileExtension;
68
68
  function findFileDotExtension(e) {
@@ -1 +1 @@
1
- import{isSetString as d}from"@stryke/type-checks";import{EMPTY_STRING as u}from"@stryke/types/base";import{normalizeString as g,normalizeWindowsPath as l}from"./correct-path";import{cwd as a}from"./cwd";import{isAbsolute as p,isAbsolutePath as c}from"./is-type";import{joinPaths as f}from"./join-paths";import{FILE_EXTENSION_REGEX as m,ROOT_FOLDER_REGEX as x}from"./regex";export function findFileName(e,t={}){const{requireExtension:r=!1,withExtension:n=!0}=t,i=l(e)?.split(e?.includes("\\")?"\\":"/")?.pop()??"";return r===!0&&!i.includes(".")?u:n===!1&&i.includes(".")?i.replace(`.${findFileExtension(i)??""}`,"")||u:i}export function findFilePath(e){const t=l(e),r=t.replace(findFileName(t,{requireExtension:!0}),"");return r==="/"?r:r.replace(/\/$/,"")}export const dirname=findFilePath;export function findFolderName(e){const t=findFilePath(e).split("/");let r="";for(let n=t.length-1;n>=0;n--){const i=t[n];if(i){r=i;break}}return r??u}export const basename=findFolderName;export function findFileExtension(e){if(e.endsWith(".")||e.endsWith("/"))return;const t=m.exec(l(e));return t&&t.length>0&&d(t[0])?t[0].replace(".",""):void 0}export const extname=findFileExtension;export function findFileDotExtension(e){const t=findFileExtension(e);return t?`.${t}`:void 0}export function findFileExtensionSafe(e){return findFileExtension(e)??u}export function findFileDotExtensionSafe(e){const t=findFileExtension(e);return t?`.${t}`:""}export function hasFileName(e){return!!findFileName(e)}export function hasFilePath(e){return!!findFilePath(e)}export function hasFolderName(e){return!!findFolderName(e)}export function hasFileExtension(e){return!!findFileExtension(e)}export function resolvePath(e,t=a()){const r=l(e).split("/");let n="",i=!1;for(let o=r.length-1;o>=-1&&!i;o--){const s=o>=0?r[o]:t;!s||s.length===0||(n=f(s,n),i=c(s))}return n=g(n,!i),i&&!c(n)?`/${n}`:n.length>0?n:"."}export function resolve(...e){e=e.map(n=>l(n));let t="",r=!1;for(let n=e.length-1;n>=-1&&!r;n--){const i=n>=0?e[n]:a();!i||i.length===0||(t=`${i}/${t}`,r=p(i))}return t=g(t,!r),r&&!p(t)?`/${t}`:t.length>0?t:"."}export function resolvePaths(...e){return resolvePath(f(...e.map(t=>l(t))))}export function relative(e,t){const r=resolve(e).replace(x,"$1").split("/"),n=resolve(t).replace(x,"$1").split("/");if(n[0][1]===":"&&r[0][1]===":"&&r[0]!==n[0])return n.join("/");const i=[...r];for(const o of i){if(n[0]!==o)break;r.shift(),n.shift()}return[...r.map(()=>".."),...n].join("/")}export function relativePath(e,t,r=!1){return relative(r!==!0?e.replace(/\/$/,""):e,r!==!0?t.replace(/\/$/,""):t)}export function relativeToCurrentDir(e){return relativePath(e,a())}export function parsePath(e){const t=/^[/\\]|^[a-z]:[/\\]/i.exec(e)?.[0]?.replace(/\\/g,"/")||"",r=l(e),n=r.replace(/\/$/,"").split("/").slice(0,-1);n.length===1&&/^[A-Z]:$/i.test(n[0])&&(n[0]+="/");const i=findFolderName(r),o=n.join("/")||(c(e)?"/":"."),s=findFileExtensionSafe(e);return{root:t,dir:o,base:i,ext:s,name:i.slice(0,i.length-s.length)}}export function renameFile(e,t){const r=parsePath(e);return f(r.dir,t.includes(".")?t:t+r.ext)}
1
+ import{isSetString as d}from"@stryke/type-checks/is-set-string";import{EMPTY_STRING as u}from"@stryke/types/base";import{normalizeString as g,normalizeWindowsPath as l}from"./correct-path";import{cwd as a}from"./cwd";import{isAbsolute as p,isAbsolutePath as c}from"./is-type";import{joinPaths as f}from"./join-paths";import{FILE_EXTENSION_REGEX as m,ROOT_FOLDER_REGEX as x}from"./regex";export function findFileName(e,t={}){const{requireExtension:r=!1,withExtension:n=!0}=t,i=l(e)?.split(e?.includes("\\")?"\\":"/")?.pop()??"";return r===!0&&!i.includes(".")?u:n===!1&&i.includes(".")?i.replace(`.${findFileExtension(i)??""}`,"")||u:i}export function findFilePath(e){const t=l(e),r=t.replace(findFileName(t,{requireExtension:!0}),"");return r==="/"?r:r.replace(/\/$/,"")}export const dirname=findFilePath;export function findFolderName(e){const t=findFilePath(e).split("/");let r="";for(let n=t.length-1;n>=0;n--){const i=t[n];if(i){r=i;break}}return r??u}export const basename=findFolderName;export function findFileExtension(e){if(e.endsWith(".")||e.endsWith("/"))return;const t=m.exec(l(e));return t&&t.length>0&&d(t[0])?t[0].replace(".",""):void 0}export const extname=findFileExtension;export function findFileDotExtension(e){const t=findFileExtension(e);return t?`.${t}`:void 0}export function findFileExtensionSafe(e){return findFileExtension(e)??u}export function findFileDotExtensionSafe(e){const t=findFileExtension(e);return t?`.${t}`:""}export function hasFileName(e){return!!findFileName(e)}export function hasFilePath(e){return!!findFilePath(e)}export function hasFolderName(e){return!!findFolderName(e)}export function hasFileExtension(e){return!!findFileExtension(e)}export function resolvePath(e,t=a()){const r=l(e).split("/");let n="",i=!1;for(let o=r.length-1;o>=-1&&!i;o--){const s=o>=0?r[o]:t;!s||s.length===0||(n=f(s,n),i=c(s))}return n=g(n,!i),i&&!c(n)?`/${n}`:n.length>0?n:"."}export function resolve(...e){e=e.map(n=>l(n));let t="",r=!1;for(let n=e.length-1;n>=-1&&!r;n--){const i=n>=0?e[n]:a();!i||i.length===0||(t=`${i}/${t}`,r=p(i))}return t=g(t,!r),r&&!p(t)?`/${t}`:t.length>0?t:"."}export function resolvePaths(...e){return resolvePath(f(...e.map(t=>l(t))))}export function relative(e,t){const r=resolve(e).replace(x,"$1").split("/"),n=resolve(t).replace(x,"$1").split("/");if(n[0][1]===":"&&r[0][1]===":"&&r[0]!==n[0])return n.join("/");const i=[...r];for(const o of i){if(n[0]!==o)break;r.shift(),n.shift()}return[...r.map(()=>".."),...n].join("/")}export function relativePath(e,t,r=!1){return relative(r!==!0?e.replace(/\/$/,""):e,r!==!0?t.replace(/\/$/,""):t)}export function relativeToCurrentDir(e){return relativePath(e,a())}export function parsePath(e){const t=/^[/\\]|^[a-z]:[/\\]/i.exec(e)?.[0]?.replace(/\\/g,"/")||"",r=l(e),n=r.replace(/\/$/,"").split("/").slice(0,-1);n.length===1&&/^[A-Z]:$/i.test(n[0])&&(n[0]+="/");const i=findFolderName(r),o=n.join("/")||(c(e)?"/":"."),s=findFileExtensionSafe(e);return{root:t,dir:o,base:i,ext:s,name:i.slice(0,i.length-s.length)}}export function renameFile(e,t){const r=parsePath(e);return f(r.dir,t.includes(".")?t:t+r.ext)}
package/dist/replace.cjs CHANGED
@@ -11,7 +11,7 @@ var _filePathFns = require("./file-path-fns.cjs");
11
11
  var _isParentPath = require("./is-parent-path.cjs");
12
12
  var _slash = require("./slash.cjs");
13
13
  function replacePath(r, o = (0, _cwd.cwd)()) {
14
- return (0, _slash.formatSlash)((0, _correctPath.correctPath)((0, _isParentPath.isParentPath)(r, o) ? (0, _slash.formatSlash)(r).replace((0, _slash.formatSlash)(o), "") : r));
14
+ return (0, _slash.formatSlash)((0, _correctPath.correctPath)((0, _isParentPath.isParentPath)(r, o) ? (0, _slash.formatSlash)(r).replace((0, _slash.formatSlash)(o), "").replace(/^\/+/g, "") : r));
15
15
  }
16
16
  function replaceExtension(r, o = "") {
17
17
  return (0, _correctPath.correctPath)(r.replace(!o || o.includes(".") ? (0, _filePathFns.findFileDotExtensionSafe)(r) : (0, _filePathFns.findFileExtensionSafe)(r), o));
package/dist/replace.mjs CHANGED
@@ -1 +1 @@
1
- import{correctPath as n}from"./correct-path";import{cwd as t}from"./cwd";import{findFileDotExtensionSafe as e,findFileExtensionSafe as f}from"./file-path-fns";import{isParentPath as s}from"./is-parent-path";import{formatSlash as i}from"./slash";export function replacePath(r,o=t()){return i(n(s(r,o)?i(r).replace(i(o),""):r))}export function replaceExtension(r,o=""){return n(r.replace(!o||o.includes(".")?e(r):f(r),o))}
1
+ import{correctPath as n}from"./correct-path";import{cwd as t}from"./cwd";import{findFileDotExtensionSafe as e,findFileExtensionSafe as f}from"./file-path-fns";import{isParentPath as s}from"./is-parent-path";import{formatSlash as i}from"./slash";export function replacePath(r,o=t()){return i(n(s(r,o)?i(r).replace(i(o),"").replace(/^\/+/g,""):r))}export function replaceExtension(r,o=""){return n(r.replace(!o||o.includes(".")?e(r):f(r),o))}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/path",
3
- "version": "0.18.3",
3
+ "version": "0.18.4",
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": {
@@ -294,5 +294,5 @@
294
294
  "main": "./dist/index.cjs",
295
295
  "module": "./dist/index.mjs",
296
296
  "types": "./dist/index.d.ts",
297
- "gitHead": "318f947b4a5068b62181d287cfa768f711d2e95e"
297
+ "gitHead": "39c2e3311f9f1246241a55748436981aa65e3ced"
298
298
  }