@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{ConfigFile as e}from"./chunk-3TCMKKX2.mjs";import"./chunk-JTTOXXPG.mjs";import"./chunk-D3BCI5SM.mjs";import"./chunk-OTEAFARC.mjs";import"./chunk-7AQU3PBW.mjs";import{vi as t}from"./chunk-LOMQZH4U.mjs";import{init_esm_shims as i}from"./chunk-UJZVJIGI.mjs";i();import{existsSync as o,mkdirSync as r,readFileSync as n,writeFileSync as s}from"fs";import c from"path";t.mock("fs",(()=>({existsSync:t.fn(),mkdirSync:t.fn(),readFileSync:t.fn(),writeFileSync:t.fn()}))),describe("ConfigFile",(()=>{const i="./mock/config.yaml",l={key:"value"};beforeEach((()=>{t.clearAllMocks(),t.resetAllMocks()})),describe("register",(()=>{it("should register parser and stringifier for a single extension",(()=>{const t=e=>JSON.stringify(e);e.register(".test",(e=>({parsed:e})),t),expect(e.stringifys[".test"]).toBe(t)})),it("should register parser and stringifier for multiple extensions",(()=>{const t=e=>JSON.stringify(e);e.register([".test1",".test2"],(e=>({parsed:e})),t),expect(e.stringifys[".test1"]).toBe(t),expect(e.stringifys[".test2"]).toBe(t)}))})),describe("save",(()=>{it("should save a file with the correct content and extension",(()=>{o.mockReturnValue(!0);const t=e.save(i,l);expect(t).toBe(i),expect(s).toHaveBeenCalledWith(i,e.stringifys[".yaml"](l),{encoding:"utf8"})})),it("should create directories if they do not exist",(()=>{o.mockReturnValue(!1),e.save(i,l),expect(r).toHaveBeenCalledWith(c.dirname(i),{recursive:!0})})),it("should throw an error for unsupported file types",(()=>{const t="./mock/unsupported.xyz";expect((()=>e.save(t,l))).toThrow(`${t} unsupported mime type: .xyz`)}))})),describe("load",(()=>{it("should load a configuration file successfully",(()=>{const r={key:"loadedValue"};o.mockReturnValue(!0),t.spyOn(e,"load").mockImplementation((()=>r));const n=e.load(i);expect(n).toEqual(r)})),it("should fallback to external file if main file is not found",(()=>{o.mockImplementation((e=>e===c.join("./mock/README.md"))),n.mockReturnValue("---\nkey: externalValue\n---");const t=e.load(i,{externalFile:"README.md"});expect(t).toEqual({key:"externalValue"})})),it("should return undefined if neither main file nor external file is found",(()=>{n.mockReturnValue(void 0);const t=e.load(i,{externalFile:"README.md"});expect(t).toBeUndefined()}))}))}));
@@ -0,0 +1,6 @@
1
+ declare function parseFrontMatter(value: string, delimiter?: string): {
2
+ data: any;
3
+ content: string;
4
+ };
5
+
6
+ export { parseFrontMatter };
@@ -0,0 +1,6 @@
1
+ declare function parseFrontMatter(value: string, delimiter?: string): {
2
+ data: any;
3
+ content: string;
4
+ };
5
+
6
+ export { parseFrontMatter };
@@ -0,0 +1 @@
1
+ "use strict";var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,f={};((e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})})(f,{parseFrontMatter:()=>s}),module.exports=(e=f,((e,f,c,u)=>{if(f&&"object"==typeof f||"function"==typeof f)for(let a of r(f))o.call(e,a)||a===c||t(e,a,{get:()=>f[a],enumerable:!(u=n(f,a))||u.enumerable});return e})(t({},"__esModule",{value:!0}),e));var c=require("yaml"),u=[];function a(e,t){if(t)if(t.customTags){if(Array.isArray(t.customTags))t.customTags=u.concat(t.customTags);else if("function"==typeof t.customTags){const e=t.customTags;t.customTags=t=>e(u.concat(t))}}else t.customTags=u;else t={customTags:u};return(0,c.parse)(e,t)}var i="---";function s(e,t=i){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 f=r.slice(e);return{data:a(o)||{},content:f}}}return{data:{},content:e}}
@@ -0,0 +1 @@
1
+ import{parseFrontMatter as m}from"./chunk-JTTOXXPG.mjs";import"./chunk-D3BCI5SM.mjs";import"./chunk-OTEAFARC.mjs";import"./chunk-UJZVJIGI.mjs";export{m as parseFrontMatter};
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1 @@
1
+ "use strict";var t=require("yaml"),e=[];function n(n,i){if(i)if(i.customTags){if(Array.isArray(i.customTags))i.customTags=e.concat(i.customTags);else if("function"==typeof i.customTags){const t=i.customTags;i.customTags=n=>t(e.concat(n))}}else i.customTags=e;else i={customTags:e};return(0,t.parse)(n,i)}function i(t,e="---"){const i=e.length,s=function(t){const e=/^\s*(#[^\r\n]*)?[\r\n]+/;let n;for(;null!==(n=e.exec(t))&&((t=t.substring(n[0].length)).startsWith("\n")||t.startsWith("\r")||t.trimStart().startsWith("#")););return t}(t);if(s.startsWith(e)&&("\n"===s[e.length]||"\r"===s[e.length])){let t=s.indexOf("\n"+e,i);if(-1!==t){const o=s.slice(i,t);for(t+=e.length+1;"\n"===s[t]||"\r"===s[t];)t++;const r=s.slice(t);return{data:n(o)||{},content:r}}}return{data:{},content:t}}describe("parseFrontMatter",(()=>{it("should parse front matter with default delimiter",(()=>{const t=i("---\ntitle: Test\ndate: 2022-01-01\n---\nThis is the body");expect(t).toEqual({data:{title:"Test",date:"2022-01-01"},content:"This is the body"})})),it("should parse front matter with default delimiter empty line",(()=>{const t=i("\n\n---\ntitle: Test\ndate: 2022-01-01\n---\nThis is the body");expect(t).toEqual({data:{title:"Test",date:"2022-01-01"},content:"This is the body"})})),it("should parse front matter with custom delimiter",(()=>{const t=i("+++\ntitle: Test\ndate: 2022-01-01\n+++","+++");expect(t).toEqual({data:{title:"Test",date:"2022-01-01"},content:""})})),it("should return null if no delimiter is found",(()=>{const t="This is the body",e={data:{},content:t},n=i(t);expect(n).toEqual(e)})),it("should handle empty front matter",(()=>{const t=i("---\n---\nThis is the body");expect(t).toEqual({data:{},content:"This is the body"})})),it("should handle multi lines",(()=>{const t=i("---\ncontent: 'hi'\n---\nThis is the body\n---\nsecond line");expect(t).toEqual({data:{content:"hi"},content:"This is the body\n---\nsecond line"})}))}));
@@ -0,0 +1 @@
1
+ import{parseFrontMatter as t}from"./chunk-JTTOXXPG.mjs";import"./chunk-D3BCI5SM.mjs";import"./chunk-OTEAFARC.mjs";import{init_esm_shims as e}from"./chunk-UJZVJIGI.mjs";e(),describe("parseFrontMatter",(()=>{it("should parse front matter with default delimiter",(()=>{const e=t("---\ntitle: Test\ndate: 2022-01-01\n---\nThis is the body");expect(e).toEqual({data:{title:"Test",date:"2022-01-01"},content:"This is the body"})})),it("should parse front matter with default delimiter empty line",(()=>{const e=t("\n\n---\ntitle: Test\ndate: 2022-01-01\n---\nThis is the body");expect(e).toEqual({data:{title:"Test",date:"2022-01-01"},content:"This is the body"})})),it("should parse front matter with custom delimiter",(()=>{const e=t("+++\ntitle: Test\ndate: 2022-01-01\n+++","+++");expect(e).toEqual({data:{title:"Test",date:"2022-01-01"},content:""})})),it("should return null if no delimiter is found",(()=>{const e="This is the body",n={data:{},content:e},i=t(e);expect(i).toEqual(n)})),it("should handle empty front matter",(()=>{const e=t("---\n---\nThis is the body");expect(e).toEqual({data:{},content:"This is the body"})})),it("should handle multi lines",(()=>{const e=t("---\ncontent: 'hi'\n---\nThis is the body\n---\nsecond line");expect(e).toEqual({data:{content:"hi"},content:"This is the body\n---\nsecond line"})}))}));
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Retrieves multi-level file extension
3
+ * @param filename The file name
4
+ * @param level The level, default is 1, indicating the number of extension levels to retrieve
5
+ * @returns Returns a concatenated string of multiple extensions, or an empty string if no extension is found
6
+ */
7
+ declare function getMultiLevelExtname(filename: string, level?: number): string;
8
+
9
+ export { getMultiLevelExtname };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Retrieves multi-level file extension
3
+ * @param filename The file name
4
+ * @param level The level, default is 1, indicating the number of extension levels to retrieve
5
+ * @returns Returns a concatenated string of multiple extensions, or an empty string if no extension is found
6
+ */
7
+ declare function getMultiLevelExtname(filename: string, level?: number): string;
8
+
9
+ export { getMultiLevelExtname };
@@ -0,0 +1 @@
1
+ "use strict";var e,t=Object.create,r=Object.defineProperty,u=Object.getOwnPropertyDescriptor,l=Object.getOwnPropertyNames,n=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t,n,o)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let b of l(t))a.call(e,b)||b===n||r(e,b,{get:()=>t[b],enumerable:!(o=u(t,b))||o.enumerable});return e},b={};((e,t)=>{for(var u in t)r(e,u,{get:t[u],enumerable:!0})})(b,{getMultiLevelExtname:()=>f}),module.exports=(e=b,o(r({},"__esModule",{value:!0}),e));var c=((e,u,l)=>(l=null!=e?t(n(e)):{},o(!u&&e&&e.__esModule?l:r(l,"default",{value:e,enumerable:!0}),e)))(require("path"));function f(e,t=1){let r="";for(;t--;){const t=c.default.extname(e);if(!t)break;r=t+r,e=c.default.basename(e,t)}return r}
@@ -0,0 +1 @@
1
+ import{getMultiLevelExtname as m}from"./chunk-7AQU3PBW.mjs";import"./chunk-UJZVJIGI.mjs";export{m as getMultiLevelExtname};
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Matches a file path against a list of glob patterns.
3
+ *
4
+ * This function checks if the given `filepath` matches any of the provided glob `pattern`s.
5
+ * If a `rootDir` is specified, the `filepath` will first be converted to a relative path
6
+ * based on the `rootDir`.
7
+ *
8
+ * @param filepath - The file path to match.
9
+ * @param pattern - An array of glob patterns to match against.
10
+ * @param rootDir - (Optional) The root directory used to calculate the relative path of `filepath`.
11
+ *
12
+ * @returns Returns `true` if the `filepath` matches any of the patterns, otherwise `false`.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { glob } from './glob';
17
+ *
18
+ * const filepath = '/home/user/project/src/index.ts';
19
+ * const patterns = ['src/*.ts', '!src/test.ts'];
20
+ * const rootDir = '/home/user/project';
21
+ *
22
+ * const result = glob(filepath, patterns, rootDir);
23
+ * console.log(result); // true
24
+ * ```
25
+ */
26
+ declare function glob(filepath: string, pattern: string[], rootDir?: string): boolean | undefined;
27
+
28
+ export { glob };
package/dist/glob.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Matches a file path against a list of glob patterns.
3
+ *
4
+ * This function checks if the given `filepath` matches any of the provided glob `pattern`s.
5
+ * If a `rootDir` is specified, the `filepath` will first be converted to a relative path
6
+ * based on the `rootDir`.
7
+ *
8
+ * @param filepath - The file path to match.
9
+ * @param pattern - An array of glob patterns to match against.
10
+ * @param rootDir - (Optional) The root directory used to calculate the relative path of `filepath`.
11
+ *
12
+ * @returns Returns `true` if the `filepath` matches any of the patterns, otherwise `false`.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { glob } from './glob';
17
+ *
18
+ * const filepath = '/home/user/project/src/index.ts';
19
+ * const patterns = ['src/*.ts', '!src/test.ts'];
20
+ * const rootDir = '/home/user/project';
21
+ *
22
+ * const result = glob(filepath, patterns, rootDir);
23
+ * console.log(result); // true
24
+ * ```
25
+ */
26
+ declare function glob(filepath: string, pattern: string[], rootDir?: string): boolean | undefined;
27
+
28
+ export { glob };
package/dist/glob.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";var e,t=Object.create,r=Object.defineProperty,u=Object.getOwnPropertyDescriptor,l=Object.getOwnPropertyNames,b=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,n=(e,t,b,n)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let a of l(t))o.call(e,a)||a===b||r(e,a,{get:()=>t[a],enumerable:!(n=u(t,a))||n.enumerable});return e},a={};((e,t)=>{for(var u in t)r(e,u,{get:t[u],enumerable:!0})})(a,{glob:()=>i}),module.exports=(e=a,n(r({},"__esModule",{value:!0}),e));var c=require("@isdk/glob"),f=((e,u,l)=>(l=null!=e?t(b(e)):{},n(!u&&e&&e.__esModule?l:r(l,"default",{value:e,enumerable:!0}),e)))(require("path"));function i(e,t,r){return r&&(e=f.default.relative(r,e)),(0,c.globMatch)(e,t)}
package/dist/glob.mjs ADDED
@@ -0,0 +1 @@
1
+ import{glob as m}from"./chunk-7APJBRA7.mjs";import"./chunk-UJZVJIGI.mjs";export{m as glob};
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,2 @@
1
+
2
+ export { }