cspell-lib 6.4.2 → 6.5.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.
@@ -14,6 +14,7 @@ export declare class SpellingDictionaryFromTrie implements SpellingDictionary {
14
14
  readonly type = "SpellingDictionaryFromTrie";
15
15
  readonly isDictionaryCaseSensitive: boolean;
16
16
  readonly containsNoSuggestWords: boolean;
17
+ readonly ignoreCharactersRegExp: RegExp | undefined;
17
18
  private weightMap;
18
19
  constructor(trie: Trie, name: string, options: SpellingDictionaryOptions, source?: string, size?: number);
19
20
  get size(): number;
@@ -22,6 +23,7 @@ export declare class SpellingDictionaryFromTrie implements SpellingDictionary {
22
23
  private resolveOptions;
23
24
  private _find;
24
25
  private findAnyForm;
26
+ private _findAnyForm;
25
27
  isNoSuggestWord(word: string, options?: HasOptions): boolean;
26
28
  isForbidden(word: string): boolean;
27
29
  suggest(word: string, numSuggestions?: number, compoundMethod?: CompoundWordsMethod, numChanges?: number, ignoreCase?: boolean): SuggestionResult[];
@@ -6,6 +6,7 @@ const Settings_1 = require("../Settings");
6
6
  const Memorizer_1 = require("../util/Memorizer");
7
7
  const repMap_1 = require("../util/repMap");
8
8
  const util_1 = require("../util/util");
9
+ const charset_1 = require("./charset");
9
10
  const SpellingDictionaryMethods_1 = require("./SpellingDictionaryMethods");
10
11
  class SpellingDictionaryFromTrie {
11
12
  constructor(trie, name, options, source = 'from trie', size) {
@@ -23,6 +24,7 @@ class SpellingDictionaryFromTrie {
23
24
  this.containsNoSuggestWords = options.noSuggest || false;
24
25
  this._size = size || 0;
25
26
  this.weightMap = options.weightMap || (0, SpellingDictionaryMethods_1.createWeightMapFromDictionaryInformation)(options.dictionaryInformation);
27
+ this.ignoreCharactersRegExp = (0, charset_1.charsetToRegExp)(this.options.dictionaryInformation?.ignore);
26
28
  }
27
29
  get size() {
28
30
  if (!this._size) {
@@ -60,6 +62,20 @@ class SpellingDictionaryFromTrie {
60
62
  return { useCompounds, ignoreCase };
61
63
  }
62
64
  findAnyForm(word, useCompounds, ignoreCase) {
65
+ const outerForms = new Set([word]);
66
+ if (this.ignoreCharactersRegExp) {
67
+ outerForms.add(word.replace(this.ignoreCharactersRegExp, ''));
68
+ outerForms.add(word.normalize('NFD').replace(this.ignoreCharactersRegExp, ''));
69
+ outerForms.add(word.normalize('NFC').replace(this.ignoreCharactersRegExp, ''));
70
+ }
71
+ for (const form of outerForms) {
72
+ const r = this._findAnyForm(form, useCompounds, ignoreCase);
73
+ if (r)
74
+ return r;
75
+ }
76
+ return undefined;
77
+ }
78
+ _findAnyForm(word, useCompounds, ignoreCase) {
63
79
  const mWord = this.mapWord(word.normalize('NFC'));
64
80
  const opts = { caseSensitive: !ignoreCase };
65
81
  const findResult = this.trie.findWord(mWord, opts);
@@ -0,0 +1,3 @@
1
+ import { CharacterSet } from '@cspell/cspell-types';
2
+ export declare function charsetToRegExp(charset: CharacterSet | undefined): RegExp | undefined;
3
+ //# sourceMappingURL=charset.d.ts.map
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.charsetToRegExp = void 0;
4
+ function charsetToRegExp(charset) {
5
+ if (!charset)
6
+ return undefined;
7
+ try {
8
+ const reg = `[${charset.replace(/[\][\\]/g, '\\$&')}]`;
9
+ return new RegExp(reg, 'g');
10
+ }
11
+ catch (e) {
12
+ return undefined;
13
+ }
14
+ }
15
+ exports.charsetToRegExp = charsetToRegExp;
16
+ //# sourceMappingURL=charset.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cspell-lib",
3
- "version": "6.4.2",
3
+ "version": "6.5.0",
4
4
  "description": "A library of useful functions used across various cspell tools.",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -48,17 +48,17 @@
48
48
  },
49
49
  "homepage": "https://github.com/streetsidesoftware/cspell#readme",
50
50
  "dependencies": {
51
- "@cspell/cspell-bundled-dicts": "^6.4.2",
51
+ "@cspell/cspell-bundled-dicts": "^6.5.0",
52
52
  "@cspell/cspell-pipe": "^6.4.2",
53
- "@cspell/cspell-types": "^6.4.2",
53
+ "@cspell/cspell-types": "^6.5.0",
54
54
  "clear-module": "^4.1.2",
55
55
  "comment-json": "^4.2.2",
56
56
  "configstore": "^5.0.1",
57
57
  "cosmiconfig": "^7.0.1",
58
58
  "cspell-glob": "^6.4.2",
59
- "cspell-grammar": "^6.4.2",
60
- "cspell-io": "^6.4.2",
61
- "cspell-trie-lib": "^6.4.2",
59
+ "cspell-grammar": "^6.5.0",
60
+ "cspell-io": "^6.5.0",
61
+ "cspell-trie-lib": "^6.5.0",
62
62
  "fast-equals": "^4.0.1",
63
63
  "find-up": "^5.0.0",
64
64
  "fs-extra": "^10.1.0",
@@ -89,9 +89,9 @@
89
89
  "jest": "^28.1.3",
90
90
  "lorem-ipsum": "^2.0.8",
91
91
  "rimraf": "^3.0.2",
92
- "rollup": "^2.77.0",
92
+ "rollup": "^2.77.1",
93
93
  "rollup-plugin-dts": "^4.2.2",
94
94
  "ts-jest": "^28.0.7"
95
95
  },
96
- "gitHead": "1f7481fd7d6a561de92ba49870da6eb1441a9d20"
96
+ "gitHead": "65c80b01e17bb0d74b57ef8b29309684a8588e27"
97
97
  }