cspell-lib 5.12.0 → 5.12.4

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.
@@ -95,6 +95,7 @@ exports.languageExtensionDefinitions = [
95
95
  { id: 'typescript', extensions: ['.ts'] },
96
96
  { id: 'typescriptreact', extensions: ['.tsx'] },
97
97
  { id: 'vb', extensions: ['.vb', '.brs', '.vbs', '.bas'] },
98
+ { id: 'vue', extensions: ['.vue'] },
98
99
  {
99
100
  id: 'xml',
100
101
  extensions: [
@@ -25,7 +25,7 @@ const Text = __importStar(require("../util/text"));
25
25
  const CSpellSettingsServer_1 = require("./CSpellSettingsServer");
26
26
  // cspell:ignore gimuy
27
27
  const regExMatchRegEx = /\/.*\/[gimuy]*/;
28
- const regExInFileSettings = [/(?:spell-?checker|cSpell)::?\s*(.*)/gi, /(LocalWords:?\s+.*)/g];
28
+ const regExInFileSettings = [/(?:spell-?checker|c?spell)::?(.*)/gi, /(LocalWords:?.*)/g];
29
29
  function getInDocumentSettings(text) {
30
30
  const settings = getPossibleInDocSettings(text)
31
31
  .concatMap((a) => parseSettingMatch(a))
@@ -36,17 +36,18 @@ function getInDocumentSettings(text) {
36
36
  }
37
37
  exports.getInDocumentSettings = getInDocumentSettings;
38
38
  function parseSettingMatch(matchArray) {
39
- const [, possibleSetting = ''] = matchArray;
39
+ const [, match = ''] = matchArray;
40
+ const possibleSetting = match.trim();
40
41
  const settingParsers = [
41
42
  [/^(?:enable|disable)(?:allow)?CompoundWords/i, parseCompoundWords],
42
43
  [/^words?\s/i, parseWords],
43
44
  [/^ignore(?:words?)?\s/i, parseIgnoreWords],
44
45
  [/^ignore_?Reg_?Exp\s+.+$/i, parseIgnoreRegExp],
45
46
  [/^include_?Reg_?Exp\s+.+$/i, parseIncludeRegExp],
46
- [/^locale?\s/i, parseLocal],
47
- [/^language\s/i, parseLocal],
47
+ [/^locale?\s/i, parseLocale],
48
+ [/^language\s/i, parseLocale],
48
49
  [/^dictionaries\s/i, parseDictionaries],
49
- [/^LocalWords:/, parseWords],
50
+ [/^LocalWords:/, (w) => parseWords(w.replace(/LocalWords:?/gi, ' '))],
50
51
  ];
51
52
  return settingParsers
52
53
  .filter(([regex]) => regex.test(possibleSetting))
@@ -61,9 +62,9 @@ function parseWords(match) {
61
62
  const words = match.split(/[,\s]+/g).slice(1);
62
63
  return { id: 'in-doc-words', words };
63
64
  }
64
- function parseLocal(match) {
65
- const parts = match.trim().split(/\s+/);
66
- const language = parts.slice(1).join(' ');
65
+ function parseLocale(match) {
66
+ const parts = match.trim().split(/[\s,]+/);
67
+ const language = parts.slice(1).join(',');
67
68
  return language ? { id: 'in-doc-local', language } : {};
68
69
  }
69
70
  function parseIgnoreWords(match) {
@@ -27,13 +27,19 @@ function getDefaultLanguageSettings() {
27
27
  return defaultLanguageSettings;
28
28
  }
29
29
  exports.getDefaultLanguageSettings = getDefaultLanguageSettings;
30
+ function localesToList(locales) {
31
+ locales = typeof locales !== 'string' ? locales.join(',') : locales;
32
+ return stringToList(locales.replace(/\s+/g, ','));
33
+ }
30
34
  function stringToList(sList) {
31
- if (typeof sList === 'string') {
32
- sList = sList
33
- .replace(/[|;]/g, ',')
34
- .split(',')
35
- .map((s) => s.trim());
35
+ if (typeof sList !== 'string') {
36
+ sList = sList.join(',');
36
37
  }
38
+ sList = sList
39
+ .replace(/[|;]/g, ',')
40
+ .split(',')
41
+ .map((s) => s.trim())
42
+ .filter((s) => !!s);
37
43
  return sList;
38
44
  }
39
45
  function normalizeLanguageId(langId) {
@@ -45,7 +51,7 @@ function normalizeLanguageIdToString(langId) {
45
51
  return [...normalizeLanguageId(langId)].join(',');
46
52
  }
47
53
  function normalizeLocale(locale) {
48
- locale = stringToList(locale);
54
+ locale = localesToList(locale);
49
55
  return new Set(locale.map((locale) => locale.toLowerCase().replace(/[^a-z]/g, '')));
50
56
  }
51
57
  exports.normalizeLocale = normalizeLocale;
@@ -14,6 +14,7 @@ export interface Loaders {
14
14
  S: Loader;
15
15
  C: Loader;
16
16
  T: Loader;
17
+ W: Loader;
17
18
  default: Loader;
18
19
  }
19
20
  export declare function loadDictionary(uri: string, options: DictionaryDefinitionPreferred): Promise<SpellingDictionary>;
@@ -26,10 +26,12 @@ const fileReader_1 = require("../util/fileReader");
26
26
  const createSpellingDictionary_1 = require("./createSpellingDictionary");
27
27
  const SpellingDictionaryError_1 = require("./SpellingDictionaryError");
28
28
  const SpellingDictionaryFromTrie_1 = require("./SpellingDictionaryFromTrie");
29
+ const gensequence_1 = require("gensequence");
29
30
  const MAX_AGE = 10000;
30
31
  const loaders = {
31
32
  S: loadSimpleWordList,
32
- C: loadSimpleWordList,
33
+ C: legacyWordList,
34
+ W: wordsPerLineWordList,
33
35
  T: loadTrie,
34
36
  default: loadSimpleWordList,
35
37
  };
@@ -47,7 +49,7 @@ function loadDictionary(uri, options) {
47
49
  exports.loadDictionary = loadDictionary;
48
50
  const importantOptionKeys = ['noSuggest', 'useCompounds'];
49
51
  function calcKey(uri, options) {
50
- const loaderType = determineType(uri);
52
+ const loaderType = determineType(uri, options);
51
53
  const optValues = importantOptionKeys.map((k) => { var _a; return ((_a = options[k]) === null || _a === void 0 ? void 0 : _a.toString()) || ''; });
52
54
  const parts = [uri, loaderType].concat(optValues);
53
55
  return parts.join('|');
@@ -92,16 +94,38 @@ function loadEntry(uri, options, now = Date.now()) {
92
94
  dictionary,
93
95
  };
94
96
  }
95
- function determineType(uri) {
96
- const defType = uri.endsWith('.trie.gz') ? 'T' : uri.endsWith('.txt.gz') ? 'S' : 'S';
97
+ function determineType(uri, opts) {
98
+ const t = (opts.type && opts.type in loaders && opts.type) || 'S';
99
+ const defLoaderType = t;
100
+ const defType = uri.endsWith('.trie.gz') ? 'T' : uri.endsWith('.txt.gz') ? defLoaderType : defLoaderType;
97
101
  const regTrieTest = /\.trie\b/i;
98
102
  return regTrieTest.test(uri) ? 'T' : defType;
99
103
  }
100
104
  function load(uri, options) {
101
- const type = determineType(uri);
105
+ const type = determineType(uri, options);
102
106
  const loader = loaders[type] || loaders.default;
103
107
  return loader(uri, options);
104
108
  }
109
+ async function legacyWordList(filename, options) {
110
+ const lines = await (0, fileReader_1.readLines)(filename);
111
+ const words = (0, gensequence_1.genSequence)(lines)
112
+ // Remove comments
113
+ .map((line) => line.replace(/#.*/g, ''))
114
+ // Split on everything else
115
+ .concatMap((line) => line.split(/[^\w\p{L}\p{M}'’]+/gu))
116
+ .filter((word) => !!word);
117
+ return (0, createSpellingDictionary_1.createSpellingDictionary)(words, determineName(filename, options), filename, options);
118
+ }
119
+ async function wordsPerLineWordList(filename, options) {
120
+ const lines = await (0, fileReader_1.readLines)(filename);
121
+ const words = (0, gensequence_1.genSequence)(lines)
122
+ // Remove comments
123
+ .map((line) => line.replace(/#.*/g, ''))
124
+ // Split on everything else
125
+ .concatMap((line) => line.split(/\s+/gu))
126
+ .filter((word) => !!word);
127
+ return (0, createSpellingDictionary_1.createSpellingDictionary)(words, determineName(filename, options), filename, options);
128
+ }
105
129
  async function loadSimpleWordList(filename, options) {
106
130
  const lines = await (0, fileReader_1.readLines)(filename);
107
131
  return (0, createSpellingDictionary_1.createSpellingDictionary)(lines, determineName(filename, options), filename, options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cspell-lib",
3
- "version": "5.12.0",
3
+ "version": "5.12.4",
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",
@@ -47,15 +47,15 @@
47
47
  },
48
48
  "homepage": "https://github.com/streetsidesoftware/cspell#readme",
49
49
  "dependencies": {
50
- "@cspell/cspell-bundled-dicts": "^5.12.0",
51
- "@cspell/cspell-types": "^5.12.0",
50
+ "@cspell/cspell-bundled-dicts": "^5.12.4",
51
+ "@cspell/cspell-types": "^5.12.4",
52
52
  "clear-module": "^4.1.1",
53
53
  "comment-json": "^4.1.1",
54
54
  "configstore": "^5.0.1",
55
55
  "cosmiconfig": "^7.0.1",
56
- "cspell-glob": "^5.12.0",
57
- "cspell-io": "^5.12.0",
58
- "cspell-trie-lib": "^5.12.0",
56
+ "cspell-glob": "^5.12.4",
57
+ "cspell-io": "^5.12.4",
58
+ "cspell-trie-lib": "^5.12.4",
59
59
  "find-up": "^5.0.0",
60
60
  "fs-extra": "^10.0.0",
61
61
  "gensequence": "^3.1.1",
@@ -72,19 +72,19 @@
72
72
  "@cspell/dict-csharp": "^1.0.11",
73
73
  "@cspell/dict-css": "^1.0.12",
74
74
  "@cspell/dict-fa-ir": "^1.0.17",
75
- "@cspell/dict-fr-fr": "^1.2.21",
75
+ "@cspell/dict-fr-fr": "^2.0.1",
76
76
  "@cspell/dict-html": "^1.1.9",
77
77
  "@cspell/dict-nl-nl": "^2.0.1",
78
- "@cspell/dict-python": "^2.0.3",
78
+ "@cspell/dict-python": "^2.0.4",
79
79
  "@types/configstore": "^5.0.1",
80
80
  "@types/fs-extra": "^9.0.13",
81
81
  "@types/jest": "^27.0.2",
82
- "@types/node": "^16.10.2",
82
+ "@types/node": "^16.11.6",
83
83
  "cspell-dict-nl-nl": "^1.1.2",
84
- "jest": "^27.2.4",
84
+ "jest": "^27.3.1",
85
85
  "lorem-ipsum": "^2.0.4",
86
86
  "rimraf": "^3.0.2",
87
- "ts-jest": "^27.0.5"
87
+ "ts-jest": "^27.0.7"
88
88
  },
89
- "gitHead": "1dbf5b70cbf27a600f10e439eabc2ab0f908bafd"
89
+ "gitHead": "3e9973c39725f65141683b373ed839562f28bd94"
90
90
  }