cspell-dictionary 6.9.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.
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/SpellingDictionary/Dictionaries.d.ts +9 -0
- package/dist/SpellingDictionary/Dictionaries.js +61 -0
- package/dist/SpellingDictionary/SpellingDictionary.d.ts +93 -0
- package/dist/SpellingDictionary/SpellingDictionary.js +6 -0
- package/dist/SpellingDictionary/SpellingDictionaryCollection.d.ts +34 -0
- package/dist/SpellingDictionary/SpellingDictionaryCollection.js +111 -0
- package/dist/SpellingDictionary/SpellingDictionaryError.d.ts +10 -0
- package/dist/SpellingDictionary/SpellingDictionaryError.js +18 -0
- package/dist/SpellingDictionary/SpellingDictionaryFromTrie.d.ts +36 -0
- package/dist/SpellingDictionary/SpellingDictionaryFromTrie.js +148 -0
- package/dist/SpellingDictionary/SpellingDictionaryMethods.d.ts +29 -0
- package/dist/SpellingDictionary/SpellingDictionaryMethods.js +114 -0
- package/dist/SpellingDictionary/charset.d.ts +3 -0
- package/dist/SpellingDictionary/charset.js +16 -0
- package/dist/SpellingDictionary/createSpellingDictionary.d.ts +17 -0
- package/dist/SpellingDictionary/createSpellingDictionary.js +91 -0
- package/dist/SpellingDictionary/index.d.ts +4 -0
- package/dist/SpellingDictionary/index.js +9 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +8 -0
- package/dist/util/Comparable.d.ts +20 -0
- package/dist/util/Comparable.js +55 -0
- package/dist/util/FreqCounter.d.ts +16 -0
- package/dist/util/FreqCounter.js +52 -0
- package/dist/util/IterableLike.d.ts +4 -0
- package/dist/util/IterableLike.js +3 -0
- package/dist/util/Memorizer.d.ts +65 -0
- package/dist/util/Memorizer.js +138 -0
- package/dist/util/MinHeapQueue.d.ts +23 -0
- package/dist/util/MinHeapQueue.js +97 -0
- package/dist/util/PairingHeap.d.ts +32 -0
- package/dist/util/PairingHeap.js +90 -0
- package/dist/util/TextMap.d.ts +15 -0
- package/dist/util/TextMap.js +62 -0
- package/dist/util/TextRange.d.ts +28 -0
- package/dist/util/TextRange.js +144 -0
- package/dist/util/clean.d.ts +7 -0
- package/dist/util/clean.js +18 -0
- package/dist/util/debugPerf.d.ts +9 -0
- package/dist/util/debugPerf.js +22 -0
- package/dist/util/errors.d.ts +17 -0
- package/dist/util/errors.js +52 -0
- package/dist/util/fileReader.d.ts +4 -0
- package/dist/util/fileReader.js +21 -0
- package/dist/util/iterableIteratorLib.d.ts +4 -0
- package/dist/util/iterableIteratorLib.js +14 -0
- package/dist/util/logger.d.ts +33 -0
- package/dist/util/logger.js +46 -0
- package/dist/util/memorizerWeak.d.ts +6 -0
- package/dist/util/memorizerWeak.js +42 -0
- package/dist/util/regexHelper.d.ts +7 -0
- package/dist/util/regexHelper.js +13 -0
- package/dist/util/repMap.d.ts +4 -0
- package/dist/util/repMap.js +38 -0
- package/dist/util/resolveFile.d.ts +13 -0
- package/dist/util/resolveFile.js +127 -0
- package/dist/util/search.d.ts +6 -0
- package/dist/util/search.js +23 -0
- package/dist/util/simpleCache.d.ts +46 -0
- package/dist/util/simpleCache.js +143 -0
- package/dist/util/text.d.ts +9 -0
- package/dist/util/text.js +55 -0
- package/dist/util/textRegex.d.ts +1 -0
- package/dist/util/textRegex.js +2 -0
- package/dist/util/timer.d.ts +26 -0
- package/dist/util/timer.js +58 -0
- package/dist/util/types.d.ts +7 -0
- package/dist/util/types.js +3 -0
- package/dist/util/util.d.ts +2 -0
- package/dist/util/util.js +8 -0
- package/dist/util/util.test copy.d.ts +2 -0
- package/dist/util/util.test copy.js +17 -0
- package/dist/util/wordSplitter.d.ts +46 -0
- package/dist/util/wordSplitter.js +326 -0
- package/package.json +47 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.getLogger = exports.setLogger = exports.log = exports.logWarning = exports.logError = void 0;
|
|
5
|
+
let _logger = console;
|
|
6
|
+
/**
|
|
7
|
+
* See `Console.error`
|
|
8
|
+
*/
|
|
9
|
+
function logError(...args) {
|
|
10
|
+
_logger.error(...args);
|
|
11
|
+
}
|
|
12
|
+
exports.logError = logError;
|
|
13
|
+
/**
|
|
14
|
+
* See `Console.warn`
|
|
15
|
+
*/
|
|
16
|
+
function logWarning(...args) {
|
|
17
|
+
_logger.warn(...args);
|
|
18
|
+
}
|
|
19
|
+
exports.logWarning = logWarning;
|
|
20
|
+
/**
|
|
21
|
+
* See `Console.log`
|
|
22
|
+
*/
|
|
23
|
+
function log(...args) {
|
|
24
|
+
_logger.log(...args);
|
|
25
|
+
}
|
|
26
|
+
exports.log = log;
|
|
27
|
+
/**
|
|
28
|
+
* Set the global cspell-lib logger
|
|
29
|
+
* @param logger - a logger like `console`
|
|
30
|
+
* @returns the old logger.
|
|
31
|
+
*/
|
|
32
|
+
function setLogger(logger) {
|
|
33
|
+
const oldLogger = _logger;
|
|
34
|
+
_logger = logger;
|
|
35
|
+
return oldLogger;
|
|
36
|
+
}
|
|
37
|
+
exports.setLogger = setLogger;
|
|
38
|
+
/**
|
|
39
|
+
* Get the current cspell-lib logger.
|
|
40
|
+
* @returns the current logger.
|
|
41
|
+
*/
|
|
42
|
+
function getLogger() {
|
|
43
|
+
return _logger;
|
|
44
|
+
}
|
|
45
|
+
exports.getLogger = getLogger;
|
|
46
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function memorizerWeak<T, K extends object>(fn: (...p: [...K[]]) => T): (...p: [...K[]]) => T;
|
|
2
|
+
export declare function memorizerWeak<T, K0 extends object, K1 extends object>(fn: (...p: [K0, K1]) => T): (...p: [K0, K1]) => T;
|
|
3
|
+
export declare function memorizerWeak<T, K0 extends object, K1 extends object, K2 extends object>(fn: (...p: [K0, K1, K2]) => T): (...p: [K0, K1, K2]) => T;
|
|
4
|
+
export declare function memorizerWeak<T, K0 extends object, K1 extends object, K2 extends object, K3 extends object>(fn: (...p: [K0, K1, K2, K3]) => T): (...p: [K0, K1, K2, K3]) => T;
|
|
5
|
+
export declare function memorizerWeak<T, K0 extends object>(fn: (...p: [K0]) => T): (...p: [K0]) => T;
|
|
6
|
+
//# sourceMappingURL=memorizerWeak.d.ts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.memorizerWeak = void 0;
|
|
4
|
+
// prettier-ignore
|
|
5
|
+
function memorizerWeak(fn) {
|
|
6
|
+
const r = {};
|
|
7
|
+
function find(p) {
|
|
8
|
+
let n = r;
|
|
9
|
+
for (const k of p) {
|
|
10
|
+
if (!n)
|
|
11
|
+
break;
|
|
12
|
+
n = n.c?.get(k);
|
|
13
|
+
}
|
|
14
|
+
return n;
|
|
15
|
+
}
|
|
16
|
+
function set(p, v) {
|
|
17
|
+
let n = r;
|
|
18
|
+
for (const k of p) {
|
|
19
|
+
const c = n.c?.get(k);
|
|
20
|
+
if (c) {
|
|
21
|
+
n = c;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const r = {};
|
|
25
|
+
n.c = n.c || new WeakMap();
|
|
26
|
+
n.c.set(k, r);
|
|
27
|
+
n = r;
|
|
28
|
+
}
|
|
29
|
+
n.v = v;
|
|
30
|
+
}
|
|
31
|
+
return (...p) => {
|
|
32
|
+
const f = find(p);
|
|
33
|
+
if (f && 'v' in f) {
|
|
34
|
+
return f.v;
|
|
35
|
+
}
|
|
36
|
+
const v = fn(...p);
|
|
37
|
+
set(p, v);
|
|
38
|
+
return v;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
exports.memorizerWeak = memorizerWeak;
|
|
42
|
+
//# sourceMappingURL=memorizerWeak.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.escapeRegEx = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Escape a string so it can be used as an exact match within a RegExp.
|
|
6
|
+
* @param s - string to escape
|
|
7
|
+
* @returns - the escaped string.
|
|
8
|
+
*/
|
|
9
|
+
function escapeRegEx(s) {
|
|
10
|
+
return s.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d');
|
|
11
|
+
}
|
|
12
|
+
exports.escapeRegEx = escapeRegEx;
|
|
13
|
+
//# sourceMappingURL=regexHelper.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMapper = void 0;
|
|
4
|
+
const regexHelper_1 = require("./regexHelper");
|
|
5
|
+
function createMapper(repMap) {
|
|
6
|
+
const filteredMap = repMap.filter(([match, _]) => !!match);
|
|
7
|
+
if (!filteredMap.length) {
|
|
8
|
+
return (a) => a;
|
|
9
|
+
}
|
|
10
|
+
const regExStr = filteredMap
|
|
11
|
+
.map(([from, _]) => from)
|
|
12
|
+
// make sure it compiles into a regex
|
|
13
|
+
.map((s) => {
|
|
14
|
+
try {
|
|
15
|
+
// fix up any nested ()
|
|
16
|
+
const r = s.match(/\(/) ? s.replace(/\((?=.*\))/g, '(?:').replace(/\(\?:\?/g, '(?') : s;
|
|
17
|
+
new RegExp(r);
|
|
18
|
+
s = r;
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
return (0, regexHelper_1.escapeRegEx)(s);
|
|
22
|
+
}
|
|
23
|
+
return s;
|
|
24
|
+
})
|
|
25
|
+
.map((s) => `(${s})`)
|
|
26
|
+
.join('|');
|
|
27
|
+
const regEx = new RegExp(regExStr, 'g');
|
|
28
|
+
const values = repMap.filter(([match, _]) => !!match).map(([_, into]) => into);
|
|
29
|
+
function resolve(m, ...matches) {
|
|
30
|
+
const index = matches.findIndex((a) => !!a);
|
|
31
|
+
return 0 <= index && index < values.length ? values[index] : m;
|
|
32
|
+
}
|
|
33
|
+
return function (s) {
|
|
34
|
+
return s.replace(regEx, resolve);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
exports.createMapper = createMapper;
|
|
38
|
+
//# sourceMappingURL=repMap.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface ResolveFileResult {
|
|
2
|
+
filename: string;
|
|
3
|
+
relativeTo: string | undefined;
|
|
4
|
+
found: boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Resolve filename to absolute paths.
|
|
8
|
+
* It tries to look for local files as well as node_modules
|
|
9
|
+
* @param filename an absolute path, relative path, `~` path, or a node_module.
|
|
10
|
+
* @param relativeTo absolute path
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolveFile(filename: string, relativeTo: string): ResolveFileResult;
|
|
13
|
+
//# sourceMappingURL=resolveFile.d.ts.map
|
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.resolveFile = void 0;
|
|
30
|
+
const fs = __importStar(require("fs"));
|
|
31
|
+
const path = __importStar(require("path"));
|
|
32
|
+
const resolve_from_1 = __importDefault(require("resolve-from"));
|
|
33
|
+
const os = __importStar(require("os"));
|
|
34
|
+
const resolve_global_1 = __importDefault(require("resolve-global"));
|
|
35
|
+
const testNodeModules = /^node_modules\//;
|
|
36
|
+
/**
|
|
37
|
+
* Resolve filename to absolute paths.
|
|
38
|
+
* It tries to look for local files as well as node_modules
|
|
39
|
+
* @param filename an absolute path, relative path, `~` path, or a node_module.
|
|
40
|
+
* @param relativeTo absolute path
|
|
41
|
+
*/
|
|
42
|
+
function resolveFile(filename, relativeTo) {
|
|
43
|
+
filename = filename.replace(/^~/, os.homedir());
|
|
44
|
+
const steps = [
|
|
45
|
+
{ filename, fn: tryUrl },
|
|
46
|
+
{ filename, fn: tryNodeResolve },
|
|
47
|
+
{ filename: path.resolve(relativeTo, filename), fn: tryResolveExists },
|
|
48
|
+
{ filename: path.resolve(filename), fn: tryResolveExists },
|
|
49
|
+
{ filename, fn: tryNodeResolveDefaultPaths },
|
|
50
|
+
{ filename, fn: tryResolveFrom },
|
|
51
|
+
{ filename: filename.replace(testNodeModules, ''), fn: tryResolveFrom },
|
|
52
|
+
{ filename, fn: tryResolveGlobal },
|
|
53
|
+
];
|
|
54
|
+
for (const step of steps) {
|
|
55
|
+
const r = step.fn(step.filename, relativeTo);
|
|
56
|
+
if (r.found)
|
|
57
|
+
return r;
|
|
58
|
+
}
|
|
59
|
+
return { filename: path.resolve(relativeTo, filename), relativeTo, found: false };
|
|
60
|
+
}
|
|
61
|
+
exports.resolveFile = resolveFile;
|
|
62
|
+
const isUrlRegExp = /^\w+:\/\//i;
|
|
63
|
+
/**
|
|
64
|
+
* Check to see if it is a URL.
|
|
65
|
+
* Note: URLs are absolute!
|
|
66
|
+
* @param filename - url string
|
|
67
|
+
* @returns ResolveFileResult
|
|
68
|
+
*/
|
|
69
|
+
function tryUrl(filename, relativeTo) {
|
|
70
|
+
if (isUrlRegExp.test(filename)) {
|
|
71
|
+
return { filename, relativeTo: undefined, found: true };
|
|
72
|
+
}
|
|
73
|
+
if (isUrlRegExp.test(relativeTo)) {
|
|
74
|
+
const url = new URL(filename, relativeTo);
|
|
75
|
+
return { filename: url.href, relativeTo, found: true };
|
|
76
|
+
}
|
|
77
|
+
return { filename, relativeTo: undefined, found: false };
|
|
78
|
+
}
|
|
79
|
+
function tryNodeResolveDefaultPaths(filename) {
|
|
80
|
+
try {
|
|
81
|
+
const r = require.resolve(filename);
|
|
82
|
+
return { filename: r, relativeTo: undefined, found: true };
|
|
83
|
+
}
|
|
84
|
+
catch (_) {
|
|
85
|
+
return { filename, relativeTo: undefined, found: false };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function tryNodeResolve(filename, relativeTo) {
|
|
89
|
+
const home = os.homedir();
|
|
90
|
+
function calcPaths(p) {
|
|
91
|
+
const paths = [p];
|
|
92
|
+
// Do not progress towards the root if it is a relative filename.
|
|
93
|
+
if (filename.startsWith('.') &&
|
|
94
|
+
(filename.startsWith('./') || filename.startsWith('.' + path.sep) || filename.startsWith('..'))) {
|
|
95
|
+
return paths;
|
|
96
|
+
}
|
|
97
|
+
for (; p && path.dirname(p) !== p && p !== home; p = path.dirname(p)) {
|
|
98
|
+
paths.push(p);
|
|
99
|
+
}
|
|
100
|
+
return paths;
|
|
101
|
+
}
|
|
102
|
+
const paths = calcPaths(path.resolve(relativeTo));
|
|
103
|
+
try {
|
|
104
|
+
const r = require.resolve(filename, { paths });
|
|
105
|
+
return { filename: r, relativeTo, found: true };
|
|
106
|
+
}
|
|
107
|
+
catch (_) {
|
|
108
|
+
return { filename, relativeTo, found: false };
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function tryResolveGlobal(filename) {
|
|
112
|
+
const r = resolve_global_1.default.silent(filename);
|
|
113
|
+
return { filename: r || filename, relativeTo: undefined, found: !!r };
|
|
114
|
+
}
|
|
115
|
+
function tryResolveExists(filename) {
|
|
116
|
+
return { filename, relativeTo: undefined, found: fs.existsSync(filename) };
|
|
117
|
+
}
|
|
118
|
+
function tryResolveFrom(filename, relativeTo) {
|
|
119
|
+
try {
|
|
120
|
+
return { filename: (0, resolve_from_1.default)(relativeTo, filename), relativeTo, found: true };
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
// Failed to resolve a relative module request
|
|
124
|
+
return { filename: filename, relativeTo, found: false };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=resolveFile.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search for an item in a sorted array.
|
|
3
|
+
* The value returned is either the position of the item or where it should be inserted.
|
|
4
|
+
*/
|
|
5
|
+
export declare function binarySearch<T>(arr: Array<T>, item: T, leftOffset?: number, rightOffset?: number): number;
|
|
6
|
+
//# sourceMappingURL=search.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.binarySearch = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Search for an item in a sorted array.
|
|
6
|
+
* The value returned is either the position of the item or where it should be inserted.
|
|
7
|
+
*/
|
|
8
|
+
function binarySearch(arr, item, leftOffset, rightOffset) {
|
|
9
|
+
let left = Math.max(leftOffset ?? 0, 0);
|
|
10
|
+
let right = Math.min(rightOffset ?? arr.length, arr.length);
|
|
11
|
+
while (left < right) {
|
|
12
|
+
const pos = (left + right) >> 1;
|
|
13
|
+
if (arr[pos] < item) {
|
|
14
|
+
left = pos + 1;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
right = pos;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return left;
|
|
21
|
+
}
|
|
22
|
+
exports.binarySearch = binarySearch;
|
|
23
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export declare class SimpleWeakCache<K extends object, T> {
|
|
2
|
+
readonly size: number;
|
|
3
|
+
private L0;
|
|
4
|
+
private L1;
|
|
5
|
+
private L2;
|
|
6
|
+
private sizeL0;
|
|
7
|
+
constructor(size: number);
|
|
8
|
+
has(key: K): boolean;
|
|
9
|
+
get(key: K): T | undefined;
|
|
10
|
+
set(key: K, value: T): void;
|
|
11
|
+
private _set;
|
|
12
|
+
private caches;
|
|
13
|
+
private rotate;
|
|
14
|
+
}
|
|
15
|
+
export declare class AutoWeakCache<K extends object, T> extends SimpleWeakCache<K, T> {
|
|
16
|
+
readonly factory: (key: K) => T;
|
|
17
|
+
constructor(factory: (key: K) => T, size: number);
|
|
18
|
+
get(key: K): T;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* This will cache between `size` and 3 x `size` items.
|
|
22
|
+
* It has three stashes, L0, L1, and L2. Each can contain `size` items.
|
|
23
|
+
* When L0 is full, its items are given to L1 and L1's are given to L2, and L2 is empties.
|
|
24
|
+
*
|
|
25
|
+
* The stashes are searched in order, L0...L2. If an item is found in L1, or L2, it is
|
|
26
|
+
* promoted to L0.
|
|
27
|
+
*/
|
|
28
|
+
export declare class SimpleCache<K, T> {
|
|
29
|
+
readonly size: number;
|
|
30
|
+
private L0;
|
|
31
|
+
private L1;
|
|
32
|
+
private L2;
|
|
33
|
+
constructor(size: number);
|
|
34
|
+
has(key: K): boolean;
|
|
35
|
+
get(key: K): T | undefined;
|
|
36
|
+
set(key: K, value: T): void;
|
|
37
|
+
private _set;
|
|
38
|
+
private caches;
|
|
39
|
+
private rotate;
|
|
40
|
+
}
|
|
41
|
+
export declare class AutoCache<K, T> extends SimpleCache<K, T> {
|
|
42
|
+
readonly factory: (key: K) => T;
|
|
43
|
+
constructor(factory: (key: K) => T, size: number);
|
|
44
|
+
get(key: K): T;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=simpleCache.d.ts.map
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AutoCache = exports.SimpleCache = exports.AutoWeakCache = exports.SimpleWeakCache = void 0;
|
|
4
|
+
class SimpleWeakCache {
|
|
5
|
+
constructor(size) {
|
|
6
|
+
this.size = size;
|
|
7
|
+
this.L0 = new WeakMap();
|
|
8
|
+
this.L1 = new WeakMap();
|
|
9
|
+
this.L2 = new WeakMap();
|
|
10
|
+
this.sizeL0 = 0;
|
|
11
|
+
}
|
|
12
|
+
has(key) {
|
|
13
|
+
for (const c of this.caches()) {
|
|
14
|
+
if (c.has(key))
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
get(key) {
|
|
20
|
+
for (const c of this.caches()) {
|
|
21
|
+
const entry = c.get(key);
|
|
22
|
+
if (entry) {
|
|
23
|
+
if (c !== this.L0) {
|
|
24
|
+
this._set(key, entry);
|
|
25
|
+
}
|
|
26
|
+
return entry.v;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
set(key, value) {
|
|
32
|
+
this._set(key, { v: value });
|
|
33
|
+
}
|
|
34
|
+
_set(key, entry) {
|
|
35
|
+
if (this.L0.has(key)) {
|
|
36
|
+
this.L0.set(key, entry);
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
if (this.sizeL0 >= this.size) {
|
|
40
|
+
this.rotate();
|
|
41
|
+
}
|
|
42
|
+
this.sizeL0 += 1;
|
|
43
|
+
this.L0.set(key, entry);
|
|
44
|
+
}
|
|
45
|
+
caches() {
|
|
46
|
+
return [this.L0, this.L1, this.L2];
|
|
47
|
+
}
|
|
48
|
+
rotate() {
|
|
49
|
+
this.L2 = this.L1;
|
|
50
|
+
this.L1 = this.L0;
|
|
51
|
+
this.L0 = new WeakMap();
|
|
52
|
+
this.sizeL0 = 0;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.SimpleWeakCache = SimpleWeakCache;
|
|
56
|
+
class AutoWeakCache extends SimpleWeakCache {
|
|
57
|
+
constructor(factory, size) {
|
|
58
|
+
super(size);
|
|
59
|
+
this.factory = factory;
|
|
60
|
+
}
|
|
61
|
+
get(key) {
|
|
62
|
+
const v = super.get(key);
|
|
63
|
+
if (v !== undefined)
|
|
64
|
+
return v;
|
|
65
|
+
const val = this.factory(key);
|
|
66
|
+
this.set(key, val);
|
|
67
|
+
return val;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.AutoWeakCache = AutoWeakCache;
|
|
71
|
+
/**
|
|
72
|
+
* This will cache between `size` and 3 x `size` items.
|
|
73
|
+
* It has three stashes, L0, L1, and L2. Each can contain `size` items.
|
|
74
|
+
* When L0 is full, its items are given to L1 and L1's are given to L2, and L2 is empties.
|
|
75
|
+
*
|
|
76
|
+
* The stashes are searched in order, L0...L2. If an item is found in L1, or L2, it is
|
|
77
|
+
* promoted to L0.
|
|
78
|
+
*/
|
|
79
|
+
class SimpleCache {
|
|
80
|
+
constructor(size) {
|
|
81
|
+
this.size = size;
|
|
82
|
+
this.L0 = new Map();
|
|
83
|
+
this.L1 = new Map();
|
|
84
|
+
this.L2 = new Map();
|
|
85
|
+
}
|
|
86
|
+
has(key) {
|
|
87
|
+
for (const c of this.caches()) {
|
|
88
|
+
if (c.has(key))
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
get(key) {
|
|
94
|
+
for (const c of this.caches()) {
|
|
95
|
+
const entry = c.get(key);
|
|
96
|
+
if (entry) {
|
|
97
|
+
if (c !== this.L0) {
|
|
98
|
+
this._set(key, entry);
|
|
99
|
+
}
|
|
100
|
+
return entry.v;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
set(key, value) {
|
|
106
|
+
this._set(key, { v: value });
|
|
107
|
+
}
|
|
108
|
+
_set(key, entry) {
|
|
109
|
+
if (this.L0.has(key)) {
|
|
110
|
+
this.L0.set(key, entry);
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
if (this.L0.size >= this.size) {
|
|
114
|
+
this.rotate();
|
|
115
|
+
}
|
|
116
|
+
this.L0.set(key, entry);
|
|
117
|
+
}
|
|
118
|
+
caches() {
|
|
119
|
+
return [this.L0, this.L1, this.L2];
|
|
120
|
+
}
|
|
121
|
+
rotate() {
|
|
122
|
+
this.L2 = this.L1;
|
|
123
|
+
this.L1 = this.L0;
|
|
124
|
+
this.L0 = new Map();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.SimpleCache = SimpleCache;
|
|
128
|
+
class AutoCache extends SimpleCache {
|
|
129
|
+
constructor(factory, size) {
|
|
130
|
+
super(size);
|
|
131
|
+
this.factory = factory;
|
|
132
|
+
}
|
|
133
|
+
get(key) {
|
|
134
|
+
const v = super.get(key);
|
|
135
|
+
if (v !== undefined)
|
|
136
|
+
return v;
|
|
137
|
+
const val = this.factory(key);
|
|
138
|
+
this.set(key, val);
|
|
139
|
+
return val;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.AutoCache = AutoCache;
|
|
143
|
+
//# sourceMappingURL=simpleCache.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function isUpperCase(word: string): boolean;
|
|
2
|
+
export declare function isLowerCase(word: string): boolean;
|
|
3
|
+
export declare function isFirstCharacterUpper(word: string): boolean;
|
|
4
|
+
export declare function isFirstCharacterLower(word: string): boolean;
|
|
5
|
+
export declare function ucFirst(word: string): string;
|
|
6
|
+
export declare function lcFirst(word: string): string;
|
|
7
|
+
export declare function matchCase(example: string, word: string): string;
|
|
8
|
+
export declare function removeAccents(text: string): string;
|
|
9
|
+
//# sourceMappingURL=text.d.ts.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeAccents = exports.matchCase = exports.lcFirst = exports.ucFirst = exports.isFirstCharacterLower = exports.isFirstCharacterUpper = exports.isLowerCase = exports.isUpperCase = void 0;
|
|
4
|
+
const regExFirstUpper = /^\p{Lu}\p{M}?\p{Ll}+$/u;
|
|
5
|
+
const regExAllUpper = /^(?:\p{Lu}\p{M}?)+$/u;
|
|
6
|
+
const regExAllLower = /^(?:\p{Ll}\p{M}?)+$/u;
|
|
7
|
+
const regExAccents = /\p{M}/gu;
|
|
8
|
+
function isUpperCase(word) {
|
|
9
|
+
return !!word.match(regExAllUpper);
|
|
10
|
+
}
|
|
11
|
+
exports.isUpperCase = isUpperCase;
|
|
12
|
+
function isLowerCase(word) {
|
|
13
|
+
return !!word.match(regExAllLower);
|
|
14
|
+
}
|
|
15
|
+
exports.isLowerCase = isLowerCase;
|
|
16
|
+
function isFirstCharacterUpper(word) {
|
|
17
|
+
return isUpperCase(word.slice(0, 1));
|
|
18
|
+
}
|
|
19
|
+
exports.isFirstCharacterUpper = isFirstCharacterUpper;
|
|
20
|
+
function isFirstCharacterLower(word) {
|
|
21
|
+
return isLowerCase(word.slice(0, 1));
|
|
22
|
+
}
|
|
23
|
+
exports.isFirstCharacterLower = isFirstCharacterLower;
|
|
24
|
+
function ucFirst(word) {
|
|
25
|
+
return word.slice(0, 1).toUpperCase() + word.slice(1);
|
|
26
|
+
}
|
|
27
|
+
exports.ucFirst = ucFirst;
|
|
28
|
+
function lcFirst(word) {
|
|
29
|
+
return word.slice(0, 1).toLowerCase() + word.slice(1);
|
|
30
|
+
}
|
|
31
|
+
exports.lcFirst = lcFirst;
|
|
32
|
+
function matchCase(example, word) {
|
|
33
|
+
if (example.match(regExFirstUpper)) {
|
|
34
|
+
return word.slice(0, 1).toUpperCase() + word.slice(1).toLowerCase();
|
|
35
|
+
}
|
|
36
|
+
if (example.match(regExAllLower)) {
|
|
37
|
+
return word.toLowerCase();
|
|
38
|
+
}
|
|
39
|
+
if (example.match(regExAllUpper)) {
|
|
40
|
+
return word.toUpperCase();
|
|
41
|
+
}
|
|
42
|
+
if (isFirstCharacterUpper(example)) {
|
|
43
|
+
return ucFirst(word);
|
|
44
|
+
}
|
|
45
|
+
if (isFirstCharacterLower(example)) {
|
|
46
|
+
return lcFirst(word);
|
|
47
|
+
}
|
|
48
|
+
return word;
|
|
49
|
+
}
|
|
50
|
+
exports.matchCase = matchCase;
|
|
51
|
+
function removeAccents(text) {
|
|
52
|
+
return text.normalize('NFD').replace(regExAccents, '');
|
|
53
|
+
}
|
|
54
|
+
exports.removeAccents = removeAccents;
|
|
55
|
+
//# sourceMappingURL=text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=textRegex.d.ts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface Timer {
|
|
2
|
+
/** Start / restart the timer. */
|
|
3
|
+
start(): void;
|
|
4
|
+
/**
|
|
5
|
+
* Calculate the amount of time in ms since the
|
|
6
|
+
* timer was created / started.
|
|
7
|
+
*/
|
|
8
|
+
elapsed(): number;
|
|
9
|
+
/**
|
|
10
|
+
* Calculate the amount of time in ms since the
|
|
11
|
+
* end of the last lap.
|
|
12
|
+
*/
|
|
13
|
+
lap(): number;
|
|
14
|
+
}
|
|
15
|
+
export declare function createTimer(hrTimeFn?: HRTimeFn): Timer;
|
|
16
|
+
export declare type HRTimeFn = (time?: HRTime) => HRTime;
|
|
17
|
+
export declare type HRTime = [number, number];
|
|
18
|
+
export declare function toMilliseconds(t: HRTime): number;
|
|
19
|
+
export declare function polyHrTime(time?: HRTime): HRTime;
|
|
20
|
+
export interface LapRecorder {
|
|
21
|
+
times: [name: string, lapTime: number, totalTime: number][];
|
|
22
|
+
lap(name: string): void;
|
|
23
|
+
report(): string[];
|
|
24
|
+
}
|
|
25
|
+
export declare function createLapRecorder(): LapRecorder;
|
|
26
|
+
//# sourceMappingURL=timer.d.ts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLapRecorder = exports.polyHrTime = exports.toMilliseconds = exports.createTimer = void 0;
|
|
4
|
+
const _hrTime = process?.hrtime || polyHrTime;
|
|
5
|
+
function createTimer(hrTimeFn = _hrTime) {
|
|
6
|
+
let start = hrTimeFn();
|
|
7
|
+
let lastLap = 0;
|
|
8
|
+
function elapsed() {
|
|
9
|
+
return toMilliseconds(hrTimeFn(start));
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
start() {
|
|
13
|
+
start = hrTimeFn();
|
|
14
|
+
lastLap = 0;
|
|
15
|
+
},
|
|
16
|
+
elapsed,
|
|
17
|
+
lap() {
|
|
18
|
+
const now = elapsed();
|
|
19
|
+
const diff = now - lastLap;
|
|
20
|
+
lastLap = now;
|
|
21
|
+
return diff;
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
exports.createTimer = createTimer;
|
|
26
|
+
function toMilliseconds(t) {
|
|
27
|
+
return (t[0] + t[1] * 1e-9) * 1000;
|
|
28
|
+
}
|
|
29
|
+
exports.toMilliseconds = toMilliseconds;
|
|
30
|
+
function polyHrTime(time) {
|
|
31
|
+
const now = Date.now() - (time ? toMilliseconds(time) : 0);
|
|
32
|
+
const inSeconds = now * 1.0e-3;
|
|
33
|
+
const s = Math.floor(inSeconds);
|
|
34
|
+
const n = (inSeconds - s) * 1.0e9;
|
|
35
|
+
return [s, n];
|
|
36
|
+
}
|
|
37
|
+
exports.polyHrTime = polyHrTime;
|
|
38
|
+
function createLapRecorder() {
|
|
39
|
+
const timer = createTimer();
|
|
40
|
+
const times = [];
|
|
41
|
+
let lapTime = 0;
|
|
42
|
+
function lap(name) {
|
|
43
|
+
const now = timer.elapsed();
|
|
44
|
+
const diff = now - lapTime;
|
|
45
|
+
times.push([name, diff, now]);
|
|
46
|
+
lapTime = diff;
|
|
47
|
+
}
|
|
48
|
+
function report() {
|
|
49
|
+
return times.map(([name, time]) => `${name}: ${time.toFixed(2)}`);
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
times,
|
|
53
|
+
lap,
|
|
54
|
+
report,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
exports.createLapRecorder = createLapRecorder;
|
|
58
|
+
//# sourceMappingURL=timer.js.map
|