@cspell/cspell-tools 9.4.0 → 9.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/bin.mjs +1 -1
  2. package/cspell-tools.config.schema.json +50 -24
  3. package/dist/app.d.mts +35 -0
  4. package/dist/app.mjs +292 -0
  5. package/dist/build-OgMPaXPZ.mjs +1403 -0
  6. package/dist/index.d.mts +35 -0
  7. package/dist/index.mjs +3 -0
  8. package/package.json +10 -9
  9. package/dist/AppOptions.d.ts +0 -31
  10. package/dist/AppOptions.js +0 -2
  11. package/dist/FeatureFlags/FeatureFlags.d.ts +0 -34
  12. package/dist/FeatureFlags/FeatureFlags.js +0 -94
  13. package/dist/FeatureFlags/index.d.ts +0 -3
  14. package/dist/FeatureFlags/index.js +0 -3
  15. package/dist/FeatureFlags/parseFlags.d.ts +0 -3
  16. package/dist/FeatureFlags/parseFlags.js +0 -20
  17. package/dist/app.d.ts +0 -4
  18. package/dist/app.js +0 -86
  19. package/dist/build.d.ts +0 -12
  20. package/dist/build.js +0 -36
  21. package/dist/compile.d.ts +0 -5
  22. package/dist/compile.js +0 -41
  23. package/dist/compiler/CompileOptions.d.ts +0 -35
  24. package/dist/compiler/CompileOptions.js +0 -2
  25. package/dist/compiler/Reader.d.ts +0 -3
  26. package/dist/compiler/Reader.js +0 -24
  27. package/dist/compiler/SourceReader.d.ts +0 -28
  28. package/dist/compiler/SourceReader.js +0 -44
  29. package/dist/compiler/WordsCollection.d.ts +0 -20
  30. package/dist/compiler/WordsCollection.js +0 -3
  31. package/dist/compiler/compile.d.ts +0 -26
  32. package/dist/compiler/compile.js +0 -263
  33. package/dist/compiler/createCompileRequest.d.ts +0 -4
  34. package/dist/compiler/createCompileRequest.js +0 -84
  35. package/dist/compiler/createWordsCollection.d.ts +0 -9
  36. package/dist/compiler/createWordsCollection.js +0 -108
  37. package/dist/compiler/fileWriter.d.ts +0 -3
  38. package/dist/compiler/fileWriter.js +0 -6
  39. package/dist/compiler/index.d.ts +0 -5
  40. package/dist/compiler/index.js +0 -4
  41. package/dist/compiler/legacyLineToWords.d.ts +0 -4
  42. package/dist/compiler/legacyLineToWords.js +0 -20
  43. package/dist/compiler/logWithTimestamp.d.ts +0 -3
  44. package/dist/compiler/logWithTimestamp.js +0 -5
  45. package/dist/compiler/logger.d.ts +0 -4
  46. package/dist/compiler/logger.js +0 -9
  47. package/dist/compiler/readers/ReaderOptions.d.ts +0 -19
  48. package/dist/compiler/readers/ReaderOptions.js +0 -2
  49. package/dist/compiler/readers/readHunspellFiles.d.ts +0 -3
  50. package/dist/compiler/readers/readHunspellFiles.js +0 -57
  51. package/dist/compiler/readers/readTextFile.d.ts +0 -3
  52. package/dist/compiler/readers/readTextFile.js +0 -20
  53. package/dist/compiler/readers/regHunspellFile.d.ts +0 -2
  54. package/dist/compiler/readers/regHunspellFile.js +0 -2
  55. package/dist/compiler/readers/textFileReader.d.ts +0 -3
  56. package/dist/compiler/readers/textFileReader.js +0 -11
  57. package/dist/compiler/readers/trieFileReader.d.ts +0 -3
  58. package/dist/compiler/readers/trieFileReader.js +0 -16
  59. package/dist/compiler/splitCamelCaseIfAllowed.d.ts +0 -5
  60. package/dist/compiler/splitCamelCaseIfAllowed.js +0 -65
  61. package/dist/compiler/streamSourceWordsFromFile.d.ts +0 -3
  62. package/dist/compiler/streamSourceWordsFromFile.js +0 -6
  63. package/dist/compiler/text.d.ts +0 -10
  64. package/dist/compiler/text.js +0 -28
  65. package/dist/compiler/wordListCompiler.d.ts +0 -17
  66. package/dist/compiler/wordListCompiler.js +0 -199
  67. package/dist/compiler/wordListParser.d.ts +0 -61
  68. package/dist/compiler/wordListParser.js +0 -184
  69. package/dist/compiler/writeTextToFile.d.ts +0 -3
  70. package/dist/compiler/writeTextToFile.js +0 -15
  71. package/dist/config/config.d.ts +0 -194
  72. package/dist/config/config.js +0 -2
  73. package/dist/config/configDefaults.d.ts +0 -9
  74. package/dist/config/configDefaults.js +0 -9
  75. package/dist/config/configUtils.d.ts +0 -5
  76. package/dist/config/configUtils.js +0 -14
  77. package/dist/config/index.d.ts +0 -4
  78. package/dist/config/index.js +0 -3
  79. package/dist/config/normalizeConfig.d.ts +0 -8
  80. package/dist/config/normalizeConfig.js +0 -13
  81. package/dist/gzip/compressFiles.d.ts +0 -16
  82. package/dist/gzip/compressFiles.js +0 -42
  83. package/dist/gzip/gzip.d.ts +0 -3
  84. package/dist/gzip/gzip.js +0 -10
  85. package/dist/gzip/index.d.ts +0 -3
  86. package/dist/gzip/index.js +0 -3
  87. package/dist/shasum/checksum.d.ts +0 -7
  88. package/dist/shasum/checksum.js +0 -19
  89. package/dist/shasum/index.d.ts +0 -3
  90. package/dist/shasum/index.js +0 -3
  91. package/dist/shasum/shasum.d.ts +0 -38
  92. package/dist/shasum/shasum.js +0 -150
  93. package/dist/test/TestHelper.d.ts +0 -53
  94. package/dist/test/TestHelper.js +0 -121
  95. package/dist/test/console.d.ts +0 -9
  96. package/dist/test/console.js +0 -34
  97. package/dist/test/escapeRegEx.d.ts +0 -7
  98. package/dist/test/escapeRegEx.js +0 -9
  99. package/dist/test/normalizeOutput.d.ts +0 -3
  100. package/dist/test/normalizeOutput.js +0 -20
  101. package/dist/types.d.ts +0 -7
  102. package/dist/types.js +0 -2
  103. package/dist/util/errors.d.ts +0 -6
  104. package/dist/util/errors.js +0 -11
  105. package/dist/util/globP.d.ts +0 -7
  106. package/dist/util/globP.js +0 -7
  107. package/dist/util/index.d.ts +0 -2
  108. package/dist/util/index.js +0 -4
  109. package/dist/util/textRegex.d.ts +0 -3
  110. package/dist/util/textRegex.js +0 -109
@@ -1,26 +0,0 @@
1
- import type { CompileRequest, CompileSourceOptions as CompileSourceConfig, Target } from '../config/index.js';
2
- interface CompileOptions {
3
- /**
4
- * Optional filter function to filter targets.
5
- */
6
- filter?: ((target: Target) => boolean) | undefined;
7
- /**
8
- * The current working directory. Defaults to process.cwd()
9
- */
10
- cwd?: string | undefined;
11
- /**
12
- * `true` - only build if files do not match checksum.
13
- */
14
- conditionalBuild: boolean;
15
- }
16
- export declare function compile(request: CompileRequest, options?: CompileOptions): Promise<void>;
17
- interface CompileTargetOptions {
18
- rootDir: string;
19
- cwd: string | undefined;
20
- conditional: boolean;
21
- checksumFile: string | undefined;
22
- dictionaryDirectives: string[] | undefined;
23
- }
24
- export declare function compileTarget(target: Target, options: CompileSourceConfig, compileOptions: CompileTargetOptions): Promise<string[]>;
25
- export {};
26
- //# sourceMappingURL=compile.d.ts.map
@@ -1,263 +0,0 @@
1
- import * as path from 'node:path';
2
- import { pipeAsync, toArray } from '@cspell/cspell-pipe';
3
- import { opAwaitAsync, opMapAsync } from '@cspell/cspell-pipe/operators';
4
- import { opConcatMap, opMap, pipe } from '@cspell/cspell-pipe/sync';
5
- import { isFileListSource, isFilePath, isFileSource } from '../config/index.js';
6
- import { checkShasumFile, updateChecksumForFiles } from '../shasum/index.js';
7
- import { stringToRegExp } from '../util/textRegex.js';
8
- import { createAllowedSplitWordsFromFiles, createWordsCollectionFromFiles } from './createWordsCollection.js';
9
- import { logWithTimestamp } from './logWithTimestamp.js';
10
- import { readTextFile } from './readers/readTextFile.js';
11
- import { streamSourceWordsFromFile } from './streamSourceWordsFromFile.js';
12
- import { compileTrie, compileWordList } from './wordListCompiler.js';
13
- import { normalizeTargetWords } from './wordListParser.js';
14
- export async function compile(request, options) {
15
- const { targets } = request;
16
- // console.warn('Request: %o', request);
17
- const rootDir = path.resolve(request.rootDir || '.');
18
- const cwd = options?.cwd;
19
- const targetOptions = {
20
- sort: request.sort,
21
- generateNonStrict: request.generateNonStrict,
22
- removeDuplicates: request.removeDuplicates,
23
- };
24
- const conditional = options?.conditionalBuild || false;
25
- const checksumFile = resolveChecksumFile(request.checksumFile || conditional, rootDir);
26
- const dictionaryDirectives = request.dictionaryDirectives;
27
- const dependencies = new Set();
28
- for (const target of targets) {
29
- const keep = options?.filter?.(target) ?? true;
30
- if (!keep)
31
- continue;
32
- const adjustedTarget = { ...targetOptions, ...target };
33
- // console.warn('adjustedTarget: %o', adjustedTarget);
34
- const deps = await compileTarget(adjustedTarget, request, {
35
- rootDir,
36
- cwd,
37
- conditional,
38
- checksumFile,
39
- dictionaryDirectives,
40
- });
41
- deps.forEach((dep) => dependencies.add(dep));
42
- }
43
- if (checksumFile && dependencies.size) {
44
- logWithTimestamp('%s', `Update checksum: ${checksumFile}`);
45
- await updateChecksumForFiles(checksumFile, [...dependencies], { root: path.dirname(checksumFile) });
46
- }
47
- logWithTimestamp(`Complete.`);
48
- return;
49
- }
50
- function resolveChecksumFile(checksumFile, root) {
51
- const cFilename = (typeof checksumFile === 'string' && checksumFile) || (checksumFile && './checksum.txt') || undefined;
52
- const file = cFilename && path.resolve(root, cFilename);
53
- // console.warn('%o', { checksumFile, cFilename, file });
54
- return file;
55
- }
56
- export async function compileTarget(target, options, compileOptions) {
57
- logWithTimestamp(`Start compile: ${target.name}`);
58
- const { rootDir, cwd, checksumFile, conditional } = compileOptions;
59
- const { format, sources, trieBase, sort = true, generateNonStrict = false, excludeWordsFrom = [], excludeWordsNotFoundIn = [], excludeWordsMatchingRegex, } = target;
60
- const targetDirectory = path.resolve(rootDir, target.targetDirectory ?? cwd ?? process.cwd());
61
- const dictionaryDirectives = target.dictionaryDirectives ?? compileOptions.dictionaryDirectives;
62
- const removeDuplicates = target.removeDuplicates ?? false;
63
- const excludeFromFilter = await createExcludeFilter(excludeWordsFrom);
64
- const includeFromFilter = await createIncludeFilter(excludeWordsNotFoundIn);
65
- const excludeRegexFilter = createExcludeRegexFilter(excludeWordsMatchingRegex);
66
- const excludeFilter = (word) => {
67
- return excludeFromFilter(word) && includeFromFilter(word) && excludeRegexFilter(word);
68
- };
69
- const generateNonStrictTrie = target.generateNonStrict ?? true;
70
- const name = normalizeTargetName(target.name);
71
- const useTrie = format.startsWith('trie');
72
- const filename = resolveTarget(name, targetDirectory, useTrie, target.compress ?? false);
73
- const filesToProcessAsync = pipeAsync(readSourceList(sources, rootDir), opMapAsync((src) => readFileSource(src, options)), opAwaitAsync());
74
- const filesToProcess = await toArray(filesToProcessAsync);
75
- const normalizer = normalizeTargetWords({
76
- sort: useTrie || sort,
77
- generateNonStrict,
78
- filter: excludeFilter,
79
- dictionaryDirectives,
80
- // removeDuplicates, // Add this in if we use it.
81
- });
82
- const checksumRoot = (checksumFile && path.dirname(checksumFile)) || rootDir;
83
- const deps = [
84
- ...calculateDependencies(filename, filesToProcess, [...excludeWordsFrom, ...excludeWordsNotFoundIn], checksumRoot),
85
- ];
86
- if (conditional && checksumFile) {
87
- const check = await checkShasumFile(checksumFile, deps, checksumRoot).catch(() => undefined);
88
- if (check?.passed) {
89
- logWithTimestamp(`Skip ${target.name}, nothing changed.`);
90
- return [];
91
- }
92
- }
93
- const action = useTrie
94
- ? async (words, dst) => {
95
- return compileTrie(pipe(words, normalizer), dst, {
96
- base: trieBase,
97
- sort: false,
98
- trie3: format === 'trie3',
99
- trie4: format === 'trie4',
100
- generateNonStrict: generateNonStrictTrie,
101
- dictionaryDirectives: undefined,
102
- // removeDuplicates, // Add this in if we use it.
103
- });
104
- }
105
- : async (words, dst) => {
106
- return compileWordList(pipe(words, normalizer), dst, {
107
- sort,
108
- generateNonStrict,
109
- dictionaryDirectives,
110
- removeDuplicates,
111
- });
112
- };
113
- await processFiles(action, filesToProcess, filename);
114
- logWithTimestamp(`Done compile: ${target.name}`);
115
- return deps;
116
- }
117
- function calculateDependencies(targetFile, filesToProcess, excludeFiles, rootDir) {
118
- const dependencies = new Set();
119
- addDependency(targetFile);
120
- excludeFiles?.forEach((f) => addDependency(f));
121
- filesToProcess.forEach((f) => addDependency(f.src));
122
- return dependencies;
123
- function addDependency(filename) {
124
- const rel = path.relative(rootDir, filename);
125
- dependencies.add(rel);
126
- dependencies.add(rel.replace(/\.aff$/, '.dic'));
127
- dependencies.add(rel.replace(/\.dic$/, '.aff'));
128
- }
129
- }
130
- function rel(filePath) {
131
- return path.relative(process.cwd(), filePath);
132
- }
133
- async function processFiles(action, filesToProcess, mergeTarget) {
134
- const toProcess = filesToProcess;
135
- const dst = mergeTarget;
136
- const words = pipe(toProcess, opMap((ftp) => {
137
- const { src } = ftp;
138
- logWithTimestamp('Process "%s" to "%s"', rel(src), rel(dst));
139
- return ftp;
140
- }), opConcatMap(function* (ftp) {
141
- yield* ftp.words;
142
- logWithTimestamp('Done processing %s', rel(ftp.src));
143
- }),
144
- // opMap((a) => (console.warn(a), a))
145
- logProgress());
146
- await action(words, dst);
147
- logWithTimestamp('Done "%s"', rel(dst));
148
- }
149
- function resolveTarget(name, directory, useTrie, useGzCompress) {
150
- const ext = ((useTrie && '.trie') || '.txt') + ((useGzCompress && '.gz') || '');
151
- const filename = name + ext;
152
- return path.resolve(directory, filename);
153
- }
154
- function readSourceList(sources, rootDir) {
155
- async function* mapSrc() {
156
- for (const src of sources) {
157
- if (isFilePath(src)) {
158
- yield { filename: path.resolve(rootDir, src) };
159
- continue;
160
- }
161
- if (isFileSource(src)) {
162
- yield { ...src, filename: path.resolve(rootDir, src.filename) };
163
- continue;
164
- }
165
- if (isFileListSource(src)) {
166
- const { listFile, ...rest } = src;
167
- const absListFile = path.resolve(rootDir, listFile);
168
- const listFileDir = path.dirname(absListFile);
169
- const files = await readFileList(absListFile);
170
- for (const filename of files) {
171
- yield { ...rest, filename: path.resolve(listFileDir, filename) };
172
- }
173
- }
174
- }
175
- }
176
- return mapSrc();
177
- }
178
- async function readFileList(fileList) {
179
- const content = await readTextFile(fileList);
180
- return content
181
- .split('\n')
182
- .map((a) => a.trim())
183
- .filter((a) => !!a);
184
- }
185
- async function readFileSource(fileSource, sourceOptions) {
186
- const { filename, keepRawCase = sourceOptions.keepRawCase || false, split = sourceOptions.split || false, maxDepth, storeSplitWordsAsCompounds, minCompoundLength, } = fileSource;
187
- const legacy = split === 'legacy';
188
- const splitWords = legacy ? false : split;
189
- // console.warn('fileSource: %o,\n targetOptions %o, \n opt: %o', fileSource, targetOptions, opt);
190
- const allowedSplitWords = await createAllowedSplitWordsFromFiles(fileSource.allowedSplitWords || sourceOptions.allowedSplitWords);
191
- const readerOptions = {
192
- maxDepth,
193
- legacy,
194
- splitWords,
195
- keepCase: keepRawCase,
196
- allowedSplitWords,
197
- storeSplitWordsAsCompounds,
198
- minCompoundLength,
199
- };
200
- logWithTimestamp(`Reading ${path.basename(filename)}`);
201
- const stream = await streamSourceWordsFromFile(filename, readerOptions);
202
- logWithTimestamp(`Done reading ${path.basename(filename)}`);
203
- const f = {
204
- src: filename,
205
- words: stream,
206
- };
207
- return f;
208
- }
209
- function normalizeTargetName(name) {
210
- return name.replace(/((\.txt|\.dic|\.aff|\.trie)(\.gz)?)?$/, '').replaceAll(/[^\p{L}\p{M}.\w\\/-]/gu, '_');
211
- }
212
- function logProgress(freq = 100_000) {
213
- function* logProgress(iter) {
214
- const _freq = freq;
215
- let count = 0;
216
- for (const v of iter) {
217
- ++count;
218
- if (!(count % _freq)) {
219
- logWithTimestamp('Progress: Words Processed - %s', count.toLocaleString());
220
- }
221
- yield v;
222
- }
223
- }
224
- return logProgress;
225
- }
226
- /**
227
- * @param excludeWordsFrom - List of files to read words from.
228
- * @returns a function that returns true if the word is not in the exclude list.
229
- */
230
- async function createExcludeFilter(excludeWordsFrom) {
231
- if (!excludeWordsFrom || !excludeWordsFrom.length)
232
- return () => true;
233
- const excludeWords = await createWordsCollectionFromFiles(excludeWordsFrom);
234
- return (word) => !excludeWords.has(word, word.toUpperCase() !== word);
235
- }
236
- /**
237
- * @param includeWordsFrom - List of files to read words from.
238
- * @returns a function that returns true if the word is in the include list.
239
- */
240
- async function createIncludeFilter(includeWordsFrom) {
241
- if (!includeWordsFrom || !includeWordsFrom.length)
242
- return () => true;
243
- const excludeWords = await createWordsCollectionFromFiles(includeWordsFrom);
244
- return (word) => excludeWords.has(word, word.toUpperCase() !== word);
245
- }
246
- /**
247
- * @param excludeWordsMatchingRegex - List of regex patterns to exclude.
248
- * @returns a function that returns true if the word does not match any of the regex patterns.
249
- */
250
- function createExcludeRegexFilter(excludeWordsMatchingRegex) {
251
- if (!excludeWordsMatchingRegex || !excludeWordsMatchingRegex.length)
252
- return () => true;
253
- const regexes = excludeWordsMatchingRegex
254
- .map((a) => stringToRegExp(a))
255
- .filter((a, i) => {
256
- if (a)
257
- return true;
258
- console.warn('Invalid regex: "%s"', excludeWordsMatchingRegex[i]);
259
- return false;
260
- });
261
- return (word) => !regexes.some((r) => r.test(word));
262
- }
263
- //# sourceMappingURL=compile.js.map
@@ -1,4 +0,0 @@
1
- import type { CompileCommonAppOptions } from '../AppOptions.js';
2
- import type { CompileRequest } from '../config/index.js';
3
- export declare function createCompileRequest(sourceFiles: string[], options: CompileCommonAppOptions): CompileRequest;
4
- //# sourceMappingURL=createCompileRequest.d.ts.map
@@ -1,84 +0,0 @@
1
- import * as path from 'node:path';
2
- export function createCompileRequest(sourceFiles, options) {
3
- options = { ...options };
4
- options.maxDepth ??= options.max_depth;
5
- const { maxDepth, split, keepRawCase, useLegacySplitter } = options;
6
- const sources = [...sourceFiles, ...(options.listFile || []).map((listFile) => ({ listFile }))];
7
- const targets = calcTargets(sources, options);
8
- const req = {
9
- targets,
10
- maxDepth: parseNumber(maxDepth),
11
- split: useLegacySplitter ? 'legacy' : split,
12
- /**
13
- * Do not generate lower case / accent free versions of words.
14
- * @default false
15
- */
16
- keepRawCase,
17
- };
18
- return req;
19
- }
20
- function calcTargets(sources, options) {
21
- const { merge, output = '.', experimental = [] } = options;
22
- const generateNonStrict = experimental.includes('compound') || undefined;
23
- // console.log('%o', sources);
24
- const format = calcFormat(options);
25
- const sort = (format === 'plaintext' && options.sort) || undefined;
26
- if (merge) {
27
- const target = {
28
- name: merge,
29
- targetDirectory: output,
30
- compress: options.compress,
31
- format,
32
- sources: sources.map(normalizeSource),
33
- sort,
34
- trieBase: parseNumber(options.trieBase),
35
- generateNonStrict,
36
- };
37
- return [target];
38
- }
39
- const targets = sources.map((source) => {
40
- const name = toTargetName(baseNameOfSource(source));
41
- const target = {
42
- name,
43
- targetDirectory: output,
44
- compress: options.compress,
45
- format,
46
- sources: [normalizeSource(source)],
47
- sort: options.sort,
48
- trieBase: parseNumber(options.trieBase),
49
- generateNonStrict,
50
- };
51
- return target;
52
- });
53
- return targets;
54
- }
55
- function calcFormat(options) {
56
- return (options.trie4 && 'trie4') || (options.trie3 && 'trie3') || (options.trie && 'trie') || 'plaintext';
57
- }
58
- function toTargetName(sourceFile) {
59
- return path.basename(sourceFile).replace(/((\.txt|\.dic|\.aff|\.trie)(\.gz)?)?$/, '');
60
- }
61
- function parseNumber(s) {
62
- const n = Number.parseInt(s ?? '');
63
- return Number.isNaN(n) ? undefined : n;
64
- }
65
- function baseNameOfSource(source) {
66
- return typeof source === 'string' ? source : isFileSource(source) ? source.filename : source.listFile;
67
- }
68
- function isFileSource(source) {
69
- return typeof source !== 'string' && source.filename !== undefined;
70
- }
71
- function normalizeSource(source) {
72
- if (typeof source === 'string') {
73
- return normalizeSourcePath(source);
74
- }
75
- if (isFileSource(source))
76
- return { ...source, filename: normalizeSourcePath(source.filename) };
77
- return { ...source, listFile: normalizeSourcePath(source.listFile) };
78
- }
79
- function normalizeSourcePath(source) {
80
- const cwd = process.cwd();
81
- const rel = path.relative(cwd, source);
82
- return rel.split('\\').join('/');
83
- }
84
- //# sourceMappingURL=createCompileRequest.js.map
@@ -1,9 +0,0 @@
1
- import type { FilePath } from '../config/config.js';
2
- import type { AllowedSplitWordsCollection, ExcludeWordsCollection, WordsCollection } from './WordsCollection.js';
3
- export declare function createAllowedSplitWordsFromFiles(files: FilePath | FilePath[] | undefined): Promise<AllowedSplitWordsCollection>;
4
- export declare function createAllowedSplitWords(words: Iterable<string> | undefined): AllowedSplitWordsCollection;
5
- export declare function createWordsCollectionFromFiles(files: FilePath | FilePath[]): Promise<WordsCollection>;
6
- export declare function createWordsCollection(words: Iterable<string>): WordsCollection;
7
- export declare function createExcludeWordsCollectionFromFiles(files: FilePath | FilePath[] | undefined): Promise<ExcludeWordsCollection>;
8
- export declare function createExcludeWordsCollection(words: Iterable<string> | undefined): ExcludeWordsCollection;
9
- //# sourceMappingURL=createWordsCollection.d.ts.map
@@ -1,108 +0,0 @@
1
- import { parseDictionary } from 'cspell-trie-lib';
2
- import { createReader } from './Reader.js';
3
- import { defaultAllowedSplitWords, defaultExcludeWordsCollection } from './WordsCollection.js';
4
- class AllowedSplitWordsImpl {
5
- collection;
6
- size;
7
- constructor(collection) {
8
- this.collection = collection;
9
- this.size = collection.size;
10
- }
11
- has(word, caseSensitive) {
12
- return !this.size || this.collection.has(word, caseSensitive);
13
- }
14
- }
15
- export async function createAllowedSplitWordsFromFiles(files) {
16
- if (!files || !files.length)
17
- return defaultAllowedSplitWords;
18
- const collection = await createWordsCollectionFromFiles(files);
19
- return new AllowedSplitWordsImpl(collection);
20
- }
21
- export function createAllowedSplitWords(words) {
22
- if (!words)
23
- return defaultAllowedSplitWords;
24
- return new AllowedSplitWordsImpl(createWordsCollection(words));
25
- }
26
- function buildHasFn(dict) {
27
- function has(word, caseSensitive) {
28
- const r = dict.hasWord(word, true);
29
- if (r || caseSensitive)
30
- return r;
31
- const lc = word.toLowerCase();
32
- if (lc == word)
33
- return false;
34
- return dict.hasWord(lc, true);
35
- }
36
- return has;
37
- }
38
- async function readFile(filename) {
39
- return await createReader(filename, {});
40
- }
41
- function readersToCollection(readers) {
42
- const dictReaders = readers.filter(isDictionaryReader).map(dictReaderToCollection);
43
- const nonDictCollection = lineReadersToCollection(readers.filter((a) => !isDictionaryReader(a)));
44
- const collections = [...dictReaders, nonDictCollection];
45
- const collection = {
46
- size: collections.reduce((s, a) => s + a.size, 0),
47
- has: (word, caseSensitive) => collections.some((a) => a.has(word, caseSensitive)),
48
- };
49
- return collection;
50
- }
51
- const cache = new WeakMap();
52
- export async function createWordsCollectionFromFiles(files) {
53
- files = Array.isArray(files) ? files : [files];
54
- const cached = cache.get(files);
55
- if (cached)
56
- return cached;
57
- const sources = await Promise.all(files.map((file) => readFile(file)));
58
- const collection = readersToCollection(sources);
59
- cache.set(files, collection);
60
- return collection;
61
- }
62
- export function createWordsCollection(words) {
63
- if (words instanceof Set)
64
- return words;
65
- const arrWords = (Array.isArray(words) ? words : [...words])
66
- .map((a) => a.trim())
67
- .filter((a) => !!a)
68
- .filter((a) => !a.startsWith('#'));
69
- const setOfWords = new Set(arrWords);
70
- const has = buildHasFn({ hasWord: (word) => setOfWords.has(word) });
71
- return { size: setOfWords.size, has };
72
- }
73
- class ExcludeWordsCollectionImpl {
74
- collection;
75
- size;
76
- constructor(collection) {
77
- this.collection = collection;
78
- this.size = collection.size;
79
- }
80
- has(word, caseSensitive) {
81
- return this.collection.has(word, caseSensitive);
82
- }
83
- }
84
- export async function createExcludeWordsCollectionFromFiles(files) {
85
- if (!files || !files.length)
86
- return defaultExcludeWordsCollection;
87
- const collection = await createWordsCollectionFromFiles(files);
88
- return new ExcludeWordsCollectionImpl(collection);
89
- }
90
- export function createExcludeWordsCollection(words) {
91
- return new ExcludeWordsCollectionImpl(words ? createWordsCollection(words) : new Set());
92
- }
93
- function isDictionaryReader(reader) {
94
- return 'hasWord' in reader && !!reader.hasWord;
95
- }
96
- function dictReaderToCollection(reader) {
97
- return { size: reader.size, has: buildHasFn(reader) };
98
- }
99
- function lineReadersToCollection(readers) {
100
- function* words() {
101
- for (const reader of readers) {
102
- yield* reader.lines;
103
- }
104
- }
105
- const dict = parseDictionary(words(), { stripCaseAndAccents: false });
106
- return { size: dict.size, has: buildHasFn(dict) };
107
- }
108
- //# sourceMappingURL=createWordsCollection.js.map
@@ -1,3 +0,0 @@
1
- export { writeTextLinesToFile as writeToFileIterableP } from './writeTextToFile.js';
2
- export declare function writeSeqToFile(seq: Iterable<string>, outFile: string): Promise<void>;
3
- //# sourceMappingURL=fileWriter.d.ts.map
@@ -1,6 +0,0 @@
1
- import { writeTextLinesToFile } from './writeTextToFile.js';
2
- export { writeTextLinesToFile as writeToFileIterableP } from './writeTextToFile.js';
3
- export function writeSeqToFile(seq, outFile) {
4
- return writeTextLinesToFile(outFile, seq);
5
- }
6
- //# sourceMappingURL=fileWriter.js.map
@@ -1,5 +0,0 @@
1
- export type { CompileRequest, CompileTargetOptions, RunConfig } from '../config/index.js';
2
- export { compile, compileTarget } from './compile.js';
3
- export { type Logger, setLogger } from './logger.js';
4
- export { compileTrie, compileWordList } from './wordListCompiler.js';
5
- //# sourceMappingURL=index.d.ts.map
@@ -1,4 +0,0 @@
1
- export { compile, compileTarget } from './compile.js';
2
- export { setLogger } from './logger.js';
3
- export { compileTrie, compileWordList } from './wordListCompiler.js';
4
- //# sourceMappingURL=index.js.map
@@ -1,4 +0,0 @@
1
- import type { AllowedSplitWordsCollection } from './WordsCollection.js';
2
- export declare function legacyLineToWords(line: string, keepCase: boolean, allowedSplitWords: AllowedSplitWordsCollection): Iterable<string>;
3
- export declare function legacyLinesToWords(lines: Iterable<string>, keepCase: boolean, allowedSplitWords: AllowedSplitWordsCollection): Iterable<string>;
4
- //# sourceMappingURL=legacyLineToWords.d.ts.map
@@ -1,20 +0,0 @@
1
- import { opConcatMap, opFilter, opMap, pipe } from '@cspell/cspell-pipe/sync';
2
- import { defaultCompileSourceOptions } from '../config/configDefaults.js';
3
- import { regExpSpaceOrDash, splitCamelCaseIfAllowed } from './splitCamelCaseIfAllowed.js';
4
- const regNonWord = /[^\p{L}\p{M}' _\d]+/giu;
5
- const regExpRepeatChars = /(.)\1{5}/i;
6
- const minCompoundLength = defaultCompileSourceOptions.minCompoundLength;
7
- export function legacyLineToWords(line, keepCase, allowedSplitWords) {
8
- // Remove punctuation and non-letters.
9
- const filteredLine = line.replaceAll(regNonWord, '|');
10
- const wordGroups = filteredLine.split('|');
11
- const _minCompoundLength = minCompoundLength;
12
- const words = pipe(wordGroups, opConcatMap((a) => a.split(regExpSpaceOrDash)), opConcatMap((a) => splitCamelCaseIfAllowed(a, allowedSplitWords, keepCase, '', _minCompoundLength)), opMap((a) => a.trim()), opFilter((a) => !!a), opFilter((s) => !regExpRepeatChars.test(s)));
13
- return words;
14
- }
15
- export function* legacyLinesToWords(lines, keepCase, allowedSplitWords) {
16
- for (const line of lines) {
17
- yield* legacyLineToWords(line, keepCase, allowedSplitWords);
18
- }
19
- }
20
- //# sourceMappingURL=legacyLineToWords.js.map
@@ -1,3 +0,0 @@
1
- import type { Logger } from './logger.js';
2
- export declare const logWithTimestamp: Logger;
3
- //# sourceMappingURL=logWithTimestamp.d.ts.map
@@ -1,5 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
- export const logWithTimestamp = (message, ...optionalParams) => {
3
- console.log(`${new Date().toISOString()} ${message}`, ...optionalParams);
4
- };
5
- //# sourceMappingURL=logWithTimestamp.js.map
@@ -1,4 +0,0 @@
1
- export type Logger = (message?: any, ...optionalParams: any[]) => void;
2
- export declare function setLogger(logger?: Logger): void;
3
- export declare function getLogger(): Logger;
4
- //# sourceMappingURL=logger.d.ts.map
@@ -1,9 +0,0 @@
1
- const defaultLogger = console.log;
2
- let log = defaultLogger;
3
- export function setLogger(logger) {
4
- log = logger ?? defaultLogger;
5
- }
6
- export function getLogger() {
7
- return log;
8
- }
9
- //# sourceMappingURL=logger.js.map
@@ -1,19 +0,0 @@
1
- export interface ReaderOptions {
2
- /**
3
- * Max Hunspell recursive depth.
4
- */
5
- maxDepth?: number | undefined;
6
- }
7
- export type AnnotatedWord = string;
8
- export interface BaseReader {
9
- size: number;
10
- type: 'Hunspell' | 'TextFile' | 'Trie';
11
- lines: Iterable<AnnotatedWord>;
12
- readonly hasWord?: (word: string, caseSensitive: boolean) => boolean;
13
- }
14
- export interface Reader extends BaseReader {
15
- }
16
- export interface DictionaryReader extends BaseReader {
17
- readonly hasWord: (word: string, caseSensitive: boolean) => boolean;
18
- }
19
- //# sourceMappingURL=ReaderOptions.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=ReaderOptions.js.map
@@ -1,3 +0,0 @@
1
- import type { BaseReader, ReaderOptions } from './ReaderOptions.js';
2
- export declare function readHunspellFiles(filename: string, options: ReaderOptions): Promise<BaseReader>;
3
- //# sourceMappingURL=readHunspellFiles.d.ts.map
@@ -1,57 +0,0 @@
1
- import { pipe } from '@cspell/cspell-pipe/sync';
2
- import { COMPOUND_FIX, FORBID_PREFIX } from 'cspell-trie-lib';
3
- import * as HR from 'hunspell-reader';
4
- import { regHunspellFile } from './regHunspellFile.js';
5
- const DEDUPE_SIZE = 1000;
6
- export async function readHunspellFiles(filename, options) {
7
- const dicFile = filename.replace(regHunspellFile, '.dic');
8
- const affFile = filename.replace(regHunspellFile, '.aff');
9
- const reader = await HR.IterableHunspellReader.createFromFiles(affFile, dicFile);
10
- reader.maxDepth = options.maxDepth !== undefined ? options.maxDepth : reader.maxDepth;
11
- const words = pipe(reader.seqAffWords(), _mapAffWords, dedupeAndSort);
12
- return {
13
- type: 'Hunspell',
14
- size: reader.dic.length,
15
- lines: words,
16
- };
17
- }
18
- function* dedupeAndSort(words) {
19
- const buffer = new Set();
20
- function flush() {
21
- const result = [...buffer].sort();
22
- buffer.clear();
23
- return result;
24
- }
25
- for (const word of words) {
26
- buffer.add(word);
27
- if (buffer.size >= DEDUPE_SIZE) {
28
- yield* flush();
29
- }
30
- }
31
- yield* flush();
32
- }
33
- function* _mapAffWords(affWords) {
34
- const hasSpecial = /[~+!]/;
35
- for (const affWord of affWords) {
36
- const { word, flags } = affWord;
37
- // For now do not include words with special characters.
38
- if (hasSpecial.test(word))
39
- continue;
40
- const compound = flags.isCompoundForbidden ? '' : COMPOUND_FIX;
41
- const forbid = flags.isForbiddenWord ? FORBID_PREFIX : '';
42
- if (!forbid) {
43
- if (flags.canBeCompoundBegin || flags.isCompoundPermitted)
44
- yield word + compound;
45
- if (flags.canBeCompoundEnd || flags.isCompoundPermitted)
46
- yield compound + word;
47
- if (flags.canBeCompoundMiddle || flags.isCompoundPermitted)
48
- yield compound + word + compound;
49
- if (!flags.isOnlyAllowedInCompound)
50
- yield word;
51
- }
52
- else {
53
- yield forbid + word;
54
- }
55
- }
56
- }
57
- //# sourceMappingURL=readHunspellFiles.js.map