@isdk/util 0.3.7 → 0.3.9
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/dist/index.d.mts +85 -31
- package/dist/index.d.ts +85 -31
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/docs/classes/BinarySemaphore.md +25 -25
- package/docs/classes/ConfigFile.md +6 -6
- package/docs/classes/Deque.md +13 -13
- package/docs/classes/IntSet.md +12 -12
- package/docs/classes/Semaphore.md +26 -26
- package/docs/classes/SignalGate.md +9 -9
- package/docs/functions/RateLimit.md +1 -1
- package/docs/functions/arrayHasAll.md +1 -1
- package/docs/functions/extNameLevel.md +1 -1
- package/docs/functions/extractCodeBlock.md +22 -62
- package/docs/functions/extractTopLevelCodeBlocks.md +37 -0
- package/docs/functions/filenameReservedRegex.md +1 -1
- package/docs/functions/findPort.md +13 -5
- package/docs/functions/getMultiLevelExtname.md +1 -1
- package/docs/functions/glob.md +1 -1
- package/docs/functions/isStringIn.md +1 -1
- package/docs/functions/isValidFilename.md +1 -1
- package/docs/functions/isValidFilepath.md +1 -1
- package/docs/functions/normalizeIncludeFiles.md +1 -1
- package/docs/functions/omitDeepBy.md +1 -1
- package/docs/functions/omitEmptyDeep.md +1 -1
- package/docs/functions/parseCodeBlockSelector.md +34 -0
- package/docs/functions/parseFrontMatter.md +1 -1
- package/docs/functions/parseYaml.md +1 -1
- package/docs/functions/reControlCharsRegex.md +1 -1
- package/docs/functions/registerYamlTag.md +1 -1
- package/docs/functions/removeLeadingEmptyLines.md +1 -1
- package/docs/functions/sanitizeFilename.md +1 -1
- package/docs/functions/sanitizeFilepath.md +1 -1
- package/docs/functions/sleep.md +1 -1
- package/docs/functions/stringifyYaml.md +1 -1
- package/docs/functions/toCamelCase.md +1 -1
- package/docs/functions/toCapitalCase.md +1 -1
- package/docs/functions/toPascalCase.md +1 -1
- package/docs/functions/traverseFolder.md +1 -1
- package/docs/functions/traverseFolderSync.md +1 -1
- package/docs/functions/yieldExec.md +1 -1
- package/docs/globals.md +5 -0
- package/docs/interfaces/BinarySemaphoreAcquireOptions.md +2 -2
- package/docs/interfaces/BinarySemaphoreOptions.md +5 -5
- package/docs/interfaces/BinarySemaphoreReleaseOptions.md +2 -2
- package/docs/interfaces/BinarySemaphoreReleaserFunc.md +3 -3
- package/docs/interfaces/CodeBlockSelectorPart.md +36 -0
- package/docs/interfaces/CodeString.md +3 -3
- package/docs/interfaces/ExtractCodeBlockOptions.md +27 -6
- package/docs/interfaces/FindPortOptions.md +25 -0
- package/docs/interfaces/IncludeFiles.md +3 -3
- package/docs/interfaces/LoadConfigFileOptions.md +3 -3
- package/docs/interfaces/SanitizeFilenameOptions.md +3 -3
- package/docs/interfaces/SemaphoreOptions.md +7 -7
- package/docs/interfaces/SemaphoreTaskItem.md +5 -5
- package/docs/type-aliases/CodeBlockCombinator.md +18 -0
- package/docs/type-aliases/SemaphoreIsReadyFuncType.md +1 -1
- package/docs/type-aliases/StringifyFunc.md +1 -1
- package/docs/type-aliases/TraverseFolderHandler.md +1 -1
- package/docs/type-aliases/TraverseFolderSyncHandler.md +1 -1
- package/docs/variables/DefaultAllTextFiles.md +1 -1
- package/docs/variables/DefaultAsyncSemaphoreCapacity.md +1 -1
- package/docs/variables/FilenameReservedRegex.md +1 -1
- package/docs/variables/WindowsReservedNameRegex.md +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -925,7 +925,18 @@ declare class SignalGate<T = void> {
|
|
|
925
925
|
wait(): Promise<T>;
|
|
926
926
|
}
|
|
927
927
|
|
|
928
|
-
|
|
928
|
+
interface FindPortOptions {
|
|
929
|
+
retryCount?: number;
|
|
930
|
+
host?: string;
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* Finds an available port.
|
|
934
|
+
*
|
|
935
|
+
* @param port - The starting port number or a string representation of it. Defaults to 0 (random port).
|
|
936
|
+
* @param options - Either the retry count (number) or an options object.
|
|
937
|
+
* @returns A promise that resolves to the available port number.
|
|
938
|
+
*/
|
|
939
|
+
declare function findPort(port: string | number | undefined, options?: number | FindPortOptions): Promise<number>;
|
|
929
940
|
|
|
930
941
|
/**
|
|
931
942
|
* Recursively removes properties from an object or array that satisfy the given predicate condition.
|
|
@@ -1056,16 +1067,47 @@ interface CodeString extends String {
|
|
|
1056
1067
|
*/
|
|
1057
1068
|
meta?: string;
|
|
1058
1069
|
}
|
|
1070
|
+
/**
|
|
1071
|
+
* Supported combinators for code block selectors.
|
|
1072
|
+
*
|
|
1073
|
+
* - `>` (Direct Child): Matches top-level code blocks within the current context.
|
|
1074
|
+
* - ` ` (Descendant): Matches all code blocks within the current context, including deeply nested ones. (Planned)
|
|
1075
|
+
* - `+` (Adjacent Sibling): Matches the very next code block at the same nesting level. (Planned)
|
|
1076
|
+
* - `~` (General Sibling): Matches all subsequent code blocks at the same nesting level. (Planned)
|
|
1077
|
+
*/
|
|
1078
|
+
type CodeBlockCombinator = '>' | ' ' | '+' | '~';
|
|
1079
|
+
/**
|
|
1080
|
+
* Represents a single segment in a code block selector path.
|
|
1081
|
+
*
|
|
1082
|
+
* A path like `md > ts` is parsed into two parts:
|
|
1083
|
+
* 1. `{ combinator: ' ', lang: 'md' }`
|
|
1084
|
+
* 2. `{ combinator: '>', lang: 'ts' }`
|
|
1085
|
+
*/
|
|
1086
|
+
interface CodeBlockSelectorPart {
|
|
1087
|
+
/**
|
|
1088
|
+
* The relationship to the previous segment in the path.
|
|
1089
|
+
* For the first segment, ' ' usually implies a search in the root context.
|
|
1090
|
+
*/
|
|
1091
|
+
combinator: CodeBlockCombinator;
|
|
1092
|
+
/**
|
|
1093
|
+
* The target language identifier or alias to match.
|
|
1094
|
+
*/
|
|
1095
|
+
lang: string;
|
|
1096
|
+
}
|
|
1059
1097
|
/**
|
|
1060
1098
|
* Options for extracting code blocks.
|
|
1061
1099
|
*/
|
|
1062
1100
|
interface ExtractCodeBlockOptions {
|
|
1063
1101
|
/**
|
|
1064
|
-
* Optional. The expected language identifier
|
|
1102
|
+
* Optional. The expected language identifier or a CSS-like selector path.
|
|
1103
|
+
* Supports aliases (e.g., 'js' for 'javascript').
|
|
1104
|
+
*
|
|
1105
|
+
* @example 'ts' - Find the last TypeScript block.
|
|
1106
|
+
* @example 'md > ts' - Find ts blocks inside md blocks.
|
|
1065
1107
|
*/
|
|
1066
1108
|
lang?: string;
|
|
1067
1109
|
/**
|
|
1068
|
-
* Optional. The 0-based index of the code block to extract.
|
|
1110
|
+
* Optional. The 0-based index of the code block to extract from the final result set.
|
|
1069
1111
|
* Supports negative indexing: -1 means the last one, -2 means the second to last, etc.
|
|
1070
1112
|
* Defaults to -1.
|
|
1071
1113
|
*/
|
|
@@ -1074,48 +1116,60 @@ interface ExtractCodeBlockOptions {
|
|
|
1074
1116
|
* Optional. If true, returns an array of all matching code blocks.
|
|
1075
1117
|
*/
|
|
1076
1118
|
all?: boolean;
|
|
1119
|
+
/**
|
|
1120
|
+
* Optional. A map of language aliases to their normalized names.
|
|
1121
|
+
*/
|
|
1122
|
+
langMap?: Record<string, string>;
|
|
1077
1123
|
}
|
|
1078
1124
|
/**
|
|
1079
|
-
* Extracts fenced code
|
|
1125
|
+
* Extracts top-level fenced code blocks from the input `text`.
|
|
1080
1126
|
*
|
|
1081
|
-
* This function
|
|
1082
|
-
*
|
|
1127
|
+
* This function handles nested blocks correctly by ensuring the closing fence
|
|
1128
|
+
* matches the length and character of the opening fence. It only scans the
|
|
1129
|
+
* immediate level of the provided text.
|
|
1130
|
+
*
|
|
1131
|
+
* @param text - The input string.
|
|
1132
|
+
* @param options - Extraction options (uses `lang` and `langMap` for filtering).
|
|
1133
|
+
* @returns An array of {@link CodeString} objects representing the matched blocks.
|
|
1134
|
+
*/
|
|
1135
|
+
declare function extractTopLevelCodeBlocks(text: string, options?: ExtractCodeBlockOptions): CodeString[];
|
|
1136
|
+
/**
|
|
1137
|
+
* Parses a selector string into an array of structured {@link CodeBlockSelectorPart} objects.
|
|
1083
1138
|
*
|
|
1084
1139
|
* @example
|
|
1085
1140
|
* ```ts
|
|
1086
|
-
*
|
|
1087
|
-
*
|
|
1088
|
-
* console.log(code); // 'console.log("hello");'
|
|
1089
|
-
* console.log(code.lang); // 'js'
|
|
1141
|
+
* parseCodeBlockSelector('md > ts');
|
|
1142
|
+
* // => [{combinator: ' ', lang: 'md'}, {combinator: '>', lang: 'ts'}]
|
|
1090
1143
|
* ```
|
|
1091
1144
|
*
|
|
1092
|
-
* @param
|
|
1093
|
-
* @
|
|
1094
|
-
* the last code block in the text is returned, irrespective of its language.
|
|
1095
|
-
* @returns The extracted code content as a {@link CodeString} instance (with `lang` and `meta` properties)
|
|
1096
|
-
* if a matching code block is found, or as the original `text` if no match is found.
|
|
1145
|
+
* @param lang - The selector string.
|
|
1146
|
+
* @returns An array of parsed selector parts.
|
|
1097
1147
|
*/
|
|
1098
|
-
declare function
|
|
1148
|
+
declare function parseCodeBlockSelector(lang?: string): CodeBlockSelectorPart[];
|
|
1099
1149
|
/**
|
|
1100
|
-
* Extracts fenced code block(s) from the input `text
|
|
1150
|
+
* Extracts fenced code block(s) from the input `text`, with support for nested path selectors.
|
|
1151
|
+
*
|
|
1152
|
+
* This function acts as a query engine for Markdown code blocks. It can extract
|
|
1153
|
+
* single blocks, multiple blocks, or drill down into nested structures using
|
|
1154
|
+
* CSS-like syntax.
|
|
1101
1155
|
*
|
|
1102
1156
|
* @example
|
|
1103
1157
|
* ```ts
|
|
1104
|
-
*
|
|
1105
|
-
*
|
|
1106
|
-
*
|
|
1107
|
-
* //
|
|
1108
|
-
* const
|
|
1158
|
+
* // Simple extraction (last block)
|
|
1159
|
+
* const code = extractCodeBlock(input, 'js');
|
|
1160
|
+
*
|
|
1161
|
+
* // Nested extraction
|
|
1162
|
+
* const inner = extractCodeBlock(input, 'md > ts');
|
|
1163
|
+
*
|
|
1164
|
+
* // Extract all matching blocks
|
|
1165
|
+
* const all = extractCodeBlock(input, { lang: 'container > item', all: true });
|
|
1109
1166
|
* ```
|
|
1110
1167
|
*
|
|
1111
|
-
* @param text - The input string
|
|
1112
|
-
* @param
|
|
1113
|
-
*
|
|
1114
|
-
*
|
|
1115
|
-
* - `all`: If `true`, returns an array of all matching blocks.
|
|
1116
|
-
* @returns If `options.all` is true, returns an array of {@link CodeString} or string.
|
|
1117
|
-
* Otherwise, returns a single {@link CodeString} or the original `text` if no match is found at the specified index.
|
|
1168
|
+
* @param text - The input string containing Markdown.
|
|
1169
|
+
* @param langOrOptions - Either a language/selector string or a full {@link ExtractCodeBlockOptions} object.
|
|
1170
|
+
* @returns A single {@link CodeString}, an array of {@link CodeString}s (if `all: true`),
|
|
1171
|
+
* or the original `text` if no matches are found at the specified index.
|
|
1118
1172
|
*/
|
|
1119
|
-
declare function extractCodeBlock(text: string,
|
|
1173
|
+
declare function extractCodeBlock(text: string, langOrOptions?: string | ExtractCodeBlockOptions): CodeString | string | (CodeString | string)[];
|
|
1120
1174
|
|
|
1121
|
-
export { BinarySemaphore, type BinarySemaphoreAcquireOptions, type BinarySemaphoreOptions, type BinarySemaphoreReleaseOptions, type BinarySemaphoreReleaserFunc, type CodeString, ConfigFile, DefaultAllTextFiles, DefaultAsyncSemaphoreCapacity, Deque, type ExtractCodeBlockOptions, FilenameReservedRegex, type IncludeFiles, IntSet, type LoadConfigFileOptions, RateLimit, type SanitizeFilenameOptions, Semaphore, type SemaphoreIsReadyFuncType, type SemaphoreOptions, type SemaphoreTaskItem, SignalGate, type StringifyFunc, type TraverseFolderHandler, type TraverseFolderSyncHandler, WindowsReservedNameRegex, arrayHasAll, extNameLevel, extractCodeBlock, filenameReservedRegex, findPort, getMultiLevelExtname, glob, isStringIn, isValidFilename, isValidFilepath, normalizeIncludeFiles, omitDeepBy, omitEmptyDeep, parseFrontMatter, parseYaml, reControlCharsRegex, registerYamlTag, removeLeadingEmptyLines, sanitizeFilename, sanitizeFilepath, sleep, stringifyYaml, toCamelCase, toCapitalCase, toPascalCase, traverseFolder, traverseFolderSync, yieldExec };
|
|
1175
|
+
export { BinarySemaphore, type BinarySemaphoreAcquireOptions, type BinarySemaphoreOptions, type BinarySemaphoreReleaseOptions, type BinarySemaphoreReleaserFunc, type CodeBlockCombinator, type CodeBlockSelectorPart, type CodeString, ConfigFile, DefaultAllTextFiles, DefaultAsyncSemaphoreCapacity, Deque, type ExtractCodeBlockOptions, FilenameReservedRegex, type FindPortOptions, type IncludeFiles, IntSet, type LoadConfigFileOptions, RateLimit, type SanitizeFilenameOptions, Semaphore, type SemaphoreIsReadyFuncType, type SemaphoreOptions, type SemaphoreTaskItem, SignalGate, type StringifyFunc, type TraverseFolderHandler, type TraverseFolderSyncHandler, WindowsReservedNameRegex, arrayHasAll, extNameLevel, extractCodeBlock, extractTopLevelCodeBlocks, filenameReservedRegex, findPort, getMultiLevelExtname, glob, isStringIn, isValidFilename, isValidFilepath, normalizeIncludeFiles, omitDeepBy, omitEmptyDeep, parseCodeBlockSelector, parseFrontMatter, parseYaml, reControlCharsRegex, registerYamlTag, removeLeadingEmptyLines, sanitizeFilename, sanitizeFilepath, sleep, stringifyYaml, toCamelCase, toCapitalCase, toPascalCase, traverseFolder, traverseFolderSync, yieldExec };
|
package/dist/index.d.ts
CHANGED
|
@@ -925,7 +925,18 @@ declare class SignalGate<T = void> {
|
|
|
925
925
|
wait(): Promise<T>;
|
|
926
926
|
}
|
|
927
927
|
|
|
928
|
-
|
|
928
|
+
interface FindPortOptions {
|
|
929
|
+
retryCount?: number;
|
|
930
|
+
host?: string;
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* Finds an available port.
|
|
934
|
+
*
|
|
935
|
+
* @param port - The starting port number or a string representation of it. Defaults to 0 (random port).
|
|
936
|
+
* @param options - Either the retry count (number) or an options object.
|
|
937
|
+
* @returns A promise that resolves to the available port number.
|
|
938
|
+
*/
|
|
939
|
+
declare function findPort(port: string | number | undefined, options?: number | FindPortOptions): Promise<number>;
|
|
929
940
|
|
|
930
941
|
/**
|
|
931
942
|
* Recursively removes properties from an object or array that satisfy the given predicate condition.
|
|
@@ -1056,16 +1067,47 @@ interface CodeString extends String {
|
|
|
1056
1067
|
*/
|
|
1057
1068
|
meta?: string;
|
|
1058
1069
|
}
|
|
1070
|
+
/**
|
|
1071
|
+
* Supported combinators for code block selectors.
|
|
1072
|
+
*
|
|
1073
|
+
* - `>` (Direct Child): Matches top-level code blocks within the current context.
|
|
1074
|
+
* - ` ` (Descendant): Matches all code blocks within the current context, including deeply nested ones. (Planned)
|
|
1075
|
+
* - `+` (Adjacent Sibling): Matches the very next code block at the same nesting level. (Planned)
|
|
1076
|
+
* - `~` (General Sibling): Matches all subsequent code blocks at the same nesting level. (Planned)
|
|
1077
|
+
*/
|
|
1078
|
+
type CodeBlockCombinator = '>' | ' ' | '+' | '~';
|
|
1079
|
+
/**
|
|
1080
|
+
* Represents a single segment in a code block selector path.
|
|
1081
|
+
*
|
|
1082
|
+
* A path like `md > ts` is parsed into two parts:
|
|
1083
|
+
* 1. `{ combinator: ' ', lang: 'md' }`
|
|
1084
|
+
* 2. `{ combinator: '>', lang: 'ts' }`
|
|
1085
|
+
*/
|
|
1086
|
+
interface CodeBlockSelectorPart {
|
|
1087
|
+
/**
|
|
1088
|
+
* The relationship to the previous segment in the path.
|
|
1089
|
+
* For the first segment, ' ' usually implies a search in the root context.
|
|
1090
|
+
*/
|
|
1091
|
+
combinator: CodeBlockCombinator;
|
|
1092
|
+
/**
|
|
1093
|
+
* The target language identifier or alias to match.
|
|
1094
|
+
*/
|
|
1095
|
+
lang: string;
|
|
1096
|
+
}
|
|
1059
1097
|
/**
|
|
1060
1098
|
* Options for extracting code blocks.
|
|
1061
1099
|
*/
|
|
1062
1100
|
interface ExtractCodeBlockOptions {
|
|
1063
1101
|
/**
|
|
1064
|
-
* Optional. The expected language identifier
|
|
1102
|
+
* Optional. The expected language identifier or a CSS-like selector path.
|
|
1103
|
+
* Supports aliases (e.g., 'js' for 'javascript').
|
|
1104
|
+
*
|
|
1105
|
+
* @example 'ts' - Find the last TypeScript block.
|
|
1106
|
+
* @example 'md > ts' - Find ts blocks inside md blocks.
|
|
1065
1107
|
*/
|
|
1066
1108
|
lang?: string;
|
|
1067
1109
|
/**
|
|
1068
|
-
* Optional. The 0-based index of the code block to extract.
|
|
1110
|
+
* Optional. The 0-based index of the code block to extract from the final result set.
|
|
1069
1111
|
* Supports negative indexing: -1 means the last one, -2 means the second to last, etc.
|
|
1070
1112
|
* Defaults to -1.
|
|
1071
1113
|
*/
|
|
@@ -1074,48 +1116,60 @@ interface ExtractCodeBlockOptions {
|
|
|
1074
1116
|
* Optional. If true, returns an array of all matching code blocks.
|
|
1075
1117
|
*/
|
|
1076
1118
|
all?: boolean;
|
|
1119
|
+
/**
|
|
1120
|
+
* Optional. A map of language aliases to their normalized names.
|
|
1121
|
+
*/
|
|
1122
|
+
langMap?: Record<string, string>;
|
|
1077
1123
|
}
|
|
1078
1124
|
/**
|
|
1079
|
-
* Extracts fenced code
|
|
1125
|
+
* Extracts top-level fenced code blocks from the input `text`.
|
|
1080
1126
|
*
|
|
1081
|
-
* This function
|
|
1082
|
-
*
|
|
1127
|
+
* This function handles nested blocks correctly by ensuring the closing fence
|
|
1128
|
+
* matches the length and character of the opening fence. It only scans the
|
|
1129
|
+
* immediate level of the provided text.
|
|
1130
|
+
*
|
|
1131
|
+
* @param text - The input string.
|
|
1132
|
+
* @param options - Extraction options (uses `lang` and `langMap` for filtering).
|
|
1133
|
+
* @returns An array of {@link CodeString} objects representing the matched blocks.
|
|
1134
|
+
*/
|
|
1135
|
+
declare function extractTopLevelCodeBlocks(text: string, options?: ExtractCodeBlockOptions): CodeString[];
|
|
1136
|
+
/**
|
|
1137
|
+
* Parses a selector string into an array of structured {@link CodeBlockSelectorPart} objects.
|
|
1083
1138
|
*
|
|
1084
1139
|
* @example
|
|
1085
1140
|
* ```ts
|
|
1086
|
-
*
|
|
1087
|
-
*
|
|
1088
|
-
* console.log(code); // 'console.log("hello");'
|
|
1089
|
-
* console.log(code.lang); // 'js'
|
|
1141
|
+
* parseCodeBlockSelector('md > ts');
|
|
1142
|
+
* // => [{combinator: ' ', lang: 'md'}, {combinator: '>', lang: 'ts'}]
|
|
1090
1143
|
* ```
|
|
1091
1144
|
*
|
|
1092
|
-
* @param
|
|
1093
|
-
* @
|
|
1094
|
-
* the last code block in the text is returned, irrespective of its language.
|
|
1095
|
-
* @returns The extracted code content as a {@link CodeString} instance (with `lang` and `meta` properties)
|
|
1096
|
-
* if a matching code block is found, or as the original `text` if no match is found.
|
|
1145
|
+
* @param lang - The selector string.
|
|
1146
|
+
* @returns An array of parsed selector parts.
|
|
1097
1147
|
*/
|
|
1098
|
-
declare function
|
|
1148
|
+
declare function parseCodeBlockSelector(lang?: string): CodeBlockSelectorPart[];
|
|
1099
1149
|
/**
|
|
1100
|
-
* Extracts fenced code block(s) from the input `text
|
|
1150
|
+
* Extracts fenced code block(s) from the input `text`, with support for nested path selectors.
|
|
1151
|
+
*
|
|
1152
|
+
* This function acts as a query engine for Markdown code blocks. It can extract
|
|
1153
|
+
* single blocks, multiple blocks, or drill down into nested structures using
|
|
1154
|
+
* CSS-like syntax.
|
|
1101
1155
|
*
|
|
1102
1156
|
* @example
|
|
1103
1157
|
* ```ts
|
|
1104
|
-
*
|
|
1105
|
-
*
|
|
1106
|
-
*
|
|
1107
|
-
* //
|
|
1108
|
-
* const
|
|
1158
|
+
* // Simple extraction (last block)
|
|
1159
|
+
* const code = extractCodeBlock(input, 'js');
|
|
1160
|
+
*
|
|
1161
|
+
* // Nested extraction
|
|
1162
|
+
* const inner = extractCodeBlock(input, 'md > ts');
|
|
1163
|
+
*
|
|
1164
|
+
* // Extract all matching blocks
|
|
1165
|
+
* const all = extractCodeBlock(input, { lang: 'container > item', all: true });
|
|
1109
1166
|
* ```
|
|
1110
1167
|
*
|
|
1111
|
-
* @param text - The input string
|
|
1112
|
-
* @param
|
|
1113
|
-
*
|
|
1114
|
-
*
|
|
1115
|
-
* - `all`: If `true`, returns an array of all matching blocks.
|
|
1116
|
-
* @returns If `options.all` is true, returns an array of {@link CodeString} or string.
|
|
1117
|
-
* Otherwise, returns a single {@link CodeString} or the original `text` if no match is found at the specified index.
|
|
1168
|
+
* @param text - The input string containing Markdown.
|
|
1169
|
+
* @param langOrOptions - Either a language/selector string or a full {@link ExtractCodeBlockOptions} object.
|
|
1170
|
+
* @returns A single {@link CodeString}, an array of {@link CodeString}s (if `all: true`),
|
|
1171
|
+
* or the original `text` if no matches are found at the specified index.
|
|
1118
1172
|
*/
|
|
1119
|
-
declare function extractCodeBlock(text: string,
|
|
1173
|
+
declare function extractCodeBlock(text: string, langOrOptions?: string | ExtractCodeBlockOptions): CodeString | string | (CodeString | string)[];
|
|
1120
1174
|
|
|
1121
|
-
export { BinarySemaphore, type BinarySemaphoreAcquireOptions, type BinarySemaphoreOptions, type BinarySemaphoreReleaseOptions, type BinarySemaphoreReleaserFunc, type CodeString, ConfigFile, DefaultAllTextFiles, DefaultAsyncSemaphoreCapacity, Deque, type ExtractCodeBlockOptions, FilenameReservedRegex, type IncludeFiles, IntSet, type LoadConfigFileOptions, RateLimit, type SanitizeFilenameOptions, Semaphore, type SemaphoreIsReadyFuncType, type SemaphoreOptions, type SemaphoreTaskItem, SignalGate, type StringifyFunc, type TraverseFolderHandler, type TraverseFolderSyncHandler, WindowsReservedNameRegex, arrayHasAll, extNameLevel, extractCodeBlock, filenameReservedRegex, findPort, getMultiLevelExtname, glob, isStringIn, isValidFilename, isValidFilepath, normalizeIncludeFiles, omitDeepBy, omitEmptyDeep, parseFrontMatter, parseYaml, reControlCharsRegex, registerYamlTag, removeLeadingEmptyLines, sanitizeFilename, sanitizeFilepath, sleep, stringifyYaml, toCamelCase, toCapitalCase, toPascalCase, traverseFolder, traverseFolderSync, yieldExec };
|
|
1175
|
+
export { BinarySemaphore, type BinarySemaphoreAcquireOptions, type BinarySemaphoreOptions, type BinarySemaphoreReleaseOptions, type BinarySemaphoreReleaserFunc, type CodeBlockCombinator, type CodeBlockSelectorPart, type CodeString, ConfigFile, DefaultAllTextFiles, DefaultAsyncSemaphoreCapacity, Deque, type ExtractCodeBlockOptions, FilenameReservedRegex, type FindPortOptions, type IncludeFiles, IntSet, type LoadConfigFileOptions, RateLimit, type SanitizeFilenameOptions, Semaphore, type SemaphoreIsReadyFuncType, type SemaphoreOptions, type SemaphoreTaskItem, SignalGate, type StringifyFunc, type TraverseFolderHandler, type TraverseFolderSyncHandler, WindowsReservedNameRegex, arrayHasAll, extNameLevel, extractCodeBlock, extractTopLevelCodeBlocks, filenameReservedRegex, findPort, getMultiLevelExtname, glob, isStringIn, isValidFilename, isValidFilepath, normalizeIncludeFiles, omitDeepBy, omitEmptyDeep, parseCodeBlockSelector, parseFrontMatter, parseYaml, reControlCharsRegex, registerYamlTag, removeLeadingEmptyLines, sanitizeFilename, sanitizeFilepath, sleep, stringifyYaml, toCamelCase, toCapitalCase, toPascalCase, traverseFolder, traverseFolderSync, yieldExec };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t,e=Object.create,i=Object.defineProperty,r=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,n=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,u=(t,e,n,u)=>{if(e&&"object"==typeof e||"function"==typeof e)for(let c of s(e))o.call(t,c)||c===n||i(t,c,{get:()=>e[c],enumerable:!(u=r(e,c))||u.enumerable});return t},c=(t,r,s)=>(s=null!=t?e(n(t)):{},u(!r&&t&&t.__esModule?s:i(s,"default",{value:t,enumerable:!0}),t)),a={};((t,e)=>{for(var r in e)i(t,r,{get:e[r],enumerable:!0})})(a,{BinarySemaphore:()=>lt,ConfigFile:()=>q,DefaultAllTextFiles:()=>R,DefaultAsyncSemaphoreCapacity:()=>at,Deque:()=>it,FilenameReservedRegex:()=>I,IntSet:()=>rt,RateLimit:()=>pt,Semaphore:()=>mt,SignalGate:()=>yt,WindowsReservedNameRegex:()=>_,arrayHasAll:()=>tt,extNameLevel:()=>X,extractCodeBlock:()=>qt,filenameReservedRegex:()=>W,findPort:()=>vt,getMultiLevelExtname:()=>p,glob:()=>A,isStringIn:()=>E,isValidFilename:()=>G,isValidFilepath:()=>H,normalizeIncludeFiles:()=>C,omitDeepBy:()=>bt,omitEmptyDeep:()=>Ft,parseFrontMatter:()=>F,parseYaml:()=>v,reControlCharsRegex:()=>Z,registerYamlTag:()=>g,removeLeadingEmptyLines:()=>b,sanitizeFilename:()=>K,sanitizeFilepath:()=>Q,sleep:()=>st,stringifyYaml:()=>w,toCamelCase:()=>M,toCapitalCase:()=>L,toPascalCase:()=>D,traverseFolder:()=>T,traverseFolderSync:()=>z,yieldExec:()=>nt}),module.exports=(t=a,u(i({},"__esModule",{value:!0}),t));var h=require("fs"),f=c(require("path")),l=require("load-config-file"),m=c(require("path"));function p(t,e=1){let i="";for(;e--;){const e=m.default.extname(t);if(!e)break;i=e+i,t=m.default.basename(t,e)}return i}var d=require("yaml"),y=[];function g(t){Array.isArray(t)||(t=[t]);for(const e of t){-1===y.indexOf(e)&&y.push(e)}}function v(t,e){if(e)if(e.customTags){if(Array.isArray(e.customTags))e.customTags=y.concat(e.customTags);else if("function"==typeof e.customTags){const t=e.customTags;e.customTags=e=>t(y.concat(e))}}else e.customTags=y;else e={customTags:y};return(0,d.parse)(t,e)}function w(t,e){if(e)if(e.customTags){if(Array.isArray(e.customTags))e.customTags=y.concat(e.customTags);else if("function"==typeof e.customTags){const t=e.customTags;e.customTags=e=>t(y.concat(e))}}else e.customTags=y;else e={customTags:y};return(0,d.stringify)(t,e)}function b(t){const e=/^\s*(#[^\r\n]*)?[\r\n]+/;let i;for(;null!==(i=e.exec(t))&&((t=t.substring(i[0].length)).startsWith("\n")||t.startsWith("\r")||t.trimStart().startsWith("#")););return t}var x="---";function F(t,e=x){const i=e.length,r=b(t);if(r.startsWith(e)&&("\n"===r[e.length]||"\r"===r[e.length])){let t=r.indexOf("\n"+e,i);if(-1!==t){const s=r.slice(i,t);for(t+=e.length+1;"\n"===r[t]||"\r"===r[t];)t++;const n=r.slice(t);return{data:v(s)||{},content:n}}}return{data:{},content:t}}var q=class{static register(t,e,i){l.Config.register(t,e),"string"==typeof t&&(t=[t]);for(const e of t)this.stringifys[e]=i}static loadSync(t,e){return function(t,{extLevel:e=1,externalFile:i}={}){t=S(t,e);let r=l.Config.loadSync(t);if(!r&&i){if(!f.default.isAbsolute(i)){const e=f.default.dirname(t);i=f.default.join(e,i)}if((0,h.existsSync)(i)){const t=F((0,h.readFileSync)(i,"utf8")).data;Object.keys(t).length&&(r=t)}}return r}(t,e)}static saveSync(t,e,i){return function(t,e,{extLevel:i=1}={}){const r=function(t,e=1){"."===t[0]&&e++;let i=p(t,e);(!i||i.split(".").length<=1)&&(t+=".yaml",i=".yaml");const r=new String(t);return r.extname=i,r}(t,i),s=r.extname;t=r.toString();const n=q.stringifys[s];if(!n)throw new Error(`${t} unsupported mime type: ${s}`);e=n(e);const o=f.default.dirname(t);(0,h.existsSync)(o)||(0,h.mkdirSync)(o,{recursive:!0});return(0,h.writeFileSync)(t,e,{encoding:"utf8"}),t}(t,e,i)}static existsSync(t,e){return t=S(t,e?.extLevel),l.Config.existsSync(t,e)}};function S(t,e=1){"."===t[0]&&e++;const i=p(t,e);return i&&i.split(".").length>1&&(t=t.slice(0,-i.length)),t}q.stringifys={},q.register([".yml",".yaml"],v,w),q.register([".json"],function(t){return JSON.parse(t)},t=>JSON.stringify(t,null,2));var k=require("@isdk/glob"),j=c(require("path"));function A(t,e,i){return i&&(t=j.default.relative(i,t)),(0,k.globMatch)(t,e)}function E(t,e){return"string"==typeof e&&(e=[e]),-1!==e.indexOf(t)}var R=["**/*.((j|t)s?(x)|m(j|t)s)?(x)","**/*.(md|markdown|txt|?(x)htm?(l)|yaml|yml|xml|json|bat|sh|bash|zsh|ini|css|scss|less|sass|py|rb|php|go|java|c|cpp|h|hpp|hxx|rust|zig)"];function C(t,e=[]){if(t)if(Array.isArray(t))t=[...t];else{const i=t.include||[],r=t.exclude||[];0===i.length&&i.push(...e),t=[...i];for(const e of r)t.push(`!${e}`)}else t=[...e];return 0===t.length&&t.push(...e),t}var O=require("fs/promises"),$=require("fs"),P=c(require("path"));async function T(t,e){const i=await(0,O.readdir)(t,{withFileTypes:!0});for(const r of i){const i=P.default.join(t,r.name);try{if(r.isDirectory()){await e(i,r)||await T(i,e)}else{if(!0===await e(i,r))break}}catch(t){console.error(`Error processing file: ${i}`),console.error(t)}}}function z(t,e){const i=(0,$.readdirSync)(t,{withFileTypes:!0});for(const r of i){const i=P.default.join(t,r.name);try{if(r.isDirectory()){e(i,r)||T(i,e)}else{if(!0===e(i,r))break}}catch(t){console.error(`Error processing file: ${i}`),console.error(t)}}}function D(t){if(!t)return"";return t.replace(/[-_ ]+/g," ").split(" ").filter(Boolean).map(t=>{let e=t.charAt(0).toUpperCase();t=t.slice(1);let i=0;for(;/[A-Z]/.test(t[i]);)i++;return e+=i?t.slice(0,i).toLowerCase()+t.slice(i):t,e}).join("")}function M(t){return(t=D(t)).charAt(0).toLowerCase()+t.slice(1)}function L(t){if(!t)return"";return t.replace(/[-_ ]+/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").split(" ").filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" ")}var N=c(require("path")),B=require("@isdk/common-error"),I=/[<>:"/\\|?*\u0000-\u001F]/,_=/^(con|prn|aux|nul|com\d|lpt\d)$/i,J=100,Y=/^\.+(\\|\/)|^\.+$/,U=/\.+$/,V=/[\u0000-\u001F\u0080-\u009F\u200E\u200F\u202A-\u202E\u2066-\u2069]/;function W(){return new RegExp(I.source,"g")}function Z(){return new RegExp(V.source,"g")}function G(t){return t&&!(I.test(t)||Z().test(t)||Y.test(t)||U.test(t))}function H(t){const e=t.split(N.default.sep);return("/"===t[0]||e[0]&&N.default.dirname(e[0])===e[0])&&e.shift(),e.every(G)}function K(t,e={}){const i=e.replacement||"!";if((I.test(i)||V.test(i))&&(0,B.throwError)("Replacement string cannot contain reserved filename characters","sanitizeFilename",B.ErrorCode.InvalidArgument),i.length>0){const e=/([<>:"/\\|?*\u0000-\u001F]){2,}/;t=t.replace(e,"$1")}if(t=(t=(t=(t=(t=t.normalize("NFD")).replace(Y,i)).replace(W(),i)).replace(Z(),i)).replace(U,""),i.length>0){"."===t[0]||"."!==t[0]||(t=i+t),"."===t[t.length-1]&&(t+=i)}t=_.test(t)?t+i:t;const r="number"==typeof e.maxLength?e.maxLength:J;if(t.length>r){const e=t.lastIndexOf(".");if(-1===e)t=t.slice(0,r);else{const i=t.slice(0,e),s=t.slice(e);t=i.slice(0,Math.max(1,r-s.length))+s}}return t}function Q(t,e={}){const i=t.split(N.default.sep);let r;("/"===t[0]||i[0]&&N.default.dirname(i[0])===i[0])&&(r=i.shift());const s=i.map(t=>K(t,e));return void 0!==r&&s.unshift(r),s.join(N.default.sep)}function X(t){return t.split(".").length-1}function tt(t,e){const i=new Set(e),r=new Set;for(const e of t)if(i.has(e)&&(r.add(e),r.size===i.size))return!0;return r.size===i.size}function et(t=0){return e=Math.min(Math.max(16,t),1073741824),e>>>=0,e-=1,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,1+(e|=e>>16);var e}var it=class extends Array{constructor(t,e){Array.isArray(t)?(super(...t),this._length=t.length,t=void 0):(super(),this._length=0),this._capacity=et(t),this._front=0,this._disableAutoResize=e}push(t){let e=this._length;this.checkCapacity(e+1);const i=this._front+e&this._capacity-1;return this[i]=t,++e<=this._capacity&&(this._length=e),i}unshift(t){let e=this._length;this.checkCapacity(++e);const i=this._capacity,r=(this._front-1&i-1^i)-i;return this[r]=t,this._front=r,e<=this._capacity&&(this._length=e),r}pop(t){let e=this._length;if(0===e)return;let i=this._front+e-1&this._capacity-1,r=this[i];for(;--e>0&&t&&null==r;)i--,r=this[i];return this[i]=void 0,this._length=e,r}shift(t){let e=this._length;if(0===e)return;let i=this._front,r=this[i];for(;--e>0&&t&&null==r;)i=i+1&this._capacity-1,r=this[i];return this[i]=void 0,this._front=i+1&this._capacity-1,this._length=e,r}get size(){return this._length}get(t){let e;if(t===(0|t)){const i=this._length;t<0&&(t+=i),t>=0&&t<i&&(e=this[this._front+t&this._capacity-1])}return e}peekBack(){const t=this._length;if(0===t)return;return this[this._front+t-1&this._capacity-1]}peekFront(){if(0!==this._length)return this[this._front]}clear(){const t=this._length,e=this._front,i=this._capacity;for(let r=0;r<t;++r)this[e+r&i-1]=void 0;this._length=0,this._front=0}isEmpty(){return 0===this._length}removeAt(t){const e=this._length;if(t<0||t>=e)return;const i=this._front,r=this._capacity-1,s=i+t&r,n=this[s];if(t<e/2)this.copyWithin(i+1&r,i,i+t&r),this[i]=void 0,this._front=i+1&r;else{this.copyWithin(s,s+1&r,i+e&r);this[i+e-1&r]=void 0}return this._length=e-1,n}checkCapacity(t){this._capacity<t&&!this._disableAutoResize&&this.resizeTo(et(1.5*this._capacity+16))}resizeTo(t){const e=this._capacity;this._capacity=t;const i=this._front,r=this._length;if(i+r>e){!function(t,e,i,r,s){for(let n=0;n<s;++n)i[n+r]=t[n+e],t[n+e]=void 0}(this,0,this,e,i+r&e-1)}}},rt=class t{constructor(t=0){this.bitField=t}static has(t,e){return!!(t&1<<e)}static add(t,e){return t|1<<e}static delete(t,e){return t&~(1<<e)}add(t){return this.bitField|=1<<t,this}delete(t){return this.bitField&=~(1<<t),this}has(e){return t.has(this.bitField,e)}clear(){return this.bitField=0,this}valueOf(){return this.bitField}toString(){return this.bitField.toString()}toJSON(){return this.bitField}};async function st(t){return new Promise(e=>setTimeout(e,t))}async function nt(){return new Promise(t=>{setImmediate(t)})}var ot=require("util-ex"),ut=require("events-ex"),ct=require("@isdk/common-error"),at=32;function ht(t){return"function"==typeof t}function ft(){return"1"}var lt=class{constructor(t={}){const{initFn:e=ft,pauseFn:i,resumeFn:r,capacity:s=at}=t;if(ht(i)!==ht(r))throw new Error("pauseFn and resumeFn must be both set for pausing");this.waiting=new it(s),this.emitter=new ut.EventEmitter,this.useDefaultTokens=e===ft,this.pauseFn=i,this.resumeFn=r,this.initTokenFn=e,this.paused=!1,this._activeCount=0,this.initFree(t),this.init(t)}initFree(t){this.free=this.initTokenFn()}onReleased(t){const e=t?.token,i=this.waiting.shift(!0);i?this._dispatchTask(i,t):(this.resumeFn&&this.paused&&(this.paused=!1,this.resumeFn()),this.unlock(e))}init(t){this.emitter.on("release",t=>{this.onReleased(t)})}_newReleaser(t){let e=!1;const i=()=>{e||(e=!0,this.release(t))};return t&&Object.assign(i,t),i}_dispatchTask(t,e){const{resolve:i}=t;i(this._newReleaser(e))}lock(t){const e=this.free;if(e)return this.free=void 0,e}unlock(t){this.free=this.useDefaultTokens?"1":t??this.initTokenFn()}tryAcquire(t){return this.lock(t)}async acquire(t){this._activeCount++;const e=t?.signal,i=t=>{this.pauseFn&&!this.paused&&(this.paused=!0,this.pauseFn());const i=this.waiting.push(t),r=t.reject;return e&&e.addEventListener("abort",()=>{this.waiting[i]=void 0;const t=e.reason instanceof Error?e.reason:new ct.AbortError(e.reason||"aborted");e.alreadyRejected=!0,r(t)}),i},r=this.tryAcquire(t),s=r&&(0,ot.isAsync)(r),n=e=>new Promise((r,s)=>{const n={...t,resolve:r,reject:s,token:e};void 0===e?i(n):this._dispatchTask(n,{...t,token:e})});return s?r.then(t=>n(t)):n(r)}release(t){this._activeCount--,this.emitter.emit("release",t)}drain(){const t=[this.acquire()];return Promise.all(t)}abort(t){let e;for(;e=this.waiting.shift(!0);)e.reject(new ct.AbortError(t))}get activeCount(){return this._activeCount}get pendingCount(){return this.waiting.size}},mt=class extends lt{constructor(t,e){if("number"==typeof t)(e=e||{}).maxConcurrency=t;else if("number"!=typeof(e=t).maxConcurrency)throw new Error("maxConcurrency must be set");super(e),this.maxConcurrency=e.maxConcurrency,e.isReadyFn&&(this.isReady=e.isReadyFn)}initFree(t){const e=t.maxConcurrency=Math.max(1,t.maxConcurrency);this.free=new it(e);for(let t=0;t<e;t++)this.free.push(this.initTokenFn())}tryAcquire(t){let e=this.isReady;if(e&&(0,ot.isAsync)(e)){return e instanceof Promise||(e=e()),e.then(e=>{if(e)return this.lock(t)})}if(!e||e())return this.lock(t)}unlock(t){this.free.push(this.useDefaultTokens?"1":t??this.initTokenFn())}lock(t){return this.free.pop()}drain(){const t=new Array(this.maxConcurrency);for(let e=0;e<this.maxConcurrency;e++)t[e]=this.acquire();return Promise.all(t)}};function pt(t,{timeUnit:e=1e3,uniformDistribution:i=!1}={}){const r=new mt(i?1:t),s=i?e/t:e;return async function(){await r.acquire(),setTimeout(()=>r.release(),s)}}var dt=require("@isdk/common-error"),yt=class{constructor(){this._isSignaled=!1,this.waitQueue=[]}get signaled(){return this._isSignaled}signal(t){if(this._isSignaled)return;this._isSignaled=!0,this._signalValue=t;const e=this.waitQueue.slice();for(this.waitQueue.length=0;e.length>0;){const t=e.shift();t?.resolve(this._signalValue)}}reset(){this._isSignaled=!1,this._signalValue=void 0,this.waitQueue.length=0}abort(t){if(this.waitQueue.length){const e=this.waitQueue.slice();this.waitQueue.length=0;const i=new dt.AbortError(t);for(;e.length>0;){const{reject:t}=e.shift();t(i)}}}async wait(){return new Promise((t,e)=>{this._isSignaled?t(this._signalValue):this.waitQueue.push({resolve:t,reject:e})})}},gt=c(require("net"));async function vt(t,e=10){return new Promise((i,r)=>{void 0===t?t=0:("string"==typeof t&&(t=parseInt(t)),t>=0||(t=0));const s=gt.default.createServer();s.on("error",i=>{"EADDRINUSE"===i.code&&(t++,--e>0)?s.listen(t):r(i)}),s.on("listening",async()=>{const t=s.address().port;s.close(e=>{e?r(e):i(t)})}),s.listen(t)})}var wt=require("lodash-es");function bt(t,e,i=new WeakMap){if(!(0,wt.isObject)(t)||(0,wt.isNil)(t))return t;if(i.has(t))return i.get(t);let r;if(Array.isArray(t)){r=[],i.set(t,r);const s=t.map(t=>bt(t,e,i)).filter((t,i)=>!e(t,i.toString()));return Object.assign(r,s),r.length>0?r:void 0}if((0,wt.isPlainObject)(t)){r={},i.set(t,r);const s=Reflect.ownKeys(t);for(const n of s){const s=bt(t[n],e,i);e(s,n)||(r[n]=s)}return(0,wt.isEmpty)(r)?void 0:r}return t}var xt=require("lodash-es");var Ft=(t,e)=>bt(t,t=>function(t){return!!(0,xt.isNil)(t)||"string"==typeof t&&0===t.trim().length||!(!(0,xt.isArray)(t)&&!(0,xt.isPlainObject)(t))&&(0,xt.isEmpty)(t)}(t)||e&&"function"==typeof t);function qt(t,e){const i="string"==typeof e?{lang:e}:e??{},{lang:r,index:s=-1,all:n}=i,o=t.trim(),u=/(```|~~~)(?<lang>\S*)[ \t]*(?<meta>\S*?)\n(?<code>[\s\S]*?)\1/gm,c=[];let a;for(;null!==(a=u.exec(o));){const t=a.groups?.lang?.toLowerCase();if(!r||r===t){let t=a.groups.code;if(a.groups.lang||a.groups.meta){const e=new String(t);a.groups.lang&&(e.lang=a.groups.lang.toLowerCase()),a.groups.meta&&(e.meta=a.groups.meta),t=e}else t=new String(t);c.push(t)}}if(n)return c;return c[s<0?c.length+s:s]??t}
|
|
1
|
+
"use strict";var t,e=Object.create,r=Object.defineProperty,n=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,i=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,c=(t,e,i,c)=>{if(e&&"object"==typeof e||"function"==typeof e)for(let u of s(e))o.call(t,u)||u===i||r(t,u,{get:()=>e[u],enumerable:!(c=n(e,u))||c.enumerable});return t},u=(t,n,s)=>(s=null!=t?e(i(t)):{},c(!n&&t&&t.__esModule?s:r(s,"default",{value:t,enumerable:!0}),t)),a={};((t,e)=>{for(var n in e)r(t,n,{get:e[n],enumerable:!0})})(a,{BinarySemaphore:()=>ft,ConfigFile:()=>F,DefaultAllTextFiles:()=>C,DefaultAsyncSemaphoreCapacity:()=>at,Deque:()=>rt,FilenameReservedRegex:()=>I,IntSet:()=>nt,RateLimit:()=>pt,Semaphore:()=>mt,SignalGate:()=>yt,WindowsReservedNameRegex:()=>_,arrayHasAll:()=>tt,extNameLevel:()=>X,extractCodeBlock:()=>Ct,extractTopLevelCodeBlocks:()=>qt,filenameReservedRegex:()=>V,findPort:()=>wt,getMultiLevelExtname:()=>p,glob:()=>q,isStringIn:()=>A,isValidFilename:()=>Z,isValidFilepath:()=>H,normalizeIncludeFiles:()=>R,omitDeepBy:()=>kt,omitEmptyDeep:()=>jt,parseCodeBlockSelector:()=>At,parseFrontMatter:()=>k,parseYaml:()=>v,reControlCharsRegex:()=>W,registerYamlTag:()=>g,removeLeadingEmptyLines:()=>b,sanitizeFilename:()=>K,sanitizeFilepath:()=>Q,sleep:()=>st,stringifyYaml:()=>w,toCamelCase:()=>D,toCapitalCase:()=>N,toPascalCase:()=>z,traverseFolder:()=>M,traverseFolderSync:()=>T,yieldExec:()=>it}),module.exports=(t=a,c(r({},"__esModule",{value:!0}),t));var h=require("fs"),l=u(require("path")),f=require("load-config-file"),m=u(require("path"));function p(t,e=1){let r="";for(;e--;){const e=m.default.extname(t);if(!e)break;r=e+r,t=m.default.basename(t,e)}return r}var d=require("yaml"),y=[];function g(t){Array.isArray(t)||(t=[t]);for(const e of t){-1===y.indexOf(e)&&y.push(e)}}function v(t,e){if(e)if(e.customTags){if(Array.isArray(e.customTags))e.customTags=y.concat(e.customTags);else if("function"==typeof e.customTags){const t=e.customTags;e.customTags=e=>t(y.concat(e))}}else e.customTags=y;else e={customTags:y};return(0,d.parse)(t,e)}function w(t,e){if(e)if(e.customTags){if(Array.isArray(e.customTags))e.customTags=y.concat(e.customTags);else if("function"==typeof e.customTags){const t=e.customTags;e.customTags=e=>t(y.concat(e))}}else e.customTags=y;else e={customTags:y};return(0,d.stringify)(t,e)}function b(t){const e=/^\s*(#[^\r\n]*)?[\r\n]+/;let r;for(;null!==(r=e.exec(t))&&((t=t.substring(r[0].length)).startsWith("\n")||t.startsWith("\r")||t.trimStart().startsWith("#")););return t}var x="---";function k(t,e=x){const r=e.length,n=b(t);if(n.startsWith(e)&&("\n"===n[e.length]||"\r"===n[e.length])){let t=n.indexOf("\n"+e,r);if(-1!==t){const s=n.slice(r,t);for(t+=e.length+1;"\n"===n[t]||"\r"===n[t];)t++;const i=n.slice(t);return{data:v(s)||{},content:i}}}return{data:{},content:t}}var F=class{static register(t,e,r){f.Config.register(t,e),"string"==typeof t&&(t=[t]);for(const e of t)this.stringifys[e]=r}static loadSync(t,e){return function(t,{extLevel:e=1,externalFile:r}={}){t=j(t,e);let n=f.Config.loadSync(t);if(!n&&r){if(!l.default.isAbsolute(r)){const e=l.default.dirname(t);r=l.default.join(e,r)}if((0,h.existsSync)(r)){const t=k((0,h.readFileSync)(r,"utf8")).data;Object.keys(t).length&&(n=t)}}return n}(t,e)}static saveSync(t,e,r){return function(t,e,{extLevel:r=1}={}){const n=function(t,e=1){"."===t[0]&&e++;let r=p(t,e);(!r||r.split(".").length<=1)&&(t+=".yaml",r=".yaml");const n=new String(t);return n.extname=r,n}(t,r),s=n.extname;t=n.toString();const i=F.stringifys[s];if(!i)throw new Error(`${t} unsupported mime type: ${s}`);e=i(e);const o=l.default.dirname(t);(0,h.existsSync)(o)||(0,h.mkdirSync)(o,{recursive:!0});return(0,h.writeFileSync)(t,e,{encoding:"utf8"}),t}(t,e,r)}static existsSync(t,e){return t=j(t,e?.extLevel),f.Config.existsSync(t,e)}};function j(t,e=1){"."===t[0]&&e++;const r=p(t,e);return r&&r.split(".").length>1&&(t=t.slice(0,-r.length)),t}F.stringifys={},F.register([".yml",".yaml"],v,w),F.register([".json"],function(t){return JSON.parse(t)},t=>JSON.stringify(t,null,2));var E=require("@isdk/glob"),S=u(require("path"));function q(t,e,r){return r&&(t=S.default.relative(r,t)),(0,E.globMatch)(t,e)}function A(t,e){return"string"==typeof e&&(e=[e]),-1!==e.indexOf(t)}var C=["**/*.((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 R(t,e=[]){if(t)if(Array.isArray(t))t=[...t];else{const r=t.include||[],n=t.exclude||[];0===r.length&&r.push(...e),t=[...r];for(const e of n)t.push(`!${e}`)}else t=[...e];return 0===t.length&&t.push(...e),t}var O=require("fs/promises"),P=require("fs"),$=u(require("path"));async function M(t,e){const r=await(0,O.readdir)(t,{withFileTypes:!0});for(const n of r){const r=$.default.join(t,n.name);try{if(n.isDirectory()){await e(r,n)||await M(r,e)}else{if(!0===await e(r,n))break}}catch(t){console.error(`Error processing file: ${r}`),console.error(t)}}}function T(t,e){const r=(0,P.readdirSync)(t,{withFileTypes:!0});for(const n of r){const r=$.default.join(t,n.name);try{if(n.isDirectory()){e(r,n)||M(r,e)}else{if(!0===e(r,n))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=>{let e=t.charAt(0).toUpperCase();t=t.slice(1);let r=0;for(;/[A-Z]/.test(t[r]);)r++;return e+=r?t.slice(0,r).toLowerCase()+t.slice(r):t,e}).join("")}function D(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(" ")}var B=u(require("path")),L=require("@isdk/common-error"),I=/[<>:"/\\|?*\u0000-\u001F]/,_=/^(con|prn|aux|nul|com\d|lpt\d)$/i,J=100,Y=/^\.+(\\|\/)|^\.+$/,G=/\.+$/,U=/[\u0000-\u001F\u0080-\u009F\u200E\u200F\u202A-\u202E\u2066-\u2069]/;function V(){return new RegExp(I.source,"g")}function W(){return new RegExp(U.source,"g")}function Z(t){return t&&!(I.test(t)||W().test(t)||Y.test(t)||G.test(t))}function H(t){const e=t.split(B.default.sep);return("/"===t[0]||e[0]&&B.default.dirname(e[0])===e[0])&&e.shift(),e.every(Z)}function K(t,e={}){const r=e.replacement||"!";if((I.test(r)||U.test(r))&&(0,L.throwError)("Replacement string cannot contain reserved filename characters","sanitizeFilename",L.ErrorCode.InvalidArgument),r.length>0){const e=/([<>:"/\\|?*\u0000-\u001F]){2,}/;t=t.replace(e,"$1")}if(t=(t=(t=(t=(t=t.normalize("NFD")).replace(Y,r)).replace(V(),r)).replace(W(),r)).replace(G,""),r.length>0){"."===t[0]||"."!==t[0]||(t=r+t),"."===t[t.length-1]&&(t+=r)}t=_.test(t)?t+r:t;const n="number"==typeof e.maxLength?e.maxLength:J;if(t.length>n){const e=t.lastIndexOf(".");if(-1===e)t=t.slice(0,n);else{const r=t.slice(0,e),s=t.slice(e);t=r.slice(0,Math.max(1,n-s.length))+s}}return t}function Q(t,e={}){const r=t.split(B.default.sep);let n;("/"===t[0]||r[0]&&B.default.dirname(r[0])===r[0])&&(n=r.shift());const s=r.map(t=>K(t,e));return void 0!==n&&s.unshift(n),s.join(B.default.sep)}function X(t){return t.split(".").length-1}function tt(t,e){const r=new Set(e),n=new Set;for(const e of t)if(r.has(e)&&(n.add(e),n.size===r.size))return!0;return n.size===r.size}function et(t=0){return e=Math.min(Math.max(16,t),1073741824),e>>>=0,e-=1,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,1+(e|=e>>16);var e}var rt=class extends Array{constructor(t,e){Array.isArray(t)?(super(...t),this._length=t.length,t=void 0):(super(),this._length=0),this._capacity=et(t),this._front=0,this._disableAutoResize=e}push(t){let e=this._length;this.checkCapacity(e+1);const r=this._front+e&this._capacity-1;return this[r]=t,++e<=this._capacity&&(this._length=e),r}unshift(t){let e=this._length;this.checkCapacity(++e);const r=this._capacity,n=(this._front-1&r-1^r)-r;return this[n]=t,this._front=n,e<=this._capacity&&(this._length=e),n}pop(t){let e=this._length;if(0===e)return;let r=this._front+e-1&this._capacity-1,n=this[r];for(;--e>0&&t&&null==n;)r--,n=this[r];return this[r]=void 0,this._length=e,n}shift(t){let e=this._length;if(0===e)return;let r=this._front,n=this[r];for(;--e>0&&t&&null==n;)r=r+1&this._capacity-1,n=this[r];return this[r]=void 0,this._front=r+1&this._capacity-1,this._length=e,n}get size(){return this._length}get(t){let e;if(t===(0|t)){const r=this._length;t<0&&(t+=r),t>=0&&t<r&&(e=this[this._front+t&this._capacity-1])}return e}peekBack(){const t=this._length;if(0===t)return;return this[this._front+t-1&this._capacity-1]}peekFront(){if(0!==this._length)return this[this._front]}clear(){const t=this._length,e=this._front,r=this._capacity;for(let n=0;n<t;++n)this[e+n&r-1]=void 0;this._length=0,this._front=0}isEmpty(){return 0===this._length}removeAt(t){const e=this._length;if(t<0||t>=e)return;const r=this._front,n=this._capacity-1,s=r+t&n,i=this[s];if(t<e/2)this.copyWithin(r+1&n,r,r+t&n),this[r]=void 0,this._front=r+1&n;else{this.copyWithin(s,s+1&n,r+e&n);this[r+e-1&n]=void 0}return this._length=e-1,i}checkCapacity(t){this._capacity<t&&!this._disableAutoResize&&this.resizeTo(et(1.5*this._capacity+16))}resizeTo(t){const e=this._capacity;this._capacity=t;const r=this._front,n=this._length;if(r+n>e){!function(t,e,r,n,s){for(let i=0;i<s;++i)r[i+n]=t[i+e],t[i+e]=void 0}(this,0,this,e,r+n&e-1)}}},nt=class t{constructor(t=0){this.bitField=t}static has(t,e){return!!(t&1<<e)}static add(t,e){return t|1<<e}static delete(t,e){return t&~(1<<e)}add(t){return this.bitField|=1<<t,this}delete(t){return this.bitField&=~(1<<t),this}has(e){return t.has(this.bitField,e)}clear(){return this.bitField=0,this}valueOf(){return this.bitField}toString(){return this.bitField.toString()}toJSON(){return this.bitField}};async function st(t){return new Promise(e=>setTimeout(e,t))}async function it(){return new Promise(t=>{setImmediate(t)})}var ot=require("util-ex"),ct=require("events-ex"),ut=require("@isdk/common-error"),at=32;function ht(t){return"function"==typeof t}function lt(){return"1"}var ft=class{constructor(t={}){const{initFn:e=lt,pauseFn:r,resumeFn:n,capacity:s=at}=t;if(ht(r)!==ht(n))throw new Error("pauseFn and resumeFn must be both set for pausing");this.waiting=new rt(s),this.emitter=new ct.EventEmitter,this.useDefaultTokens=e===lt,this.pauseFn=r,this.resumeFn=n,this.initTokenFn=e,this.paused=!1,this._activeCount=0,this.initFree(t),this.init(t)}initFree(t){this.free=this.initTokenFn()}onReleased(t){const e=t?.token,r=this.waiting.shift(!0);r?this._dispatchTask(r,t):(this.resumeFn&&this.paused&&(this.paused=!1,this.resumeFn()),this.unlock(e))}init(t){this.emitter.on("release",t=>{this.onReleased(t)})}_newReleaser(t){let e=!1;const r=()=>{e||(e=!0,this.release(t))};return t&&Object.assign(r,t),r}_dispatchTask(t,e){const{resolve:r}=t;r(this._newReleaser(e))}lock(t){const e=this.free;if(e)return this.free=void 0,e}unlock(t){this.free=this.useDefaultTokens?"1":t??this.initTokenFn()}tryAcquire(t){return this.lock(t)}async acquire(t){this._activeCount++;const e=t?.signal,r=t=>{this.pauseFn&&!this.paused&&(this.paused=!0,this.pauseFn());const r=this.waiting.push(t),n=t.reject;return e&&e.addEventListener("abort",()=>{this.waiting[r]=void 0;const t=e.reason instanceof Error?e.reason:new ut.AbortError(e.reason||"aborted");e.alreadyRejected=!0,n(t)}),r},n=this.tryAcquire(t),s=n&&(0,ot.isAsync)(n),i=e=>new Promise((n,s)=>{const i={...t,resolve:n,reject:s,token:e};void 0===e?r(i):this._dispatchTask(i,{...t,token:e})});return s?n.then(t=>i(t)):i(n)}release(t){this._activeCount--,this.emitter.emit("release",t)}drain(){const t=[this.acquire()];return Promise.all(t)}abort(t){let e;for(;e=this.waiting.shift(!0);)e.reject(new ut.AbortError(t))}get activeCount(){return this._activeCount}get pendingCount(){return this.waiting.size}},mt=class extends ft{constructor(t,e){if("number"==typeof t)(e=e||{}).maxConcurrency=t;else if("number"!=typeof(e=t).maxConcurrency)throw new Error("maxConcurrency must be set");super(e),this.maxConcurrency=e.maxConcurrency,e.isReadyFn&&(this.isReady=e.isReadyFn)}initFree(t){const e=t.maxConcurrency=Math.max(1,t.maxConcurrency);this.free=new rt(e);for(let t=0;t<e;t++)this.free.push(this.initTokenFn())}tryAcquire(t){let e=this.isReady;if(e&&(0,ot.isAsync)(e)){return e instanceof Promise||(e=e()),e.then(e=>{if(e)return this.lock(t)})}if(!e||e())return this.lock(t)}unlock(t){this.free.push(this.useDefaultTokens?"1":t??this.initTokenFn())}lock(t){return this.free.pop()}drain(){const t=new Array(this.maxConcurrency);for(let e=0;e<this.maxConcurrency;e++)t[e]=this.acquire();return Promise.all(t)}};function pt(t,{timeUnit:e=1e3,uniformDistribution:r=!1}={}){const n=new mt(r?1:t),s=r?e/t:e;return async function(){await n.acquire(),setTimeout(()=>n.release(),s)}}var dt=require("@isdk/common-error"),yt=class{constructor(){this._isSignaled=!1,this.waitQueue=[]}get signaled(){return this._isSignaled}signal(t){if(this._isSignaled)return;this._isSignaled=!0,this._signalValue=t;const e=this.waitQueue.slice();for(this.waitQueue.length=0;e.length>0;){const t=e.shift();t?.resolve(this._signalValue)}}reset(){this._isSignaled=!1,this._signalValue=void 0,this.waitQueue.length=0}abort(t){if(this.waitQueue.length){const e=this.waitQueue.slice();this.waitQueue.length=0;const r=new dt.AbortError(t);for(;e.length>0;){const{reject:t}=e.shift();t(r)}}}async wait(){return new Promise((t,e)=>{this._isSignaled?t(this._signalValue):this.waitQueue.push({resolve:t,reject:e})})}},gt=u(require("net")),vt=Promise.resolve();async function wt(t,e){const r=await(vt=vt.catch(()=>{}).then(()=>async function(t,e){let r,n,s=10;"number"==typeof e?s=e:e&&"object"==typeof e&&(s=e.retryCount??10,r=e.host);if(void 0===t)n=0;else if(n="string"==typeof t?parseInt(t,10):Math.floor(t),n>=0||(n=0),n>65535)throw new Error("Port out of range: "+n);for(let t=0;t<=s;t++)try{return await bt(n,r)}catch(e){if(t===s)throw e;const r="EACCES"===e.code||"EPERM"===e.code,i="EADDRINUSE"===e.code;if(!r&&!i)throw e;if(r&&n<1024?n=1024:n++,n>65535)throw new Error("No available ports found up to 65535")}throw new Error("No available ports found")}(t,e)));return r}function bt(t,e){return new Promise((r,n)=>{const s=gt.default.createServer();s.unref(),s.on("error",t=>{s.close(()=>n(t))}),s.listen(t,e,()=>{const t=s.address().port;s.close(e=>{e?n(e):r(t)})})})}var xt=require("lodash-es");function kt(t,e,r=new WeakMap){if(!(0,xt.isObject)(t)||(0,xt.isNil)(t))return t;if(r.has(t))return r.get(t);let n;if(Array.isArray(t)){n=[],r.set(t,n);const s=t.map(t=>kt(t,e,r)).filter((t,r)=>!e(t,r.toString()));return Object.assign(n,s),n.length>0?n:void 0}if((0,xt.isPlainObject)(t)){n={},r.set(t,n);const s=Reflect.ownKeys(t);for(const i of s){const s=kt(t[i],e,r);e(s,i)||(n[i]=s)}return(0,xt.isEmpty)(n)?void 0:n}return t}var Ft=require("lodash-es");var jt=(t,e)=>kt(t,t=>function(t){return!!(0,Ft.isNil)(t)||"string"==typeof t&&0===t.trim().length||!(!(0,Ft.isArray)(t)&&!(0,Ft.isPlainObject)(t))&&(0,Ft.isEmpty)(t)}(t)||e&&"function"==typeof t),Et={javascript:"js",jsx:"js",typescript:"ts",tsx:"ts",markdown:"md",python:"py",ruby:"rb",bash:"sh",zsh:"sh",shell:"sh",yaml:"yml",golang:"go",rust:"rs","c#":"cs",csharp:"cs","c++":"cpp"};function St(t,e){if(!t)return t;const r=t.toLowerCase();return e&&r in e?e[r]:Et[r]||r}function qt(t,e={}){const{lang:r,langMap:n}=e,s=St(r,n),i=/^[ \t]*(?<fence>`{3,}|~{3,})(?<lang>\S*)[ \t]*(?<meta>\S*?)\n(?<code>[\s\S]+?\n)?[ \t]*\k<fence>$/gm,o=[];let c;for(i.lastIndex=0;null!==(c=i.exec(t));){const t=c.groups?.lang?.toLowerCase();if(!s||s===St(t,n)){const t=c.groups.code||"",e=new String(t);c.groups.lang&&(e.lang=c.groups.lang.toLowerCase()),c.groups.meta&&(e.meta=c.groups.meta),o.push(e)}}return o}function At(t){if(!t)return[];const e=[],r=/([>+~])?\s*([^\s>+~]+)/g;let n;for(;null!==(n=r.exec(t));){const t=n[1]||" ",r=n[2];e.push({combinator:t,lang:r})}return e}function Ct(t,e){const r="string"==typeof e?{lang:e}:e??{},{index:n=-1,all:s}=r,i=At(r.lang);let o=[];if(0===i.length)o=qt(t,r);else{let e=[t];for(let t=0;t<i.length;t++){const{combinator:n,lang:s}=i[t],c=t===i.length-1,u=[],a=0===t&&" "===n?">":n;for(const t of e){let e=[];switch(a){case">":e=qt(t,{...r,lang:s,all:!0});break;case" ":console.warn('Descendant selector " " is not implemented yet.');break;case"+":console.warn('Adjacent sibling selector "+" is not implemented yet.');break;case"~":console.warn('General sibling selector "~" is not implemented yet.')}u.push(...e)}if(c)o=u;else if(e=u.map(t=>t.toString()),0===e.length)break}}if(s)return o;const c=o[n<0?o.length+n:n];return void 0!==c?c:t}
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as t,mkdirSync as s,readFileSync as i,writeFileSync as r}from"fs";import n from"path";import{Config as e}from"load-config-file";import o from"path";function c(t,s=1){let i="";for(;s--;){const s=o.extname(t);if(!s)break;i=s+i,t=o.basename(t,s)}return i}import{parse as h,stringify as u}from"yaml";var f=[];function a(t){Array.isArray(t)||(t=[t]);for(const s of t){-1===f.indexOf(s)&&f.push(s)}}function l(t,s){if(s)if(s.customTags){if(Array.isArray(s.customTags))s.customTags=f.concat(s.customTags);else if("function"==typeof s.customTags){const t=s.customTags;s.customTags=s=>t(f.concat(s))}}else s.customTags=f;else s={customTags:f};return h(t,s)}function m(t,s){if(s)if(s.customTags){if(Array.isArray(s.customTags))s.customTags=f.concat(s.customTags);else if("function"==typeof s.customTags){const t=s.customTags;s.customTags=s=>t(f.concat(s))}}else s.customTags=f;else s={customTags:f};return u(t,s)}function p(t){const s=/^\s*(#[^\r\n]*)?[\r\n]+/;let i;for(;null!==(i=s.exec(t))&&((t=t.substring(i[0].length)).startsWith("\n")||t.startsWith("\r")||t.trimStart().startsWith("#")););return t}function d(t,s="---"){const i=s.length,r=p(t);if(r.startsWith(s)&&("\n"===r[s.length]||"\r"===r[s.length])){let t=r.indexOf("\n"+s,i);if(-1!==t){const n=r.slice(i,t);for(t+=s.length+1;"\n"===r[t]||"\r"===r[t];)t++;const e=r.slice(t);return{data:l(n)||{},content:e}}}return{data:{},content:t}}var y=class{static register(t,s,i){e.register(t,s),"string"==typeof t&&(t=[t]);for(const s of t)this.stringifys[s]=i}static loadSync(s,r){return function(s,{extLevel:r=1,externalFile:o}={}){s=g(s,r);let c=e.loadSync(s);if(!c&&o){if(!n.isAbsolute(o)){const t=n.dirname(s);o=n.join(t,o)}if(t(o)){const t=d(i(o,"utf8")).data;Object.keys(t).length&&(c=t)}}return c}(s,r)}static saveSync(i,e,o){return function(i,e,{extLevel:o=1}={}){const h=function(t,s=1){"."===t[0]&&s++;let i=c(t,s);(!i||i.split(".").length<=1)&&(t+=".yaml",i=".yaml");const r=new String(t);return r.extname=i,r}(i,o),u=h.extname;i=h.toString();const f=y.stringifys[u];if(!f)throw new Error(`${i} unsupported mime type: ${u}`);e=f(e);const a=n.dirname(i);t(a)||s(a,{recursive:!0});return r(i,e,{encoding:"utf8"}),i}(i,e,o)}static existsSync(t,s){return t=g(t,s?.extLevel),e.existsSync(t,s)}};function g(t,s=1){"."===t[0]&&s++;const i=c(t,s);return i&&i.split(".").length>1&&(t=t.slice(0,-i.length)),t}y.stringifys={},y.register([".yml",".yaml"],l,m),y.register([".json"],function(t){return JSON.parse(t)},t=>JSON.stringify(t,null,2));import{globMatch as v}from"@isdk/glob";import w from"path";function b(t,s,i){return i&&(t=w.relative(i,t)),v(t,s)}function x(t,s){return"string"==typeof s&&(s=[s]),-1!==s.indexOf(t)}var k=["**/*.((j|t)s?(x)|m(j|t)s)?(x)","**/*.(md|markdown|txt|?(x)htm?(l)|yaml|yml|xml|json|bat|sh|bash|zsh|ini|css|scss|less|sass|py|rb|php|go|java|c|cpp|h|hpp|hxx|rust|zig)"];function F(t,s=[]){if(t)if(Array.isArray(t))t=[...t];else{const i=t.include||[],r=t.exclude||[];0===i.length&&i.push(...s),t=[...i];for(const s of r)t.push(`!${s}`)}else t=[...s];return 0===t.length&&t.push(...s),t}import{readdir as A}from"fs/promises";import{readdirSync as S}from"fs";import E from"path";async function j(t,s){const i=await A(t,{withFileTypes:!0});for(const r of i){const i=E.join(t,r.name);try{if(r.isDirectory()){await s(i,r)||await j(i,s)}else{if(!0===await s(i,r))break}}catch(t){console.error(`Error processing file: ${i}`),console.error(t)}}}function $(t,s){const i=S(t,{withFileTypes:!0});for(const r of i){const i=E.join(t,r.name);try{if(r.isDirectory()){s(i,r)||j(i,s)}else{if(!0===s(i,r))break}}catch(t){console.error(`Error processing file: ${i}`),console.error(t)}}}function P(t){if(!t)return"";return t.replace(/[-_ ]+/g," ").split(" ").filter(Boolean).map(t=>{let s=t.charAt(0).toUpperCase();t=t.slice(1);let i=0;for(;/[A-Z]/.test(t[i]);)i++;return s+=i?t.slice(0,i).toLowerCase()+t.slice(i):t,s}).join("")}function O(t){return(t=P(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 R from"path";import{ErrorCode as z,throwError as N}from"@isdk/common-error";var C=/[<>:"/\\|?*\u0000-\u001F]/,M=/^(con|prn|aux|nul|com\d|lpt\d)$/i,D=/^\.+(\\|\/)|^\.+$/,_=/\.+$/,q=/[\u0000-\u001F\u0080-\u009F\u200E\u200F\u202A-\u202E\u2066-\u2069]/;function B(){return new RegExp(C.source,"g")}function I(){return new RegExp(q.source,"g")}function J(t){return t&&!(C.test(t)||I().test(t)||D.test(t)||_.test(t))}function L(t){const s=t.split(R.sep);return("/"===t[0]||s[0]&&R.dirname(s[0])===s[0])&&s.shift(),s.every(J)}function U(t,s={}){const i=s.replacement||"!";if((C.test(i)||q.test(i))&&N("Replacement string cannot contain reserved filename characters","sanitizeFilename",z.InvalidArgument),i.length>0){const s=/([<>:"/\\|?*\u0000-\u001F]){2,}/;t=t.replace(s,"$1")}if(t=(t=(t=(t=(t=t.normalize("NFD")).replace(D,i)).replace(B(),i)).replace(I(),i)).replace(_,""),i.length>0){"."===t[0]||"."!==t[0]||(t=i+t),"."===t[t.length-1]&&(t+=i)}t=M.test(t)?t+i:t;const r="number"==typeof s.maxLength?s.maxLength:100;if(t.length>r){const s=t.lastIndexOf(".");if(-1===s)t=t.slice(0,r);else{const i=t.slice(0,s),n=t.slice(s);t=i.slice(0,Math.max(1,r-n.length))+n}}return t}function Z(t,s={}){const i=t.split(R.sep);let r;("/"===t[0]||i[0]&&R.dirname(i[0])===i[0])&&(r=i.shift());const n=i.map(t=>U(t,s));return void 0!==r&&n.unshift(r),n.join(R.sep)}function W(t){return t.split(".").length-1}function G(t,s){const i=new Set(s),r=new Set;for(const s of t)if(i.has(s)&&(r.add(s),r.size===i.size))return!0;return r.size===i.size}function H(t=0){return s=Math.min(Math.max(16,t),1073741824),s>>>=0,s-=1,s|=s>>1,s|=s>>2,s|=s>>4,s|=s>>8,1+(s|=s>>16);var s}var K=class extends Array{constructor(t,s){Array.isArray(t)?(super(...t),this._length=t.length,t=void 0):(super(),this._length=0),this._capacity=H(t),this._front=0,this._disableAutoResize=s}push(t){let s=this._length;this.checkCapacity(s+1);const i=this._front+s&this._capacity-1;return this[i]=t,++s<=this._capacity&&(this._length=s),i}unshift(t){let s=this._length;this.checkCapacity(++s);const i=this._capacity,r=(this._front-1&i-1^i)-i;return this[r]=t,this._front=r,s<=this._capacity&&(this._length=s),r}pop(t){let s=this._length;if(0===s)return;let i=this._front+s-1&this._capacity-1,r=this[i];for(;--s>0&&t&&null==r;)i--,r=this[i];return this[i]=void 0,this._length=s,r}shift(t){let s=this._length;if(0===s)return;let i=this._front,r=this[i];for(;--s>0&&t&&null==r;)i=i+1&this._capacity-1,r=this[i];return this[i]=void 0,this._front=i+1&this._capacity-1,this._length=s,r}get size(){return this._length}get(t){let s;if(t===(0|t)){const i=this._length;t<0&&(t+=i),t>=0&&t<i&&(s=this[this._front+t&this._capacity-1])}return s}peekBack(){const t=this._length;if(0===t)return;return this[this._front+t-1&this._capacity-1]}peekFront(){if(0!==this._length)return this[this._front]}clear(){const t=this._length,s=this._front,i=this._capacity;for(let r=0;r<t;++r)this[s+r&i-1]=void 0;this._length=0,this._front=0}isEmpty(){return 0===this._length}removeAt(t){const s=this._length;if(t<0||t>=s)return;const i=this._front,r=this._capacity-1,n=i+t&r,e=this[n];if(t<s/2)this.copyWithin(i+1&r,i,i+t&r),this[i]=void 0,this._front=i+1&r;else{this.copyWithin(n,n+1&r,i+s&r);this[i+s-1&r]=void 0}return this._length=s-1,e}checkCapacity(t){this._capacity<t&&!this._disableAutoResize&&this.resizeTo(H(1.5*this._capacity+16))}resizeTo(t){const s=this._capacity;this._capacity=t;const i=this._front,r=this._length;if(i+r>s){!function(t,s,i,r,n){for(let e=0;e<n;++e)i[e+r]=t[e+s],t[e+s]=void 0}(this,0,this,s,i+r&s-1)}}},Q=class t{constructor(t=0){this.bitField=t}static has(t,s){return!!(t&1<<s)}static add(t,s){return t|1<<s}static delete(t,s){return t&~(1<<s)}add(t){return this.bitField|=1<<t,this}delete(t){return this.bitField&=~(1<<t),this}has(s){return t.has(this.bitField,s)}clear(){return this.bitField=0,this}valueOf(){return this.bitField}toString(){return this.bitField.toString()}toJSON(){return this.bitField}};async function V(t){return new Promise(s=>setTimeout(s,t))}async function X(){return new Promise(t=>{setImmediate(t)})}import{isAsync as Y}from"util-ex";import{EventEmitter as tt}from"events-ex";import{AbortError as st}from"@isdk/common-error";var it=32;function rt(t){return"function"==typeof t}function nt(){return"1"}var et=class{constructor(t={}){const{initFn:s=nt,pauseFn:i,resumeFn:r,capacity:n=it}=t;if(rt(i)!==rt(r))throw new Error("pauseFn and resumeFn must be both set for pausing");this.waiting=new K(n),this.emitter=new tt,this.useDefaultTokens=s===nt,this.pauseFn=i,this.resumeFn=r,this.initTokenFn=s,this.paused=!1,this._activeCount=0,this.initFree(t),this.init(t)}initFree(t){this.free=this.initTokenFn()}onReleased(t){const s=t?.token,i=this.waiting.shift(!0);i?this._dispatchTask(i,t):(this.resumeFn&&this.paused&&(this.paused=!1,this.resumeFn()),this.unlock(s))}init(t){this.emitter.on("release",t=>{this.onReleased(t)})}_newReleaser(t){let s=!1;const i=()=>{s||(s=!0,this.release(t))};return t&&Object.assign(i,t),i}_dispatchTask(t,s){const{resolve:i}=t;i(this._newReleaser(s))}lock(t){const s=this.free;if(s)return this.free=void 0,s}unlock(t){this.free=this.useDefaultTokens?"1":t??this.initTokenFn()}tryAcquire(t){return this.lock(t)}async acquire(t){this._activeCount++;const s=t?.signal,i=t=>{this.pauseFn&&!this.paused&&(this.paused=!0,this.pauseFn());const i=this.waiting.push(t),r=t.reject;return s&&s.addEventListener("abort",()=>{this.waiting[i]=void 0;const t=s.reason instanceof Error?s.reason:new st(s.reason||"aborted");s.alreadyRejected=!0,r(t)}),i},r=this.tryAcquire(t),n=r&&Y(r),e=s=>new Promise((r,n)=>{const e={...t,resolve:r,reject:n,token:s};void 0===s?i(e):this._dispatchTask(e,{...t,token:s})});return n?r.then(t=>e(t)):e(r)}release(t){this._activeCount--,this.emitter.emit("release",t)}drain(){const t=[this.acquire()];return Promise.all(t)}abort(t){let s;for(;s=this.waiting.shift(!0);)s.reject(new st(t))}get activeCount(){return this._activeCount}get pendingCount(){return this.waiting.size}},ot=class extends et{constructor(t,s){if("number"==typeof t)(s=s||{}).maxConcurrency=t;else if("number"!=typeof(s=t).maxConcurrency)throw new Error("maxConcurrency must be set");super(s),this.maxConcurrency=s.maxConcurrency,s.isReadyFn&&(this.isReady=s.isReadyFn)}initFree(t){const s=t.maxConcurrency=Math.max(1,t.maxConcurrency);this.free=new K(s);for(let t=0;t<s;t++)this.free.push(this.initTokenFn())}tryAcquire(t){let s=this.isReady;if(s&&Y(s)){return s instanceof Promise||(s=s()),s.then(s=>{if(s)return this.lock(t)})}if(!s||s())return this.lock(t)}unlock(t){this.free.push(this.useDefaultTokens?"1":t??this.initTokenFn())}lock(t){return this.free.pop()}drain(){const t=new Array(this.maxConcurrency);for(let s=0;s<this.maxConcurrency;s++)t[s]=this.acquire();return Promise.all(t)}};function ct(t,{timeUnit:s=1e3,uniformDistribution:i=!1}={}){const r=new ot(i?1:t),n=i?s/t:s;return async function(){await r.acquire(),setTimeout(()=>r.release(),n)}}import{AbortError as ht}from"@isdk/common-error";var ut=class{constructor(){this._isSignaled=!1,this.waitQueue=[]}get signaled(){return this._isSignaled}signal(t){if(this._isSignaled)return;this._isSignaled=!0,this._signalValue=t;const s=this.waitQueue.slice();for(this.waitQueue.length=0;s.length>0;){const t=s.shift();t?.resolve(this._signalValue)}}reset(){this._isSignaled=!1,this._signalValue=void 0,this.waitQueue.length=0}abort(t){if(this.waitQueue.length){const s=this.waitQueue.slice();this.waitQueue.length=0;const i=new ht(t);for(;s.length>0;){const{reject:t}=s.shift();t(i)}}}async wait(){return new Promise((t,s)=>{this._isSignaled?t(this._signalValue):this.waitQueue.push({resolve:t,reject:s})})}};import ft from"net";async function at(t,s=10){return new Promise((i,r)=>{void 0===t?t=0:("string"==typeof t&&(t=parseInt(t)),t>=0||(t=0));const n=ft.createServer();n.on("error",i=>{"EADDRINUSE"===i.code&&(t++,--s>0)?n.listen(t):r(i)}),n.on("listening",async()=>{const t=n.address().port;n.close(s=>{s?r(s):i(t)})}),n.listen(t)})}import{isEmpty as lt,isNil as mt,isObject as pt,isPlainObject as dt}from"lodash-es";function yt(t,s,i=new WeakMap){if(!pt(t)||mt(t))return t;if(i.has(t))return i.get(t);let r;if(Array.isArray(t)){r=[],i.set(t,r);const n=t.map(t=>yt(t,s,i)).filter((t,i)=>!s(t,i.toString()));return Object.assign(r,n),r.length>0?r:void 0}if(dt(t)){r={},i.set(t,r);const n=Reflect.ownKeys(t);for(const e of n){const n=yt(t[e],s,i);s(n,e)||(r[e]=n)}return lt(r)?void 0:r}return t}import{isArray as gt,isEmpty as vt,isNil as wt,isPlainObject as bt}from"lodash-es";var xt=(t,s)=>yt(t,t=>function(t){return!!wt(t)||"string"==typeof t&&0===t.trim().length||!(!gt(t)&&!bt(t))&&vt(t)}(t)||s&&"function"==typeof t);function kt(t,s){const i="string"==typeof s?{lang:s}:s??{},{lang:r,index:n=-1,all:e}=i,o=t.trim(),c=/(```|~~~)(?<lang>\S*)[ \t]*(?<meta>\S*?)\n(?<code>[\s\S]*?)\1/gm,h=[];let u;for(;null!==(u=c.exec(o));){const t=u.groups?.lang?.toLowerCase();if(!r||r===t){let t=u.groups.code;if(u.groups.lang||u.groups.meta){const s=new String(t);u.groups.lang&&(s.lang=u.groups.lang.toLowerCase()),u.groups.meta&&(s.meta=u.groups.meta),t=s}else t=new String(t);h.push(t)}}if(e)return h;return h[n<0?h.length+n:n]??t}export{et as BinarySemaphore,y as ConfigFile,k as DefaultAllTextFiles,it as DefaultAsyncSemaphoreCapacity,K as Deque,C as FilenameReservedRegex,Q as IntSet,ct as RateLimit,ot as Semaphore,ut as SignalGate,M as WindowsReservedNameRegex,G as arrayHasAll,W as extNameLevel,kt as extractCodeBlock,B as filenameReservedRegex,at as findPort,c as getMultiLevelExtname,b as glob,x as isStringIn,J as isValidFilename,L as isValidFilepath,F as normalizeIncludeFiles,yt as omitDeepBy,xt as omitEmptyDeep,d as parseFrontMatter,l as parseYaml,I as reControlCharsRegex,a as registerYamlTag,p as removeLeadingEmptyLines,U as sanitizeFilename,Z as sanitizeFilepath,V as sleep,m as stringifyYaml,O as toCamelCase,T as toCapitalCase,P as toPascalCase,j as traverseFolder,$ as traverseFolderSync,X as yieldExec};
|
|
1
|
+
import{existsSync as t,mkdirSync as s,readFileSync as r,writeFileSync as n}from"fs";import i from"path";import{Config as e}from"load-config-file";import o from"path";function c(t,s=1){let r="";for(;s--;){const s=o.extname(t);if(!s)break;r=s+r,t=o.basename(t,s)}return r}import{parse as h,stringify as u}from"yaml";var f=[];function a(t){Array.isArray(t)||(t=[t]);for(const s of t){-1===f.indexOf(s)&&f.push(s)}}function l(t,s){if(s)if(s.customTags){if(Array.isArray(s.customTags))s.customTags=f.concat(s.customTags);else if("function"==typeof s.customTags){const t=s.customTags;s.customTags=s=>t(f.concat(s))}}else s.customTags=f;else s={customTags:f};return h(t,s)}function m(t,s){if(s)if(s.customTags){if(Array.isArray(s.customTags))s.customTags=f.concat(s.customTags);else if("function"==typeof s.customTags){const t=s.customTags;s.customTags=s=>t(f.concat(s))}}else s.customTags=f;else s={customTags:f};return u(t,s)}function p(t){const s=/^\s*(#[^\r\n]*)?[\r\n]+/;let r;for(;null!==(r=s.exec(t))&&((t=t.substring(r[0].length)).startsWith("\n")||t.startsWith("\r")||t.trimStart().startsWith("#")););return t}function y(t,s="---"){const r=s.length,n=p(t);if(n.startsWith(s)&&("\n"===n[s.length]||"\r"===n[s.length])){let t=n.indexOf("\n"+s,r);if(-1!==t){const i=n.slice(r,t);for(t+=s.length+1;"\n"===n[t]||"\r"===n[t];)t++;const e=n.slice(t);return{data:l(i)||{},content:e}}}return{data:{},content:t}}var d=class{static register(t,s,r){e.register(t,s),"string"==typeof t&&(t=[t]);for(const s of t)this.stringifys[s]=r}static loadSync(s,n){return function(s,{extLevel:n=1,externalFile:o}={}){s=g(s,n);let c=e.loadSync(s);if(!c&&o){if(!i.isAbsolute(o)){const t=i.dirname(s);o=i.join(t,o)}if(t(o)){const t=y(r(o,"utf8")).data;Object.keys(t).length&&(c=t)}}return c}(s,n)}static saveSync(r,e,o){return function(r,e,{extLevel:o=1}={}){const h=function(t,s=1){"."===t[0]&&s++;let r=c(t,s);(!r||r.split(".").length<=1)&&(t+=".yaml",r=".yaml");const n=new String(t);return n.extname=r,n}(r,o),u=h.extname;r=h.toString();const f=d.stringifys[u];if(!f)throw new Error(`${r} unsupported mime type: ${u}`);e=f(e);const a=i.dirname(r);t(a)||s(a,{recursive:!0});return n(r,e,{encoding:"utf8"}),r}(r,e,o)}static existsSync(t,s){return t=g(t,s?.extLevel),e.existsSync(t,s)}};function g(t,s=1){"."===t[0]&&s++;const r=c(t,s);return r&&r.split(".").length>1&&(t=t.slice(0,-r.length)),t}d.stringifys={},d.register([".yml",".yaml"],l,m),d.register([".json"],function(t){return JSON.parse(t)},t=>JSON.stringify(t,null,2));import{globMatch as w}from"@isdk/glob";import v from"path";function b(t,s,r){return r&&(t=v.relative(r,t)),w(t,s)}function k(t,s){return"string"==typeof s&&(s=[s]),-1!==s.indexOf(t)}var x=["**/*.((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 E(t,s=[]){if(t)if(Array.isArray(t))t=[...t];else{const r=t.include||[],n=t.exclude||[];0===r.length&&r.push(...s),t=[...r];for(const s of n)t.push(`!${s}`)}else t=[...s];return 0===t.length&&t.push(...s),t}import{readdir as j}from"fs/promises";import{readdirSync as A}from"fs";import F from"path";async function S(t,s){const r=await j(t,{withFileTypes:!0});for(const n of r){const r=F.join(t,n.name);try{if(n.isDirectory()){await s(r,n)||await S(r,s)}else{if(!0===await s(r,n))break}}catch(t){console.error(`Error processing file: ${r}`),console.error(t)}}}function P(t,s){const r=A(t,{withFileTypes:!0});for(const n of r){const r=F.join(t,n.name);try{if(n.isDirectory()){s(r,n)||S(r,s)}else{if(!0===s(r,n))break}}catch(t){console.error(`Error processing file: ${r}`),console.error(t)}}}function $(t){if(!t)return"";return t.replace(/[-_ ]+/g," ").split(" ").filter(Boolean).map(t=>{let s=t.charAt(0).toUpperCase();t=t.slice(1);let r=0;for(;/[A-Z]/.test(t[r]);)r++;return s+=r?t.slice(0,r).toLowerCase()+t.slice(r):t,s}).join("")}function M(t){return(t=$(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 T}from"@isdk/common-error";var z=/[<>:"/\\|?*\u0000-\u001F]/,C=/^(con|prn|aux|nul|com\d|lpt\d)$/i,D=/^\.+(\\|\/)|^\.+$/,_=/\.+$/,q=/[\u0000-\u001F\u0080-\u009F\u200E\u200F\u202A-\u202E\u2066-\u2069]/;function B(){return new RegExp(z.source,"g")}function I(){return new RegExp(q.source,"g")}function J(t){return t&&!(z.test(t)||I().test(t)||D.test(t)||_.test(t))}function L(t){const s=t.split(O.sep);return("/"===t[0]||s[0]&&O.dirname(s[0])===s[0])&&s.shift(),s.every(J)}function U(t,s={}){const r=s.replacement||"!";if((z.test(r)||q.test(r))&&T("Replacement string cannot contain reserved filename characters","sanitizeFilename",R.InvalidArgument),r.length>0){const s=/([<>:"/\\|?*\u0000-\u001F]){2,}/;t=t.replace(s,"$1")}if(t=(t=(t=(t=(t=t.normalize("NFD")).replace(D,r)).replace(B(),r)).replace(I(),r)).replace(_,""),r.length>0){"."===t[0]||"."!==t[0]||(t=r+t),"."===t[t.length-1]&&(t+=r)}t=C.test(t)?t+r:t;const n="number"==typeof s.maxLength?s.maxLength:100;if(t.length>n){const s=t.lastIndexOf(".");if(-1===s)t=t.slice(0,n);else{const r=t.slice(0,s),i=t.slice(s);t=r.slice(0,Math.max(1,n-i.length))+i}}return t}function Z(t,s={}){const r=t.split(O.sep);let n;("/"===t[0]||r[0]&&O.dirname(r[0])===r[0])&&(n=r.shift());const i=r.map(t=>U(t,s));return void 0!==n&&i.unshift(n),i.join(O.sep)}function G(t){return t.split(".").length-1}function W(t,s){const r=new Set(s),n=new Set;for(const s of t)if(r.has(s)&&(n.add(s),n.size===r.size))return!0;return n.size===r.size}function H(t=0){return s=Math.min(Math.max(16,t),1073741824),s>>>=0,s-=1,s|=s>>1,s|=s>>2,s|=s>>4,s|=s>>8,1+(s|=s>>16);var s}var K=class extends Array{constructor(t,s){Array.isArray(t)?(super(...t),this._length=t.length,t=void 0):(super(),this._length=0),this._capacity=H(t),this._front=0,this._disableAutoResize=s}push(t){let s=this._length;this.checkCapacity(s+1);const r=this._front+s&this._capacity-1;return this[r]=t,++s<=this._capacity&&(this._length=s),r}unshift(t){let s=this._length;this.checkCapacity(++s);const r=this._capacity,n=(this._front-1&r-1^r)-r;return this[n]=t,this._front=n,s<=this._capacity&&(this._length=s),n}pop(t){let s=this._length;if(0===s)return;let r=this._front+s-1&this._capacity-1,n=this[r];for(;--s>0&&t&&null==n;)r--,n=this[r];return this[r]=void 0,this._length=s,n}shift(t){let s=this._length;if(0===s)return;let r=this._front,n=this[r];for(;--s>0&&t&&null==n;)r=r+1&this._capacity-1,n=this[r];return this[r]=void 0,this._front=r+1&this._capacity-1,this._length=s,n}get size(){return this._length}get(t){let s;if(t===(0|t)){const r=this._length;t<0&&(t+=r),t>=0&&t<r&&(s=this[this._front+t&this._capacity-1])}return s}peekBack(){const t=this._length;if(0===t)return;return this[this._front+t-1&this._capacity-1]}peekFront(){if(0!==this._length)return this[this._front]}clear(){const t=this._length,s=this._front,r=this._capacity;for(let n=0;n<t;++n)this[s+n&r-1]=void 0;this._length=0,this._front=0}isEmpty(){return 0===this._length}removeAt(t){const s=this._length;if(t<0||t>=s)return;const r=this._front,n=this._capacity-1,i=r+t&n,e=this[i];if(t<s/2)this.copyWithin(r+1&n,r,r+t&n),this[r]=void 0,this._front=r+1&n;else{this.copyWithin(i,i+1&n,r+s&n);this[r+s-1&n]=void 0}return this._length=s-1,e}checkCapacity(t){this._capacity<t&&!this._disableAutoResize&&this.resizeTo(H(1.5*this._capacity+16))}resizeTo(t){const s=this._capacity;this._capacity=t;const r=this._front,n=this._length;if(r+n>s){!function(t,s,r,n,i){for(let e=0;e<i;++e)r[e+n]=t[e+s],t[e+s]=void 0}(this,0,this,s,r+n&s-1)}}},Q=class t{constructor(t=0){this.bitField=t}static has(t,s){return!!(t&1<<s)}static add(t,s){return t|1<<s}static delete(t,s){return t&~(1<<s)}add(t){return this.bitField|=1<<t,this}delete(t){return this.bitField&=~(1<<t),this}has(s){return t.has(this.bitField,s)}clear(){return this.bitField=0,this}valueOf(){return this.bitField}toString(){return this.bitField.toString()}toJSON(){return this.bitField}};async function V(t){return new Promise(s=>setTimeout(s,t))}async function X(){return new Promise(t=>{setImmediate(t)})}import{isAsync as Y}from"util-ex";import{EventEmitter as tt}from"events-ex";import{AbortError as st}from"@isdk/common-error";var rt=32;function nt(t){return"function"==typeof t}function it(){return"1"}var et=class{constructor(t={}){const{initFn:s=it,pauseFn:r,resumeFn:n,capacity:i=rt}=t;if(nt(r)!==nt(n))throw new Error("pauseFn and resumeFn must be both set for pausing");this.waiting=new K(i),this.emitter=new tt,this.useDefaultTokens=s===it,this.pauseFn=r,this.resumeFn=n,this.initTokenFn=s,this.paused=!1,this._activeCount=0,this.initFree(t),this.init(t)}initFree(t){this.free=this.initTokenFn()}onReleased(t){const s=t?.token,r=this.waiting.shift(!0);r?this._dispatchTask(r,t):(this.resumeFn&&this.paused&&(this.paused=!1,this.resumeFn()),this.unlock(s))}init(t){this.emitter.on("release",t=>{this.onReleased(t)})}_newReleaser(t){let s=!1;const r=()=>{s||(s=!0,this.release(t))};return t&&Object.assign(r,t),r}_dispatchTask(t,s){const{resolve:r}=t;r(this._newReleaser(s))}lock(t){const s=this.free;if(s)return this.free=void 0,s}unlock(t){this.free=this.useDefaultTokens?"1":t??this.initTokenFn()}tryAcquire(t){return this.lock(t)}async acquire(t){this._activeCount++;const s=t?.signal,r=t=>{this.pauseFn&&!this.paused&&(this.paused=!0,this.pauseFn());const r=this.waiting.push(t),n=t.reject;return s&&s.addEventListener("abort",()=>{this.waiting[r]=void 0;const t=s.reason instanceof Error?s.reason:new st(s.reason||"aborted");s.alreadyRejected=!0,n(t)}),r},n=this.tryAcquire(t),i=n&&Y(n),e=s=>new Promise((n,i)=>{const e={...t,resolve:n,reject:i,token:s};void 0===s?r(e):this._dispatchTask(e,{...t,token:s})});return i?n.then(t=>e(t)):e(n)}release(t){this._activeCount--,this.emitter.emit("release",t)}drain(){const t=[this.acquire()];return Promise.all(t)}abort(t){let s;for(;s=this.waiting.shift(!0);)s.reject(new st(t))}get activeCount(){return this._activeCount}get pendingCount(){return this.waiting.size}},ot=class extends et{constructor(t,s){if("number"==typeof t)(s=s||{}).maxConcurrency=t;else if("number"!=typeof(s=t).maxConcurrency)throw new Error("maxConcurrency must be set");super(s),this.maxConcurrency=s.maxConcurrency,s.isReadyFn&&(this.isReady=s.isReadyFn)}initFree(t){const s=t.maxConcurrency=Math.max(1,t.maxConcurrency);this.free=new K(s);for(let t=0;t<s;t++)this.free.push(this.initTokenFn())}tryAcquire(t){let s=this.isReady;if(s&&Y(s)){return s instanceof Promise||(s=s()),s.then(s=>{if(s)return this.lock(t)})}if(!s||s())return this.lock(t)}unlock(t){this.free.push(this.useDefaultTokens?"1":t??this.initTokenFn())}lock(t){return this.free.pop()}drain(){const t=new Array(this.maxConcurrency);for(let s=0;s<this.maxConcurrency;s++)t[s]=this.acquire();return Promise.all(t)}};function ct(t,{timeUnit:s=1e3,uniformDistribution:r=!1}={}){const n=new ot(r?1:t),i=r?s/t:s;return async function(){await n.acquire(),setTimeout(()=>n.release(),i)}}import{AbortError as ht}from"@isdk/common-error";var ut=class{constructor(){this._isSignaled=!1,this.waitQueue=[]}get signaled(){return this._isSignaled}signal(t){if(this._isSignaled)return;this._isSignaled=!0,this._signalValue=t;const s=this.waitQueue.slice();for(this.waitQueue.length=0;s.length>0;){const t=s.shift();t?.resolve(this._signalValue)}}reset(){this._isSignaled=!1,this._signalValue=void 0,this.waitQueue.length=0}abort(t){if(this.waitQueue.length){const s=this.waitQueue.slice();this.waitQueue.length=0;const r=new ht(t);for(;s.length>0;){const{reject:t}=s.shift();t(r)}}}async wait(){return new Promise((t,s)=>{this._isSignaled?t(this._signalValue):this.waitQueue.push({resolve:t,reject:s})})}};import ft from"net";var at=Promise.resolve();async function lt(t,s){const r=await(at=at.catch(()=>{}).then(()=>async function(t,s){let r,n,i=10;"number"==typeof s?i=s:s&&"object"==typeof s&&(i=s.retryCount??10,r=s.host);if(void 0===t)n=0;else if(n="string"==typeof t?parseInt(t,10):Math.floor(t),n>=0||(n=0),n>65535)throw new Error("Port out of range: "+n);for(let t=0;t<=i;t++)try{return await mt(n,r)}catch(s){if(t===i)throw s;const r="EACCES"===s.code||"EPERM"===s.code,e="EADDRINUSE"===s.code;if(!r&&!e)throw s;if(r&&n<1024?n=1024:n++,n>65535)throw new Error("No available ports found up to 65535")}throw new Error("No available ports found")}(t,s)));return r}function mt(t,s){return new Promise((r,n)=>{const i=ft.createServer();i.unref(),i.on("error",t=>{i.close(()=>n(t))}),i.listen(t,s,()=>{const t=i.address().port;i.close(s=>{s?n(s):r(t)})})})}import{isEmpty as pt,isNil as yt,isObject as dt,isPlainObject as gt}from"lodash-es";function wt(t,s,r=new WeakMap){if(!dt(t)||yt(t))return t;if(r.has(t))return r.get(t);let n;if(Array.isArray(t)){n=[],r.set(t,n);const i=t.map(t=>wt(t,s,r)).filter((t,r)=>!s(t,r.toString()));return Object.assign(n,i),n.length>0?n:void 0}if(gt(t)){n={},r.set(t,n);const i=Reflect.ownKeys(t);for(const e of i){const i=wt(t[e],s,r);s(i,e)||(n[e]=i)}return pt(n)?void 0:n}return t}import{isArray as vt,isEmpty as bt,isNil as kt,isPlainObject as xt}from"lodash-es";var Et=(t,s)=>wt(t,t=>function(t){return!!kt(t)||"string"==typeof t&&0===t.trim().length||!(!vt(t)&&!xt(t))&&bt(t)}(t)||s&&"function"==typeof t),jt={javascript:"js",jsx:"js",typescript:"ts",tsx:"ts",markdown:"md",python:"py",ruby:"rb",bash:"sh",zsh:"sh",shell:"sh",yaml:"yml",golang:"go",rust:"rs","c#":"cs",csharp:"cs","c++":"cpp"};function At(t,s){if(!t)return t;const r=t.toLowerCase();return s&&r in s?s[r]:jt[r]||r}function Ft(t,s={}){const{lang:r,langMap:n}=s,i=At(r,n),e=/^[ \t]*(?<fence>`{3,}|~{3,})(?<lang>\S*)[ \t]*(?<meta>\S*?)\n(?<code>[\s\S]+?\n)?[ \t]*\k<fence>$/gm,o=[];let c;for(e.lastIndex=0;null!==(c=e.exec(t));){const t=c.groups?.lang?.toLowerCase();if(!i||i===At(t,n)){const t=c.groups.code||"",s=new String(t);c.groups.lang&&(s.lang=c.groups.lang.toLowerCase()),c.groups.meta&&(s.meta=c.groups.meta),o.push(s)}}return o}function St(t){if(!t)return[];const s=[],r=/([>+~])?\s*([^\s>+~]+)/g;let n;for(;null!==(n=r.exec(t));){const t=n[1]||" ",r=n[2];s.push({combinator:t,lang:r})}return s}function Pt(t,s){const r="string"==typeof s?{lang:s}:s??{},{index:n=-1,all:i}=r,e=St(r.lang);let o=[];if(0===e.length)o=Ft(t,r);else{let s=[t];for(let t=0;t<e.length;t++){const{combinator:n,lang:i}=e[t],c=t===e.length-1,h=[],u=0===t&&" "===n?">":n;for(const t of s){let s=[];switch(u){case">":s=Ft(t,{...r,lang:i,all:!0});break;case" ":console.warn('Descendant selector " " is not implemented yet.');break;case"+":console.warn('Adjacent sibling selector "+" is not implemented yet.');break;case"~":console.warn('General sibling selector "~" is not implemented yet.')}h.push(...s)}if(c)o=h;else if(s=h.map(t=>t.toString()),0===s.length)break}}if(i)return o;const c=o[n<0?o.length+n:n];return void 0!==c?c:t}export{et as BinarySemaphore,d as ConfigFile,x as DefaultAllTextFiles,rt as DefaultAsyncSemaphoreCapacity,K as Deque,z as FilenameReservedRegex,Q as IntSet,ct as RateLimit,ot as Semaphore,ut as SignalGate,C as WindowsReservedNameRegex,W as arrayHasAll,G as extNameLevel,Pt as extractCodeBlock,Ft as extractTopLevelCodeBlocks,B as filenameReservedRegex,lt as findPort,c as getMultiLevelExtname,b as glob,k as isStringIn,J as isValidFilename,L as isValidFilepath,E as normalizeIncludeFiles,wt as omitDeepBy,Et as omitEmptyDeep,St as parseCodeBlockSelector,y as parseFrontMatter,l as parseYaml,I as reControlCharsRegex,a as registerYamlTag,p as removeLeadingEmptyLines,U as sanitizeFilename,Z as sanitizeFilepath,V as sleep,m as stringifyYaml,M as toCamelCase,N as toCapitalCase,$ as toPascalCase,S as traverseFolder,P as traverseFolderSync,X as yieldExec};
|