cspell-lib 6.4.2 → 6.6.1-alpha.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.
@@ -15,8 +15,25 @@ export declare const defaultConfigFilenames: readonly string[];
15
15
  * @param pathToSettingsFile - path to the source file of the configuration settings.
16
16
  */
17
17
  declare function normalizeSettings(rawSettings: CSpellSettingsWST, pathToSettingsFile: string, pnpSettings: PnPSettings): CSpellSettingsI;
18
+ /**
19
+ * Read / import a cspell configuration file.
20
+ * @param filename - the path to the file.
21
+ * Supported types: json, yaml, js, and cjs. ES Modules are not supported.
22
+ * - absolute path `/absolute/path/to/file`
23
+ * - relative path `./path/to/file` (relative to the current working directory)
24
+ * - package `@cspell/dict-typescript/cspell-ext.json`
25
+ */
18
26
  export declare function readSettings(filename: string): CSpellSettingsI;
19
27
  export declare function readSettings(filename: string, defaultValues: CSpellSettingsWST): CSpellSettingsI;
28
+ /**
29
+ * Read / import a cspell configuration file.
30
+ * @param filename - the path to the file.
31
+ * Supported types: json, yaml, js, and cjs. ES Modules are not supported.
32
+ * - absolute path `/absolute/path/to/file`
33
+ * - relative path `./path/to/file` (relative to `relativeTo`)
34
+ * - package `@cspell/dict-typescript/cspell-ext.json` searches for node_modules relative to `relativeTo`
35
+ * @param relativeTo - absolute path to start searching for relative files or node_modules.
36
+ */
20
37
  export declare function readSettings(filename: string, relativeTo: string): CSpellSettingsI;
21
38
  export declare function readSettings(filename: string, relativeTo: string, defaultValues: CSpellSettingsWST): CSpellSettingsI;
22
39
  export declare function searchForConfig(searchFrom: string | undefined, pnpSettings?: PnPSettings): Promise<CSpellSettingsI | undefined>;
@@ -101,7 +101,12 @@ const cachedFiles = new Map();
101
101
  */
102
102
  function readConfig(fileRef) {
103
103
  // cspellConfigExplorerSync
104
- const { filename } = fileRef;
104
+ const { filename, error } = fileRef;
105
+ if (error) {
106
+ fileRef.error =
107
+ error instanceof ImportError_1.ImportError ? error : new ImportError_1.ImportError(`Failed to read config file: "${filename}"`, error);
108
+ return { __importRef: fileRef };
109
+ }
105
110
  const s = {};
106
111
  try {
107
112
  const r = cspellConfigExplorerSync.load(filename);
@@ -191,9 +196,8 @@ function mergeSourceList(orig, append) {
191
196
  }
192
197
  function importSettings(fileRef, defaultValues, pnpSettings) {
193
198
  defaultValues = defaultValues ?? defaultSettings;
194
- let { filename } = fileRef;
195
- filename = path.resolve(filename);
196
- const importRef = { ...fileRef, filename };
199
+ const { filename } = fileRef;
200
+ const importRef = { ...fileRef };
197
201
  const cached = cachedFiles.get(filename);
198
202
  if (cached) {
199
203
  const cachedImportRef = cached.__importRef || importRef;
@@ -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.6.1-alpha.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",
@@ -14,15 +14,15 @@
14
14
  ],
15
15
  "scripts": {
16
16
  "clean": "rimraf dist temp coverage .tsbuildinfo",
17
- "build": "npm run compile && npm run build-api",
17
+ "build": "pnpm run compile && pnpm run build-api",
18
18
  "build-dev": "tsc -p tsconfig.dev.json",
19
19
  "build-api": "rollup -c api/rollup.config.mjs",
20
- "clean-build": "npm run clean && npm run build",
20
+ "clean-build": "pnpm run clean && pnpm run build",
21
21
  "compile": "tsc -p .",
22
22
  "watch": "tsc --watch -p .",
23
23
  "coverage": "jest --coverage",
24
24
  "test-watch": "jest --watch",
25
- "prepublishOnly": "npm run clean-build && npm test",
25
+ "prepublishOnly": "pnpm run clean-build",
26
26
  "test": "jest",
27
27
  "update-snapshot": "jest --updateSnapshot"
28
28
  },
@@ -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",
52
- "@cspell/cspell-pipe": "^6.4.2",
53
- "@cspell/cspell-types": "^6.4.2",
51
+ "@cspell/cspell-bundled-dicts": "^6.6.1-alpha.0",
52
+ "@cspell/cspell-pipe": "^6.6.1-alpha.0",
53
+ "@cspell/cspell-types": "^6.6.1-alpha.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
- "cspell-glob": "^6.4.2",
59
- "cspell-grammar": "^6.4.2",
60
- "cspell-io": "^6.4.2",
61
- "cspell-trie-lib": "^6.4.2",
58
+ "cspell-glob": "^6.6.1-alpha.0",
59
+ "cspell-grammar": "^6.6.1-alpha.0",
60
+ "cspell-io": "^6.6.1-alpha.0",
61
+ "cspell-trie-lib": "^6.6.1-alpha.0",
62
62
  "fast-equals": "^4.0.1",
63
63
  "find-up": "^5.0.0",
64
64
  "fs-extra": "^10.1.0",
@@ -84,14 +84,14 @@
84
84
  "@types/configstore": "^5.0.1",
85
85
  "@types/fs-extra": "^9.0.13",
86
86
  "@types/jest": "^28.1.6",
87
- "@types/node": "^18.6.1",
87
+ "@types/node": "^18.6.5",
88
88
  "cspell-dict-nl-nl": "^1.1.2",
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.2",
93
93
  "rollup-plugin-dts": "^4.2.2",
94
94
  "ts-jest": "^28.0.7"
95
95
  },
96
- "gitHead": "1f7481fd7d6a561de92ba49870da6eb1441a9d20"
96
+ "gitHead": "4c7eb0181563a4459da772fd736b252f07f020b9"
97
97
  }