Comparing version 4.0.0 to 4.0.1
# Changelog | ||
## 4.0.1 | ||
- Fixed error handling for Yandex.Speller API #83, #84. | ||
- Updated deps in package.json. | ||
## 4.0.0 | ||
@@ -4,0 +8,0 @@ - Add --init CLI option #77 |
@@ -52,3 +52,3 @@ 'use strict'; | ||
* | ||
* @return {Array} | ||
* @returns {Array} | ||
*/ | ||
@@ -63,3 +63,3 @@ get() { | ||
* @param {string} file - JSON file. | ||
* @return {Array} | ||
* @returns {Array} | ||
*/ | ||
@@ -75,3 +75,3 @@ loadDictionary(file) { | ||
printDebug('Use dictionary: ' + file); | ||
} catch(e) { | ||
} catch (e) { | ||
console.error(chalk.red(e)); | ||
@@ -87,3 +87,4 @@ process.exit(exitCodes.ERROR_DICTIONARY); | ||
* @param {string[]} words | ||
* @return {boolean} | ||
* @param {string} title | ||
* @returns {boolean} | ||
*/ | ||
@@ -105,3 +106,3 @@ checkDuplicates(words, title) { | ||
* @param {string} file | ||
* @return {boolean} | ||
* @returns {boolean} | ||
*/ | ||
@@ -132,3 +133,3 @@ checkTyposInDictionary(words, file) { | ||
* @param {Object[]} data - Array of typos. | ||
* @return {Object[]} | ||
* @returns {Object[]} | ||
*/ | ||
@@ -140,3 +141,4 @@ removeDictWords(data) { | ||
data.forEach(function(typo) { | ||
if ((typo.code !== 1 && typo.code !== 3) || this.isTypo(typo.word, dictionary)) { | ||
// ERROR_TOO_MANY_ERRORS = 4 | ||
if (typo.code === 4 || this.isTypo(typo.word, dictionary)) { | ||
result.push(typo); | ||
@@ -153,3 +155,3 @@ } | ||
* @param {string[]|RegExp[]} dictionary | ||
* @return {boolean} | ||
* @returns {boolean} | ||
*/ | ||
@@ -165,3 +167,3 @@ isTypo(word, dictionary) { | ||
* @param {string[]} dict | ||
* @return {Array} | ||
* @returns {Array} | ||
*/ | ||
@@ -182,3 +184,3 @@ prepareDictionary(dict) { | ||
result.push(new RegExp(preparedWord)); | ||
} catch(e) { | ||
} catch (e) { | ||
console.error(chalk.red('Incorrect dictionary RegExp in "' + word + '", ' + e)); | ||
@@ -194,3 +196,3 @@ } | ||
* @param {string} text | ||
* @return {boolean} | ||
* @returns {boolean} | ||
*/ | ||
@@ -212,3 +214,3 @@ isNotOptimizedRegExp(text) { | ||
* @param {string[]} words | ||
* @return {string[]} | ||
* @returns {string[]} | ||
*/ | ||
@@ -234,3 +236,3 @@ getDuplicates(words) { | ||
* @param {string} symbol | ||
* @return {boolean} | ||
* @returns {boolean} | ||
*/ | ||
@@ -244,3 +246,3 @@ isLetter(symbol) { | ||
* @param {string} letter | ||
* @return {boolean} | ||
* @returns {boolean} | ||
*/ | ||
@@ -254,3 +256,3 @@ isUpperCase(letter) { | ||
* @param {string} letter | ||
* @return {boolean} | ||
* @returns {boolean} | ||
*/ | ||
@@ -257,0 +259,0 @@ isLowerCase(letter) { |
@@ -8,3 +8,3 @@ 'use strict'; | ||
* @param {string} text | ||
* @return {boolean} | ||
* @returns {boolean} | ||
*/ | ||
@@ -18,3 +18,3 @@ isHTML(text) { | ||
* @param {string} text | ||
* @return {boolean} | ||
* @returns {boolean} | ||
*/ | ||
@@ -34,3 +34,3 @@ isMarkdown(text) { | ||
* @param {Object} settings | ||
* @return {string} | ||
* @returns {string} | ||
*/ | ||
@@ -72,3 +72,3 @@ getFormat(text, settings) { | ||
* @param {string} format | ||
* @return {string} | ||
* @returns {string} | ||
*/ | ||
@@ -75,0 +75,0 @@ getApiFormat(format) { |
@@ -10,3 +10,3 @@ 'use strict'; | ||
* @param {string} text | ||
* @return {boolean} | ||
* @returns {boolean} | ||
*/ | ||
@@ -20,3 +20,3 @@ hasIgnoredText(text) { | ||
* @param {string} text | ||
* @return {text} | ||
* @returns {text} | ||
*/ | ||
@@ -33,3 +33,3 @@ lines(text) { | ||
* @param {string} text | ||
* @return {text} | ||
* @returns {text} | ||
*/ | ||
@@ -46,3 +46,3 @@ blocks(text) { | ||
* @param {string} text | ||
* @return {text} | ||
* @returns {text} | ||
*/ | ||
@@ -70,3 +70,3 @@ comments(text) { | ||
* @param {Array} tags | ||
* @return {text} | ||
* @returns {text} | ||
*/ | ||
@@ -91,3 +91,3 @@ tags(text, tags) { | ||
* | ||
* @return {Array} | ||
* @returns {Array} | ||
*/ | ||
@@ -110,3 +110,3 @@ prepareRegExpToIgnoreText(data) { | ||
} | ||
} catch(e) { | ||
} catch (e) { | ||
console.error(chalk.red('Error in RegExp "' + re.toString() + '": ' + e)); | ||
@@ -113,0 +113,0 @@ } |
@@ -27,3 +27,3 @@ 'use strict'; | ||
reports.push(require(moduleName)); | ||
} catch(e) { | ||
} catch (e) { | ||
console.error(chalk.red('Can\'t load report module "' + moduleName + '".')); | ||
@@ -30,0 +30,0 @@ console.error(chalk.red(e)); |
@@ -51,3 +51,3 @@ 'use strict'; | ||
if (utils.hasManyErrors(data.data)) { | ||
errors.push(chalk.red('Too many errors')); | ||
errors.push(chalk.red('Too many errors\n')); | ||
} | ||
@@ -54,0 +54,0 @@ |
@@ -42,3 +42,3 @@ 'use strict'; | ||
console.log(chalk.cyan('JSON dictionary with typos: ./' + this.filename)); | ||
} catch(e) { | ||
} catch (e) { | ||
console.error(chalk.red(e)); | ||
@@ -45,0 +45,0 @@ } |
@@ -125,3 +125,3 @@ 'use strict'; | ||
console.log(chalk.cyan('HTML report: ./' + this.filename)); | ||
} catch(e) { | ||
} catch (e) { | ||
console.error(chalk.red(e)); | ||
@@ -128,0 +128,0 @@ } |
@@ -12,3 +12,3 @@ 'use strict'; | ||
console.log(chalk.cyan('JSON report: ./' + this.filename)); | ||
} catch(e) { | ||
} catch (e) { | ||
console.error(chalk.red(e)); | ||
@@ -15,0 +15,0 @@ } |
@@ -54,3 +54,3 @@ 'use strict'; | ||
buf.push('|' + (i + 1)); | ||
buf.push('|`' + escape(el.word) + '`' + (el.count > 1 ? ' <sup>' + el.count + '</sup>': '')); | ||
buf.push('|`' + escape(el.word) + '`' + (el.count > 1 ? ' <sup>' + el.count + '</sup>' : '')); | ||
buf.push('|' + (pos.length ? pos[0].line + ':' + pos[0].column : ' ')); | ||
@@ -81,3 +81,3 @@ buf.push('|' + suggest); | ||
console.log(chalk.cyan('Markdown report: ./' + this.filename)); | ||
} catch(e) { | ||
} catch (e) { | ||
console.error(chalk.red(e)); | ||
@@ -84,0 +84,0 @@ } |
@@ -24,6 +24,6 @@ 'use strict'; | ||
yaspeller.sortByPositions(data.data); | ||
} | ||
if (!process.exitCode && hasData(err, data)) { | ||
process.exitCode = exitCodes.HAS_TYPOS; | ||
if (!process.exitCode) { | ||
process.exitCode = exitCodes.HAS_TYPOS; | ||
} | ||
} | ||
@@ -43,3 +43,3 @@ | ||
* @param {string[]} args | ||
* @return {string[]} | ||
* @returns {string[]} | ||
*/ | ||
@@ -67,3 +67,3 @@ expandGlobArgs(args) { | ||
* @param {Object} settings | ||
* @return {Array} | ||
* @returns {Array} | ||
*/ | ||
@@ -89,3 +89,3 @@ forResources(resources, settings) { | ||
* @param {string} [filename] | ||
* @return {Array} | ||
* @returns {Array} | ||
*/ | ||
@@ -92,0 +92,0 @@ forStdin(settings, filename) { |
@@ -19,3 +19,3 @@ 'use strict'; | ||
* @param {string} path | ||
* @return {boolean} | ||
* @returns {boolean} | ||
*/ | ||
@@ -29,3 +29,3 @@ isDir(path) { | ||
* @param {string} file | ||
* @return {Object} | ||
* @returns {Object} | ||
*/ | ||
@@ -48,3 +48,3 @@ getConfig(file) { | ||
printDebug('Using config: ' + file); | ||
} catch(e) { | ||
} catch (e) { | ||
console.error(chalk.red(e)); | ||
@@ -61,3 +61,3 @@ process.exit(exitCodes.ERROR_CONFIG); | ||
* @param {boolean} [throwIfFileNotExists] | ||
* @return {*} | ||
* @returns {*} | ||
*/ | ||
@@ -74,3 +74,3 @@ loadFileAsJson(file, throwIfFileNotExists) { | ||
data = require(pth.resolve(file)); | ||
} catch(e) { | ||
} catch (e) { | ||
throw new Error(e); | ||
@@ -82,3 +82,3 @@ } | ||
data = JSON.parse(json); | ||
} catch(e) { | ||
} catch (e) { | ||
throw new Error('Error parsing in the file: ' + file); | ||
@@ -102,3 +102,3 @@ } | ||
* @param {string[]} excludeFiles | ||
* @return {Object[]} | ||
* @returns {Object[]} | ||
*/ | ||
@@ -133,4 +133,3 @@ findFiles(dir, fileExtensions, excludeFiles) { | ||
* @param {string[]} fileExtensions | ||
* | ||
* @return {boolean} | ||
* @returns {boolean} | ||
*/ | ||
@@ -146,4 +145,3 @@ isReqFileExtension(file, fileExtensions) { | ||
* @param {string[]} excludeFiles | ||
* | ||
* @return {boolean} | ||
* @returns {boolean} | ||
*/ | ||
@@ -157,4 +155,3 @@ isExcludedFile(file, excludeFiles) { | ||
* @param {string} text | ||
* | ||
* @return {boolean} | ||
* @returns {boolean} | ||
*/ | ||
@@ -168,4 +165,3 @@ hasEnRu(text) { | ||
* @param {string} word | ||
* | ||
* @return {string} | ||
* @returns {string} | ||
*/ | ||
@@ -179,4 +175,3 @@ replaceRu(word) { | ||
* @param {string} word | ||
* | ||
* @return {string} | ||
* @returns {string} | ||
*/ | ||
@@ -190,4 +185,3 @@ replaceEn(word) { | ||
* @param {string} path | ||
* | ||
* @return {boolean} | ||
* @returns {boolean} | ||
*/ | ||
@@ -201,4 +195,3 @@ isUrl(path) { | ||
* @param {string} path | ||
* | ||
* @return {boolean} | ||
* @returns {boolean} | ||
*/ | ||
@@ -213,4 +206,3 @@ isSitemap(path) { | ||
* @param {Array} data | ||
* | ||
* @return {Array} | ||
* @returns {Array} | ||
*/ | ||
@@ -233,4 +225,3 @@ getTyposByCode(code, data) { | ||
* @param {Array} data | ||
* | ||
* @return {boolean} | ||
* @returns {boolean} | ||
*/ | ||
@@ -242,4 +233,3 @@ hasManyErrors(data) { | ||
* Get uptime in sec. | ||
* | ||
* @return {string} | ||
* @returns {string} | ||
*/ | ||
@@ -251,5 +241,4 @@ uptime() { | ||
* Get a array with unique values. | ||
* | ||
* @param {Array} arr | ||
* @return {Array} | ||
* @returns {Array} | ||
*/ | ||
@@ -263,3 +252,3 @@ uniq(arr) { | ||
* @param {string} text | ||
* @return {string} | ||
* @returns {string} | ||
*/ | ||
@@ -266,0 +255,0 @@ kebabCase(text) { |
@@ -18,2 +18,3 @@ 'use strict'; | ||
const MAX_LEN_TEXT = 10000; // Max length of text for Yandex.Speller API | ||
const TOO_MANY_ERRORS = 4; | ||
@@ -103,3 +104,3 @@ function getMaxRequest(settings) { | ||
if (apiSettings.checkYo) { | ||
if (!buf.err && apiSettings.checkYo) { | ||
checkYo(text, buf.data); | ||
@@ -116,2 +117,3 @@ } | ||
code: 100, | ||
position: el.position, | ||
word: el.before, | ||
@@ -204,5 +206,5 @@ s: [el.after], | ||
callback( | ||
err, | ||
err ? data : {resource: file, data: data, time: Date.now() - startTime}, | ||
originalText | ||
err, | ||
err ? data : {resource: file, data: data, time: Date.now() - startTime}, | ||
originalText | ||
); | ||
@@ -235,25 +237,25 @@ }, settings); | ||
request.get({ | ||
method: 'GET', | ||
uri: url, | ||
gzip: true | ||
}, | ||
function(error, response, text) { | ||
if (error) { | ||
callback(true, error); | ||
return; | ||
} | ||
method: 'GET', | ||
uri: url, | ||
gzip: true | ||
}, | ||
function(error, response, text) { | ||
if (error) { | ||
callback(true, error); | ||
return; | ||
} | ||
if (response.statusCode !== 200) { | ||
callback(true, Error(url + ': returns status code is ' + response.statusCode)); | ||
return; | ||
} | ||
if (response.statusCode !== 200) { | ||
callback(true, Error(url + ': returns status code is ' + response.statusCode)); | ||
return; | ||
} | ||
const startTime = Date.now(); | ||
checkText(text, function(err, data, originalText) { | ||
callback( | ||
err, | ||
err ? data : {resource: url, data: data, time: Date.now() - startTime}, | ||
originalText | ||
); | ||
}, settings); | ||
const startTime = Date.now(); | ||
checkText(text, function(err, data, originalText) { | ||
callback( | ||
err, | ||
err ? data : {resource: url, data: data, time: Date.now() - startTime}, | ||
originalText | ||
); | ||
}, settings); | ||
}); | ||
@@ -337,2 +339,6 @@ } | ||
data.forEach(function(item) { | ||
if (item.position) { | ||
return; | ||
} | ||
const result = []; | ||
@@ -363,3 +369,3 @@ const letters = '[^a-zA-Zа-яА-ЯЁёҐґЄєІіЇї]'; | ||
* @param {Object[]} data - Array of typos. | ||
* @return {Object[]} | ||
* @returns {Object[]} | ||
*/ | ||
@@ -374,2 +380,3 @@ function removeDuplicates(data) { | ||
const s = el.s; | ||
const hasPosition = Array.isArray(el.position); | ||
@@ -384,5 +391,5 @@ if (!word) { | ||
obj[code][word] = { | ||
code: code, | ||
word: word, | ||
count: el.count || 0 | ||
code, | ||
word, | ||
count: el.count || 1, | ||
}; | ||
@@ -393,5 +400,15 @@ | ||
} | ||
if (hasPosition) { | ||
obj[code][word].position = el.position; | ||
} | ||
} else { | ||
const objWord = obj[code][word]; | ||
objWord.count += el.count || 1; | ||
if (hasPosition) { | ||
objWord.position = Array.isArray(objWord.position) ? | ||
objWord.position.concat(el.position) : | ||
el.position; | ||
} | ||
} | ||
obj[code][word].count++; | ||
}); | ||
@@ -495,3 +512,3 @@ | ||
return yaspellerApi.errorCodes.filter(function(el) { | ||
return el.code !== 4; | ||
return el.code !== TOO_MANY_ERRORS; | ||
}).map(function(el) { | ||
@@ -498,0 +515,0 @@ return { |
@@ -13,3 +13,3 @@ { | ||
"description": "Search tool typos in the text, files and websites", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"license": "MIT", | ||
@@ -37,3 +37,3 @@ "homepage": "https://github.com/hcodes/yaspeller", | ||
"async": "^2.5.0", | ||
"chalk": "^2.0.1", | ||
"chalk": "^2.3.0", | ||
"commander": "^2.11.0", | ||
@@ -46,15 +46,14 @@ "entities": "^1.1.1", | ||
"minimatch": "^3.0.4", | ||
"request": "^2.81.0", | ||
"showdown": "^1.7.1", | ||
"request": "^2.83.0", | ||
"showdown": "^1.8.1", | ||
"strip-json-comments": "^2.0.1", | ||
"xml2js": "^0.4.17", | ||
"yandex-speller": "^2.0.1" | ||
"xml2js": "^0.4.19", | ||
"yandex-speller": "^2.1.1" | ||
}, | ||
"devDependencies": { | ||
"chai": "~4.1.0", | ||
"eslint": "~4.6.1", | ||
"istanbul": "~0.4.5", | ||
"jscs": "~3.0.7", | ||
"mocha": "~3.5.0", | ||
"sinon": "~3.2.1" | ||
"chai": "^4.1.0", | ||
"eslint": "^4.10.0", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^4.0.1", | ||
"sinon": "^4.1.1" | ||
}, | ||
@@ -65,5 +64,4 @@ "engines": { | ||
"scripts": { | ||
"test": "npm run-script eslint && npm run-script jscs && npm run-script unit-test-coverage", | ||
"jscs": "./node_modules/.bin/jscs .", | ||
"eslint": "./node_modules/.bin/eslint .", | ||
"test": "npm run-script eslint && npm run-script unit-test-coverage", | ||
"eslint": "eslint .", | ||
"yaspeller": "node bin/yaspeller .", | ||
@@ -70,0 +68,0 @@ "unit-test": "./node_modules/.bin/mocha -u bdd -R spec --recursive test", |
Sorry, the diff of this file is not supported yet
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
73358
5
1930
Updatedchalk@^2.3.0
Updatedrequest@^2.83.0
Updatedshowdown@^1.8.1
Updatedxml2js@^0.4.19
Updatedyandex-speller@^2.1.1