cspell-trie-lib
Advanced tools
Comparing version 8.7.0 to 8.8.0
@@ -23,2 +23,3 @@ export function insertWordsAtCursor(cursor, words) { | ||
// detect second half of a surrogate pair and backup. | ||
// eslint-disable-next-line unicorn/prefer-code-point | ||
const c = a.charCodeAt(i) & 0xffff; | ||
@@ -25,0 +26,0 @@ if (c >= 0xdc00 && c <= 0xdfff) { |
@@ -44,4 +44,4 @@ import { genSequence } from 'gensequence'; | ||
function* walkByTallies(tallies) { | ||
const nodes = [...genSequence(tallies).filter((a) => a[1] >= MinReferenceCount)].sort((a, b) => b[1] - a[1]); | ||
for (const [n] of nodes) { | ||
const nodes = genSequence(tallies).filter((a) => a[1] >= MinReferenceCount); | ||
for (const [n] of [...nodes].sort((a, b) => b[1] - a[1])) { | ||
yield* walkByRollup(n); | ||
@@ -48,0 +48,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import assert from 'assert'; | ||
import assert from 'node:assert'; | ||
import { PairingHeap } from '../utils/PairingHeap.js'; | ||
@@ -3,0 +3,0 @@ import { createWeightCostCalculator } from './weightedMaps.js'; |
@@ -14,3 +14,3 @@ import { distanceAStarWeightedEx } from './distanceAStarWeighted.js'; | ||
function vizWidth(s) { | ||
const r = s.replace(/[\u0300-\u036F\u007f-\u009f]/gu, ''); | ||
const r = s.replaceAll(/[\u0300-\u036F\u007F-\u009F]/gu, ''); | ||
let i = 0; | ||
@@ -17,0 +17,0 @@ for (const c of r) { |
@@ -1,5 +0,2 @@ | ||
const initialRow = '.' | ||
.repeat(50) | ||
.split('') | ||
.map((_, i) => i); | ||
const initialRow = [...'.'.repeat(50)].map((_, i) => i); | ||
Object.freeze(initialRow); | ||
@@ -88,3 +85,3 @@ /** | ||
// ); | ||
const results = resultsByCost.reduce((acc, r) => (acc.length < count ? acc.concat(r) : acc), []); | ||
const results = resultsByCost.reduce((acc, r) => (acc.length < count ? [...acc, ...r] : acc), []); | ||
return results.slice(0, count); | ||
@@ -91,0 +88,0 @@ function levenshteinDistance(b) { |
@@ -287,3 +287,3 @@ import { DEFAULT_COMPOUNDED_WORD_SEPARATOR } from '../suggestions/constants.js'; | ||
function normalizeMap(map) { | ||
return map.replace(matchPossibleWordSeparators, DEFAULT_COMPOUNDED_WORD_SEPARATOR); | ||
return map.replaceAll(matchPossibleWordSeparators, DEFAULT_COMPOUNDED_WORD_SEPARATOR); | ||
} | ||
@@ -290,0 +290,0 @@ export const __testing__ = { |
@@ -27,3 +27,3 @@ import { TrieNodeTrie } from '../TrieNode/TrieNodeTrie.js'; | ||
if (match) { | ||
return parseInt(match[1], 10); | ||
return Number.parseInt(match[1], 10); | ||
} | ||
@@ -30,0 +30,0 @@ } |
@@ -41,3 +41,3 @@ import * as iv1 from './importExportV1.js'; | ||
if (match) { | ||
return parseInt(match[1], 10); | ||
return Number.parseInt(match[1], 10); | ||
} | ||
@@ -44,0 +44,0 @@ } |
@@ -13,3 +13,3 @@ import { genSequence } from 'gensequence'; | ||
function escapeChar(char) { | ||
return char.replace(regExpEscapeChars, '\\$1'); // lgtm[js/incomplete-sanitization] | ||
return char.replaceAll(regExpEscapeChars, '\\$1'); // lgtm[js/incomplete-sanitization] | ||
} | ||
@@ -33,5 +33,7 @@ function trieToExportString(node, base) { | ||
function generateHeader(base, comment) { | ||
const header = ['#!/usr/bin/env cspell-trie reader', 'TrieXv1', 'base=' + base] | ||
.concat(comment ? comment.split('\n').map((a) => '# ' + a) : []) | ||
.concat(['# Data:']); | ||
const header = [ | ||
...['#!/usr/bin/env cspell-trie reader', 'TrieXv1', 'base=' + base], | ||
...(comment ? comment.split('\n').map((a) => '# ' + a) : []), | ||
...['# Data:'], | ||
]; | ||
return genSequence(header).map((a) => a + '\n'); | ||
@@ -50,5 +52,6 @@ } | ||
const rows = toReferences(root).map((node) => { | ||
const row = [...trieToExportString(node, radix), '\n'].join('').replace(regExTrailingComma, '$1'); | ||
const row = [...trieToExportString(node, radix), '\n'].join('').replaceAll(regExTrailingComma, '$1'); | ||
return row; | ||
}); | ||
// eslint-disable-next-line unicorn/prefer-spread | ||
return generateHeader(radix, comment).concat(rows); | ||
@@ -73,3 +76,2 @@ } | ||
const headerRows = []; | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
@@ -98,5 +100,5 @@ const next = iter.next(); | ||
return line | ||
.replace(regNotEscapedCommas, pattern) | ||
.replaceAll(regNotEscapedCommas, pattern) | ||
.split(regUnescapeCommas) | ||
.map((a) => a.replace(regUnescape, '$1')); | ||
.map((a) => a.replaceAll(regUnescape, '$1')); | ||
} | ||
@@ -116,2 +118,3 @@ function decodeLine(line, nodes) { | ||
const n = genSequence([DATA]) | ||
// eslint-disable-next-line unicorn/prefer-spread | ||
.concat(iter) | ||
@@ -118,0 +121,0 @@ .map((a) => a.replace(/\r?\n/, '')) |
@@ -77,5 +77,10 @@ import { genSequence } from 'gensequence'; | ||
function generateHeader(base, comment) { | ||
const header = ['#!/usr/bin/env cspell-trie reader', 'TrieXv2', 'base=' + base] | ||
.concat(comment ? comment.split('\n').map((a) => '# ' + a) : []) | ||
.concat(['# Data:', DATA]); | ||
const header = [ | ||
'#!/usr/bin/env cspell-trie reader', | ||
'TrieXv2', | ||
'base=' + base, | ||
...(comment ? comment.split('\n').map((a) => '# ' + a) : []), | ||
'# Data:', | ||
DATA, | ||
]; | ||
return genSequence(header); | ||
@@ -95,5 +100,6 @@ } | ||
const rows = flattenToReferences(rootRef).map((n) => toLine(n, base)); | ||
return generateHeader(radix, comment) | ||
return (generateHeader(radix, comment) | ||
// eslint-disable-next-line unicorn/prefer-spread | ||
.concat(rows) | ||
.map((a) => a + '\n'); | ||
.map((a) => a + '\n')); | ||
} | ||
@@ -117,3 +123,2 @@ function* toIterableIterator(iter) { | ||
const headerRows = []; | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
@@ -142,3 +147,3 @@ const next = iter.next(); | ||
.filter((a) => !!a) | ||
.map((r) => parseInt(r, base)); | ||
.map((r) => Number.parseInt(r, base)); | ||
return { | ||
@@ -145,0 +150,0 @@ letter: line[0], |
@@ -15,5 +15,10 @@ import { opAppend, pipe } from '@cspell/cspell-pipe/sync'; | ||
function generateHeader(base, comment) { | ||
const header = ['#!/usr/bin/env cspell-trie reader', 'TrieXv3', 'base=' + base] | ||
.concat(comment ? comment.split('\n').map((a) => '# ' + a) : []) | ||
.concat(['# Data:', DATA]); | ||
const header = [ | ||
'#!/usr/bin/env cspell-trie reader', | ||
'TrieXv3', | ||
'base=' + base, | ||
...(comment ? comment.split('\n').map((a) => '# ' + a) : []), | ||
'# Data:', | ||
DATA, | ||
]; | ||
return header.map((a) => a + '\n'); | ||
@@ -55,3 +60,3 @@ } | ||
switch (s) { | ||
case EOW: | ||
case EOW: { | ||
yield* flush(); | ||
@@ -62,9 +67,12 @@ backBuffer.last = EOW; | ||
break; | ||
case BACK: | ||
} | ||
case BACK: { | ||
backBuffer.count++; | ||
break; | ||
case EOL: | ||
} | ||
case EOL: { | ||
backBuffer.eol = true; | ||
break; | ||
default: | ||
} | ||
default: { | ||
if (backBuffer.words >= WORDS_PER_LINE) { | ||
@@ -78,2 +86,3 @@ backBuffer.eol = true; | ||
yield s; | ||
} | ||
} | ||
@@ -80,0 +89,0 @@ } |
@@ -31,6 +31,17 @@ /* eslint-disable no-irregular-whitespace */ | ||
const INLINE_DATA_COMMENT_LINE = '/'; | ||
const specialCharacters = stringToCharSet([EOW, BACK, EOL, REF, REF_REL, EOR, ESCAPE, LF, REF_INDEX_BEGIN, REF_INDEX_END, INLINE_DATA_COMMENT_LINE] | ||
.concat('0123456789'.split('')) | ||
.concat('`~!@#$%^&*()_-+=[]{};:\'"<>,./?\\|'.split('')) | ||
.join('')); | ||
const specialCharacters = stringToCharSet([ | ||
EOW, | ||
BACK, | ||
EOL, | ||
REF, | ||
REF_REL, | ||
EOR, | ||
ESCAPE, | ||
LF, | ||
REF_INDEX_BEGIN, | ||
REF_INDEX_END, | ||
INLINE_DATA_COMMENT_LINE, | ||
...'0123456789', | ||
...'`~!@#$%^&*()_-+=[]{};:\'"<>,./?\\|', | ||
].join('')); | ||
const SPECIAL_CHARACTERS_MAP = [ | ||
@@ -95,3 +106,3 @@ ['\n', '\\n'], | ||
switch (s) { | ||
case EOW: | ||
case EOW: { | ||
yield* flush(); | ||
@@ -102,9 +113,12 @@ backBuffer.last = EOW; | ||
break; | ||
case BACK: | ||
} | ||
case BACK: { | ||
backBuffer.count++; | ||
break; | ||
case EOL: | ||
} | ||
case EOL: { | ||
backBuffer.eol = true; | ||
break; | ||
default: | ||
} | ||
default: { | ||
if (backBuffer.words >= WORDS_PER_LINE) { | ||
@@ -118,2 +132,3 @@ backBuffer.eol = true; | ||
yield s; | ||
} | ||
} | ||
@@ -166,3 +181,3 @@ } | ||
.join(',') | ||
.replace(/.{110,130}[,]/g, '$&\n') + | ||
.replaceAll(/.{110,130}[,]/g, '$&\n') + | ||
'\n]\n'; | ||
@@ -247,3 +262,3 @@ return pipe([generateHeader(radix, comment), reference], opAppend(lines)); | ||
const { root, nodes, stack } = acc; | ||
const r = parseInt(ref, radix); | ||
const r = Number.parseInt(ref, radix); | ||
const top = stack[stack.length - 1]; | ||
@@ -330,3 +345,3 @@ const p = stack[stack.length - 2].node; | ||
} | ||
let n = s === BACK ? 1 : parseInt(s, 10) - 1; | ||
let n = s === BACK ? 1 : Number.parseInt(s, 10) - 1; | ||
const { stack } = acc; | ||
@@ -373,5 +388,5 @@ while (n-- > 0) { | ||
refIndex = json | ||
.replace(/[\s[\]]/g, '') | ||
.replaceAll(/[\s[\]]/g, '') | ||
.split(',') | ||
.map((n) => parseInt(n, radix)); | ||
.map((n) => Number.parseInt(n, radix)); | ||
return { ...acc, parser: undefined }; | ||
@@ -383,3 +398,3 @@ } | ||
} | ||
reduce(pipe(iter, opConcatMap((a) => a.split(''))), parserMain, { | ||
reduce(pipe(iter, opConcatMap((a) => [...a])), parserMain, { | ||
nodes: [root], | ||
@@ -386,0 +401,0 @@ root, |
@@ -80,3 +80,3 @@ import { TrieNodeBuilder } from '../TrieNode/TrieNodeBuilder.js'; | ||
const { cursor } = acc; | ||
const r = parseInt(ref, radix); | ||
const r = Number.parseInt(ref, radix); | ||
// +1 is used because EOW node was added but not counted. | ||
@@ -129,3 +129,3 @@ cursor.reference(r + 1); | ||
} | ||
const n = s === BACK ? 1 : parseInt(s, 10) - 1; | ||
const n = s === BACK ? 1 : Number.parseInt(s, 10) - 1; | ||
acc.cursor.backStep(n); | ||
@@ -132,0 +132,0 @@ acc.parser = parseBack; |
@@ -80,8 +80,11 @@ import { CASE_INSENSITIVE_PREFIX, COMPOUND_FIX, FORBID_PREFIX } from '../constants.js'; | ||
switch (compoundMode) { | ||
case 'none': | ||
case 'none': { | ||
return options.matchCase ? __findExact() : __findCompound(); | ||
case 'compound': | ||
} | ||
case 'compound': { | ||
return __findCompound(); | ||
case 'legacy': | ||
} | ||
case 'legacy': { | ||
return findLegacyCompound(root, word, options); | ||
} | ||
} | ||
@@ -124,3 +127,2 @@ } | ||
let node; | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
@@ -154,7 +156,5 @@ const s = stack[i]; | ||
} | ||
if (!i && !r.caseMatched) { | ||
if (w !== w.toLowerCase()) { | ||
// It is not going to be found. | ||
break; | ||
} | ||
if (!i && !r.caseMatched && w !== w.toLowerCase()) { | ||
// It is not going to be found. | ||
break; | ||
} | ||
@@ -214,3 +214,2 @@ } | ||
let node; | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
@@ -217,0 +216,0 @@ const s = stack[i]; |
@@ -23,7 +23,7 @@ import { isDefined } from '../../utils/isDefined.js'; | ||
const setOfCompoundRoots = new Set(compoundRoots); | ||
const rootsForCompoundMethods = roots.concat(compoundRoots); | ||
const rootsForCompoundMethods = [...roots, ...compoundRoots]; | ||
const compoundMethodRoots = { | ||
[CompoundWordsMethod.NONE]: [], | ||
[CompoundWordsMethod.JOIN_WORDS]: [...rootsForCompoundMethods.map((r) => [JOIN_SEPARATOR, r])], | ||
[CompoundWordsMethod.SEPARATE_WORDS]: [...rootsForCompoundMethods.map((r) => [WORD_SEPARATOR, r])], | ||
[CompoundWordsMethod.JOIN_WORDS]: rootsForCompoundMethods.map((r) => [JOIN_SEPARATOR, r]), | ||
[CompoundWordsMethod.SEPARATE_WORDS]: rootsForCompoundMethods.map((r) => [WORD_SEPARATOR, r]), | ||
}; | ||
@@ -30,0 +30,0 @@ function* children(n, hintOffset) { |
@@ -17,3 +17,3 @@ import { CompoundWordsMethod, JOIN_SEPARATOR, WORD_SEPARATOR } from './walkerTypes.js'; | ||
const c = n.keys().map((k, i) => [k, n.child(i)]); | ||
return n.eow && rc ? c.concat(rc) : c; | ||
return n.eow && rc ? [...c, ...rc] : c; | ||
} | ||
@@ -20,0 +20,0 @@ if (n.eow) { |
@@ -28,3 +28,3 @@ import { addAdjustment, createWeightMap } from '../distance/weightedMaps.js'; | ||
export function mapDictionaryInformationToWeightMap(dictInfo) { | ||
const defs = mapDictionaryInformation(dictInfo).concat(defaultDefs); | ||
const defs = [...mapDictionaryInformation(dictInfo), ...defaultDefs]; | ||
const adjustments = mapDictionaryInformationToAdjustment(dictInfo); | ||
@@ -31,0 +31,0 @@ const map = createWeightMap(...defs); |
@@ -127,3 +127,3 @@ import { opFilter, opFlatten, opMap, pipe } from '@cspell/cspell-pipe/sync'; | ||
const pairsUpper = pairs.map((p) => p.toLocaleUpperCase(costs.locale)); | ||
const map = uniqueU(pairs.concat(pairsUpper)).join('|'); | ||
const map = uniqueU([...pairs, ...pairsUpper]).join('|'); | ||
const cost = costs.keyboardCost; | ||
@@ -130,0 +130,0 @@ return { |
@@ -55,14 +55,18 @@ import { opCombine as opPipe, opConcatMap, opFilter, opMap } from '@cspell/cspell-pipe/sync'; | ||
switch (flag) { | ||
case 'split': | ||
case 'split': { | ||
split = true; | ||
break; | ||
case 'no-split': | ||
} | ||
case 'no-split': { | ||
split = false; | ||
break; | ||
case 'no-generate-alternatives': | ||
} | ||
case 'no-generate-alternatives': { | ||
stripCaseAndAccents = false; | ||
break; | ||
case 'generate-alternatives': | ||
} | ||
case 'generate-alternatives': { | ||
stripCaseAndAccents = true; | ||
break; | ||
} | ||
} | ||
@@ -105,3 +109,3 @@ } | ||
function stripKeepCasePrefixAndQuotes(word) { | ||
word = word.replace(/"(.*?)"/g, '$1'); | ||
word = word.replaceAll(/"(.*?)"/g, '$1'); | ||
return word[0] === keepCase ? word.slice(1) : word; | ||
@@ -126,7 +130,7 @@ } | ||
if (split) { | ||
const lineEscaped = line.indexOf('"') >= 0 | ||
? line.replace(/".*?"/g, (quoted) => ' ' + quoted.replace(/(\s)/g, '\\$1') + ' ') | ||
const lineEscaped = line.includes('"') | ||
? line.replaceAll(/".*?"/g, (quoted) => ' ' + quoted.replaceAll(/(\s)/g, '\\$1') + ' ') | ||
: line; | ||
const words = splitLine(lineEscaped, splitSeparator); | ||
yield* words.map((escaped) => escaped.replace(/\\/g, '')); | ||
yield* words.map((escaped) => escaped.replaceAll('\\', '')); | ||
if (!splitKeepBoth) | ||
@@ -195,6 +199,6 @@ continue; | ||
function encodeLine(line) { | ||
return line.replace(RegExpToEncode, (_, v) => '<<' + encodeURIComponent(v) + '>>'); | ||
return line.replaceAll(RegExpToEncode, (_, v) => '<<' + encodeURIComponent(v) + '>>'); | ||
} | ||
function decodeLine(line) { | ||
return line.replace(RegExpDecode, (_, v) => '\\' + decodeURIComponent(v)); | ||
return line.replaceAll(RegExpDecode, (_, v) => '\\' + decodeURIComponent(v)); | ||
} | ||
@@ -201,0 +205,0 @@ function splitLine(line, regExp) { |
@@ -39,4 +39,4 @@ const intl = new Intl.Collator('en', { sensitivity: 'base' }); | ||
function forms(letters) { | ||
const n = letters.normalize('NFC').replace(/\p{M}/gu, ''); | ||
const na = n.normalize('NFD').replace(/\p{M}/gu, ''); | ||
const n = letters.normalize('NFC').replaceAll(/\p{M}/gu, ''); | ||
const na = n.normalize('NFD').replaceAll(/\p{M}/gu, ''); | ||
const s = new Set(n + n.toLowerCase() + n.toUpperCase() + na + na.toLowerCase() + na.toUpperCase()); | ||
@@ -43,0 +43,0 @@ return [...s].join(''); |
@@ -51,8 +51,10 @@ import { isWordTerminationNode } from '../TrieNode/trie-util.js'; | ||
switch (typeof maxCost) { | ||
case 'number': | ||
case 'number': { | ||
costLimit = maxCost; | ||
break; | ||
case 'symbol': | ||
} | ||
case 'symbol': { | ||
stopNow = true; | ||
break; | ||
} | ||
} | ||
@@ -81,3 +83,3 @@ } | ||
const mxMin = Math.min(...mxRange); | ||
const tag = [a].concat(mxRange.map((c) => c - mxMin)).join(); | ||
const tag = [a, ...mxRange.map((c) => c - mxMin)].join(','); | ||
const ht = historyTags.get(tag); | ||
@@ -84,0 +86,0 @@ if (ht && ht.m <= mxMin) { |
@@ -94,3 +94,5 @@ import { CompoundWordsMethod, JOIN_SEPARATOR, WORD_SEPARATOR } from '../ITrieNode/walker/index.js'; | ||
a.cost - b.cost || | ||
// eslint-disable-next-line unicorn/prefer-code-point | ||
Math.abs(a.word.charCodeAt(0) - srcWord.charCodeAt(0)) - | ||
// eslint-disable-next-line unicorn/prefer-code-point | ||
Math.abs(b.word.charCodeAt(0) - srcWord.charCodeAt(0))); | ||
@@ -143,7 +145,5 @@ } | ||
} | ||
if (n.eow && i) { | ||
if (n.eow && i && compoundMethod) { | ||
// legacy word compound | ||
if (compoundMethod) { | ||
storePath(t, root, i, costLegacyCompound, wordSeparator, p, 'L', wordSeparator); | ||
} | ||
storePath(t, root, i, costLegacyCompound, wordSeparator, p, 'L', wordSeparator); | ||
} | ||
@@ -264,3 +264,3 @@ // swap | ||
let tt = t; | ||
for (const c of [...s]) { | ||
for (const c of s) { | ||
tt = tt.t[c] ??= createCostTrie(); | ||
@@ -332,3 +332,3 @@ } | ||
const lines = []; | ||
lines.push(`:: [${t.c.join()}]`); | ||
lines.push(`:: [${t.c.join(',')}]`); | ||
for (const [letter, child] of Object.entries(t.t)) { | ||
@@ -335,0 +335,0 @@ lines.push(letter + ':'); |
@@ -218,3 +218,3 @@ import { findNode } from '../ITrieNode/trie-util.js'; | ||
const offsetToNodeIndex = new Map(nodeOffsets.map((offset, i) => [offset, i])); | ||
const nodes = new Array(nodeOffsets.length); | ||
const nodes = Array.from({ length: nodeOffsets.length }); | ||
for (let i = 0; i < nodes.length; ++i) { | ||
@@ -225,3 +225,4 @@ const offset = nodeOffsets[i]; | ||
const count = n & TrieBlob.NodeMaskNumChildren; | ||
const node = new Array(count + 1); | ||
// Preallocate the array to the correct size. | ||
const node = Array.from({ length: count + 1 }); | ||
node[0] = eow; | ||
@@ -228,0 +229,0 @@ nodes[i] = node; |
@@ -91,2 +91,3 @@ import { assert } from '../utils/assert.js'; | ||
const insertChar = (char) => { | ||
// eslint-disable-next-line unicorn/prefer-code-point | ||
const cc = char.charCodeAt(0) & 0xfc00; | ||
@@ -93,0 +94,0 @@ // Work with partial surrogate pairs. |
@@ -10,2 +10,3 @@ import { assert } from '../utils/assert.js'; | ||
})(SpecialCharIndex || (SpecialCharIndex = {})); | ||
// eslint-disable-next-line unicorn/no-static-only-class | ||
export class NumberSequenceByteEncoderDecoder { | ||
@@ -26,14 +27,18 @@ static encode(n) { | ||
switch (a) { | ||
case SpecialCharIndex.Index8bit: | ||
case SpecialCharIndex.Index8bit: { | ||
// assert(encodedSequence.length === 2); | ||
return (b || 0) + this.SpecialCharIndexMask; | ||
case SpecialCharIndex.Index14bit: | ||
} | ||
case SpecialCharIndex.Index14bit: { | ||
// assert(encodedSequence.length === 3); | ||
return ((b || 0) << 7) + (c || 0); | ||
case SpecialCharIndex.Index21bit: | ||
} | ||
case SpecialCharIndex.Index21bit: { | ||
// assert(encodedSequence.length === 4); | ||
return ((b || 0) << 14) + ((c || 0) << 7) + (d || 0); | ||
default: | ||
} | ||
default: { | ||
// assert(a <= SpecialCharIndex.MaxCharIndex); | ||
return a; | ||
} | ||
} | ||
@@ -84,13 +89,17 @@ } | ||
switch (idx) { | ||
case NumberSequenceByteEncoderDecoder.SpecialCharIndex8bit: | ||
case NumberSequenceByteEncoderDecoder.SpecialCharIndex8bit: { | ||
this.accumulation += NumberSequenceByteEncoderDecoder.SpecialCharIndexMask; | ||
break; | ||
case NumberSequenceByteEncoderDecoder.SpecialCharIndex16bit: | ||
} | ||
case NumberSequenceByteEncoderDecoder.SpecialCharIndex16bit: { | ||
this.byteMode = 2; | ||
break; | ||
case NumberSequenceByteEncoderDecoder.SpecialCharIndex24bit: | ||
} | ||
case NumberSequenceByteEncoderDecoder.SpecialCharIndex24bit: { | ||
this.byteMode = 3; | ||
break; | ||
default: | ||
} | ||
default: { | ||
throw new Error('Invalid SpecialCharIndex'); | ||
} | ||
} | ||
@@ -97,0 +106,0 @@ return undefined; |
@@ -30,3 +30,3 @@ import { defaultTrieInfo } from '../constants.js'; | ||
const version = '00.01.00'; | ||
const endianSig = 0x04030201; | ||
const endianSig = 0x0403_0201; | ||
export class TrieBlob { | ||
@@ -239,7 +239,3 @@ nodes; | ||
if (header.getUint32(HEADER.endian, useLittle) !== endianSig) { | ||
// swap the bytes | ||
// blob.swap32(); | ||
if (header.getUint32(HEADER.endian, useLittle) !== endianSig) { | ||
throw new ErrorDecodeTrieBlob('Invalid TrieBlob Header'); | ||
} | ||
throw new ErrorDecodeTrieBlob('Invalid TrieBlob Header'); | ||
} | ||
@@ -258,3 +254,3 @@ const offsetNodes = header.getUint32(HEADER.nodes, useLittle); | ||
} | ||
static NodeMaskEOW = 0x00000100; | ||
static NodeMaskEOW = 0x0000_0100; | ||
static NodeMaskNumChildren = (1 << NodeHeaderNumChildrenBits) - 1; | ||
@@ -270,3 +266,3 @@ static NodeMaskNumChildrenShift = NodeHeaderNumChildrenShift; | ||
*/ | ||
static NodeMaskChildCharIndex = 0x000000ff; | ||
static NodeMaskChildCharIndex = 0x0000_00ff; | ||
/** SpecialCharIndexMask is used to indicate a node chain */ | ||
@@ -307,3 +303,3 @@ static SpecialCharIndexMask = 0xf8; | ||
const view = new DataView(buf.buffer); | ||
return view.getUint32(0, true) === 0x04030201; | ||
return view.getUint32(0, true) === 0x0403_0201; | ||
} | ||
@@ -310,0 +306,0 @@ function checkSig(blob) { |
@@ -26,5 +26,5 @@ import { consolidate } from './consolidate.js'; | ||
// cspell:words sigs | ||
const MAX_NUM_SIGS = 100000; | ||
const MAX_TRANSFORMS = 1000000; | ||
const MAX_CACHE_SIZE = 1000000; | ||
const MAX_NUM_SIGS = 100_000; | ||
const MAX_TRANSFORMS = 1_000_000; | ||
const MAX_CACHE_SIZE = 1_000_000; | ||
export class TrieBuilder { | ||
@@ -133,3 +133,4 @@ count = 0; | ||
buildTail(s) { | ||
const v = this.tails.get(s); | ||
const ss = s.join(''); | ||
const v = this.tails.get(ss); | ||
if (v) | ||
@@ -139,3 +140,3 @@ return v; | ||
const tail = s.slice(1); | ||
const t = this.tails.get(tail); | ||
const t = this.tails.get(tail.join('')); | ||
const c = t || this.buildTail(tail); | ||
@@ -147,3 +148,3 @@ const n = this.addChild(this.createNode(), head, c); | ||
const cachedNode = this.tryCacheFrozen(this.freeze(n)); | ||
this.tails.set(s, cachedNode); | ||
this.tails.set(ss, cachedNode); | ||
// console.warn('tail: %s', s); | ||
@@ -161,3 +162,3 @@ return cachedNode; | ||
if (Object.isFrozen(node)) { | ||
const n = this.transforms.get(node)?.get(s); | ||
const n = this.transforms.get(node)?.get(s.join('')); | ||
if (n) { | ||
@@ -167,3 +168,3 @@ return this.tryCacheFrozen(n); | ||
} | ||
if (!s) { | ||
if (!s.length) { | ||
if (!node.c) { | ||
@@ -183,3 +184,3 @@ return this._eow; | ||
node = this.addChild(node, head, child); | ||
this.storeTransform(orig, s, node); | ||
this.storeTransform(orig, s.join(''), node); | ||
this.lastPath[d] = { s: head, n: child }; | ||
@@ -207,4 +208,5 @@ return node; | ||
// } | ||
const chars = [...word]; | ||
let d = 1; | ||
for (const s of word.split('')) { | ||
for (const s of chars) { | ||
const p = this.lastPath[d]; | ||
@@ -216,4 +218,4 @@ if (p?.s !== s) | ||
// remove the remaining part of the path because it doesn't match this word. | ||
if (word.length < d) { | ||
d = word.length; | ||
if (chars.length < d) { | ||
d = chars.length; | ||
} | ||
@@ -223,3 +225,3 @@ this.lastPath.length = d; | ||
const { n } = this.lastPath[d]; | ||
const tail = word.slice(d); | ||
const tail = chars.slice(d); | ||
this.lastPath[d].n = this._insert(n, tail, d + 1); | ||
@@ -234,4 +236,4 @@ while (d > 0) { | ||
break; | ||
const tail = word.slice(d); | ||
this.storeTransform(pn, tail, parent.n); | ||
const tail = chars.slice(d); | ||
this.storeTransform(pn, tail.join(''), parent.n); | ||
} | ||
@@ -309,4 +311,4 @@ } | ||
if (!Object.isFrozen(n) || !('id' in n)) | ||
throw Error('Must be TrieNodeExFrozen'); | ||
throw new Error('Must be TrieNodeExFrozen'); | ||
} | ||
//# sourceMappingURL=TrieBuilder.js.map |
@@ -78,8 +78,11 @@ import { CASE_INSENSITIVE_PREFIX, COMPOUND_FIX, FORBID_PREFIX } from '../constants.js'; | ||
switch (compoundMode) { | ||
case 'none': | ||
case 'none': { | ||
return options.matchCase ? __findExact() : __findCompound(); | ||
case 'compound': | ||
} | ||
case 'compound': { | ||
return __findCompound(); | ||
case 'legacy': | ||
} | ||
case 'legacy': { | ||
return findLegacyCompound(root, word, options); | ||
} | ||
} | ||
@@ -122,3 +125,2 @@ } | ||
let node; | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
@@ -152,7 +154,5 @@ const s = stack[i]; | ||
} | ||
if (!i && !r.caseMatched) { | ||
if (w !== w.toLowerCase()) { | ||
// It is not going to be found. | ||
break; | ||
} | ||
if (!i && !r.caseMatched && w !== w.toLowerCase()) { | ||
// It is not going to be found. | ||
break; | ||
} | ||
@@ -211,3 +211,2 @@ } | ||
let node; | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
@@ -214,0 +213,0 @@ const s = stack[i]; |
@@ -10,3 +10,3 @@ import { insertWordsAtCursor } from '../Builder/index.js'; | ||
root = { ...defaultTrieInfo, c: Object.create(null) }; | ||
wordToCharacters = (word) => word.split(''); | ||
wordToCharacters = (word) => [...word]; | ||
setOptions(options) { | ||
@@ -13,0 +13,0 @@ const opts = mergeOptionalWithDefaults(options, this.root); |
@@ -16,3 +16,3 @@ import { consolidate } from '../consolidate.js'; | ||
} | ||
wordToCharacters = (word) => word.split(''); | ||
wordToCharacters = (word) => [...word]; | ||
get iTrieRoot() { | ||
@@ -19,0 +19,0 @@ return this._iTrieRoot || (this._iTrieRoot = trieRootToITrieRoot(this.root)); |
@@ -13,3 +13,3 @@ /** | ||
*/ | ||
export const normalizeWordToLowercase = (text) => text.toLowerCase().normalize('NFD').replace(/\p{M}/gu, ''); | ||
export const normalizeWordToLowercase = (text) => text.toLowerCase().normalize('NFD').replaceAll(/\p{M}/gu, ''); | ||
/** | ||
@@ -22,4 +22,4 @@ * generate case insensitive forms of a word | ||
const t = text.toLowerCase(); | ||
return [t, t.normalize('NFD').replace(/\p{M}/gu, '')]; | ||
return [t, t.normalize('NFD').replaceAll(/\p{M}/gu, '')]; | ||
}; | ||
//# sourceMappingURL=normalizeWord.js.map |
@@ -30,3 +30,3 @@ export interface PairHeapNode<T> { | ||
/** Add items to the heap */ | ||
concat(i: Iterable<T>): this; | ||
append(i: Iterable<T>): this; | ||
/** get the next value */ | ||
@@ -33,0 +33,0 @@ next(): IteratorResult<T>; |
@@ -22,3 +22,3 @@ export class PairingHeap { | ||
/** Add items to the heap */ | ||
concat(i) { | ||
append(i) { | ||
for (const v of i) { | ||
@@ -25,0 +25,0 @@ this.add(v); |
@@ -22,8 +22,6 @@ /** | ||
} | ||
if (char === rangeChar) { | ||
if (char === rangeChar && prev) { | ||
// store the `-` if there isn't a previous value. | ||
if (prev) { | ||
mode = 1; | ||
continue; | ||
} | ||
mode = 1; | ||
continue; | ||
} | ||
@@ -93,3 +91,3 @@ charSet.add(char); | ||
export function stripAccents(characters) { | ||
return characters.normalize('NFD').replace(/\p{M}/gu, ''); | ||
return characters.normalize('NFD').replaceAll(/\p{M}/gu, ''); | ||
} | ||
@@ -102,8 +100,10 @@ /** | ||
export function stripNonAccents(characters) { | ||
return characters.normalize('NFD').replace(/[^\p{M}]/gu, ''); | ||
return characters.normalize('NFD').replaceAll(/[^\p{M}]/gu, ''); | ||
} | ||
export function isValidUtf16Character(char) { | ||
const len = char.length; | ||
// eslint-disable-next-line unicorn/prefer-code-point | ||
const code = char.charCodeAt(0) & 0xfc00; | ||
const valid = (len === 1 && (code & 0xf800) !== 0xd800) || | ||
// eslint-disable-next-line unicorn/prefer-code-point | ||
(len === 2 && (code & 0xfc00) === 0xd800 && (char.charCodeAt(1) & 0xfc00) === 0xdc00); | ||
@@ -115,6 +115,3 @@ return valid; | ||
const len = char.length; | ||
const codes = char | ||
.slice(0, 2) | ||
.split('') | ||
.map((c) => '0x' + ('0000' + c.charCodeAt(0).toString(16)).slice(-4)); | ||
const codes = toCharCodes(char.slice(0, 2)).map((c) => '0x' + ('0000' + c.toString(16)).slice(-4)); | ||
let message; | ||
@@ -133,2 +130,10 @@ if (len == 1) { | ||
} | ||
function toCharCodes(s) { | ||
const values = []; | ||
for (let i = 0; i < s.length; ++i) { | ||
// eslint-disable-next-line unicorn/prefer-code-point | ||
values.push(s.charCodeAt(i)); | ||
} | ||
return values; | ||
} | ||
//# sourceMappingURL=text.js.map |
@@ -69,3 +69,3 @@ export function startTimer() { | ||
return { | ||
name: '| '.repeat(d) + (e.name || '').replace(/\t/g, ' '), | ||
name: '| '.repeat(d) + (e.name || '').replaceAll('\t', ' '), | ||
at: `${t(e.at)}`, | ||
@@ -72,0 +72,0 @@ elapsed: e.elapsed ? `${t(e.elapsed)}` : '--', |
@@ -45,3 +45,3 @@ export function isDefined(a) { | ||
export function regexQuote(text) { | ||
return text.replace(/([[\]\-+(){},|*.\\])/g, '\\$1'); | ||
return text.replaceAll(/([[\]\-+(){},|*.\\])/g, '\\$1'); | ||
} | ||
@@ -48,0 +48,0 @@ /** |
@@ -26,7 +26,7 @@ import { isDefined } from '../utils/isDefined.js'; | ||
const setOfCompoundRoots = new Set(compoundRoots); | ||
const rootsForCompoundMethods = roots.concat(compoundRoots); | ||
const rootsForCompoundMethods = [...roots, ...compoundRoots]; | ||
const compoundMethodRoots = { | ||
[CompoundWordsMethod.NONE]: [], | ||
[CompoundWordsMethod.JOIN_WORDS]: [...rootsForCompoundMethods.map((r) => [JOIN_SEPARATOR, r])], | ||
[CompoundWordsMethod.SEPARATE_WORDS]: [...rootsForCompoundMethods.map((r) => [WORD_SEPARATOR, r])], | ||
[CompoundWordsMethod.JOIN_WORDS]: rootsForCompoundMethods.map((r) => [JOIN_SEPARATOR, r]), | ||
[CompoundWordsMethod.SEPARATE_WORDS]: rootsForCompoundMethods.map((r) => [WORD_SEPARATOR, r]), | ||
}; | ||
@@ -33,0 +33,0 @@ function* children(n, hintOffset) { |
@@ -17,3 +17,3 @@ import { trieNodeToITrieNode } from '../TrieNode/trie.js'; | ||
if (n.c && n.f && rc) { | ||
return Object.entries(n.c).concat(rc); | ||
return [...Object.entries(n.c), ...rc]; | ||
} | ||
@@ -20,0 +20,0 @@ if (n.c) { |
{ | ||
"name": "cspell-trie-lib", | ||
"version": "8.7.0", | ||
"version": "8.8.0", | ||
"description": "Trie Data Structure to support cspell.", | ||
@@ -27,3 +27,3 @@ "type": "module", | ||
"build": "pnpm run build:lib && pnpm run build:api", | ||
"build:lib": "tsc -b .", | ||
"build:lib": "tsc -p .", | ||
"build:api": "rollup -c api/rollup.config.mjs", | ||
@@ -33,4 +33,5 @@ "clean-build": "pnpm run clean && pnpm run build", | ||
"test:watch": "vitest", | ||
"test:perf": "insight --register ts-node/esm --file \"**/*.perf.{mts,ts}\" -t 500", | ||
"test": "vitest run", | ||
"watch": "tsc -b . -w" | ||
"watch": "tsc -p . -w" | ||
}, | ||
@@ -53,4 +54,4 @@ "repository": { | ||
"dependencies": { | ||
"@cspell/cspell-pipe": "8.7.0", | ||
"@cspell/cspell-types": "8.7.0", | ||
"@cspell/cspell-pipe": "8.8.0", | ||
"@cspell/cspell-types": "8.8.0", | ||
"gensequence": "^7.0.0" | ||
@@ -62,8 +63,8 @@ }, | ||
"devDependencies": { | ||
"@cspell/dict-en_us": "^4.3.17", | ||
"@cspell/dict-es-es": "^2.4.0", | ||
"@cspell/dict-en_us": "^4.3.19", | ||
"@cspell/dict-es-es": "^3.0.0", | ||
"@cspell/dict-nl-nl": "^2.3.0", | ||
"import-meta-resolve": "^4.0.0" | ||
"import-meta-resolve": "^4.1.0" | ||
}, | ||
"gitHead": "5318079ed11fe77e981287ecf1c40d6f28dd91ed" | ||
"gitHead": "a42bce675c00cb2d51809b3ae3894119ea4f5ce7" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
423379
11300
+ Added@cspell/cspell-pipe@8.8.0(transitive)
+ Added@cspell/cspell-types@8.8.0(transitive)
- Removed@cspell/cspell-pipe@8.7.0(transitive)
- Removed@cspell/cspell-types@8.7.0(transitive)
Updated@cspell/cspell-pipe@8.8.0
Updated@cspell/cspell-types@8.8.0