@mxfb/tools 0.0.16 → 0.0.18

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/index.js CHANGED
@@ -1,10 +1,14 @@
1
1
  import * as Comp from './components/Comp/index.js'
2
2
  import * as findDuplicatesInArray from './utils/agnostic/find-duplicates-in-array/index.js'
3
+ import * as isRecord from './utils/agnostic/is-record/index.js'
3
4
  import * as isInDirectory from './utils/node/is-in-directory/index.js'
4
5
  import * as listSubdirectoriesIndexes from './utils/node/list-subdirectories-indexes/index.js'
6
+ import * as listSubpaths from './utils/node/list-subpaths/index.js'
5
7
  import * as readWriteFile from './utils/node/read-write-file/index.js'
6
8
  export { Comp }
7
9
  export { findDuplicatesInArray }
10
+ export { isRecord }
8
11
  export { isInDirectory }
9
12
  export { listSubdirectoriesIndexes }
13
+ export { listSubpaths }
10
14
  export { readWriteFile }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mxfb/tools",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "description": "",
5
5
  "author": "Maxime Fabas",
6
6
  "license": "ISC",
@@ -0,0 +1 @@
1
+ export default function isRecord(input: unknown): input is Record<string, unknown>;
@@ -0,0 +1 @@
1
+ function r(e){return typeof e!="object"||e===null?!1:Object.keys(e).every(n=>typeof n=="string")}export{r as default};
@@ -0,0 +1,24 @@
1
+ /// <reference types="node" />
2
+ import { Stats } from 'node:fs';
3
+ type ChildType = 'file' | 'directory' | 'symlink';
4
+ type ChildDetails = {
5
+ type: ChildType;
6
+ hidden: boolean;
7
+ realPath: string;
8
+ };
9
+ type Options = {
10
+ directories?: boolean;
11
+ files?: boolean;
12
+ symlinks?: boolean;
13
+ hidden?: boolean;
14
+ followSimlinks?: boolean;
15
+ dedupeSimlinksContents?: boolean;
16
+ maxDepth?: number;
17
+ filter?: (path: string, details: ChildDetails) => boolean | Promise<boolean>;
18
+ };
19
+ type Context = {
20
+ depth?: number;
21
+ lstats?: Stats | null;
22
+ };
23
+ export default function listSubpaths(inputPath: string, _options?: Options, _context?: Context): Promise<string[]>;
24
+ export {};
@@ -0,0 +1 @@
1
+ import{promises as h}from"node:fs";import m from"node:path";var k={directories:!0,files:!0,symlinks:!0,hidden:!0,followSimlinks:!1,dedupeSimlinksContents:!1,maxDepth:1/0,filter:()=>!0},C=i=>({...k,...i}),x={depth:0,lstats:null},D=i=>({...x,...i});async function d(i,y={},b={}){let t=C(y),l=D(b),s=[];if(l.depth>t.maxDepth||!(l.lstats??await h.lstat(i)).isDirectory())return s;let w=await h.readdir(i);return await Promise.all(w.map(async S=>{let e=m.join(i,S),a=await h.lstat(e);try{let o=a.isDirectory(),n=a.isSymbolicLink(),p=!o&&!n,u=m.basename(e).startsWith("."),r;if(o?r="directory":n?r="symlink":r="file",o&&t.directories===!1)throw!0;if(n&&t.symlinks===!1||p&&t.files===!1||u&&t.hidden===!1)throw!1;let f=n?await h.realpath(e):e;if(!await t.filter(e,{type:r,hidden:u,realPath:f}))throw!0;if(n)if(t.followSimlinks===!1)s.push(e);else{let c=await d(f,t,{depth:l.depth+1});s.push(f,...c)}else if(o){let c=await d(e,t,{depth:l.depth+1,lstats:a});s.push(e,...c)}else s.push(e)}catch(o){if(typeof o!="boolean")throw new Error("This try/catch block should only throw booleans");if(!o)return[];let p=await d(e,t,{depth:l.depth+1,lstats:a});s.push(...p)}})),t.dedupeSimlinksContents?Array.from(new Set(s)):s}export{d as default};