How to use the gensequence.genSequence function in gensequence

To help you get started, we’ve selected a few gensequence examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github streetsidesoftware / cspell / packages / cspell-tools / dist / wordListCompiler.js View on Github external
function lineToWords(line) {
    // Remove punctuation and non-letters.
    const filteredLine = line.replace(regNonWordOrSpace, '|');
    const wordGroups = filteredLine.split('|');
    const words = gensequence_1.genSequence(wordGroups)
        .concatMap(a => [a, ...a.split(regExpSpaceOrDash)])
        .concatMap(a => splitCamelCase(a))
        .map(a => a.trim())
        .filter(s => s.length > 2)
        .filter(s => !regExpRepeatChars.test(s))
        .map(a => a.toLowerCase())
        .reduceToSequence((s, w) => s.add(w), new Set());
    return words;
}
exports.lineToWords = lineToWords;
github streetsidesoftware / cspell / dist / SpellingDictionary / SpellingDictionaryCollection.js View on Github external
function makeSuggestions(dicts, word, numSuggestions) {
    // Make a map of the unique suggestions.  If there are duplicates, keep the lowest cost.
    const allSuggestions = gensequence_1.genSequence(dicts)
        .concatMap(dict => dict.suggest(word, numSuggestions))
        .reduceToSequence((map, sug) => {
        const cost = Math.min(sug.cost, (map.get(sug.word) || sug).cost);
        map.set(sug.word, __assign({}, sug, { cost }));
        return map;
    }, new Map())
        .map(([, v]) => v)
        .toArray()
        .sort((a, b) => a.cost - b.cost);
    return allSuggestions.slice(0, numSuggestions);
}
exports.makeSuggestions = makeSuggestions;
github streetsidesoftware / cspell / packages / cspell-trie-lib / src / lib / importExportV1.ts View on Github external
function generateHeader(base: number, comment: string): Sequence {
    const header = [
        '#!/usr/bin/env cspell-trie reader',
        'TrieXv1',
        'base=' + base,
    ]
    .concat(comment
        ? comment.split('\n').map(a => '# ' + a)
        : []
    )
    .concat([
        '# Data:'
    ]);
    return genSequence(header)
        .map(a => a + '\n');
}
github streetsidesoftware / cspell / packages / cspell-trie / src / lib / importExport.ts View on Github external
function generateHeader(base: number, comment: string): Sequence {
    const header = [
        '#!/usr/bin/env cspell-trie reader',
        'TrieXv1',
        'base=' + base,
    ]
    .concat(comment
        ? comment.split('\n').map(a => '# ' + a)
        : []
    )
    .concat([
        '# Data:'
    ]);
    return genSequence(header)
        .map(a => a + '\n');
}
github streetsidesoftware / cspell / packages / cspell-trie-lib / src / lib / importExportV3.ts View on Github external
function generateHeader(base: number, comment: string): Sequence {
    const header = [
        '#!/usr/bin/env cspell-trie reader',
        'TrieXv3',
        'base=' + base,
    ]
    .concat(comment
        ? comment.split('\n').map(a => '# ' + a)
        : []
    )
    .concat([
        '# Data:',
        DATA,
    ]);
    return genSequence(header).map(a => a + '\n');
}
github streetsidesoftware / cspell / packages / cspell-trie / src / app.ts View on Github external
async function fileToLines(filename: string): Promise> {
    const buffer = await fs.readFile(filename);
    const file = (filename.match(/\.gz$/) ? zlib.gunzipSync(buffer) : buffer).toString(UTF8);
    return genSequence(file.split(/\r?\n/));
}
github streetsidesoftware / vscode-spell-checker / server / src / textValidator.ts View on Github external
export function wordSplitter(word: string): Sequence<[string, string]> {
    function* split(word: string): IterableIterator<[string, string]> {
        for (let i = minWordSplitLen; i <= word.length - minWordSplitLen; ++i) {
            yield [word.slice(0, i), word.slice(i)];
        }
    }
    return genSequence(split(word));
}
github streetsidesoftware / cspell / packages / cspell-lib / src / SpellingDictionary / SpellingDictionaryCollection.ts View on Github external
export function isWordInAnyDictionary(dicts: SpellingDictionary[], word: string, options: SearchOptions) {
    return !!genSequence(dicts)
        .first(dict => dict.has(word, options));
}
github streetsidesoftware / vscode-spell-checker / server / src / SpellingDictionaryCollection.ts View on Github external
export function isWordInAnyDictionary(dicts: SpellingDictionary[], word: string) {
    return !!genSequence(dicts)
        .first(dict => dict.has(word));
}
github streetsidesoftware / cspell / packages / cspell-trie / src / lib / importExport.ts View on Github external
function leaves(node: TrieNode): Sequence {
    function *walk(node: TrieNode, k: string, p?: TrieNode): IterableIterator {
        if (!node.c) {
            yield { n: node, p, k};
        } else {
            for (const n of node.c) {
                yield* walk(n[1], n[0], node);
            }
        }
    }

    return genSequence(walk(node, ''));
}

gensequence

Small library to simplify working with Generators and Iterators in Javascript / Typescript

MIT
Latest version published 10 months ago

Package Health Score

74 / 100
Full package analysis

Popular gensequence functions