rrdir 14.2.12 → 14.2.13
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/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{lstat as e,readdir as t,stat as n}from"node:fs/promises";import{lstat as r,lstatSync as i,readdir as a,readdirSync as o,stat as s,statSync as c}from"node:fs";import{isAbsolute as l,resolve as u,sep as d}from"node:path";const f=new TextDecoder,p=f.decode.bind(f),m=new TextEncoder().encode(d);function h(e,t){if(t){let t=e;if(t.length===1&&t[0]===46)return t.subarray(0,0);let n=new Uint8Array(t.length+m.length);return n.set(t,0),n.set(m,t.length),n}return e===`.`?``:e+d}function g(e,t,n){if(n){let n=t;if(n.length===0)return e;let r=e,i=new Uint8Array(n.length+r.length);return i.set(n,0),i.set(r,n.length),i}return t+e}function _(e,t,n,r,i){return i?{path:e,directory:t,symlink:n,stats:r}:{path:e,directory:t,symlink:n}}function v(e,t){e=e.replace(/\\/g,`/`);let n=e.endsWith(`/**`),r=e.replace(/\*\*|\*|[.+?^${}()|[\]\\]/g,e=>e===`**`?`.*`:e===`*`?`[^/]*`:`\\${e}`);return n?(r=r.slice(0,-3),r=`^${r}(?:/.*)?$`):r=`^${r}$`,new RegExp(r,t?`i`:``)}function y(e,t,n){if(!e?.length)return null;let r=e.map(e=>v(e,t)),i=n?``:u(`.`)+d
|
|
1
|
+
import{lstat as e,readdir as t,stat as n}from"node:fs/promises";import{lstat as r,lstatSync as i,readdir as a,readdirSync as o,stat as s,statSync as c}from"node:fs";import{isAbsolute as l,resolve as u,sep as d}from"node:path";const f=new TextDecoder,p=f.decode.bind(f),m=new TextEncoder().encode(d);function h(e,t){if(t){let t=e;if(t.length===1&&t[0]===46)return t.subarray(0,0);let n=new Uint8Array(t.length+m.length);return n.set(t,0),n.set(m,t.length),n}return e===`.`?``:e+d}function g(e,t,n){if(n){let n=t;if(n.length===0)return e;let r=e,i=new Uint8Array(n.length+r.length);return i.set(n,0),i.set(r,n.length),i}return t+e}function _(e,t,n,r,i){return i?{path:e,directory:t,symlink:n,stats:r}:{path:e,directory:t,symlink:n}}function v(e,t){e=e.replace(/\\/g,`/`);let n=e.endsWith(`/**`),r=e.replace(/\*\*|\*|[.+?^${}()|[\]\\]/g,e=>e===`**`?`.*`:e===`*`?`[^/]*`:`\\${e}`);return n?(r=r.slice(0,-3),r=`^${r}(?:/.*)?$`):r=`^${r}$`,new RegExp(r,t?`i`:``)}function y(e,t,n){if(!e?.length)return null;let r=e.map(e=>v(e,t)),i=n?``:u(`.`)+d;return d===`\\`?e=>{let t=(i+e).replace(/\\/g,`/`);for(let e of r)if(e.test(t))return!0;return!1}:e=>{let t=i+e;for(let e of r)if(e.test(t))return!0;return!1}}function b(t,a){if(t instanceof Uint8Array){let e=t[t.length-1];(e===47||e===92)&&(t=t.subarray(0,-1))}else /[/\\]$/.test(t)&&(t=t.substring(0,t.length-1));let o=t instanceof Uint8Array,u=!!a.insensitive,d=t instanceof Uint8Array?l(p(t)):l(t),f=y(a.include,u,d),m=y(a.exclude,u,d),h=!!a.followSymlinks;return{dir:t,internalOpts:{includeMatcher:f,excludeMatcher:m,isBuffer:o,followSymlinks:h,needStats:!!a.stats,strict:!!a.strict,readdirOpts:{encoding:o?`buffer`:`utf8`,withFileTypes:!0},statFn:h?n:e,statCbFn:h?s:r,statSyncFn:h?c:i}}}async function*x(e,n={}){let r=b(e,n),{includeMatcher:i,excludeMatcher:a,isBuffer:o,followSymlinks:s,needStats:c,strict:l,readdirOpts:u,statFn:d}=r.internalOpts;e=r.dir;let f=[e];for(;f.length>0;){let e=await Promise.all(f.map(e=>t(e,u).then(t=>({dir:e,dirents:t}),t=>({dir:e,err:t})))),n=[];for(let t of e){if(`err`in t){if(l)throw t.err;yield{path:t.dir,err:t.err};continue}let e=h(t.dir,o);for(let r of t.dirents){let t=g(r.name,e,o),u=!0;if(a||i){let e=o?p(t):t;if(a?.(e))continue;i&&(u=i(e))}let f=!1,m=!1;r.isFile()||(f=r.isDirectory(),f||(m=r.isSymbolicLink()));let h,v;if(s&&m||u&&c)try{h=await d(t)}catch(e){if(l)throw e;u&&(v={path:t,err:e})}let y=h?h.isDirectory():f;u&&(yield v??_(t,y,m&&!s,h,c)),y&&n.push(t)}}f=n}}function S(e,t={}){let n=b(e,t),r=[];return new Promise((e,t)=>{C(n.dir,n.internalOpts,r,n=>{n?t(n):e(r)})})}function C(e,t,n,r){let{includeMatcher:i,excludeMatcher:o,isBuffer:s,followSymlinks:c,needStats:l,strict:u,readdirOpts:d,statCbFn:f}=t;a(e,d,(a,d)=>{if(a)return u?r(a):(n.push({path:e,err:a}),r());let m=d;if(!m.length)return r();let v=h(e,s),y=[],b=0,x=!1,S,w=!1,T=()=>{if(w)return;if(S)return w=!0,r(S);if(!x||b>0)return;if(w=!0,!y.length)return r();let e=y.length,i=t=>{t&&!S&&(S=t),--e===0&&r(S)};for(let e of y)C(e,t,n,i)};for(let e of m){let t=g(e.name,v,s),r=!0;if(o||i){let e=s?p(t):t;if(o?.(e))continue;i&&(r=i(e))}let a=!1,d=!1;e.isFile()||(a=e.isDirectory(),a||(d=e.isSymbolicLink())),c&&d||r&&l?(b++,f(t,(e,i)=>{if(e&&u)S??=e;else{let o=i?i.isDirectory():a;r&&n.push(e?{path:t,err:e}:_(t,o,d&&!c,i,l)),o&&y.push(t)}b--,T()})):(r&&n.push(_(t,a,d&&!c,void 0,l)),a&&y.push(t))}x=!0,T()})}function w(e,t={}){let n=b(e,t),r=[];return T(n.dir,n.internalOpts,r),r}function T(e,t,n){let{includeMatcher:r,excludeMatcher:i,isBuffer:a,followSymlinks:s,needStats:c,strict:l,readdirOpts:u,statSyncFn:d}=t,f=[e];for(;f.length>0;){let e=f.pop(),t=[];try{t=o(e,u)}catch(t){if(l)throw t;n.push({path:e,err:t});continue}if(!t.length)continue;let m=h(e,a);for(let e of t){let t=g(e.name,m,a),o=!0;if(i||r){let e=a?p(t):t;if(i?.(e))continue;r&&(o=r(e))}let u=!1,h=!1;e.isFile()||(u=e.isDirectory(),u||(h=e.isSymbolicLink()));let v,y;if(s&&h||o&&c)try{v=d(t)}catch(e){if(l)throw e;o&&(y={path:t,err:e})}let b=v?v.isDirectory():u;o&&n.push(y??_(t,b,h&&!s,v,c)),b&&f.push(t)}}}export{x as rrdir,S as rrdirAsync,w as rrdirSync};
|