@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.
- package/README.md +6 -0
- package/dist/chunk-3TCMKKX2.mjs +1 -0
- package/dist/chunk-46TT3NZV.mjs +1 -0
- package/dist/chunk-7APJBRA7.mjs +1 -0
- package/dist/chunk-7AQU3PBW.mjs +1 -0
- package/dist/chunk-D3BCI5SM.mjs +1 -0
- package/dist/chunk-FXF2KJLF.mjs +1 -0
- package/dist/chunk-GGOKSJK4.mjs +1 -0
- package/dist/chunk-JTTOXXPG.mjs +1 -0
- package/dist/chunk-LOMQZH4U.mjs +292 -0
- package/dist/chunk-OTEAFARC.mjs +1 -0
- package/dist/chunk-UJZVJIGI.mjs +1 -0
- package/dist/config-file.d.mts +75 -0
- package/dist/config-file.d.ts +75 -0
- package/dist/config-file.js +1 -0
- package/dist/config-file.mjs +1 -0
- package/dist/config-file.test.d.mts +2 -0
- package/dist/config-file.test.d.ts +2 -0
- package/dist/config-file.test.js +292 -0
- package/dist/config-file.test.mjs +1 -0
- package/dist/front-matter.d.mts +6 -0
- package/dist/front-matter.d.ts +6 -0
- package/dist/front-matter.js +1 -0
- package/dist/front-matter.mjs +1 -0
- package/dist/front-matter.test.d.mts +2 -0
- package/dist/front-matter.test.d.ts +2 -0
- package/dist/front-matter.test.js +1 -0
- package/dist/front-matter.test.mjs +1 -0
- package/dist/get-multi-level-extname.d.mts +9 -0
- package/dist/get-multi-level-extname.d.ts +9 -0
- package/dist/get-multi-level-extname.js +1 -0
- package/dist/get-multi-level-extname.mjs +1 -0
- package/dist/glob.d.mts +28 -0
- package/dist/glob.d.ts +28 -0
- package/dist/glob.js +1 -0
- package/dist/glob.mjs +1 -0
- package/dist/glob.test.d.mts +2 -0
- package/dist/glob.test.d.ts +2 -0
- package/dist/glob.test.js +292 -0
- package/dist/glob.test.mjs +1 -0
- package/dist/include-files.d.mts +31 -0
- package/dist/include-files.d.ts +31 -0
- package/dist/include-files.js +1 -0
- package/dist/include-files.mjs +1 -0
- package/dist/include-files.test.d.mts +2 -0
- package/dist/include-files.test.d.ts +2 -0
- package/dist/include-files.test.js +292 -0
- package/dist/include-files.test.mjs +1 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/is-string-in.d.mts +19 -0
- package/dist/is-string-in.d.ts +19 -0
- package/dist/is-string-in.js +1 -0
- package/dist/is-string-in.mjs +1 -0
- package/dist/magic-string.es-TUA2PMWY.mjs +1 -0
- package/dist/remove-leading-empty-lines.d.mts +18 -0
- package/dist/remove-leading-empty-lines.d.ts +18 -0
- package/dist/remove-leading-empty-lines.js +1 -0
- package/dist/remove-leading-empty-lines.mjs +1 -0
- package/dist/remove-leading-empty-lines.test.d.mts +2 -0
- package/dist/remove-leading-empty-lines.test.d.ts +2 -0
- package/dist/remove-leading-empty-lines.test.js +1 -0
- package/dist/remove-leading-empty-lines.test.mjs +1 -0
- package/dist/traverse-folder.d.mts +56 -0
- package/dist/traverse-folder.d.ts +56 -0
- package/dist/traverse-folder.js +1 -0
- package/dist/traverse-folder.mjs +1 -0
- package/dist/traverse-folder.test.d.mts +2 -0
- package/dist/traverse-folder.test.d.ts +2 -0
- package/dist/traverse-folder.test.js +292 -0
- package/dist/traverse-folder.test.mjs +1 -0
- package/dist/yaml.d.mts +59 -0
- package/dist/yaml.d.ts +59 -0
- package/dist/yaml.js +1 -0
- package/dist/yaml.mjs +1 -0
- package/docs/README.md +10 -0
- package/docs/classes/ConfigFile.md +169 -0
- package/docs/functions/getMultiLevelExtname.md +33 -0
- package/docs/functions/glob.md +56 -0
- package/docs/functions/isStringIn.md +43 -0
- package/docs/functions/normalizeIncludeFiles.md +49 -0
- package/docs/functions/parseFrontMatter.md +33 -0
- package/docs/functions/parseYaml.md +45 -0
- package/docs/functions/registerYamlTag.md +37 -0
- package/docs/functions/removeLeadingEmptyLines.md +39 -0
- package/docs/functions/stringifyYaml.md +45 -0
- package/docs/functions/traverseFolder.md +44 -0
- package/docs/functions/traverseFolderSync.md +44 -0
- package/docs/globals.md +36 -0
- package/docs/interfaces/IncludeFiles.md +25 -0
- package/docs/type-aliases/TraverseFolderHandler.md +33 -0
- package/docs/type-aliases/TraverseFolderSyncHandler.md +33 -0
- package/docs/variables/DefaultAllTextFiles.md +11 -0
- package/package.json +68 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{traverseFolder as t,traverseFolderSync as e}from"./chunk-46TT3NZV.mjs";import{vi as r}from"./chunk-LOMQZH4U.mjs";import{init_esm_shims as s}from"./chunk-UJZVJIGI.mjs";s();import{Dirent as o,readdirSync as i}from"fs";import{readdir as c}from"fs/promises";import n from"path";var a=o;r.mock("fs/promises",(()=>({readdir:r.fn()}))),r.mock("fs",(()=>({readdirSync:r.fn(),Dirent:class{constructor(t){this.isFile=()=>!0,this.name=t}}}))),describe("traverseFolder",(()=>{it("should traverse all files and directories asynchronously",(async()=>{const e=[new a("file1.txt"),new a("file2.txt"),new a("subdir")];c.mockResolvedValue(e);const s=r.fn().mockImplementation((()=>!1));await t("/mock/path",s),expect(s).toHaveBeenCalledTimes(3),expect(s).toHaveBeenCalledWith(n.join("/mock/path","file1.txt"),e[0]),expect(s).toHaveBeenCalledWith(n.join("/mock/path","file2.txt"),e[1]),expect(s).toHaveBeenCalledWith(n.join("/mock/path","subdir"),e[2])})),it("should stop traversal when handler returns true",(async()=>{const e=[new a("file1.txt"),new a("file2.txt"),new a("file3.txt")];c.mockResolvedValue(e);const s=r.fn().mockImplementation((t=>t.endsWith("file2.txt")));await t("/mock/path",s),expect(s).toHaveBeenCalledTimes(2)}))})),describe("traverseFolderSync",(()=>{it("should traverse all files and directories synchronously",(()=>{const t=[new a("file1.txt"),new a("file2.txt"),new a("subdir")];i.mockReturnValue(t);const s=r.fn().mockImplementation((()=>!1));e("/mock/path",s),expect(s).toHaveBeenCalledTimes(3),expect(s).toHaveBeenCalledWith(n.join("/mock/path","file1.txt"),t[0]),expect(s).toHaveBeenCalledWith(n.join("/mock/path","file2.txt"),t[1]),expect(s).toHaveBeenCalledWith(n.join("/mock/path","subdir"),t[2])})),it("should stop traversal when handler returns true",(()=>{const t=[new a("file1.txt"),new a("file2.txt"),new a("file3.txt")];i.mockReturnValue(t);const s=r.fn().mockImplementation((t=>t.endsWith("file2.txt")));e("/mock/path",s),expect(s).toHaveBeenCalledTimes(2)}))}));
|
package/dist/yaml.d.mts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ParseOptions, DocumentOptions, SchemaOptions, ToJSOptions, CreateNodeOptions, ToStringOptions } from 'yaml';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Registers custom YAML tags to be used in parsing and stringifying YAML content.
|
|
5
|
+
*
|
|
6
|
+
* @param tags - A single tag or an array of tags to register.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { registerYamlTag } from './yaml';
|
|
11
|
+
*
|
|
12
|
+
* const customTag = {
|
|
13
|
+
* tag: '!custom',
|
|
14
|
+
* resolve: (value) => `resolved-${value}`,
|
|
15
|
+
* };
|
|
16
|
+
* registerYamlTag(customTag);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare function registerYamlTag(tags: any): void;
|
|
20
|
+
/**
|
|
21
|
+
* Parses a YAML string into a JavaScript object with optional custom tags.
|
|
22
|
+
*
|
|
23
|
+
* @param content - The YAML string to parse.
|
|
24
|
+
* @param options - Optional parsing options, including custom tags.
|
|
25
|
+
* @returns The parsed JavaScript object.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { parseYaml } from './yaml';
|
|
30
|
+
*
|
|
31
|
+
* const yamlContent = `
|
|
32
|
+
* example: !custom value
|
|
33
|
+
* `;
|
|
34
|
+
* const result = parseYaml(yamlContent);
|
|
35
|
+
* console.log(result); // { example: 'resolved-value' }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
declare function parseYaml(content: string, options?: ParseOptions & DocumentOptions & SchemaOptions & ToJSOptions): any;
|
|
39
|
+
/**
|
|
40
|
+
* Converts a JavaScript object into a YAML string with optional custom tags.
|
|
41
|
+
*
|
|
42
|
+
* @param content - The JavaScript object to convert to YAML.
|
|
43
|
+
* @param options - Optional stringification options, including custom tags.
|
|
44
|
+
* @returns The YAML string representation of the input object.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* import { stringifyYaml } from './yaml';
|
|
49
|
+
*
|
|
50
|
+
* const data = {
|
|
51
|
+
* example: 'value',
|
|
52
|
+
* };
|
|
53
|
+
* const yamlString = stringifyYaml(data);
|
|
54
|
+
* console.log(yamlString); // "example: value\n"
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare function stringifyYaml(content: any, options?: DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions & ToStringOptions): string;
|
|
58
|
+
|
|
59
|
+
export { parseYaml, registerYamlTag, stringifyYaml };
|
package/dist/yaml.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ParseOptions, DocumentOptions, SchemaOptions, ToJSOptions, CreateNodeOptions, ToStringOptions } from 'yaml';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Registers custom YAML tags to be used in parsing and stringifying YAML content.
|
|
5
|
+
*
|
|
6
|
+
* @param tags - A single tag or an array of tags to register.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { registerYamlTag } from './yaml';
|
|
11
|
+
*
|
|
12
|
+
* const customTag = {
|
|
13
|
+
* tag: '!custom',
|
|
14
|
+
* resolve: (value) => `resolved-${value}`,
|
|
15
|
+
* };
|
|
16
|
+
* registerYamlTag(customTag);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare function registerYamlTag(tags: any): void;
|
|
20
|
+
/**
|
|
21
|
+
* Parses a YAML string into a JavaScript object with optional custom tags.
|
|
22
|
+
*
|
|
23
|
+
* @param content - The YAML string to parse.
|
|
24
|
+
* @param options - Optional parsing options, including custom tags.
|
|
25
|
+
* @returns The parsed JavaScript object.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { parseYaml } from './yaml';
|
|
30
|
+
*
|
|
31
|
+
* const yamlContent = `
|
|
32
|
+
* example: !custom value
|
|
33
|
+
* `;
|
|
34
|
+
* const result = parseYaml(yamlContent);
|
|
35
|
+
* console.log(result); // { example: 'resolved-value' }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
declare function parseYaml(content: string, options?: ParseOptions & DocumentOptions & SchemaOptions & ToJSOptions): any;
|
|
39
|
+
/**
|
|
40
|
+
* Converts a JavaScript object into a YAML string with optional custom tags.
|
|
41
|
+
*
|
|
42
|
+
* @param content - The JavaScript object to convert to YAML.
|
|
43
|
+
* @param options - Optional stringification options, including custom tags.
|
|
44
|
+
* @returns The YAML string representation of the input object.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* import { stringifyYaml } from './yaml';
|
|
49
|
+
*
|
|
50
|
+
* const data = {
|
|
51
|
+
* example: 'value',
|
|
52
|
+
* };
|
|
53
|
+
* const yamlString = stringifyYaml(data);
|
|
54
|
+
* console.log(yamlString); // "example: value\n"
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare function stringifyYaml(content: any, options?: DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions & ToStringOptions): string;
|
|
58
|
+
|
|
59
|
+
export { parseYaml, registerYamlTag, stringifyYaml };
|
package/dist/yaml.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e,t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,f=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,n={};((e,r)=>{for(var f in r)t(e,f,{get:r[f],enumerable:!0})})(n,{parseYaml:()=>a,registerYamlTag:()=>u,stringifyYaml:()=>c}),module.exports=(e=n,((e,n,i,s)=>{if(n&&"object"==typeof n||"function"==typeof n)for(let u of f(n))o.call(e,u)||u===i||t(e,u,{get:()=>n[u],enumerable:!(s=r(n,u))||s.enumerable});return e})(t({},"__esModule",{value:!0}),e));var i=require("yaml"),s=[];function u(e){Array.isArray(e)||(e=[e]);for(const t of e){-1===s.indexOf(t)&&s.push(t)}}function a(e,t){if(t)if(t.customTags){if(Array.isArray(t.customTags))t.customTags=s.concat(t.customTags);else if("function"==typeof t.customTags){const e=t.customTags;t.customTags=t=>e(s.concat(t))}}else t.customTags=s;else t={customTags:s};return(0,i.parse)(e,t)}function c(e,t){if(t)if(t.customTags){if(Array.isArray(t.customTags))t.customTags=s.concat(t.customTags);else if("function"==typeof t.customTags){const e=t.customTags;t.customTags=t=>e(s.concat(t))}}else t.customTags=s;else t={customTags:s};return(0,i.stringify)(e,t)}
|
package/dist/yaml.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{parseYaml as m,registerYamlTag as o,stringifyYaml as r}from"./chunk-OTEAFARC.mjs";import"./chunk-UJZVJIGI.mjs";export{m as parseYaml,o as registerYamlTag,r as stringifyYaml};
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
**@isdk/util**
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
# Utility Functions
|
|
6
|
+
|
|
7
|
+
This package provides a set of utility functions.
|
|
8
|
+
|
|
9
|
+
[](https://npmjs.org/package/@isdk/util)
|
|
10
|
+
[](https://npmjs.org/package/@isdk/util)
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
[**@isdk/util**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/util](../globals.md) / ConfigFile
|
|
6
|
+
|
|
7
|
+
# Class: ConfigFile
|
|
8
|
+
|
|
9
|
+
Defined in: [config-file.ts:45](https://github.com/isdk/util.js/blob/9d50730dc10248681409cd2901eedc5302b8836b/src/config-file.ts#L45)
|
|
10
|
+
|
|
11
|
+
Represents a configuration file utility class that provides methods to load and save configuration files.
|
|
12
|
+
It supports multiple file formats such as YAML, JSON, etc., by registering corresponding parsers and stringifiers.
|
|
13
|
+
|
|
14
|
+
## Example
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
// Register a custom file type handler
|
|
18
|
+
ConfigFile.register('.custom', (content) => {
|
|
19
|
+
return { data: content.toUpperCase() }; // Example parser
|
|
20
|
+
}, (obj) => {
|
|
21
|
+
return obj.data.toLowerCase(); // Example stringifier
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Save a configuration file
|
|
25
|
+
ConfigFile.save('config.custom', { key: 'value' });
|
|
26
|
+
|
|
27
|
+
// Load a configuration file
|
|
28
|
+
const config = ConfigFile.load('config.custom');
|
|
29
|
+
console.log(config); // Output: { key: 'value' }
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Constructors
|
|
33
|
+
|
|
34
|
+
### Constructor
|
|
35
|
+
|
|
36
|
+
> **new ConfigFile**(): `ConfigFile`
|
|
37
|
+
|
|
38
|
+
#### Returns
|
|
39
|
+
|
|
40
|
+
`ConfigFile`
|
|
41
|
+
|
|
42
|
+
## Properties
|
|
43
|
+
|
|
44
|
+
### stringifys
|
|
45
|
+
|
|
46
|
+
> `static` **stringifys**: `Record`\<`string`, `StringifyFunc`\> = `{}`
|
|
47
|
+
|
|
48
|
+
Defined in: [config-file.ts:49](https://github.com/isdk/util.js/blob/9d50730dc10248681409cd2901eedc5302b8836b/src/config-file.ts#L49)
|
|
49
|
+
|
|
50
|
+
A record of registered stringify functions for different file extensions.
|
|
51
|
+
|
|
52
|
+
## Methods
|
|
53
|
+
|
|
54
|
+
### load()
|
|
55
|
+
|
|
56
|
+
> `static` **load**(`filename`, `options`?): `any`
|
|
57
|
+
|
|
58
|
+
Defined in: [config-file.ts:84](https://github.com/isdk/util.js/blob/9d50730dc10248681409cd2901eedc5302b8836b/src/config-file.ts#L84)
|
|
59
|
+
|
|
60
|
+
Loads a configuration file based on the provided filename and options.
|
|
61
|
+
|
|
62
|
+
#### Parameters
|
|
63
|
+
|
|
64
|
+
##### filename
|
|
65
|
+
|
|
66
|
+
`string`
|
|
67
|
+
|
|
68
|
+
The path to the configuration file.
|
|
69
|
+
|
|
70
|
+
##### options?
|
|
71
|
+
|
|
72
|
+
`LoadConfigFileOptions`
|
|
73
|
+
|
|
74
|
+
Additional options for loading the configuration file.
|
|
75
|
+
|
|
76
|
+
#### Returns
|
|
77
|
+
|
|
78
|
+
`any`
|
|
79
|
+
|
|
80
|
+
The parsed configuration object.
|
|
81
|
+
|
|
82
|
+
#### Example
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
const config = ConfigFile.load('config.yaml');
|
|
86
|
+
console.log(config); // Output: { key: 'value' }
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
***
|
|
90
|
+
|
|
91
|
+
### register()
|
|
92
|
+
|
|
93
|
+
> `static` **register**(`extname`, `parser`, `stringify`): `void`
|
|
94
|
+
|
|
95
|
+
Defined in: [config-file.ts:63](https://github.com/isdk/util.js/blob/9d50730dc10248681409cd2901eedc5302b8836b/src/config-file.ts#L63)
|
|
96
|
+
|
|
97
|
+
Registers a parser and stringifier for specific file extensions.
|
|
98
|
+
|
|
99
|
+
#### Parameters
|
|
100
|
+
|
|
101
|
+
##### extname
|
|
102
|
+
|
|
103
|
+
The file extension(s) to register the parser and stringifier for.
|
|
104
|
+
|
|
105
|
+
`string` | `string`[]
|
|
106
|
+
|
|
107
|
+
##### parser
|
|
108
|
+
|
|
109
|
+
(`content`) => `any`
|
|
110
|
+
|
|
111
|
+
A function that parses the file content into an object.
|
|
112
|
+
|
|
113
|
+
##### stringify
|
|
114
|
+
|
|
115
|
+
`StringifyFunc`
|
|
116
|
+
|
|
117
|
+
A function that converts an object back into file content.
|
|
118
|
+
|
|
119
|
+
#### Returns
|
|
120
|
+
|
|
121
|
+
`void`
|
|
122
|
+
|
|
123
|
+
#### Example
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
ConfigFile.register(['.json'], JSON.parse, (obj) => JSON.stringify(obj, null, 2));
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
***
|
|
130
|
+
|
|
131
|
+
### save()
|
|
132
|
+
|
|
133
|
+
> `static` **save**(`filename`, `config`, `options`?): `string`
|
|
134
|
+
|
|
135
|
+
Defined in: [config-file.ts:101](https://github.com/isdk/util.js/blob/9d50730dc10248681409cd2901eedc5302b8836b/src/config-file.ts#L101)
|
|
136
|
+
|
|
137
|
+
Saves a configuration object to a file with the specified filename and options.
|
|
138
|
+
|
|
139
|
+
#### Parameters
|
|
140
|
+
|
|
141
|
+
##### filename
|
|
142
|
+
|
|
143
|
+
`string`
|
|
144
|
+
|
|
145
|
+
The path where the configuration file should be saved.
|
|
146
|
+
|
|
147
|
+
##### config
|
|
148
|
+
|
|
149
|
+
`any`
|
|
150
|
+
|
|
151
|
+
The configuration object to save.
|
|
152
|
+
|
|
153
|
+
##### options?
|
|
154
|
+
|
|
155
|
+
`LoadConfigFileOptions`
|
|
156
|
+
|
|
157
|
+
Additional options for saving the configuration file.
|
|
158
|
+
|
|
159
|
+
#### Returns
|
|
160
|
+
|
|
161
|
+
`string`
|
|
162
|
+
|
|
163
|
+
The final filename where the configuration was saved.
|
|
164
|
+
|
|
165
|
+
#### Example
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
ConfigFile.save('config.json', { key: 'value' });
|
|
169
|
+
```
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[**@isdk/util**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/util](../globals.md) / getMultiLevelExtname
|
|
6
|
+
|
|
7
|
+
# Function: getMultiLevelExtname()
|
|
8
|
+
|
|
9
|
+
> **getMultiLevelExtname**(`filename`, `level`): `string`
|
|
10
|
+
|
|
11
|
+
Defined in: [get-multi-level-extname.ts:9](https://github.com/isdk/util.js/blob/9d50730dc10248681409cd2901eedc5302b8836b/src/get-multi-level-extname.ts#L9)
|
|
12
|
+
|
|
13
|
+
Retrieves multi-level file extension
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
### filename
|
|
18
|
+
|
|
19
|
+
`string`
|
|
20
|
+
|
|
21
|
+
The file name
|
|
22
|
+
|
|
23
|
+
### level
|
|
24
|
+
|
|
25
|
+
`number` = `1`
|
|
26
|
+
|
|
27
|
+
The level, default is 1, indicating the number of extension levels to retrieve
|
|
28
|
+
|
|
29
|
+
## Returns
|
|
30
|
+
|
|
31
|
+
`string`
|
|
32
|
+
|
|
33
|
+
Returns a concatenated string of multiple extensions, or an empty string if no extension is found
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
[**@isdk/util**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/util](../globals.md) / glob
|
|
6
|
+
|
|
7
|
+
# Function: glob()
|
|
8
|
+
|
|
9
|
+
> **glob**(`filepath`, `pattern`, `rootDir`?): `undefined` \| `boolean`
|
|
10
|
+
|
|
11
|
+
Defined in: [glob.ts:29](https://github.com/isdk/util.js/blob/9d50730dc10248681409cd2901eedc5302b8836b/src/glob.ts#L29)
|
|
12
|
+
|
|
13
|
+
Matches a file path against a list of glob patterns.
|
|
14
|
+
|
|
15
|
+
This function checks if the given `filepath` matches any of the provided glob `pattern`s.
|
|
16
|
+
If a `rootDir` is specified, the `filepath` will first be converted to a relative path
|
|
17
|
+
based on the `rootDir`.
|
|
18
|
+
|
|
19
|
+
## Parameters
|
|
20
|
+
|
|
21
|
+
### filepath
|
|
22
|
+
|
|
23
|
+
`string`
|
|
24
|
+
|
|
25
|
+
The file path to match.
|
|
26
|
+
|
|
27
|
+
### pattern
|
|
28
|
+
|
|
29
|
+
`string`[]
|
|
30
|
+
|
|
31
|
+
An array of glob patterns to match against.
|
|
32
|
+
|
|
33
|
+
### rootDir?
|
|
34
|
+
|
|
35
|
+
`string`
|
|
36
|
+
|
|
37
|
+
(Optional) The root directory used to calculate the relative path of `filepath`.
|
|
38
|
+
|
|
39
|
+
## Returns
|
|
40
|
+
|
|
41
|
+
`undefined` \| `boolean`
|
|
42
|
+
|
|
43
|
+
Returns `true` if the `filepath` matches any of the patterns, otherwise `false`.
|
|
44
|
+
|
|
45
|
+
## Example
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { glob } from './glob';
|
|
49
|
+
|
|
50
|
+
const filepath = '/home/user/project/src/index.ts';
|
|
51
|
+
const patterns = ['src/*.ts', '!src/test.ts'];
|
|
52
|
+
const rootDir = '/home/user/project';
|
|
53
|
+
|
|
54
|
+
const result = glob(filepath, patterns, rootDir);
|
|
55
|
+
console.log(result); // true
|
|
56
|
+
```
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[**@isdk/util**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/util](../globals.md) / isStringIn
|
|
6
|
+
|
|
7
|
+
# Function: isStringIn()
|
|
8
|
+
|
|
9
|
+
> **isStringIn**(`str`, `arr`): `boolean`
|
|
10
|
+
|
|
11
|
+
Defined in: [is-string-in.ts:17](https://github.com/isdk/util.js/blob/9d50730dc10248681409cd2901eedc5302b8836b/src/is-string-in.ts#L17)
|
|
12
|
+
|
|
13
|
+
Checks if a given string exists within an array of strings or a single string.
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
### str
|
|
18
|
+
|
|
19
|
+
`string`
|
|
20
|
+
|
|
21
|
+
The string to search for.
|
|
22
|
+
|
|
23
|
+
### arr
|
|
24
|
+
|
|
25
|
+
An array of strings or a single string to search within.
|
|
26
|
+
|
|
27
|
+
`string` | `string`[]
|
|
28
|
+
|
|
29
|
+
## Returns
|
|
30
|
+
|
|
31
|
+
`boolean`
|
|
32
|
+
|
|
33
|
+
Returns `true` if the string is found, otherwise `false`.
|
|
34
|
+
|
|
35
|
+
## Example
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
const result = isStringIn("apple", ["banana", "apple", "cherry"]);
|
|
39
|
+
console.log(result); // true
|
|
40
|
+
|
|
41
|
+
const singleResult = isStringIn("hello", "hello");
|
|
42
|
+
console.log(singleResult); // true
|
|
43
|
+
```
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
[**@isdk/util**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/util](../globals.md) / normalizeIncludeFiles
|
|
6
|
+
|
|
7
|
+
# Function: normalizeIncludeFiles()
|
|
8
|
+
|
|
9
|
+
> **normalizeIncludeFiles**(`files`?, `defaultFiles`?): `string`[]
|
|
10
|
+
|
|
11
|
+
Defined in: [include-files.ts:34](https://github.com/isdk/util.js/blob/9d50730dc10248681409cd2901eedc5302b8836b/src/include-files.ts#L34)
|
|
12
|
+
|
|
13
|
+
Normalizes a list of file patterns for glob matching.
|
|
14
|
+
|
|
15
|
+
This function takes either an array of file patterns or an object containing `include` and `exclude` arrays,
|
|
16
|
+
and returns a normalized array of file patterns. If no patterns are provided, it defaults to including
|
|
17
|
+
all text-based files as defined in `DefaultAllTextFiles`.
|
|
18
|
+
|
|
19
|
+
## Parameters
|
|
20
|
+
|
|
21
|
+
### files?
|
|
22
|
+
|
|
23
|
+
Either an array of file patterns or an object with `include` and `exclude` properties.
|
|
24
|
+
|
|
25
|
+
`string`[] | [`IncludeFiles`](../interfaces/IncludeFiles.md)
|
|
26
|
+
|
|
27
|
+
### defaultFiles?
|
|
28
|
+
|
|
29
|
+
`string`[] = `DefaultAllTextFiles`
|
|
30
|
+
|
|
31
|
+
An optional array of default file patterns to use if no include patterns are specified.
|
|
32
|
+
Defaults to `DefaultAllTextFiles`.
|
|
33
|
+
|
|
34
|
+
## Returns
|
|
35
|
+
|
|
36
|
+
`string`[]
|
|
37
|
+
|
|
38
|
+
A normalized array of file patterns, with excluded patterns prefixed by `!`.
|
|
39
|
+
|
|
40
|
+
## Example
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
const result = normalizeIncludeFiles({
|
|
44
|
+
include: ['*.ts', '*.js'],
|
|
45
|
+
exclude: ['node_modules/**']
|
|
46
|
+
});
|
|
47
|
+
console.log(result);
|
|
48
|
+
// Output: ['*.ts', '*.js', '!node_modules/**']
|
|
49
|
+
```
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[**@isdk/util**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/util](../globals.md) / parseFrontMatter
|
|
6
|
+
|
|
7
|
+
# Function: parseFrontMatter()
|
|
8
|
+
|
|
9
|
+
> **parseFrontMatter**(`value`, `delimiter`): `object`
|
|
10
|
+
|
|
11
|
+
Defined in: [front-matter.ts:6](https://github.com/isdk/util.js/blob/9d50730dc10248681409cd2901eedc5302b8836b/src/front-matter.ts#L6)
|
|
12
|
+
|
|
13
|
+
## Parameters
|
|
14
|
+
|
|
15
|
+
### value
|
|
16
|
+
|
|
17
|
+
`string`
|
|
18
|
+
|
|
19
|
+
### delimiter
|
|
20
|
+
|
|
21
|
+
`string` = `FrontMatterDelimiter`
|
|
22
|
+
|
|
23
|
+
## Returns
|
|
24
|
+
|
|
25
|
+
`object`
|
|
26
|
+
|
|
27
|
+
### content
|
|
28
|
+
|
|
29
|
+
> **content**: `string`
|
|
30
|
+
|
|
31
|
+
### data
|
|
32
|
+
|
|
33
|
+
> **data**: `any`
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[**@isdk/util**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/util](../globals.md) / parseYaml
|
|
6
|
+
|
|
7
|
+
# Function: parseYaml()
|
|
8
|
+
|
|
9
|
+
> **parseYaml**(`content`, `options`?): `any`
|
|
10
|
+
|
|
11
|
+
Defined in: [yaml.ts:51](https://github.com/isdk/util.js/blob/9d50730dc10248681409cd2901eedc5302b8836b/src/yaml.ts#L51)
|
|
12
|
+
|
|
13
|
+
Parses a YAML string into a JavaScript object with optional custom tags.
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
### content
|
|
18
|
+
|
|
19
|
+
`string`
|
|
20
|
+
|
|
21
|
+
The YAML string to parse.
|
|
22
|
+
|
|
23
|
+
### options?
|
|
24
|
+
|
|
25
|
+
`ParseOptions` & `DocumentOptions` & `SchemaOptions` & `ToJSOptions`
|
|
26
|
+
|
|
27
|
+
Optional parsing options, including custom tags.
|
|
28
|
+
|
|
29
|
+
## Returns
|
|
30
|
+
|
|
31
|
+
`any`
|
|
32
|
+
|
|
33
|
+
The parsed JavaScript object.
|
|
34
|
+
|
|
35
|
+
## Example
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { parseYaml } from './yaml';
|
|
39
|
+
|
|
40
|
+
const yamlContent = `
|
|
41
|
+
example: !custom value
|
|
42
|
+
`;
|
|
43
|
+
const result = parseYaml(yamlContent);
|
|
44
|
+
console.log(result); // { example: 'resolved-value' }
|
|
45
|
+
```
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[**@isdk/util**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/util](../globals.md) / registerYamlTag
|
|
6
|
+
|
|
7
|
+
# Function: registerYamlTag()
|
|
8
|
+
|
|
9
|
+
> **registerYamlTag**(`tags`): `void`
|
|
10
|
+
|
|
11
|
+
Defined in: [yaml.ts:23](https://github.com/isdk/util.js/blob/9d50730dc10248681409cd2901eedc5302b8836b/src/yaml.ts#L23)
|
|
12
|
+
|
|
13
|
+
Registers custom YAML tags to be used in parsing and stringifying YAML content.
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
### tags
|
|
18
|
+
|
|
19
|
+
`any`
|
|
20
|
+
|
|
21
|
+
A single tag or an array of tags to register.
|
|
22
|
+
|
|
23
|
+
## Returns
|
|
24
|
+
|
|
25
|
+
`void`
|
|
26
|
+
|
|
27
|
+
## Example
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { registerYamlTag } from './yaml';
|
|
31
|
+
|
|
32
|
+
const customTag = {
|
|
33
|
+
tag: '!custom',
|
|
34
|
+
resolve: (value) => `resolved-${value}`,
|
|
35
|
+
};
|
|
36
|
+
registerYamlTag(customTag);
|
|
37
|
+
```
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[**@isdk/util**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/util](../globals.md) / removeLeadingEmptyLines
|
|
6
|
+
|
|
7
|
+
# Function: removeLeadingEmptyLines()
|
|
8
|
+
|
|
9
|
+
> **removeLeadingEmptyLines**(`text`): `string`
|
|
10
|
+
|
|
11
|
+
Defined in: [remove-leading-empty-lines.ts:16](https://github.com/isdk/util.js/blob/9d50730dc10248681409cd2901eedc5302b8836b/src/remove-leading-empty-lines.ts#L16)
|
|
12
|
+
|
|
13
|
+
Removes all leading empty lines or "#" comments line from the given string.
|
|
14
|
+
|
|
15
|
+
This function trims any sequence of empty lines that appear at the beginning
|
|
16
|
+
of the input string. It accounts for different newline characters including
|
|
17
|
+
'\n', '\r\n', and also considers lines that contain only whitespace characters.
|
|
18
|
+
|
|
19
|
+
## Parameters
|
|
20
|
+
|
|
21
|
+
### text
|
|
22
|
+
|
|
23
|
+
`string`
|
|
24
|
+
|
|
25
|
+
The string from which to remove leading empty lines.
|
|
26
|
+
|
|
27
|
+
## Returns
|
|
28
|
+
|
|
29
|
+
`string`
|
|
30
|
+
|
|
31
|
+
The string with leading empty lines removed.
|
|
32
|
+
|
|
33
|
+
## Example
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
const sampleText = '# This is a comment\n\nHello, world!\n';
|
|
37
|
+
const cleanedText = removeLeadingEmptyLines(sampleText);
|
|
38
|
+
// cleanedText is now 'Hello, world!\n'
|
|
39
|
+
```
|