cspell-dictionary 8.7.0 → 8.8.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.
@@ -83,7 +83,7 @@ class SpellingDictionaryCollectionImpl {
83
83
  this.dictionaries.forEach((dict) => dict.genSuggestions(collector, _suggestOptions));
84
84
  }
85
85
  getErrors() {
86
- return this.dictionaries.reduce((errors, dict) => errors.concat(dict.getErrors?.() || []), []);
86
+ return this.dictionaries.reduce((errors, dict) => [...errors, ...(dict.getErrors?.() || [])], []);
87
87
  }
88
88
  _isForbiddenInDict(word, ignoreCase) {
89
89
  return isWordForbiddenInAnyDictionary(this.dictionaries, word, ignoreCase);
@@ -12,7 +12,7 @@ export class SpellingDictionaryFromTrie {
12
12
  name;
13
13
  options;
14
14
  source;
15
- static cachedWordsLimit = 50000;
15
+ static cachedWordsLimit = 50_000;
16
16
  _size = 0;
17
17
  knownWords = new Set();
18
18
  unknownWords = new Set();
@@ -159,10 +159,8 @@ function findCache(fn, size = 2000) {
159
159
  const cache = createCache01(size);
160
160
  function find(word, useCompounds, ignoreCase) {
161
161
  const r = cache.get(word);
162
- if (r !== undefined) {
163
- if (r.useCompounds === useCompounds && r.ignoreCase === ignoreCase) {
164
- return r.findResult;
165
- }
162
+ if (r !== undefined && r.useCompounds === useCompounds && r.ignoreCase === ignoreCase) {
163
+ return r.findResult;
166
164
  }
167
165
  const findResult = fn(word, useCompounds, ignoreCase);
168
166
  cache.set(word, { useCompounds, ignoreCase, findResult });
@@ -1,4 +1,4 @@
1
- import assert from 'assert';
1
+ import assert from 'node:assert';
2
2
  import { appendToDef, createTyposDef } from './util.js';
3
3
  function assertString(v) {
4
4
  assert(typeof v === 'string', 'A string was expected.');
@@ -123,7 +123,7 @@ function splitEntry(line) {
123
123
  return line.split(typoSuggestionsSeparator, 2);
124
124
  }
125
125
  export function parseTyposFile(content) {
126
- const lines = splitIntoLines(content.replace(inlineComment, ''));
126
+ const lines = splitIntoLines(content.replaceAll(inlineComment, ''));
127
127
  return reduceToTyposDef(lines);
128
128
  }
129
129
  function isIterable(v) {
@@ -1,4 +1,5 @@
1
- function expand(pattern, options = { begin: '(', end: ')', sep: '|' }, start = 0) {
1
+ function expand(pattern, options, start = 0) {
2
+ const _options = options ?? { begin: '(', end: ')', sep: '|' };
2
3
  const len = pattern.length;
3
4
  const parts = [];
4
5
  function push(word) {
@@ -13,16 +14,16 @@ function expand(pattern, options = { begin: '(', end: ')', sep: '|' }, start = 0
13
14
  let curWord = '';
14
15
  while (i < len) {
15
16
  const ch = pattern[i++];
16
- if (ch === options.end) {
17
+ if (ch === _options.end) {
17
18
  break;
18
19
  }
19
- if (ch === options.begin) {
20
- const nested = expand(pattern, options, i);
20
+ if (ch === _options.begin) {
21
+ const nested = expand(pattern, _options, i);
21
22
  i = nested.idx;
22
23
  curWord = nested.parts.flatMap((p) => (Array.isArray(curWord) ? curWord.map((w) => w + p) : [curWord + p]));
23
24
  continue;
24
25
  }
25
- if (ch === options.sep) {
26
+ if (ch === _options.sep) {
26
27
  push(curWord);
27
28
  curWord = '';
28
29
  continue;
@@ -32,7 +33,7 @@ function expand(pattern, options = { begin: '(', end: ')', sep: '|' }, start = 0
32
33
  push(curWord);
33
34
  return { parts, idx: i };
34
35
  }
35
- export function expandBraces(pattern, options = { begin: '(', end: ')', sep: '|' }) {
36
- return expand(pattern, options).parts;
36
+ export function expandBraces(pattern, options) {
37
+ return expand(pattern, options ?? { begin: '(', end: ')', sep: '|' }).parts;
37
38
  }
38
39
  //# sourceMappingURL=braceExpansion.js.map
@@ -4,6 +4,6 @@
4
4
  * @returns - the escaped string.
5
5
  */
6
6
  export function escapeRegEx(s) {
7
- return s.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d');
7
+ return s.replaceAll(/[|\\{}()[\]^$+*?.]/g, '\\$&').replaceAll('-', '\\x2d');
8
8
  }
9
9
  //# sourceMappingURL=regexHelper.js.map
@@ -7,7 +7,7 @@ export function createMapper(repMap, ignoreCharset) {
7
7
  repMap = repMap || [];
8
8
  const charsetMap = charsetToRepMapRegEx(ignoreCharset);
9
9
  if (charsetMap) {
10
- repMap = repMap.concat(charsetMap);
10
+ repMap = [...repMap, ...charsetMap];
11
11
  }
12
12
  const filteredMap = repMap.filter(([match, _]) => !!match);
13
13
  if (!filteredMap.length) {
@@ -28,7 +28,7 @@ function charsetToRepMapRegEx(charset, replaceWith = '') {
28
28
  return undefined;
29
29
  return charset
30
30
  .split('|')
31
- .map((chars) => `[${chars.replace(/[\][\\]/g, '\\$&')}]`)
31
+ .map((chars) => `[${chars.replaceAll(/[\][\\]/g, '\\$&')}]`)
32
32
  .map((map) => [map, replaceWith]);
33
33
  }
34
34
  function charsetToRepMap(charset, replaceWith = '') {
@@ -53,11 +53,11 @@ function createMapperRegExp(repMap) {
53
53
  .map((s) => {
54
54
  try {
55
55
  // fix up any nested ()
56
- const r = s.match(/\(/) ? s.replace(/\((?=.*\))/g, '(?:').replace(/\(\?:\?/g, '(?') : s;
56
+ const r = /\(/.test(s) ? s.replaceAll(/\((?=.*\))/g, '(?:').replaceAll('(?:?', '(?') : s;
57
57
  new RegExp(r);
58
58
  s = r;
59
59
  }
60
- catch (err) {
60
+ catch {
61
61
  return escapeRegEx(s);
62
62
  }
63
63
  return s;
@@ -125,7 +125,7 @@ function calcAllEdits(root, word) {
125
125
  return edits;
126
126
  }
127
127
  function createTrie(repMap, ignoreCharset) {
128
- const combined = [repMap, charsetToRepMap(ignoreCharset)].filter(isDefined).flatMap((a) => a);
128
+ const combined = [repMap, charsetToRepMap(ignoreCharset)].filter(isDefined).flat();
129
129
  const expanded = expandReplaceMap(combined);
130
130
  const trieRoot = Object.create(null);
131
131
  expanded.forEach(([match, replaceWith]) => addToTrie(trieRoot, match, replaceWith));
package/dist/util/text.js CHANGED
@@ -3,10 +3,10 @@ const regExAllUpper = /^(?:\p{Lu}\p{M}?)+$/u;
3
3
  const regExAllLower = /^(?:\p{Ll}\p{M}?)+$/u;
4
4
  const regExAccents = /\p{M}/gu;
5
5
  export function isUpperCase(word) {
6
- return !!word.match(regExAllUpper);
6
+ return !!regExAllUpper.test(word);
7
7
  }
8
8
  export function isLowerCase(word) {
9
- return !!word.match(regExAllLower);
9
+ return !!regExAllLower.test(word);
10
10
  }
11
11
  export function isFirstCharacterUpper(word) {
12
12
  return isUpperCase(word.slice(0, 1));
@@ -21,13 +21,13 @@ export function lcFirst(word) {
21
21
  return word.slice(0, 1).toLowerCase() + word.slice(1);
22
22
  }
23
23
  export function matchCase(example, word) {
24
- if (example.match(regExFirstUpper)) {
24
+ if (regExFirstUpper.test(example)) {
25
25
  return word.slice(0, 1).toUpperCase() + word.slice(1).toLowerCase();
26
26
  }
27
- if (example.match(regExAllLower)) {
27
+ if (regExAllLower.test(example)) {
28
28
  return word.toLowerCase();
29
29
  }
30
- if (example.match(regExAllUpper)) {
30
+ if (regExAllUpper.test(example)) {
31
31
  return word.toUpperCase();
32
32
  }
33
33
  if (isFirstCharacterUpper(example)) {
@@ -39,9 +39,9 @@ export function matchCase(example, word) {
39
39
  return word;
40
40
  }
41
41
  export function removeAccents(text) {
42
- return text.normalize('NFD').replace(regExAccents, '');
42
+ return text.normalize('NFD').replaceAll(regExAccents, '');
43
43
  }
44
44
  export function removeUnboundAccents(text) {
45
- return text.replace(regExAccents, '');
45
+ return text.replaceAll(regExAccents, '');
46
46
  }
47
47
  //# sourceMappingURL=text.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cspell-dictionary",
3
- "version": "8.7.0",
3
+ "version": "8.8.0",
4
4
  "description": "A spelling dictionary library useful for checking words and getting suggestions.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -47,11 +47,11 @@
47
47
  "node": ">=18"
48
48
  },
49
49
  "dependencies": {
50
- "@cspell/cspell-pipe": "8.7.0",
51
- "@cspell/cspell-types": "8.7.0",
52
- "cspell-trie-lib": "8.7.0",
50
+ "@cspell/cspell-pipe": "8.8.0",
51
+ "@cspell/cspell-types": "8.8.0",
52
+ "cspell-trie-lib": "8.8.0",
53
53
  "fast-equals": "^5.0.1",
54
54
  "gensequence": "^7.0.0"
55
55
  },
56
- "gitHead": "5318079ed11fe77e981287ecf1c40d6f28dd91ed"
56
+ "gitHead": "a42bce675c00cb2d51809b3ae3894119ea4f5ce7"
57
57
  }