@stryke/path 0.21.6 → 0.22.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/file-path-fns.cjs +14 -13
- package/dist/file-path-fns.d.ts +4 -2
- package/dist/file-path-fns.mjs +1 -1
- package/package.json +5 -5
package/dist/file-path-fns.cjs
CHANGED
|
@@ -38,25 +38,26 @@ function findFileName(e, t = {}) {
|
|
|
38
38
|
i = (0, _correctPath.normalizeWindowsPath)(e)?.split(e?.includes("\\") ? "\\" : "/")?.pop() ?? "";
|
|
39
39
|
return r === !0 && !i.includes(".") ? _base.EMPTY_STRING : n === !1 && i.includes(".") ? i.replace(`.${findFileExtension(i) ?? ""}`, "") || _base.EMPTY_STRING : i;
|
|
40
40
|
}
|
|
41
|
-
function findFilePath(e) {
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
requireExtension: !
|
|
41
|
+
function findFilePath(e, t = {}) {
|
|
42
|
+
const r = (0, _correctPath.normalizeWindowsPath)(e),
|
|
43
|
+
n = r.replace(findFileName(r, {
|
|
44
|
+
requireExtension: !1,
|
|
45
|
+
...t
|
|
45
46
|
}), "");
|
|
46
|
-
return
|
|
47
|
+
return n === "/" ? n : n.replace(/\/$/, "");
|
|
47
48
|
}
|
|
48
49
|
const dirname = exports.dirname = findFilePath;
|
|
49
|
-
function findFolderName(e) {
|
|
50
|
-
const
|
|
51
|
-
let
|
|
52
|
-
for (let
|
|
53
|
-
const
|
|
54
|
-
if (
|
|
55
|
-
|
|
50
|
+
function findFolderName(e, t) {
|
|
51
|
+
const r = findFilePath(e, t).split("/");
|
|
52
|
+
let n = "";
|
|
53
|
+
for (let i = r.length - 1; i >= 0; i--) {
|
|
54
|
+
const o = r[i];
|
|
55
|
+
if (o) {
|
|
56
|
+
n = o;
|
|
56
57
|
break;
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
|
-
return
|
|
60
|
+
return n ?? _base.EMPTY_STRING;
|
|
60
61
|
}
|
|
61
62
|
const basename = exports.basename = findFolderName;
|
|
62
63
|
function findFileExtension(e) {
|
package/dist/file-path-fns.d.ts
CHANGED
|
@@ -39,9 +39,10 @@ export declare function findFileName(filePath: string, options?: FindFileNameOpt
|
|
|
39
39
|
* ```
|
|
40
40
|
*
|
|
41
41
|
* @param filePath - The file path to process
|
|
42
|
+
* @param options - Options to control the file name extraction
|
|
42
43
|
* @returns The full file path's directories
|
|
43
44
|
*/
|
|
44
|
-
export declare function findFilePath(filePath: string): string;
|
|
45
|
+
export declare function findFilePath(filePath: string, options?: FindFileNameOptions): string;
|
|
45
46
|
export declare const dirname: typeof findFilePath;
|
|
46
47
|
/**
|
|
47
48
|
* Find the top most folder containing the file from a file path.
|
|
@@ -55,9 +56,10 @@ export declare const dirname: typeof findFilePath;
|
|
|
55
56
|
* // folderPath = "Documents"
|
|
56
57
|
*
|
|
57
58
|
* @param filePath - The file path to process
|
|
59
|
+
* @param options - Options to control the file name extraction
|
|
58
60
|
* @returns The folder containing the file
|
|
59
61
|
*/
|
|
60
|
-
export declare function findFolderName(filePath: string): string;
|
|
62
|
+
export declare function findFolderName(filePath: string, options?: FindFileNameOptions): string;
|
|
61
63
|
export declare const basename: typeof findFolderName;
|
|
62
64
|
/**
|
|
63
65
|
* Find the file extension from a file path.
|
package/dist/file-path-fns.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isSetString as d}from"@stryke/type-checks/is-set-string";import{EMPTY_STRING as
|
|
1
|
+
import{isSetString as d}from"@stryke/type-checks/is-set-string";import{EMPTY_STRING as a}from"@stryke/types/base";import{normalizeString as p,normalizeWindowsPath as l}from"./correct-path";import{cwd as u}from"./cwd";import{isAbsolute as g,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(".")?a:n===!1&&i.includes(".")?i.replace(`.${findFileExtension(i)??""}`,"")||a:i}export function findFilePath(e,t={}){const r=l(e),n=r.replace(findFileName(r,{requireExtension:!1,...t}),"");return n==="/"?n:n.replace(/\/$/,"")}export const dirname=findFilePath;export function findFolderName(e,t){const r=findFilePath(e,t).split("/");let n="";for(let i=r.length-1;i>=0;i--){const o=r[i];if(o){n=o;break}}return n??a}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)??a}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=u()){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=p(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]:u();!i||i.length===0||(t=`${i}/${t}`,r=g(i))}return t=p(t,!r),r&&!g(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,u())}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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/path",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.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.50",
|
|
14
|
-
"@stryke/convert": "^0.6.
|
|
15
|
-
"@stryke/type-checks": "^0.4.
|
|
16
|
-
"@stryke/types": "^0.10.
|
|
14
|
+
"@stryke/convert": "^0.6.13",
|
|
15
|
+
"@stryke/type-checks": "^0.4.4",
|
|
16
|
+
"@stryke/types": "^0.10.13"
|
|
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": "
|
|
283
|
+
"gitHead": "eb28313b3230b7ea654c87586ca07773e2e57f52"
|
|
284
284
|
}
|