cspell-tools 5.1.0 → 8.17.5

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.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017 Jason Dent
3
+ Copyright (c) 2019 cspell
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,9 +1,11 @@
1
- # cSpell-Tools
1
+ # CSpell-Tools
2
2
 
3
- Tools used to assist cSpell Development.
3
+ Tools used to assist CSpell Development.
4
4
 
5
5
  The Primary use of this tool is to build dictionaries used by cspell. This tool will convert a word list or a hunspell file into a file usable by cspell.
6
6
 
7
+ This package is an alias for `@cspell/cspell-tools`.
8
+
7
9
  ## Install
8
10
 
9
11
  ```sh
@@ -35,3 +37,23 @@ This will read and expand the `english.dic` file based upon the rules in `englis
35
37
  For large files, this process can take a long time and us a lot of memory.
36
38
 
37
39
  The tool `cspell-trie` can be used to read the contents of a `.trie` or `.trie.gz` file.
40
+
41
+ ## CSpell for Enterprise
42
+
43
+ <!--- @@inject: ../../static/tidelift.md --->
44
+
45
+ Available as part of the Tidelift Subscription.
46
+
47
+ The maintainers of cspell and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source packages you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-cspell?utm_source=npm-cspell&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
48
+
49
+ <!--- @@inject-end: ../../static/tidelift.md --->
50
+
51
+ <!--- @@inject: ../../static/footer.md --->
52
+
53
+ <br/>
54
+
55
+ ---
56
+
57
+ <p align="center">Brought to you by<a href="https://streetsidesoftware.com" title="Street Side Software"><img width="16" alt="Street Side Software Logo" src="https://i.imgur.com/CyduuVY.png" /> Street Side Software</a></p>
58
+
59
+ <!--- @@inject-end: ../../static/footer.md --->
package/bin.mjs ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ import '@cspell/cspell-tools/bin';
package/package.json CHANGED
@@ -1,24 +1,24 @@
1
1
  {
2
2
  "name": "cspell-tools",
3
- "version": "5.1.0",
4
- "description": "Tools to assist with the development of cSpell",
5
- "typings": "dist/index.d.ts",
3
+ "version": "8.17.5",
4
+ "description": "Tools to assist with the development of cSpell. Alias of @cspell/cspell-tools",
5
+ "publishConfig": {
6
+ "access": "public",
7
+ "provenance": true
8
+ },
9
+ "type": "module",
10
+ "sideEffects": false,
6
11
  "bin": {
7
- "cspell-tools": "bin.js"
12
+ "cspell-tools": "bin.mjs"
8
13
  },
9
14
  "scripts": {
10
- "build": "tsc -p .",
11
- "watch": "tsc -p . -w",
12
- "clean-build": "npm run clean && npm run build",
13
- "clean": "rimraf dist temp coverage",
14
- "coverage": "jest --coverage",
15
- "test-watch": "jest --watch",
16
- "test": "jest",
17
- "update-snapshot": "jest --updateSnapshot"
15
+ "test": "pnpm test-shasum",
16
+ "test-shasum": "node ./bin.mjs shasum package.json"
18
17
  },
19
18
  "repository": {
20
19
  "type": "git",
21
- "url": "git+https://github.com/streetsidesoftware/cspell.git"
20
+ "url": "https://github.com/streetsidesoftware/cspell.git",
21
+ "directory": "packages/cspell-tools-alias"
22
22
  },
23
23
  "keywords": [
24
24
  "cSpell",
@@ -27,42 +27,25 @@
27
27
  "Compiler"
28
28
  ],
29
29
  "files": [
30
- "bin.js",
31
- "dist/**",
32
- "!**/*.map",
33
- "!**/*.test.*"
30
+ "bin.mjs",
31
+ "!**/*.tsbuildInfo",
32
+ "!**/__mocks__",
33
+ "!**/*.test.*",
34
+ "!**/*.spec.*",
35
+ "!**/*.map"
34
36
  ],
35
37
  "author": "Jason Dent",
36
38
  "license": "MIT",
37
39
  "bugs": {
38
40
  "url": "https://github.com/streetsidesoftware/cspell/labels/cspell-tools"
39
41
  },
40
- "homepage": "https://github.com/streetsidesoftware/cspell#readme",
42
+ "homepage": "https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell-tools-alias#readme",
41
43
  "dependencies": {
42
- "commander": "^6.2.1",
43
- "cspell-io": "^5.1.0",
44
- "cspell-trie-lib": "^5.1.0",
45
- "cspell-util-bundle": "^5.1.0",
46
- "fs-extra": "^9.0.1",
47
- "gensequence": "^3.1.1",
48
- "glob": "^7.1.6",
49
- "hunspell-reader": "^3.2.0"
44
+ "@cspell/cspell-tools": "8.17.5"
50
45
  },
51
46
  "engines": {
52
- "node": ">=12.0.0"
53
- },
54
- "devDependencies": {
55
- "@types/fs-extra": "^9.0.6",
56
- "@types/glob": "^7.1.3",
57
- "@types/jest": "^26.0.19",
58
- "@types/node": "^14.14.16",
59
- "@types/rimraf": "^3.0.0",
60
- "@types/shelljs": "^0.8.8",
61
- "jest": "^26.6.3",
62
- "lorem-ipsum": "^2.0.3",
63
- "rimraf": "^3.0.2",
64
- "shelljs": "^0.8.4"
47
+ "node": ">=18"
65
48
  },
66
- "main": "bin.js",
67
- "gitHead": "4160b964818f29a97a29b36e583a6f4d7c8de300"
49
+ "module": "bin.mjs",
50
+ "gitHead": "2d80ee2aa347d07c52aa9c85aa248538834d7f3c"
68
51
  }
package/CHANGELOG.md DELETED
@@ -1,118 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- # [5.1.0](https://github.com/streetsidesoftware/cspell/compare/v5.0.8...v5.1.0) (2020-12-27)
7
-
8
- **Note:** Version bump only for package cspell-tools
9
-
10
-
11
-
12
-
13
-
14
- ## [5.0.8](https://github.com/streetsidesoftware/cspell/compare/v5.0.7...v5.0.8) (2020-12-17)
15
-
16
- **Note:** Version bump only for package cspell-tools
17
-
18
-
19
-
20
-
21
-
22
- ## [5.0.5](https://github.com/streetsidesoftware/cspell/compare/v5.0.4...v5.0.5) (2020-12-15)
23
-
24
- **Note:** Version bump only for package cspell-tools
25
-
26
-
27
-
28
-
29
-
30
- ## [5.0.4](https://github.com/streetsidesoftware/cspell/compare/v5.0.3...v5.0.4) (2020-12-15)
31
-
32
- **Note:** Version bump only for package cspell-tools
33
-
34
-
35
-
36
-
37
-
38
- ## [5.0.3](https://github.com/streetsidesoftware/cspell/compare/v5.0.2...v5.0.3) (2020-12-04)
39
-
40
- **Note:** Version bump only for package cspell-tools
41
-
42
-
43
-
44
-
45
-
46
- ## [5.0.2](https://github.com/streetsidesoftware/cspell/compare/v5.0.2-alpha.1...v5.0.2) (2020-11-26)
47
-
48
- **Note:** Version bump only for package cspell-tools
49
-
50
-
51
-
52
-
53
-
54
- ## [5.0.1](https://github.com/streetsidesoftware/cspell/compare/v5.0.1-alpha.15...v5.0.1) (2020-11-20)
55
-
56
- **Note:** Version bump only for package cspell-tools
57
-
58
-
59
-
60
-
61
-
62
- ## [5.0.1-alpha.15](https://github.com/streetsidesoftware/cspell/compare/v5.0.1-alpha.14...v5.0.1-alpha.15) (2020-11-18)
63
-
64
-
65
- ### Bug Fixes
66
-
67
- * force new version ([3ab08ab](https://github.com/streetsidesoftware/cspell/commit/3ab08ab5ae1939d934b2f0fb23d33defc60c1a7f))
68
-
69
-
70
-
71
-
72
-
73
- ## 5.0.1-alpha.14 (2020-11-17)
74
-
75
- **Note:** Version bump only for package cspell-tools
76
-
77
- ## [5.0.1-alpha.0](https://github.com/streetsidesoftware/cspell/compare/cspell-tools@4.1.12...cspell-tools@5.0.1-alpha.0) (2020-02-20)
78
-
79
- **Note:** Version bump only for package cspell-tools
80
-
81
- # Release Notes
82
-
83
- ## 2.0
84
-
85
- - Update to rxjs 6
86
-
87
- ## 1.4.1
88
-
89
- - Update packages
90
-
91
- ## 1.4.0
92
-
93
- - Update packages
94
- - Remove dependency on fs-promise
95
-
96
- ## 1.3.2
97
-
98
- - Fix issue with writing files when the destination path does not exist.
99
-
100
- ## 1.3.1
101
-
102
- - Add command line tool for building trie files.
103
-
104
- ## 1.2.1
105
-
106
- - Hyphenated words are now treated as two words.
107
-
108
- ## 1.1.0
109
-
110
- - use cspell-lib for file i/o.
111
-
112
- ## 1.0.10
113
-
114
- - allow globs on the command line so `cspell-tools compile *.txt` works on windows.
115
-
116
- ## 1.0.7
117
-
118
- - update packages
package/bin.js DELETED
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- 'use strict';
4
-
5
- const app = require('./dist/app');
6
- const program = require('commander');
7
-
8
- app.run(program, process.argv).catch((e) => {
9
- if (!(e instanceof program.CommanderError)) {
10
- console.log(e);
11
- }
12
- process.exitCode = 1;
13
- });
package/dist/app.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import * as program from 'commander';
2
- export declare function run(program: program.Command, argv: string[]): Promise<void>;
package/dist/app.js DELETED
@@ -1,174 +0,0 @@
1
- "use strict";
2
- // For large dictionaries, it is necessary to increase the memory limit.
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
6
- }) : (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- o[k2] = m[k];
9
- }));
10
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
11
- Object.defineProperty(o, "default", { enumerable: true, value: v });
12
- }) : function(o, v) {
13
- o["default"] = v;
14
- });
15
- var __importStar = (this && this.__importStar) || function (mod) {
16
- if (mod && mod.__esModule) return mod;
17
- var result = {};
18
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
19
- __setModuleDefault(result, mod);
20
- return result;
21
- };
22
- var __importDefault = (this && this.__importDefault) || function (mod) {
23
- return (mod && mod.__esModule) ? mod : { "default": mod };
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.run = void 0;
27
- const compiler_1 = require("./compiler");
28
- const compiler = __importStar(require("./compiler"));
29
- const path = __importStar(require("path"));
30
- const glob_1 = __importDefault(require("glob"));
31
- const gensequence_1 = require("gensequence");
32
- const iterateWordsFromFile_1 = require("./compiler/iterateWordsFromFile");
33
- // eslint-disable-next-line @typescript-eslint/no-var-requires
34
- const npmPackage = require(path.join(__dirname, '..', 'package.json'));
35
- function globP(pattern) {
36
- return new Promise((resolve, reject) => {
37
- glob_1.default(pattern, (err, result) => {
38
- err ? reject(err) : resolve(result);
39
- });
40
- });
41
- }
42
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
- const log = (message, ...optionalParams) => {
44
- console.log(`${new Date().toISOString()} ${message}`, ...optionalParams);
45
- };
46
- compiler.setLogger(log);
47
- function collect(value, previous) {
48
- return previous.concat([value]);
49
- }
50
- function run(program, argv) {
51
- program.exitOverride();
52
- return new Promise((resolve, reject) => {
53
- program.version(npmPackage.version);
54
- program
55
- .command('compile <src...>')
56
- .description('compile words lists into simple dictionary files.')
57
- .option('-o, --output <path>', 'Specify the output directory, otherwise files are written back to the same location.')
58
- .option('-n, --no-compress', 'By default the files are Gzipped, this will turn that off.')
59
- .option('-m, --max_depth <limit>', 'Maximum depth to apply suffix rules.')
60
- .option('-M, --merge <target>', 'Merge all files into a single target file (extensions are applied)')
61
- .option('-s, --no-split', 'Treat each line as a dictionary entry, do not split')
62
- .option('-x, --experimental <flag>', 'Experimental flags, used for testing new concepts. Flags: compound', collect, [])
63
- .option('--no-sort', 'Do not sort the result')
64
- .action((src, options) => {
65
- const experimental = new Set(options.experimental);
66
- const skipNormalization = experimental.has('compound');
67
- const result = processAction(src, '.txt', options, async (src, dst) => {
68
- return compiler_1.compileWordList(src, dst, {
69
- splitWords: options.split,
70
- sort: options.sort,
71
- skipNormalization,
72
- }).then(() => src);
73
- });
74
- resolve(result);
75
- });
76
- program
77
- .command('compile-trie <src...>')
78
- .description('Compile words lists or Hunspell dictionary into trie files used by cspell.')
79
- .option('-o, --output <path>', 'Specify the output directory, otherwise files are written back to the same location.')
80
- .option('-m, --max_depth <limit>', 'Maximum depth to apply suffix rules.')
81
- .option('-M, --merge <target>', 'Merge all files into a single target file (extensions are applied)')
82
- .option('-n, --no-compress', 'By default the files are Gzipped, this will turn that off.')
83
- .option('-x, --experimental <flag>', 'Experimental flags, used for testing new concepts. Flags: compound', collect, [])
84
- .option('--trie3', '[Beta] Use file format trie3')
85
- .action((src, options) => {
86
- const experimental = new Set(options.experimental);
87
- const skipNormalization = experimental.has('compound');
88
- const compileOptions = { ...options, skipNormalization };
89
- const result = processAction(src, '.trie', options, async (words, dst) => {
90
- return compiler_1.compileTrie(words, dst, compileOptions);
91
- });
92
- resolve(result);
93
- });
94
- try {
95
- program.parse(argv);
96
- if (!argv.slice(2).length) {
97
- program.help();
98
- }
99
- }
100
- catch (e) {
101
- reject(e);
102
- }
103
- resolve();
104
- });
105
- }
106
- exports.run = run;
107
- function parseNumber(s) {
108
- const n = parseInt(s !== null && s !== void 0 ? s : '');
109
- return isNaN(n) ? undefined : n;
110
- }
111
- async function processAction(src, fileExt, options, action) {
112
- console.log('Compile:\n output: %s\n compress: %s\n files:\n %s \n\n', options.output || 'default', options.compress ? 'true' : 'false', src.join('\n '));
113
- const ext = fileExt + (options.compress ? '.gz' : '');
114
- const maxDepth = parseNumber(options.max_depth);
115
- const experimental = new Set(options.experimental);
116
- const useAnnotation = experimental.has('compound');
117
- const readerOptions = { maxDepth, useAnnotation };
118
- const globResults = await Promise.all(src.map((s) => globP(s)));
119
- const filesToProcess = gensequence_1.genSequence(globResults)
120
- .concatMap((files) => files)
121
- .map(async (filename) => {
122
- log(`Reading ${path.basename(filename)}`);
123
- const words = await iterateWordsFromFile_1.streamWordsFromFile(filename, readerOptions);
124
- log(`Done reading ${path.basename(filename)}`);
125
- const f = {
126
- src: filename,
127
- words,
128
- };
129
- return f;
130
- });
131
- const r = options.merge
132
- ? processFiles(action, filesToProcess, toMergeTargetFile(options.merge, options.output, ext))
133
- : processFilesIndividually(action, filesToProcess, (s) => toTargetFile(s, options.output, ext));
134
- await r;
135
- log(`Complete.`);
136
- }
137
- function toFilename(name, ext) {
138
- return path.basename(name).replace(/((\.txt|\.dic|\.aff|\.trie)(\.gz)?)?$/, '') + ext;
139
- }
140
- function toTargetFile(filename, destination, ext) {
141
- const outFileName = toFilename(filename, ext);
142
- const dir = destination !== null && destination !== void 0 ? destination : path.dirname(filename);
143
- return path.join(dir, outFileName);
144
- }
145
- function toMergeTargetFile(filename, destination, ext) {
146
- const outFileName = path.join(path.dirname(filename), toFilename(filename, ext));
147
- return path.resolve(destination !== null && destination !== void 0 ? destination : '.', outFileName);
148
- }
149
- async function processFilesIndividually(action, filesToProcess, srcToTarget) {
150
- const toProcess = filesToProcess.map(async (pFtp) => {
151
- const { src, words } = await pFtp;
152
- const dst = srcToTarget(src);
153
- log('Process "%s" to "%s"', src, dst);
154
- await action(words, dst);
155
- log('Done "%s" to "%s"', src, dst);
156
- });
157
- for (const p of toProcess) {
158
- await p;
159
- }
160
- }
161
- async function processFiles(action, filesToProcess, mergeTarget) {
162
- const toProcess = await Promise.all([...filesToProcess]);
163
- const dst = mergeTarget;
164
- const words = gensequence_1.genSequence(toProcess)
165
- .map((ftp) => {
166
- const { src } = ftp;
167
- log('Process "%s" to "%s"', src, dst);
168
- return ftp;
169
- })
170
- .concatMap((ftp) => ftp.words);
171
- await action(words, dst);
172
- log('Done "%s"', dst);
173
- }
174
- //# sourceMappingURL=app.js.map
@@ -1,18 +0,0 @@
1
- import { Sequence } from 'gensequence';
2
- export interface ReaderOptions {
3
- useAnnotation?: boolean;
4
- maxDepth?: number;
5
- }
6
- export declare type AnnotatedWord = string;
7
- interface BaseReader {
8
- size: number;
9
- annotatedWords: () => Sequence<AnnotatedWord>;
10
- rawWords: () => Sequence<string>;
11
- }
12
- export interface Reader extends BaseReader {
13
- [Symbol.iterator]: () => Sequence<string>;
14
- }
15
- export declare function createReader(filename: string, options: ReaderOptions): Promise<Reader>;
16
- export declare function createArrayReader(lines: string[]): BaseReader;
17
- export declare function readHunspellFiles(filename: string, options: ReaderOptions): Promise<BaseReader>;
18
- export {};
@@ -1,181 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.readHunspellFiles = exports.createArrayReader = exports.createReader = void 0;
23
- const gensequence_1 = require("gensequence");
24
- const HR = __importStar(require("hunspell-reader"));
25
- const fs = __importStar(require("fs-extra"));
26
- const cspell_trie_lib_1 = require("cspell-trie-lib");
27
- const zlib = __importStar(require("zlib"));
28
- const regHunspellFile = /\.(dic|aff)$/i;
29
- // cspell:word dedupe
30
- const DEDUPE_SIZE = 1000;
31
- const regExMatchComments = /\s*(#|\/\/).*/;
32
- // Readers first match wins
33
- const readers = [
34
- { test: /\.trie\b/, method: trieFileReader },
35
- { test: regHunspellFile, method: readHunspellFiles },
36
- ];
37
- function findMatchingReader(filename, options) {
38
- for (const reader of readers) {
39
- if (reader.test.test(filename)) {
40
- return reader.method(filename, options);
41
- }
42
- }
43
- return textFileReader(filename, options);
44
- }
45
- async function createReader(filename, options) {
46
- const baseReader = await findMatchingReader(filename, options);
47
- return Object.assign(baseReader, {
48
- [Symbol.iterator]: options.useAnnotation ? baseReader.annotatedWords : baseReader.rawWords,
49
- });
50
- }
51
- exports.createReader = createReader;
52
- function createArrayReader(lines) {
53
- const rawWords = () => gensequence_1.genSequence(lines);
54
- const annotatedWords = () => gensequence_1.genSequence(lines).pipe(_mapText, dedupeAndSort);
55
- return {
56
- size: lines.length,
57
- annotatedWords,
58
- rawWords,
59
- };
60
- }
61
- exports.createArrayReader = createArrayReader;
62
- async function readHunspellFiles(filename, options) {
63
- const dicFile = filename.replace(regHunspellFile, '.dic');
64
- const affFile = filename.replace(regHunspellFile, '.aff');
65
- const reader = await HR.IterableHunspellReader.createFromFiles(affFile, dicFile);
66
- reader.maxDepth = options.maxDepth !== undefined ? options.maxDepth : reader.maxDepth;
67
- const normalizeAndDedupe = gensequence_1.operators.pipe(_stripCaseAndAccents, dedupeAndSort);
68
- const rawWords = () => reader.seqWords();
69
- return {
70
- size: reader.dic.length,
71
- annotatedWords() {
72
- return reader.seqAffWords().pipe(_mapAffWords).pipe(normalizeAndDedupe);
73
- },
74
- rawWords,
75
- };
76
- }
77
- exports.readHunspellFiles = readHunspellFiles;
78
- async function trieFileReader(filename) {
79
- const trieRoot = cspell_trie_lib_1.importTrie(await readTextFile(filename));
80
- const trie = new cspell_trie_lib_1.Trie(trieRoot);
81
- const rawWords = () => trie.words();
82
- return {
83
- get size() {
84
- return trie.size();
85
- },
86
- annotatedWords: rawWords,
87
- rawWords,
88
- };
89
- }
90
- function readTextFile(filename) {
91
- const lines = fs
92
- .readFile(filename)
93
- .then((buffer) => (/\.gz$/.test(filename) ? zlib.gunzipSync(buffer) : buffer))
94
- .then((buffer) => buffer.toString('utf8'))
95
- .then((content) => content.split(/\r?\n/g));
96
- return lines;
97
- }
98
- async function textFileReader(filename, _options) {
99
- const lines = await readTextFile(filename);
100
- return createArrayReader(lines);
101
- }
102
- const _mapText = gensequence_1.operators.pipe(_comments, _compoundBegin, _compoundEnd, _stripCaseAndAccents);
103
- function* _comments(lines) {
104
- for (const line of lines) {
105
- const w = line.replace(regExMatchComments, '').trim();
106
- if (w)
107
- yield w;
108
- }
109
- }
110
- function* _compoundEnd(lines) {
111
- for (const line of lines) {
112
- if (line[0] !== cspell_trie_lib_1.OPTIONAL_COMPOUND) {
113
- yield line;
114
- continue;
115
- }
116
- const w = line.slice(1);
117
- yield w;
118
- yield cspell_trie_lib_1.COMPOUND + w;
119
- }
120
- }
121
- function* _compoundBegin(lines) {
122
- for (const line of lines) {
123
- if (line[line.length - 1] !== cspell_trie_lib_1.OPTIONAL_COMPOUND) {
124
- yield line;
125
- continue;
126
- }
127
- const w = line.slice(0, -1);
128
- yield w;
129
- yield w + cspell_trie_lib_1.COMPOUND;
130
- }
131
- }
132
- function* _stripCaseAndAccents(words) {
133
- for (const word of words) {
134
- // Words are normalized to the compact format: e + ` => è
135
- yield word.normalize();
136
- // covert to lower case and strip accents.
137
- const n = word
138
- .toLowerCase()
139
- .normalize('NFD')
140
- .replace(/[\u0300-\u036f]/g, '');
141
- // All words are added for case-insensitive searches.
142
- // It is a space / speed trade-off. In this case, speed is more important.
143
- yield cspell_trie_lib_1.NORMALIZED + n;
144
- }
145
- }
146
- function* dedupeAndSort(words) {
147
- const buffer = [];
148
- function sortDedupeClear() {
149
- const s = new Set(buffer.sort());
150
- buffer.length = 0;
151
- return s;
152
- }
153
- for (const word of words) {
154
- buffer.push(word);
155
- if (buffer.length >= DEDUPE_SIZE) {
156
- yield* sortDedupeClear();
157
- }
158
- }
159
- yield* sortDedupeClear();
160
- }
161
- function* _mapAffWords(affWords) {
162
- for (const affWord of affWords) {
163
- const { word, flags } = affWord;
164
- const compound = flags.isCompoundForbidden ? '' : cspell_trie_lib_1.COMPOUND;
165
- const forbid = flags.isForbiddenWord ? cspell_trie_lib_1.FORBID : '';
166
- if (!forbid) {
167
- if (flags.canBeCompoundBegin)
168
- yield word + compound;
169
- if (flags.canBeCompoundEnd)
170
- yield compound + word;
171
- if (flags.canBeCompoundMiddle)
172
- yield compound + word + compound;
173
- if (!flags.isOnlyAllowedInCompound)
174
- yield word;
175
- }
176
- else {
177
- yield forbid + word;
178
- }
179
- }
180
- }
181
- //# sourceMappingURL=Reader.js.map
@@ -1,3 +0,0 @@
1
- import { Sequence } from 'gensequence';
2
- export { writeToFile, writeToFileIterableP, writeToFileIterable } from 'cspell-io';
3
- export declare function writeSeqToFile(seq: Sequence<string>, outFile: string): Promise<void>;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.writeSeqToFile = exports.writeToFileIterable = exports.writeToFileIterableP = exports.writeToFile = void 0;
4
- const cspell_io_1 = require("cspell-io");
5
- var cspell_io_2 = require("cspell-io");
6
- Object.defineProperty(exports, "writeToFile", { enumerable: true, get: function () { return cspell_io_2.writeToFile; } });
7
- Object.defineProperty(exports, "writeToFileIterableP", { enumerable: true, get: function () { return cspell_io_2.writeToFileIterableP; } });
8
- Object.defineProperty(exports, "writeToFileIterable", { enumerable: true, get: function () { return cspell_io_2.writeToFileIterable; } });
9
- function writeSeqToFile(seq, outFile) {
10
- return cspell_io_1.writeToFileIterableP(outFile, seq);
11
- }
12
- exports.writeSeqToFile = writeSeqToFile;
13
- //# sourceMappingURL=fileWriter.js.map
@@ -1 +0,0 @@
1
- export * from './wordListCompiler';
@@ -1,14 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./wordListCompiler"), exports);
14
- //# sourceMappingURL=index.js.map
@@ -1,3 +0,0 @@
1
- import { Sequence } from 'gensequence';
2
- import { ReaderOptions } from './Reader';
3
- export declare function streamWordsFromFile(filename: string, options: ReaderOptions): Promise<Sequence<string>>;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.streamWordsFromFile = void 0;
4
- const Reader_1 = require("./Reader");
5
- async function streamWordsFromFile(filename, options) {
6
- const reader = await Reader_1.createReader(filename, options);
7
- return reader[Symbol.iterator]();
8
- }
9
- exports.streamWordsFromFile = streamWordsFromFile;
10
- //# sourceMappingURL=iterateWordsFromFile.js.map
@@ -1,4 +0,0 @@
1
- /**
2
- * Split camelCase words into an array of strings.
3
- */
4
- export declare function splitCamelCaseWord(word: string): string[];
@@ -1,20 +0,0 @@
1
- "use strict";
2
- // cSpell:ignore ings ning gimuy
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.splitCamelCaseWord = void 0;
5
- const cspell_util_bundle_1 = require("cspell-util-bundle");
6
- const regExUpperSOrIng = cspell_util_bundle_1.xregexp("(\\p{Lu}+'?(?:s|ing|ies|es|ings|ed|ning))(?!\\p{Ll})", 'g');
7
- const regExSplitWords = cspell_util_bundle_1.xregexp('(\\p{Ll})(\\p{Lu})', 'g');
8
- const regExSplitWords2 = cspell_util_bundle_1.xregexp('(\\p{Lu})(\\p{Lu}\\p{Ll})', 'g');
9
- /**
10
- * Split camelCase words into an array of strings.
11
- */
12
- function splitCamelCaseWord(word) {
13
- const wPrime = word.replace(regExUpperSOrIng, (s) => s[0] + s.substr(1).toLowerCase());
14
- const separator = '_<^*_*^>_';
15
- const pass1 = cspell_util_bundle_1.xregexp.replace(wPrime, regExSplitWords, '$1' + separator + '$2');
16
- const pass2 = cspell_util_bundle_1.xregexp.replace(pass1, regExSplitWords2, '$1' + separator + '$2');
17
- return cspell_util_bundle_1.xregexp.split(pass2, separator);
18
- }
19
- exports.splitCamelCaseWord = splitCamelCaseWord;
20
- //# sourceMappingURL=text.js.map
@@ -1,23 +0,0 @@
1
- import { Sequence } from 'gensequence';
2
- import * as Trie from 'cspell-trie-lib';
3
- export declare type Logger = (message?: any, ...optionalParams: any[]) => void;
4
- export declare function setLogger(logger?: Logger): void;
5
- declare type Normalizer = (lines: Sequence<string>) => Sequence<string>;
6
- export declare function normalizeWords(lines: Sequence<string>): Sequence<string>;
7
- export declare function lineToWords(line: string): Sequence<string>;
8
- export interface CompileOptions {
9
- skipNormalization?: boolean;
10
- }
11
- export interface CompileWordListOptions extends CompileOptions {
12
- splitWords: boolean;
13
- sort: boolean;
14
- }
15
- export declare function compileWordList(words: Sequence<string>, destFilename: string, options: CompileWordListOptions): Promise<void>;
16
- export declare function normalizeWordsToTrie(words: Sequence<string>, normalizer?: Normalizer): Trie.TrieRoot;
17
- export interface CompileTrieOptions extends CompileOptions {
18
- base?: number;
19
- trie3?: boolean;
20
- }
21
- export declare const consolidate: typeof Trie.consolidate;
22
- export declare function compileTrie(words: Sequence<string>, destFilename: string, options: CompileTrieOptions): Promise<void>;
23
- export {};
@@ -1,119 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.compileTrie = exports.consolidate = exports.normalizeWordsToTrie = exports.compileWordList = exports.lineToWords = exports.normalizeWords = exports.setLogger = void 0;
23
- const cspell_util_bundle_1 = require("cspell-util-bundle");
24
- const gensequence_1 = require("gensequence");
25
- const Text = __importStar(require("./text"));
26
- const path = __importStar(require("path"));
27
- const fs_extra_1 = require("fs-extra");
28
- const Trie = __importStar(require("cspell-trie-lib"));
29
- const fileWriter_1 = require("./fileWriter");
30
- const util_1 = require("hunspell-reader/dist/util");
31
- const regNonWordOrSpace = cspell_util_bundle_1.xregexp("[^\\p{L}' ]+", 'gi');
32
- const regExpSpaceOrDash = /(?:\s+)|(?:-+)/g;
33
- const regExpRepeatChars = /(.)\1{3,}/i;
34
- let log = defaultLogger;
35
- function setLogger(logger) {
36
- log = logger !== null && logger !== void 0 ? logger : defaultLogger;
37
- }
38
- exports.setLogger = setLogger;
39
- function defaultLogger(message, ...optionalParams) {
40
- console.log(message, ...optionalParams);
41
- }
42
- function normalizeWords(lines) {
43
- return lines.concatMap((line) => lineToWords(line));
44
- }
45
- exports.normalizeWords = normalizeWords;
46
- function lineToWords(line) {
47
- // Remove punctuation and non-letters.
48
- const filteredLine = line.replace(regNonWordOrSpace, '|');
49
- const wordGroups = filteredLine.split('|');
50
- const words = gensequence_1.genSequence(wordGroups)
51
- .concatMap((a) => [a, ...a.split(regExpSpaceOrDash)])
52
- .concatMap((a) => splitCamelCase(a))
53
- .map((a) => a.trim())
54
- .filter((a) => !!a)
55
- .filter((s) => !regExpRepeatChars.test(s))
56
- .map((a) => a.toLowerCase());
57
- return words;
58
- }
59
- exports.lineToWords = lineToWords;
60
- function splitCamelCase(word) {
61
- const splitWords = Text.splitCamelCaseWord(word);
62
- // We only want to preserve this: "New York" and not "Namespace DNSLookup"
63
- if (splitWords.length > 1 && regExpSpaceOrDash.test(word)) {
64
- return gensequence_1.genSequence(splitWords).concatMap((w) => w.split(regExpSpaceOrDash));
65
- }
66
- return splitWords;
67
- }
68
- async function compileWordList(words, destFilename, options) {
69
- const destDir = path.dirname(destFilename);
70
- const pDir = fs_extra_1.mkdirp(destDir);
71
- const compile = options.skipNormalization
72
- ? (a) => a
73
- : options.splitWords
74
- ? compileWordListWithSplitSeq
75
- : compileSimpleWordListSeq;
76
- const seq = compile(words)
77
- .filter((a) => !!a)
78
- .filter(util_1.uniqueFilter(10000));
79
- const finalSeq = options.sort ? gensequence_1.genSequence(sort(seq)) : seq;
80
- await pDir;
81
- return fileWriter_1.writeSeqToFile(finalSeq.map((a) => a + '\n'), destFilename);
82
- }
83
- exports.compileWordList = compileWordList;
84
- function sort(words) {
85
- return [...words].sort();
86
- }
87
- function compileWordListWithSplitSeq(words) {
88
- return words.concatMap((line) => lineToWords(line).toArray());
89
- }
90
- function compileSimpleWordListSeq(words) {
91
- return words.map((a) => a.toLowerCase());
92
- }
93
- function normalizeWordsToTrie(words, normalizer = normalizeWords) {
94
- return Trie.buildTrie(normalizer(words)).root;
95
- }
96
- exports.normalizeWordsToTrie = normalizeWordsToTrie;
97
- exports.consolidate = Trie.consolidate;
98
- async function compileTrie(words, destFilename, options) {
99
- var _a;
100
- log('Reading Words into Trie');
101
- const base = (_a = options.base) !== null && _a !== void 0 ? _a : 32;
102
- const version = options.trie3 ? 3 : 1;
103
- const destDir = path.dirname(destFilename);
104
- const pDir = fs_extra_1.mkdirp(destDir);
105
- const normalizer = options.skipNormalization ? (a) => a : normalizeWords;
106
- const root = normalizeWordsToTrie(words, normalizer);
107
- log('Reduce duplicate word endings');
108
- const trie = exports.consolidate(root);
109
- log(`Writing to file ${path.basename(destFilename)}`);
110
- await pDir;
111
- await fileWriter_1.writeSeqToFile(Trie.serializeTrie(trie, {
112
- base,
113
- comment: 'Built by cspell-tools.',
114
- version,
115
- }), destFilename);
116
- log(`Done writing to file ${path.basename(destFilename)}`);
117
- }
118
- exports.compileTrie = compileTrie;
119
- //# sourceMappingURL=wordListCompiler.js.map