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

yaspeller

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yaspeller - npm Package Compare versions

Comparing version 2.4.0 to 2.5.0

32

CHANGELOG.md
# Changelog
## 2.5.0
- Replace npm module `eyo` to `eyo-kernel`
- Output warnings of duplicate words in dictionaries
- Update deps in package.json
- Simplified regular expressions in words in the dictionary
Before(<= 2.4.0):
```js
[
"someword1", // someword1 = someword1
"Someword2", // Someword2 = Someword2
"/some(w|W)ord[23]/", // some(w|W)ord[23] = some(w|W)ord[23]
"/Some(w|W)ord/" // Some(w|W)ord = Some(w|W)ord
]
```
After(2.5.0):
```js
[
"someword1", // someword1 = someword1 and Someword1
"Someword2", // Someword2 = Someword2
"some(w|W)ord[23]", // some(w|W)ord[23] = some(w|W)ord[23] and Some(w|W)ord[23]
"Some(w|W)ord" // Some(w|W)ord = Some(w|W)ord
]
```
## 2.4.0

@@ -7,7 +33,7 @@ - Ability to ignore text when checking

### Bug fixes
- Fix JSON comments in dictionaries and configs
- Fix JSON comments in dictionaries and config's
## 2.3.0
- JSON comments in dictionaries and configs #35
- Аbility to specify multiple dictionaries in option --dictionary #33
- JSON comments in dictionaries and config's #35
- Ability to specify multiple dictionaries in option --dictionary #33
- Markdown report #31

@@ -14,0 +40,0 @@ - Update deps in package.json

var chalk = require('chalk'),
util = require('util'),
_ = require('lodash'),
debug = require('./debug'),
exitCodes = require('./exit-codes'),
utils = require('./utils'),
printDebug = debug.print;
printDebug = debug.print,
letters = '[a-zа-яё\\d-]',
reNotOptimized = new RegExp('(^|^\\/|' + letters + ')' +
'(\\(|\\[)' + letters + '(\\)|\\])(' + letters + '|\\/$|$)', 'i'),
rePrepare = new RegExp('(^\\/|^)(' + letters + ')(' + letters + '|$)');
function isTypo(word, dictionary) {
return !dictionary.some(function(dictWord) {
return util.isRegExp(dictWord) ? dictWord.test(word) : word === dictWord;
});
}
module.exports = {

@@ -19,16 +17,33 @@ /**

* @param {Array} files
* @param {Array} dictionary - Dictionary from .yaspellerrc
* @param {Array} configDictionary - Dictionary from .yaspellerrc
* @return {Array}
*/
getDictionary: function(files, dictionary) {
var result = [];
getDictionary: function(files, configDictionary) {
var result = [],
count = 0,
commonUniqueWords = [],
that = this;
if(dictionary) {
result = dictionary;
function prepare(words, file) {
result = result.concat(words);
that.checkDuplicates(words, 'Dictionary duplicate words in "' + file + '":');
that.checkTyposInDictionary(words, file);
commonUniqueWords = commonUniqueWords.concat(_.unique(words));
count++;
}
if(configDictionary) {
prepare(configDictionary, '.yaspellerrc');
}
files && files.forEach(function(file) {
result = result.concat(this.loadDictionary(file));
prepare(this.loadDictionary(file), file);
}, this);
if(count > 1) {
this.checkDuplicates(commonUniqueWords, 'Duplicate words in dictionaries:');
}
return this.prepareDictionary(result);

@@ -59,2 +74,45 @@ },

/**
* Check duplicate words in dictionary.
*
* @param {string[]} words
* @return {boolean}
*/
checkDuplicates: function(words, title) {
var duplicates = this.getDuplicates(words);
if(duplicates.length) {
console.log(chalk.cyan(title + '\n' + duplicates.join('\n') + '\n'));
return true;
}
return false;
},
/**
* Check typos in dictionary.
*
* @param {string[]} words
* @param {string} file
* @return {boolean}
*/
checkTyposInDictionary: function(words, file) {
var typos = [];
words.forEach(function(word) {
if(utils.hasEnRu(word)) {
typos.push(word);
}
});
var hasTypos = typos.length ? true : false;
if(hasTypos) {
console.log(chalk.cyan('Has typos in "' + file + '":'));
typos.forEach(function(typo) {
console.log(chalk.cyan(typo + ' - en: ' + utils.replaceEn(typo) +
', ru: ' + utils.replaceEn(typo)));
});
console.log('');
}
return hasTypos;
},
/**
* Remove typos that is in the dictionary.

@@ -70,6 +128,6 @@ *

data.forEach(function(typo) {
if((typo.code !== 1 && typo.code !== 3) || isTypo(typo.word, dictionary)) {
if((typo.code !== 1 && typo.code !== 3) || this.isTypo(typo.word, dictionary)) {
result.push(typo);
}
});
}, this);

@@ -79,2 +137,14 @@ return result;

/**
* It's a typo?
*
* @param {string} word
* @param {string[]|RegExp[]} dictionary
* @return {boolean}
*/
isTypo: function(word, dictionary) {
return !dictionary.some(function(dictWord) {
return dictWord.test(word);
});
},
/**
* Prepare dictionary.

@@ -88,10 +158,22 @@ *

dict.forEach(function(word) {
if(word.search(/^\/.+\/i?$/) !== -1) {
try {
result.push(this.parseRegExp(word));
} catch(e) {
console.error(chalk.red('Incorrect RegExp "' + word + '", ' + e));
if(this.isNotOptimizedRegExp(word)) {
console.log(chalk.cyan('Not optimized dictionary RegExp in "' + word + '"'));
}
// /unknownWord(s)?/ = /unknownWord(s)?/ and /UnknownWord(s)?/
// /UnknownWord(s)?/ = /UnknownWord(s)?/
var preparedWord = word.replace(rePrepare, function($, $1, $2, $3) {
return $1 + '[' + $2 + $2.toUpperCase() + ']' + $3;
});
try {
if(word.search(/^\/.+\/i?$/) !== -1) {
// Old format
result.push(this.parseRegExpOldFormat(preparedWord));
} else {
result.push(new RegExp(preparedWord));
}
} else {
result.push(word);
} catch(e) {
console.error(chalk.red('Incorrect dictionary RegExp in "' + word + '", ' + e));
}

@@ -103,11 +185,76 @@ }, this);

/**
* Parse RegExp.
* Is not optimized RegExp?
*
* @param {string} text
* @return {boolean}
*/
isNotOptimizedRegExp: function(text) {
if(text.search(/(\(\)|\[\])/) !== -1) { // /[]Unknownword()/
return true;
}
if(text.search(reNotOptimized) !== -1) { // /Unknow(n)wo[r]d/
return true;
}
return false;
},
/**
* Get duplicate words.
*
* @param {string[]} words
* @return {string[]}
*/
getDuplicates: function(words) {
var buffer = {},
result = [];
words.forEach(function(word) {
if(!buffer[word]) {
buffer[word] = 1;
} else if(buffer[word] === 1) {
buffer[word]++;
result.push(word);
}
});
return result;
},
/**
* Parse RegExp old format.
*
* @param {string} text
* @return {RegExp}
*/
parseRegExp: function(text) {
parseRegExpOldFormat: function(text) {
var buf = text.split('\/');
return new RegExp('^' + buf[1] + '$', buf[2] || '');
},
/**
* Is a letter?
*
* @param {string} symbol
* @return {boolean}
*/
isLetter: function(symbol) {
return symbol.toLowerCase() !== symbol.toUpperCase();
},
/**
* Is a letter in upper case?
*
* @param {string} letter
* @return {boolean}
*/
isUpperCase: function(letter) {
return letter === letter.toUpperCase();
},
/**
* Is a letter in lower case?
*
* @param {string} letter
* @return {boolean}
*/
isLowerCase: function(letter) {
return letter === letter.toLowerCase();
}
};

2

lib/yaspeller.js
/* jshint maxlen: 300 */
var async = require('async'),
entities = require('entities'),
eyo = require('eyo'),
eyo = require('eyo-kernel'),
fs = require('fs'),

@@ -6,0 +6,0 @@ formatModule = require('./format'),

@@ -13,3 +13,3 @@ {

"description": "Search tool typos in the text, files and websites",
"version": "2.4.0",
"version": "2.5.0",
"license": "MIT",

@@ -36,6 +36,6 @@ "homepage": "https://github.com/hcodes/yaspeller",

"dependencies": {
"async": "~1.0.0",
"async": "~1.2.1",
"chalk": "~1.0.0",
"commander": "~2.8.0",
"eyo": "~1.1.0",
"eyo-kernel": "~1.0.0",
"entities": "~1.1.1",

@@ -46,3 +46,3 @@ "isutf8": "~1.0.11",

"request": "2.x",
"showdown": "~1.0.1",
"showdown": "~1.1.0",
"strip-json-comments": "~1.0.2",

@@ -52,6 +52,6 @@ "xml2js": "~0.4.5"

"devDependencies": {
"chai": "~2.3.0",
"chai": "~3.0.0",
"istanbul": "~0.3.7",
"jscs": "~1.13.1",
"jshint": "~2.7.0",
"jshint": "~2.8.0",
"mocha": "~2.2.1",

@@ -58,0 +58,0 @@ "sinon": "^1.14.1"

@@ -49,6 +49,6 @@ yaspeller

JSON file for own dictionary.
```JSON
```js
[
"someword1",
"someword2",
"someword1", // someword1 = someword1 and Someword1
"Someword2", // Someword2 = Someword2
"someword3"

@@ -61,7 +61,8 @@ ]

[
"someword1", // JSON comments
"/(S|s)omeword2/",
"/someword3/i"
"unknownword",
"unknown(W|w)ord[12]?", // unknown(W|w)ord[12]? = unknown(W|w)ord[12]? and Unknown(W|w)ord[12]?
"Unknown(W|w)ord[34]?" // Unknown(W|w)ord[34]? = Unknown(W|w)ord[34]?
]
```
Examples:<br/>

@@ -174,4 +175,7 @@ `yaspeller --dictionary my_dict.json .`<br/>

"dictionary": [
"someword1", // JSON comments
"/(S|s)omeword2/"
// JSON comments
"someword1", // someword1 = someword1 and Someword1
"Someword2", // Someword2 = Someword2
"some(w|W)ord[23]", // some(w|W)ord[23] = some(w|W)ord[23] and Some(w|W)ord[23]
"Some(w|W)ord" // Some(w|W)ord = Some(w|W)ord
],

@@ -178,0 +182,0 @@ "ignoreTags": ["code", "script"],

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