@isdk/util 0.1.1

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 (96) hide show
  1. package/README.md +6 -0
  2. package/dist/chunk-3TCMKKX2.mjs +1 -0
  3. package/dist/chunk-46TT3NZV.mjs +1 -0
  4. package/dist/chunk-7APJBRA7.mjs +1 -0
  5. package/dist/chunk-7AQU3PBW.mjs +1 -0
  6. package/dist/chunk-D3BCI5SM.mjs +1 -0
  7. package/dist/chunk-FXF2KJLF.mjs +1 -0
  8. package/dist/chunk-GGOKSJK4.mjs +1 -0
  9. package/dist/chunk-JTTOXXPG.mjs +1 -0
  10. package/dist/chunk-LOMQZH4U.mjs +292 -0
  11. package/dist/chunk-OTEAFARC.mjs +1 -0
  12. package/dist/chunk-UJZVJIGI.mjs +1 -0
  13. package/dist/config-file.d.mts +75 -0
  14. package/dist/config-file.d.ts +75 -0
  15. package/dist/config-file.js +1 -0
  16. package/dist/config-file.mjs +1 -0
  17. package/dist/config-file.test.d.mts +2 -0
  18. package/dist/config-file.test.d.ts +2 -0
  19. package/dist/config-file.test.js +292 -0
  20. package/dist/config-file.test.mjs +1 -0
  21. package/dist/front-matter.d.mts +6 -0
  22. package/dist/front-matter.d.ts +6 -0
  23. package/dist/front-matter.js +1 -0
  24. package/dist/front-matter.mjs +1 -0
  25. package/dist/front-matter.test.d.mts +2 -0
  26. package/dist/front-matter.test.d.ts +2 -0
  27. package/dist/front-matter.test.js +1 -0
  28. package/dist/front-matter.test.mjs +1 -0
  29. package/dist/get-multi-level-extname.d.mts +9 -0
  30. package/dist/get-multi-level-extname.d.ts +9 -0
  31. package/dist/get-multi-level-extname.js +1 -0
  32. package/dist/get-multi-level-extname.mjs +1 -0
  33. package/dist/glob.d.mts +28 -0
  34. package/dist/glob.d.ts +28 -0
  35. package/dist/glob.js +1 -0
  36. package/dist/glob.mjs +1 -0
  37. package/dist/glob.test.d.mts +2 -0
  38. package/dist/glob.test.d.ts +2 -0
  39. package/dist/glob.test.js +292 -0
  40. package/dist/glob.test.mjs +1 -0
  41. package/dist/include-files.d.mts +31 -0
  42. package/dist/include-files.d.ts +31 -0
  43. package/dist/include-files.js +1 -0
  44. package/dist/include-files.mjs +1 -0
  45. package/dist/include-files.test.d.mts +2 -0
  46. package/dist/include-files.test.d.ts +2 -0
  47. package/dist/include-files.test.js +292 -0
  48. package/dist/include-files.test.mjs +1 -0
  49. package/dist/index.d.mts +11 -0
  50. package/dist/index.d.ts +11 -0
  51. package/dist/index.js +1 -0
  52. package/dist/index.mjs +1 -0
  53. package/dist/is-string-in.d.mts +19 -0
  54. package/dist/is-string-in.d.ts +19 -0
  55. package/dist/is-string-in.js +1 -0
  56. package/dist/is-string-in.mjs +1 -0
  57. package/dist/magic-string.es-TUA2PMWY.mjs +1 -0
  58. package/dist/remove-leading-empty-lines.d.mts +18 -0
  59. package/dist/remove-leading-empty-lines.d.ts +18 -0
  60. package/dist/remove-leading-empty-lines.js +1 -0
  61. package/dist/remove-leading-empty-lines.mjs +1 -0
  62. package/dist/remove-leading-empty-lines.test.d.mts +2 -0
  63. package/dist/remove-leading-empty-lines.test.d.ts +2 -0
  64. package/dist/remove-leading-empty-lines.test.js +1 -0
  65. package/dist/remove-leading-empty-lines.test.mjs +1 -0
  66. package/dist/traverse-folder.d.mts +56 -0
  67. package/dist/traverse-folder.d.ts +56 -0
  68. package/dist/traverse-folder.js +1 -0
  69. package/dist/traverse-folder.mjs +1 -0
  70. package/dist/traverse-folder.test.d.mts +2 -0
  71. package/dist/traverse-folder.test.d.ts +2 -0
  72. package/dist/traverse-folder.test.js +292 -0
  73. package/dist/traverse-folder.test.mjs +1 -0
  74. package/dist/yaml.d.mts +59 -0
  75. package/dist/yaml.d.ts +59 -0
  76. package/dist/yaml.js +1 -0
  77. package/dist/yaml.mjs +1 -0
  78. package/docs/README.md +10 -0
  79. package/docs/classes/ConfigFile.md +169 -0
  80. package/docs/functions/getMultiLevelExtname.md +33 -0
  81. package/docs/functions/glob.md +56 -0
  82. package/docs/functions/isStringIn.md +43 -0
  83. package/docs/functions/normalizeIncludeFiles.md +49 -0
  84. package/docs/functions/parseFrontMatter.md +33 -0
  85. package/docs/functions/parseYaml.md +45 -0
  86. package/docs/functions/registerYamlTag.md +37 -0
  87. package/docs/functions/removeLeadingEmptyLines.md +39 -0
  88. package/docs/functions/stringifyYaml.md +45 -0
  89. package/docs/functions/traverseFolder.md +44 -0
  90. package/docs/functions/traverseFolderSync.md +44 -0
  91. package/docs/globals.md +36 -0
  92. package/docs/interfaces/IncludeFiles.md +25 -0
  93. package/docs/type-aliases/TraverseFolderHandler.md +33 -0
  94. package/docs/type-aliases/TraverseFolderSyncHandler.md +33 -0
  95. package/docs/variables/DefaultAllTextFiles.md +11 -0
  96. package/package.json +68 -0
@@ -0,0 +1 @@
1
+ import{init_esm_shims as f}from"./chunk-UJZVJIGI.mjs";f();import{parse as o,stringify as e}from"yaml";var r=[];function t(f){Array.isArray(f)||(f=[f]);for(const o of f){-1===r.indexOf(o)&&r.push(o)}}function n(f,e){if(e)if(e.customTags){if(Array.isArray(e.customTags))e.customTags=r.concat(e.customTags);else if("function"==typeof e.customTags){const f=e.customTags;e.customTags=o=>f(r.concat(o))}}else e.customTags=r;else e={customTags:r};return o(f,e)}function i(f,o){if(o)if(o.customTags){if(Array.isArray(o.customTags))o.customTags=r.concat(o.customTags);else if("function"==typeof o.customTags){const f=o.customTags;o.customTags=o=>f(r.concat(o))}}else o.customTags=r;else o={customTags:r};return e(f,o)}export{t as registerYamlTag,n as parseYaml,i as stringifyYaml};
@@ -0,0 +1 @@
1
+ var e,t,r=Object.create,n=Object.defineProperty,u=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,i=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty,s=(e=>"undefined"!=typeof require?require:"undefined"!=typeof Proxy?new Proxy(e,{get:(e,t)=>("undefined"!=typeof require?require:e)[t]}):e)((function(e){if("undefined"!=typeof require)return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')})),p=(e,t)=>function(){return t||(0,e[o(e)[0]])((t={exports:{}}).exports,t),t.exports},c=(e,t,s)=>(s=null!=e?r(i(e)):{},((e,t,r,i)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let s of o(t))f.call(e,s)||s===r||n(e,s,{get:()=>t[s],enumerable:!(i=u(t,s))||i.enumerable});return e})(!t&&e&&e.__esModule?s:n(s,"default",{value:e,enumerable:!0}),e)),l=(e,t,r)=>((e,t,r)=>t in e?n(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r),d=(e={"node_modules/.pnpm/tsup@8.4.0_postcss@8.5.3_tsx@4.19.3_typescript@5.8.2_yaml@2.7.1/node_modules/tsup/assets/esm_shims.js"(){}},function(){return e&&(t=(0,e[o(e)[0]])(e=0)),t});export{s as __require,p as __commonJS,c as __toESM,l as __publicField,d as init_esm_shims};
@@ -0,0 +1,75 @@
1
+ type StringifyFunc = (content: any) => string;
2
+ interface LoadConfigFileOptions {
3
+ extLevel?: number;
4
+ externalFile?: string;
5
+ }
6
+ /**
7
+ * Represents a configuration file utility class that provides methods to load and save configuration files.
8
+ * It supports multiple file formats such as YAML, JSON, etc., by registering corresponding parsers and stringifiers.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * // Register a custom file type handler
13
+ * ConfigFile.register('.custom', (content) => {
14
+ * return { data: content.toUpperCase() }; // Example parser
15
+ * }, (obj) => {
16
+ * return obj.data.toLowerCase(); // Example stringifier
17
+ * });
18
+ *
19
+ * // Save a configuration file
20
+ * ConfigFile.save('config.custom', { key: 'value' });
21
+ *
22
+ * // Load a configuration file
23
+ * const config = ConfigFile.load('config.custom');
24
+ * console.log(config); // Output: { key: 'value' }
25
+ * ```
26
+ */
27
+ declare class ConfigFile {
28
+ /**
29
+ * A record of registered stringify functions for different file extensions.
30
+ */
31
+ static stringifys: Record<string, StringifyFunc>;
32
+ /**
33
+ * Registers a parser and stringifier for specific file extensions.
34
+ *
35
+ * @param extname - The file extension(s) to register the parser and stringifier for.
36
+ * @param parser - A function that parses the file content into an object.
37
+ * @param stringify - A function that converts an object back into file content.
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * ConfigFile.register(['.json'], JSON.parse, (obj) => JSON.stringify(obj, null, 2));
42
+ * ```
43
+ */
44
+ static register(extname: string | string[], parser: (content: string) => any, stringify: StringifyFunc): void;
45
+ /**
46
+ * Loads a configuration file based on the provided filename and options.
47
+ *
48
+ * @param filename - The path to the configuration file.
49
+ * @param options - Additional options for loading the configuration file.
50
+ * @returns The parsed configuration object.
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const config = ConfigFile.load('config.yaml');
55
+ * console.log(config); // Output: { key: 'value' }
56
+ * ```
57
+ */
58
+ static load(filename: string, options?: LoadConfigFileOptions): any;
59
+ /**
60
+ * Saves a configuration object to a file with the specified filename and options.
61
+ *
62
+ * @param filename - The path where the configuration file should be saved.
63
+ * @param config - The configuration object to save.
64
+ * @param options - Additional options for saving the configuration file.
65
+ * @returns The final filename where the configuration was saved.
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * ConfigFile.save('config.json', { key: 'value' });
70
+ * ```
71
+ */
72
+ static save(filename: string, config: any, options?: LoadConfigFileOptions): string;
73
+ }
74
+
75
+ export { ConfigFile };
@@ -0,0 +1,75 @@
1
+ type StringifyFunc = (content: any) => string;
2
+ interface LoadConfigFileOptions {
3
+ extLevel?: number;
4
+ externalFile?: string;
5
+ }
6
+ /**
7
+ * Represents a configuration file utility class that provides methods to load and save configuration files.
8
+ * It supports multiple file formats such as YAML, JSON, etc., by registering corresponding parsers and stringifiers.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * // Register a custom file type handler
13
+ * ConfigFile.register('.custom', (content) => {
14
+ * return { data: content.toUpperCase() }; // Example parser
15
+ * }, (obj) => {
16
+ * return obj.data.toLowerCase(); // Example stringifier
17
+ * });
18
+ *
19
+ * // Save a configuration file
20
+ * ConfigFile.save('config.custom', { key: 'value' });
21
+ *
22
+ * // Load a configuration file
23
+ * const config = ConfigFile.load('config.custom');
24
+ * console.log(config); // Output: { key: 'value' }
25
+ * ```
26
+ */
27
+ declare class ConfigFile {
28
+ /**
29
+ * A record of registered stringify functions for different file extensions.
30
+ */
31
+ static stringifys: Record<string, StringifyFunc>;
32
+ /**
33
+ * Registers a parser and stringifier for specific file extensions.
34
+ *
35
+ * @param extname - The file extension(s) to register the parser and stringifier for.
36
+ * @param parser - A function that parses the file content into an object.
37
+ * @param stringify - A function that converts an object back into file content.
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * ConfigFile.register(['.json'], JSON.parse, (obj) => JSON.stringify(obj, null, 2));
42
+ * ```
43
+ */
44
+ static register(extname: string | string[], parser: (content: string) => any, stringify: StringifyFunc): void;
45
+ /**
46
+ * Loads a configuration file based on the provided filename and options.
47
+ *
48
+ * @param filename - The path to the configuration file.
49
+ * @param options - Additional options for loading the configuration file.
50
+ * @returns The parsed configuration object.
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const config = ConfigFile.load('config.yaml');
55
+ * console.log(config); // Output: { key: 'value' }
56
+ * ```
57
+ */
58
+ static load(filename: string, options?: LoadConfigFileOptions): any;
59
+ /**
60
+ * Saves a configuration object to a file with the specified filename and options.
61
+ *
62
+ * @param filename - The path where the configuration file should be saved.
63
+ * @param config - The configuration object to save.
64
+ * @param options - Additional options for saving the configuration file.
65
+ * @returns The final filename where the configuration was saved.
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * ConfigFile.save('config.json', { key: 'value' });
70
+ * ```
71
+ */
72
+ static save(filename: string, config: any, options?: LoadConfigFileOptions): string;
73
+ }
74
+
75
+ export { ConfigFile };
@@ -0,0 +1 @@
1
+ "use strict";var e,t=Object.create,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,i=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty,u=(e,t,i,u)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let c of o(t))f.call(e,c)||c===i||n(e,c,{get:()=>t[c],enumerable:!(u=r(t,c))||u.enumerable});return e},c=(e,r,o)=>(o=null!=e?t(i(e)):{},u(!r&&e&&e.__esModule?o:n(o,"default",{value:e,enumerable:!0}),e)),l={};((e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})})(l,{ConfigFile:()=>g}),module.exports=(e=l,u(n({},"__esModule",{value:!0}),e));var s=require("fs"),a=c(require("path")),m=require("load-config-file"),y=c(require("path"));function b(e,t=1){let n="";for(;t--;){const t=y.default.extname(e);if(!t)break;n=t+n,e=y.default.basename(e,t)}return n}var v=require("yaml"),p=[];function d(e,t){if(t)if(t.customTags){if(Array.isArray(t.customTags))t.customTags=p.concat(t.customTags);else if("function"==typeof t.customTags){const e=t.customTags;t.customTags=t=>e(p.concat(t))}}else t.customTags=p;else t={customTags:p};return(0,v.parse)(e,t)}var g=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 load(e,t){return function(e,{extLevel:t=1,externalFile:n}={}){"."===e[0]&&t++;const r=b(e,t);r&&r.split(".").length>1&&(e=e.slice(0,-r.length));let o=m.Config.loadSync(e);if(!o&&n){if(!a.default.isAbsolute(n)){const t=a.default.dirname(e);n=a.default.join(t,n)}if((0,s.existsSync)(n)){const e=function(e,t="---"){const n=t.length,r=function(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}(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:d(o)||{},content:i}}}return{data:{},content:e}}((0,s.readFileSync)(n,"utf8")).data;Object.keys(e).length&&(o=e)}}return o}(e,t)}static save(e,t,n){return function(e,t,{extLevel:n=1}={}){"."===e[0]&&n++;let r=b(e,n);(!r||r.split(".").length<=1)&&(e+=".yaml",r=".yaml");const o=g.stringifys[r];if(!o)throw new Error(`${e} unsupported mime type: ${r}`);t=o(t);const i=a.default.dirname(e);(0,s.existsSync)(i)||(0,s.mkdirSync)(i,{recursive:!0});return(0,s.writeFileSync)(e,t,{encoding:"utf8"}),e}(e,t,n)}};g.stringifys={},g.register([".yml",".yaml"],d,(function(e,t){if(t)if(t.customTags){if(Array.isArray(t.customTags))t.customTags=p.concat(t.customTags);else if("function"==typeof t.customTags){const e=t.customTags;t.customTags=t=>e(p.concat(t))}}else t.customTags=p;else t={customTags:p};return(0,v.stringify)(e,t)})),g.register([".json"],(function(e){return JSON.parse(e)}),(e=>JSON.stringify(e,null,2)));
@@ -0,0 +1 @@
1
+ import{ConfigFile as m}from"./chunk-3TCMKKX2.mjs";import"./chunk-JTTOXXPG.mjs";import"./chunk-D3BCI5SM.mjs";import"./chunk-OTEAFARC.mjs";import"./chunk-7AQU3PBW.mjs";import"./chunk-UJZVJIGI.mjs";export{m as ConfigFile};
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,2 @@
1
+
2
+ export { }