Socket
Socket
Sign inDemoInstall

dree

Package Overview
Dependencies
Maintainers
0
Versions
132
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dree - npm Package Compare versions

Comparing version 5.0.9 to 5.1.0

2

bundled/bin/index.js
#!/usr/bin/env node
import b from"yargs";import{hideBin as m}from"yargs/helpers";import{writeFileSync as u}from"node:fs";import*as s from"../lib/esm/index.esm.js";import{PostSortMethodPredefined as h,SortMethodPredefined as c}from"../lib/esm/index.esm.js";function y(t){return t.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function a(t){let e=/^\/(?<pattern>.*)\/(?<flags>[igm]*)?$/;return t?t.map(n=>{let o=n.match(e);return o?new RegExp(y(o.groups.pattern),o.groups.flags):n}):[]}function p(t){if(t)switch(t){case"ascending":return c.ALPHABETICAL;case"descending":return c.ALPHABETICAL_REVERSE;default:return t}}function g(t){if(t)switch(t){case"ascending":return h.ALPHABETICAL;case"descending":return h.ALPHABETICAL_REVERSE;default:return t}}async function w(){await b(m(process.argv)).scriptName("dree").version("5.0.9").command("parse <source>","Save the directory tree as a text file",t=>{t.positional("source",{describe:"The path of the root of the directory tree",type:"string"})},t=>{let e=t,n={symbolicLinks:e.symbolicLinks,followLinks:e.followLinks,showHidden:e.showHidden,depth:e.depth,exclude:a(e.exclude),extensions:e.extensions,sorted:p(e.sorted),homeShortcut:e.homeShortcut,skipErrors:e.skipErrors},o=e.source,r=e.dest,i=!e.dest||e.show,d=s.parse(o,n);i&&console.log(d),r&&u(r,d)}).command("scan <source>","Save the directory tree as a json file",t=>{t.positional("source",{describe:"The path of the root of the directory tree",type:"string"}).options({tabs:{describe:"How many tabs will be used to indent the resulted json",type:"number",default:0},pretty:{describe:"If the resulted json will be pretty printed with 4 tabs. Overwrites the tabs option",type:"boolean",default:!1}})},t=>{let e=t,n={stat:e.stat,normalize:e.normalize,symbolicLinks:e.symbolicLinks,followLinks:e.followLinks,sizeInBytes:e.sizeInBytes,size:e.size,hash:e.hash,hashAlgorithm:e.hashAlgorithm,hashEncoding:e.hashEncoding,showHidden:e.showHidden,depth:e.depth,exclude:a(e.exclude),matches:a(e.matches),emptyDirectory:e.emptyDirectory,excludeEmptyDirectories:e.excludeEmptyDirectories,descendants:e.descendants,descendantsIgnoreDirectories:e.descendantsIgnoreDirectories,extensions:e.extensions,sorted:p(e.sorted),postSorted:g(e.postSorted),homeShortcut:e.homeShortcut,skipErrors:e.skipErrors},o=e.source,r=e.dest,i=!e.dest||e.show,f=e.pretty?4:e.tabs,l=JSON.stringify(s.scan(o,n),null,f);i&&console.log(l),r&&u(r,l)}).options({dest:{alias:"d",describe:"The path of the output file destination. If not specified, in any case the result will be printed on the command line.",type:"string"},show:{alias:"s",default:!1,describe:"Whether you want to print the result on the command line. This will be ignored and set to true if no destination is specified.",type:"boolean"},stat:{default:!1,describe:"Whether you want the fs.stat included in the json result",type:"boolean",hidden:!0},normalize:{default:!1,describe:"Whether you want to normalize the path in the json result",type:"boolean",hidden:!0},"symbolic-links":{default:!0,describe:"Whether you want to consider symbolic links during the elaboration, could not work on windows",type:"boolean",hidden:!0},"follow-links":{default:!1,describe:"Whether you want to follow symbolic links during the elaboration, could not work on windows",type:"boolean",hidden:!0},"size-in-bytes":{default:!0,describe:"Whether you want to include the size in bytes in the json result",type:"boolean",hidden:!0},size:{default:!0,describe:"Whether you want to include the size in a proper unit in the json result",type:"boolean",hidden:!0},hash:{default:!0,describe:"Whether you want to include the hash in the json result",type:"boolean",hidden:!0},"hash-algorithm":{default:"md5",describe:"The hash algorithm that you want to use for the hash in the json result",type:"string",choices:["md5","sha1"],hidden:!0},"hash-encoding":{default:"hex",describe:"The hash encoding that you want to use for the hash in the json result",type:"string",choiches:["hex","base64","latin1"],hidden:!0},"show-hidden":{default:!0,describe:"Whether you want to consider hidden files during the elaboration",type:"boolean",hidden:!0},depth:{default:void 0,describe:"The max depth wich could be reached during the elaboration from the given folder",type:"number",hidden:!0},exclude:{describe:"An array of strings (glob patterns) or regex (just write them as you would with js, e.g. /^[a-b]*$/g) whose all matched path will not be considered during the elaboration",type:"array",hidden:!0},matches:{describe:"An array of strings (glob patterns) or regex (just write them as you would with js, e.g. /^[a-b]*$/g) and all the non-matching paths will not be considered by the algorithm. Note: All the ancestors of a matching node will be added",type:"array",hidden:!0},extensions:{describe:"An array of strings containing all the extensions wich will be considered",type:"array",hidden:!0},"empty-directory":{default:!1,describe:"Whether you want to include the property isEmpty in the result",type:"boolean",hidden:!0},"exclude-empty-directories":{default:!1,describe:"Whether you want to exclude all the empty directories from the result, even if they contains nodes excluded by other options",type:"boolean",hidden:!0},sorted:{default:void 0,describe:"Whether you want the result to contain values sorted with a dree pre-defined sorting method. 'ascending' or 'descending' are kept for retrocompatibility. The sort is done before the scanning for the scan command. If not specified, the result values are not ordered.",type:"string",choices:[...Object.values(c),"ascending","descending"],hidden:!0},postSorted:{default:void 0,describe:"Whether you want the result to contain values sorted with a dree pre-defined sorting method. 'ascending' or 'descending' are kept for retrocompatibility. The sort is done after the scanning for the scan command. If not specified, the result values are not ordered.",type:"string",choices:[...Object.values(h),"ascending","descending"],hidden:!0},descendants:{default:!1,describe:"Whether you want the result to contain the number of descendants for each node",type:"boolean",hidden:!0},"descendants-ignore-directories":{default:!1,describe:"Whether you want the result directories to be ignored when calculating the number of descendants",type:"boolean",hidden:!0},"home-shortcut":{default:!1,describe:"Whether you want the unix homedir shortcut ~ to be expanded to the user home directory",type:"boolean",hidden:!0},"skip-errors":{default:!0,describe:"Whether you want to skip folders and files wich give errors during the execution",type:"boolean",hidden:!0},options:{alias:"o",describe:"A path to a json config file. If an option is both on the file and in the command, the command one will be considered",config:!0}}).showHidden("all-options").completion("completion","Creates the completion bash script to add o your .bashrc in order to have the tab autocompletion for this cli service").demandCommand(1,"You must specify a command").strict().epilogue("For more information, find our manual at https://github.com/euberdeveloper/dree#readme").argv}w();
import b from"yargs";import{hideBin as m}from"yargs/helpers";import{writeFileSync as u}from"node:fs";import*as o from"../lib/esm/index.esm.js";import{PostSortMethodPredefined as h,SortMethodPredefined as c}from"../lib/esm/index.esm.js";function y(t){return t.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function a(t){let e=/^\/(?<pattern>.*)\/(?<flags>[igm]*)?$/;return t?t.map(r=>{let n=r.match(e);return n?new RegExp(y(n.groups.pattern),n.groups.flags):r}):[]}function p(t){if(t)switch(t){case"ascending":return c.ALPHABETICAL;case"descending":return c.ALPHABETICAL_REVERSE;default:return t}}function g(t){if(t)switch(t){case"ascending":return h.ALPHABETICAL;case"descending":return h.ALPHABETICAL_REVERSE;default:return t}}async function w(){await b(m(process.argv)).scriptName("dree").version("5.1.0").command("parse <source>","Save the directory tree as a text file",t=>{t.positional("source",{describe:"The path of the root of the directory tree",type:"string"}).options({ascii:{default:!1,describe:"Whether you want the result to be in ascii format",type:"boolean",hidden:!0}})},t=>{let e=t,r={symbolicLinks:e.symbolicLinks,followLinks:e.followLinks,showHidden:e.showHidden,depth:e.depth,exclude:a(e.exclude),extensions:e.extensions,sorted:p(e.sorted),homeShortcut:e.homeShortcut,symbols:e.ascii?o.ASCII_SYMBOLS:o.DEFAULT_SYMBOLS,skipErrors:e.skipErrors},n=e.source,s=e.dest,i=!e.dest||e.show,d=o.parse(n,r);i&&console.log(d),s&&u(s,d)}).command("scan <source>","Save the directory tree as a json file",t=>{t.positional("source",{describe:"The path of the root of the directory tree",type:"string"}).options({tabs:{describe:"How many tabs will be used to indent the resulted json",type:"number",default:0},pretty:{describe:"If the resulted json will be pretty printed with 4 tabs. Overwrites the tabs option",type:"boolean",default:!1}})},t=>{let e=t,r={stat:e.stat,normalize:e.normalize,symbolicLinks:e.symbolicLinks,followLinks:e.followLinks,sizeInBytes:e.sizeInBytes,size:e.size,hash:e.hash,hashAlgorithm:e.hashAlgorithm,hashEncoding:e.hashEncoding,showHidden:e.showHidden,depth:e.depth,exclude:a(e.exclude),matches:a(e.matches),emptyDirectory:e.emptyDirectory,excludeEmptyDirectories:e.excludeEmptyDirectories,descendants:e.descendants,descendantsIgnoreDirectories:e.descendantsIgnoreDirectories,extensions:e.extensions,sorted:p(e.sorted),postSorted:g(e.postSorted),homeShortcut:e.homeShortcut,skipErrors:e.skipErrors},n=e.source,s=e.dest,i=!e.dest||e.show,f=e.pretty?4:e.tabs,l=JSON.stringify(o.scan(n,r),null,f);i&&console.log(l),s&&u(s,l)}).options({dest:{alias:"d",describe:"The path of the output file destination. If not specified, in any case the result will be printed on the command line.",type:"string"},show:{alias:"s",default:!1,describe:"Whether you want to print the result on the command line. This will be ignored and set to true if no destination is specified.",type:"boolean"},stat:{default:!1,describe:"Whether you want the fs.stat included in the json result",type:"boolean",hidden:!0},normalize:{default:!1,describe:"Whether you want to normalize the path in the json result",type:"boolean",hidden:!0},"symbolic-links":{default:!0,describe:"Whether you want to consider symbolic links during the elaboration, could not work on windows",type:"boolean",hidden:!0},"follow-links":{default:!1,describe:"Whether you want to follow symbolic links during the elaboration, could not work on windows",type:"boolean",hidden:!0},"size-in-bytes":{default:!0,describe:"Whether you want to include the size in bytes in the json result",type:"boolean",hidden:!0},size:{default:!0,describe:"Whether you want to include the size in a proper unit in the json result",type:"boolean",hidden:!0},hash:{default:!0,describe:"Whether you want to include the hash in the json result",type:"boolean",hidden:!0},"hash-algorithm":{default:"md5",describe:"The hash algorithm that you want to use for the hash in the json result",type:"string",choices:["md5","sha1"],hidden:!0},"hash-encoding":{default:"hex",describe:"The hash encoding that you want to use for the hash in the json result",type:"string",choiches:["hex","base64","latin1"],hidden:!0},"show-hidden":{default:!0,describe:"Whether you want to consider hidden files during the elaboration",type:"boolean",hidden:!0},depth:{default:void 0,describe:"The max depth wich could be reached during the elaboration from the given folder",type:"number",hidden:!0},exclude:{describe:"An array of strings (glob patterns) or regex (just write them as you would with js, e.g. /^[a-b]*$/g) whose all matched path will not be considered during the elaboration",type:"array",hidden:!0},matches:{describe:"An array of strings (glob patterns) or regex (just write them as you would with js, e.g. /^[a-b]*$/g) and all the non-matching paths will not be considered by the algorithm. Note: All the ancestors of a matching node will be added",type:"array",hidden:!0},extensions:{describe:"An array of strings containing all the extensions wich will be considered",type:"array",hidden:!0},"empty-directory":{default:!1,describe:"Whether you want to include the property isEmpty in the result",type:"boolean",hidden:!0},"exclude-empty-directories":{default:!1,describe:"Whether you want to exclude all the empty directories from the result, even if they contains nodes excluded by other options",type:"boolean",hidden:!0},sorted:{default:void 0,describe:"Whether you want the result to contain values sorted with a dree pre-defined sorting method. 'ascending' or 'descending' are kept for retrocompatibility. The sort is done before the scanning for the scan command. If not specified, the result values are not ordered.",type:"string",choices:[...Object.values(c),"ascending","descending"],hidden:!0},postSorted:{default:void 0,describe:"Whether you want the result to contain values sorted with a dree pre-defined sorting method. 'ascending' or 'descending' are kept for retrocompatibility. The sort is done after the scanning for the scan command. If not specified, the result values are not ordered.",type:"string",choices:[...Object.values(h),"ascending","descending"],hidden:!0},descendants:{default:!1,describe:"Whether you want the result to contain the number of descendants for each node",type:"boolean",hidden:!0},"descendants-ignore-directories":{default:!1,describe:"Whether you want the result directories to be ignored when calculating the number of descendants",type:"boolean",hidden:!0},"home-shortcut":{default:!1,describe:"Whether you want the unix homedir shortcut ~ to be expanded to the user home directory",type:"boolean",hidden:!0},"skip-errors":{default:!0,describe:"Whether you want to skip folders and files wich give errors during the execution",type:"boolean",hidden:!0},options:{alias:"o",describe:"A path to a json config file. If an option is both on the file and in the command, the command one will be considered",config:!0}}).showHidden("all-options").completion("completion","Creates the completion bash script to add o your .bashrc in order to have the tab autocompletion for this cli service").demandCommand(1,"You must specify a command").strict().epilogue("For more information, find our manual at https://github.com/euberdeveloper/dree#readme").argv}w();

@@ -228,2 +228,15 @@ // Generated by dts-bundle-generator v9.5.1

/**
* Interface of the symbols used to represent the tree in a string.
* See [[DEFAULT_SYMBOLS]] for an example with the default values
*/
export interface TreeSymbols {
dirChild: string;
fileChild: string;
forkChild: string;
lastChild: string;
linkChild: string;
tabIndent: string;
pipeIndent: string;
}
/**
* Interface of the options object used with "parse" or "parseTree" functions

@@ -275,2 +288,6 @@ */

/**
* Symbols used to represent the tree in a string
*/
symbols?: TreeSymbols;
/**
* If true, folders whose user has not permissions will be skipped. An error will be thrown otherwise. Note: in fact every

@@ -282,2 +299,11 @@ * error thrown by fs calls will be ignored

/**
* The default symbols used to represent the tree in a string
*/
export declare const DEFAULT_SYMBOLS: TreeSymbols;
/**
* The ascii symbols used to represent the tree in a string.
* Note: Inspiration was taken from the bash command: `tree --charset=ascii`
*/
export declare const ASCII_SYMBOLS: TreeSymbols;
/**
* Returns the Directory Tree of a given path. This function in synchronous.

@@ -284,0 +310,0 @@ * @param {string} path The path which you want to inspect

@@ -1,5 +0,5 @@

var p=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var Z=Object.prototype.hasOwnProperty;var ee=(r,t)=>{for(var n in t)p(r,n,{get:t[n],enumerable:!0})},te=(r,t,n,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of X(t))!Z.call(r,s)&&s!==n&&p(r,s,{get:()=>t[s],enumerable:!(e=W(t,s))||e.enumerable});return r};var re=r=>te(p({},"__esModule",{value:!0}),r);var de={};ee(de,{PostSortMethodPredefined:()=>Y,SortMethodPredefined:()=>H,Type:()=>_,parse:()=>le,parseAsync:()=>ce,parseTree:()=>ue,parseTreeAsync:()=>oe,scan:()=>ie,scanAsync:()=>ae});module.exports=re(de);var m=require("node:path"),v=require("node:os"),N=require("node:crypto"),x=require("node:fs"),L=require("node:fs/promises"),F=require("minimatch"),_=(n=>(n.DIRECTORY="directory",n.FILE="file",n))(_||{}),H=(s=>(s.ALPHABETICAL="alpha",s.ALPHABETICAL_REVERSE="antialpha",s.ALPHABETICAL_INSENSITIVE="alpha-insensitive",s.ALPHABETICAL_INSENSITIVE_REVERSE="antialpha-insensitive",s))(H||{}),Y=(l=>(l.ALPHABETICAL="alpha",l.ALPHABETICAL_REVERSE="antialpha",l.ALPHABETICAL_INSENSITIVE="alpha-insensitive",l.ALPHABETICAL_INSENSITIVE_REVERSE="antialpha-insensitive",l.FOLDERS_FIRST="folders-first",l.FILES_FIRST="files-first",l))(Y||{}),C={stat:!1,normalize:!1,symbolicLinks:!0,followLinks:!1,sizeInBytes:!0,size:!0,hash:!0,hashAlgorithm:"md5",hashEncoding:"hex",showHidden:!0,depth:void 0,exclude:void 0,matches:void 0,extensions:void 0,emptyDirectory:!1,excludeEmptyDirectories:!1,descendants:!1,descendantsIgnoreDirectories:!1,sorted:!1,postSorted:!1,homeShortcut:!1,skipErrors:!0},B={symbolicLinks:!0,followLinks:!1,showHidden:!0,depth:void 0,exclude:void 0,extensions:void 0,sorted:!1,postSorted:!1,homeShortcut:!1,skipErrors:!0};function w(r,t){return(0,m.resolve)(t.homeShortcut?r.replace(/^~($|\/|\\)/,(0,v.homedir)()+"$1"):r)}function b(r){return(Array.isArray(r)?r:[r]).map(t=>t instanceof RegExp?t:(0,F.makeRe)(t,{dot:!0})).filter(t=>t instanceof RegExp)}function V(r){let t={};if(r){for(let n in C)t[n]=r[n]!==void 0?r[n]:C[n];t.depth<0&&(t.depth=0)}else t=C;return t}function D(r){let t={};if(r){for(let n in B)t[n]=r[n]!==void 0?r[n]:B[n];t.depth<0&&(t.depth=0)}else t=B;return t}function R(r){let t=["B","KB","MB","GB","TB"],n;for(n=0;n<t.length&&r>1e3;n++)r/=1e3;return Math.round(r*100)/100+" "+t[n]}function A(r,t){return r.localeCompare(t)}function P(r,t){return r.toLowerCase().localeCompare(t.toLowerCase())}function k(r,t){if(!t)return r;if(t===!0)return r.sort(A);if(typeof t=="string")switch(t){case"alpha":return r.sort(A);case"antialpha":return r.sort(A).reverse();case"alpha-insensitive":return r.sort(P);case"antialpha-insensitive":return r.sort(P).reverse();default:return r}else if(typeof t=="function")return r.sort(t)}function z(r,t){return A(r.name,t.name)}function O(r,t){return P(r.name,t.name)}function ne(r,t){return r.type==="directory"&&t.type==="file"?-1:r.type==="file"&&t.type==="directory"?1:0}function se(r,t){return r.type==="file"&&t.type==="directory"?-1:r.type==="directory"&&t.type==="file"?1:0}function M(r,t){if(!t)return r;if(t===!0)return r.sort(z);if(typeof t=="string")switch(t){case"alpha":return r.sort(z);case"antialpha":return r.sort(z).reverse();case"alpha-insensitive":return r.sort(O);case"antialpha-insensitive":return r.sort(O).reverse();case"folders-first":return r.sort(ne);case"files-first":return r.sort(se);default:return r}else if(typeof t=="function")return r.sort(t)}function $(r,t){if(!t)return r;if(t===!0)return r.sort((n,e)=>A(n.relativePath,e.relativePath));if(typeof t=="string")switch(t){case"alpha":return r.sort((n,e)=>A(n.relativePath,e.relativePath));case"antialpha":return r.sort((n,e)=>A(n.relativePath,e.relativePath)).reverse();case"alpha-insensitive":return r.sort((n,e)=>P(n.relativePath,e.relativePath));case"antialpha-insensitive":return r.sort((n,e)=>P(n.relativePath,e.relativePath)).reverse();default:return r}else if(typeof t=="function")return r.sort((n,e)=>t(n.relativePath,e.relativePath))}function q(r,t,n,e,s,d){if(e.depth!==void 0&&n>e.depth)return null;let l=r===t?".":(0,m.relative)(r,t);if(e.exclude&&r!==t&&b(e.exclude).some(I=>I.test(`/${l}`)))return null;let i=(0,m.basename)(t),h;try{h=(0,x.statSync)(t)}catch(c){if(e.skipErrors)return null;throw c}let a;try{a=(0,x.lstatSync)(t)}catch(c){if(e.skipErrors)return null;throw c}let E=a.isSymbolicLink(),S=h.isFile()?"file":"directory";if(!e.showHidden&&i.charAt(0)==="."||!e.symbolicLinks&&E)return null;let g;if(e.hash){let c=e.hashAlgorithm;g=(0,N.createHash)(c),g.update(i)}let o={name:i,path:e.normalize?t.replace(/\\/g,"/"):t,relativePath:e.normalize?l.replace(/\\/g,"/"):l,type:S,isSymbolicLink:E,stat:e.followLinks?h:a};switch(e.stat||delete o.stat,S){case"directory":let c=[],I;if(e.followLinks||!E){try{I=(0,x.readdirSync)(t),I=k(I,e.sorted)}catch(u){if(e.skipErrors)return null;throw u}if(e.emptyDirectory&&(o.isEmpty=!I.length),I.forEach(u=>{let f=q(r,(0,m.resolve)(t,u),n+1,e,s,d);f!==null&&c.push(f)}),e.excludeEmptyDirectories&&!c.length)return null}if(e.matches&&r!==t){let u=b(e.matches);if(!c.length&&u.some(f=>!f.test(`/${l}`)))return null}if(e.sizeInBytes||e.size){let u=c.reduce((f,y)=>f+y.sizeInBytes,0);o.sizeInBytes=u,o.size=e.size?R(u):void 0,e.sizeInBytes||c.forEach(f=>f.sizeInBytes=void 0)}if(e.hash){c.forEach(f=>{g.update(f.hash)});let u=e.hashEncoding;o.hash=g.digest(u)}e.descendants&&(o.descendants=c.reduce((u,f)=>u+(f.type==="directory"&&e.descendantsIgnoreDirectories?0:1)+(f.descendants??0),0)),c.length&&(o.children=e.postSorted?M(c,e.postSorted):c);break;case"file":if(o.extension=(0,m.extname)(t).replace(".",""),e.extensions&&e.extensions.indexOf(o.extension)===-1||e.matches&&r!==t&&b(e.matches).some(f=>!f.test(`/${l}`)))return null;if(e.sizeInBytes||e.size){let u=e.followLinks?h.size:a.size;o.sizeInBytes=u,o.size=e.size?R(u):void 0}if(e.hash){let u;try{u=(0,x.readFileSync)(t)}catch(y){if(e.skipErrors)return null;throw y}g.update(u);let f=e.hashEncoding;o.hash=g.digest(f)}break;default:return null}return s&&S==="file"?s(o,e.followLinks?h:a):d&&S==="directory"&&d(o,e.followLinks?h:a),o}async function U(r,t,n,e,s,d){if(e.depth!==void 0&&n>e.depth)return null;let l=r===t?".":(0,m.relative)(r,t);if(e.exclude&&r!==t&&b(e.exclude).some(I=>I.test(`/${l}`)))return null;let i=(0,m.basename)(t),h;try{h=await(0,L.stat)(t)}catch(c){if(e.skipErrors)return null;throw c}let a;try{a=await(0,L.lstat)(t)}catch(c){if(e.skipErrors)return null;throw c}let E=a.isSymbolicLink(),S=h.isFile()?"file":"directory";if(!e.showHidden&&i.charAt(0)==="."||!e.symbolicLinks&&E)return null;let g;if(e.hash){let c=e.hashAlgorithm;g=(0,N.createHash)(c),g.update(i)}let o={name:i,path:e.normalize?t.replace(/\\/g,"/"):t,relativePath:e.normalize?l.replace(/\\/g,"/"):l,type:S,isSymbolicLink:E,stat:e.followLinks?h:a};switch(e.stat||delete o.stat,S){case"directory":let c=[],I;if(e.followLinks||!E){try{I=await(0,L.readdir)(t),I=k(I,e.sorted)}catch(u){if(e.skipErrors)return null;throw u}if(e.emptyDirectory&&(o.isEmpty=!I.length),c=await Promise.all(I.map(async u=>await U(r,(0,m.resolve)(t,u),n+1,e,s,d))),c=c.filter(u=>u!==null),e.excludeEmptyDirectories&&!c.length)return null}if(e.matches&&r!==t){let u=b(e.matches);if(!c.length&&u.some(f=>!f.test(`/${l}`)))return null}if(e.sizeInBytes||e.size){let u=c.reduce((f,y)=>f+y.sizeInBytes,0);o.sizeInBytes=u,o.size=e.size?R(u):void 0,e.sizeInBytes||c.forEach(f=>f.sizeInBytes=void 0)}if(e.hash){c.forEach(f=>{g.update(f.hash)});let u=e.hashEncoding;o.hash=g.digest(u)}e.descendants&&(o.descendants=c.reduce((u,f)=>u+(f.type==="directory"&&e.descendantsIgnoreDirectories?0:1)+(f.descendants??0),0)),c.length&&(o.children=e.postSorted?M(c,e.postSorted):c);break;case"file":if(o.extension=(0,m.extname)(t).replace(".",""),e.extensions&&e.extensions.indexOf(o.extension)===-1||e.matches&&r!==t&&b(e.matches).some(f=>!f.test(`/${l}`)))return null;if(e.sizeInBytes||e.size){let u=e.followLinks?h.size:a.size;o.sizeInBytes=u,o.size=e.size?R(u):void 0}if(e.hash){let u;try{u=await(0,L.readFile)(t)}catch(y){if(e.skipErrors)return null;throw y}g.update(u);let f=e.hashEncoding;o.hash=g.digest(f)}break;default:return null}return s&&S==="file"?await s(o,e.followLinks?h:a):d&&S==="directory"&&await d(o,e.followLinks?h:a),o}function G(r,t,n){return!t.symbolicLinks&&r.isSymbolicLink||!t.showHidden&&r.name.charAt(0)==="."||t.extensions!==void 0&&r.type==="file"&&t.extensions.indexOf(r.extension)===-1||t.exclude&&b(t.exclude).some(e=>e.test(`/${r.relativePath}`))||t.depth!==void 0&&n>t.depth}function K(r,t,n,e,s){let d="";return t.map((i,h)=>{let a="";if(e.depth!==void 0&&s>e.depth||e.exclude&&b(e.exclude).some(T=>T.test(`/${(0,m.relative)(r,i)}`)))return"";let E=(0,m.basename)(i),S;try{S=(0,x.statSync)(i)}catch(y){if(e.skipErrors)return null;throw y}let g;try{g=(0,x.lstatSync)(i)}catch(y){if(e.skipErrors)return null;throw y}let o=g.isSymbolicLink(),c=S.isFile()?"file":"directory";if(!e.showHidden&&E.charAt(0)==="."||!e.symbolicLinks&&o)return"";let I=(0,m.extname)(i).replace(".","");if(e.extensions&&c==="file"&&e.extensions.indexOf(I)===-1)return"";let u=o?">>":c==="directory"?"\u2500> ":"\u2500\u2500 ",f=n+(h===t.length-1?" ":"\u2502 ");if(a+=u+E,(e.followLinks||!o)&&c==="directory"){let y;try{y=(0,x.readdirSync)(i).map(T=>(0,m.resolve)(i,T)),y=k(y,e.sorted)}catch(T){if(e.skipErrors)return null;throw T}a+=y.length?K(r,y,f,e,s+1):""}return a}).filter(i=>!!i).forEach((i,h,a)=>{d+=n+(h===a.length-1?"\u2514"+i:"\u251C"+i)}),d}async function j(r,t,n,e,s){let d="";return(await Promise.all(t.map(async(i,h)=>{let a="";if(e.depth!==void 0&&s>e.depth||e.exclude&&b(e.exclude).some(T=>T.test(`/${(0,m.relative)(r,i)}`)))return"";let E=(0,m.basename)(i),S;try{S=await(0,L.stat)(i)}catch(y){if(e.skipErrors)return null;throw y}let g;try{g=await(0,L.lstat)(i)}catch(y){if(e.skipErrors)return null;throw y}let o=g.isSymbolicLink(),c=S.isFile()?"file":"directory";if(!e.showHidden&&E.charAt(0)==="."||!e.symbolicLinks&&o)return"";let I=(0,m.extname)(i).replace(".","");if(e.extensions&&c==="file"&&e.extensions.indexOf(I)===-1)return"";let u=o?">>":c==="directory"?"\u2500> ":"\u2500\u2500 ",f=n+(h===t.length-1?" ":"\u2502 ");if(a+=u+E,(e.followLinks||!o)&&c==="directory"){let y;try{y=(await(0,L.readdir)(i)).map(T=>(0,m.resolve)(i,T)),y=k(y,e.sorted)}catch(T){if(e.skipErrors)return null;throw T}a+=y.length?await j(r,y,f,e,s+1):""}return a}))).filter(i=>!!i).forEach((i,h,a)=>{d+=n+(h===a.length-1?"\u2514"+i:"\u251C"+i)}),d}function J(r,t,n,e){let s="";return r=$(r,n.sorted),r.filter(d=>!G(d,n,e)).forEach((d,l,i)=>{let h=d.isSymbolicLink?">>":d.type==="directory"?"\u2500> ":"\u2500\u2500 ",a=l===i.length-1?"\u2514"+h:"\u251C"+h,E=t+(l===i.length-1?" ":"\u2502 ");s+=t+a+d.name,s+=d.children&&(n.followLinks||!d.isSymbolicLink)?J(d.children,E,n,e+1):""}),s}async function Q(r,t,n,e){let s="";r=$(r,n.sorted);let d=r.filter(l=>!G(l,n,e));for(let l=0;l<d.length;l++){let i=d[l],h=i.isSymbolicLink?">>":i.type==="directory"?"\u2500> ":"\u2500\u2500 ",a=l===d.length-1?"\u2514"+h:"\u251C"+h,E=t+(l===d.length-1?" ":"\u2502 ");s+=t+a+i.name,s+=i.children&&(n.followLinks||!i.isSymbolicLink)?await Q(i.children,E,n,e+1):""}return s}function ie(r,t,n,e){let s=V(t),d=w(r,s),l=q(d,d,0,s,n,e);return l&&(l.sizeInBytes=s.sizeInBytes?l.sizeInBytes:void 0),l}async function ae(r,t,n,e){let s=V(t),d=w(r,s),l=await U(d,d,0,s,n,e);return l&&(l.sizeInBytes=s.sizeInBytes?l.sizeInBytes:void 0),l}function le(r,t){let n="",e=D(t),s=w(r,e),d=(0,m.basename)(s);n+=d;let l;try{l=(0,x.statSync)(s)}catch(a){if(e.skipErrors)return null;throw a}let i;try{i=(0,x.lstatSync)(s)}catch(a){if(e.skipErrors)return null;throw a}let h=i.isSymbolicLink();if((e.followLinks||!h)&&l.isDirectory()){let a;try{a=(0,x.readdirSync)(s).map(E=>(0,m.resolve)(s,E)),a=k(a,e.sorted)}catch(E){if(e.skipErrors)return null;throw E}n+=a.length?K(s,a,`
`,e,1):""}return n}async function ce(r,t){let n="",e=D(t),s=w(r,e),d=(0,m.basename)(s);n+=d;let l;try{l=await(0,L.stat)(s)}catch(a){if(e.skipErrors)return null;throw a}let i;try{i=await(0,L.lstat)(s)}catch(a){if(e.skipErrors)return null;throw a}let h=i.isSymbolicLink();if((e.followLinks||!h)&&l.isDirectory()){let a;try{a=(await(0,L.readdir)(s)).map(E=>(0,m.resolve)(s,E)),a=k(a,e.sorted)}catch(E){if(e.skipErrors)return null;throw E}n+=a.length?await j(s,a,`
`,e,1):""}return n}function ue(r,t){let n="",e=D(t);return n+=r?r.name:"",n+=r.children?J(r.children,`
`,e,1):"",n}async function oe(r,t){let n="",e=D(t);return n+=r?r.name:"",n+=r.children?await Q(r.children,`
`,e,1):"",n}0&&(module.exports={PostSortMethodPredefined,SortMethodPredefined,Type,parse,parseAsync,parseTree,parseTreeAsync,scan,scanAsync});
var D=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var ee=Object.prototype.hasOwnProperty;var te=(r,t)=>{for(var n in t)D(r,n,{get:t[n],enumerable:!0})},re=(r,t,n,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Z(t))!ee.call(r,s)&&s!==n&&D(r,s,{get:()=>t[s],enumerable:!(e=X(t,s))||e.enumerable});return r};var ne=r=>re(D({},"__esModule",{value:!0}),r);var he={};te(he,{ASCII_SYMBOLS:()=>se,DEFAULT_SYMBOLS:()=>M,PostSortMethodPredefined:()=>Y,SortMethodPredefined:()=>H,Type:()=>_,parse:()=>de,parseAsync:()=>ue,parseTree:()=>oe,parseTreeAsync:()=>fe,scan:()=>ae,scanAsync:()=>ce});module.exports=ne(he);var E=require("node:path"),v=require("node:os"),O=require("node:crypto"),S=require("node:fs"),x=require("node:fs/promises"),F=require("minimatch"),_=(n=>(n.DIRECTORY="directory",n.FILE="file",n))(_||{}),H=(s=>(s.ALPHABETICAL="alpha",s.ALPHABETICAL_REVERSE="antialpha",s.ALPHABETICAL_INSENSITIVE="alpha-insensitive",s.ALPHABETICAL_INSENSITIVE_REVERSE="antialpha-insensitive",s))(H||{}),Y=(a=>(a.ALPHABETICAL="alpha",a.ALPHABETICAL_REVERSE="antialpha",a.ALPHABETICAL_INSENSITIVE="alpha-insensitive",a.ALPHABETICAL_INSENSITIVE_REVERSE="antialpha-insensitive",a.FOLDERS_FIRST="folders-first",a.FILES_FIRST="files-first",a))(Y||{}),p={stat:!1,normalize:!1,symbolicLinks:!0,followLinks:!1,sizeInBytes:!0,size:!0,hash:!0,hashAlgorithm:"md5",hashEncoding:"hex",showHidden:!0,depth:void 0,exclude:void 0,matches:void 0,extensions:void 0,emptyDirectory:!1,excludeEmptyDirectories:!1,descendants:!1,descendantsIgnoreDirectories:!1,sorted:!1,postSorted:!1,homeShortcut:!1,skipErrors:!0},M={dirChild:"\u2500> ",fileChild:"\u2500\u2500 ",forkChild:"\u251C",lastChild:"\u2514",linkChild:">>",tabIndent:" ",pipeIndent:"\u2502 "},se={dirChild:"-\\ ",fileChild:"-- ",forkChild:"|",lastChild:"`",linkChild:"->",tabIndent:" ",pipeIndent:"| "},B={symbolicLinks:!0,followLinks:!1,showHidden:!0,depth:void 0,exclude:void 0,extensions:void 0,sorted:!1,postSorted:!1,homeShortcut:!1,symbols:M,skipErrors:!0};function R(r,t){return(0,E.resolve)(t.homeShortcut?r.replace(/^~($|\/|\\)/,(0,v.homedir)()+"$1"):r)}function T(r){return(Array.isArray(r)?r:[r]).map(t=>t instanceof RegExp?t:(0,F.makeRe)(t,{dot:!0})).filter(t=>t instanceof RegExp)}function V(r){let t={};if(r){for(let n in p)t[n]=r[n]!==void 0?r[n]:p[n];t.depth<0&&(t.depth=0)}else t=p;return t}function w(r){let t={};if(r){for(let n in B)t[n]=r[n]!==void 0?r[n]:B[n];t.depth<0&&(t.depth=0)}else t=B;return t}function P(r){let t=["B","KB","MB","GB","TB"],n;for(n=0;n<t.length&&r>1e3;n++)r/=1e3;return Math.round(r*100)/100+" "+t[n]}function k(r,t){return r.localeCompare(t)}function C(r,t){return r.toLowerCase().localeCompare(t.toLowerCase())}function A(r,t){if(!t)return r;if(t===!0)return r.sort(k);if(typeof t=="string")switch(t){case"alpha":return r.sort(k);case"antialpha":return r.sort(k).reverse();case"alpha-insensitive":return r.sort(C);case"antialpha-insensitive":return r.sort(C).reverse();default:return r}else if(typeof t=="function")return r.sort(t)}function z(r,t){return k(r.name,t.name)}function N(r,t){return C(r.name,t.name)}function ie(r,t){return r.type==="directory"&&t.type==="file"?-1:r.type==="file"&&t.type==="directory"?1:0}function le(r,t){return r.type==="file"&&t.type==="directory"?-1:r.type==="directory"&&t.type==="file"?1:0}function $(r,t){if(!t)return r;if(t===!0)return r.sort(z);if(typeof t=="string")switch(t){case"alpha":return r.sort(z);case"antialpha":return r.sort(z).reverse();case"alpha-insensitive":return r.sort(N);case"antialpha-insensitive":return r.sort(N).reverse();case"folders-first":return r.sort(ie);case"files-first":return r.sort(le);default:return r}else if(typeof t=="function")return r.sort(t)}function U(r,t){if(!t)return r;if(t===!0)return r.sort((n,e)=>k(n.relativePath,e.relativePath));if(typeof t=="string")switch(t){case"alpha":return r.sort((n,e)=>k(n.relativePath,e.relativePath));case"antialpha":return r.sort((n,e)=>k(n.relativePath,e.relativePath)).reverse();case"alpha-insensitive":return r.sort((n,e)=>C(n.relativePath,e.relativePath));case"antialpha-insensitive":return r.sort((n,e)=>C(n.relativePath,e.relativePath)).reverse();default:return r}else if(typeof t=="function")return r.sort((n,e)=>t(n.relativePath,e.relativePath))}function q(r,t,n,e,s,o){if(e.depth!==void 0&&n>e.depth)return null;let a=r===t?".":(0,E.relative)(r,t);if(e.exclude&&r!==t&&T(e.exclude).some(g=>g.test(`/${a}`)))return null;let i=(0,E.basename)(t),h;try{h=(0,S.statSync)(t)}catch(c){if(e.skipErrors)return null;throw c}let l;try{l=(0,S.lstatSync)(t)}catch(c){if(e.skipErrors)return null;throw c}let m=l.isSymbolicLink(),I=h.isFile()?"file":"directory";if(!e.showHidden&&i.charAt(0)==="."||!e.symbolicLinks&&m)return null;let b;if(e.hash){let c=e.hashAlgorithm;b=(0,O.createHash)(c),b.update(i)}let u={name:i,path:e.normalize?t.replace(/\\/g,"/"):t,relativePath:e.normalize?a.replace(/\\/g,"/"):a,type:I,isSymbolicLink:m,stat:e.followLinks?h:l};switch(e.stat||delete u.stat,I){case"directory":let c=[],g;if(e.followLinks||!m){try{g=(0,S.readdirSync)(t),g=A(g,e.sorted)}catch(d){if(e.skipErrors)return null;throw d}if(e.emptyDirectory&&(u.isEmpty=!g.length),g.forEach(d=>{let f=q(r,(0,E.resolve)(t,d),n+1,e,s,o);f!==null&&c.push(f)}),e.excludeEmptyDirectories&&!c.length)return null}if(e.matches&&r!==t){let d=T(e.matches);if(!c.length&&d.some(f=>!f.test(`/${a}`)))return null}if(e.sizeInBytes||e.size){let d=c.reduce((f,y)=>f+y.sizeInBytes,0);u.sizeInBytes=d,u.size=e.size?P(d):void 0,e.sizeInBytes||c.forEach(f=>f.sizeInBytes=void 0)}if(e.hash){c.forEach(f=>{b.update(f.hash)});let d=e.hashEncoding;u.hash=b.digest(d)}e.descendants&&(u.descendants=c.reduce((d,f)=>d+(f.type==="directory"&&e.descendantsIgnoreDirectories?0:1)+(f.descendants??0),0)),c.length&&(u.children=e.postSorted?$(c,e.postSorted):c);break;case"file":if(u.extension=(0,E.extname)(t).replace(".",""),e.extensions&&e.extensions.indexOf(u.extension)===-1||e.matches&&r!==t&&T(e.matches).some(f=>!f.test(`/${a}`)))return null;if(e.sizeInBytes||e.size){let d=e.followLinks?h.size:l.size;u.sizeInBytes=d,u.size=e.size?P(d):void 0}if(e.hash){let d;try{d=(0,S.readFileSync)(t)}catch(y){if(e.skipErrors)return null;throw y}b.update(d);let f=e.hashEncoding;u.hash=b.digest(f)}break;default:return null}return s&&I==="file"?s(u,e.followLinks?h:l):o&&I==="directory"&&o(u,e.followLinks?h:l),u}async function G(r,t,n,e,s,o){if(e.depth!==void 0&&n>e.depth)return null;let a=r===t?".":(0,E.relative)(r,t);if(e.exclude&&r!==t&&T(e.exclude).some(g=>g.test(`/${a}`)))return null;let i=(0,E.basename)(t),h;try{h=await(0,x.stat)(t)}catch(c){if(e.skipErrors)return null;throw c}let l;try{l=await(0,x.lstat)(t)}catch(c){if(e.skipErrors)return null;throw c}let m=l.isSymbolicLink(),I=h.isFile()?"file":"directory";if(!e.showHidden&&i.charAt(0)==="."||!e.symbolicLinks&&m)return null;let b;if(e.hash){let c=e.hashAlgorithm;b=(0,O.createHash)(c),b.update(i)}let u={name:i,path:e.normalize?t.replace(/\\/g,"/"):t,relativePath:e.normalize?a.replace(/\\/g,"/"):a,type:I,isSymbolicLink:m,stat:e.followLinks?h:l};switch(e.stat||delete u.stat,I){case"directory":let c=[],g;if(e.followLinks||!m){try{g=await(0,x.readdir)(t),g=A(g,e.sorted)}catch(d){if(e.skipErrors)return null;throw d}if(e.emptyDirectory&&(u.isEmpty=!g.length),c=await Promise.all(g.map(async d=>await G(r,(0,E.resolve)(t,d),n+1,e,s,o))),c=c.filter(d=>d!==null),e.excludeEmptyDirectories&&!c.length)return null}if(e.matches&&r!==t){let d=T(e.matches);if(!c.length&&d.some(f=>!f.test(`/${a}`)))return null}if(e.sizeInBytes||e.size){let d=c.reduce((f,y)=>f+y.sizeInBytes,0);u.sizeInBytes=d,u.size=e.size?P(d):void 0,e.sizeInBytes||c.forEach(f=>f.sizeInBytes=void 0)}if(e.hash){c.forEach(f=>{b.update(f.hash)});let d=e.hashEncoding;u.hash=b.digest(d)}e.descendants&&(u.descendants=c.reduce((d,f)=>d+(f.type==="directory"&&e.descendantsIgnoreDirectories?0:1)+(f.descendants??0),0)),c.length&&(u.children=e.postSorted?$(c,e.postSorted):c);break;case"file":if(u.extension=(0,E.extname)(t).replace(".",""),e.extensions&&e.extensions.indexOf(u.extension)===-1||e.matches&&r!==t&&T(e.matches).some(f=>!f.test(`/${a}`)))return null;if(e.sizeInBytes||e.size){let d=e.followLinks?h.size:l.size;u.sizeInBytes=d,u.size=e.size?P(d):void 0}if(e.hash){let d;try{d=await(0,x.readFile)(t)}catch(y){if(e.skipErrors)return null;throw y}b.update(d);let f=e.hashEncoding;u.hash=b.digest(f)}break;default:return null}return s&&I==="file"?await s(u,e.followLinks?h:l):o&&I==="directory"&&await o(u,e.followLinks?h:l),u}function K(r,t,n){return!t.symbolicLinks&&r.isSymbolicLink||!t.showHidden&&r.name.charAt(0)==="."||t.extensions!==void 0&&r.type==="file"&&t.extensions.indexOf(r.extension)===-1||t.exclude&&T(t.exclude).some(e=>e.test(`/${r.relativePath}`))||t.depth!==void 0&&n>t.depth}function j(r,t,n,e,s){let o="";return t.map((i,h)=>{let l="";if(e.depth!==void 0&&s>e.depth||e.exclude&&T(e.exclude).some(L=>L.test(`/${(0,E.relative)(r,i)}`)))return"";let m=(0,E.basename)(i),I;try{I=(0,S.statSync)(i)}catch(y){if(e.skipErrors)return null;throw y}let b;try{b=(0,S.lstatSync)(i)}catch(y){if(e.skipErrors)return null;throw y}let u=b.isSymbolicLink(),c=I.isFile()?"file":"directory";if(!e.showHidden&&m.charAt(0)==="."||!e.symbolicLinks&&u)return"";let g=(0,E.extname)(i).replace(".","");if(e.extensions&&c==="file"&&e.extensions.indexOf(g)===-1)return"";let d=u?e.symbols.linkChild:c==="directory"?e.symbols.dirChild:e.symbols.fileChild,f=n+(h===t.length-1?e.symbols.tabIndent:e.symbols.pipeIndent);if(l+=d+m,(e.followLinks||!u)&&c==="directory"){let y;try{y=(0,S.readdirSync)(i).map(L=>(0,E.resolve)(i,L)),y=A(y,e.sorted)}catch(L){if(e.skipErrors)return null;throw L}l+=y.length?j(r,y,f,e,s+1):""}return l}).filter(i=>!!i).forEach((i,h,l)=>{o+=n+(h===l.length-1?e.symbols.lastChild+i:e.symbols.forkChild+i)}),o}async function J(r,t,n,e,s){let o="";return(await Promise.all(t.map(async(i,h)=>{let l="";if(e.depth!==void 0&&s>e.depth||e.exclude&&T(e.exclude).some(L=>L.test(`/${(0,E.relative)(r,i)}`)))return"";let m=(0,E.basename)(i),I;try{I=await(0,x.stat)(i)}catch(y){if(e.skipErrors)return null;throw y}let b;try{b=await(0,x.lstat)(i)}catch(y){if(e.skipErrors)return null;throw y}let u=b.isSymbolicLink(),c=I.isFile()?"file":"directory";if(!e.showHidden&&m.charAt(0)==="."||!e.symbolicLinks&&u)return"";let g=(0,E.extname)(i).replace(".","");if(e.extensions&&c==="file"&&e.extensions.indexOf(g)===-1)return"";let d=u?e.symbols.linkChild:c==="directory"?e.symbols.dirChild:e.symbols.fileChild,f=n+(h===t.length-1?e.symbols.tabIndent:e.symbols.pipeIndent);if(l+=d+m,(e.followLinks||!u)&&c==="directory"){let y;try{y=(await(0,x.readdir)(i)).map(L=>(0,E.resolve)(i,L)),y=A(y,e.sorted)}catch(L){if(e.skipErrors)return null;throw L}l+=y.length?await J(r,y,f,e,s+1):""}return l}))).filter(i=>!!i).forEach((i,h,l)=>{o+=n+(h===l.length-1?e.symbols.lastChild+i:e.symbols.forkChild+i)}),o}function Q(r,t,n,e){let s="";return r=U(r,n.sorted),r.filter(o=>!K(o,n,e)).forEach((o,a,i)=>{let h=o.isSymbolicLink?n.symbols.linkChild:o.type==="directory"?n.symbols.dirChild:n.symbols.fileChild,l=a===i.length-1?n.symbols.lastChild+h:n.symbols.forkChild+h,m=t+(a===i.length-1?n.symbols.tabIndent:n.symbols.pipeIndent);s+=t+l+o.name,s+=o.children&&(n.followLinks||!o.isSymbolicLink)?Q(o.children,m,n,e+1):""}),s}async function W(r,t,n,e){let s="";r=U(r,n.sorted);let o=r.filter(a=>!K(a,n,e));for(let a=0;a<o.length;a++){let i=o[a],h=i.isSymbolicLink?n.symbols.linkChild:i.type==="directory"?n.symbols.dirChild:n.symbols.fileChild,l=a===o.length-1?n.symbols.lastChild+h:n.symbols.forkChild+h,m=t+(a===o.length-1?n.symbols.tabIndent:n.symbols.pipeIndent);s+=t+l+i.name,s+=i.children&&(n.followLinks||!i.isSymbolicLink)?await W(i.children,m,n,e+1):""}return s}function ae(r,t,n,e){let s=V(t),o=R(r,s),a=q(o,o,0,s,n,e);return a&&(a.sizeInBytes=s.sizeInBytes?a.sizeInBytes:void 0),a}async function ce(r,t,n,e){let s=V(t),o=R(r,s),a=await G(o,o,0,s,n,e);return a&&(a.sizeInBytes=s.sizeInBytes?a.sizeInBytes:void 0),a}function de(r,t){let n="",e=w(t),s=R(r,e),o=(0,E.basename)(s);n+=o;let a;try{a=(0,S.statSync)(s)}catch(l){if(e.skipErrors)return null;throw l}let i;try{i=(0,S.lstatSync)(s)}catch(l){if(e.skipErrors)return null;throw l}let h=i.isSymbolicLink();if((e.followLinks||!h)&&a.isDirectory()){let l;try{l=(0,S.readdirSync)(s).map(m=>(0,E.resolve)(s,m)),l=A(l,e.sorted)}catch(m){if(e.skipErrors)return null;throw m}n+=l.length?j(s,l,`
`,e,1):""}return n}async function ue(r,t){let n="",e=w(t),s=R(r,e),o=(0,E.basename)(s);n+=o;let a;try{a=await(0,x.stat)(s)}catch(l){if(e.skipErrors)return null;throw l}let i;try{i=await(0,x.lstat)(s)}catch(l){if(e.skipErrors)return null;throw l}let h=i.isSymbolicLink();if((e.followLinks||!h)&&a.isDirectory()){let l;try{l=(await(0,x.readdir)(s)).map(m=>(0,E.resolve)(s,m)),l=A(l,e.sorted)}catch(m){if(e.skipErrors)return null;throw m}n+=l.length?await J(s,l,`
`,e,1):""}return n}function oe(r,t){let n="",e=w(t);return n+=r?r.name:"",n+=r.children?Q(r.children,`
`,e,1):"",n}async function fe(r,t){let n="",e=w(t);return n+=r?r.name:"",n+=r.children?await W(r.children,`
`,e,1):"",n}0&&(module.exports={ASCII_SYMBOLS,DEFAULT_SYMBOLS,PostSortMethodPredefined,SortMethodPredefined,Type,parse,parseAsync,parseTree,parseTreeAsync,scan,scanAsync});
{
"name": "dree",
"version": "5.0.9",
"version": "5.1.0",
"description": "A nodejs module wich helps you handle a directory tree providing you its abstraction through tested functions and a custom configuration.",

@@ -40,5 +40,5 @@ "main": "bundled/lib/commonjs/index.js",

"bundle:test": "node build.test.mjs",
"script:getr:linux": "node scripts/generate-expected-tests-results linux",
"script:getr:mac": "node scripts/generate-expected-tests-results mac",
"script:getr:windows": "node scripts/generate-expected-tests-results windows",
"script:getr:linux": "tsx scripts/generate-expected-tests-results linux",
"script:getr:mac": "tsx scripts/generate-expected-tests-results mac",
"script:getr:windows": "tsx scripts/generate-expected-tests-results windows",
"pretest:source": "pnpm transpile",

@@ -105,2 +105,3 @@ "test:source": "mocha --reporter spec test/test.js",

"shx": "^0.3.4",
"tsx": "^4.17.0",
"typedoc": "^0.26.5",

@@ -107,0 +108,0 @@ "typescript": "^5.5.4"

@@ -228,2 +228,15 @@ // Generated by dts-bundle-generator v9.5.1

/**
* Interface of the symbols used to represent the tree in a string.
* See [[DEFAULT_SYMBOLS]] for an example with the default values
*/
export interface TreeSymbols {
dirChild: string;
fileChild: string;
forkChild: string;
lastChild: string;
linkChild: string;
tabIndent: string;
pipeIndent: string;
}
/**
* Interface of the options object used with "parse" or "parseTree" functions

@@ -275,2 +288,6 @@ */

/**
* Symbols used to represent the tree in a string
*/
symbols?: TreeSymbols;
/**
* If true, folders whose user has not permissions will be skipped. An error will be thrown otherwise. Note: in fact every

@@ -282,2 +299,11 @@ * error thrown by fs calls will be ignored

/**
* The default symbols used to represent the tree in a string
*/
export declare const DEFAULT_SYMBOLS: TreeSymbols;
/**
* The ascii symbols used to represent the tree in a string.
* Note: Inspiration was taken from the bash command: `tree --charset=ascii`
*/
export declare const ASCII_SYMBOLS: TreeSymbols;
/**
* Returns the Directory Tree of a given path. This function in synchronous.

@@ -284,0 +310,0 @@ * @param {string} path The path which you want to inspect

@@ -1,5 +0,5 @@

import{resolve as T,basename as b,extname as R,relative as w}from"node:path";import{homedir as X}from"node:os";import{createHash as V}from"node:crypto";import{statSync as N,readdirSync as O,readFileSync as Z,lstatSync as v}from"node:fs";import{stat as F,readdir as _,readFile as ee,lstat as H}from"node:fs/promises";import{makeRe as te}from"minimatch";var re=(n=>(n.DIRECTORY="directory",n.FILE="file",n))(re||{}),ne=(a=>(a.ALPHABETICAL="alpha",a.ALPHABETICAL_REVERSE="antialpha",a.ALPHABETICAL_INSENSITIVE="alpha-insensitive",a.ALPHABETICAL_INSENSITIVE_REVERSE="antialpha-insensitive",a))(ne||{}),se=(l=>(l.ALPHABETICAL="alpha",l.ALPHABETICAL_REVERSE="antialpha",l.ALPHABETICAL_INSENSITIVE="alpha-insensitive",l.ALPHABETICAL_INSENSITIVE_REVERSE="antialpha-insensitive",l.FOLDERS_FIRST="folders-first",l.FILES_FIRST="files-first",l))(se||{}),C={stat:!1,normalize:!1,symbolicLinks:!0,followLinks:!1,sizeInBytes:!0,size:!0,hash:!0,hashAlgorithm:"md5",hashEncoding:"hex",showHidden:!0,depth:void 0,exclude:void 0,matches:void 0,extensions:void 0,emptyDirectory:!1,excludeEmptyDirectories:!1,descendants:!1,descendantsIgnoreDirectories:!1,sorted:!1,postSorted:!1,homeShortcut:!1,skipErrors:!0},B={symbolicLinks:!0,followLinks:!1,showHidden:!0,depth:void 0,exclude:void 0,extensions:void 0,sorted:!1,postSorted:!1,homeShortcut:!1,skipErrors:!0};function D(r,t){return T(t.homeShortcut?r.replace(/^~($|\/|\\)/,X()+"$1"):r)}function x(r){return(Array.isArray(r)?r:[r]).map(t=>t instanceof RegExp?t:te(t,{dot:!0})).filter(t=>t instanceof RegExp)}function M(r){let t={};if(r){for(let n in C)t[n]=r[n]!==void 0?r[n]:C[n];t.depth<0&&(t.depth=0)}else t=C;return t}function p(r){let t={};if(r){for(let n in B)t[n]=r[n]!==void 0?r[n]:B[n];t.depth<0&&(t.depth=0)}else t=B;return t}function P(r){let t=["B","KB","MB","GB","TB"],n;for(n=0;n<t.length&&r>1e3;n++)r/=1e3;return Math.round(r*100)/100+" "+t[n]}function L(r,t){return r.localeCompare(t)}function k(r,t){return r.toLowerCase().localeCompare(t.toLowerCase())}function A(r,t){if(!t)return r;if(t===!0)return r.sort(L);if(typeof t=="string")switch(t){case"alpha":return r.sort(L);case"antialpha":return r.sort(L).reverse();case"alpha-insensitive":return r.sort(k);case"antialpha-insensitive":return r.sort(k).reverse();default:return r}else if(typeof t=="function")return r.sort(t)}function z(r,t){return L(r.name,t.name)}function Y(r,t){return k(r.name,t.name)}function ie(r,t){return r.type==="directory"&&t.type==="file"?-1:r.type==="file"&&t.type==="directory"?1:0}function ae(r,t){return r.type==="file"&&t.type==="directory"?-1:r.type==="directory"&&t.type==="file"?1:0}function $(r,t){if(!t)return r;if(t===!0)return r.sort(z);if(typeof t=="string")switch(t){case"alpha":return r.sort(z);case"antialpha":return r.sort(z).reverse();case"alpha-insensitive":return r.sort(Y);case"antialpha-insensitive":return r.sort(Y).reverse();case"folders-first":return r.sort(ie);case"files-first":return r.sort(ae);default:return r}else if(typeof t=="function")return r.sort(t)}function q(r,t){if(!t)return r;if(t===!0)return r.sort((n,e)=>L(n.relativePath,e.relativePath));if(typeof t=="string")switch(t){case"alpha":return r.sort((n,e)=>L(n.relativePath,e.relativePath));case"antialpha":return r.sort((n,e)=>L(n.relativePath,e.relativePath)).reverse();case"alpha-insensitive":return r.sort((n,e)=>k(n.relativePath,e.relativePath));case"antialpha-insensitive":return r.sort((n,e)=>k(n.relativePath,e.relativePath)).reverse();default:return r}else if(typeof t=="function")return r.sort((n,e)=>t(n.relativePath,e.relativePath))}function U(r,t,n,e,a,d){if(e.depth!==void 0&&n>e.depth)return null;let l=r===t?".":w(r,t);if(e.exclude&&r!==t&&x(e.exclude).some(g=>g.test(`/${l}`)))return null;let s=b(t),h;try{h=N(t)}catch(c){if(e.skipErrors)return null;throw c}let i;try{i=v(t)}catch(c){if(e.skipErrors)return null;throw c}let E=i.isSymbolicLink(),I=h.isFile()?"file":"directory";if(!e.showHidden&&s.charAt(0)==="."||!e.symbolicLinks&&E)return null;let m;if(e.hash){let c=e.hashAlgorithm;m=V(c),m.update(s)}let o={name:s,path:e.normalize?t.replace(/\\/g,"/"):t,relativePath:e.normalize?l.replace(/\\/g,"/"):l,type:I,isSymbolicLink:E,stat:e.followLinks?h:i};switch(e.stat||delete o.stat,I){case"directory":let c=[],g;if(e.followLinks||!E){try{g=O(t),g=A(g,e.sorted)}catch(u){if(e.skipErrors)return null;throw u}if(e.emptyDirectory&&(o.isEmpty=!g.length),g.forEach(u=>{let f=U(r,T(t,u),n+1,e,a,d);f!==null&&c.push(f)}),e.excludeEmptyDirectories&&!c.length)return null}if(e.matches&&r!==t){let u=x(e.matches);if(!c.length&&u.some(f=>!f.test(`/${l}`)))return null}if(e.sizeInBytes||e.size){let u=c.reduce((f,y)=>f+y.sizeInBytes,0);o.sizeInBytes=u,o.size=e.size?P(u):void 0,e.sizeInBytes||c.forEach(f=>f.sizeInBytes=void 0)}if(e.hash){c.forEach(f=>{m.update(f.hash)});let u=e.hashEncoding;o.hash=m.digest(u)}e.descendants&&(o.descendants=c.reduce((u,f)=>u+(f.type==="directory"&&e.descendantsIgnoreDirectories?0:1)+(f.descendants??0),0)),c.length&&(o.children=e.postSorted?$(c,e.postSorted):c);break;case"file":if(o.extension=R(t).replace(".",""),e.extensions&&e.extensions.indexOf(o.extension)===-1||e.matches&&r!==t&&x(e.matches).some(f=>!f.test(`/${l}`)))return null;if(e.sizeInBytes||e.size){let u=e.followLinks?h.size:i.size;o.sizeInBytes=u,o.size=e.size?P(u):void 0}if(e.hash){let u;try{u=Z(t)}catch(y){if(e.skipErrors)return null;throw y}m.update(u);let f=e.hashEncoding;o.hash=m.digest(f)}break;default:return null}return a&&I==="file"?a(o,e.followLinks?h:i):d&&I==="directory"&&d(o,e.followLinks?h:i),o}async function G(r,t,n,e,a,d){if(e.depth!==void 0&&n>e.depth)return null;let l=r===t?".":w(r,t);if(e.exclude&&r!==t&&x(e.exclude).some(g=>g.test(`/${l}`)))return null;let s=b(t),h;try{h=await F(t)}catch(c){if(e.skipErrors)return null;throw c}let i;try{i=await H(t)}catch(c){if(e.skipErrors)return null;throw c}let E=i.isSymbolicLink(),I=h.isFile()?"file":"directory";if(!e.showHidden&&s.charAt(0)==="."||!e.symbolicLinks&&E)return null;let m;if(e.hash){let c=e.hashAlgorithm;m=V(c),m.update(s)}let o={name:s,path:e.normalize?t.replace(/\\/g,"/"):t,relativePath:e.normalize?l.replace(/\\/g,"/"):l,type:I,isSymbolicLink:E,stat:e.followLinks?h:i};switch(e.stat||delete o.stat,I){case"directory":let c=[],g;if(e.followLinks||!E){try{g=await _(t),g=A(g,e.sorted)}catch(u){if(e.skipErrors)return null;throw u}if(e.emptyDirectory&&(o.isEmpty=!g.length),c=await Promise.all(g.map(async u=>await G(r,T(t,u),n+1,e,a,d))),c=c.filter(u=>u!==null),e.excludeEmptyDirectories&&!c.length)return null}if(e.matches&&r!==t){let u=x(e.matches);if(!c.length&&u.some(f=>!f.test(`/${l}`)))return null}if(e.sizeInBytes||e.size){let u=c.reduce((f,y)=>f+y.sizeInBytes,0);o.sizeInBytes=u,o.size=e.size?P(u):void 0,e.sizeInBytes||c.forEach(f=>f.sizeInBytes=void 0)}if(e.hash){c.forEach(f=>{m.update(f.hash)});let u=e.hashEncoding;o.hash=m.digest(u)}e.descendants&&(o.descendants=c.reduce((u,f)=>u+(f.type==="directory"&&e.descendantsIgnoreDirectories?0:1)+(f.descendants??0),0)),c.length&&(o.children=e.postSorted?$(c,e.postSorted):c);break;case"file":if(o.extension=R(t).replace(".",""),e.extensions&&e.extensions.indexOf(o.extension)===-1||e.matches&&r!==t&&x(e.matches).some(f=>!f.test(`/${l}`)))return null;if(e.sizeInBytes||e.size){let u=e.followLinks?h.size:i.size;o.sizeInBytes=u,o.size=e.size?P(u):void 0}if(e.hash){let u;try{u=await ee(t)}catch(y){if(e.skipErrors)return null;throw y}m.update(u);let f=e.hashEncoding;o.hash=m.digest(f)}break;default:return null}return a&&I==="file"?await a(o,e.followLinks?h:i):d&&I==="directory"&&await d(o,e.followLinks?h:i),o}function K(r,t,n){return!t.symbolicLinks&&r.isSymbolicLink||!t.showHidden&&r.name.charAt(0)==="."||t.extensions!==void 0&&r.type==="file"&&t.extensions.indexOf(r.extension)===-1||t.exclude&&x(t.exclude).some(e=>e.test(`/${r.relativePath}`))||t.depth!==void 0&&n>t.depth}function j(r,t,n,e,a){let d="";return t.map((s,h)=>{let i="";if(e.depth!==void 0&&a>e.depth||e.exclude&&x(e.exclude).some(S=>S.test(`/${w(r,s)}`)))return"";let E=b(s),I;try{I=N(s)}catch(y){if(e.skipErrors)return null;throw y}let m;try{m=v(s)}catch(y){if(e.skipErrors)return null;throw y}let o=m.isSymbolicLink(),c=I.isFile()?"file":"directory";if(!e.showHidden&&E.charAt(0)==="."||!e.symbolicLinks&&o)return"";let g=R(s).replace(".","");if(e.extensions&&c==="file"&&e.extensions.indexOf(g)===-1)return"";let u=o?">>":c==="directory"?"\u2500> ":"\u2500\u2500 ",f=n+(h===t.length-1?" ":"\u2502 ");if(i+=u+E,(e.followLinks||!o)&&c==="directory"){let y;try{y=O(s).map(S=>T(s,S)),y=A(y,e.sorted)}catch(S){if(e.skipErrors)return null;throw S}i+=y.length?j(r,y,f,e,a+1):""}return i}).filter(s=>!!s).forEach((s,h,i)=>{d+=n+(h===i.length-1?"\u2514"+s:"\u251C"+s)}),d}async function J(r,t,n,e,a){let d="";return(await Promise.all(t.map(async(s,h)=>{let i="";if(e.depth!==void 0&&a>e.depth||e.exclude&&x(e.exclude).some(S=>S.test(`/${w(r,s)}`)))return"";let E=b(s),I;try{I=await F(s)}catch(y){if(e.skipErrors)return null;throw y}let m;try{m=await H(s)}catch(y){if(e.skipErrors)return null;throw y}let o=m.isSymbolicLink(),c=I.isFile()?"file":"directory";if(!e.showHidden&&E.charAt(0)==="."||!e.symbolicLinks&&o)return"";let g=R(s).replace(".","");if(e.extensions&&c==="file"&&e.extensions.indexOf(g)===-1)return"";let u=o?">>":c==="directory"?"\u2500> ":"\u2500\u2500 ",f=n+(h===t.length-1?" ":"\u2502 ");if(i+=u+E,(e.followLinks||!o)&&c==="directory"){let y;try{y=(await _(s)).map(S=>T(s,S)),y=A(y,e.sorted)}catch(S){if(e.skipErrors)return null;throw S}i+=y.length?await J(r,y,f,e,a+1):""}return i}))).filter(s=>!!s).forEach((s,h,i)=>{d+=n+(h===i.length-1?"\u2514"+s:"\u251C"+s)}),d}function Q(r,t,n,e){let a="";return r=q(r,n.sorted),r.filter(d=>!K(d,n,e)).forEach((d,l,s)=>{let h=d.isSymbolicLink?">>":d.type==="directory"?"\u2500> ":"\u2500\u2500 ",i=l===s.length-1?"\u2514"+h:"\u251C"+h,E=t+(l===s.length-1?" ":"\u2502 ");a+=t+i+d.name,a+=d.children&&(n.followLinks||!d.isSymbolicLink)?Q(d.children,E,n,e+1):""}),a}async function W(r,t,n,e){let a="";r=q(r,n.sorted);let d=r.filter(l=>!K(l,n,e));for(let l=0;l<d.length;l++){let s=d[l],h=s.isSymbolicLink?">>":s.type==="directory"?"\u2500> ":"\u2500\u2500 ",i=l===d.length-1?"\u2514"+h:"\u251C"+h,E=t+(l===d.length-1?" ":"\u2502 ");a+=t+i+s.name,a+=s.children&&(n.followLinks||!s.isSymbolicLink)?await W(s.children,E,n,e+1):""}return a}function me(r,t,n,e){let a=M(t),d=D(r,a),l=U(d,d,0,a,n,e);return l&&(l.sizeInBytes=a.sizeInBytes?l.sizeInBytes:void 0),l}async function ge(r,t,n,e){let a=M(t),d=D(r,a),l=await G(d,d,0,a,n,e);return l&&(l.sizeInBytes=a.sizeInBytes?l.sizeInBytes:void 0),l}function Ie(r,t){let n="",e=p(t),a=D(r,e),d=b(a);n+=d;let l;try{l=N(a)}catch(i){if(e.skipErrors)return null;throw i}let s;try{s=v(a)}catch(i){if(e.skipErrors)return null;throw i}let h=s.isSymbolicLink();if((e.followLinks||!h)&&l.isDirectory()){let i;try{i=O(a).map(E=>T(a,E)),i=A(i,e.sorted)}catch(E){if(e.skipErrors)return null;throw E}n+=i.length?j(a,i,`
`,e,1):""}return n}async function Se(r,t){let n="",e=p(t),a=D(r,e),d=b(a);n+=d;let l;try{l=await F(a)}catch(i){if(e.skipErrors)return null;throw i}let s;try{s=await H(a)}catch(i){if(e.skipErrors)return null;throw i}let h=s.isSymbolicLink();if((e.followLinks||!h)&&l.isDirectory()){let i;try{i=(await _(a)).map(E=>T(a,E)),i=A(i,e.sorted)}catch(E){if(e.skipErrors)return null;throw E}n+=i.length?await J(a,i,`
`,e,1):""}return n}function xe(r,t){let n="",e=p(t);return n+=r?r.name:"",n+=r.children?Q(r.children,`
`,e,1):"",n}async function Le(r,t){let n="",e=p(t);return n+=r?r.name:"",n+=r.children?await W(r.children,`
`,e,1):"",n}export{se as PostSortMethodPredefined,ne as SortMethodPredefined,re as Type,Ie as parse,Se as parseAsync,xe as parseTree,Le as parseTreeAsync,me as scan,ge as scanAsync};
import{resolve as L,basename as T,extname as P,relative as R}from"node:path";import{homedir as X}from"node:os";import{createHash as M}from"node:crypto";import{statSync as O,readdirSync as N,readFileSync as Z,lstatSync as v}from"node:fs";import{stat as F,readdir as _,readFile as ee,lstat as H}from"node:fs/promises";import{makeRe as te}from"minimatch";var re=(n=>(n.DIRECTORY="directory",n.FILE="file",n))(re||{}),ne=(l=>(l.ALPHABETICAL="alpha",l.ALPHABETICAL_REVERSE="antialpha",l.ALPHABETICAL_INSENSITIVE="alpha-insensitive",l.ALPHABETICAL_INSENSITIVE_REVERSE="antialpha-insensitive",l))(ne||{}),se=(a=>(a.ALPHABETICAL="alpha",a.ALPHABETICAL_REVERSE="antialpha",a.ALPHABETICAL_INSENSITIVE="alpha-insensitive",a.ALPHABETICAL_INSENSITIVE_REVERSE="antialpha-insensitive",a.FOLDERS_FIRST="folders-first",a.FILES_FIRST="files-first",a))(se||{}),p={stat:!1,normalize:!1,symbolicLinks:!0,followLinks:!1,sizeInBytes:!0,size:!0,hash:!0,hashAlgorithm:"md5",hashEncoding:"hex",showHidden:!0,depth:void 0,exclude:void 0,matches:void 0,extensions:void 0,emptyDirectory:!1,excludeEmptyDirectories:!1,descendants:!1,descendantsIgnoreDirectories:!1,sorted:!1,postSorted:!1,homeShortcut:!1,skipErrors:!0},ie={dirChild:"\u2500> ",fileChild:"\u2500\u2500 ",forkChild:"\u251C",lastChild:"\u2514",linkChild:">>",tabIndent:" ",pipeIndent:"\u2502 "},be={dirChild:"-\\ ",fileChild:"-- ",forkChild:"|",lastChild:"`",linkChild:"->",tabIndent:" ",pipeIndent:"| "},B={symbolicLinks:!0,followLinks:!1,showHidden:!0,depth:void 0,exclude:void 0,extensions:void 0,sorted:!1,postSorted:!1,homeShortcut:!1,symbols:ie,skipErrors:!0};function w(r,t){return L(t.homeShortcut?r.replace(/^~($|\/|\\)/,X()+"$1"):r)}function S(r){return(Array.isArray(r)?r:[r]).map(t=>t instanceof RegExp?t:te(t,{dot:!0})).filter(t=>t instanceof RegExp)}function V(r){let t={};if(r){for(let n in p)t[n]=r[n]!==void 0?r[n]:p[n];t.depth<0&&(t.depth=0)}else t=p;return t}function D(r){let t={};if(r){for(let n in B)t[n]=r[n]!==void 0?r[n]:B[n];t.depth<0&&(t.depth=0)}else t=B;return t}function C(r){let t=["B","KB","MB","GB","TB"],n;for(n=0;n<t.length&&r>1e3;n++)r/=1e3;return Math.round(r*100)/100+" "+t[n]}function x(r,t){return r.localeCompare(t)}function A(r,t){return r.toLowerCase().localeCompare(t.toLowerCase())}function k(r,t){if(!t)return r;if(t===!0)return r.sort(x);if(typeof t=="string")switch(t){case"alpha":return r.sort(x);case"antialpha":return r.sort(x).reverse();case"alpha-insensitive":return r.sort(A);case"antialpha-insensitive":return r.sort(A).reverse();default:return r}else if(typeof t=="function")return r.sort(t)}function z(r,t){return x(r.name,t.name)}function Y(r,t){return A(r.name,t.name)}function le(r,t){return r.type==="directory"&&t.type==="file"?-1:r.type==="file"&&t.type==="directory"?1:0}function ae(r,t){return r.type==="file"&&t.type==="directory"?-1:r.type==="directory"&&t.type==="file"?1:0}function $(r,t){if(!t)return r;if(t===!0)return r.sort(z);if(typeof t=="string")switch(t){case"alpha":return r.sort(z);case"antialpha":return r.sort(z).reverse();case"alpha-insensitive":return r.sort(Y);case"antialpha-insensitive":return r.sort(Y).reverse();case"folders-first":return r.sort(le);case"files-first":return r.sort(ae);default:return r}else if(typeof t=="function")return r.sort(t)}function U(r,t){if(!t)return r;if(t===!0)return r.sort((n,e)=>x(n.relativePath,e.relativePath));if(typeof t=="string")switch(t){case"alpha":return r.sort((n,e)=>x(n.relativePath,e.relativePath));case"antialpha":return r.sort((n,e)=>x(n.relativePath,e.relativePath)).reverse();case"alpha-insensitive":return r.sort((n,e)=>A(n.relativePath,e.relativePath));case"antialpha-insensitive":return r.sort((n,e)=>A(n.relativePath,e.relativePath)).reverse();default:return r}else if(typeof t=="function")return r.sort((n,e)=>t(n.relativePath,e.relativePath))}function q(r,t,n,e,l,o){if(e.depth!==void 0&&n>e.depth)return null;let a=r===t?".":R(r,t);if(e.exclude&&r!==t&&S(e.exclude).some(b=>b.test(`/${a}`)))return null;let s=T(t),h;try{h=O(t)}catch(c){if(e.skipErrors)return null;throw c}let i;try{i=v(t)}catch(c){if(e.skipErrors)return null;throw c}let m=i.isSymbolicLink(),g=h.isFile()?"file":"directory";if(!e.showHidden&&s.charAt(0)==="."||!e.symbolicLinks&&m)return null;let E;if(e.hash){let c=e.hashAlgorithm;E=M(c),E.update(s)}let u={name:s,path:e.normalize?t.replace(/\\/g,"/"):t,relativePath:e.normalize?a.replace(/\\/g,"/"):a,type:g,isSymbolicLink:m,stat:e.followLinks?h:i};switch(e.stat||delete u.stat,g){case"directory":let c=[],b;if(e.followLinks||!m){try{b=N(t),b=k(b,e.sorted)}catch(d){if(e.skipErrors)return null;throw d}if(e.emptyDirectory&&(u.isEmpty=!b.length),b.forEach(d=>{let f=q(r,L(t,d),n+1,e,l,o);f!==null&&c.push(f)}),e.excludeEmptyDirectories&&!c.length)return null}if(e.matches&&r!==t){let d=S(e.matches);if(!c.length&&d.some(f=>!f.test(`/${a}`)))return null}if(e.sizeInBytes||e.size){let d=c.reduce((f,y)=>f+y.sizeInBytes,0);u.sizeInBytes=d,u.size=e.size?C(d):void 0,e.sizeInBytes||c.forEach(f=>f.sizeInBytes=void 0)}if(e.hash){c.forEach(f=>{E.update(f.hash)});let d=e.hashEncoding;u.hash=E.digest(d)}e.descendants&&(u.descendants=c.reduce((d,f)=>d+(f.type==="directory"&&e.descendantsIgnoreDirectories?0:1)+(f.descendants??0),0)),c.length&&(u.children=e.postSorted?$(c,e.postSorted):c);break;case"file":if(u.extension=P(t).replace(".",""),e.extensions&&e.extensions.indexOf(u.extension)===-1||e.matches&&r!==t&&S(e.matches).some(f=>!f.test(`/${a}`)))return null;if(e.sizeInBytes||e.size){let d=e.followLinks?h.size:i.size;u.sizeInBytes=d,u.size=e.size?C(d):void 0}if(e.hash){let d;try{d=Z(t)}catch(y){if(e.skipErrors)return null;throw y}E.update(d);let f=e.hashEncoding;u.hash=E.digest(f)}break;default:return null}return l&&g==="file"?l(u,e.followLinks?h:i):o&&g==="directory"&&o(u,e.followLinks?h:i),u}async function G(r,t,n,e,l,o){if(e.depth!==void 0&&n>e.depth)return null;let a=r===t?".":R(r,t);if(e.exclude&&r!==t&&S(e.exclude).some(b=>b.test(`/${a}`)))return null;let s=T(t),h;try{h=await F(t)}catch(c){if(e.skipErrors)return null;throw c}let i;try{i=await H(t)}catch(c){if(e.skipErrors)return null;throw c}let m=i.isSymbolicLink(),g=h.isFile()?"file":"directory";if(!e.showHidden&&s.charAt(0)==="."||!e.symbolicLinks&&m)return null;let E;if(e.hash){let c=e.hashAlgorithm;E=M(c),E.update(s)}let u={name:s,path:e.normalize?t.replace(/\\/g,"/"):t,relativePath:e.normalize?a.replace(/\\/g,"/"):a,type:g,isSymbolicLink:m,stat:e.followLinks?h:i};switch(e.stat||delete u.stat,g){case"directory":let c=[],b;if(e.followLinks||!m){try{b=await _(t),b=k(b,e.sorted)}catch(d){if(e.skipErrors)return null;throw d}if(e.emptyDirectory&&(u.isEmpty=!b.length),c=await Promise.all(b.map(async d=>await G(r,L(t,d),n+1,e,l,o))),c=c.filter(d=>d!==null),e.excludeEmptyDirectories&&!c.length)return null}if(e.matches&&r!==t){let d=S(e.matches);if(!c.length&&d.some(f=>!f.test(`/${a}`)))return null}if(e.sizeInBytes||e.size){let d=c.reduce((f,y)=>f+y.sizeInBytes,0);u.sizeInBytes=d,u.size=e.size?C(d):void 0,e.sizeInBytes||c.forEach(f=>f.sizeInBytes=void 0)}if(e.hash){c.forEach(f=>{E.update(f.hash)});let d=e.hashEncoding;u.hash=E.digest(d)}e.descendants&&(u.descendants=c.reduce((d,f)=>d+(f.type==="directory"&&e.descendantsIgnoreDirectories?0:1)+(f.descendants??0),0)),c.length&&(u.children=e.postSorted?$(c,e.postSorted):c);break;case"file":if(u.extension=P(t).replace(".",""),e.extensions&&e.extensions.indexOf(u.extension)===-1||e.matches&&r!==t&&S(e.matches).some(f=>!f.test(`/${a}`)))return null;if(e.sizeInBytes||e.size){let d=e.followLinks?h.size:i.size;u.sizeInBytes=d,u.size=e.size?C(d):void 0}if(e.hash){let d;try{d=await ee(t)}catch(y){if(e.skipErrors)return null;throw y}E.update(d);let f=e.hashEncoding;u.hash=E.digest(f)}break;default:return null}return l&&g==="file"?await l(u,e.followLinks?h:i):o&&g==="directory"&&await o(u,e.followLinks?h:i),u}function K(r,t,n){return!t.symbolicLinks&&r.isSymbolicLink||!t.showHidden&&r.name.charAt(0)==="."||t.extensions!==void 0&&r.type==="file"&&t.extensions.indexOf(r.extension)===-1||t.exclude&&S(t.exclude).some(e=>e.test(`/${r.relativePath}`))||t.depth!==void 0&&n>t.depth}function j(r,t,n,e,l){let o="";return t.map((s,h)=>{let i="";if(e.depth!==void 0&&l>e.depth||e.exclude&&S(e.exclude).some(I=>I.test(`/${R(r,s)}`)))return"";let m=T(s),g;try{g=O(s)}catch(y){if(e.skipErrors)return null;throw y}let E;try{E=v(s)}catch(y){if(e.skipErrors)return null;throw y}let u=E.isSymbolicLink(),c=g.isFile()?"file":"directory";if(!e.showHidden&&m.charAt(0)==="."||!e.symbolicLinks&&u)return"";let b=P(s).replace(".","");if(e.extensions&&c==="file"&&e.extensions.indexOf(b)===-1)return"";let d=u?e.symbols.linkChild:c==="directory"?e.symbols.dirChild:e.symbols.fileChild,f=n+(h===t.length-1?e.symbols.tabIndent:e.symbols.pipeIndent);if(i+=d+m,(e.followLinks||!u)&&c==="directory"){let y;try{y=N(s).map(I=>L(s,I)),y=k(y,e.sorted)}catch(I){if(e.skipErrors)return null;throw I}i+=y.length?j(r,y,f,e,l+1):""}return i}).filter(s=>!!s).forEach((s,h,i)=>{o+=n+(h===i.length-1?e.symbols.lastChild+s:e.symbols.forkChild+s)}),o}async function J(r,t,n,e,l){let o="";return(await Promise.all(t.map(async(s,h)=>{let i="";if(e.depth!==void 0&&l>e.depth||e.exclude&&S(e.exclude).some(I=>I.test(`/${R(r,s)}`)))return"";let m=T(s),g;try{g=await F(s)}catch(y){if(e.skipErrors)return null;throw y}let E;try{E=await H(s)}catch(y){if(e.skipErrors)return null;throw y}let u=E.isSymbolicLink(),c=g.isFile()?"file":"directory";if(!e.showHidden&&m.charAt(0)==="."||!e.symbolicLinks&&u)return"";let b=P(s).replace(".","");if(e.extensions&&c==="file"&&e.extensions.indexOf(b)===-1)return"";let d=u?e.symbols.linkChild:c==="directory"?e.symbols.dirChild:e.symbols.fileChild,f=n+(h===t.length-1?e.symbols.tabIndent:e.symbols.pipeIndent);if(i+=d+m,(e.followLinks||!u)&&c==="directory"){let y;try{y=(await _(s)).map(I=>L(s,I)),y=k(y,e.sorted)}catch(I){if(e.skipErrors)return null;throw I}i+=y.length?await J(r,y,f,e,l+1):""}return i}))).filter(s=>!!s).forEach((s,h,i)=>{o+=n+(h===i.length-1?e.symbols.lastChild+s:e.symbols.forkChild+s)}),o}function Q(r,t,n,e){let l="";return r=U(r,n.sorted),r.filter(o=>!K(o,n,e)).forEach((o,a,s)=>{let h=o.isSymbolicLink?n.symbols.linkChild:o.type==="directory"?n.symbols.dirChild:n.symbols.fileChild,i=a===s.length-1?n.symbols.lastChild+h:n.symbols.forkChild+h,m=t+(a===s.length-1?n.symbols.tabIndent:n.symbols.pipeIndent);l+=t+i+o.name,l+=o.children&&(n.followLinks||!o.isSymbolicLink)?Q(o.children,m,n,e+1):""}),l}async function W(r,t,n,e){let l="";r=U(r,n.sorted);let o=r.filter(a=>!K(a,n,e));for(let a=0;a<o.length;a++){let s=o[a],h=s.isSymbolicLink?n.symbols.linkChild:s.type==="directory"?n.symbols.dirChild:n.symbols.fileChild,i=a===o.length-1?n.symbols.lastChild+h:n.symbols.forkChild+h,m=t+(a===o.length-1?n.symbols.tabIndent:n.symbols.pipeIndent);l+=t+i+s.name,l+=s.children&&(n.followLinks||!s.isSymbolicLink)?await W(s.children,m,n,e+1):""}return l}function ge(r,t,n,e){let l=V(t),o=w(r,l),a=q(o,o,0,l,n,e);return a&&(a.sizeInBytes=l.sizeInBytes?a.sizeInBytes:void 0),a}async function Ie(r,t,n,e){let l=V(t),o=w(r,l),a=await G(o,o,0,l,n,e);return a&&(a.sizeInBytes=l.sizeInBytes?a.sizeInBytes:void 0),a}function Se(r,t){let n="",e=D(t),l=w(r,e),o=T(l);n+=o;let a;try{a=O(l)}catch(i){if(e.skipErrors)return null;throw i}let s;try{s=v(l)}catch(i){if(e.skipErrors)return null;throw i}let h=s.isSymbolicLink();if((e.followLinks||!h)&&a.isDirectory()){let i;try{i=N(l).map(m=>L(l,m)),i=k(i,e.sorted)}catch(m){if(e.skipErrors)return null;throw m}n+=i.length?j(l,i,`
`,e,1):""}return n}async function xe(r,t){let n="",e=D(t),l=w(r,e),o=T(l);n+=o;let a;try{a=await F(l)}catch(i){if(e.skipErrors)return null;throw i}let s;try{s=await H(l)}catch(i){if(e.skipErrors)return null;throw i}let h=s.isSymbolicLink();if((e.followLinks||!h)&&a.isDirectory()){let i;try{i=(await _(l)).map(m=>L(l,m)),i=k(i,e.sorted)}catch(m){if(e.skipErrors)return null;throw m}n+=i.length?await J(l,i,`
`,e,1):""}return n}function Le(r,t){let n="",e=D(t);return n+=r?r.name:"",n+=r.children?Q(r.children,`
`,e,1):"",n}async function Te(r,t){let n="",e=D(t);return n+=r?r.name:"",n+=r.children?await W(r.children,`
`,e,1):"",n}export{be as ASCII_SYMBOLS,ie as DEFAULT_SYMBOLS,se as PostSortMethodPredefined,ne as SortMethodPredefined,re as Type,Se as parse,xe as parseAsync,Le as parseTree,Te as parseTreeAsync,ge as scan,Ie as scanAsync};
# [5.1.0](https://github.com/euberdeveloper/dree/compare/5.0.9...5.1.0) (2024-08-18)
### Bug Fixes
* **scripts:** fix generation of expected parsed ([7364aad](https://github.com/euberdeveloper/dree/commit/7364aadbcf7976c0f6eafcd7ff4ab03e7d18813f))
* **scripts:** fix generation of parse-tree expecteds ([75785a9](https://github.com/euberdeveloper/dree/commit/75785a9b9138a0ffa0c56dec01774c1e3612b12e))
### Features
* **bin:** add --ascii option ([0dbdc60](https://github.com/euberdeveloper/dree/commit/0dbdc60b326430fde4cbbbada5643114d36dbb60))
* **lib:** add customizable symbols for parse tree ([d1033ef](https://github.com/euberdeveloper/dree/commit/d1033eff539e2d4250e74a3669e277d1d8f883fa))
* **lib:** add default ascii symbols for parse ([df42f8e](https://github.com/euberdeveloper/dree/commit/df42f8e8a3d7ec34872392a3da3c02e7c4b1c62b))
## [5.0.9](https://github.com/euberdeveloper/dree/compare/5.0.8...5.0.9) (2024-08-15)

@@ -4,0 +19,0 @@

{
"name": "dree",
"version": "5.0.9",
"version": "5.1.0",
"description": "A nodejs module wich helps you handle a directory tree providing you its abstraction through tested functions and a custom configuration.",

@@ -41,5 +41,5 @@ "main": "bundled/lib/commonjs/index.js",

"bundle:test": "node build.test.mjs",
"script:getr:linux": "node scripts/generate-expected-tests-results linux",
"script:getr:mac": "node scripts/generate-expected-tests-results mac",
"script:getr:windows": "node scripts/generate-expected-tests-results windows",
"script:getr:linux": "tsx scripts/generate-expected-tests-results linux",
"script:getr:mac": "tsx scripts/generate-expected-tests-results mac",
"script:getr:windows": "tsx scripts/generate-expected-tests-results windows",
"pretest:source": "pnpm transpile",

@@ -106,2 +106,3 @@ "test:source": "mocha --reporter spec test/test.js",

"shx": "^0.3.4",
"tsx": "^4.17.0",
"typedoc": "^0.26.5",

@@ -108,0 +109,0 @@ "typescript": "^5.5.4"

@@ -152,3 +152,4 @@ ![Test](https://github.com/euberdeveloper/dree/workflows/Test/badge.svg)

exclude: /dir_to_exclude/,
extensions: [ 'txt', 'jpg' ]
extensions: [ 'txt', 'jpg' ],
symbols: dree.ASCII_SYMBOLS
};

@@ -493,4 +494,33 @@

* __homeShortcut__: Default value: `false`. If true, the unix homedir shortcut ~ will be expanded to the user home directory.
* __symbols__: Default value: `DEFAULT_SYMBOLS`. Symbols used to represent the tree in a string.
* __skipErrors__: Default value: `true`. If true, folders whose user has not permissions will be skipped. An error will be thrown otherwise. Note: in fact every error thrown by `fs` calls will be ignored.
**DEFAULT_SYMBOLS object:**
```typescript
{
dirChild: '─> ',
fileChild: '── ',
forkChild: '├',
lastChild: '└',
linkChild: '>>',
tabIndent: ' ',
pipeIndent: '│ '
}
```
**ASCII_SYMBOLS object:**
```typescript
{
dirChild: '-\\ ',
fileChild: '-- ',
forkChild: '|',
lastChild: '`',
linkChild: '->',
tabIndent: ' ',
pipeIndent: '| '
}
```
**Result string:**

@@ -606,3 +636,3 @@

├─> scripts
│ └── generate-expected-tests-results.js
│ └── generate-expected-tests-results.ts
├─> source

@@ -622,2 +652,3 @@ │ ├─> bin

│ └── test.js
├── tsconfig.json
├── typedoc.cjs

@@ -624,0 +655,0 @@ └── typedoc.dev.cjs

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc