cspell-lib 10.3.1-alpha.1 → 10.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -6
- package/dist/lib/Settings/patterns.js +2 -2
- package/dist/lib/Transform/IntlSegmentTextTransformer.d.ts +0 -1
- package/dist/lib/Transform/IntlSegmentTextTransformer.js +1 -2
- package/dist/lib/Transform/Transformer.d.ts +1 -0
- package/dist/lib/Transform/Transformer.js +1 -0
- package/dist/lib/Transform/WordBreakTextTransformer.d.ts +10 -0
- package/dist/lib/Transform/WordBreakTextTransformer.js +114 -0
- package/dist/lib/Transform/index.d.ts +1 -0
- package/dist/lib/Transform/index.js +1 -0
- package/dist/lib/exclusionHelper.d.ts +0 -1
- package/dist/lib/exclusionHelper.js +0 -1
- package/dist/lib/spellCheckFile.d.ts +3 -3
- package/dist/lib/spellCheckFile.js +3 -3
- package/dist/lib/textValidation/docValidator.d.ts +2 -1
- package/dist/lib/textValidation/docValidator.js +10 -5
- package/dist/lib/util/logger.d.ts +3 -5
- package/dist/lib/util/text.d.ts +1 -1
- package/dist/lib/util/text.js +1 -1
- package/dist/lib/util/textRegex.d.ts +2 -1
- package/dist/lib/util/textRegex.js +16 -15
- package/package.json +19 -19
package/README.md
CHANGED
|
@@ -6,13 +6,11 @@
|
|
|
6
6
|
|
|
7
7
|
<!--- @@inject: ../../static/sponsor.md --->
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
If our spell checkers save you time, please consider supporting their development.
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
[](https://www.paypal.com/donate/?hosted_button_id=26LNBP2Q6MKCY)
|
|
11
|
+
<p align="left">
|
|
12
|
+
<a href="https://github.com/sponsors/streetsidesoftware" title="GitHub Sponsor"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cspell.org/img/sponsor/github-sponsor-dark.png" /><img alt="GitHub Sponsor" src="https://cspell.org/img/sponsor/github-sponsor.png" width="180" /></picture></a> <a href="https://www.paypal.com/donate/?hosted_button_id=26LNBP2Q6MKCY" title="PayPal"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cspell.org/img/sponsor/paypal-dark.png" /><img alt="PayPal" src="https://cspell.org/img/sponsor/paypal.png" width="180" /></picture></a> <a href="https://opencollective.com/cspell" title="Open Collective"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cspell.org/img/sponsor/open-collective-dark.png" /><img alt="Open Collective" src="https://cspell.org/img/sponsor/open-collective.png" width="180" /></picture></a> <a href="https://streetsidesoftware.com/sponsor/" title="Street Side Software"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cspell.org/img/sponsor/cspell-dark.png" /><img alt="CSpell" src="https://cspell.org/img/sponsor/cspell.png" width="180" /></picture></a>
|
|
13
|
+
</p>
|
|
16
14
|
|
|
17
15
|
<!--- @@inject-end: ../../static/sponsor.md --->
|
|
18
16
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { stringToRegExpOrUndefined } from '../util/textRegex.js';
|
|
2
2
|
import { isDefined } from '../util/util.js';
|
|
3
3
|
import { CalcLeftRightResultWeakCache } from './mergeCache.js';
|
|
4
4
|
const emptyRegExpList = [];
|
|
@@ -34,6 +34,6 @@ function _resolvePatterns(regExpList, patternDefinitions) {
|
|
|
34
34
|
return result;
|
|
35
35
|
}
|
|
36
36
|
function toRegExp(pattern) {
|
|
37
|
-
return pattern instanceof RegExp ? new RegExp(pattern) :
|
|
37
|
+
return pattern instanceof RegExp ? new RegExp(pattern) : stringToRegExpOrUndefined(pattern, 'gim', 'g');
|
|
38
38
|
}
|
|
39
39
|
//# sourceMappingURL=patterns.js.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { MappedText } from '@cspell/cspell-types';
|
|
2
2
|
import type { TextTransformer } from './Transformer.js';
|
|
3
|
-
export declare const softHyphen = "\u00AD";
|
|
4
3
|
export declare class IntlSegmentTextTransformer implements TextTransformer {
|
|
5
4
|
#private;
|
|
6
5
|
constructor(locale: string | string[]);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { normalizeLocaleIntl } from '../Settings/LanguageSettings.js';
|
|
2
2
|
import { applyEditsToMappedText } from './TextMapEdit.js';
|
|
3
|
-
import { toMappedText } from './Transformer.js';
|
|
4
|
-
export const softHyphen = '\u00AD';
|
|
3
|
+
import { softHyphen, toMappedText } from './Transformer.js';
|
|
5
4
|
const regExSplitWordCharacters = /(?<=[\p{L}\p{M}])[\p{L}\p{M}]/uy;
|
|
6
5
|
export class IntlSegmentTextTransformer {
|
|
7
6
|
#locale;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { MappedText } from '@cspell/cspell-types';
|
|
2
2
|
import type { Range } from '@cspell/cspell-types/Parser';
|
|
3
|
+
export declare const softHyphen = "\u00AD";
|
|
3
4
|
export interface TextTransformer {
|
|
4
5
|
transform(text: string | MappedText): MappedText;
|
|
5
6
|
transformAll(src: Iterable<string | MappedText>): Iterable<MappedText>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MappedText, WordSegmentationSettings } from '@cspell/cspell-types';
|
|
2
|
+
import type { TextTransformer } from './Transformer.js';
|
|
3
|
+
export declare class SoftWordBreakTextTransformer implements TextTransformer {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(settings: WordSegmentationSettings);
|
|
6
|
+
transform(text: string | MappedText): MappedText;
|
|
7
|
+
transformAll(src: Iterable<string | MappedText>): Iterable<MappedText>;
|
|
8
|
+
}
|
|
9
|
+
export declare function createSoftWordBreakTextTransformer(settings: WordSegmentationSettings): TextTransformer;
|
|
10
|
+
//# sourceMappingURL=WordBreakTextTransformer.d.ts.map
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { escapeRegEx } from '../util/regexHelper.js';
|
|
2
|
+
import { regExMatchRegExParts, stringToRegExpOrUndefined } from '../util/textRegex.js';
|
|
3
|
+
import { applyEditsToMappedText } from './TextMapEdit.js';
|
|
4
|
+
import { softHyphen, toMappedText } from './Transformer.js';
|
|
5
|
+
export class SoftWordBreakTextTransformer {
|
|
6
|
+
#patterns;
|
|
7
|
+
constructor(settings) {
|
|
8
|
+
this.#patterns = compileSoftWordBreakPatterns(settings);
|
|
9
|
+
}
|
|
10
|
+
transform(text) {
|
|
11
|
+
const mText = toMappedText(text);
|
|
12
|
+
if (!this.#patterns.length)
|
|
13
|
+
return mText;
|
|
14
|
+
return applySoftWordBreaks(mText, this.#patterns);
|
|
15
|
+
}
|
|
16
|
+
*transformAll(src) {
|
|
17
|
+
for (const item of src) {
|
|
18
|
+
yield this.transform(item);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function createSoftWordBreakTextTransformer(settings) {
|
|
23
|
+
return new SoftWordBreakTextTransformer(settings);
|
|
24
|
+
}
|
|
25
|
+
function compileSoftWordBreakPatterns(settings) {
|
|
26
|
+
const enabled = settings.softWordBreaks;
|
|
27
|
+
const definitions = settings.softWordBreakDefinitions;
|
|
28
|
+
if (!enabled || !definitions)
|
|
29
|
+
return [];
|
|
30
|
+
const patterns = [];
|
|
31
|
+
for (const name of Object.keys(enabled)) {
|
|
32
|
+
if (!enabled[name])
|
|
33
|
+
continue;
|
|
34
|
+
const rule = definitions[name];
|
|
35
|
+
if (!rule)
|
|
36
|
+
continue;
|
|
37
|
+
for (const part of Array.isArray(rule) ? rule : [rule]) {
|
|
38
|
+
patterns.push(compileSoftWordBreak(part));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return patterns;
|
|
42
|
+
}
|
|
43
|
+
function compileSoftWordBreak(rule) {
|
|
44
|
+
if (rule instanceof RegExp) {
|
|
45
|
+
return new RegExp(rule, rule.flags.includes('g') ? rule.flags : rule.flags + 'g');
|
|
46
|
+
}
|
|
47
|
+
if (regExMatchRegExParts.test(rule)) {
|
|
48
|
+
const regex = stringToRegExpOrUndefined(rule);
|
|
49
|
+
if (!regex) {
|
|
50
|
+
throw new Error(`Invalid soft word break regular expression: "${rule}"`);
|
|
51
|
+
}
|
|
52
|
+
return regex;
|
|
53
|
+
}
|
|
54
|
+
return compileSoftWordBreakPattern(rule);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Compiles a `SoftWordBreakPattern` string, e.g. `"^ptr|"` or `"before|after$"`, into a
|
|
58
|
+
* zero-width RegExp using lookbehind/lookahead so the matched break position can be located
|
|
59
|
+
* without consuming the surrounding text.
|
|
60
|
+
*/
|
|
61
|
+
function compileSoftWordBreakPattern(pattern) {
|
|
62
|
+
const pipeIndex = pattern.indexOf('|');
|
|
63
|
+
if (pipeIndex < 0) {
|
|
64
|
+
throw new Error(`Invalid soft word break pattern: "${pattern}"`);
|
|
65
|
+
}
|
|
66
|
+
let before = pattern.slice(0, pipeIndex);
|
|
67
|
+
let after = pattern.slice(pipeIndex + 1);
|
|
68
|
+
const startAnchored = before.startsWith('^');
|
|
69
|
+
if (startAnchored) {
|
|
70
|
+
before = before.slice(1);
|
|
71
|
+
}
|
|
72
|
+
const endAnchored = after.endsWith('$');
|
|
73
|
+
if (endAnchored) {
|
|
74
|
+
after = after.slice(0, -1);
|
|
75
|
+
}
|
|
76
|
+
const lookbehind = startAnchored ? `\\b${escapeRegEx(before)}` : escapeRegEx(before);
|
|
77
|
+
const lookahead = endAnchored ? `${escapeRegEx(after)}\\b` : escapeRegEx(after);
|
|
78
|
+
return new RegExp(`(?<=${lookbehind})(?=${lookahead})`, 'gu');
|
|
79
|
+
}
|
|
80
|
+
function applySoftWordBreaks(mText, patterns) {
|
|
81
|
+
const text = mText.text;
|
|
82
|
+
const edits = [];
|
|
83
|
+
for (const pattern of patterns) {
|
|
84
|
+
// Use a fresh RegExp per scan so unrelated calls don't share `lastIndex` state.
|
|
85
|
+
const reg = new RegExp(pattern.source, pattern.flags);
|
|
86
|
+
for (const m of text.matchAll(reg)) {
|
|
87
|
+
const index = m.index;
|
|
88
|
+
const match = m[0];
|
|
89
|
+
const range = [index, index + match.length];
|
|
90
|
+
const editText = match ? softHyphen + match + softHyphen : softHyphen;
|
|
91
|
+
edits.push({ text: editText, range });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (!edits.length)
|
|
95
|
+
return mText;
|
|
96
|
+
return applyEditsToMappedText(mText, mergeEdits(edits));
|
|
97
|
+
}
|
|
98
|
+
function mergeEdits(edits) {
|
|
99
|
+
edits.sort((a, b) => a.range[0] - b.range[0] || a.range[1] - b.range[1]);
|
|
100
|
+
const merged = [];
|
|
101
|
+
let lastStart = -1;
|
|
102
|
+
let lastEnd = -1;
|
|
103
|
+
for (const edit of edits) {
|
|
104
|
+
if (edit.range[0] < lastEnd)
|
|
105
|
+
continue;
|
|
106
|
+
if (edit.range[0] === lastStart && edit.range[1] === lastEnd)
|
|
107
|
+
continue;
|
|
108
|
+
merged.push(edit);
|
|
109
|
+
lastStart = edit.range[0];
|
|
110
|
+
lastEnd = edit.range[1];
|
|
111
|
+
}
|
|
112
|
+
return merged;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=WordBreakTextTransformer.js.map
|
|
@@ -9,4 +9,5 @@ export { excludeRanges, extractRangeText, findMatchingRanges, findMatchingRanges
|
|
|
9
9
|
export type { TextTransformer } from './Transformer.js';
|
|
10
10
|
export { chainTransformers } from './Transformer.js';
|
|
11
11
|
export type { Offset, SimpleRange } from './types.js';
|
|
12
|
+
export { createSoftWordBreakTextTransformer } from './WordBreakTextTransformer.js';
|
|
12
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -4,4 +4,5 @@ export { createSourceMapCursor } from './SourceMap.js';
|
|
|
4
4
|
export { createSubstitutionTransformer, SubstitutionTransformer } from './SubstitutionTransformer.js';
|
|
5
5
|
export { excludeRanges, extractRangeText, findMatchingRanges, findMatchingRangesForPatterns } from './TextRange.js';
|
|
6
6
|
export { chainTransformers } from './Transformer.js';
|
|
7
|
+
export { createSoftWordBreakTextTransformer } from './WordBreakTextTransformer.js';
|
|
7
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -17,7 +17,6 @@ export declare function generateExclusionFunctionForUri(globs: Glob[], root: str
|
|
|
17
17
|
* @todo Support multi root globs.
|
|
18
18
|
* @param globs - glob patterns
|
|
19
19
|
* @param root - root directory
|
|
20
|
-
* @param allowedSchemes - allowed schemas
|
|
21
20
|
*/
|
|
22
21
|
export declare function generateExclusionFunctionForFiles(globs: Glob[], root: string): FileExclusionFunction;
|
|
23
22
|
//# sourceMappingURL=exclusionHelper.d.ts.map
|
|
@@ -42,7 +42,6 @@ export function generateExclusionFunctionForUri(globs, root, allowedSchemes = de
|
|
|
42
42
|
* @todo Support multi root globs.
|
|
43
43
|
* @param globs - glob patterns
|
|
44
44
|
* @param root - root directory
|
|
45
|
-
* @param allowedSchemes - allowed schemas
|
|
46
45
|
*/
|
|
47
46
|
export function generateExclusionFunctionForFiles(globs, root) {
|
|
48
47
|
const matcher = new GlobMatcher(globs, { root, dot: true });
|
|
@@ -71,21 +71,21 @@ export interface SpellCheckFileResultRPC {
|
|
|
71
71
|
* Spell Check a file
|
|
72
72
|
* @param file - absolute path to file to read and check.
|
|
73
73
|
* @param options - options to control checking
|
|
74
|
-
* @param
|
|
74
|
+
* @param settingsOrConfigFile - default settings to use.
|
|
75
75
|
*/
|
|
76
76
|
export declare function spellCheckFile(file: string | Uri | URL, options: SpellCheckFileOptions, settingsOrConfigFile: CSpellUserSettings | ICSpellConfigFile): Promise<SpellCheckFileResult>;
|
|
77
77
|
/**
|
|
78
78
|
* Spell Check a Document.
|
|
79
79
|
* @param document - document to be checked. If `document.text` is `undefined` the file will be loaded
|
|
80
80
|
* @param options - options to control checking
|
|
81
|
-
* @param
|
|
81
|
+
* @param settingsOrConfigFile - default settings to use.
|
|
82
82
|
*/
|
|
83
83
|
export declare function spellCheckDocument(document: Document | DocumentWithText, options: SpellCheckFileOptions, settingsOrConfigFile: CSpellUserSettings | ICSpellConfigFile): Promise<SpellCheckFileResult>;
|
|
84
84
|
/**
|
|
85
85
|
* Spell Check a Document.
|
|
86
86
|
* @param document - document to be checked. If `document.text` is `undefined` the file will be loaded
|
|
87
87
|
* @param options - options to control checking
|
|
88
|
-
* @param
|
|
88
|
+
* @param settingsOrConfigFile - default settings to use.
|
|
89
89
|
*/
|
|
90
90
|
export declare function spellCheckDocumentRPC(document: Document | DocumentWithText, options: SpellCheckFileOptionsRPC, settingsOrConfigFile: CSpellUserSettings | ICSpellConfigFile): Promise<SpellCheckFileResultRPC>;
|
|
91
91
|
export interface DetermineFinalDocumentSettingsResult {
|
|
@@ -12,7 +12,7 @@ import { toUri } from './util/Uri.js';
|
|
|
12
12
|
* Spell Check a file
|
|
13
13
|
* @param file - absolute path to file to read and check.
|
|
14
14
|
* @param options - options to control checking
|
|
15
|
-
* @param
|
|
15
|
+
* @param settingsOrConfigFile - default settings to use.
|
|
16
16
|
*/
|
|
17
17
|
export function spellCheckFile(file, options, settingsOrConfigFile) {
|
|
18
18
|
const doc = {
|
|
@@ -24,7 +24,7 @@ export function spellCheckFile(file, options, settingsOrConfigFile) {
|
|
|
24
24
|
* Spell Check a Document.
|
|
25
25
|
* @param document - document to be checked. If `document.text` is `undefined` the file will be loaded
|
|
26
26
|
* @param options - options to control checking
|
|
27
|
-
* @param
|
|
27
|
+
* @param settingsOrConfigFile - default settings to use.
|
|
28
28
|
*/
|
|
29
29
|
export async function spellCheckDocument(document, options, settingsOrConfigFile) {
|
|
30
30
|
const settingsUsed = satisfiesCSpellConfigFile(settingsOrConfigFile)
|
|
@@ -78,7 +78,7 @@ export async function spellCheckDocument(document, options, settingsOrConfigFile
|
|
|
78
78
|
* Spell Check a Document.
|
|
79
79
|
* @param document - document to be checked. If `document.text` is `undefined` the file will be loaded
|
|
80
80
|
* @param options - options to control checking
|
|
81
|
-
* @param
|
|
81
|
+
* @param settingsOrConfigFile - default settings to use.
|
|
82
82
|
*/
|
|
83
83
|
export async function spellCheckDocumentRPC(document, options, settingsOrConfigFile) {
|
|
84
84
|
const { issues, checked, errors, configErrors, dictionaryErrors, perf } = await spellCheckDocument(document, options, settingsOrConfigFile);
|
|
@@ -52,7 +52,8 @@ export declare class DocumentValidator {
|
|
|
52
52
|
static create(doc: TextDocument, options: DocumentValidatorOptions, settingsOrConfigFile: CSpellUserSettings | ICSpellConfigFile): Promise<DocumentValidator>;
|
|
53
53
|
/**
|
|
54
54
|
* @param doc - Document to validate
|
|
55
|
-
* @param
|
|
55
|
+
* @param options - options controlling how the document is validated.
|
|
56
|
+
* @param settings - configuration to use (not finalized).
|
|
56
57
|
*/
|
|
57
58
|
constructor(doc: TextDocument, options: DocumentValidatorOptions, settings: CSpellUserSettings);
|
|
58
59
|
get ready(): boolean;
|
|
@@ -10,7 +10,7 @@ import { extractImportErrors, finalizeSettings, loadConfig, mergeSettings, resol
|
|
|
10
10
|
import { validateInDocumentSettings } from '../Settings/InDocSettings.js';
|
|
11
11
|
import { getDictionaryInternal } from '../SpellingDictionary/index.js';
|
|
12
12
|
import { calcSuggestionAdjustedToToMatchCase } from '../suggestions.js';
|
|
13
|
-
import { chainTransformers, createIntlSegmentTextTransformer, createMappedTextSegmenter, createSubstitutionTransformer, } from '../Transform/index.js';
|
|
13
|
+
import { chainTransformers, createIntlSegmentTextTransformer, createMappedTextSegmenter, createSoftWordBreakTextTransformer, createSubstitutionTransformer, } from '../Transform/index.js';
|
|
14
14
|
import { catchPromiseError, toError } from '../util/errors.js';
|
|
15
15
|
import { AutoCache } from '../util/simpleCache.js';
|
|
16
16
|
import { uriToFilePath } from '../util/Uri.js';
|
|
@@ -44,7 +44,8 @@ export class DocumentValidator {
|
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
46
|
* @param doc - Document to validate
|
|
47
|
-
* @param
|
|
47
|
+
* @param options - options controlling how the document is validated.
|
|
48
|
+
* @param settings - configuration to use (not finalized).
|
|
48
49
|
*/
|
|
49
50
|
constructor(doc, options, settings) {
|
|
50
51
|
this.settings = settings;
|
|
@@ -152,9 +153,13 @@ export class DocumentValidator {
|
|
|
152
153
|
if (sub.missing) {
|
|
153
154
|
this.addPossibleError(`Missing substitutions: ${sub.missing.join(', ')}`);
|
|
154
155
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
156
|
+
let transformer = sub.transformer;
|
|
157
|
+
if (finalSettings.useIntlWordSegmentation) {
|
|
158
|
+
transformer = chainTransformers(transformer, createIntlSegmentTextTransformer(finalSettings.language || ''));
|
|
159
|
+
}
|
|
160
|
+
if (finalSettings.softWordBreaks) {
|
|
161
|
+
transformer = chainTransformers(transformer, createSoftWordBreakTextTransformer(finalSettings));
|
|
162
|
+
}
|
|
158
163
|
const validateOptions = { ...settingsToValidateOptions(finalSettings), transformer };
|
|
159
164
|
// Avoid excluding text ranges that have a full substitution applied.
|
|
160
165
|
const rangeTransformer = finalSettings.substitutions?.length ? sub.transformer : undefined;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
type Console = typeof console;
|
|
2
1
|
export interface Logger {
|
|
3
|
-
log:
|
|
4
|
-
warn:
|
|
5
|
-
error:
|
|
2
|
+
log: (...args: unknown[]) => void;
|
|
3
|
+
warn: (...args: unknown[]) => void;
|
|
4
|
+
error: (...args: unknown[]) => void;
|
|
6
5
|
}
|
|
7
6
|
/**
|
|
8
7
|
* See `Console.error`
|
|
@@ -27,5 +26,4 @@ export declare function setLogger(logger: Logger): Logger;
|
|
|
27
26
|
* @returns the current logger.
|
|
28
27
|
*/
|
|
29
28
|
export declare function getLogger(): Logger;
|
|
30
|
-
export {};
|
|
31
29
|
//# sourceMappingURL=logger.d.ts.map
|
package/dist/lib/util/text.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TextDocumentOffset, TextOffset } from '@cspell/cspell-types';
|
|
2
2
|
import type { Uri } from './IUri.js';
|
|
3
|
-
export { stringToRegExp } from './textRegex.js';
|
|
3
|
+
export { stringToRegExpOrUndefined as stringToRegExp } from './textRegex.js';
|
|
4
4
|
export declare function splitCamelCaseWordWithOffset(wo: TextOffset): TextOffset[];
|
|
5
5
|
/**
|
|
6
6
|
* Split camelCase words into an array of strings.
|
package/dist/lib/util/text.js
CHANGED
|
@@ -2,7 +2,7 @@ import { opConcatMap, opMap, pipe } from '@cspell/cspell-pipe/sync';
|
|
|
2
2
|
import { binarySearch } from './search.js';
|
|
3
3
|
import { regExAccents, regExAllLower, regExAllUpper, regExFirstUpper, regExIgnoreCharacters, regExpCamelCaseWordBreaksWithEnglishSuffix, regExWords, regExWordsAndDigits, } from './textRegex.js';
|
|
4
4
|
import { toUri } from './Uri.js';
|
|
5
|
-
export { stringToRegExp } from './textRegex.js';
|
|
5
|
+
export { stringToRegExpOrUndefined as stringToRegExp } from './textRegex.js';
|
|
6
6
|
// CSpell:ignore ings ning gimuy tsmerge
|
|
7
7
|
export function splitCamelCaseWordWithOffset(wo) {
|
|
8
8
|
return splitWordWithOffset(wo, regExpCamelCaseWordBreaksWithEnglishSuffix);
|
|
@@ -19,5 +19,6 @@ export declare const regExDanglingQuote: RegExp;
|
|
|
19
19
|
/** Match tailing endings after CAPS words */
|
|
20
20
|
export declare const regExTrailingEndings: RegExp;
|
|
21
21
|
export declare const regExNumericLiteral: RegExp;
|
|
22
|
-
export declare function
|
|
22
|
+
export declare function stringToRegExpOrUndefined(pattern: string | RegExp, defaultFlags?: string, forceFlags?: string): RegExp | undefined;
|
|
23
|
+
export declare function stringToRegExp(pattern: string | RegExp, defaultFlags?: string, forceFlags?: string): RegExp;
|
|
23
24
|
//# sourceMappingURL=textRegex.d.ts.map
|
|
@@ -21,28 +21,29 @@ export const regExDanglingQuote = /(?<=(?:^|(?!\p{M})\P{L})(?:\p{L}\p{M}?)?)[']/
|
|
|
21
21
|
/** Match tailing endings after CAPS words */
|
|
22
22
|
export const regExTrailingEndings = /(?<=(?:\p{Lu}\p{M}?){2})['’]?(?:s|d|ings?|ies|e[ds]?|ning|th|nth)(?!\p{Ll})/gu;
|
|
23
23
|
export const regExNumericLiteral = /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/;
|
|
24
|
-
export function
|
|
25
|
-
if (pattern instanceof RegExp) {
|
|
26
|
-
return pattern;
|
|
27
|
-
}
|
|
24
|
+
export function stringToRegExpOrUndefined(pattern, defaultFlags = 'gimu', forceFlags = 'g') {
|
|
28
25
|
try {
|
|
29
|
-
|
|
30
|
-
...(pattern.match(regExMatchRegExParts) || ['', pattern.trim(), defaultFlags]),
|
|
31
|
-
forceFlags,
|
|
32
|
-
];
|
|
33
|
-
if (pat) {
|
|
34
|
-
const regPattern = flag.includes('x') ? removeVerboseFromRegExp(pat) : pat;
|
|
35
|
-
// Make sure the flags are unique.
|
|
36
|
-
const flags = [...new Set(forceFlags + flag)].join('').replaceAll(/[^gimuy]/g, '');
|
|
37
|
-
const regex = new RegExp(regPattern, flags);
|
|
38
|
-
return regex;
|
|
39
|
-
}
|
|
26
|
+
return stringToRegExp(pattern, defaultFlags, forceFlags);
|
|
40
27
|
}
|
|
41
28
|
catch {
|
|
42
29
|
/* empty */
|
|
43
30
|
}
|
|
44
31
|
return undefined;
|
|
45
32
|
}
|
|
33
|
+
export function stringToRegExp(pattern, defaultFlags = 'gimu', forceFlags = 'g') {
|
|
34
|
+
if (pattern instanceof RegExp) {
|
|
35
|
+
return pattern;
|
|
36
|
+
}
|
|
37
|
+
const [, pat, flag] = [...(pattern.match(regExMatchRegExParts) || ['', pattern.trim(), defaultFlags]), forceFlags];
|
|
38
|
+
if (!pat) {
|
|
39
|
+
throw new Error(`Invalid regular expression: "${pattern}"`);
|
|
40
|
+
}
|
|
41
|
+
const regPattern = flag.includes('x') ? removeVerboseFromRegExp(pat) : pat;
|
|
42
|
+
// Make sure the flags are unique.
|
|
43
|
+
const flags = [...new Set(forceFlags + flag)].join('').replaceAll(/[^gimuy]/g, '');
|
|
44
|
+
const regex = new RegExp(regPattern, flags);
|
|
45
|
+
return regex;
|
|
46
|
+
}
|
|
46
47
|
const SPACES = {
|
|
47
48
|
' ': true,
|
|
48
49
|
'\n': true,
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public",
|
|
5
5
|
"provenance": true
|
|
6
6
|
},
|
|
7
|
-
"version": "10.3.1
|
|
7
|
+
"version": "10.3.1",
|
|
8
8
|
"description": "A library of useful functions used across various cspell tools.",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"sideEffects": false,
|
|
@@ -75,22 +75,22 @@
|
|
|
75
75
|
},
|
|
76
76
|
"homepage": "https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell-lib#readme",
|
|
77
77
|
"dependencies": {
|
|
78
|
-
"@cspell/cspell-bundled-dicts": "10.3.1
|
|
79
|
-
"@cspell/cspell-performance-monitor": "10.3.1
|
|
80
|
-
"@cspell/cspell-pipe": "10.3.1
|
|
81
|
-
"@cspell/cspell-resolver": "10.3.1
|
|
82
|
-
"@cspell/cspell-types": "10.3.1
|
|
83
|
-
"@cspell/dynamic-import": "10.3.1
|
|
84
|
-
"@cspell/filetypes": "10.3.1
|
|
85
|
-
"@cspell/rpc": "10.3.1
|
|
86
|
-
"@cspell/strong-weak-map": "10.3.1
|
|
87
|
-
"@cspell/url": "10.3.1
|
|
88
|
-
"cspell-config-lib": "10.3.1
|
|
89
|
-
"cspell-dictionary": "10.3.1
|
|
90
|
-
"cspell-glob": "10.3.1
|
|
91
|
-
"cspell-grammar": "10.3.1
|
|
92
|
-
"cspell-io": "10.3.1
|
|
93
|
-
"cspell-trie-lib": "10.3.1
|
|
78
|
+
"@cspell/cspell-bundled-dicts": "10.3.1",
|
|
79
|
+
"@cspell/cspell-performance-monitor": "10.3.1",
|
|
80
|
+
"@cspell/cspell-pipe": "10.3.1",
|
|
81
|
+
"@cspell/cspell-resolver": "10.3.1",
|
|
82
|
+
"@cspell/cspell-types": "10.3.1",
|
|
83
|
+
"@cspell/dynamic-import": "10.3.1",
|
|
84
|
+
"@cspell/filetypes": "10.3.1",
|
|
85
|
+
"@cspell/rpc": "10.3.1",
|
|
86
|
+
"@cspell/strong-weak-map": "10.3.1",
|
|
87
|
+
"@cspell/url": "10.3.1",
|
|
88
|
+
"cspell-config-lib": "10.3.1",
|
|
89
|
+
"cspell-dictionary": "10.3.1",
|
|
90
|
+
"cspell-glob": "10.3.1",
|
|
91
|
+
"cspell-grammar": "10.3.1",
|
|
92
|
+
"cspell-io": "10.3.1",
|
|
93
|
+
"cspell-trie-lib": "10.3.1",
|
|
94
94
|
"env-paths": "^4.0.0",
|
|
95
95
|
"gensequence": "^8.0.8",
|
|
96
96
|
"import-fresh": "^4.0.0",
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"node": ">=22.18.0"
|
|
104
104
|
},
|
|
105
105
|
"devDependencies": {
|
|
106
|
-
"@cspell/cspell-tools": "10.3.1
|
|
106
|
+
"@cspell/cspell-tools": "10.3.1",
|
|
107
107
|
"@cspell/dict-cpp": "^7.1.0",
|
|
108
108
|
"@cspell/dict-csharp": "^4.0.8",
|
|
109
109
|
"@cspell/dict-css": "^4.1.2",
|
|
@@ -123,5 +123,5 @@
|
|
|
123
123
|
"lorem-ipsum": "^3.0.0",
|
|
124
124
|
"perf-insight": "^2.0.1"
|
|
125
125
|
},
|
|
126
|
-
"gitHead": "
|
|
126
|
+
"gitHead": "793953d1c2b4f1cab257389ff6ecb3ae2dd40230"
|
|
127
127
|
}
|