Socket
Socket
Sign inDemoInstall

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.3.0 to 2.4.0

lib/format.js

6

CHANGELOG.md
# Changelog
## 2.4.0
- Ability to ignore text when checking
### Bug fixes
- Fix JSON comments in dictionaries and configs
## 2.3.0

@@ -4,0 +10,0 @@ - JSON comments in dictionaries and configs #35

2

lib/dictionary.js

@@ -47,3 +47,3 @@ var chalk = require('chalk'),

try {
data = utils.loadJsonFile(file, true);
data = utils.loadFileAsJson(file, true);

@@ -50,0 +50,0 @@ printDebug('Use dictionary: ' + file);

@@ -35,7 +35,7 @@ var chalk = require('chalk'),

if(file) {
data = this.loadJsonFile(file);
data = this.loadFileAsJson(file);
} else {
data = this.loadJsonFile('./.yaspellerrc');
data = this.loadFileAsJson('./.yaspellerrc');
if(!data) {
data = this.loadJsonFile('./.yaspeller.json');
data = this.loadFileAsJson('./.yaspeller.json');
}

@@ -53,3 +53,3 @@ }

/**
* Load JSON file with comments.
* Load file as JSON with comments.
*

@@ -60,20 +60,25 @@ * @param {string} file

*/
loadJsonFile: function(file, throwIfFileNotExists) {
loadFileAsJson: function(file, throwIfFileNotExists) {
var data;
if(fs.existsSync(file)) {
try {
var json = fs.readFileSync(file);
if(isutf8(json)) {
json = json.toString('utf-8');
if(['.js', '.json'].indexOf(pth.extname(file)) !== -1) {
var json = fs.readFileSync(file);
if(isutf8(json)) {
json = json.toString('utf-8');
if(pth.extname(file) === '.js') {
try {
data = require(pth.resolve(file));
} catch(e) {
throw new Error(e);
}
} else {
try {
json = stripJsonComments(json);
data = JSON.parse(json);
} catch(e) {
throw new Error('Error parsing in the file: ' + file);
}
data = JSON.parse(json);
} else {
throw new Error(file + ': is not utf-8.');
}
} catch(e) {
throw new Error('Error parsing in the file: ' + file);
} else {
throw new Error(file + ': is not utf-8.');
}

@@ -80,0 +85,0 @@ } else if(throwIfFileNotExists) {

@@ -6,2 +6,4 @@ /* jshint maxlen: 300 */

fs = require('fs'),
formatModule = require('./format'),
ignore = require('./ignore'),
isutf8 = require('isutf8'),

@@ -18,53 +20,2 @@ request = require('request'),

function isHTML(text) {
return text.search(/<[a-z!]/i) !== -1;
}
function isMarkdown(text) {
return [
/^===/m,
/^\s{0,5}```/m,
/-- ?:?\|/,
/\)\[(https?|mailto):/
].some(function(el) {
return text.search(el) !== -1;
});
}
function getFormat(text, settings) {
var format = settings.format,
extname = (settings.extname || '').toLowerCase(),
extnames = {
'.htm': 'html',
'.html': 'html',
'.xhtml': 'html',
'.xml': 'html',
'.svg': 'html',
'.markdown': 'markdown',
'.md': 'markdown'
};
if(['html', 'markdown', 'plain'].indexOf(format) !== -1) {
return format;
}
if(format === 'auto' || !format) {
if(extnames[extname]) {
return extnames[extname];
}
if(isMarkdown(text)) {
return 'markdown';
} else if(isHTML(text)) {
return 'html';
}
}
return 'plain';
}
function getApiFormat(format) {
return format === 'html' || format === 'markdown' ? 'html' : 'plain';
}
function getOptions(options) {

@@ -104,33 +55,2 @@ var result = 0,

function ignoreComments(text) {
var comments = [
['<!--', '-->'],
['<!ENTITY', '>'],
['<!DOCTYPE', '>'],
['<\\?xml', '\\?>'],
['<!\\[CDATA\\[', '\\]\\]>']
];
comments.forEach(function(tag) {
var re = new RegExp(tag[0] + '[^]*?' + tag[1], 'gi');
text = text.replace(re, ' ');
});
return text;
}
function ignoreTags(text, tags) {
var bufTags = [];
tags.forEach(function(tag) {
bufTags.push(['<' + tag + '(\\s[^>]*?)?>', '</' + tag + '>']);
}, this);
bufTags.forEach(function(tag) {
var re = new RegExp(tag[0] + '[^]*?' + tag[1], 'gi');
text = text.replace(re, ' ');
});
return text;
}
function getMaxRequest(settings) {

@@ -168,6 +88,15 @@ return settings.maxRequest || 2;

var format = getFormat(text, settings),
var format = formatModule.getFormat(text, settings),
options = getOptions(settings.options),
lang = settings.lang || 'en,ru';
if(Array.isArray(lang)) {
lang = lang.join(',');
}
if(ignore.hasIgnoredText(text)) {
text = ignore.lines(text);
text = ignore.blocks(text);
}
if(format === 'html' || format === 'markdown') {

@@ -179,6 +108,6 @@ if(format === 'markdown') {

if(settings.ignoreTags) {
text = ignoreTags(text, settings.ignoreTags);
text = ignore.tags(text, settings.ignoreTags);
}
text = ignoreComments(text);
text = ignore.comments(text);
text = stripTags(text);

@@ -190,9 +119,5 @@ text = entities.decodeHTML(text);

if(Array.isArray(lang)) {
lang = lang.join(',');
}
var tasks = [],
texts = splitText(text),
apiFormat = getApiFormat(format);
apiFormat = formatModule.getApiFormat(format);

@@ -199,0 +124,0 @@ texts.forEach(function(el, i) {

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

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

@@ -16,0 +16,0 @@ "homepage": "https://github.com/hcodes/yaspeller",

@@ -60,3 +60,3 @@ yaspeller

[
"someword1",
"someword1", // JSON comments
"/(S|s)omeword2/",

@@ -156,3 +156,3 @@ "/someword3/i"

**Advanced example:**
```JSON
```js
{

@@ -174,3 +174,3 @@ "excludeFiles": [

"dictionary": [
"someword1",
"someword1", // JSON comments
"/(S|s)omeword2/"

@@ -206,2 +206,29 @@ ],

## Ignore text from checking
### Ignore a line
```js
var re = /a-z/; // yaspeller ignore
```
```js
var re = /a-z/; /* yaspeller ignore */
```
```html
<span>a-z</span> <!-- yaspeller ignore -->
```
### Ignore a block
```js
/* yaspeller ignore:start */
var reUpper = /A-Z/,
reLower = /a-z/;
/* yaspeller ignore:end */
```
```html
<!-- yaspeller ignore:start -->
<span>A-Z</span>
<div>a-z</div>
<!-- yaspeller ignore:end -->
```
## [Gulp](http://gulpjs.com) plugin

@@ -208,0 +235,0 @@ ```js

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