cspell-lib 10.4.0-alpha.1 → 10.4.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.
|
@@ -5,6 +5,12 @@ export declare function normalizeLanguageId(langId: LanguageId | LanguageId[]):
|
|
|
5
5
|
export declare function normalizeLocale(locale: LocaleId | LocaleId[]): Set<LocaleId>;
|
|
6
6
|
export declare function normalizeLocaleIntl(locale: LocaleId | LocaleId[]): Set<LocaleId>;
|
|
7
7
|
export declare function isLocaleInSet(locale: LocaleId | LocaleId[], setOfLocals: Set<LocaleId>): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Normalize a locale for use with `Intl` and `toLocaleLowerCase`. Locales that aren't valid are dropped.
|
|
10
|
+
* @param locale - a locale or a list of locales, for example `en,tr_TR`.
|
|
11
|
+
* @returns the valid locales, or `undefined` if there are none.
|
|
12
|
+
*/
|
|
13
|
+
export declare function normalizeLocaleForIntl(locale: LocaleId | LocaleId[] | undefined): string | string[] | undefined;
|
|
8
14
|
/**
|
|
9
15
|
* Test if a locale should be ok with Intl
|
|
10
16
|
* @param locale - locale string
|
|
@@ -61,6 +61,21 @@ export function isLocaleInSet(locale, setOfLocals) {
|
|
|
61
61
|
const locales = normalizeLocale(locale);
|
|
62
62
|
return doSetsIntersect(locales, setOfLocals);
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Normalize a locale for use with `Intl` and `toLocaleLowerCase`. Locales that aren't valid are dropped.
|
|
66
|
+
* @param locale - a locale or a list of locales, for example `en,tr_TR`.
|
|
67
|
+
* @returns the valid locales, or `undefined` if there are none.
|
|
68
|
+
*/
|
|
69
|
+
export function normalizeLocaleForIntl(locale) {
|
|
70
|
+
if (!locale)
|
|
71
|
+
return undefined;
|
|
72
|
+
const locales = [...normalizeLocaleIntl(locale)].filter((locale) => isValidLocaleIntlFormat(locale));
|
|
73
|
+
if (!locales.length)
|
|
74
|
+
return undefined;
|
|
75
|
+
if (locales.length === 1)
|
|
76
|
+
return locales[0];
|
|
77
|
+
return locales;
|
|
78
|
+
}
|
|
64
79
|
const regExpValidIntlLocaleStrict = /^[a-z]{2}(-[A-Z]{2})?$/;
|
|
65
80
|
const regExpValidIntlLocale = new RegExp(regExpValidIntlLocaleStrict, 'i');
|
|
66
81
|
/**
|
|
@@ -56,6 +56,7 @@ import { createFailedToLoadDictionary, createFlagWordsDictionary, createFlagWord
|
|
|
56
56
|
import { compareStats, toFileURL, urlBasename } from 'cspell-io';
|
|
57
57
|
import { measurePerf } from '../../perf/index.js';
|
|
58
58
|
import { isDictionaryDefinitionInlineInternal, isDictionaryFileDefinitionInternal } from '../../Settings/index.js';
|
|
59
|
+
import { normalizeLocaleForIntl } from '../../Settings/LanguageSettings.js';
|
|
59
60
|
import { AutoResolveWeakCache, AutoResolveWeakWeakCache } from '../../util/AutoResolve.js';
|
|
60
61
|
import { toError } from '../../util/errors.js';
|
|
61
62
|
import { SimpleCache } from '../../util/simpleCache.js';
|
|
@@ -260,7 +261,7 @@ async function legacyWordList(reader, filename, options) {
|
|
|
260
261
|
if (options.kind === 'suggest-words') {
|
|
261
262
|
return createSuggestDictionary([...words], options.name, filename.toString());
|
|
262
263
|
}
|
|
263
|
-
return createSpellingDictionary(words, options.name, filename.toString(),
|
|
264
|
+
return createSpellingDictionary(words, options.name, filename.toString(), toSpellingDictionaryOptions(options), true);
|
|
264
265
|
}
|
|
265
266
|
catch (e_1) {
|
|
266
267
|
env_1.error = e_1;
|
|
@@ -283,7 +284,7 @@ async function wordsPerLineWordList(reader, filename, options) {
|
|
|
283
284
|
if (options.kind === 'suggest-words') {
|
|
284
285
|
return createSuggestDictionary([...words], options.name, filename.href);
|
|
285
286
|
}
|
|
286
|
-
return createSpellingDictionary(words, options.name, filename.href,
|
|
287
|
+
return createSpellingDictionary(words, options.name, filename.href, toSpellingDictionaryOptions(options), true);
|
|
287
288
|
}
|
|
288
289
|
async function loadSimpleWordList(reader, filename, options) {
|
|
289
290
|
const env_2 = { stack: [], error: void 0, hasError: false };
|
|
@@ -296,7 +297,7 @@ async function loadSimpleWordList(reader, filename, options) {
|
|
|
296
297
|
if (options.kind === 'suggest-words') {
|
|
297
298
|
return createSuggestDictionary(lines, options.name, filename.href);
|
|
298
299
|
}
|
|
299
|
-
return createSpellingDictionary(lines, options.name, filename.href,
|
|
300
|
+
return createSpellingDictionary(lines, options.name, filename.href, toSpellingDictionaryOptions(options));
|
|
300
301
|
}
|
|
301
302
|
catch (e_2) {
|
|
302
303
|
env_2.error = e_2;
|
|
@@ -317,7 +318,7 @@ async function loadTrie(reader, filename, options) {
|
|
|
317
318
|
if (options.kind === 'suggest-words') {
|
|
318
319
|
return createSuggestDictionaryFromTrieFile(content, options.name, filename.href);
|
|
319
320
|
}
|
|
320
|
-
return createSpellingDictionaryFromTrieFile(content, options.name, filename.href,
|
|
321
|
+
return createSpellingDictionaryFromTrieFile(content, options.name, filename.href, toSpellingDictionaryOptions(options));
|
|
321
322
|
}
|
|
322
323
|
catch (e_3) {
|
|
323
324
|
env_3.error = e_3;
|
|
@@ -327,6 +328,21 @@ async function loadTrie(reader, filename, options) {
|
|
|
327
328
|
__disposeResources(env_3);
|
|
328
329
|
}
|
|
329
330
|
}
|
|
331
|
+
/**
|
|
332
|
+
* The options for a spelling dictionary: the effect of `kind`, and the dictionary's locale, normalized once here so
|
|
333
|
+
* lookups don't have to. A locale that isn't valid is dropped.
|
|
334
|
+
*/
|
|
335
|
+
function toSpellingDictionaryOptions(options) {
|
|
336
|
+
const opts = applyKind(options);
|
|
337
|
+
if (!isDictionaryFileDefinitionInternal(opts))
|
|
338
|
+
return opts;
|
|
339
|
+
const locales = normalizeLocaleForIntl(opts.dictionaryInformation?.locale);
|
|
340
|
+
const locale = Array.isArray(locales) ? locales[0] : locales;
|
|
341
|
+
if (!locale)
|
|
342
|
+
return opts;
|
|
343
|
+
// `weightMap` is a getter on some definitions, so copy it explicitly.
|
|
344
|
+
return { ...opts, weightMap: opts.weightMap, locale };
|
|
345
|
+
}
|
|
330
346
|
/**
|
|
331
347
|
* Apply the effect of `kind` on the options passed to a normal `words` dictionary loader.
|
|
332
348
|
* `flag-words` and `suggest-words` are handled by the callers directly since they use a different
|
package/dist/lib/suggestions.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import assert from 'node:assert';
|
|
2
2
|
import { satisfiesCSpellConfigFile } from 'cspell-config-lib';
|
|
3
3
|
import { finalizeSettings, getDefaultSettings, getGlobalSettingsAsync, mergeSettings, resolveConfigFileImports, } from './Settings/index.js';
|
|
4
|
-
import { calcSettingsForLanguageId,
|
|
4
|
+
import { calcSettingsForLanguageId, normalizeLocaleForIntl } from './Settings/LanguageSettings.js';
|
|
5
5
|
import { getDictionaryInternal, refreshDictionaryCache } from './SpellingDictionary/index.js';
|
|
6
6
|
import { createAutoResolveCache } from './util/AutoResolve.js';
|
|
7
7
|
import { memoizeLastCall } from './util/memoizeLastCall.js';
|
|
@@ -58,7 +58,7 @@ async function _suggestionsForWordAsync(word, options, settings, dictionaryColle
|
|
|
58
58
|
: settings;
|
|
59
59
|
const opts = { ignoreCase, numChanges, numSuggestions, includeTies };
|
|
60
60
|
const suggestionsByDictionary = dictionaryCollection.dictionaries.flatMap((dict) => dict.suggest(word, opts).map((r) => ({ ...r, dictName: dict.name })));
|
|
61
|
-
const locale =
|
|
61
|
+
const locale = normalizeLocaleForIntl(language || config.language || undefined);
|
|
62
62
|
const collator = Intl.Collator(locale);
|
|
63
63
|
const combined = limitResults(combine(suggestionsByDictionary.sort((a, b) => a.cost - b.cost || collator.compare(a.word, b.word))), numSuggestions, includeTies);
|
|
64
64
|
const sugsAdjusted = calcSuggestionAdjustedToToMatchCase(word, combined, locale, ignoreCase, extendsDictionaryCollection);
|
|
@@ -87,18 +87,8 @@ function combine(suggestions) {
|
|
|
87
87
|
}
|
|
88
88
|
return [...words.values()];
|
|
89
89
|
}
|
|
90
|
-
function adjustLocale(locale) {
|
|
91
|
-
if (!locale)
|
|
92
|
-
return undefined;
|
|
93
|
-
const locales = [...normalizeLocaleIntl(locale)].filter((locale) => isValidLocaleIntlFormat(locale));
|
|
94
|
-
if (!locales.length)
|
|
95
|
-
return undefined;
|
|
96
|
-
if (locales.length === 1)
|
|
97
|
-
return locales[0];
|
|
98
|
-
return locales;
|
|
99
|
-
}
|
|
100
90
|
export function calcSuggestionAdjustedToToMatchCase(originalWord, sugs, locale, ignoreCase, dict) {
|
|
101
|
-
locale =
|
|
91
|
+
locale = normalizeLocaleForIntl(locale);
|
|
102
92
|
const knownSugs = new Set(sugs.map((sug) => sug.word));
|
|
103
93
|
const matchStyle = { ...analyzeCase(originalWord), locale, ignoreCase };
|
|
104
94
|
/* Add adjusted words */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cspell-lib",
|
|
3
|
-
"version": "10.4.0
|
|
3
|
+
"version": "10.4.0",
|
|
4
4
|
"description": "A library of useful functions used across various cspell tools.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -75,22 +75,22 @@
|
|
|
75
75
|
"watch": "tsc -p . --watch"
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
|
-
"@cspell/cspell-bundled-dicts": "10.4.0
|
|
79
|
-
"@cspell/cspell-performance-monitor": "10.4.0
|
|
80
|
-
"@cspell/cspell-pipe": "10.4.0
|
|
81
|
-
"@cspell/cspell-resolver": "10.4.0
|
|
82
|
-
"@cspell/cspell-types": "10.4.0
|
|
83
|
-
"@cspell/dynamic-import": "10.4.0
|
|
84
|
-
"@cspell/filetypes": "10.4.0
|
|
85
|
-
"@cspell/rpc": "10.4.0
|
|
86
|
-
"@cspell/strong-weak-map": "10.4.0
|
|
87
|
-
"@cspell/url": "10.4.0
|
|
88
|
-
"cspell-config-lib": "10.4.0
|
|
89
|
-
"cspell-dictionary": "10.4.0
|
|
90
|
-
"cspell-glob": "10.4.0
|
|
91
|
-
"cspell-grammar": "10.4.0
|
|
92
|
-
"cspell-io": "10.4.0
|
|
93
|
-
"cspell-trie-lib": "10.4.0
|
|
78
|
+
"@cspell/cspell-bundled-dicts": "10.4.0",
|
|
79
|
+
"@cspell/cspell-performance-monitor": "10.4.0",
|
|
80
|
+
"@cspell/cspell-pipe": "10.4.0",
|
|
81
|
+
"@cspell/cspell-resolver": "10.4.0",
|
|
82
|
+
"@cspell/cspell-types": "10.4.0",
|
|
83
|
+
"@cspell/dynamic-import": "10.4.0",
|
|
84
|
+
"@cspell/filetypes": "10.4.0",
|
|
85
|
+
"@cspell/rpc": "10.4.0",
|
|
86
|
+
"@cspell/strong-weak-map": "10.4.0",
|
|
87
|
+
"@cspell/url": "10.4.0",
|
|
88
|
+
"cspell-config-lib": "10.4.0",
|
|
89
|
+
"cspell-dictionary": "10.4.0",
|
|
90
|
+
"cspell-glob": "10.4.0",
|
|
91
|
+
"cspell-grammar": "10.4.0",
|
|
92
|
+
"cspell-io": "10.4.0",
|
|
93
|
+
"cspell-trie-lib": "10.4.0",
|
|
94
94
|
"env-paths": "^4.0.0",
|
|
95
95
|
"gensequence": "^8.0.8",
|
|
96
96
|
"import-fresh": "^4.0.1",
|
|
@@ -100,16 +100,16 @@
|
|
|
100
100
|
"xdg-basedir": "^5.1.0"
|
|
101
101
|
},
|
|
102
102
|
"devDependencies": {
|
|
103
|
-
"@cspell/dict-cpp": "^7.1.
|
|
103
|
+
"@cspell/dict-cpp": "^7.1.3",
|
|
104
104
|
"@cspell/dict-csharp": "^4.0.8",
|
|
105
105
|
"@cspell/dict-css": "^4.1.2",
|
|
106
|
-
"@cspell/dict-en_us": "^4.4.
|
|
107
|
-
"@cspell/dict-fa-ir": "^4.0.
|
|
106
|
+
"@cspell/dict-en_us": "^4.4.41",
|
|
107
|
+
"@cspell/dict-fa-ir": "^4.0.6",
|
|
108
108
|
"@cspell/dict-fr-fr": "^2.3.2",
|
|
109
109
|
"@cspell/dict-html": "^4.0.16",
|
|
110
110
|
"@cspell/dict-nl-nl": "^2.4.2",
|
|
111
111
|
"@cspell/dict-python": "^4.5.2",
|
|
112
|
-
"@cspell/dict-th-th": "^1.0.
|
|
112
|
+
"@cspell/dict-th-th": "^1.0.3",
|
|
113
113
|
"@cspell/dictionary-bundler-plugin": "",
|
|
114
114
|
"@types/configstore": "^6.0.2",
|
|
115
115
|
"comment-json": "^5.0.0",
|
|
@@ -122,5 +122,5 @@
|
|
|
122
122
|
"engines": {
|
|
123
123
|
"node": ">=22.18.0"
|
|
124
124
|
},
|
|
125
|
-
"gitHead": "
|
|
125
|
+
"gitHead": "7e2bbb5e866c827ac5d2cf6b84bf3e1a016d0823"
|
|
126
126
|
}
|