Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cspell-tools

Package Overview
Dependencies
Maintainers
1
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cspell-tools - npm Package Compare versions

Comparing version 4.0.14 to 4.0.15

2

dist/compiler/fileWriter.d.ts
import { Sequence } from 'gensequence';
export { writeToFile, writeToFileIterableP, writeToFileIterable } from 'cspell-io';
export declare function writeSeqToFile(seq: Sequence<string>, outFile: string | undefined): Promise<void>;
export declare function writeSeqToFile(seq: Sequence<string>, outFile: string): Promise<void>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const gensequence_1 = require("gensequence");
const iterableToStream_1 = require("hunspell-reader/dist/iterableToStream");
const util_1 = require("hunspell-reader/dist/util");
const cspell_io_1 = require("cspell-io");

@@ -12,40 +9,5 @@ var cspell_io_2 = require("cspell-io");

function writeSeqToFile(seq, outFile) {
if (outFile) {
return cspell_io_1.writeToFileIterableP(outFile, seq);
}
return new Promise((resolve, reject) => {
let resolved = false;
const out = process.stdout;
const bufferedSeq = gensequence_1.genSequence(util_1.batch(seq, 500)).map(batch => batch.join(''));
const dataStream = iterableToStream_1.iterableToStream(bufferedSeq);
const fileStream = dataStream.pipe(out);
const endEvents = ['finish', 'close', 'end'];
function resolvePromise() {
if (!resolved) {
resolved = true;
resolve();
}
}
const endHandler = () => {
cleanupStreams();
setTimeout(resolvePromise, 10);
};
const errorHandler = (e) => {
cleanupStreams();
reject(e);
};
listenToStreams();
function listenToStreams() {
endEvents.forEach(event => fileStream.addListener(event, endHandler));
fileStream.addListener('error', errorHandler);
dataStream.addListener('end', endHandler);
}
function cleanupStreams() {
endEvents.forEach(event => fileStream.removeListener(event, endHandler));
fileStream.removeListener('error', errorHandler);
dataStream.removeListener('end', endHandler);
}
});
return cspell_io_1.writeToFileIterableP(outFile, seq);
}
exports.writeSeqToFile = writeSeqToFile;
//# sourceMappingURL=fileWriter.js.map

@@ -1,12 +0,1 @@

import { Sequence } from 'gensequence';
export interface WordOffset {
word: string;
offset: number;
}
export interface TextOffset {
text: string;
offset: number;
}
export declare type STW = string | TextOffset | WordOffset;
export declare function splitCamelCaseWordWithOffset(wo: WordOffset): Array<WordOffset>;
/**

@@ -16,31 +5,1 @@ * Split camelCase words into an array of strings.

export declare function splitCamelCaseWord(word: string): string[];
/**
* Extract out whole words from a string of text.
*/
export declare function extractWordsFromText1(text: string): WordOffset[];
/**
* This function lets you iterate over regular expression matches.
*/
export declare function match(reg: RegExp, text: string): Sequence<RegExpExecArray>;
export declare function matchToTextOffset(reg: RegExp, text: STW): Sequence<TextOffset>;
export declare function matchToWordOffset(reg: RegExp, text: STW): Sequence<WordOffset>;
export declare function extractLinesOfText(text: STW): Sequence<TextOffset>;
/**
* Extract out whole words from a string of text.
*/
export declare function extractWordsFromText(text: string): Sequence<WordOffset>;
export declare function extractWordsFromCode(text: string): Sequence<WordOffset>;
export declare function isUpperCase(word: string): boolean;
export declare function isLowerCase(word: string): boolean;
export declare function isFirstCharacterUpper(word: string): boolean;
export declare function isFirstCharacterLower(word: string): boolean;
export declare function ucFirst(word: string): string;
export declare function lcFirst(word: string): string;
export declare function snakeToCamel(word: string): string;
export declare function camelToSnake(word: string): string;
export declare function matchCase(example: string, word: string): string;
export declare function isTextOffset(x: any): x is TextOffset;
export declare function isWordOffset(x: any): x is WordOffset;
export declare function toWordOffset(text: string | WordOffset | TextOffset): WordOffset;
export declare function toTextOffset(text: string | WordOffset | TextOffset): TextOffset;
export declare function stringToRegExp(pattern: string | RegExp, defaultFlags?: string, forceFlags?: string): RegExp | undefined;

@@ -6,19 +6,5 @@ "use strict";

const cspell_util_bundle_1 = require("cspell-util-bundle");
const gensequence_1 = require("gensequence");
const regExLines = /.*\r?\n/g;
// const regExIdentifiers = XRegExp('(?:\\p{L}|[0-9_\'])+', 'gi');
const regExUpperSOrIng = cspell_util_bundle_1.xregexp('(\\p{Lu}+\'?(?:s|ing|ies|es|ings|ed|ning))(?!\\p{Ll})', 'g');
const regExSplitWords = cspell_util_bundle_1.xregexp('(\\p{Ll})(\\p{Lu})', 'g');
const regExSplitWords2 = cspell_util_bundle_1.xregexp('(\\p{Lu})(\\p{Lu}\\p{Ll})', 'g');
const regExWords = cspell_util_bundle_1.xregexp("\\p{L}(?:[']\\p{L}|\\p{L})+|\\p{L}", 'g');
const regExIgnoreCharacters = cspell_util_bundle_1.xregexp('\\p{Hiragana}|\\p{Han}|\\p{Katakana}', 'g');
const regExFirstUpper = cspell_util_bundle_1.xregexp('^\\p{Lu}\\p{Ll}+$');
const regExAllUpper = cspell_util_bundle_1.xregexp('^\\p{Lu}+$');
const regExAllLower = cspell_util_bundle_1.xregexp('^\\p{Ll}+$');
const regExMatchRegExParts = /^\/(.*)\/([gimuy]*)$/;
function splitCamelCaseWordWithOffset(wo) {
return splitCamelCaseWord(wo.word)
.map(gensequence_1.scanMap((last, word) => ({ word, offset: last.offset + last.word.length }), { word: '', offset: wo.offset }));
}
exports.splitCamelCaseWordWithOffset = splitCamelCaseWordWithOffset;
/**

@@ -35,160 +21,2 @@ * Split camelCase words into an array of strings.

exports.splitCamelCaseWord = splitCamelCaseWord;
/**
* Extract out whole words from a string of text.
*/
function extractWordsFromText1(text) {
const words = [];
const reg = cspell_util_bundle_1.xregexp(regExWords);
let match;
while (match = reg.exec(text)) {
words.push({
word: match[0],
offset: match.index
});
}
return words;
}
exports.extractWordsFromText1 = extractWordsFromText1;
/**
* This function lets you iterate over regular expression matches.
*/
function match(reg, text) {
return gensequence_1.sequenceFromRegExpMatch(reg, text);
}
exports.match = match;
function matchToTextOffset(reg, text) {
const textOffset = toTextOffset(text);
const fnOffsetMap = offsetMap(textOffset.offset);
return match(reg, textOffset.text)
.map(m => fnOffsetMap({ text: m[0], offset: m.index }));
}
exports.matchToTextOffset = matchToTextOffset;
function matchToWordOffset(reg, text) {
return gensequence_1.genSequence(matchToTextOffset(reg, text))
.map(t => ({ word: t.text, offset: t.offset }));
}
exports.matchToWordOffset = matchToWordOffset;
function extractLinesOfText(text) {
return matchToTextOffset(regExLines, text);
}
exports.extractLinesOfText = extractLinesOfText;
/**
* Extract out whole words from a string of text.
*/
function extractWordsFromText(text) {
const reg = cspell_util_bundle_1.xregexp(regExWords);
return matchToWordOffset(reg, text)
// remove characters that match against \p{L} but are not letters (Chinese characters are an example).
.map(wo => ({
word: cspell_util_bundle_1.xregexp.replace(wo.word, regExIgnoreCharacters, (match) => ' '.repeat(match.length)).trim(),
offset: wo.offset
}))
.filter(wo => !!wo.word);
}
exports.extractWordsFromText = extractWordsFromText;
function extractWordsFromCode(text) {
return extractWordsFromText(text)
.concatMap(splitCamelCaseWordWithOffset);
}
exports.extractWordsFromCode = extractWordsFromCode;
function isUpperCase(word) {
return !!word.match(regExAllUpper);
}
exports.isUpperCase = isUpperCase;
function isLowerCase(word) {
return !!word.match(regExAllLower);
}
exports.isLowerCase = isLowerCase;
function isFirstCharacterUpper(word) {
return isUpperCase(word.slice(0, 1));
}
exports.isFirstCharacterUpper = isFirstCharacterUpper;
function isFirstCharacterLower(word) {
return isLowerCase(word.slice(0, 1));
}
exports.isFirstCharacterLower = isFirstCharacterLower;
function ucFirst(word) {
return word.slice(0, 1).toUpperCase() + word.slice(1);
}
exports.ucFirst = ucFirst;
function lcFirst(word) {
return word.slice(0, 1).toLowerCase() + word.slice(1);
}
exports.lcFirst = lcFirst;
function snakeToCamel(word) {
return word.split('_').map(ucFirst).join('');
}
exports.snakeToCamel = snakeToCamel;
function camelToSnake(word) {
return splitCamelCaseWord(word).join('_').toLowerCase();
}
exports.camelToSnake = camelToSnake;
function matchCase(example, word) {
if (example.match(regExFirstUpper)) {
return word.slice(0, 1).toUpperCase() + word.slice(1).toLowerCase();
}
if (example.match(regExAllLower)) {
return word.toLowerCase();
}
if (example.match(regExAllUpper)) {
return word.toUpperCase();
}
if (isFirstCharacterUpper(example)) {
return ucFirst(word);
}
if (isFirstCharacterLower(example)) {
return lcFirst(word);
}
return word;
}
exports.matchCase = matchCase;
function isTextOffset(x) {
return typeof x === 'object' && typeof x.text === 'string' && typeof x.offset === 'number';
}
exports.isTextOffset = isTextOffset;
function isWordOffset(x) {
return typeof x === 'object' && typeof x.word === 'string' && typeof x.offset === 'number';
}
exports.isWordOffset = isWordOffset;
function toWordOffset(text) {
if (typeof text === 'string') {
return { word: text, offset: 0 };
}
if (isWordOffset(text)) {
return text;
}
return { word: text.text, offset: text.offset };
}
exports.toWordOffset = toWordOffset;
function toTextOffset(text) {
if (typeof text === 'string') {
return { text: text, offset: 0 };
}
if (isTextOffset(text)) {
return text;
}
return { text: text.word, offset: text.offset };
}
exports.toTextOffset = toTextOffset;
function offsetMap(offset) {
return (xo) => Object.assign({}, xo, { offset: xo.offset + offset });
}
function stringToRegExp(pattern, defaultFlags = 'gim', forceFlags = 'g') {
if (pattern instanceof RegExp) {
return pattern;
}
try {
const [, pat, flag] = [...(pattern.match(regExMatchRegExParts) || ['', pattern, defaultFlags]), forceFlags];
// Make sure the flags are unique.
const flags = [...(new Set(forceFlags + flag))].join('').replace(/[^gimuy]/g, '');
if (pat) {
const regex = new RegExp(pat, flags);
return regex;
}
}
catch (e) {
}
return undefined;
}
exports.stringToRegExp = stringToRegExp;
//# sourceMappingURL=text.js.map
{
"name": "cspell-tools",
"version": "4.0.14",
"version": "4.0.15",
"description": "Tools to assist with the development of cSpell",

@@ -14,7 +14,6 @@ "typings": "dist/index.d.ts",

"clean": "rimraf dist && rimraf temp",
"coverage": "NODE_ENV=test nyc --silent --no-clean --temp-dir=../../.nyc_output npm run test-ts",
"lint": "tslint --project tsconfig.json",
"test-ts": "NODE_ENV=test ../../node_modules/.bin/mocha --require ts-node/register --recursive \"src/**/*.test.ts\"",
"test-watch": "../../node_modules/.bin/mocha --require ts-node/register --watch --recursive \"src/**/*.test.ts\"",
"test": "mocha --recursive ./dist/**/*.test.js"
"coverage": "jest --coverage",
"test-watch": "../../node_modules/.bin/jest --watch",
"test": "jest"
},

@@ -45,5 +44,5 @@ "repository": {

"commander": "^2.20.0",
"cspell-io": "^4.0.10",
"cspell-trie-lib": "^4.0.8",
"cspell-util-bundle": "^4.0.1",
"cspell-io": "^4.0.11",
"cspell-trie-lib": "^4.0.9",
"cspell-util-bundle": "^4.0.2",
"fs-extra": "^7.0.1",

@@ -77,3 +76,3 @@ "gensequence": "^2.1.2",

},
"gitHead": "f0870f747b05f0a2b6fdc1a5118bc4224baa7700"
"gitHead": "a889d1ac70724471454a4189f4082f3af4971074"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc