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,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.__testing__ = exports.MinHeapQueue = void 0;
|
|
4
|
+
function swap(t, i, j) {
|
|
5
|
+
const a = t[i];
|
|
6
|
+
t[i] = t[j];
|
|
7
|
+
t[j] = a;
|
|
8
|
+
}
|
|
9
|
+
function addToHeap(t, c, compare) {
|
|
10
|
+
t.push(c);
|
|
11
|
+
let b = t.length - 1;
|
|
12
|
+
let a = (b - 1) >> 1;
|
|
13
|
+
while (b > 0 && compare(t[a], t[b]) >= 0) {
|
|
14
|
+
swap(t, a, b);
|
|
15
|
+
b = a;
|
|
16
|
+
a = (b - 1) >> 1;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function takeFromHeap(t, compare) {
|
|
20
|
+
const result = t[0];
|
|
21
|
+
if (t.length <= 1) {
|
|
22
|
+
t.length = 0;
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
t[0] = t[t.length - 1];
|
|
26
|
+
t.length -= 1;
|
|
27
|
+
const m = t.length - 1;
|
|
28
|
+
let i = 0;
|
|
29
|
+
let j = i * 2 + 1;
|
|
30
|
+
while (j < m) {
|
|
31
|
+
const a = j;
|
|
32
|
+
const b = j + 1;
|
|
33
|
+
const k = compare(t[a], t[b]) < 0 ? a : b;
|
|
34
|
+
if (compare(t[i], t[k]) <= 0) {
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
swap(t, i, k);
|
|
38
|
+
i = k;
|
|
39
|
+
j = i * 2 + 1;
|
|
40
|
+
}
|
|
41
|
+
if (j === m) {
|
|
42
|
+
if (compare(t[i], t[j]) > 0) {
|
|
43
|
+
swap(t, i, j);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* MinHeapQueue - based upon a minHeap array.
|
|
50
|
+
*/
|
|
51
|
+
class MinHeapQueue {
|
|
52
|
+
constructor(compare) {
|
|
53
|
+
this.compare = compare;
|
|
54
|
+
this.values = [];
|
|
55
|
+
}
|
|
56
|
+
add(t) {
|
|
57
|
+
addToHeap(this.values, t, this.compare);
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
get length() {
|
|
61
|
+
return this.values.length;
|
|
62
|
+
}
|
|
63
|
+
dequeue() {
|
|
64
|
+
return takeFromHeap(this.values, this.compare);
|
|
65
|
+
}
|
|
66
|
+
concat(i) {
|
|
67
|
+
for (const v of i) {
|
|
68
|
+
this.add(v);
|
|
69
|
+
}
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
next() {
|
|
73
|
+
const value = this.dequeue();
|
|
74
|
+
return value !== undefined
|
|
75
|
+
? {
|
|
76
|
+
value,
|
|
77
|
+
}
|
|
78
|
+
: {
|
|
79
|
+
value,
|
|
80
|
+
done: true,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
[Symbol.iterator]() {
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
clone() {
|
|
87
|
+
const clone = new MinHeapQueue(this.compare);
|
|
88
|
+
clone.values = this.values.concat();
|
|
89
|
+
return clone;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.MinHeapQueue = MinHeapQueue;
|
|
93
|
+
exports.__testing__ = {
|
|
94
|
+
addToHeap,
|
|
95
|
+
takeFromHeap,
|
|
96
|
+
};
|
|
97
|
+
//# sourceMappingURL=MinHeapQueue.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface PairHeapNode<T> {
|
|
2
|
+
/** Value */
|
|
3
|
+
v: T;
|
|
4
|
+
/** Siblings */
|
|
5
|
+
s: PairHeapNode<T> | undefined;
|
|
6
|
+
/** Children */
|
|
7
|
+
c: PairHeapNode<T> | undefined;
|
|
8
|
+
}
|
|
9
|
+
export declare type CompareFn<T> = (a: T, b: T) => number;
|
|
10
|
+
export declare class PairingHeap<T> implements IterableIterator<T> {
|
|
11
|
+
readonly compare: CompareFn<T>;
|
|
12
|
+
private _heap;
|
|
13
|
+
private _size;
|
|
14
|
+
constructor(compare: CompareFn<T>);
|
|
15
|
+
add(v: T): this;
|
|
16
|
+
dequeue(): T | undefined;
|
|
17
|
+
concat(i: Iterable<T>): this;
|
|
18
|
+
next(): IteratorResult<T>;
|
|
19
|
+
peek(): T | undefined;
|
|
20
|
+
[Symbol.iterator](): IterableIterator<T>;
|
|
21
|
+
get length(): number;
|
|
22
|
+
}
|
|
23
|
+
declare function insert<T>(compare: CompareFn<T>, heap: PairHeapNode<T> | undefined, v: T): PairHeapNode<T>;
|
|
24
|
+
declare function merge<T>(compare: CompareFn<T>, a: PairHeapNode<T>, b: PairHeapNode<T>): PairHeapNode<T>;
|
|
25
|
+
declare function mergeSiblings<T>(compare: CompareFn<T>, n: PairHeapNode<T>): PairHeapNode<T>;
|
|
26
|
+
export declare const heapMethods: {
|
|
27
|
+
insert: typeof insert;
|
|
28
|
+
merge: typeof merge;
|
|
29
|
+
mergeSiblings: typeof mergeSiblings;
|
|
30
|
+
};
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=PairingHeap.d.ts.map
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.heapMethods = exports.PairingHeap = void 0;
|
|
4
|
+
class PairingHeap {
|
|
5
|
+
constructor(compare) {
|
|
6
|
+
this.compare = compare;
|
|
7
|
+
this._size = 0;
|
|
8
|
+
}
|
|
9
|
+
add(v) {
|
|
10
|
+
this._heap = insert(this.compare, this._heap, v);
|
|
11
|
+
++this._size;
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
dequeue() {
|
|
15
|
+
const n = this.next();
|
|
16
|
+
if (n.done)
|
|
17
|
+
return undefined;
|
|
18
|
+
return n.value;
|
|
19
|
+
}
|
|
20
|
+
concat(i) {
|
|
21
|
+
for (const v of i) {
|
|
22
|
+
this.add(v);
|
|
23
|
+
}
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
next() {
|
|
27
|
+
if (!this._heap) {
|
|
28
|
+
return { value: undefined, done: true };
|
|
29
|
+
}
|
|
30
|
+
const value = this._heap.v;
|
|
31
|
+
--this._size;
|
|
32
|
+
this._heap = removeHead(this.compare, this._heap);
|
|
33
|
+
return { value };
|
|
34
|
+
}
|
|
35
|
+
peek() {
|
|
36
|
+
return this._heap?.v;
|
|
37
|
+
}
|
|
38
|
+
[Symbol.iterator]() {
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
get length() {
|
|
42
|
+
return this._size;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.PairingHeap = PairingHeap;
|
|
46
|
+
function removeHead(compare, heap) {
|
|
47
|
+
if (!heap || !heap.c)
|
|
48
|
+
return undefined;
|
|
49
|
+
return mergeSiblings(compare, heap.c);
|
|
50
|
+
}
|
|
51
|
+
function insert(compare, heap, v) {
|
|
52
|
+
const n = {
|
|
53
|
+
v,
|
|
54
|
+
s: undefined,
|
|
55
|
+
c: undefined,
|
|
56
|
+
};
|
|
57
|
+
if (!heap || compare(v, heap.v) <= 0) {
|
|
58
|
+
n.c = heap;
|
|
59
|
+
return n;
|
|
60
|
+
}
|
|
61
|
+
n.s = heap.c;
|
|
62
|
+
heap.c = n;
|
|
63
|
+
return heap;
|
|
64
|
+
}
|
|
65
|
+
function merge(compare, a, b) {
|
|
66
|
+
if (compare(a.v, b.v) <= 0) {
|
|
67
|
+
a.s = undefined;
|
|
68
|
+
b.s = a.c;
|
|
69
|
+
a.c = b;
|
|
70
|
+
return a;
|
|
71
|
+
}
|
|
72
|
+
b.s = undefined;
|
|
73
|
+
a.s = b.c;
|
|
74
|
+
b.c = a;
|
|
75
|
+
return b;
|
|
76
|
+
}
|
|
77
|
+
function mergeSiblings(compare, n) {
|
|
78
|
+
if (!n.s)
|
|
79
|
+
return n;
|
|
80
|
+
const s = n.s;
|
|
81
|
+
const ss = s.s;
|
|
82
|
+
const m = merge(compare, n, s);
|
|
83
|
+
return ss ? merge(compare, m, mergeSiblings(compare, ss)) : m;
|
|
84
|
+
}
|
|
85
|
+
exports.heapMethods = {
|
|
86
|
+
insert,
|
|
87
|
+
merge,
|
|
88
|
+
mergeSiblings,
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=PairingHeap.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { MappedText } from '@cspell/cspell-types';
|
|
2
|
+
import { Range } from '@cspell/cspell-types/Parser';
|
|
3
|
+
/**
|
|
4
|
+
* Extract a substring from a TextMap.
|
|
5
|
+
* @param textMap - A text range with an optional map
|
|
6
|
+
* @param extractRange - The range in the original document to extract
|
|
7
|
+
* @returns The TextMap covering extractRange
|
|
8
|
+
*/
|
|
9
|
+
export declare function extractTextMapRangeOrigin(textMap: MappedText, extractRange: Range): MappedText;
|
|
10
|
+
interface WithRange {
|
|
11
|
+
readonly range: Range;
|
|
12
|
+
}
|
|
13
|
+
export declare function doesIntersect(textMap: WithRange, rangeOrigin: Range): boolean;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=TextMap.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.doesIntersect = exports.extractTextMapRangeOrigin = void 0;
|
|
7
|
+
const assert_1 = __importDefault(require("assert"));
|
|
8
|
+
/**
|
|
9
|
+
* Extract a substring from a TextMap.
|
|
10
|
+
* @param textMap - A text range with an optional map
|
|
11
|
+
* @param extractRange - The range in the original document to extract
|
|
12
|
+
* @returns The TextMap covering extractRange
|
|
13
|
+
*/
|
|
14
|
+
function extractTextMapRangeOrigin(textMap, extractRange) {
|
|
15
|
+
const { text: srcTxt, range: srcRange, map: srcMap } = textMap;
|
|
16
|
+
const [r0, r1] = srcRange;
|
|
17
|
+
const startOrig = Math.min(Math.max(extractRange[0], r0), r1);
|
|
18
|
+
const endOrig = Math.min(Math.max(extractRange[1], r0), r1);
|
|
19
|
+
const a = startOrig - r0;
|
|
20
|
+
const b = endOrig - r0;
|
|
21
|
+
const range = [startOrig, endOrig];
|
|
22
|
+
if (!srcMap || !srcMap.length || a === b) {
|
|
23
|
+
const text = srcTxt.slice(a, b);
|
|
24
|
+
return { text, range };
|
|
25
|
+
}
|
|
26
|
+
(0, assert_1.default)((srcMap.length & 1) === 0, 'Map must be pairs of values.');
|
|
27
|
+
const mapLen = srcMap.length;
|
|
28
|
+
const mapEndSrc = srcMap[mapLen - 2];
|
|
29
|
+
const mapEndDst = srcMap[mapLen - 1];
|
|
30
|
+
const endDiff = srcTxt.length - mapEndDst;
|
|
31
|
+
const head = !srcMap[0] && !srcMap[1] ? [] : [0, 0];
|
|
32
|
+
const tail = [mapEndSrc + endDiff, mapEndDst + endDiff];
|
|
33
|
+
const sMap = head.concat(srcMap).concat(tail);
|
|
34
|
+
let idx = 0;
|
|
35
|
+
for (; idx < sMap.length && a >= sMap[idx]; idx += 2) {
|
|
36
|
+
// empty
|
|
37
|
+
}
|
|
38
|
+
const aIdx = idx;
|
|
39
|
+
idx -= 2;
|
|
40
|
+
const a0 = a - sMap[idx];
|
|
41
|
+
const a1 = a0 + sMap[idx + 1];
|
|
42
|
+
for (; idx < sMap.length && b > sMap[idx]; idx += 2) {
|
|
43
|
+
// empty
|
|
44
|
+
}
|
|
45
|
+
const bIdx = idx;
|
|
46
|
+
const b0 = b - sMap[idx];
|
|
47
|
+
const b1 = b0 + sMap[idx + 1];
|
|
48
|
+
const text = srcTxt.slice(a1, b1);
|
|
49
|
+
if (bIdx === aIdx) {
|
|
50
|
+
return { text, range };
|
|
51
|
+
}
|
|
52
|
+
const ab = [a0, a1];
|
|
53
|
+
const map = sMap.slice(aIdx, bIdx + 2).map((v, i) => v - ab[i & 1]);
|
|
54
|
+
return { text, range, map };
|
|
55
|
+
}
|
|
56
|
+
exports.extractTextMapRangeOrigin = extractTextMapRangeOrigin;
|
|
57
|
+
function doesIntersect(textMap, rangeOrigin) {
|
|
58
|
+
const r = textMap.range;
|
|
59
|
+
return r[0] < rangeOrigin[1] && r[1] > rangeOrigin[0];
|
|
60
|
+
}
|
|
61
|
+
exports.doesIntersect = doesIntersect;
|
|
62
|
+
//# sourceMappingURL=TextMap.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface MatchRange {
|
|
2
|
+
startPos: number;
|
|
3
|
+
endPos: number;
|
|
4
|
+
}
|
|
5
|
+
export interface MatchRangeWithText extends MatchRange {
|
|
6
|
+
text: string;
|
|
7
|
+
}
|
|
8
|
+
export interface MatchRangeOptionalText extends MatchRange {
|
|
9
|
+
text?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function findMatchingRanges(pattern: RegExp, text: string): MatchRangeOptionalText[];
|
|
12
|
+
export declare function unionRanges(ranges: MatchRange[]): MatchRange[];
|
|
13
|
+
export declare function findMatchingRangesForPatterns(patterns: RegExp[], text: string): MatchRange[];
|
|
14
|
+
/**
|
|
15
|
+
* Create a new set of positions that have the excluded position ranges removed.
|
|
16
|
+
*/
|
|
17
|
+
export declare function excludeRanges(includeRanges: MatchRange[], excludeRanges: MatchRange[]): MatchRange[];
|
|
18
|
+
export declare function extractRangeText(text: string, ranges: MatchRange[]): MatchRangeWithText[];
|
|
19
|
+
declare const SymSortedMatchRangeArray: unique symbol;
|
|
20
|
+
interface SortedMatchRangeArray extends Array<MatchRange> {
|
|
21
|
+
[SymSortedMatchRangeArray]: true;
|
|
22
|
+
}
|
|
23
|
+
declare function makeSortedMatchRangeArray(sortedValues: MatchRange[]): SortedMatchRangeArray;
|
|
24
|
+
export declare const __testing__: {
|
|
25
|
+
makeSortedMatchRangeArray: typeof makeSortedMatchRangeArray;
|
|
26
|
+
};
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=TextRange.d.ts.map
|
|
@@ -0,0 +1,144 @@
|
|
|
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.__testing__ = exports.extractRangeText = exports.excludeRanges = exports.findMatchingRangesForPatterns = exports.unionRanges = exports.findMatchingRanges = void 0;
|
|
27
|
+
const GS = __importStar(require("gensequence"));
|
|
28
|
+
function toMatchRangeWithText(m) {
|
|
29
|
+
const index = m.index || 0;
|
|
30
|
+
const _text = m[0];
|
|
31
|
+
return {
|
|
32
|
+
startPos: index,
|
|
33
|
+
endPos: index + _text.length,
|
|
34
|
+
text: _text,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function findMatchingRanges(pattern, text) {
|
|
38
|
+
if (pattern.source === '.*') {
|
|
39
|
+
return [{ startPos: 0, endPos: text.length }];
|
|
40
|
+
}
|
|
41
|
+
const regex = new RegExp(pattern);
|
|
42
|
+
if (!regex.global) {
|
|
43
|
+
const m = text.match(regex);
|
|
44
|
+
if (!m)
|
|
45
|
+
return [];
|
|
46
|
+
return [toMatchRangeWithText(m)];
|
|
47
|
+
}
|
|
48
|
+
return [...text.matchAll(regex)].map(toMatchRangeWithText);
|
|
49
|
+
}
|
|
50
|
+
exports.findMatchingRanges = findMatchingRanges;
|
|
51
|
+
function compareRanges(a, b) {
|
|
52
|
+
return a.startPos - b.startPos || a.endPos - b.endPos;
|
|
53
|
+
}
|
|
54
|
+
function unionRanges(ranges) {
|
|
55
|
+
return makeSortedMatchRangeArray([..._unionRanges(ranges)]);
|
|
56
|
+
}
|
|
57
|
+
exports.unionRanges = unionRanges;
|
|
58
|
+
function* _unionRanges(ranges) {
|
|
59
|
+
const sortedRanges = sortMatchRangeArray(ranges);
|
|
60
|
+
if (!sortedRanges.length)
|
|
61
|
+
return;
|
|
62
|
+
let { startPos, endPos } = sortedRanges[0];
|
|
63
|
+
for (const r of ranges) {
|
|
64
|
+
if (r.startPos > endPos) {
|
|
65
|
+
yield { startPos, endPos };
|
|
66
|
+
startPos = r.startPos;
|
|
67
|
+
endPos = r.endPos;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
endPos = Math.max(endPos, r.endPos);
|
|
71
|
+
}
|
|
72
|
+
if (startPos < endPos) {
|
|
73
|
+
yield { startPos, endPos };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function findMatchingRangesForPatterns(patterns, text) {
|
|
77
|
+
const matchedPatterns = GS.genSequence(patterns).concatMap((pattern) => findMatchingRanges(pattern, text));
|
|
78
|
+
return unionRanges(matchedPatterns.toArray());
|
|
79
|
+
}
|
|
80
|
+
exports.findMatchingRangesForPatterns = findMatchingRangesForPatterns;
|
|
81
|
+
/**
|
|
82
|
+
* Create a new set of positions that have the excluded position ranges removed.
|
|
83
|
+
*/
|
|
84
|
+
function excludeRanges(includeRanges, excludeRanges) {
|
|
85
|
+
return [..._excludeRanges(sortMatchRangeArray(includeRanges), sortMatchRangeArray(excludeRanges))];
|
|
86
|
+
}
|
|
87
|
+
exports.excludeRanges = excludeRanges;
|
|
88
|
+
function* _excludeRanges(includeRanges, excludeRanges) {
|
|
89
|
+
if (!includeRanges.length)
|
|
90
|
+
return;
|
|
91
|
+
if (!excludeRanges.length) {
|
|
92
|
+
yield* includeRanges;
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
let exIndex = 0;
|
|
96
|
+
const limit = excludeRanges.length;
|
|
97
|
+
for (const incRange of includeRanges) {
|
|
98
|
+
const endPos = incRange.endPos;
|
|
99
|
+
let startPos = incRange.startPos;
|
|
100
|
+
for (; exIndex < limit; ++exIndex) {
|
|
101
|
+
const ex = excludeRanges[exIndex];
|
|
102
|
+
if (ex.startPos >= endPos)
|
|
103
|
+
break;
|
|
104
|
+
if (ex.endPos <= startPos)
|
|
105
|
+
continue;
|
|
106
|
+
if (ex.startPos > startPos) {
|
|
107
|
+
yield { startPos, endPos: ex.startPos };
|
|
108
|
+
}
|
|
109
|
+
startPos = ex.endPos;
|
|
110
|
+
if (startPos >= endPos)
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
if (startPos < endPos) {
|
|
114
|
+
yield { startPos, endPos };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function extractRangeText(text, ranges) {
|
|
119
|
+
return ranges.map(({ startPos, endPos }) => ({
|
|
120
|
+
startPos,
|
|
121
|
+
endPos,
|
|
122
|
+
text: text.slice(startPos, endPos),
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
exports.extractRangeText = extractRangeText;
|
|
126
|
+
const SymSortedMatchRangeArray = Symbol('SortedMatchRangeArray');
|
|
127
|
+
function sortMatchRangeArray(values) {
|
|
128
|
+
if (isSortedMatchRangeArray(values))
|
|
129
|
+
return values;
|
|
130
|
+
return makeSortedMatchRangeArray(values.sort(compareRanges));
|
|
131
|
+
}
|
|
132
|
+
function isSortedMatchRangeArray(a) {
|
|
133
|
+
return a[SymSortedMatchRangeArray] === true;
|
|
134
|
+
}
|
|
135
|
+
function makeSortedMatchRangeArray(sortedValues) {
|
|
136
|
+
const sorted = sortedValues;
|
|
137
|
+
sorted[SymSortedMatchRangeArray] = true;
|
|
138
|
+
Object.freeze(sorted);
|
|
139
|
+
return sorted;
|
|
140
|
+
}
|
|
141
|
+
exports.__testing__ = {
|
|
142
|
+
makeSortedMatchRangeArray,
|
|
143
|
+
};
|
|
144
|
+
//# sourceMappingURL=TextRange.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clean = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Delete all `undefined` fields from an object.
|
|
6
|
+
* @param src - object to be cleaned
|
|
7
|
+
*/
|
|
8
|
+
function clean(src) {
|
|
9
|
+
const r = src;
|
|
10
|
+
for (const key of Object.keys(r)) {
|
|
11
|
+
if (r[key] === undefined) {
|
|
12
|
+
delete r[key];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return r;
|
|
16
|
+
}
|
|
17
|
+
exports.clean = clean;
|
|
18
|
+
//# sourceMappingURL=clean.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Measure and log result.
|
|
3
|
+
* @param fn - function to measure.
|
|
4
|
+
* @param message - message to log
|
|
5
|
+
* @param callback - called when the function has finished.
|
|
6
|
+
* @returns a function
|
|
7
|
+
*/
|
|
8
|
+
export declare function perfFn<P extends any[], R>(fn: (...args: P) => R, message: string, callback?: (m: string, elapsedMs: number) => void): (...args: P) => R;
|
|
9
|
+
//# sourceMappingURL=debugPerf.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.perfFn = void 0;
|
|
4
|
+
const timer_1 = require("./timer");
|
|
5
|
+
/**
|
|
6
|
+
* Measure and log result.
|
|
7
|
+
* @param fn - function to measure.
|
|
8
|
+
* @param message - message to log
|
|
9
|
+
* @param callback - called when the function has finished.
|
|
10
|
+
* @returns a function
|
|
11
|
+
*/
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
+
function perfFn(fn, message, callback = (message, time) => console.error(`${message}: ${time.toFixed(2)}ms`)) {
|
|
14
|
+
return (...args) => {
|
|
15
|
+
const timer = (0, timer_1.createTimer)();
|
|
16
|
+
const r = fn(...args);
|
|
17
|
+
callback(message, timer.elapsed());
|
|
18
|
+
return r;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
exports.perfFn = perfFn;
|
|
22
|
+
//# sourceMappingURL=debugPerf.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
declare function getTypeOf(t: unknown): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
|
|
3
|
+
export declare function isErrnoException(e: unknown): e is NodeJS.ErrnoException;
|
|
4
|
+
export declare function isError(e: unknown): e is Error;
|
|
5
|
+
export declare function toError(e: unknown, errorFactory?: UnknownErrorConstructor): Error;
|
|
6
|
+
interface UnknownErrorConstructor {
|
|
7
|
+
new (cause: unknown): Error;
|
|
8
|
+
}
|
|
9
|
+
export declare class UnknownError extends Error {
|
|
10
|
+
readonly cause: unknown;
|
|
11
|
+
constructor(cause: unknown);
|
|
12
|
+
}
|
|
13
|
+
export declare const __testing__: {
|
|
14
|
+
getTypeOf: typeof getTypeOf;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.__testing__ = exports.UnknownError = exports.toError = exports.isError = exports.isErrnoException = void 0;
|
|
4
|
+
const util_1 = require("util");
|
|
5
|
+
function getTypeOf(t) {
|
|
6
|
+
return typeof t;
|
|
7
|
+
}
|
|
8
|
+
const allowStringOrUndefined = {
|
|
9
|
+
string: true,
|
|
10
|
+
undefined: true,
|
|
11
|
+
};
|
|
12
|
+
const allowNumberOrUndefined = {
|
|
13
|
+
number: true,
|
|
14
|
+
undefined: true,
|
|
15
|
+
};
|
|
16
|
+
function isErrnoException(e) {
|
|
17
|
+
if (!e || typeof e !== 'object')
|
|
18
|
+
return false;
|
|
19
|
+
if (!isError(e))
|
|
20
|
+
return false;
|
|
21
|
+
const ex = e;
|
|
22
|
+
return (typeof ex.errno in allowNumberOrUndefined &&
|
|
23
|
+
typeof ex.code in allowStringOrUndefined &&
|
|
24
|
+
typeof ex.path in allowStringOrUndefined);
|
|
25
|
+
}
|
|
26
|
+
exports.isErrnoException = isErrnoException;
|
|
27
|
+
function isError(e) {
|
|
28
|
+
if (e instanceof Error)
|
|
29
|
+
return true;
|
|
30
|
+
if (!e || typeof e !== 'object')
|
|
31
|
+
return false;
|
|
32
|
+
const ex = e;
|
|
33
|
+
return typeof ex.name == 'string' && typeof ex.message == 'string' && typeof ex.stack in allowStringOrUndefined;
|
|
34
|
+
}
|
|
35
|
+
exports.isError = isError;
|
|
36
|
+
function toError(e, errorFactory = UnknownError) {
|
|
37
|
+
if (isError(e))
|
|
38
|
+
return e;
|
|
39
|
+
return new errorFactory(e);
|
|
40
|
+
}
|
|
41
|
+
exports.toError = toError;
|
|
42
|
+
class UnknownError extends Error {
|
|
43
|
+
constructor(cause) {
|
|
44
|
+
super((0, util_1.format)(cause));
|
|
45
|
+
this.cause = cause;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.UnknownError = UnknownError;
|
|
49
|
+
exports.__testing__ = {
|
|
50
|
+
getTypeOf,
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare function readLines(filename: string, encoding?: BufferEncoding): Promise<IterableIterator<string>>;
|
|
3
|
+
export declare function readLinesSync(filename: string, encoding?: BufferEncoding): string[];
|
|
4
|
+
//# sourceMappingURL=fileReader.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readLinesSync = exports.readLines = void 0;
|
|
4
|
+
const cspell_io_1 = require("cspell-io");
|
|
5
|
+
const iterableIteratorLib_1 = require("./iterableIteratorLib");
|
|
6
|
+
async function readLines(filename, encoding = 'utf8') {
|
|
7
|
+
try {
|
|
8
|
+
const content = await (0, cspell_io_1.readFile)(filename, encoding);
|
|
9
|
+
return (0, iterableIteratorLib_1.toIterableIterator)(content.split(/\r?\n/g));
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
return Promise.reject(e);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.readLines = readLines;
|
|
16
|
+
function readLinesSync(filename, encoding = 'utf8') {
|
|
17
|
+
const content = (0, cspell_io_1.readFileSync)(filename, encoding);
|
|
18
|
+
return content.split(/\r?\n/g);
|
|
19
|
+
}
|
|
20
|
+
exports.readLinesSync = readLinesSync;
|
|
21
|
+
//# sourceMappingURL=fileReader.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { IterableLike } from './IterableLike';
|
|
2
|
+
export declare function toIterableIterator<T>(i: IterableLike<T>): IterableIterator<T>;
|
|
3
|
+
export declare function concatIterables<T>(...iterables: IterableLike<T>[]): IterableIterator<T>;
|
|
4
|
+
//# sourceMappingURL=iterableIteratorLib.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.concatIterables = exports.toIterableIterator = void 0;
|
|
4
|
+
function* toIterableIterator(i) {
|
|
5
|
+
yield* i;
|
|
6
|
+
}
|
|
7
|
+
exports.toIterableIterator = toIterableIterator;
|
|
8
|
+
function* concatIterables(...iterables) {
|
|
9
|
+
for (const i of iterables) {
|
|
10
|
+
yield* i;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.concatIterables = concatIterables;
|
|
14
|
+
//# sourceMappingURL=iterableIteratorLib.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
declare type Console = typeof console;
|
|
4
|
+
export interface Logger {
|
|
5
|
+
log: Console['log'];
|
|
6
|
+
warn: Console['warn'];
|
|
7
|
+
error: Console['error'];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* See `Console.error`
|
|
11
|
+
*/
|
|
12
|
+
export declare function logError(...args: any[]): void;
|
|
13
|
+
/**
|
|
14
|
+
* See `Console.warn`
|
|
15
|
+
*/
|
|
16
|
+
export declare function logWarning(...args: any[]): void;
|
|
17
|
+
/**
|
|
18
|
+
* See `Console.log`
|
|
19
|
+
*/
|
|
20
|
+
export declare function log(...args: any[]): void;
|
|
21
|
+
/**
|
|
22
|
+
* Set the global cspell-lib logger
|
|
23
|
+
* @param logger - a logger like `console`
|
|
24
|
+
* @returns the old logger.
|
|
25
|
+
*/
|
|
26
|
+
export declare function setLogger(logger: Logger): Logger;
|
|
27
|
+
/**
|
|
28
|
+
* Get the current cspell-lib logger.
|
|
29
|
+
* @returns the current logger.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getLogger(): Logger;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=logger.d.ts.map
|