@cspell/cspell-tools 6.29.0 → 6.29.1

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.
@@ -141,7 +141,7 @@ async function readFileSource(fileSource, sourceOptions) {
141
141
  const legacy = split === 'legacy';
142
142
  const splitWords = legacy ? false : split;
143
143
  // console.warn('fileSource: %o,\n targetOptions %o, \n opt: %o', fileSource, targetOptions, opt);
144
- const allowedSplitWords = await (0, createWordsCollection_1.createAllowedSplitWords)(fileSource.allowedSplitWords || sourceOptions.allowedSplitWords);
144
+ const allowedSplitWords = await (0, createWordsCollection_1.createAllowedSplitWordsFromFiles)(fileSource.allowedSplitWords || sourceOptions.allowedSplitWords);
145
145
  const readerOptions = {
146
146
  maxDepth,
147
147
  legacy,
@@ -1,6 +1,9 @@
1
1
  import type { FilePath } from '../config/config';
2
2
  import type { AllowedSplitWordsCollection, ExcludeWordsCollection, WordsCollection } from './WordsCollection';
3
- export declare function createAllowedSplitWords(files: FilePath | FilePath[] | undefined): Promise<AllowedSplitWordsCollection>;
4
- export declare function createWordsCollection(files: FilePath | FilePath[]): Promise<WordsCollection>;
5
- export declare function createExcludeWordsCollection(files: FilePath | FilePath[] | undefined): Promise<ExcludeWordsCollection>;
3
+ export declare function createAllowedSplitWordsFromFiles(files: FilePath | FilePath[] | undefined): Promise<AllowedSplitWordsCollection>;
4
+ export declare function createAllowedSplitWords(words: Iterable<string> | undefined): AllowedSplitWordsCollection;
5
+ export declare function createWordsCollectionFromFiles(files: FilePath | FilePath[]): Promise<WordsCollection>;
6
+ export declare function createWordsCollection(words: Iterable<string>): WordsCollection;
7
+ export declare function createExcludeWordsCollectionFromFiles(files: FilePath | FilePath[] | undefined): Promise<ExcludeWordsCollection>;
8
+ export declare function createExcludeWordsCollection(words: Iterable<string> | undefined): ExcludeWordsCollection;
6
9
  //# sourceMappingURL=createWordsCollection.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createExcludeWordsCollection = exports.createWordsCollection = exports.createAllowedSplitWords = void 0;
3
+ exports.createExcludeWordsCollection = exports.createExcludeWordsCollectionFromFiles = exports.createWordsCollection = exports.createWordsCollectionFromFiles = exports.createAllowedSplitWords = exports.createAllowedSplitWordsFromFiles = void 0;
4
4
  const Reader_1 = require("./Reader");
5
5
  const WordsCollection_1 = require("./WordsCollection");
6
6
  class AllowedSplitWordsImpl {
@@ -12,32 +12,44 @@ class AllowedSplitWordsImpl {
12
12
  return !this.size || this.words.has(word);
13
13
  }
14
14
  }
15
- async function createAllowedSplitWords(files) {
15
+ async function createAllowedSplitWordsFromFiles(files) {
16
16
  if (!files || !files.length)
17
17
  return WordsCollection_1.defaultAllowedSplitWords;
18
- const collection = await createWordsCollection(files);
18
+ const collection = await createWordsCollectionFromFiles(files);
19
19
  return new AllowedSplitWordsImpl(collection);
20
20
  }
21
+ exports.createAllowedSplitWordsFromFiles = createAllowedSplitWordsFromFiles;
22
+ function createAllowedSplitWords(words) {
23
+ if (!words)
24
+ return WordsCollection_1.defaultAllowedSplitWords;
25
+ return new AllowedSplitWordsImpl(createWordsCollection(words));
26
+ }
21
27
  exports.createAllowedSplitWords = createAllowedSplitWords;
22
28
  async function readFile(filename) {
23
29
  const reader = await (0, Reader_1.createReader)(filename, {});
24
30
  return [...reader];
25
31
  }
26
32
  const cache = new WeakMap();
27
- async function createWordsCollection(files) {
33
+ async function createWordsCollectionFromFiles(files) {
28
34
  files = Array.isArray(files) ? files : [files];
29
35
  const cached = cache.get(files);
30
36
  if (cached)
31
37
  return cached;
32
38
  const sources = await Promise.all(files.map((file) => readFile(file)));
33
- const collection = new Set(sources
34
- .flatMap((a) => a)
35
- .map((a) => a.trim())
36
- .filter((a) => !!a)
37
- .filter((a) => !a.startsWith('#')));
39
+ const collection = createWordsCollection(sources.flatMap((a) => a));
38
40
  cache.set(files, collection);
39
41
  return collection;
40
42
  }
43
+ exports.createWordsCollectionFromFiles = createWordsCollectionFromFiles;
44
+ function createWordsCollection(words) {
45
+ if (words instanceof Set)
46
+ return words;
47
+ const arrWords = (Array.isArray(words) ? words : [...words])
48
+ .map((a) => a.trim())
49
+ .filter((a) => !!a)
50
+ .filter((a) => !a.startsWith('#'));
51
+ return new Set(arrWords);
52
+ }
41
53
  exports.createWordsCollection = createWordsCollection;
42
54
  class ExcludeWordsCollectionImpl {
43
55
  constructor(collection) {
@@ -48,11 +60,15 @@ class ExcludeWordsCollectionImpl {
48
60
  return this.words.has(word);
49
61
  }
50
62
  }
51
- async function createExcludeWordsCollection(files) {
63
+ async function createExcludeWordsCollectionFromFiles(files) {
52
64
  if (!files || !files.length)
53
65
  return WordsCollection_1.defaultExcludeWordsCollection;
54
- const collection = await createWordsCollection(files);
66
+ const collection = await createWordsCollectionFromFiles(files);
55
67
  return new ExcludeWordsCollectionImpl(collection);
56
68
  }
69
+ exports.createExcludeWordsCollectionFromFiles = createExcludeWordsCollectionFromFiles;
70
+ function createExcludeWordsCollection(words) {
71
+ return new ExcludeWordsCollectionImpl(words ? createWordsCollection(words) : new Set());
72
+ }
57
73
  exports.createExcludeWordsCollection = createExcludeWordsCollection;
58
74
  //# sourceMappingURL=createWordsCollection.js.map
@@ -1,40 +1,15 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
3
  exports.legacyLinesToWords = exports.legacyLineToWords = void 0;
27
4
  const sync_1 = require("@cspell/cspell-pipe/sync");
28
- const Text = __importStar(require("./text"));
5
+ const splitCamelCaseIfAllowed_1 = require("./splitCamelCaseIfAllowed");
29
6
  const regNonWord = /[^\p{L}\p{M}' \d]+/giu;
30
- const regExpSpaceOrDash = /[- ]+/g;
31
7
  const regExpRepeatChars = /(.)\1{5}/i;
32
- const regExpIsNumber = /^\d+$/;
33
8
  function legacyLineToWords(line, keepCase, allowedSplitWords) {
34
9
  // Remove punctuation and non-letters.
35
10
  const filteredLine = line.replace(regNonWord, '|');
36
11
  const wordGroups = filteredLine.split('|');
37
- const words = (0, sync_1.pipe)(wordGroups, (0, sync_1.opConcatMap)((a) => [...a.split(regExpSpaceOrDash)]), (0, sync_1.opConcatMap)((a) => splitCamelCaseIfAllowed(a, allowedSplitWords, keepCase)), (0, sync_1.opMap)((a) => a.trim()), (0, sync_1.opFilter)((a) => !!a), (0, sync_1.opFilter)((s) => !regExpRepeatChars.test(s)));
12
+ const words = (0, sync_1.pipe)(wordGroups, (0, sync_1.opConcatMap)((a) => [...a.split(splitCamelCaseIfAllowed_1.regExpSpaceOrDash)]), (0, sync_1.opConcatMap)((a) => (0, splitCamelCaseIfAllowed_1.splitCamelCaseIfAllowed)(a, allowedSplitWords, keepCase)), (0, sync_1.opMap)((a) => a.trim()), (0, sync_1.opFilter)((a) => !!a), (0, sync_1.opFilter)((s) => !regExpRepeatChars.test(s)));
38
13
  return words;
39
14
  }
40
15
  exports.legacyLineToWords = legacyLineToWords;
@@ -44,30 +19,4 @@ function* legacyLinesToWords(lines, keepCase, allowedSplitWords) {
44
19
  }
45
20
  }
46
21
  exports.legacyLinesToWords = legacyLinesToWords;
47
- function splitCamelCaseIfAllowed(word, allowedWords, keepCase) {
48
- const split = [...splitCamelCase(word)].map((a) => (keepCase ? a : a.toLowerCase()));
49
- const missing = split.find((w) => isUnknown(w, allowedWords));
50
- const words = missing === undefined ? split : [word];
51
- return keepCase ? words : words.map(adjustCase);
52
- }
53
- function adjustCase(word) {
54
- if (word[0].toLowerCase() == word[0])
55
- return word;
56
- if (word.slice(1).toLowerCase() === word.slice(1))
57
- return word[0].toLowerCase() + word.slice(1);
58
- if (word.toUpperCase() === word)
59
- return word.toLowerCase();
60
- return word;
61
- }
62
- function isUnknown(word, allowedWords) {
63
- return word.length > 3 && !allowedWords.has(word);
64
- }
65
- function splitCamelCase(word) {
66
- const splitWords = Text.splitCamelCaseWord(word).filter((word) => !regExpIsNumber.test(word));
67
- // We only want to preserve this: "New York" and not "Namespace DNSLookup"
68
- if (splitWords.length > 1 && regExpSpaceOrDash.test(word)) {
69
- return (0, sync_1.pipe)(splitWords, (0, sync_1.opConcatMap)((w) => w.split(regExpSpaceOrDash)));
70
- }
71
- return splitWords;
72
- }
73
22
  //# sourceMappingURL=legacyLineToWords.js.map
@@ -0,0 +1,5 @@
1
+ import type { AllowedSplitWordsCollection } from './WordsCollection';
2
+ export declare const regExpSpaceOrDash: RegExp;
3
+ export declare const regExpIsNumber: RegExp;
4
+ export declare function splitCamelCaseIfAllowed(word: string, allowedWords: AllowedSplitWordsCollection, keepCase: boolean): string[];
5
+ //# sourceMappingURL=splitCamelCaseIfAllowed.d.ts.map
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.splitCamelCaseIfAllowed = exports.regExpIsNumber = exports.regExpSpaceOrDash = void 0;
27
+ const Text = __importStar(require("./text"));
28
+ exports.regExpSpaceOrDash = /[- ]+/g;
29
+ exports.regExpIsNumber = /^\d+$/;
30
+ function splitCamelCaseIfAllowed(word, allowedWords, keepCase) {
31
+ const split = [...splitCamelCase(word)];
32
+ if (split.length == 1)
33
+ return adjustCases(split, allowedWords, keepCase);
34
+ const missing = split.find((w) => isUnknown(w, allowedWords));
35
+ if (missing !== undefined)
36
+ return [word];
37
+ return adjustCases(split, allowedWords, keepCase);
38
+ }
39
+ exports.splitCamelCaseIfAllowed = splitCamelCaseIfAllowed;
40
+ function adjustCases(words, allowedWords, keepCase) {
41
+ return words.map((w) => adjustCase(w, allowedWords, keepCase));
42
+ }
43
+ function adjustCase(word, allowedWords, keepCase) {
44
+ const lc = word.toLowerCase();
45
+ if (!allowedWords.has(lc))
46
+ return word;
47
+ if (lc === word)
48
+ return word;
49
+ if (word.slice(1).toLowerCase() === word.slice(1))
50
+ return lc;
51
+ if (!keepCase && word.toUpperCase() === word)
52
+ return word.toLowerCase();
53
+ return word;
54
+ }
55
+ function isUnknown(word, allowedWords) {
56
+ return !allowedWords.has(word) && !allowedWords.has(word.toLowerCase());
57
+ }
58
+ function splitCamelCase(word) {
59
+ const splitWords = Text.splitCamelCaseWord(word).filter((word) => !exports.regExpIsNumber.test(word));
60
+ // We only want to preserve this: "New York" and not "Namespace DNSLookup"
61
+ if (splitWords.length > 1 && exports.regExpSpaceOrDash.test(word)) {
62
+ return splitWords.flatMap((w) => w.split(exports.regExpSpaceOrDash));
63
+ }
64
+ return splitWords;
65
+ }
66
+ //# sourceMappingURL=splitCamelCaseIfAllowed.js.map
@@ -12,7 +12,7 @@ function splitCamelCaseWord(word) {
12
12
  const wPrime = word.replace(regExUpperSOrIng, (s) => s[0] + s.slice(1).toLowerCase());
13
13
  const pass1 = wPrime.replace(regExSplitWords, '$1|$2');
14
14
  const pass2 = pass1.replace(regExSplitWords2, '$1|$2');
15
- const pass3 = pass2.replace(/\d+/g, '|');
15
+ const pass3 = pass2.replace(/[\d_]+/g, '|');
16
16
  return pass3.split('|').filter((a) => !!a);
17
17
  }
18
18
  exports.splitCamelCaseWord = splitCamelCaseWord;
@@ -5,6 +5,7 @@ const sync_1 = require("@cspell/cspell-pipe/sync");
5
5
  const cspell_trie_lib_1 = require("cspell-trie-lib");
6
6
  const util_1 = require("hunspell-reader/dist/util");
7
7
  const legacyLineToWords_1 = require("./legacyLineToWords");
8
+ const splitCamelCaseIfAllowed_1 = require("./splitCamelCaseIfAllowed");
8
9
  function normalizeTargetWords(options) {
9
10
  const lineParser = (0, cspell_trie_lib_1.createDictionaryLineParser)({
10
11
  stripCaseAndAccents: options.generateNonStrict,
@@ -61,7 +62,6 @@ function createParseFileLineMapper(options) {
61
62
  const { splitKeepBoth = _defaultOptions.splitKeepBoth, allowedSplitWords = _defaultOptions.allowedSplitWords } = _options;
62
63
  let { legacy = _defaultOptions.legacy } = _options;
63
64
  let { split = _defaultOptions.split, keepCase = legacy ? false : _defaultOptions.keepCase } = _options;
64
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
65
  function isString(line) {
66
66
  return typeof line === 'string';
67
67
  }
@@ -136,7 +136,13 @@ function createParseFileLineMapper(options) {
136
136
  continue;
137
137
  }
138
138
  if (split) {
139
- yield* splitLine(line);
139
+ const words = splitLine(line);
140
+ if (!allowedSplitWords.size) {
141
+ yield* words;
142
+ }
143
+ else {
144
+ yield* words.flatMap((word) => (0, splitCamelCaseIfAllowed_1.splitCamelCaseIfAllowed)(word, allowedSplitWords, keepCase));
145
+ }
140
146
  if (!splitKeepBoth)
141
147
  continue;
142
148
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cspell/cspell-tools",
3
- "version": "6.29.0",
3
+ "version": "6.29.1",
4
4
  "description": "Tools to assist with the development of cSpell",
5
5
  "typings": "dist/index.d.ts",
6
6
  "publishConfig": {
@@ -48,13 +48,13 @@
48
48
  },
49
49
  "homepage": "https://github.com/streetsidesoftware/cspell#readme",
50
50
  "dependencies": {
51
- "@cspell/cspell-pipe": "6.29.0",
51
+ "@cspell/cspell-pipe": "6.29.1",
52
52
  "commander": "^10.0.0",
53
53
  "cosmiconfig": "^8.1.0",
54
- "cspell-trie-lib": "6.29.0",
54
+ "cspell-trie-lib": "6.29.1",
55
55
  "gensequence": "^5.0.2",
56
56
  "glob": "^8.1.0",
57
- "hunspell-reader": "6.29.0"
57
+ "hunspell-reader": "6.29.1"
58
58
  },
59
59
  "engines": {
60
60
  "node": ">=14"
@@ -69,5 +69,5 @@
69
69
  "ts-json-schema-generator": "^1.2.0"
70
70
  },
71
71
  "main": "bin.js",
72
- "gitHead": "2eabb1c47c12c2a42eb95d30329be6f544ee2ffc"
72
+ "gitHead": "e524c611f3529b22a7e8ae3449a5c9a01332d44f"
73
73
  }