@isdk/util 0.3.0 → 0.3.2

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 (38) hide show
  1. package/dist/index.d.mts +44 -1
  2. package/dist/index.d.ts +44 -1
  3. package/dist/index.js +1 -1
  4. package/dist/index.mjs +1 -1
  5. package/docs/classes/ConfigFile.md +54 -5
  6. package/docs/functions/arrayHasAll.md +48 -0
  7. package/docs/functions/extNameLevel.md +1 -1
  8. package/docs/functions/filenameReservedRegex.md +1 -1
  9. package/docs/functions/getMultiLevelExtname.md +1 -1
  10. package/docs/functions/glob.md +1 -1
  11. package/docs/functions/isStringIn.md +1 -1
  12. package/docs/functions/isValidFilename.md +1 -1
  13. package/docs/functions/isValidFilepath.md +1 -1
  14. package/docs/functions/normalizeIncludeFiles.md +1 -1
  15. package/docs/functions/parseFrontMatter.md +1 -1
  16. package/docs/functions/parseYaml.md +1 -1
  17. package/docs/functions/reControlCharsRegex.md +1 -1
  18. package/docs/functions/registerYamlTag.md +1 -1
  19. package/docs/functions/removeLeadingEmptyLines.md +1 -1
  20. package/docs/functions/sanitizeFilename.md +1 -1
  21. package/docs/functions/sanitizeFilepath.md +1 -1
  22. package/docs/functions/stringifyYaml.md +1 -1
  23. package/docs/functions/toCamelCase.md +1 -1
  24. package/docs/functions/toCapitalCase.md +1 -1
  25. package/docs/functions/toPascalCase.md +1 -1
  26. package/docs/functions/traverseFolder.md +1 -1
  27. package/docs/functions/traverseFolderSync.md +1 -1
  28. package/docs/globals.md +1 -0
  29. package/docs/interfaces/IncludeFiles.md +3 -3
  30. package/docs/interfaces/LoadConfigFileOptions.md +3 -3
  31. package/docs/interfaces/SanitizeFilenameOptions.md +3 -3
  32. package/docs/type-aliases/StringifyFunc.md +1 -1
  33. package/docs/type-aliases/TraverseFolderHandler.md +1 -1
  34. package/docs/type-aliases/TraverseFolderSyncHandler.md +1 -1
  35. package/docs/variables/DefaultAllTextFiles.md +1 -1
  36. package/docs/variables/FilenameReservedRegex.md +1 -1
  37. package/docs/variables/WindowsReservedNameRegex.md +1 -1
  38. package/package.json +2 -2
package/dist/index.d.mts CHANGED
@@ -73,6 +73,33 @@ declare class ConfigFile {
73
73
  * ```
74
74
  */
75
75
  static saveSync(filename: string, config: any, options?: LoadConfigFileOptions): string;
76
+ /**
77
+ * Checks if a configuration file exists at the specified path.
78
+ *
79
+ * This method normalizes the filename by removing the extension (if present) and then delegates
80
+ * to the underlying LoadConfigFile utility to perform the existence check. The normalization
81
+ * ensures consistent handling of files regardless of whether they include extensions in the
82
+ * provided filename.
83
+ *
84
+ * @param filename - The path to the configuration file to check for existence.
85
+ * This can include or omit the file extension.
86
+ * @param options - Optional configuration options that may affect how the file existence
87
+ * is checked, including extension level handling.
88
+ *
89
+ * @returns `true` if the configuration file exists, `false` otherwise.
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * // Check if a YAML config file exists
94
+ * const exists = ConfigFile.existsSync('config.yaml');
95
+ * console.log(exists); // true or false
96
+ *
97
+ * // Check with options
98
+ * const existsWithExt = ConfigFile.existsSync('config', { extLevel: 2 });
99
+ * console.log(existsWithExt); // true or false
100
+ * ```
101
+ */
102
+ static existsSync(filename: string, options?: LoadConfigFileOptions): boolean;
76
103
  }
77
104
 
78
105
  /**
@@ -421,4 +448,20 @@ declare function sanitizeFilepath(filepath: string, options?: SanitizeFilenameOp
421
448
  */
422
449
  declare function extNameLevel(extName: string): number;
423
450
 
424
- export { ConfigFile, DefaultAllTextFiles, FilenameReservedRegex, type IncludeFiles, type LoadConfigFileOptions, type SanitizeFilenameOptions, type StringifyFunc, type TraverseFolderHandler, type TraverseFolderSyncHandler, WindowsReservedNameRegex, extNameLevel, filenameReservedRegex, getMultiLevelExtname, glob, isStringIn, isValidFilename, isValidFilepath, normalizeIncludeFiles, parseFrontMatter, parseYaml, reControlCharsRegex, registerYamlTag, removeLeadingEmptyLines, sanitizeFilename, sanitizeFilepath, stringifyYaml, toCamelCase, toCapitalCase, toPascalCase, traverseFolder, traverseFolderSync };
451
+ /**
452
+ * Checks whether the provided array contains all of the specified elements.
453
+ *
454
+ * @typeParam T - The type of elements in the arrays.
455
+ * @param array - The array to check against.
456
+ * @param elements - The list of elements to be checked for presence in the array.
457
+ * @returns `true` if all elements are present in the array; otherwise, `false`.
458
+ *
459
+ * @example
460
+ * ```ts
461
+ * arrayHasAll([1, 2, 3], [2, 3]); // true
462
+ * arrayHasAll(['a', 'b', 'c'], ['x', 'y']); // false
463
+ * ```
464
+ */
465
+ declare function arrayHasAll<T = any>(array: T[], elements: T[]): boolean;
466
+
467
+ export { ConfigFile, DefaultAllTextFiles, FilenameReservedRegex, type IncludeFiles, type LoadConfigFileOptions, type SanitizeFilenameOptions, type StringifyFunc, type TraverseFolderHandler, type TraverseFolderSyncHandler, WindowsReservedNameRegex, arrayHasAll, extNameLevel, filenameReservedRegex, getMultiLevelExtname, glob, isStringIn, isValidFilename, isValidFilepath, normalizeIncludeFiles, parseFrontMatter, parseYaml, reControlCharsRegex, registerYamlTag, removeLeadingEmptyLines, sanitizeFilename, sanitizeFilepath, stringifyYaml, toCamelCase, toCapitalCase, toPascalCase, traverseFolder, traverseFolderSync };
package/dist/index.d.ts CHANGED
@@ -73,6 +73,33 @@ declare class ConfigFile {
73
73
  * ```
74
74
  */
75
75
  static saveSync(filename: string, config: any, options?: LoadConfigFileOptions): string;
76
+ /**
77
+ * Checks if a configuration file exists at the specified path.
78
+ *
79
+ * This method normalizes the filename by removing the extension (if present) and then delegates
80
+ * to the underlying LoadConfigFile utility to perform the existence check. The normalization
81
+ * ensures consistent handling of files regardless of whether they include extensions in the
82
+ * provided filename.
83
+ *
84
+ * @param filename - The path to the configuration file to check for existence.
85
+ * This can include or omit the file extension.
86
+ * @param options - Optional configuration options that may affect how the file existence
87
+ * is checked, including extension level handling.
88
+ *
89
+ * @returns `true` if the configuration file exists, `false` otherwise.
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * // Check if a YAML config file exists
94
+ * const exists = ConfigFile.existsSync('config.yaml');
95
+ * console.log(exists); // true or false
96
+ *
97
+ * // Check with options
98
+ * const existsWithExt = ConfigFile.existsSync('config', { extLevel: 2 });
99
+ * console.log(existsWithExt); // true or false
100
+ * ```
101
+ */
102
+ static existsSync(filename: string, options?: LoadConfigFileOptions): boolean;
76
103
  }
77
104
 
78
105
  /**
@@ -421,4 +448,20 @@ declare function sanitizeFilepath(filepath: string, options?: SanitizeFilenameOp
421
448
  */
422
449
  declare function extNameLevel(extName: string): number;
423
450
 
424
- export { ConfigFile, DefaultAllTextFiles, FilenameReservedRegex, type IncludeFiles, type LoadConfigFileOptions, type SanitizeFilenameOptions, type StringifyFunc, type TraverseFolderHandler, type TraverseFolderSyncHandler, WindowsReservedNameRegex, extNameLevel, filenameReservedRegex, getMultiLevelExtname, glob, isStringIn, isValidFilename, isValidFilepath, normalizeIncludeFiles, parseFrontMatter, parseYaml, reControlCharsRegex, registerYamlTag, removeLeadingEmptyLines, sanitizeFilename, sanitizeFilepath, stringifyYaml, toCamelCase, toCapitalCase, toPascalCase, traverseFolder, traverseFolderSync };
451
+ /**
452
+ * Checks whether the provided array contains all of the specified elements.
453
+ *
454
+ * @typeParam T - The type of elements in the arrays.
455
+ * @param array - The array to check against.
456
+ * @param elements - The list of elements to be checked for presence in the array.
457
+ * @returns `true` if all elements are present in the array; otherwise, `false`.
458
+ *
459
+ * @example
460
+ * ```ts
461
+ * arrayHasAll([1, 2, 3], [2, 3]); // true
462
+ * arrayHasAll(['a', 'b', 'c'], ['x', 'y']); // false
463
+ * ```
464
+ */
465
+ declare function arrayHasAll<T = any>(array: T[], elements: T[]): boolean;
466
+
467
+ export { ConfigFile, DefaultAllTextFiles, FilenameReservedRegex, type IncludeFiles, type LoadConfigFileOptions, type SanitizeFilenameOptions, type StringifyFunc, type TraverseFolderHandler, type TraverseFolderSyncHandler, WindowsReservedNameRegex, arrayHasAll, extNameLevel, filenameReservedRegex, getMultiLevelExtname, glob, isStringIn, isValidFilename, isValidFilepath, normalizeIncludeFiles, parseFrontMatter, parseYaml, reControlCharsRegex, registerYamlTag, removeLeadingEmptyLines, sanitizeFilename, sanitizeFilepath, stringifyYaml, toCamelCase, toCapitalCase, toPascalCase, traverseFolder, traverseFolderSync };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e,t=Object.create,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,o=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,a=(e,t,o,a)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let u of i(t))s.call(e,u)||u===o||n(e,u,{get:()=>t[u],enumerable:!(a=r(t,u))||a.enumerable});return e},u=(e,r,i)=>(i=null!=e?t(o(e)):{},a(!r&&e&&e.__esModule?i:n(i,"default",{value:e,enumerable:!0}),e)),c={};((e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})})(c,{ConfigFile:()=>q,DefaultAllTextFiles:()=>O,FilenameReservedRegex:()=>B,WindowsReservedNameRegex:()=>D,extNameLevel:()=>U,filenameReservedRegex:()=>W,getMultiLevelExtname:()=>g,glob:()=>R,isStringIn:()=>E,isValidFilename:()=>G,isValidFilepath:()=>H,normalizeIncludeFiles:()=>C,parseFrontMatter:()=>j,parseYaml:()=>h,reControlCharsRegex:()=>Z,registerYamlTag:()=>v,removeLeadingEmptyLines:()=>b,sanitizeFilename:()=>K,sanitizeFilepath:()=>Q,stringifyYaml:()=>F,toCamelCase:()=>N,toCapitalCase:()=>M,toPascalCase:()=>T,traverseFolder:()=>L,traverseFolderSync:()=>S}),module.exports=(e=c,a(n({},"__esModule",{value:!0}),e));var l=require("fs"),f=u(require("path")),m=require("load-config-file"),p=u(require("path"));function g(e,t=1){let n="";for(;t--;){const t=p.default.extname(e);if(!t)break;n=t+n,e=p.default.basename(e,t)}return n}var y=require("yaml"),d=[];function v(e){Array.isArray(e)||(e=[e]);for(const t of e){-1===d.indexOf(t)&&d.push(t)}}function h(e,t){if(t)if(t.customTags){if(Array.isArray(t.customTags))t.customTags=d.concat(t.customTags);else if("function"==typeof t.customTags){const e=t.customTags;t.customTags=t=>e(d.concat(t))}}else t.customTags=d;else t={customTags:d};return(0,y.parse)(e,t)}function F(e,t){if(t)if(t.customTags){if(Array.isArray(t.customTags))t.customTags=d.concat(t.customTags);else if("function"==typeof t.customTags){const e=t.customTags;t.customTags=t=>e(d.concat(t))}}else t.customTags=d;else t={customTags:d};return(0,y.stringify)(e,t)}function b(e){const t=/^\s*(#[^\r\n]*)?[\r\n]+/;let n;for(;null!==(n=t.exec(e))&&((e=e.substring(n[0].length)).startsWith("\n")||e.startsWith("\r")||e.trimStart().startsWith("#")););return e}var x="---";function j(e,t=x){const n=t.length,r=b(e);if(r.startsWith(t)&&("\n"===r[t.length]||"\r"===r[t.length])){let e=r.indexOf("\n"+t,n);if(-1!==e){const i=r.slice(n,e);for(e+=t.length+1;"\n"===r[e]||"\r"===r[e];)e++;const o=r.slice(e);return{data:h(i)||{},content:o}}}return{data:{},content:e}}var q=class{static register(e,t,n){m.Config.register(e,t),"string"==typeof e&&(e=[e]);for(const t of e)this.stringifys[t]=n}static loadSync(e,t){return function(e,{extLevel:t=1,externalFile:n}={}){"."===e[0]&&t++;const r=g(e,t);r&&r.split(".").length>1&&(e=e.slice(0,-r.length));let i=m.Config.loadSync(e);if(!i&&n){if(!f.default.isAbsolute(n)){const t=f.default.dirname(e);n=f.default.join(t,n)}if((0,l.existsSync)(n)){const e=j((0,l.readFileSync)(n,"utf8")).data;Object.keys(e).length&&(i=e)}}return i}(e,t)}static saveSync(e,t,n){return function(e,t,{extLevel:n=1}={}){"."===e[0]&&n++;let r=g(e,n);(!r||r.split(".").length<=1)&&(e+=".yaml",r=".yaml");const i=q.stringifys[r];if(!i)throw new Error(`${e} unsupported mime type: ${r}`);t=i(t);const o=f.default.dirname(e);(0,l.existsSync)(o)||(0,l.mkdirSync)(o,{recursive:!0});return(0,l.writeFileSync)(e,t,{encoding:"utf8"}),e}(e,t,n)}};q.stringifys={},q.register([".yml",".yaml"],h,F),q.register([".json"],(function(e){return JSON.parse(e)}),(e=>JSON.stringify(e,null,2)));var w=require("@isdk/glob"),$=u(require("path"));function R(e,t,n){return n&&(e=$.default.relative(n,e)),(0,w.globMatch)(e,t)}function E(e,t){return"string"==typeof t&&(t=[t]),-1!==t.indexOf(e)}var O=["**/*.((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(e,t=[]){if(e)if(Array.isArray(e))e=[...e];else{const n=e.include||[],r=e.exclude||[];0===n.length&&n.push(...t),e=[...n];for(const t of r)e.push(`!${t}`)}else e=[...t];return 0===e.length&&e.push(...t),e}var z=require("fs/promises"),A=require("fs"),k=u(require("path"));async function L(e,t){const n=await(0,z.readdir)(e,{withFileTypes:!0});for(const r of n){const n=k.default.join(e,r.name);try{if(r.isDirectory()){await t(n,r)||await L(n,t)}else{if(!0===await t(n,r))break}}catch(e){console.error(`Error processing file: ${n}`),console.error(e)}}}function S(e,t){const n=(0,A.readdirSync)(e,{withFileTypes:!0});for(const r of n){const n=k.default.join(e,r.name);try{if(r.isDirectory()){t(n,r)||L(n,t)}else{if(!0===t(n,r))break}}catch(e){console.error(`Error processing file: ${n}`),console.error(e)}}}function T(e){if(!e)return"";return e.replace(/[-_ ]+/g," ").split(" ").filter(Boolean).map((e=>e.charAt(0).toUpperCase()+e.slice(1))).join("")}function N(e){return(e=T(e)).charAt(0).toLowerCase()+e.slice(1)}function M(e){if(!e)return"";return e.replace(/[-_ ]+/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").split(" ").filter(Boolean).map((e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase())).join(" ")}var _=u(require("path")),Y=require("@isdk/common-error"),B=/[<>:"/\\|?*\u0000-\u001F]/,D=/^(con|prn|aux|nul|com\d|lpt\d)$/i,I=100,J=/^\.+(\\|\/)|^\.+$/,V=/\.+$/,P=/[\u0000-\u001F\u0080-\u009F\u200E\u200F\u202A-\u202E\u2066-\u2069]/;function W(){return new RegExp(B.source,"g")}function Z(){return new RegExp(P.source,"g")}function G(e){return e&&!(B.test(e)||Z().test(e)||J.test(e)||V.test(e))}function H(e){const t=e.split(_.default.sep);return("/"===e[0]||t[0]&&_.default.dirname(t[0])===t[0])&&t.shift(),t.every(G)}function K(e,t={}){const n=t.replacement||"!";if((B.test(n)||P.test(n))&&(0,Y.throwError)("Replacement string cannot contain reserved filename characters","sanitizeFilename",Y.ErrorCode.InvalidArgument),n.length>0){const t=/([<>:"/\\|?*\u0000-\u001F]){2,}/;e=e.replace(t,"$1")}if(e=(e=(e=(e=(e=e.normalize("NFD")).replace(J,n)).replace(W(),n)).replace(Z(),n)).replace(V,""),n.length>0){"."===e[0]||"."!==e[0]||(e=n+e),"."===e[e.length-1]&&(e+=n)}e=D.test(e)?e+n:e;const r="number"==typeof t.maxLength?t.maxLength:I;if(e.length>r){const t=e.lastIndexOf(".");if(-1===t)e=e.slice(0,r);else{const n=e.slice(0,t),i=e.slice(t);e=n.slice(0,Math.max(1,r-i.length))+i}}return e}function Q(e,t={}){const n=e.split(_.default.sep);let r;("/"===e[0]||n[0]&&_.default.dirname(n[0])===n[0])&&(r=n.shift());const i=n.map((e=>K(e,t)));return void 0!==r&&i.unshift(r),i.join(_.default.sep)}function U(e){return e.split(".").length-1}
1
+ "use strict";var e,t=Object.create,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,i=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,a=(e,t,i,a)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let c of o(t))s.call(e,c)||c===i||n(e,c,{get:()=>t[c],enumerable:!(a=r(t,c))||a.enumerable});return e},c=(e,r,o)=>(o=null!=e?t(i(e)):{},a(!r&&e&&e.__esModule?o:n(o,"default",{value:e,enumerable:!0}),e)),u={};((e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})})(u,{ConfigFile:()=>j,DefaultAllTextFiles:()=>O,FilenameReservedRegex:()=>D,WindowsReservedNameRegex:()=>I,arrayHasAll:()=>ee,extNameLevel:()=>X,filenameReservedRegex:()=>W,getMultiLevelExtname:()=>g,glob:()=>S,isStringIn:()=>E,isValidFilename:()=>G,isValidFilepath:()=>K,normalizeIncludeFiles:()=>A,parseFrontMatter:()=>w,parseYaml:()=>h,reControlCharsRegex:()=>Z,registerYamlTag:()=>v,removeLeadingEmptyLines:()=>F,sanitizeFilename:()=>Q,sanitizeFilepath:()=>U,stringifyYaml:()=>x,toCamelCase:()=>M,toCapitalCase:()=>_,toPascalCase:()=>N,traverseFolder:()=>L,traverseFolderSync:()=>T}),module.exports=(e=u,a(n({},"__esModule",{value:!0}),e));var f=require("fs"),l=c(require("path")),m=require("load-config-file"),p=c(require("path"));function g(e,t=1){let n="";for(;t--;){const t=p.default.extname(e);if(!t)break;n=t+n,e=p.default.basename(e,t)}return n}var y=require("yaml"),d=[];function v(e){Array.isArray(e)||(e=[e]);for(const t of e){-1===d.indexOf(t)&&d.push(t)}}function h(e,t){if(t)if(t.customTags){if(Array.isArray(t.customTags))t.customTags=d.concat(t.customTags);else if("function"==typeof t.customTags){const e=t.customTags;t.customTags=t=>e(d.concat(t))}}else t.customTags=d;else t={customTags:d};return(0,y.parse)(e,t)}function x(e,t){if(t)if(t.customTags){if(Array.isArray(t.customTags))t.customTags=d.concat(t.customTags);else if("function"==typeof t.customTags){const e=t.customTags;t.customTags=t=>e(d.concat(t))}}else t.customTags=d;else t={customTags:d};return(0,y.stringify)(e,t)}function F(e){const t=/^\s*(#[^\r\n]*)?[\r\n]+/;let n;for(;null!==(n=t.exec(e))&&((e=e.substring(n[0].length)).startsWith("\n")||e.startsWith("\r")||e.trimStart().startsWith("#")););return e}var b="---";function w(e,t=b){const n=t.length,r=F(e);if(r.startsWith(t)&&("\n"===r[t.length]||"\r"===r[t.length])){let e=r.indexOf("\n"+t,n);if(-1!==e){const o=r.slice(n,e);for(e+=t.length+1;"\n"===r[e]||"\r"===r[e];)e++;const i=r.slice(e);return{data:h(o)||{},content:i}}}return{data:{},content:e}}var j=class{static register(e,t,n){m.Config.register(e,t),"string"==typeof e&&(e=[e]);for(const t of e)this.stringifys[t]=n}static loadSync(e,t){return function(e,{extLevel:t=1,externalFile:n}={}){e=q(e,t);let r=m.Config.loadSync(e);if(!r&&n){if(!l.default.isAbsolute(n)){const t=l.default.dirname(e);n=l.default.join(t,n)}if((0,f.existsSync)(n)){const e=w((0,f.readFileSync)(n,"utf8")).data;Object.keys(e).length&&(r=e)}}return r}(e,t)}static saveSync(e,t,n){return function(e,t,{extLevel:n=1}={}){const r=function(e,t=1){"."===e[0]&&t++;let n=g(e,t);(!n||n.split(".").length<=1)&&(e+=".yaml",n=".yaml");const r=new String(e);return r.extname=n,r}(e,n),o=r.extname;e=r.toString();const i=j.stringifys[o];if(!i)throw new Error(`${e} unsupported mime type: ${o}`);t=i(t);const s=l.default.dirname(e);(0,f.existsSync)(s)||(0,f.mkdirSync)(s,{recursive:!0});return(0,f.writeFileSync)(e,t,{encoding:"utf8"}),e}(e,t,n)}static existsSync(e,t){return e=q(e,t?.extLevel),m.Config.existsSync(e,t)}};function q(e,t=1){"."===e[0]&&t++;const n=g(e,t);return n&&n.split(".").length>1&&(e=e.slice(0,-n.length)),e}j.stringifys={},j.register([".yml",".yaml"],h,x),j.register([".json"],(function(e){return JSON.parse(e)}),(e=>JSON.stringify(e,null,2)));var $=require("@isdk/glob"),R=c(require("path"));function S(e,t,n){return n&&(e=R.default.relative(n,e)),(0,$.globMatch)(e,t)}function E(e,t){return"string"==typeof t&&(t=[t]),-1!==t.indexOf(e)}var O=["**/*.((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 A(e,t=[]){if(e)if(Array.isArray(e))e=[...e];else{const n=e.include||[],r=e.exclude||[];0===n.length&&n.push(...t),e=[...n];for(const t of r)e.push(`!${t}`)}else e=[...t];return 0===e.length&&e.push(...t),e}var C=require("fs/promises"),z=require("fs"),k=c(require("path"));async function L(e,t){const n=await(0,C.readdir)(e,{withFileTypes:!0});for(const r of n){const n=k.default.join(e,r.name);try{if(r.isDirectory()){await t(n,r)||await L(n,t)}else{if(!0===await t(n,r))break}}catch(e){console.error(`Error processing file: ${n}`),console.error(e)}}}function T(e,t){const n=(0,z.readdirSync)(e,{withFileTypes:!0});for(const r of n){const n=k.default.join(e,r.name);try{if(r.isDirectory()){t(n,r)||L(n,t)}else{if(!0===t(n,r))break}}catch(e){console.error(`Error processing file: ${n}`),console.error(e)}}}function N(e){if(!e)return"";return e.replace(/[-_ ]+/g," ").split(" ").filter(Boolean).map((e=>e.charAt(0).toUpperCase()+e.slice(1))).join("")}function M(e){return(e=N(e)).charAt(0).toLowerCase()+e.slice(1)}function _(e){if(!e)return"";return e.replace(/[-_ ]+/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").split(" ").filter(Boolean).map((e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase())).join(" ")}var Y=c(require("path")),B=require("@isdk/common-error"),D=/[<>:"/\\|?*\u0000-\u001F]/,I=/^(con|prn|aux|nul|com\d|lpt\d)$/i,J=100,V=/^\.+(\\|\/)|^\.+$/,H=/\.+$/,P=/[\u0000-\u001F\u0080-\u009F\u200E\u200F\u202A-\u202E\u2066-\u2069]/;function W(){return new RegExp(D.source,"g")}function Z(){return new RegExp(P.source,"g")}function G(e){return e&&!(D.test(e)||Z().test(e)||V.test(e)||H.test(e))}function K(e){const t=e.split(Y.default.sep);return("/"===e[0]||t[0]&&Y.default.dirname(t[0])===t[0])&&t.shift(),t.every(G)}function Q(e,t={}){const n=t.replacement||"!";if((D.test(n)||P.test(n))&&(0,B.throwError)("Replacement string cannot contain reserved filename characters","sanitizeFilename",B.ErrorCode.InvalidArgument),n.length>0){const t=/([<>:"/\\|?*\u0000-\u001F]){2,}/;e=e.replace(t,"$1")}if(e=(e=(e=(e=(e=e.normalize("NFD")).replace(V,n)).replace(W(),n)).replace(Z(),n)).replace(H,""),n.length>0){"."===e[0]||"."!==e[0]||(e=n+e),"."===e[e.length-1]&&(e+=n)}e=I.test(e)?e+n:e;const r="number"==typeof t.maxLength?t.maxLength:J;if(e.length>r){const t=e.lastIndexOf(".");if(-1===t)e=e.slice(0,r);else{const n=e.slice(0,t),o=e.slice(t);e=n.slice(0,Math.max(1,r-o.length))+o}}return e}function U(e,t={}){const n=e.split(Y.default.sep);let r;("/"===e[0]||n[0]&&Y.default.dirname(n[0])===n[0])&&(r=n.shift());const o=n.map((e=>Q(e,t)));return void 0!==r&&o.unshift(r),o.join(Y.default.sep)}function X(e){return e.split(".").length-1}function ee(e,t){const n=new Set(t),r=new Set;for(const t of e)if(n.has(t)&&(r.add(t),r.size===n.size))return!0;return r.size===n.size}
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{existsSync as t,mkdirSync as n,readFileSync as o,writeFileSync as r}from"fs";import e from"path";import{Config as i}from"load-config-file";import s from"path";function f(t,n=1){let o="";for(;n--;){const n=s.extname(t);if(!n)break;o=n+o,t=s.basename(t,n)}return o}import{parse as c,stringify as u}from"yaml";var a=[];function l(t){Array.isArray(t)||(t=[t]);for(const n of t){-1===a.indexOf(n)&&a.push(n)}}function m(t,n){if(n)if(n.customTags){if(Array.isArray(n.customTags))n.customTags=a.concat(n.customTags);else if("function"==typeof n.customTags){const t=n.customTags;n.customTags=n=>t(a.concat(n))}}else n.customTags=a;else n={customTags:a};return c(t,n)}function p(t,n){if(n)if(n.customTags){if(Array.isArray(n.customTags))n.customTags=a.concat(n.customTags);else if("function"==typeof n.customTags){const t=n.customTags;n.customTags=n=>t(a.concat(n))}}else n.customTags=a;else n={customTags:a};return u(t,n)}function y(t){const n=/^\s*(#[^\r\n]*)?[\r\n]+/;let o;for(;null!==(o=n.exec(t))&&((t=t.substring(o[0].length)).startsWith("\n")||t.startsWith("\r")||t.trimStart().startsWith("#")););return t}function g(t,n="---"){const o=n.length,r=y(t);if(r.startsWith(n)&&("\n"===r[n.length]||"\r"===r[n.length])){let t=r.indexOf("\n"+n,o);if(-1!==t){const e=r.slice(o,t);for(t+=n.length+1;"\n"===r[t]||"\r"===r[t];)t++;const i=r.slice(t);return{data:m(e)||{},content:i}}}return{data:{},content:t}}var h=class{static register(t,n,o){i.register(t,n),"string"==typeof t&&(t=[t]);for(const n of t)this.stringifys[n]=o}static loadSync(n,r){return function(n,{extLevel:r=1,externalFile:s}={}){"."===n[0]&&r++;const c=f(n,r);c&&c.split(".").length>1&&(n=n.slice(0,-c.length));let u=i.loadSync(n);if(!u&&s){if(!e.isAbsolute(s)){const t=e.dirname(n);s=e.join(t,s)}if(t(s)){const t=g(o(s,"utf8")).data;Object.keys(t).length&&(u=t)}}return u}(n,r)}static saveSync(o,i,s){return function(o,i,{extLevel:s=1}={}){"."===o[0]&&s++;let c=f(o,s);(!c||c.split(".").length<=1)&&(o+=".yaml",c=".yaml");const u=h.stringifys[c];if(!u)throw new Error(`${o} unsupported mime type: ${c}`);i=u(i);const a=e.dirname(o);t(a)||n(a,{recursive:!0});return r(o,i,{encoding:"utf8"}),o}(o,i,s)}};h.stringifys={},h.register([".yml",".yaml"],m,p),h.register([".json"],(function(t){return JSON.parse(t)}),(t=>JSON.stringify(t,null,2)));import{globMatch as d}from"@isdk/glob";import x from"path";function v(t,n,o){return o&&(t=x.relative(o,t)),d(t,n)}function w(t,n){return"string"==typeof n&&(n=[n]),-1!==n.indexOf(t)}var $=["**/*.((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,n=[]){if(t)if(Array.isArray(t))t=[...t];else{const o=t.include||[],r=t.exclude||[];0===o.length&&o.push(...n),t=[...o];for(const n of r)t.push(`!${n}`)}else t=[...n];return 0===t.length&&t.push(...n),t}import{readdir as b}from"fs/promises";import{readdirSync as E}from"fs";import j from"path";async function k(t,n){const o=await b(t,{withFileTypes:!0});for(const r of o){const o=j.join(t,r.name);try{if(r.isDirectory()){await n(o,r)||await k(o,n)}else{if(!0===await n(o,r))break}}catch(t){console.error(`Error processing file: ${o}`),console.error(t)}}}function A(t,n){const o=E(t,{withFileTypes:!0});for(const r of o){const o=j.join(t,r.name);try{if(r.isDirectory()){n(o,r)||k(o,n)}else{if(!0===n(o,r))break}}catch(t){console.error(`Error processing file: ${o}`),console.error(t)}}}function z(t){if(!t)return"";return t.replace(/[-_ ]+/g," ").split(" ").filter(Boolean).map((t=>t.charAt(0).toUpperCase()+t.slice(1))).join("")}function S(t){return(t=z(t)).charAt(0).toLowerCase()+t.slice(1)}function T(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 N from"path";import{ErrorCode as O,throwError as R}from"@isdk/common-error";var B=/[<>:"/\\|?*\u0000-\u001F]/,J=/^(con|prn|aux|nul|com\d|lpt\d)$/i,L=/^\.+(\\|\/)|^\.+$/,_=/\.+$/,C=/[\u0000-\u001F\u0080-\u009F\u200E\u200F\u202A-\u202E\u2066-\u2069]/;function D(){return new RegExp(B.source,"g")}function M(){return new RegExp(C.source,"g")}function Z(t){return t&&!(B.test(t)||M().test(t)||L.test(t)||_.test(t))}function q(t){const n=t.split(N.sep);return("/"===t[0]||n[0]&&N.dirname(n[0])===n[0])&&n.shift(),n.every(Z)}function G(t,n={}){const o=n.replacement||"!";if((B.test(o)||C.test(o))&&R("Replacement string cannot contain reserved filename characters","sanitizeFilename",O.InvalidArgument),o.length>0){const n=/([<>:"/\\|?*\u0000-\u001F]){2,}/;t=t.replace(n,"$1")}if(t=(t=(t=(t=(t=t.normalize("NFD")).replace(L,o)).replace(D(),o)).replace(M(),o)).replace(_,""),o.length>0){"."===t[0]||"."!==t[0]||(t=o+t),"."===t[t.length-1]&&(t+=o)}t=J.test(t)?t+o:t;const r="number"==typeof n.maxLength?n.maxLength:100;if(t.length>r){const n=t.lastIndexOf(".");if(-1===n)t=t.slice(0,r);else{const o=t.slice(0,n),e=t.slice(n);t=o.slice(0,Math.max(1,r-e.length))+e}}return t}function H(t,n={}){const o=t.split(N.sep);let r;("/"===t[0]||o[0]&&N.dirname(o[0])===o[0])&&(r=o.shift());const e=o.map((t=>G(t,n)));return void 0!==r&&e.unshift(r),e.join(N.sep)}function I(t){return t.split(".").length-1}export{h as ConfigFile,$ as DefaultAllTextFiles,B as FilenameReservedRegex,J as WindowsReservedNameRegex,I as extNameLevel,D as filenameReservedRegex,f as getMultiLevelExtname,v as glob,w as isStringIn,Z as isValidFilename,q as isValidFilepath,F as normalizeIncludeFiles,g as parseFrontMatter,m as parseYaml,M as reControlCharsRegex,l as registerYamlTag,y as removeLeadingEmptyLines,G as sanitizeFilename,H as sanitizeFilepath,p as stringifyYaml,S as toCamelCase,T as toCapitalCase,z as toPascalCase,k as traverseFolder,A as traverseFolderSync};
1
+ import{existsSync as t,mkdirSync as n,readFileSync as r,writeFileSync as o}from"fs";import e from"path";import{Config as i}from"load-config-file";import s from"path";function c(t,n=1){let r="";for(;n--;){const n=s.extname(t);if(!n)break;r=n+r,t=s.basename(t,n)}return r}import{parse as f,stringify as u}from"yaml";var a=[];function l(t){Array.isArray(t)||(t=[t]);for(const n of t){-1===a.indexOf(n)&&a.push(n)}}function m(t,n){if(n)if(n.customTags){if(Array.isArray(n.customTags))n.customTags=a.concat(n.customTags);else if("function"==typeof n.customTags){const t=n.customTags;n.customTags=n=>t(a.concat(n))}}else n.customTags=a;else n={customTags:a};return f(t,n)}function p(t,n){if(n)if(n.customTags){if(Array.isArray(n.customTags))n.customTags=a.concat(n.customTags);else if("function"==typeof n.customTags){const t=n.customTags;n.customTags=n=>t(a.concat(n))}}else n.customTags=a;else n={customTags:a};return u(t,n)}function y(t){const n=/^\s*(#[^\r\n]*)?[\r\n]+/;let r;for(;null!==(r=n.exec(t))&&((t=t.substring(r[0].length)).startsWith("\n")||t.startsWith("\r")||t.trimStart().startsWith("#")););return t}function g(t,n="---"){const r=n.length,o=y(t);if(o.startsWith(n)&&("\n"===o[n.length]||"\r"===o[n.length])){let t=o.indexOf("\n"+n,r);if(-1!==t){const e=o.slice(r,t);for(t+=n.length+1;"\n"===o[t]||"\r"===o[t];)t++;const i=o.slice(t);return{data:m(e)||{},content:i}}}return{data:{},content:t}}var h=class{static register(t,n,r){i.register(t,n),"string"==typeof t&&(t=[t]);for(const n of t)this.stringifys[n]=r}static loadSync(n,o){return function(n,{extLevel:o=1,externalFile:s}={}){n=x(n,o);let c=i.loadSync(n);if(!c&&s){if(!e.isAbsolute(s)){const t=e.dirname(n);s=e.join(t,s)}if(t(s)){const t=g(r(s,"utf8")).data;Object.keys(t).length&&(c=t)}}return c}(n,o)}static saveSync(r,i,s){return function(r,i,{extLevel:s=1}={}){const f=function(t,n=1){"."===t[0]&&n++;let r=c(t,n);(!r||r.split(".").length<=1)&&(t+=".yaml",r=".yaml");const o=new String(t);return o.extname=r,o}(r,s),u=f.extname;r=f.toString();const a=h.stringifys[u];if(!a)throw new Error(`${r} unsupported mime type: ${u}`);i=a(i);const l=e.dirname(r);t(l)||n(l,{recursive:!0});return o(r,i,{encoding:"utf8"}),r}(r,i,s)}static existsSync(t,n){return t=x(t,n?.extLevel),i.existsSync(t,n)}};function x(t,n=1){"."===t[0]&&n++;const r=c(t,n);return r&&r.split(".").length>1&&(t=t.slice(0,-r.length)),t}h.stringifys={},h.register([".yml",".yaml"],m,p),h.register([".json"],(function(t){return JSON.parse(t)}),(t=>JSON.stringify(t,null,2)));import{globMatch as d}from"@isdk/glob";import w from"path";function v(t,n,r){return r&&(t=w.relative(r,t)),d(t,n)}function $(t,n){return"string"==typeof n&&(n=[n]),-1!==n.indexOf(t)}var F=["**/*.((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 b(t,n=[]){if(t)if(Array.isArray(t))t=[...t];else{const r=t.include||[],o=t.exclude||[];0===r.length&&r.push(...n),t=[...r];for(const n of o)t.push(`!${n}`)}else t=[...n];return 0===t.length&&t.push(...n),t}import{readdir as S}from"fs/promises";import{readdirSync as E}from"fs";import j from"path";async function k(t,n){const r=await S(t,{withFileTypes:!0});for(const o of r){const r=j.join(t,o.name);try{if(o.isDirectory()){await n(r,o)||await k(r,n)}else{if(!0===await n(r,o))break}}catch(t){console.error(`Error processing file: ${r}`),console.error(t)}}}function A(t,n){const r=E(t,{withFileTypes:!0});for(const o of r){const r=j.join(t,o.name);try{if(o.isDirectory()){n(r,o)||k(r,n)}else{if(!0===n(r,o))break}}catch(t){console.error(`Error processing file: ${r}`),console.error(t)}}}function z(t){if(!t)return"";return t.replace(/[-_ ]+/g," ").split(" ").filter(Boolean).map((t=>t.charAt(0).toUpperCase()+t.slice(1))).join("")}function T(t){return(t=z(t)).charAt(0).toLowerCase()+t.slice(1)}function N(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 B}from"@isdk/common-error";var J=/[<>:"/\\|?*\u0000-\u001F]/,L=/^(con|prn|aux|nul|com\d|lpt\d)$/i,_=/^\.+(\\|\/)|^\.+$/,C=/\.+$/,D=/[\u0000-\u001F\u0080-\u009F\u200E\u200F\u202A-\u202E\u2066-\u2069]/;function M(){return new RegExp(J.source,"g")}function Z(){return new RegExp(D.source,"g")}function q(t){return t&&!(J.test(t)||Z().test(t)||_.test(t)||C.test(t))}function G(t){const n=t.split(O.sep);return("/"===t[0]||n[0]&&O.dirname(n[0])===n[0])&&n.shift(),n.every(q)}function H(t,n={}){const r=n.replacement||"!";if((J.test(r)||D.test(r))&&B("Replacement string cannot contain reserved filename characters","sanitizeFilename",R.InvalidArgument),r.length>0){const n=/([<>:"/\\|?*\u0000-\u001F]){2,}/;t=t.replace(n,"$1")}if(t=(t=(t=(t=(t=t.normalize("NFD")).replace(_,r)).replace(M(),r)).replace(Z(),r)).replace(C,""),r.length>0){"."===t[0]||"."!==t[0]||(t=r+t),"."===t[t.length-1]&&(t+=r)}t=L.test(t)?t+r:t;const o="number"==typeof n.maxLength?n.maxLength:100;if(t.length>o){const n=t.lastIndexOf(".");if(-1===n)t=t.slice(0,o);else{const r=t.slice(0,n),e=t.slice(n);t=r.slice(0,Math.max(1,o-e.length))+e}}return t}function I(t,n={}){const r=t.split(O.sep);let o;("/"===t[0]||r[0]&&O.dirname(r[0])===r[0])&&(o=r.shift());const e=r.map((t=>H(t,n)));return void 0!==o&&e.unshift(o),e.join(O.sep)}function K(t){return t.split(".").length-1}function P(t,n){const r=new Set(n),o=new Set;for(const n of t)if(r.has(n)&&(o.add(n),o.size===r.size))return!0;return o.size===r.size}export{h as ConfigFile,F as DefaultAllTextFiles,J as FilenameReservedRegex,L as WindowsReservedNameRegex,P as arrayHasAll,K as extNameLevel,M as filenameReservedRegex,c as getMultiLevelExtname,v as glob,$ as isStringIn,q as isValidFilename,G as isValidFilepath,b as normalizeIncludeFiles,g as parseFrontMatter,m as parseYaml,Z as reControlCharsRegex,l as registerYamlTag,y as removeLeadingEmptyLines,H as sanitizeFilename,I as sanitizeFilepath,p as stringifyYaml,T as toCamelCase,N as toCapitalCase,z as toPascalCase,k as traverseFolder,A as traverseFolderSync};
@@ -6,7 +6,7 @@
6
6
 
7
7
  # Class: ConfigFile
8
8
 
9
- Defined in: [config-file.ts:46](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/config-file.ts#L46)
9
+ Defined in: [config-file.ts:46](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/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,17 +45,66 @@ console.log(config); // Output: { key: 'value' }
45
45
 
46
46
  > `static` **stringifys**: `Record`\<`string`, [`StringifyFunc`](../type-aliases/StringifyFunc.md)\> = `{}`
47
47
 
48
- Defined in: [config-file.ts:50](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/config-file.ts#L50)
48
+ Defined in: [config-file.ts:50](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/config-file.ts#L50)
49
49
 
50
50
  A record of registered stringify functions for different file extensions.
51
51
 
52
52
  ## Methods
53
53
 
54
+ ### existsSync()
55
+
56
+ > `static` **existsSync**(`filename`, `options`?): `boolean`
57
+
58
+ Defined in: [config-file.ts:132](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/config-file.ts#L132)
59
+
60
+ Checks if a configuration file exists at the specified path.
61
+
62
+ This method normalizes the filename by removing the extension (if present) and then delegates
63
+ to the underlying LoadConfigFile utility to perform the existence check. The normalization
64
+ ensures consistent handling of files regardless of whether they include extensions in the
65
+ provided filename.
66
+
67
+ #### Parameters
68
+
69
+ ##### filename
70
+
71
+ `string`
72
+
73
+ The path to the configuration file to check for existence.
74
+ This can include or omit the file extension.
75
+
76
+ ##### options?
77
+
78
+ [`LoadConfigFileOptions`](../interfaces/LoadConfigFileOptions.md)
79
+
80
+ Optional configuration options that may affect how the file existence
81
+ is checked, including extension level handling.
82
+
83
+ #### Returns
84
+
85
+ `boolean`
86
+
87
+ `true` if the configuration file exists, `false` otherwise.
88
+
89
+ #### Example
90
+
91
+ ```typescript
92
+ // Check if a YAML config file exists
93
+ const exists = ConfigFile.existsSync('config.yaml');
94
+ console.log(exists); // true or false
95
+
96
+ // Check with options
97
+ const existsWithExt = ConfigFile.existsSync('config', { extLevel: 2 });
98
+ console.log(existsWithExt); // true or false
99
+ ```
100
+
101
+ ***
102
+
54
103
  ### loadSync()
55
104
 
56
105
  > `static` **loadSync**(`filename`, `options`?): `any`
57
106
 
58
- Defined in: [config-file.ts:85](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/config-file.ts#L85)
107
+ Defined in: [config-file.ts:85](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/config-file.ts#L85)
59
108
 
60
109
  Loads a configuration file based on the provided filename and options.
61
110
 
@@ -92,7 +141,7 @@ console.log(config); // Output: { key: 'value' }
92
141
 
93
142
  > `static` **register**(`extname`, `parser`, `stringify`): `void`
94
143
 
95
- Defined in: [config-file.ts:64](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/config-file.ts#L64)
144
+ Defined in: [config-file.ts:64](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/config-file.ts#L64)
96
145
 
97
146
  Registers a parser and stringifier for specific file extensions.
98
147
 
@@ -132,7 +181,7 @@ ConfigFile.register(['.json'], JSON.parse, (obj) => JSON.stringify(obj, null, 2)
132
181
 
133
182
  > `static` **saveSync**(`filename`, `config`, `options`?): `string`
134
183
 
135
- Defined in: [config-file.ts:102](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/config-file.ts#L102)
184
+ Defined in: [config-file.ts:102](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/config-file.ts#L102)
136
185
 
137
186
  Saves a configuration object to a file with the specified filename and options.
138
187
 
@@ -0,0 +1,48 @@
1
+ [**@isdk/util**](../README.md)
2
+
3
+ ***
4
+
5
+ [@isdk/util](../globals.md) / arrayHasAll
6
+
7
+ # Function: arrayHasAll()
8
+
9
+ > **arrayHasAll**\<`T`\>(`array`, `elements`): `boolean`
10
+
11
+ Defined in: [array-has-all.ts:15](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/array-has-all.ts#L15)
12
+
13
+ Checks whether the provided array contains all of the specified elements.
14
+
15
+ ## Type Parameters
16
+
17
+ ### T
18
+
19
+ `T` = `any`
20
+
21
+ The type of elements in the arrays.
22
+
23
+ ## Parameters
24
+
25
+ ### array
26
+
27
+ `T`[]
28
+
29
+ The array to check against.
30
+
31
+ ### elements
32
+
33
+ `T`[]
34
+
35
+ The list of elements to be checked for presence in the array.
36
+
37
+ ## Returns
38
+
39
+ `boolean`
40
+
41
+ `true` if all elements are present in the array; otherwise, `false`.
42
+
43
+ ## Example
44
+
45
+ ```ts
46
+ arrayHasAll([1, 2, 3], [2, 3]); // true
47
+ arrayHasAll(['a', 'b', 'c'], ['x', 'y']); // false
48
+ ```
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **extNameLevel**(`extName`): `number`
10
10
 
11
- Defined in: [filename.ts:189](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/filename.ts#L189)
11
+ Defined in: [filename.ts:189](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/filename.ts#L189)
12
12
 
13
13
  Calculates the level of an extension name.
14
14
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **filenameReservedRegex**(): `RegExp`
10
10
 
11
- Defined in: [filename.ts:42](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/filename.ts#L42)
11
+ Defined in: [filename.ts:42](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/filename.ts#L42)
12
12
 
13
13
  Returns a new regular expression instance for reserved filename characters with the 'g' flag.
14
14
  use this to reset the with global option
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **getMultiLevelExtname**(`filename`, `level`): `string`
10
10
 
11
- Defined in: [get-multi-level-extname.ts:9](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/get-multi-level-extname.ts#L9)
11
+ Defined in: [get-multi-level-extname.ts:9](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/get-multi-level-extname.ts#L9)
12
12
 
13
13
  Retrieves multi-level file extension
14
14
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **glob**(`filepath`, `pattern`, `rootDir`?): `undefined` \| `boolean`
10
10
 
11
- Defined in: [glob.ts:29](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/glob.ts#L29)
11
+ Defined in: [glob.ts:29](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/glob.ts#L29)
12
12
 
13
13
  Matches a file path against a list of glob patterns.
14
14
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **isStringIn**(`str`, `arr`): `boolean`
10
10
 
11
- Defined in: [is-string-in.ts:17](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/is-string-in.ts#L17)
11
+ Defined in: [is-string-in.ts:17](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/is-string-in.ts#L17)
12
12
 
13
13
  Checks if a given string exists within an array of strings or a single string.
14
14
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **isValidFilename**(`filename`): `boolean` \| `""`
10
10
 
11
- Defined in: [filename.ts:63](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/filename.ts#L63)
11
+ Defined in: [filename.ts:63](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/filename.ts#L63)
12
12
 
13
13
  Validates if a given string is a valid filename.
14
14
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **isValidFilepath**(`filepath`): `boolean`
10
10
 
11
- Defined in: [filename.ts:72](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/filename.ts#L72)
11
+ Defined in: [filename.ts:72](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/filename.ts#L72)
12
12
 
13
13
  Validates whether the given filepath is valid.
14
14
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **normalizeIncludeFiles**(`files`?, `defaultFiles`?): `string`[]
10
10
 
11
- Defined in: [include-files.ts:34](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/include-files.ts#L34)
11
+ Defined in: [include-files.ts:34](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/include-files.ts#L34)
12
12
 
13
13
  Normalizes a list of file patterns for glob matching.
14
14
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **parseFrontMatter**(`value`, `delimiter`): `object`
10
10
 
11
- Defined in: [front-matter.ts:6](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/front-matter.ts#L6)
11
+ Defined in: [front-matter.ts:6](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/front-matter.ts#L6)
12
12
 
13
13
  ## Parameters
14
14
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **parseYaml**(`content`, `options`?): `any`
10
10
 
11
- Defined in: [yaml.ts:51](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/yaml.ts#L51)
11
+ Defined in: [yaml.ts:51](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/yaml.ts#L51)
12
12
 
13
13
  Parses a YAML string into a JavaScript object with optional custom tags.
14
14
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **reControlCharsRegex**(): `RegExp`
10
10
 
11
- Defined in: [filename.ts:50](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/filename.ts#L50)
11
+ Defined in: [filename.ts:50](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/filename.ts#L50)
12
12
 
13
13
  Returns a new regular expression instance for control characters in a filename with the 'g' flag.
14
14
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **registerYamlTag**(`tags`): `void`
10
10
 
11
- Defined in: [yaml.ts:23](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/yaml.ts#L23)
11
+ Defined in: [yaml.ts:23](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/yaml.ts#L23)
12
12
 
13
13
  Registers custom YAML tags to be used in parsing and stringifying YAML content.
14
14
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **removeLeadingEmptyLines**(`text`): `string`
10
10
 
11
- Defined in: [remove-leading-empty-lines.ts:16](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/remove-leading-empty-lines.ts#L16)
11
+ Defined in: [remove-leading-empty-lines.ts:16](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/remove-leading-empty-lines.ts#L16)
12
12
 
13
13
  Removes all leading empty lines or "#" comments line from the given string.
14
14
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **sanitizeFilename**(`filename`, `options`): `string`
10
10
 
11
- Defined in: [filename.ts:97](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/filename.ts#L97)
11
+ Defined in: [filename.ts:97](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/filename.ts#L97)
12
12
 
13
13
  Sanitizes a given filename by replacing invalid characters with a specified replacement character or a default.
14
14
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **sanitizeFilepath**(`filepath`, `options`): `string`
10
10
 
11
- Defined in: [filename.ts:149](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/filename.ts#L149)
11
+ Defined in: [filename.ts:149](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/filename.ts#L149)
12
12
 
13
13
  Sanitizes each part of a file path and reassembles it, ensuring the path is valid according to provided options.
14
14
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **stringifyYaml**(`content`, `options`?): `string`
10
10
 
11
- Defined in: [yaml.ts:85](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/yaml.ts#L85)
11
+ Defined in: [yaml.ts:85](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/yaml.ts#L85)
12
12
 
13
13
  Converts a JavaScript object into a YAML string with optional custom tags.
14
14
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **toCamelCase**(`str`): `string`
10
10
 
11
- Defined in: [to-camel-case.ts:17](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/to-camel-case.ts#L17)
11
+ Defined in: [to-camel-case.ts:17](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/to-camel-case.ts#L17)
12
12
 
13
13
  Converts a string to camelCase.
14
14
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **toCapitalCase**(`str`): `string`
10
10
 
11
- Defined in: [to-capital-case.ts:17](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/to-capital-case.ts#L17)
11
+ Defined in: [to-capital-case.ts:17](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/to-capital-case.ts#L17)
12
12
 
13
13
  Converts a string to capital case, where the first letter of each word is capitalized
14
14
  and the rest are in lowercase. Words are separated by spaces, hyphens, or underscores.
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **toPascalCase**(`str`): `string`
10
10
 
11
- Defined in: [to-pascal-case.ts:16](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/to-pascal-case.ts#L16)
11
+ Defined in: [to-pascal-case.ts:16](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/to-pascal-case.ts#L16)
12
12
 
13
13
  Converts a string to PascalCase.
14
14
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **traverseFolder**(`directoryPath`, `fileHandler`): `Promise`\<`void`\>
10
10
 
11
- Defined in: [traverse-folder.ts:38](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/traverse-folder.ts#L38)
11
+ Defined in: [traverse-folder.ts:38](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/traverse-folder.ts#L38)
12
12
 
13
13
  Traverses a folder asynchronously and applies a handler to each file or directory.
14
14
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **traverseFolderSync**(`directoryPath`, `fileHandler`): `void`
10
10
 
11
- Defined in: [traverse-folder.ts:76](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/traverse-folder.ts#L76)
11
+ Defined in: [traverse-folder.ts:76](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/traverse-folder.ts#L76)
12
12
 
13
13
  Traverses a folder synchronously and applies a handler to each file or directory.
14
14
 
package/docs/globals.md CHANGED
@@ -28,6 +28,7 @@
28
28
 
29
29
  ## Functions
30
30
 
31
+ - [arrayHasAll](functions/arrayHasAll.md)
31
32
  - [extNameLevel](functions/extNameLevel.md)
32
33
  - [filenameReservedRegex](functions/filenameReservedRegex.md)
33
34
  - [getMultiLevelExtname](functions/getMultiLevelExtname.md)
@@ -6,7 +6,7 @@
6
6
 
7
7
  # Interface: IncludeFiles
8
8
 
9
- Defined in: [include-files.ts:6](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/include-files.ts#L6)
9
+ Defined in: [include-files.ts:6](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/include-files.ts#L6)
10
10
 
11
11
  ## Properties
12
12
 
@@ -14,7 +14,7 @@ Defined in: [include-files.ts:6](https://github.com/isdk/util.js/blob/4a17f40c64
14
14
 
15
15
  > `optional` **exclude**: `string`[]
16
16
 
17
- Defined in: [include-files.ts:8](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/include-files.ts#L8)
17
+ Defined in: [include-files.ts:8](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/include-files.ts#L8)
18
18
 
19
19
  ***
20
20
 
@@ -22,4 +22,4 @@ Defined in: [include-files.ts:8](https://github.com/isdk/util.js/blob/4a17f40c64
22
22
 
23
23
  > `optional` **include**: `string`[]
24
24
 
25
- Defined in: [include-files.ts:7](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/include-files.ts#L7)
25
+ Defined in: [include-files.ts:7](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/include-files.ts#L7)
@@ -6,7 +6,7 @@
6
6
 
7
7
  # Interface: LoadConfigFileOptions
8
8
 
9
- Defined in: [config-file.ts:20](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/config-file.ts#L20)
9
+ Defined in: [config-file.ts:20](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/config-file.ts#L20)
10
10
 
11
11
  ## Properties
12
12
 
@@ -14,7 +14,7 @@ Defined in: [config-file.ts:20](https://github.com/isdk/util.js/blob/4a17f40c648
14
14
 
15
15
  > `optional` **externalFile**: `string`
16
16
 
17
- Defined in: [config-file.ts:22](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/config-file.ts#L22)
17
+ Defined in: [config-file.ts:22](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/config-file.ts#L22)
18
18
 
19
19
  ***
20
20
 
@@ -22,4 +22,4 @@ Defined in: [config-file.ts:22](https://github.com/isdk/util.js/blob/4a17f40c648
22
22
 
23
23
  > `optional` **extLevel**: `number`
24
24
 
25
- Defined in: [config-file.ts:21](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/config-file.ts#L21)
25
+ Defined in: [config-file.ts:21](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/config-file.ts#L21)
@@ -6,7 +6,7 @@
6
6
 
7
7
  # Interface: SanitizeFilenameOptions
8
8
 
9
- Defined in: [filename.ts:83](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/filename.ts#L83)
9
+ Defined in: [filename.ts:83](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/filename.ts#L83)
10
10
 
11
11
  ## Properties
12
12
 
@@ -14,7 +14,7 @@ Defined in: [filename.ts:83](https://github.com/isdk/util.js/blob/4a17f40c6487cc
14
14
 
15
15
  > `optional` **maxLength**: `number`
16
16
 
17
- Defined in: [filename.ts:85](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/filename.ts#L85)
17
+ Defined in: [filename.ts:85](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/filename.ts#L85)
18
18
 
19
19
  ***
20
20
 
@@ -22,4 +22,4 @@ Defined in: [filename.ts:85](https://github.com/isdk/util.js/blob/4a17f40c6487cc
22
22
 
23
23
  > `optional` **replacement**: `string`
24
24
 
25
- Defined in: [filename.ts:84](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/filename.ts#L84)
25
+ Defined in: [filename.ts:84](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/filename.ts#L84)
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **StringifyFunc** = (`content`) => `string`
10
10
 
11
- Defined in: [config-file.ts:18](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/config-file.ts#L18)
11
+ Defined in: [config-file.ts:18](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/config-file.ts#L18)
12
12
 
13
13
  ## Parameters
14
14
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **TraverseFolderHandler** = (`filePath`, `entry`) => `boolean` \| `void` \| `Promise`\<`boolean` \| `void`\>
10
10
 
11
- Defined in: [traverse-folder.ts:11](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/traverse-folder.ts#L11)
11
+ Defined in: [traverse-folder.ts:11](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/traverse-folder.ts#L11)
12
12
 
13
13
  A handler function for asynchronous folder traversal.
14
14
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **TraverseFolderSyncHandler** = (`filePath`, `entry`) => `boolean` \| `void`
10
10
 
11
- Defined in: [traverse-folder.ts:18](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/traverse-folder.ts#L18)
11
+ Defined in: [traverse-folder.ts:18](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/traverse-folder.ts#L18)
12
12
 
13
13
  A handler function for synchronous folder traversal.
14
14
 
@@ -8,4 +8,4 @@
8
8
 
9
9
  > `const` **DefaultAllTextFiles**: `string`[]
10
10
 
11
- Defined in: [include-files.ts:1](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/include-files.ts#L1)
11
+ Defined in: [include-files.ts:1](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/include-files.ts#L1)
@@ -8,7 +8,7 @@
8
8
 
9
9
  > `const` **FilenameReservedRegex**: `RegExp`
10
10
 
11
- Defined in: [filename.ts:8](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/filename.ts#L8)
11
+ Defined in: [filename.ts:8](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/filename.ts#L8)
12
12
 
13
13
  Regular expression pattern for reserved characters in a filename.
14
14
  do not use /g global option here: when the regex is executed multiple times, it will always begin where it left off last time.
@@ -8,6 +8,6 @@
8
8
 
9
9
  > `const` **WindowsReservedNameRegex**: `RegExp`
10
10
 
11
- Defined in: [filename.ts:13](https://github.com/isdk/util.js/blob/4a17f40c6487cc8186e888c58b4e6268f4dcb357/src/filename.ts#L13)
11
+ Defined in: [filename.ts:13](https://github.com/isdk/util.js/blob/e52ad0627fc33dea09d8db6ef431d619770364c0/src/filename.ts#L13)
12
12
 
13
13
  Regular expression pattern for reserved names on Windows systems.
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@isdk/util",
3
3
  "description": "a set of utility functions",
4
- "version": "0.3.0",
4
+ "version": "0.3.2",
5
5
  "author": "Riceball LEE @snowyu",
6
6
  "bugs": "https://github.com/isdk/util.js/issues",
7
7
  "dependencies": {
8
8
  "@isdk/common-error": "^0.1.4",
9
9
  "@isdk/glob": "^0.1.0",
10
- "load-config-file": "2.0.0",
10
+ "load-config-file": "^2.1.0",
11
11
  "yaml": "^2.7.0"
12
12
  },
13
13
  "devDependencies": {