@isdk/util 0.3.3 → 0.3.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.
Files changed (52) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/index.mjs +1 -1
  3. package/docs/classes/BinarySemaphore.md +37 -37
  4. package/docs/classes/ConfigFile.md +9 -9
  5. package/docs/classes/Deque.md +56 -56
  6. package/docs/classes/IntSet.md +12 -12
  7. package/docs/classes/Semaphore.md +38 -38
  8. package/docs/classes/SignalGate.md +12 -12
  9. package/docs/functions/RateLimit.md +2 -2
  10. package/docs/functions/arrayHasAll.md +1 -1
  11. package/docs/functions/extNameLevel.md +1 -1
  12. package/docs/functions/filenameReservedRegex.md +1 -1
  13. package/docs/functions/findPort.md +1 -1
  14. package/docs/functions/getMultiLevelExtname.md +1 -1
  15. package/docs/functions/glob.md +3 -3
  16. package/docs/functions/isStringIn.md +1 -1
  17. package/docs/functions/isValidFilename.md +1 -1
  18. package/docs/functions/isValidFilepath.md +1 -1
  19. package/docs/functions/normalizeIncludeFiles.md +2 -2
  20. package/docs/functions/parseFrontMatter.md +1 -1
  21. package/docs/functions/parseYaml.md +2 -2
  22. package/docs/functions/reControlCharsRegex.md +1 -1
  23. package/docs/functions/registerYamlTag.md +1 -1
  24. package/docs/functions/removeLeadingEmptyLines.md +1 -1
  25. package/docs/functions/sanitizeFilename.md +1 -1
  26. package/docs/functions/sanitizeFilepath.md +1 -1
  27. package/docs/functions/sleep.md +1 -1
  28. package/docs/functions/stringifyYaml.md +2 -2
  29. package/docs/functions/toCamelCase.md +1 -1
  30. package/docs/functions/toCapitalCase.md +1 -1
  31. package/docs/functions/toPascalCase.md +1 -1
  32. package/docs/functions/traverseFolder.md +1 -1
  33. package/docs/functions/traverseFolderSync.md +1 -1
  34. package/docs/functions/yieldExec.md +1 -1
  35. package/docs/interfaces/BinarySemaphoreAcquireOptions.md +2 -2
  36. package/docs/interfaces/BinarySemaphoreOptions.md +5 -5
  37. package/docs/interfaces/BinarySemaphoreReleaseOptions.md +2 -2
  38. package/docs/interfaces/BinarySemaphoreReleaserFunc.md +3 -3
  39. package/docs/interfaces/IncludeFiles.md +3 -3
  40. package/docs/interfaces/LoadConfigFileOptions.md +3 -3
  41. package/docs/interfaces/SanitizeFilenameOptions.md +3 -3
  42. package/docs/interfaces/SemaphoreOptions.md +7 -7
  43. package/docs/interfaces/SemaphoreTaskItem.md +6 -6
  44. package/docs/type-aliases/SemaphoreIsReadyFuncType.md +1 -1
  45. package/docs/type-aliases/StringifyFunc.md +1 -1
  46. package/docs/type-aliases/TraverseFolderHandler.md +1 -1
  47. package/docs/type-aliases/TraverseFolderSyncHandler.md +1 -1
  48. package/docs/variables/DefaultAllTextFiles.md +1 -1
  49. package/docs/variables/DefaultAsyncSemaphoreCapacity.md +1 -1
  50. package/docs/variables/FilenameReservedRegex.md +1 -1
  51. package/docs/variables/WindowsReservedNameRegex.md +1 -1
  52. package/package.json +18 -18
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var t,e=Object.create,i=Object.defineProperty,s=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,n=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,u=(t,e,n,u)=>{if(e&&"object"==typeof e||"function"==typeof e)for(let c of r(e))o.call(t,c)||c===n||i(t,c,{get:()=>e[c],enumerable:!(u=s(e,c))||u.enumerable});return t},c=(t,s,r)=>(r=null!=t?e(n(t)):{},u(!s&&t&&t.__esModule?r:i(r,"default",{value:t,enumerable:!0}),t)),h={};((t,e)=>{for(var s in e)i(t,s,{get:e[s],enumerable:!0})})(h,{BinarySemaphore:()=>ft,ConfigFile:()=>q,DefaultAllTextFiles:()=>R,DefaultAsyncSemaphoreCapacity:()=>ht,Deque:()=>it,FilenameReservedRegex:()=>_,IntSet:()=>st,RateLimit:()=>pt,Semaphore:()=>mt,SignalGate:()=>yt,WindowsReservedNameRegex:()=>B,arrayHasAll:()=>tt,extNameLevel:()=>X,filenameReservedRegex:()=>Z,findPort:()=>gt,getMultiLevelExtname:()=>p,glob:()=>A,isStringIn:()=>E,isValidFilename:()=>H,isValidFilepath:()=>W,normalizeIncludeFiles:()=>C,parseFrontMatter:()=>x,parseYaml:()=>g,reControlCharsRegex:()=>G,registerYamlTag:()=>v,removeLeadingEmptyLines:()=>b,sanitizeFilename:()=>K,sanitizeFilepath:()=>Q,sleep:()=>rt,stringifyYaml:()=>w,toCamelCase:()=>L,toCapitalCase:()=>M,toPascalCase:()=>D,traverseFolder:()=>T,traverseFolderSync:()=>z,yieldExec:()=>nt}),module.exports=(t=h,u(i({},"__esModule",{value:!0}),t));var a=require("fs"),l=c(require("path")),f=require("load-config-file"),m=c(require("path"));function p(t,e=1){let i="";for(;e--;){const e=m.default.extname(t);if(!e)break;i=e+i,t=m.default.basename(t,e)}return i}var d=require("yaml"),y=[];function v(t){Array.isArray(t)||(t=[t]);for(const e of t){-1===y.indexOf(e)&&y.push(e)}}function g(t,e){if(e)if(e.customTags){if(Array.isArray(e.customTags))e.customTags=y.concat(e.customTags);else if("function"==typeof e.customTags){const t=e.customTags;e.customTags=e=>t(y.concat(e))}}else e.customTags=y;else e={customTags:y};return(0,d.parse)(t,e)}function w(t,e){if(e)if(e.customTags){if(Array.isArray(e.customTags))e.customTags=y.concat(e.customTags);else if("function"==typeof e.customTags){const t=e.customTags;e.customTags=e=>t(y.concat(e))}}else e.customTags=y;else e={customTags:y};return(0,d.stringify)(t,e)}function b(t){const e=/^\s*(#[^\r\n]*)?[\r\n]+/;let i;for(;null!==(i=e.exec(t))&&((t=t.substring(i[0].length)).startsWith("\n")||t.startsWith("\r")||t.trimStart().startsWith("#")););return t}var F="---";function x(t,e=F){const i=e.length,s=b(t);if(s.startsWith(e)&&("\n"===s[e.length]||"\r"===s[e.length])){let t=s.indexOf("\n"+e,i);if(-1!==t){const r=s.slice(i,t);for(t+=e.length+1;"\n"===s[t]||"\r"===s[t];)t++;const n=s.slice(t);return{data:g(r)||{},content:n}}}return{data:{},content:t}}var q=class{static register(t,e,i){f.Config.register(t,e),"string"==typeof t&&(t=[t]);for(const e of t)this.stringifys[e]=i}static loadSync(t,e){return function(t,{extLevel:e=1,externalFile:i}={}){t=k(t,e);let s=f.Config.loadSync(t);if(!s&&i){if(!l.default.isAbsolute(i)){const e=l.default.dirname(t);i=l.default.join(e,i)}if((0,a.existsSync)(i)){const t=x((0,a.readFileSync)(i,"utf8")).data;Object.keys(t).length&&(s=t)}}return s}(t,e)}static saveSync(t,e,i){return function(t,e,{extLevel:i=1}={}){const s=function(t,e=1){"."===t[0]&&e++;let i=p(t,e);(!i||i.split(".").length<=1)&&(t+=".yaml",i=".yaml");const s=new String(t);return s.extname=i,s}(t,i),r=s.extname;t=s.toString();const n=q.stringifys[r];if(!n)throw new Error(`${t} unsupported mime type: ${r}`);e=n(e);const o=l.default.dirname(t);(0,a.existsSync)(o)||(0,a.mkdirSync)(o,{recursive:!0});return(0,a.writeFileSync)(t,e,{encoding:"utf8"}),t}(t,e,i)}static existsSync(t,e){return t=k(t,e?.extLevel),f.Config.existsSync(t,e)}};function k(t,e=1){"."===t[0]&&e++;const i=p(t,e);return i&&i.split(".").length>1&&(t=t.slice(0,-i.length)),t}q.stringifys={},q.register([".yml",".yaml"],g,w),q.register([".json"],(function(t){return JSON.parse(t)}),(t=>JSON.stringify(t,null,2)));var S=require("@isdk/glob"),j=c(require("path"));function A(t,e,i){return i&&(t=j.default.relative(i,t)),(0,S.globMatch)(t,e)}function E(t,e){return"string"==typeof e&&(e=[e]),-1!==e.indexOf(t)}var R=["**/*.((j|t)s?(x)|m(j|t)s)?(x)","**/*.(md|markdown|txt|?(x)htm?(l)|yaml|yml|xml|json|bat|sh|bash|zsh|ini|css|scss|less|sass|py|rb|php|go|java|c|cpp|h|hpp|hxx|rust|zig)"];function C(t,e=[]){if(t)if(Array.isArray(t))t=[...t];else{const i=t.include||[],s=t.exclude||[];0===i.length&&i.push(...e),t=[...i];for(const e of s)t.push(`!${e}`)}else t=[...e];return 0===t.length&&t.push(...e),t}var O=require("fs/promises"),$=require("fs"),P=c(require("path"));async function T(t,e){const i=await(0,O.readdir)(t,{withFileTypes:!0});for(const s of i){const i=P.default.join(t,s.name);try{if(s.isDirectory()){await e(i,s)||await T(i,e)}else{if(!0===await e(i,s))break}}catch(t){console.error(`Error processing file: ${i}`),console.error(t)}}}function z(t,e){const i=(0,$.readdirSync)(t,{withFileTypes:!0});for(const s of i){const i=P.default.join(t,s.name);try{if(s.isDirectory()){e(i,s)||T(i,e)}else{if(!0===e(i,s))break}}catch(t){console.error(`Error processing file: ${i}`),console.error(t)}}}function D(t){if(!t)return"";return t.replace(/[-_ ]+/g," ").split(" ").filter(Boolean).map((t=>{let e=t.charAt(0).toUpperCase();t=t.slice(1);let i=0;for(;/[A-Z]/.test(t[i]);)i++;return e+=i?t.slice(0,i).toLowerCase()+t.slice(i):t,e})).join("")}function L(t){return(t=D(t)).charAt(0).toLowerCase()+t.slice(1)}function M(t){if(!t)return"";return t.replace(/[-_ ]+/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").split(" ").filter(Boolean).map((t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase())).join(" ")}var N=c(require("path")),I=require("@isdk/common-error"),_=/[<>:"/\\|?*\u0000-\u001F]/,B=/^(con|prn|aux|nul|com\d|lpt\d)$/i,J=100,Y=/^\.+(\\|\/)|^\.+$/,U=/\.+$/,V=/[\u0000-\u001F\u0080-\u009F\u200E\u200F\u202A-\u202E\u2066-\u2069]/;function Z(){return new RegExp(_.source,"g")}function G(){return new RegExp(V.source,"g")}function H(t){return t&&!(_.test(t)||G().test(t)||Y.test(t)||U.test(t))}function W(t){const e=t.split(N.default.sep);return("/"===t[0]||e[0]&&N.default.dirname(e[0])===e[0])&&e.shift(),e.every(H)}function K(t,e={}){const i=e.replacement||"!";if((_.test(i)||V.test(i))&&(0,I.throwError)("Replacement string cannot contain reserved filename characters","sanitizeFilename",I.ErrorCode.InvalidArgument),i.length>0){const e=/([<>:"/\\|?*\u0000-\u001F]){2,}/;t=t.replace(e,"$1")}if(t=(t=(t=(t=(t=t.normalize("NFD")).replace(Y,i)).replace(Z(),i)).replace(G(),i)).replace(U,""),i.length>0){"."===t[0]||"."!==t[0]||(t=i+t),"."===t[t.length-1]&&(t+=i)}t=B.test(t)?t+i:t;const s="number"==typeof e.maxLength?e.maxLength:J;if(t.length>s){const e=t.lastIndexOf(".");if(-1===e)t=t.slice(0,s);else{const i=t.slice(0,e),r=t.slice(e);t=i.slice(0,Math.max(1,s-r.length))+r}}return t}function Q(t,e={}){const i=t.split(N.default.sep);let s;("/"===t[0]||i[0]&&N.default.dirname(i[0])===i[0])&&(s=i.shift());const r=i.map((t=>K(t,e)));return void 0!==s&&r.unshift(s),r.join(N.default.sep)}function X(t){return t.split(".").length-1}function tt(t,e){const i=new Set(e),s=new Set;for(const e of t)if(i.has(e)&&(s.add(e),s.size===i.size))return!0;return s.size===i.size}function et(t=0){return e=Math.min(Math.max(16,t),1073741824),e>>>=0,e-=1,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,1+(e|=e>>16);var e}var it=class extends Array{constructor(t,e){Array.isArray(t)?(super(...t),this._length=t.length,t=void 0):(super(),this._length=0),this._capacity=et(t),this._front=0,this._disableAutoResize=e}push(t){let e=this._length;this.checkCapacity(e+1);const i=this._front+e&this._capacity-1;return this[i]=t,++e<=this._capacity&&(this._length=e),i}unshift(t){let e=this._length;this.checkCapacity(++e);const i=this._capacity,s=(this._front-1&i-1^i)-i;return this[s]=t,this._front=s,e<=this._capacity&&(this._length=e),s}pop(t){let e=this._length;if(0===e)return;let i=this._front+e-1&this._capacity-1,s=this[i];for(;--e>0&&t&&null==s;)i--,s=this[i];return this[i]=void 0,this._length=e,s}shift(t){let e=this._length;if(0===e)return;let i=this._front,s=this[i];for(;--e>0&&t&&null==s;)i=i+1&this._capacity-1,s=this[i];return this[i]=void 0,this._front=i+1&this._capacity-1,this._length=e,s}get size(){return this._length}get(t){let e;if(t===(0|t)){const i=this._length;t<0&&(t+=i),t>=0&&t<i&&(e=this[this._front+t&this._capacity-1])}return e}peekBack(){const t=this._length;if(0===t)return;return this[this._front+t-1&this._capacity-1]}peekFront(){if(0!==this._length)return this[this._front]}clear(){const t=this._length,e=this._front,i=this._capacity;for(let s=0;s<t;++s)this[e+s&i-1]=void 0;this._length=0,this._front=0}isEmpty(){return 0===this._length}removeAt(t){const e=this._length;if(t<0||t>=e)return;const i=this._front,s=this._capacity-1,r=i+t&s,n=this[r];if(t<e/2)this.copyWithin(i+1&s,i,i+t&s),this[i]=void 0,this._front=i+1&s;else{this.copyWithin(r,r+1&s,i+e&s);this[i+e-1&s]=void 0}return this._length=e-1,n}checkCapacity(t){this._capacity<t&&!this._disableAutoResize&&this.resizeTo(et(1.5*this._capacity+16))}resizeTo(t){const e=this._capacity;this._capacity=t;const i=this._front,s=this._length;if(i+s>e){!function(t,e,i,s,r){for(let n=0;n<r;++n)i[n+s]=t[n+e],t[n+e]=void 0}(this,0,this,e,i+s&e-1)}}},st=class t{constructor(t=0){this.bitField=t}static has(t,e){return!!(t&1<<e)}static add(t,e){return t|1<<e}static delete(t,e){return t&~(1<<e)}add(t){return this.bitField|=1<<t,this}delete(t){return this.bitField&=~(1<<t),this}has(e){return t.has(this.bitField,e)}clear(){return this.bitField=0,this}valueOf(){return this.bitField}toString(){return this.bitField.toString()}toJSON(){return this.bitField}};async function rt(t){return new Promise((e=>setTimeout(e,t)))}async function nt(){return new Promise((t=>{setImmediate(t)}))}var ot=require("util-ex"),ut=require("events-ex"),ct=require("@isdk/common-error"),ht=32;function at(t){return"function"==typeof t}function lt(){return"1"}var ft=class{constructor(t={}){const{initFn:e=lt,pauseFn:i,resumeFn:s,capacity:r=ht}=t;if(at(i)!==at(s))throw new Error("pauseFn and resumeFn must be both set for pausing");this.waiting=new it(r),this.emitter=new ut.EventEmitter,this.useDefaultTokens=e===lt,this.pauseFn=i,this.resumeFn=s,this.initTokenFn=e,this.paused=!1,this._activeCount=0,this.initFree(t),this.init(t)}initFree(t){this.free=this.initTokenFn()}onReleased(t){const e=t?.token,i=this.waiting.shift(!0);i?this._dispatchTask(i,t):(this.resumeFn&&this.paused&&(this.paused=!1,this.resumeFn()),this.unlock(e))}init(t){this.emitter.on("release",(t=>{this.onReleased(t)}))}_newReleaser(t){let e=!1;const i=()=>{e||(e=!0,this.release(t))};return t&&Object.assign(i,t),i}_dispatchTask(t,e){const{resolve:i}=t;i(this._newReleaser(e))}lock(t){let e=this.free;if(e)return this.free=void 0,e}unlock(t){this.free=this.useDefaultTokens?"1":t??this.initTokenFn()}tryAcquire(t){return this.lock(t)}async acquire(t){this._activeCount++;const e=t?.signal,i=t=>{this.pauseFn&&!this.paused&&(this.paused=!0,this.pauseFn());const i=this.waiting.push(t),s=t.reject;return e&&e.addEventListener("abort",(()=>{this.waiting[i]=void 0;const t=e.reason instanceof Error?e.reason:new ct.AbortError(e.reason||"aborted");e.alreadyRejected=!0,s(t)})),i};let s=this.tryAcquire(t);const r=s&&(0,ot.isAsync)(s),n=e=>new Promise(((s,r)=>{const n={...t,resolve:s,reject:r,token:e};void 0===e?i(n):this._dispatchTask(n,{...t,token:e})}));return r?s.then((t=>n(t))):n(s)}release(t){this._activeCount--,this.emitter.emit("release",t)}drain(){const t=[this.acquire()];return Promise.all(t)}abort(t){let e;for(;e=this.waiting.shift(!0);)e.reject(new ct.AbortError(t))}get activeCount(){return this._activeCount}get pendingCount(){return this.waiting.size}},mt=class extends ft{constructor(t,e){if("number"==typeof t)(e=e||{}).maxConcurrency=t;else{if("number"!=typeof(e=t).maxConcurrency)throw new Error("maxConcurrency must be set");t=e.maxConcurrency}super(e),this.maxConcurrency=e.maxConcurrency,e.isReadyFn&&(this.isReady=e.isReadyFn)}initFree(t){const e=t.maxConcurrency=Math.max(1,t.maxConcurrency);this.free=new it(e);for(let t=0;t<e;t++)this.free.push(this.initTokenFn())}tryAcquire(t){let e=this.isReady;if(e&&(0,ot.isAsync)(e)){return e instanceof Promise||(e=e()),e.then((e=>{if(e)return this.lock(t)}))}if(!e||e())return this.lock(t)}unlock(t){this.free.push(this.useDefaultTokens?"1":t??this.initTokenFn())}lock(t){return this.free.pop()}drain(){const t=new Array(this.maxConcurrency);for(let e=0;e<this.maxConcurrency;e++)t[e]=this.acquire();return Promise.all(t)}};function pt(t,{timeUnit:e=1e3,uniformDistribution:i=!1}={}){const s=new mt(i?1:t),r=i?e/t:e;return async function(){await s.acquire(),setTimeout((()=>s.release()),r)}}var dt=require("@isdk/common-error"),yt=class{constructor(){this._isSignaled=!1,this.waitQueue=[]}get signaled(){return this._isSignaled}signal(t){if(this._isSignaled)return;this._isSignaled=!0,this._signalValue=t;const e=this.waitQueue.slice();for(this.waitQueue.length=0;e.length>0;){const t=e.shift();t?.resolve(this._signalValue)}}reset(){this._isSignaled=!1,this._signalValue=void 0,this.waitQueue.length=0}abort(t){if(this.waitQueue.length){const e=this.waitQueue.slice();this.waitQueue.length=0;const i=new dt.AbortError(t);for(;e.length>0;){const{reject:t}=e.shift();t(i)}}}async wait(){return new Promise(((t,e)=>{this._isSignaled?t(this._signalValue):this.waitQueue.push({resolve:t,reject:e})}))}},vt=c(require("net"));async function gt(t,e=10){return new Promise(((i,s)=>{void 0===t?t=0:("string"==typeof t&&(t=parseInt(t)),t>=0||(t=0));const r=vt.default.createServer();r.on("error",(i=>{"EADDRINUSE"===i.code&&(t++,--e>0)?r.listen(t):s(i)})),r.on("listening",(async()=>{const t=r.address().port;r.close((e=>{e?s(e):i(t)}))})),r.listen(t)}))}
1
+ "use strict";var t,e=Object.create,i=Object.defineProperty,s=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,n=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,u=(t,e,n,u)=>{if(e&&"object"==typeof e||"function"==typeof e)for(let c of r(e))o.call(t,c)||c===n||i(t,c,{get:()=>e[c],enumerable:!(u=s(e,c))||u.enumerable});return t},c=(t,s,r)=>(r=null!=t?e(n(t)):{},u(!s&&t&&t.__esModule?r:i(r,"default",{value:t,enumerable:!0}),t)),h={};((t,e)=>{for(var s in e)i(t,s,{get:e[s],enumerable:!0})})(h,{BinarySemaphore:()=>ft,ConfigFile:()=>q,DefaultAllTextFiles:()=>R,DefaultAsyncSemaphoreCapacity:()=>ht,Deque:()=>it,FilenameReservedRegex:()=>_,IntSet:()=>st,RateLimit:()=>pt,Semaphore:()=>mt,SignalGate:()=>yt,WindowsReservedNameRegex:()=>B,arrayHasAll:()=>tt,extNameLevel:()=>X,filenameReservedRegex:()=>Z,findPort:()=>gt,getMultiLevelExtname:()=>p,glob:()=>A,isStringIn:()=>E,isValidFilename:()=>H,isValidFilepath:()=>W,normalizeIncludeFiles:()=>C,parseFrontMatter:()=>x,parseYaml:()=>g,reControlCharsRegex:()=>G,registerYamlTag:()=>v,removeLeadingEmptyLines:()=>b,sanitizeFilename:()=>K,sanitizeFilepath:()=>Q,sleep:()=>rt,stringifyYaml:()=>w,toCamelCase:()=>L,toCapitalCase:()=>M,toPascalCase:()=>D,traverseFolder:()=>T,traverseFolderSync:()=>z,yieldExec:()=>nt}),module.exports=(t=h,u(i({},"__esModule",{value:!0}),t));var a=require("fs"),l=c(require("path")),f=require("load-config-file"),m=c(require("path"));function p(t,e=1){let i="";for(;e--;){const e=m.default.extname(t);if(!e)break;i=e+i,t=m.default.basename(t,e)}return i}var d=require("yaml"),y=[];function v(t){Array.isArray(t)||(t=[t]);for(const e of t){-1===y.indexOf(e)&&y.push(e)}}function g(t,e){if(e)if(e.customTags){if(Array.isArray(e.customTags))e.customTags=y.concat(e.customTags);else if("function"==typeof e.customTags){const t=e.customTags;e.customTags=e=>t(y.concat(e))}}else e.customTags=y;else e={customTags:y};return(0,d.parse)(t,e)}function w(t,e){if(e)if(e.customTags){if(Array.isArray(e.customTags))e.customTags=y.concat(e.customTags);else if("function"==typeof e.customTags){const t=e.customTags;e.customTags=e=>t(y.concat(e))}}else e.customTags=y;else e={customTags:y};return(0,d.stringify)(t,e)}function b(t){const e=/^\s*(#[^\r\n]*)?[\r\n]+/;let i;for(;null!==(i=e.exec(t))&&((t=t.substring(i[0].length)).startsWith("\n")||t.startsWith("\r")||t.trimStart().startsWith("#")););return t}var F="---";function x(t,e=F){const i=e.length,s=b(t);if(s.startsWith(e)&&("\n"===s[e.length]||"\r"===s[e.length])){let t=s.indexOf("\n"+e,i);if(-1!==t){const r=s.slice(i,t);for(t+=e.length+1;"\n"===s[t]||"\r"===s[t];)t++;const n=s.slice(t);return{data:g(r)||{},content:n}}}return{data:{},content:t}}var q=class{static register(t,e,i){f.Config.register(t,e),"string"==typeof t&&(t=[t]);for(const e of t)this.stringifys[e]=i}static loadSync(t,e){return function(t,{extLevel:e=1,externalFile:i}={}){t=k(t,e);let s=f.Config.loadSync(t);if(!s&&i){if(!l.default.isAbsolute(i)){const e=l.default.dirname(t);i=l.default.join(e,i)}if((0,a.existsSync)(i)){const t=x((0,a.readFileSync)(i,"utf8")).data;Object.keys(t).length&&(s=t)}}return s}(t,e)}static saveSync(t,e,i){return function(t,e,{extLevel:i=1}={}){const s=function(t,e=1){"."===t[0]&&e++;let i=p(t,e);(!i||i.split(".").length<=1)&&(t+=".yaml",i=".yaml");const s=new String(t);return s.extname=i,s}(t,i),r=s.extname;t=s.toString();const n=q.stringifys[r];if(!n)throw new Error(`${t} unsupported mime type: ${r}`);e=n(e);const o=l.default.dirname(t);(0,a.existsSync)(o)||(0,a.mkdirSync)(o,{recursive:!0});return(0,a.writeFileSync)(t,e,{encoding:"utf8"}),t}(t,e,i)}static existsSync(t,e){return t=k(t,e?.extLevel),f.Config.existsSync(t,e)}};function k(t,e=1){"."===t[0]&&e++;const i=p(t,e);return i&&i.split(".").length>1&&(t=t.slice(0,-i.length)),t}q.stringifys={},q.register([".yml",".yaml"],g,w),q.register([".json"],function(t){return JSON.parse(t)},t=>JSON.stringify(t,null,2));var S=require("@isdk/glob"),j=c(require("path"));function A(t,e,i){return i&&(t=j.default.relative(i,t)),(0,S.globMatch)(t,e)}function E(t,e){return"string"==typeof e&&(e=[e]),-1!==e.indexOf(t)}var R=["**/*.((j|t)s?(x)|m(j|t)s)?(x)","**/*.(md|markdown|txt|?(x)htm?(l)|yaml|yml|xml|json|bat|sh|bash|zsh|ini|css|scss|less|sass|py|rb|php|go|java|c|cpp|h|hpp|hxx|rust|zig)"];function C(t,e=[]){if(t)if(Array.isArray(t))t=[...t];else{const i=t.include||[],s=t.exclude||[];0===i.length&&i.push(...e),t=[...i];for(const e of s)t.push(`!${e}`)}else t=[...e];return 0===t.length&&t.push(...e),t}var O=require("fs/promises"),$=require("fs"),P=c(require("path"));async function T(t,e){const i=await(0,O.readdir)(t,{withFileTypes:!0});for(const s of i){const i=P.default.join(t,s.name);try{if(s.isDirectory()){await e(i,s)||await T(i,e)}else{if(!0===await e(i,s))break}}catch(t){console.error(`Error processing file: ${i}`),console.error(t)}}}function z(t,e){const i=(0,$.readdirSync)(t,{withFileTypes:!0});for(const s of i){const i=P.default.join(t,s.name);try{if(s.isDirectory()){e(i,s)||T(i,e)}else{if(!0===e(i,s))break}}catch(t){console.error(`Error processing file: ${i}`),console.error(t)}}}function D(t){if(!t)return"";return t.replace(/[-_ ]+/g," ").split(" ").filter(Boolean).map(t=>{let e=t.charAt(0).toUpperCase();t=t.slice(1);let i=0;for(;/[A-Z]/.test(t[i]);)i++;return e+=i?t.slice(0,i).toLowerCase()+t.slice(i):t,e}).join("")}function L(t){return(t=D(t)).charAt(0).toLowerCase()+t.slice(1)}function M(t){if(!t)return"";return t.replace(/[-_ ]+/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").split(" ").filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" ")}var N=c(require("path")),I=require("@isdk/common-error"),_=/[<>:"/\\|?*\u0000-\u001F]/,B=/^(con|prn|aux|nul|com\d|lpt\d)$/i,J=100,Y=/^\.+(\\|\/)|^\.+$/,U=/\.+$/,V=/[\u0000-\u001F\u0080-\u009F\u200E\u200F\u202A-\u202E\u2066-\u2069]/;function Z(){return new RegExp(_.source,"g")}function G(){return new RegExp(V.source,"g")}function H(t){return t&&!(_.test(t)||G().test(t)||Y.test(t)||U.test(t))}function W(t){const e=t.split(N.default.sep);return("/"===t[0]||e[0]&&N.default.dirname(e[0])===e[0])&&e.shift(),e.every(H)}function K(t,e={}){const i=e.replacement||"!";if((_.test(i)||V.test(i))&&(0,I.throwError)("Replacement string cannot contain reserved filename characters","sanitizeFilename",I.ErrorCode.InvalidArgument),i.length>0){const e=/([<>:"/\\|?*\u0000-\u001F]){2,}/;t=t.replace(e,"$1")}if(t=(t=(t=(t=(t=t.normalize("NFD")).replace(Y,i)).replace(Z(),i)).replace(G(),i)).replace(U,""),i.length>0){"."===t[0]||"."!==t[0]||(t=i+t),"."===t[t.length-1]&&(t+=i)}t=B.test(t)?t+i:t;const s="number"==typeof e.maxLength?e.maxLength:J;if(t.length>s){const e=t.lastIndexOf(".");if(-1===e)t=t.slice(0,s);else{const i=t.slice(0,e),r=t.slice(e);t=i.slice(0,Math.max(1,s-r.length))+r}}return t}function Q(t,e={}){const i=t.split(N.default.sep);let s;("/"===t[0]||i[0]&&N.default.dirname(i[0])===i[0])&&(s=i.shift());const r=i.map(t=>K(t,e));return void 0!==s&&r.unshift(s),r.join(N.default.sep)}function X(t){return t.split(".").length-1}function tt(t,e){const i=new Set(e),s=new Set;for(const e of t)if(i.has(e)&&(s.add(e),s.size===i.size))return!0;return s.size===i.size}function et(t=0){return e=Math.min(Math.max(16,t),1073741824),e>>>=0,e-=1,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,1+(e|=e>>16);var e}var it=class extends Array{constructor(t,e){Array.isArray(t)?(super(...t),this._length=t.length,t=void 0):(super(),this._length=0),this._capacity=et(t),this._front=0,this._disableAutoResize=e}push(t){let e=this._length;this.checkCapacity(e+1);const i=this._front+e&this._capacity-1;return this[i]=t,++e<=this._capacity&&(this._length=e),i}unshift(t){let e=this._length;this.checkCapacity(++e);const i=this._capacity,s=(this._front-1&i-1^i)-i;return this[s]=t,this._front=s,e<=this._capacity&&(this._length=e),s}pop(t){let e=this._length;if(0===e)return;let i=this._front+e-1&this._capacity-1,s=this[i];for(;--e>0&&t&&null==s;)i--,s=this[i];return this[i]=void 0,this._length=e,s}shift(t){let e=this._length;if(0===e)return;let i=this._front,s=this[i];for(;--e>0&&t&&null==s;)i=i+1&this._capacity-1,s=this[i];return this[i]=void 0,this._front=i+1&this._capacity-1,this._length=e,s}get size(){return this._length}get(t){let e;if(t===(0|t)){const i=this._length;t<0&&(t+=i),t>=0&&t<i&&(e=this[this._front+t&this._capacity-1])}return e}peekBack(){const t=this._length;if(0===t)return;return this[this._front+t-1&this._capacity-1]}peekFront(){if(0!==this._length)return this[this._front]}clear(){const t=this._length,e=this._front,i=this._capacity;for(let s=0;s<t;++s)this[e+s&i-1]=void 0;this._length=0,this._front=0}isEmpty(){return 0===this._length}removeAt(t){const e=this._length;if(t<0||t>=e)return;const i=this._front,s=this._capacity-1,r=i+t&s,n=this[r];if(t<e/2)this.copyWithin(i+1&s,i,i+t&s),this[i]=void 0,this._front=i+1&s;else{this.copyWithin(r,r+1&s,i+e&s);this[i+e-1&s]=void 0}return this._length=e-1,n}checkCapacity(t){this._capacity<t&&!this._disableAutoResize&&this.resizeTo(et(1.5*this._capacity+16))}resizeTo(t){const e=this._capacity;this._capacity=t;const i=this._front,s=this._length;if(i+s>e){!function(t,e,i,s,r){for(let n=0;n<r;++n)i[n+s]=t[n+e],t[n+e]=void 0}(this,0,this,e,i+s&e-1)}}},st=class t{constructor(t=0){this.bitField=t}static has(t,e){return!!(t&1<<e)}static add(t,e){return t|1<<e}static delete(t,e){return t&~(1<<e)}add(t){return this.bitField|=1<<t,this}delete(t){return this.bitField&=~(1<<t),this}has(e){return t.has(this.bitField,e)}clear(){return this.bitField=0,this}valueOf(){return this.bitField}toString(){return this.bitField.toString()}toJSON(){return this.bitField}};async function rt(t){return new Promise(e=>setTimeout(e,t))}async function nt(){return new Promise(t=>{setImmediate(t)})}var ot=require("util-ex"),ut=require("events-ex"),ct=require("@isdk/common-error"),ht=32;function at(t){return"function"==typeof t}function lt(){return"1"}var ft=class{constructor(t={}){const{initFn:e=lt,pauseFn:i,resumeFn:s,capacity:r=ht}=t;if(at(i)!==at(s))throw new Error("pauseFn and resumeFn must be both set for pausing");this.waiting=new it(r),this.emitter=new ut.EventEmitter,this.useDefaultTokens=e===lt,this.pauseFn=i,this.resumeFn=s,this.initTokenFn=e,this.paused=!1,this._activeCount=0,this.initFree(t),this.init(t)}initFree(t){this.free=this.initTokenFn()}onReleased(t){const e=t?.token,i=this.waiting.shift(!0);i?this._dispatchTask(i,t):(this.resumeFn&&this.paused&&(this.paused=!1,this.resumeFn()),this.unlock(e))}init(t){this.emitter.on("release",t=>{this.onReleased(t)})}_newReleaser(t){let e=!1;const i=()=>{e||(e=!0,this.release(t))};return t&&Object.assign(i,t),i}_dispatchTask(t,e){const{resolve:i}=t;i(this._newReleaser(e))}lock(t){let e=this.free;if(e)return this.free=void 0,e}unlock(t){this.free=this.useDefaultTokens?"1":t??this.initTokenFn()}tryAcquire(t){return this.lock(t)}async acquire(t){this._activeCount++;const e=t?.signal,i=t=>{this.pauseFn&&!this.paused&&(this.paused=!0,this.pauseFn());const i=this.waiting.push(t),s=t.reject;return e&&e.addEventListener("abort",()=>{this.waiting[i]=void 0;const t=e.reason instanceof Error?e.reason:new ct.AbortError(e.reason||"aborted");e.alreadyRejected=!0,s(t)}),i};let s=this.tryAcquire(t);const r=s&&(0,ot.isAsync)(s),n=e=>new Promise((s,r)=>{const n={...t,resolve:s,reject:r,token:e};void 0===e?i(n):this._dispatchTask(n,{...t,token:e})});return r?s.then(t=>n(t)):n(s)}release(t){this._activeCount--,this.emitter.emit("release",t)}drain(){const t=[this.acquire()];return Promise.all(t)}abort(t){let e;for(;e=this.waiting.shift(!0);)e.reject(new ct.AbortError(t))}get activeCount(){return this._activeCount}get pendingCount(){return this.waiting.size}},mt=class extends ft{constructor(t,e){if("number"==typeof t)(e=e||{}).maxConcurrency=t;else{if("number"!=typeof(e=t).maxConcurrency)throw new Error("maxConcurrency must be set");t=e.maxConcurrency}super(e),this.maxConcurrency=e.maxConcurrency,e.isReadyFn&&(this.isReady=e.isReadyFn)}initFree(t){const e=t.maxConcurrency=Math.max(1,t.maxConcurrency);this.free=new it(e);for(let t=0;t<e;t++)this.free.push(this.initTokenFn())}tryAcquire(t){let e=this.isReady;if(e&&(0,ot.isAsync)(e)){return e instanceof Promise||(e=e()),e.then(e=>{if(e)return this.lock(t)})}if(!e||e())return this.lock(t)}unlock(t){this.free.push(this.useDefaultTokens?"1":t??this.initTokenFn())}lock(t){return this.free.pop()}drain(){const t=new Array(this.maxConcurrency);for(let e=0;e<this.maxConcurrency;e++)t[e]=this.acquire();return Promise.all(t)}};function pt(t,{timeUnit:e=1e3,uniformDistribution:i=!1}={}){const s=new mt(i?1:t),r=i?e/t:e;return async function(){await s.acquire(),setTimeout(()=>s.release(),r)}}var dt=require("@isdk/common-error"),yt=class{constructor(){this._isSignaled=!1,this.waitQueue=[]}get signaled(){return this._isSignaled}signal(t){if(this._isSignaled)return;this._isSignaled=!0,this._signalValue=t;const e=this.waitQueue.slice();for(this.waitQueue.length=0;e.length>0;){const t=e.shift();t?.resolve(this._signalValue)}}reset(){this._isSignaled=!1,this._signalValue=void 0,this.waitQueue.length=0}abort(t){if(this.waitQueue.length){const e=this.waitQueue.slice();this.waitQueue.length=0;const i=new dt.AbortError(t);for(;e.length>0;){const{reject:t}=e.shift();t(i)}}}async wait(){return new Promise((t,e)=>{this._isSignaled?t(this._signalValue):this.waitQueue.push({resolve:t,reject:e})})}},vt=c(require("net"));async function gt(t,e=10){return new Promise((i,s)=>{void 0===t?t=0:("string"==typeof t&&(t=parseInt(t)),t>=0||(t=0));const r=vt.default.createServer();r.on("error",i=>{"EADDRINUSE"===i.code&&(t++,--e>0)?r.listen(t):s(i)}),r.on("listening",async()=>{const t=r.address().port;r.close(e=>{e?s(e):i(t)})}),r.listen(t)})}
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{existsSync as t,mkdirSync as s,readFileSync as i,writeFileSync as r}from"fs";import n from"path";import{Config as e}from"load-config-file";import o from"path";function h(t,s=1){let i="";for(;s--;){const s=o.extname(t);if(!s)break;i=s+i,t=o.basename(t,s)}return i}import{parse as c,stringify as u}from"yaml";var f=[];function a(t){Array.isArray(t)||(t=[t]);for(const s of t){-1===f.indexOf(s)&&f.push(s)}}function l(t,s){if(s)if(s.customTags){if(Array.isArray(s.customTags))s.customTags=f.concat(s.customTags);else if("function"==typeof s.customTags){const t=s.customTags;s.customTags=s=>t(f.concat(s))}}else s.customTags=f;else s={customTags:f};return c(t,s)}function m(t,s){if(s)if(s.customTags){if(Array.isArray(s.customTags))s.customTags=f.concat(s.customTags);else if("function"==typeof s.customTags){const t=s.customTags;s.customTags=s=>t(f.concat(s))}}else s.customTags=f;else s={customTags:f};return u(t,s)}function p(t){const s=/^\s*(#[^\r\n]*)?[\r\n]+/;let i;for(;null!==(i=s.exec(t))&&((t=t.substring(i[0].length)).startsWith("\n")||t.startsWith("\r")||t.trimStart().startsWith("#")););return t}function y(t,s="---"){const i=s.length,r=p(t);if(r.startsWith(s)&&("\n"===r[s.length]||"\r"===r[s.length])){let t=r.indexOf("\n"+s,i);if(-1!==t){const n=r.slice(i,t);for(t+=s.length+1;"\n"===r[t]||"\r"===r[t];)t++;const e=r.slice(t);return{data:l(n)||{},content:e}}}return{data:{},content:t}}var d=class{static register(t,s,i){e.register(t,s),"string"==typeof t&&(t=[t]);for(const s of t)this.stringifys[s]=i}static loadSync(s,r){return function(s,{extLevel:r=1,externalFile:o}={}){s=v(s,r);let h=e.loadSync(s);if(!h&&o){if(!n.isAbsolute(o)){const t=n.dirname(s);o=n.join(t,o)}if(t(o)){const t=y(i(o,"utf8")).data;Object.keys(t).length&&(h=t)}}return h}(s,r)}static saveSync(i,e,o){return function(i,e,{extLevel:o=1}={}){const c=function(t,s=1){"."===t[0]&&s++;let i=h(t,s);(!i||i.split(".").length<=1)&&(t+=".yaml",i=".yaml");const r=new String(t);return r.extname=i,r}(i,o),u=c.extname;i=c.toString();const f=d.stringifys[u];if(!f)throw new Error(`${i} unsupported mime type: ${u}`);e=f(e);const a=n.dirname(i);t(a)||s(a,{recursive:!0});return r(i,e,{encoding:"utf8"}),i}(i,e,o)}static existsSync(t,s){return t=v(t,s?.extLevel),e.existsSync(t,s)}};function v(t,s=1){"."===t[0]&&s++;const i=h(t,s);return i&&i.split(".").length>1&&(t=t.slice(0,-i.length)),t}d.stringifys={},d.register([".yml",".yaml"],l,m),d.register([".json"],(function(t){return JSON.parse(t)}),(t=>JSON.stringify(t,null,2)));import{globMatch as g}from"@isdk/glob";import w from"path";function b(t,s,i){return i&&(t=w.relative(i,t)),g(t,s)}function x(t,s){return"string"==typeof s&&(s=[s]),-1!==s.indexOf(t)}var k=["**/*.((j|t)s?(x)|m(j|t)s)?(x)","**/*.(md|markdown|txt|?(x)htm?(l)|yaml|yml|xml|json|bat|sh|bash|zsh|ini|css|scss|less|sass|py|rb|php|go|java|c|cpp|h|hpp|hxx|rust|zig)"];function F(t,s=[]){if(t)if(Array.isArray(t))t=[...t];else{const i=t.include||[],r=t.exclude||[];0===i.length&&i.push(...s),t=[...i];for(const s of r)t.push(`!${s}`)}else t=[...s];return 0===t.length&&t.push(...s),t}import{readdir as A}from"fs/promises";import{readdirSync as E}from"fs";import S from"path";async function $(t,s){const i=await A(t,{withFileTypes:!0});for(const r of i){const i=S.join(t,r.name);try{if(r.isDirectory()){await s(i,r)||await $(i,s)}else{if(!0===await s(i,r))break}}catch(t){console.error(`Error processing file: ${i}`),console.error(t)}}}function j(t,s){const i=E(t,{withFileTypes:!0});for(const r of i){const i=S.join(t,r.name);try{if(r.isDirectory()){s(i,r)||$(i,s)}else{if(!0===s(i,r))break}}catch(t){console.error(`Error processing file: ${i}`),console.error(t)}}}function P(t){if(!t)return"";return t.replace(/[-_ ]+/g," ").split(" ").filter(Boolean).map((t=>{let s=t.charAt(0).toUpperCase();t=t.slice(1);let i=0;for(;/[A-Z]/.test(t[i]);)i++;return s+=i?t.slice(0,i).toLowerCase()+t.slice(i):t,s})).join("")}function T(t){return(t=P(t)).charAt(0).toLowerCase()+t.slice(1)}function z(t){if(!t)return"";return t.replace(/[-_ ]+/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").split(" ").filter(Boolean).map((t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase())).join(" ")}import O from"path";import{ErrorCode as R,throwError as C}from"@isdk/common-error";var N=/[<>:"/\\|?*\u0000-\u001F]/,D=/^(con|prn|aux|nul|com\d|lpt\d)$/i,M=/^\.+(\\|\/)|^\.+$/,_=/\.+$/,q=/[\u0000-\u001F\u0080-\u009F\u200E\u200F\u202A-\u202E\u2066-\u2069]/;function B(){return new RegExp(N.source,"g")}function I(){return new RegExp(q.source,"g")}function J(t){return t&&!(N.test(t)||I().test(t)||M.test(t)||_.test(t))}function L(t){const s=t.split(O.sep);return("/"===t[0]||s[0]&&O.dirname(s[0])===s[0])&&s.shift(),s.every(J)}function U(t,s={}){const i=s.replacement||"!";if((N.test(i)||q.test(i))&&C("Replacement string cannot contain reserved filename characters","sanitizeFilename",R.InvalidArgument),i.length>0){const s=/([<>:"/\\|?*\u0000-\u001F]){2,}/;t=t.replace(s,"$1")}if(t=(t=(t=(t=(t=t.normalize("NFD")).replace(M,i)).replace(B(),i)).replace(I(),i)).replace(_,""),i.length>0){"."===t[0]||"."!==t[0]||(t=i+t),"."===t[t.length-1]&&(t+=i)}t=D.test(t)?t+i:t;const r="number"==typeof s.maxLength?s.maxLength:100;if(t.length>r){const s=t.lastIndexOf(".");if(-1===s)t=t.slice(0,r);else{const i=t.slice(0,s),n=t.slice(s);t=i.slice(0,Math.max(1,r-n.length))+n}}return t}function Z(t,s={}){const i=t.split(O.sep);let r;("/"===t[0]||i[0]&&O.dirname(i[0])===i[0])&&(r=i.shift());const n=i.map((t=>U(t,s)));return void 0!==r&&n.unshift(r),n.join(O.sep)}function G(t){return t.split(".").length-1}function H(t,s){const i=new Set(s),r=new Set;for(const s of t)if(i.has(s)&&(r.add(s),r.size===i.size))return!0;return r.size===i.size}function K(t=0){return s=Math.min(Math.max(16,t),1073741824),s>>>=0,s-=1,s|=s>>1,s|=s>>2,s|=s>>4,s|=s>>8,1+(s|=s>>16);var s}var Q=class extends Array{constructor(t,s){Array.isArray(t)?(super(...t),this._length=t.length,t=void 0):(super(),this._length=0),this._capacity=K(t),this._front=0,this._disableAutoResize=s}push(t){let s=this._length;this.checkCapacity(s+1);const i=this._front+s&this._capacity-1;return this[i]=t,++s<=this._capacity&&(this._length=s),i}unshift(t){let s=this._length;this.checkCapacity(++s);const i=this._capacity,r=(this._front-1&i-1^i)-i;return this[r]=t,this._front=r,s<=this._capacity&&(this._length=s),r}pop(t){let s=this._length;if(0===s)return;let i=this._front+s-1&this._capacity-1,r=this[i];for(;--s>0&&t&&null==r;)i--,r=this[i];return this[i]=void 0,this._length=s,r}shift(t){let s=this._length;if(0===s)return;let i=this._front,r=this[i];for(;--s>0&&t&&null==r;)i=i+1&this._capacity-1,r=this[i];return this[i]=void 0,this._front=i+1&this._capacity-1,this._length=s,r}get size(){return this._length}get(t){let s;if(t===(0|t)){const i=this._length;t<0&&(t+=i),t>=0&&t<i&&(s=this[this._front+t&this._capacity-1])}return s}peekBack(){const t=this._length;if(0===t)return;return this[this._front+t-1&this._capacity-1]}peekFront(){if(0!==this._length)return this[this._front]}clear(){const t=this._length,s=this._front,i=this._capacity;for(let r=0;r<t;++r)this[s+r&i-1]=void 0;this._length=0,this._front=0}isEmpty(){return 0===this._length}removeAt(t){const s=this._length;if(t<0||t>=s)return;const i=this._front,r=this._capacity-1,n=i+t&r,e=this[n];if(t<s/2)this.copyWithin(i+1&r,i,i+t&r),this[i]=void 0,this._front=i+1&r;else{this.copyWithin(n,n+1&r,i+s&r);this[i+s-1&r]=void 0}return this._length=s-1,e}checkCapacity(t){this._capacity<t&&!this._disableAutoResize&&this.resizeTo(K(1.5*this._capacity+16))}resizeTo(t){const s=this._capacity;this._capacity=t;const i=this._front,r=this._length;if(i+r>s){!function(t,s,i,r,n){for(let e=0;e<n;++e)i[e+r]=t[e+s],t[e+s]=void 0}(this,0,this,s,i+r&s-1)}}},V=class t{constructor(t=0){this.bitField=t}static has(t,s){return!!(t&1<<s)}static add(t,s){return t|1<<s}static delete(t,s){return t&~(1<<s)}add(t){return this.bitField|=1<<t,this}delete(t){return this.bitField&=~(1<<t),this}has(s){return t.has(this.bitField,s)}clear(){return this.bitField=0,this}valueOf(){return this.bitField}toString(){return this.bitField.toString()}toJSON(){return this.bitField}};async function W(t){return new Promise((s=>setTimeout(s,t)))}async function X(){return new Promise((t=>{setImmediate(t)}))}import{isAsync as Y}from"util-ex";import{EventEmitter as tt}from"events-ex";import{AbortError as st}from"@isdk/common-error";var it=32;function rt(t){return"function"==typeof t}function nt(){return"1"}var et=class{constructor(t={}){const{initFn:s=nt,pauseFn:i,resumeFn:r,capacity:n=it}=t;if(rt(i)!==rt(r))throw new Error("pauseFn and resumeFn must be both set for pausing");this.waiting=new Q(n),this.emitter=new tt,this.useDefaultTokens=s===nt,this.pauseFn=i,this.resumeFn=r,this.initTokenFn=s,this.paused=!1,this._activeCount=0,this.initFree(t),this.init(t)}initFree(t){this.free=this.initTokenFn()}onReleased(t){const s=t?.token,i=this.waiting.shift(!0);i?this._dispatchTask(i,t):(this.resumeFn&&this.paused&&(this.paused=!1,this.resumeFn()),this.unlock(s))}init(t){this.emitter.on("release",(t=>{this.onReleased(t)}))}_newReleaser(t){let s=!1;const i=()=>{s||(s=!0,this.release(t))};return t&&Object.assign(i,t),i}_dispatchTask(t,s){const{resolve:i}=t;i(this._newReleaser(s))}lock(t){let s=this.free;if(s)return this.free=void 0,s}unlock(t){this.free=this.useDefaultTokens?"1":t??this.initTokenFn()}tryAcquire(t){return this.lock(t)}async acquire(t){this._activeCount++;const s=t?.signal,i=t=>{this.pauseFn&&!this.paused&&(this.paused=!0,this.pauseFn());const i=this.waiting.push(t),r=t.reject;return s&&s.addEventListener("abort",(()=>{this.waiting[i]=void 0;const t=s.reason instanceof Error?s.reason:new st(s.reason||"aborted");s.alreadyRejected=!0,r(t)})),i};let r=this.tryAcquire(t);const n=r&&Y(r),e=s=>new Promise(((r,n)=>{const e={...t,resolve:r,reject:n,token:s};void 0===s?i(e):this._dispatchTask(e,{...t,token:s})}));return n?r.then((t=>e(t))):e(r)}release(t){this._activeCount--,this.emitter.emit("release",t)}drain(){const t=[this.acquire()];return Promise.all(t)}abort(t){let s;for(;s=this.waiting.shift(!0);)s.reject(new st(t))}get activeCount(){return this._activeCount}get pendingCount(){return this.waiting.size}},ot=class extends et{constructor(t,s){if("number"==typeof t)(s=s||{}).maxConcurrency=t;else{if("number"!=typeof(s=t).maxConcurrency)throw new Error("maxConcurrency must be set");t=s.maxConcurrency}super(s),this.maxConcurrency=s.maxConcurrency,s.isReadyFn&&(this.isReady=s.isReadyFn)}initFree(t){const s=t.maxConcurrency=Math.max(1,t.maxConcurrency);this.free=new Q(s);for(let t=0;t<s;t++)this.free.push(this.initTokenFn())}tryAcquire(t){let s=this.isReady;if(s&&Y(s)){return s instanceof Promise||(s=s()),s.then((s=>{if(s)return this.lock(t)}))}if(!s||s())return this.lock(t)}unlock(t){this.free.push(this.useDefaultTokens?"1":t??this.initTokenFn())}lock(t){return this.free.pop()}drain(){const t=new Array(this.maxConcurrency);for(let s=0;s<this.maxConcurrency;s++)t[s]=this.acquire();return Promise.all(t)}};function ht(t,{timeUnit:s=1e3,uniformDistribution:i=!1}={}){const r=new ot(i?1:t),n=i?s/t:s;return async function(){await r.acquire(),setTimeout((()=>r.release()),n)}}import{AbortError as ct}from"@isdk/common-error";var ut=class{constructor(){this._isSignaled=!1,this.waitQueue=[]}get signaled(){return this._isSignaled}signal(t){if(this._isSignaled)return;this._isSignaled=!0,this._signalValue=t;const s=this.waitQueue.slice();for(this.waitQueue.length=0;s.length>0;){const t=s.shift();t?.resolve(this._signalValue)}}reset(){this._isSignaled=!1,this._signalValue=void 0,this.waitQueue.length=0}abort(t){if(this.waitQueue.length){const s=this.waitQueue.slice();this.waitQueue.length=0;const i=new ct(t);for(;s.length>0;){const{reject:t}=s.shift();t(i)}}}async wait(){return new Promise(((t,s)=>{this._isSignaled?t(this._signalValue):this.waitQueue.push({resolve:t,reject:s})}))}};import ft from"net";async function at(t,s=10){return new Promise(((i,r)=>{void 0===t?t=0:("string"==typeof t&&(t=parseInt(t)),t>=0||(t=0));const n=ft.createServer();n.on("error",(i=>{"EADDRINUSE"===i.code&&(t++,--s>0)?n.listen(t):r(i)})),n.on("listening",(async()=>{const t=n.address().port;n.close((s=>{s?r(s):i(t)}))})),n.listen(t)}))}export{et as BinarySemaphore,d as ConfigFile,k as DefaultAllTextFiles,it as DefaultAsyncSemaphoreCapacity,Q as Deque,N as FilenameReservedRegex,V as IntSet,ht as RateLimit,ot as Semaphore,ut as SignalGate,D as WindowsReservedNameRegex,H as arrayHasAll,G as extNameLevel,B as filenameReservedRegex,at as findPort,h as getMultiLevelExtname,b as glob,x as isStringIn,J as isValidFilename,L as isValidFilepath,F as normalizeIncludeFiles,y as parseFrontMatter,l as parseYaml,I as reControlCharsRegex,a as registerYamlTag,p as removeLeadingEmptyLines,U as sanitizeFilename,Z as sanitizeFilepath,W as sleep,m as stringifyYaml,T as toCamelCase,z as toCapitalCase,P as toPascalCase,$ as traverseFolder,j as traverseFolderSync,X as yieldExec};
1
+ import{existsSync as t,mkdirSync as s,readFileSync as i,writeFileSync as r}from"fs";import n from"path";import{Config as e}from"load-config-file";import o from"path";function h(t,s=1){let i="";for(;s--;){const s=o.extname(t);if(!s)break;i=s+i,t=o.basename(t,s)}return i}import{parse as c,stringify as u}from"yaml";var f=[];function a(t){Array.isArray(t)||(t=[t]);for(const s of t){-1===f.indexOf(s)&&f.push(s)}}function l(t,s){if(s)if(s.customTags){if(Array.isArray(s.customTags))s.customTags=f.concat(s.customTags);else if("function"==typeof s.customTags){const t=s.customTags;s.customTags=s=>t(f.concat(s))}}else s.customTags=f;else s={customTags:f};return c(t,s)}function m(t,s){if(s)if(s.customTags){if(Array.isArray(s.customTags))s.customTags=f.concat(s.customTags);else if("function"==typeof s.customTags){const t=s.customTags;s.customTags=s=>t(f.concat(s))}}else s.customTags=f;else s={customTags:f};return u(t,s)}function p(t){const s=/^\s*(#[^\r\n]*)?[\r\n]+/;let i;for(;null!==(i=s.exec(t))&&((t=t.substring(i[0].length)).startsWith("\n")||t.startsWith("\r")||t.trimStart().startsWith("#")););return t}function y(t,s="---"){const i=s.length,r=p(t);if(r.startsWith(s)&&("\n"===r[s.length]||"\r"===r[s.length])){let t=r.indexOf("\n"+s,i);if(-1!==t){const n=r.slice(i,t);for(t+=s.length+1;"\n"===r[t]||"\r"===r[t];)t++;const e=r.slice(t);return{data:l(n)||{},content:e}}}return{data:{},content:t}}var d=class{static register(t,s,i){e.register(t,s),"string"==typeof t&&(t=[t]);for(const s of t)this.stringifys[s]=i}static loadSync(s,r){return function(s,{extLevel:r=1,externalFile:o}={}){s=v(s,r);let h=e.loadSync(s);if(!h&&o){if(!n.isAbsolute(o)){const t=n.dirname(s);o=n.join(t,o)}if(t(o)){const t=y(i(o,"utf8")).data;Object.keys(t).length&&(h=t)}}return h}(s,r)}static saveSync(i,e,o){return function(i,e,{extLevel:o=1}={}){const c=function(t,s=1){"."===t[0]&&s++;let i=h(t,s);(!i||i.split(".").length<=1)&&(t+=".yaml",i=".yaml");const r=new String(t);return r.extname=i,r}(i,o),u=c.extname;i=c.toString();const f=d.stringifys[u];if(!f)throw new Error(`${i} unsupported mime type: ${u}`);e=f(e);const a=n.dirname(i);t(a)||s(a,{recursive:!0});return r(i,e,{encoding:"utf8"}),i}(i,e,o)}static existsSync(t,s){return t=v(t,s?.extLevel),e.existsSync(t,s)}};function v(t,s=1){"."===t[0]&&s++;const i=h(t,s);return i&&i.split(".").length>1&&(t=t.slice(0,-i.length)),t}d.stringifys={},d.register([".yml",".yaml"],l,m),d.register([".json"],function(t){return JSON.parse(t)},t=>JSON.stringify(t,null,2));import{globMatch as g}from"@isdk/glob";import w from"path";function b(t,s,i){return i&&(t=w.relative(i,t)),g(t,s)}function x(t,s){return"string"==typeof s&&(s=[s]),-1!==s.indexOf(t)}var k=["**/*.((j|t)s?(x)|m(j|t)s)?(x)","**/*.(md|markdown|txt|?(x)htm?(l)|yaml|yml|xml|json|bat|sh|bash|zsh|ini|css|scss|less|sass|py|rb|php|go|java|c|cpp|h|hpp|hxx|rust|zig)"];function F(t,s=[]){if(t)if(Array.isArray(t))t=[...t];else{const i=t.include||[],r=t.exclude||[];0===i.length&&i.push(...s),t=[...i];for(const s of r)t.push(`!${s}`)}else t=[...s];return 0===t.length&&t.push(...s),t}import{readdir as A}from"fs/promises";import{readdirSync as E}from"fs";import S from"path";async function $(t,s){const i=await A(t,{withFileTypes:!0});for(const r of i){const i=S.join(t,r.name);try{if(r.isDirectory()){await s(i,r)||await $(i,s)}else{if(!0===await s(i,r))break}}catch(t){console.error(`Error processing file: ${i}`),console.error(t)}}}function j(t,s){const i=E(t,{withFileTypes:!0});for(const r of i){const i=S.join(t,r.name);try{if(r.isDirectory()){s(i,r)||$(i,s)}else{if(!0===s(i,r))break}}catch(t){console.error(`Error processing file: ${i}`),console.error(t)}}}function P(t){if(!t)return"";return t.replace(/[-_ ]+/g," ").split(" ").filter(Boolean).map(t=>{let s=t.charAt(0).toUpperCase();t=t.slice(1);let i=0;for(;/[A-Z]/.test(t[i]);)i++;return s+=i?t.slice(0,i).toLowerCase()+t.slice(i):t,s}).join("")}function T(t){return(t=P(t)).charAt(0).toLowerCase()+t.slice(1)}function z(t){if(!t)return"";return t.replace(/[-_ ]+/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").split(" ").filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" ")}import O from"path";import{ErrorCode as R,throwError as C}from"@isdk/common-error";var N=/[<>:"/\\|?*\u0000-\u001F]/,D=/^(con|prn|aux|nul|com\d|lpt\d)$/i,M=/^\.+(\\|\/)|^\.+$/,_=/\.+$/,q=/[\u0000-\u001F\u0080-\u009F\u200E\u200F\u202A-\u202E\u2066-\u2069]/;function B(){return new RegExp(N.source,"g")}function I(){return new RegExp(q.source,"g")}function J(t){return t&&!(N.test(t)||I().test(t)||M.test(t)||_.test(t))}function L(t){const s=t.split(O.sep);return("/"===t[0]||s[0]&&O.dirname(s[0])===s[0])&&s.shift(),s.every(J)}function U(t,s={}){const i=s.replacement||"!";if((N.test(i)||q.test(i))&&C("Replacement string cannot contain reserved filename characters","sanitizeFilename",R.InvalidArgument),i.length>0){const s=/([<>:"/\\|?*\u0000-\u001F]){2,}/;t=t.replace(s,"$1")}if(t=(t=(t=(t=(t=t.normalize("NFD")).replace(M,i)).replace(B(),i)).replace(I(),i)).replace(_,""),i.length>0){"."===t[0]||"."!==t[0]||(t=i+t),"."===t[t.length-1]&&(t+=i)}t=D.test(t)?t+i:t;const r="number"==typeof s.maxLength?s.maxLength:100;if(t.length>r){const s=t.lastIndexOf(".");if(-1===s)t=t.slice(0,r);else{const i=t.slice(0,s),n=t.slice(s);t=i.slice(0,Math.max(1,r-n.length))+n}}return t}function Z(t,s={}){const i=t.split(O.sep);let r;("/"===t[0]||i[0]&&O.dirname(i[0])===i[0])&&(r=i.shift());const n=i.map(t=>U(t,s));return void 0!==r&&n.unshift(r),n.join(O.sep)}function G(t){return t.split(".").length-1}function H(t,s){const i=new Set(s),r=new Set;for(const s of t)if(i.has(s)&&(r.add(s),r.size===i.size))return!0;return r.size===i.size}function K(t=0){return s=Math.min(Math.max(16,t),1073741824),s>>>=0,s-=1,s|=s>>1,s|=s>>2,s|=s>>4,s|=s>>8,1+(s|=s>>16);var s}var Q=class extends Array{constructor(t,s){Array.isArray(t)?(super(...t),this._length=t.length,t=void 0):(super(),this._length=0),this._capacity=K(t),this._front=0,this._disableAutoResize=s}push(t){let s=this._length;this.checkCapacity(s+1);const i=this._front+s&this._capacity-1;return this[i]=t,++s<=this._capacity&&(this._length=s),i}unshift(t){let s=this._length;this.checkCapacity(++s);const i=this._capacity,r=(this._front-1&i-1^i)-i;return this[r]=t,this._front=r,s<=this._capacity&&(this._length=s),r}pop(t){let s=this._length;if(0===s)return;let i=this._front+s-1&this._capacity-1,r=this[i];for(;--s>0&&t&&null==r;)i--,r=this[i];return this[i]=void 0,this._length=s,r}shift(t){let s=this._length;if(0===s)return;let i=this._front,r=this[i];for(;--s>0&&t&&null==r;)i=i+1&this._capacity-1,r=this[i];return this[i]=void 0,this._front=i+1&this._capacity-1,this._length=s,r}get size(){return this._length}get(t){let s;if(t===(0|t)){const i=this._length;t<0&&(t+=i),t>=0&&t<i&&(s=this[this._front+t&this._capacity-1])}return s}peekBack(){const t=this._length;if(0===t)return;return this[this._front+t-1&this._capacity-1]}peekFront(){if(0!==this._length)return this[this._front]}clear(){const t=this._length,s=this._front,i=this._capacity;for(let r=0;r<t;++r)this[s+r&i-1]=void 0;this._length=0,this._front=0}isEmpty(){return 0===this._length}removeAt(t){const s=this._length;if(t<0||t>=s)return;const i=this._front,r=this._capacity-1,n=i+t&r,e=this[n];if(t<s/2)this.copyWithin(i+1&r,i,i+t&r),this[i]=void 0,this._front=i+1&r;else{this.copyWithin(n,n+1&r,i+s&r);this[i+s-1&r]=void 0}return this._length=s-1,e}checkCapacity(t){this._capacity<t&&!this._disableAutoResize&&this.resizeTo(K(1.5*this._capacity+16))}resizeTo(t){const s=this._capacity;this._capacity=t;const i=this._front,r=this._length;if(i+r>s){!function(t,s,i,r,n){for(let e=0;e<n;++e)i[e+r]=t[e+s],t[e+s]=void 0}(this,0,this,s,i+r&s-1)}}},V=class t{constructor(t=0){this.bitField=t}static has(t,s){return!!(t&1<<s)}static add(t,s){return t|1<<s}static delete(t,s){return t&~(1<<s)}add(t){return this.bitField|=1<<t,this}delete(t){return this.bitField&=~(1<<t),this}has(s){return t.has(this.bitField,s)}clear(){return this.bitField=0,this}valueOf(){return this.bitField}toString(){return this.bitField.toString()}toJSON(){return this.bitField}};async function W(t){return new Promise(s=>setTimeout(s,t))}async function X(){return new Promise(t=>{setImmediate(t)})}import{isAsync as Y}from"util-ex";import{EventEmitter as tt}from"events-ex";import{AbortError as st}from"@isdk/common-error";var it=32;function rt(t){return"function"==typeof t}function nt(){return"1"}var et=class{constructor(t={}){const{initFn:s=nt,pauseFn:i,resumeFn:r,capacity:n=it}=t;if(rt(i)!==rt(r))throw new Error("pauseFn and resumeFn must be both set for pausing");this.waiting=new Q(n),this.emitter=new tt,this.useDefaultTokens=s===nt,this.pauseFn=i,this.resumeFn=r,this.initTokenFn=s,this.paused=!1,this._activeCount=0,this.initFree(t),this.init(t)}initFree(t){this.free=this.initTokenFn()}onReleased(t){const s=t?.token,i=this.waiting.shift(!0);i?this._dispatchTask(i,t):(this.resumeFn&&this.paused&&(this.paused=!1,this.resumeFn()),this.unlock(s))}init(t){this.emitter.on("release",t=>{this.onReleased(t)})}_newReleaser(t){let s=!1;const i=()=>{s||(s=!0,this.release(t))};return t&&Object.assign(i,t),i}_dispatchTask(t,s){const{resolve:i}=t;i(this._newReleaser(s))}lock(t){let s=this.free;if(s)return this.free=void 0,s}unlock(t){this.free=this.useDefaultTokens?"1":t??this.initTokenFn()}tryAcquire(t){return this.lock(t)}async acquire(t){this._activeCount++;const s=t?.signal,i=t=>{this.pauseFn&&!this.paused&&(this.paused=!0,this.pauseFn());const i=this.waiting.push(t),r=t.reject;return s&&s.addEventListener("abort",()=>{this.waiting[i]=void 0;const t=s.reason instanceof Error?s.reason:new st(s.reason||"aborted");s.alreadyRejected=!0,r(t)}),i};let r=this.tryAcquire(t);const n=r&&Y(r),e=s=>new Promise((r,n)=>{const e={...t,resolve:r,reject:n,token:s};void 0===s?i(e):this._dispatchTask(e,{...t,token:s})});return n?r.then(t=>e(t)):e(r)}release(t){this._activeCount--,this.emitter.emit("release",t)}drain(){const t=[this.acquire()];return Promise.all(t)}abort(t){let s;for(;s=this.waiting.shift(!0);)s.reject(new st(t))}get activeCount(){return this._activeCount}get pendingCount(){return this.waiting.size}},ot=class extends et{constructor(t,s){if("number"==typeof t)(s=s||{}).maxConcurrency=t;else{if("number"!=typeof(s=t).maxConcurrency)throw new Error("maxConcurrency must be set");t=s.maxConcurrency}super(s),this.maxConcurrency=s.maxConcurrency,s.isReadyFn&&(this.isReady=s.isReadyFn)}initFree(t){const s=t.maxConcurrency=Math.max(1,t.maxConcurrency);this.free=new Q(s);for(let t=0;t<s;t++)this.free.push(this.initTokenFn())}tryAcquire(t){let s=this.isReady;if(s&&Y(s)){return s instanceof Promise||(s=s()),s.then(s=>{if(s)return this.lock(t)})}if(!s||s())return this.lock(t)}unlock(t){this.free.push(this.useDefaultTokens?"1":t??this.initTokenFn())}lock(t){return this.free.pop()}drain(){const t=new Array(this.maxConcurrency);for(let s=0;s<this.maxConcurrency;s++)t[s]=this.acquire();return Promise.all(t)}};function ht(t,{timeUnit:s=1e3,uniformDistribution:i=!1}={}){const r=new ot(i?1:t),n=i?s/t:s;return async function(){await r.acquire(),setTimeout(()=>r.release(),n)}}import{AbortError as ct}from"@isdk/common-error";var ut=class{constructor(){this._isSignaled=!1,this.waitQueue=[]}get signaled(){return this._isSignaled}signal(t){if(this._isSignaled)return;this._isSignaled=!0,this._signalValue=t;const s=this.waitQueue.slice();for(this.waitQueue.length=0;s.length>0;){const t=s.shift();t?.resolve(this._signalValue)}}reset(){this._isSignaled=!1,this._signalValue=void 0,this.waitQueue.length=0}abort(t){if(this.waitQueue.length){const s=this.waitQueue.slice();this.waitQueue.length=0;const i=new ct(t);for(;s.length>0;){const{reject:t}=s.shift();t(i)}}}async wait(){return new Promise((t,s)=>{this._isSignaled?t(this._signalValue):this.waitQueue.push({resolve:t,reject:s})})}};import ft from"net";async function at(t,s=10){return new Promise((i,r)=>{void 0===t?t=0:("string"==typeof t&&(t=parseInt(t)),t>=0||(t=0));const n=ft.createServer();n.on("error",i=>{"EADDRINUSE"===i.code&&(t++,--s>0)?n.listen(t):r(i)}),n.on("listening",async()=>{const t=n.address().port;n.close(s=>{s?r(s):i(t)})}),n.listen(t)})}export{et as BinarySemaphore,d as ConfigFile,k as DefaultAllTextFiles,it as DefaultAsyncSemaphoreCapacity,Q as Deque,N as FilenameReservedRegex,V as IntSet,ht as RateLimit,ot as Semaphore,ut as SignalGate,D as WindowsReservedNameRegex,H as arrayHasAll,G as extNameLevel,B as filenameReservedRegex,at as findPort,h as getMultiLevelExtname,b as glob,x as isStringIn,J as isValidFilename,L as isValidFilepath,F as normalizeIncludeFiles,y as parseFrontMatter,l as parseYaml,I as reControlCharsRegex,a as registerYamlTag,p as removeLeadingEmptyLines,U as sanitizeFilename,Z as sanitizeFilepath,W as sleep,m as stringifyYaml,T as toCamelCase,z as toCapitalCase,P as toPascalCase,$ as traverseFolder,j as traverseFolderSync,X as yieldExec};
@@ -6,7 +6,7 @@
6
6
 
7
7
  # Class: BinarySemaphore
8
8
 
9
- Defined in: [src/async-semaphore.ts:88](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/async-semaphore.ts#L88)
9
+ Defined in: [src/async-semaphore.ts:88](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/async-semaphore.ts#L88)
10
10
 
11
11
  A binary semaphore implementation for managing concurrency in asynchronous operations.
12
12
  Unlike a general semaphore, a binary semaphore allows only one caller to acquire the semaphore at a time.
@@ -47,7 +47,7 @@ const data = await Promise.all(array.map(fetchData));
47
47
 
48
48
  > **new BinarySemaphore**(`options`): `BinarySemaphore`
49
49
 
50
- Defined in: [src/async-semaphore.ts:145](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/async-semaphore.ts#L145)
50
+ Defined in: [src/async-semaphore.ts:145](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/async-semaphore.ts#L145)
51
51
 
52
52
  Creates a binary semaphore object for managing concurrency in asynchronous operations.
53
53
 
@@ -67,7 +67,7 @@ Creates a binary semaphore object for managing concurrency in asynchronous opera
67
67
 
68
68
  > `protected` **\_activeCount**: `number`
69
69
 
70
- Defined in: [src/async-semaphore.ts:97](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/async-semaphore.ts#L97)
70
+ Defined in: [src/async-semaphore.ts:97](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/async-semaphore.ts#L97)
71
71
 
72
72
  ***
73
73
 
@@ -75,7 +75,7 @@ Defined in: [src/async-semaphore.ts:97](https://github.com/isdk/util.js/blob/f6a
75
75
 
76
76
  > `protected` **emitter**: `EventEmitter`
77
77
 
78
- Defined in: [src/async-semaphore.ts:91](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/async-semaphore.ts#L91)
78
+ Defined in: [src/async-semaphore.ts:91](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/async-semaphore.ts#L91)
79
79
 
80
80
  ***
81
81
 
@@ -83,15 +83,15 @@ Defined in: [src/async-semaphore.ts:91](https://github.com/isdk/util.js/blob/f6a
83
83
 
84
84
  > `protected` **free**: `any`
85
85
 
86
- Defined in: [src/async-semaphore.ts:90](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/async-semaphore.ts#L90)
86
+ Defined in: [src/async-semaphore.ts:90](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/async-semaphore.ts#L90)
87
87
 
88
88
  ***
89
89
 
90
90
  ### initTokenFn()
91
91
 
92
- > `protected` **initTokenFn**: (`token`?) => `void`
92
+ > `protected` **initTokenFn**: (`token?`) => `void`
93
93
 
94
- Defined in: [src/async-semaphore.ts:95](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/async-semaphore.ts#L95)
94
+ Defined in: [src/async-semaphore.ts:95](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/async-semaphore.ts#L95)
95
95
 
96
96
  #### Parameters
97
97
 
@@ -109,7 +109,7 @@ Defined in: [src/async-semaphore.ts:95](https://github.com/isdk/util.js/blob/f6a
109
109
 
110
110
  > `protected` **paused**: `boolean`
111
111
 
112
- Defined in: [src/async-semaphore.ts:96](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/async-semaphore.ts#L96)
112
+ Defined in: [src/async-semaphore.ts:96](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/async-semaphore.ts#L96)
113
113
 
114
114
  ***
115
115
 
@@ -117,7 +117,7 @@ Defined in: [src/async-semaphore.ts:96](https://github.com/isdk/util.js/blob/f6a
117
117
 
118
118
  > `protected` `optional` **pauseFn**: () => `void`
119
119
 
120
- Defined in: [src/async-semaphore.ts:93](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/async-semaphore.ts#L93)
120
+ Defined in: [src/async-semaphore.ts:93](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/async-semaphore.ts#L93)
121
121
 
122
122
  #### Returns
123
123
 
@@ -129,7 +129,7 @@ Defined in: [src/async-semaphore.ts:93](https://github.com/isdk/util.js/blob/f6a
129
129
 
130
130
  > `protected` `optional` **resumeFn**: () => `void`
131
131
 
132
- Defined in: [src/async-semaphore.ts:94](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/async-semaphore.ts#L94)
132
+ Defined in: [src/async-semaphore.ts:94](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/async-semaphore.ts#L94)
133
133
 
134
134
  #### Returns
135
135
 
@@ -141,15 +141,15 @@ Defined in: [src/async-semaphore.ts:94](https://github.com/isdk/util.js/blob/f6a
141
141
 
142
142
  > `protected` **useDefaultTokens**: `boolean`
143
143
 
144
- Defined in: [src/async-semaphore.ts:92](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/async-semaphore.ts#L92)
144
+ Defined in: [src/async-semaphore.ts:92](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/async-semaphore.ts#L92)
145
145
 
146
146
  ***
147
147
 
148
148
  ### waiting
149
149
 
150
- > `readonly` **waiting**: [`Deque`](Deque.md)\<`undefined` \| [`SemaphoreTaskItem`](../interfaces/SemaphoreTaskItem.md)\>
150
+ > `readonly` **waiting**: [`Deque`](Deque.md)\<[`SemaphoreTaskItem`](../interfaces/SemaphoreTaskItem.md) \| `undefined`\>
151
151
 
152
- Defined in: [src/async-semaphore.ts:89](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/async-semaphore.ts#L89)
152
+ Defined in: [src/async-semaphore.ts:89](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/async-semaphore.ts#L89)
153
153
 
154
154
  ## Accessors
155
155
 
@@ -159,7 +159,7 @@ Defined in: [src/async-semaphore.ts:89](https://github.com/isdk/util.js/blob/f6a
159
159
 
160
160
  > **get** **activeCount**(): `number`
161
161
 
162
- Defined in: [src/async-semaphore.ts:318](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/async-semaphore.ts#L318)
162
+ Defined in: [src/async-semaphore.ts:318](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/async-semaphore.ts#L318)
163
163
 
164
164
  Get the total count of all active operations.
165
165
 
@@ -181,7 +181,7 @@ The total count of active operations, including both waiting and ongoing tasks.
181
181
 
182
182
  > **get** **pendingCount**(): `number`
183
183
 
184
- Defined in: [src/async-semaphore.ts:327](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/async-semaphore.ts#L327)
184
+ Defined in: [src/async-semaphore.ts:327](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/async-semaphore.ts#L327)
185
185
 
186
186
  Get the number of callers waiting on the semaphore, i.e. the number of pending promises.
187
187
 
@@ -195,9 +195,9 @@ The number of waiters in the waiting list.
195
195
 
196
196
  ### \_dispatchTask()
197
197
 
198
- > **\_dispatchTask**(`task`, `options`?): `void`
198
+ > **\_dispatchTask**(`task`, `options?`): `void`
199
199
 
200
- Defined in: [src/async-semaphore.ts:212](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/async-semaphore.ts#L212)
200
+ Defined in: [src/async-semaphore.ts:212](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/async-semaphore.ts#L212)
201
201
 
202
202
  #### Parameters
203
203
 
@@ -217,9 +217,9 @@ Defined in: [src/async-semaphore.ts:212](https://github.com/isdk/util.js/blob/f6
217
217
 
218
218
  ### \_newReleaser()
219
219
 
220
- > **\_newReleaser**(`options`?): [`BinarySemaphoreReleaserFunc`](../interfaces/BinarySemaphoreReleaserFunc.md)
220
+ > **\_newReleaser**(`options?`): [`BinarySemaphoreReleaserFunc`](../interfaces/BinarySemaphoreReleaserFunc.md)
221
221
 
222
- Defined in: [src/async-semaphore.ts:199](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/async-semaphore.ts#L199)
222
+ Defined in: [src/async-semaphore.ts:199](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/async-semaphore.ts#L199)
223
223
 
224
224
  #### Parameters
225
225
 
@@ -235,9 +235,9 @@ Defined in: [src/async-semaphore.ts:199](https://github.com/isdk/util.js/blob/f6
235
235
 
236
236
  ### abort()
237
237
 
238
- > **abort**(`reason`?): `void`
238
+ > **abort**(`reason?`): `void`
239
239
 
240
- Defined in: [src/async-semaphore.ts:301](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/async-semaphore.ts#L301)
240
+ Defined in: [src/async-semaphore.ts:301](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/async-semaphore.ts#L301)
241
241
 
242
242
  #### Parameters
243
243
 
@@ -253,9 +253,9 @@ Defined in: [src/async-semaphore.ts:301](https://github.com/isdk/util.js/blob/f6
253
253
 
254
254
  ### acquire()
255
255
 
256
- > **acquire**(`options`?): `Promise`\<[`BinarySemaphoreReleaserFunc`](../interfaces/BinarySemaphoreReleaserFunc.md)\>
256
+ > **acquire**(`options?`): `Promise`\<[`BinarySemaphoreReleaserFunc`](../interfaces/BinarySemaphoreReleaserFunc.md)\>
257
257
 
258
- Defined in: [src/async-semaphore.ts:243](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/async-semaphore.ts#L243)
258
+ Defined in: [src/async-semaphore.ts:243](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/async-semaphore.ts#L243)
259
259
 
260
260
  Acquire a token from the semaphore, thus decrement the number of available execution slots. If initFn is not used then the return value of the function can be discarded.
261
261
 
@@ -277,7 +277,7 @@ A promise that resolves to a release function when a token is acquired. If the s
277
277
 
278
278
  > **drain**(): `Promise`\<`any`[]\>
279
279
 
280
- Defined in: [src/async-semaphore.ts:296](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/async-semaphore.ts#L296)
280
+ Defined in: [src/async-semaphore.ts:296](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/async-semaphore.ts#L296)
281
281
 
282
282
  Drains the semaphore and returns all the initialized tokens in an array. Draining is an ideal way to ensure there are no pending async tasks, for example before a process will terminate.
283
283
 
@@ -291,7 +291,7 @@ Drains the semaphore and returns all the initialized tokens in an array. Drainin
291
291
 
292
292
  > **init**(`options`): `void`
293
293
 
294
- Defined in: [src/async-semaphore.ts:193](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/async-semaphore.ts#L193)
294
+ Defined in: [src/async-semaphore.ts:193](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/async-semaphore.ts#L193)
295
295
 
296
296
  #### Parameters
297
297
 
@@ -307,9 +307,9 @@ Defined in: [src/async-semaphore.ts:193](https://github.com/isdk/util.js/blob/f6
307
307
 
308
308
  ### initFree()
309
309
 
310
- > **initFree**(`options`?): `void`
310
+ > **initFree**(`options?`): `void`
311
311
 
312
- Defined in: [src/async-semaphore.ts:173](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/async-semaphore.ts#L173)
312
+ Defined in: [src/async-semaphore.ts:173](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/async-semaphore.ts#L173)
313
313
 
314
314
  #### Parameters
315
315
 
@@ -325,9 +325,9 @@ Defined in: [src/async-semaphore.ts:173](https://github.com/isdk/util.js/blob/f6
325
325
 
326
326
  ### lock()
327
327
 
328
- > **lock**(`options`?): `any`
328
+ > **lock**(`options?`): `any`
329
329
 
330
- Defined in: [src/async-semaphore.ts:217](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/async-semaphore.ts#L217)
330
+ Defined in: [src/async-semaphore.ts:217](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/async-semaphore.ts#L217)
331
331
 
332
332
  #### Parameters
333
333
 
@@ -343,9 +343,9 @@ Defined in: [src/async-semaphore.ts:217](https://github.com/isdk/util.js/blob/f6
343
343
 
344
344
  ### onReleased()
345
345
 
346
- > **onReleased**(`options`?): `void`
346
+ > **onReleased**(`options?`): `void`
347
347
 
348
- Defined in: [src/async-semaphore.ts:177](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/async-semaphore.ts#L177)
348
+ Defined in: [src/async-semaphore.ts:177](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/async-semaphore.ts#L177)
349
349
 
350
350
  #### Parameters
351
351
 
@@ -361,9 +361,9 @@ Defined in: [src/async-semaphore.ts:177](https://github.com/isdk/util.js/blob/f6
361
361
 
362
362
  ### release()
363
363
 
364
- > **release**(`options`?): `void`
364
+ > **release**(`options?`): `void`
365
365
 
366
- Defined in: [src/async-semaphore.ts:288](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/async-semaphore.ts#L288)
366
+ Defined in: [src/async-semaphore.ts:288](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/async-semaphore.ts#L288)
367
367
 
368
368
  Releases the semaphore, incrementing the number of free execution slots. If there are tasks in the waiting queue, the next task will be dispatched.
369
369
 
@@ -381,9 +381,9 @@ Releases the semaphore, incrementing the number of free execution slots. If ther
381
381
 
382
382
  ### tryAcquire()
383
383
 
384
- > **tryAcquire**(`options`?): `any`
384
+ > **tryAcquire**(`options?`): `any`
385
385
 
386
- Defined in: [src/async-semaphore.ts:234](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/async-semaphore.ts#L234)
386
+ Defined in: [src/async-semaphore.ts:234](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/async-semaphore.ts#L234)
387
387
 
388
388
  Attempt to acquire a token from the semaphore, if one is available immediately. Otherwise, return undefined.
389
389
 
@@ -403,9 +403,9 @@ Returns a token if the semaphore is not full; otherwise, returns `undefined`.
403
403
 
404
404
  ### unlock()
405
405
 
406
- > **unlock**(`token`?): `void`
406
+ > **unlock**(`token?`): `void`
407
407
 
408
- Defined in: [src/async-semaphore.ts:225](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/async-semaphore.ts#L225)
408
+ Defined in: [src/async-semaphore.ts:225](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/async-semaphore.ts#L225)
409
409
 
410
410
  #### Parameters
411
411
 
@@ -6,7 +6,7 @@
6
6
 
7
7
  # Class: ConfigFile
8
8
 
9
- Defined in: [src/config-file.ts:46](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/config-file.ts#L46)
9
+ Defined in: [src/config-file.ts:46](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/config-file.ts#L46)
10
10
 
11
11
  Represents a configuration file utility class that provides methods to load and save configuration files.
12
12
  It supports multiple file formats such as YAML, JSON, etc., by registering corresponding parsers and stringifiers.
@@ -45,7 +45,7 @@ console.log(config); // Output: { key: 'value' }
45
45
 
46
46
  > `static` **stringifys**: `Record`\<`string`, [`StringifyFunc`](../type-aliases/StringifyFunc.md)\> = `{}`
47
47
 
48
- Defined in: [src/config-file.ts:50](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/config-file.ts#L50)
48
+ Defined in: [src/config-file.ts:50](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/config-file.ts#L50)
49
49
 
50
50
  A record of registered stringify functions for different file extensions.
51
51
 
@@ -53,9 +53,9 @@ A record of registered stringify functions for different file extensions.
53
53
 
54
54
  ### existsSync()
55
55
 
56
- > `static` **existsSync**(`filename`, `options`?): `boolean`
56
+ > `static` **existsSync**(`filename`, `options?`): `boolean`
57
57
 
58
- Defined in: [src/config-file.ts:132](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/config-file.ts#L132)
58
+ Defined in: [src/config-file.ts:132](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/config-file.ts#L132)
59
59
 
60
60
  Checks if a configuration file exists at the specified path.
61
61
 
@@ -102,9 +102,9 @@ console.log(existsWithExt); // true or false
102
102
 
103
103
  ### loadSync()
104
104
 
105
- > `static` **loadSync**(`filename`, `options`?): `any`
105
+ > `static` **loadSync**(`filename`, `options?`): `any`
106
106
 
107
- Defined in: [src/config-file.ts:85](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/config-file.ts#L85)
107
+ Defined in: [src/config-file.ts:85](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/config-file.ts#L85)
108
108
 
109
109
  Loads a configuration file based on the provided filename and options.
110
110
 
@@ -141,7 +141,7 @@ console.log(config); // Output: { key: 'value' }
141
141
 
142
142
  > `static` **register**(`extname`, `parser`, `stringify`): `void`
143
143
 
144
- Defined in: [src/config-file.ts:64](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/config-file.ts#L64)
144
+ Defined in: [src/config-file.ts:64](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/config-file.ts#L64)
145
145
 
146
146
  Registers a parser and stringifier for specific file extensions.
147
147
 
@@ -179,9 +179,9 @@ ConfigFile.register(['.json'], JSON.parse, (obj) => JSON.stringify(obj, null, 2)
179
179
 
180
180
  ### saveSync()
181
181
 
182
- > `static` **saveSync**(`filename`, `config`, `options`?): `string`
182
+ > `static` **saveSync**(`filename`, `config`, `options?`): `string`
183
183
 
184
- Defined in: [src/config-file.ts:102](https://github.com/isdk/util.js/blob/f6ac1e1b241d01211870dd55d000c1e9d4daa404/src/config-file.ts#L102)
184
+ Defined in: [src/config-file.ts:102](https://github.com/isdk/util.js/blob/1244ecc63e69dca791e24e154694c362d05c92c5/src/config-file.ts#L102)
185
185
 
186
186
  Saves a configuration object to a file with the specified filename and options.
187
187