Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
reducing the size of dependencies
Browse files Browse the repository at this point in the history
chalk -> picocolors
cosmiconfig -> lilconfig
markdown-it -> marked
parse-json -> secure-json-parse
  • Loading branch information
alchazov committed Oct 26, 2021
1 parent 48cd6a2 commit 7839f1a
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 286 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Ignore Internet addresses, email addresses and filenames.
Max count of requests in parallel.<br/>
Default: `2`.

#### `--no-colors`
#### `--no-color`
Clean output without colors.

#### `--only-errors`
Expand Down
2 changes: 1 addition & 1 deletion README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ JSON-褎邪泄谢 褋芯斜褋褌胁械薪薪芯谐芯 褋谢芯胁邪褉褟.
袨写薪芯胁褉械屑械薪薪芯械 泻芯谢懈褔械褋褌胁芯 蟹邪锌褉芯褋芯胁 泻 API Yandex.Speller.<br/>
袩芯 褍屑芯谢褔邪薪懈褞: `2`.

#### `--no-colors`
#### `--no-color`
袣芯薪褋芯谢褜薪褘泄 胁褘胁芯写 斜械蟹 褑胁械褌邪.

#### `--only-errors`
Expand Down
4 changes: 0 additions & 4 deletions lib/cli/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const async = require('async');
const chalk = require('chalk');
const program = require('commander');

const { cliActionInit } = require('./actions');
Expand All @@ -17,9 +16,6 @@ setCliOptions(defaultConfig);
program.parse(process.argv);

setDebugMode(program.debug);
if (!program.colors) {
chalk.level = 0;
}

const mergedOptions = getMergedOptions(program.config);

Expand Down
2 changes: 1 addition & 1 deletion lib/cli/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function setCliOptions(defaultConfig) {
.option('-e, --file-extensions <value>', 'set file extensions to search for files in a folder. Example: ".md,.html"', splitByCommas)
.option('--init', 'save default config ".yaspellerrc" in current directory')
.option('--dictionary <file>', 'json file for own dictionary', value => splitTrim(value, ':'))
.option('--no-colors', 'clean output without colors')
.option('--no-color', 'clean output without colors')
.option('--report <type>', 'generate a report: console, text, html or json. Default: "console"', splitByCommas)
.option('--ignore-tags <tags>', `ignore tags. Default: "${defaultConfig.ignoreTags.join(',')}"`, splitByCommas)
.option('--ignore-text <regexp>', 'ignore text using RegExp')
Expand Down
8 changes: 4 additions & 4 deletions lib/config/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

const cosmiconfig = require('cosmiconfig').cosmiconfigSync;
const lilconfig = require('lilconfig').lilconfigSync;
const stripJsonComments = require('strip-json-comments');
const parseJson = require('parse-json');
const sjson = require('secure-json-parse');
const path = require('path');

const exitCodes = require('../exit-codes');
Expand All @@ -12,7 +12,7 @@ const defaultConfig = require('../../.yaspellerrc.default.json');

function loadJson(filepath, content) {
try {
return parseJson(stripJsonComments(content));
return sjson.parse(stripJsonComments(content));
} catch (err) {
err.message = `JSON Error in ${filepath}:\n${err.message}`;
throw err;
Expand All @@ -30,7 +30,7 @@ function getType(value) {
* @returns {Object}
*/
function getConfig(file) {
const explorer = cosmiconfig('yaspeller', {
const explorer = lilconfig('yaspeller', {
loaders: {
'.json': loadJson,
noExt: loadJson
Expand Down
14 changes: 7 additions & 7 deletions lib/helpers/console.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

const chalk = require('chalk');
const pico = require('picocolors');

const { jsonStringify } = require('./string');
const { isDebugMode } = require('./debug');
Expand All @@ -9,19 +9,19 @@ function consoleLog(data) {
}

function consoleInfo(data) {
console.info(chalk.cyan(data));
console.info(pico.cyan(data));
}

function consoleWarn(data) {
console.warn(chalk.yellow(data));
console.warn(pico.yellow(data));
}

function consoleError(data) {
console.error(chalk.red(data));
console.error(pico.red(data));
}

function consoleOk(data) {
console.log(chalk.green(data));
console.log(pico.green(data));
}

/**
Expand All @@ -31,12 +31,12 @@ function consoleOk(data) {
*/
function consoleDebug(text) {
if (isDebugMode()) {
const prefix = chalk.cyan('[DEBUG]');
const prefix = pico.cyan('[DEBUG]');
if (typeof text === 'object' && text) {
console.log(prefix);

Object.keys(text).forEach(key => {
console.log(chalk.cyan(' ' + key + ': ') + jsonStringify(text[key]));
console.log(pico.cyan(' ' + key + ': ') + jsonStringify(text[key]));
});
} else {
console.log(prefix + ' ' + text);
Expand Down
26 changes: 13 additions & 13 deletions lib/reports/console.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const chalk = require('chalk');
const pico = require('picocolors');
const program = require('commander');

const yaspeller = require('../yaspeller');
Expand Down Expand Up @@ -36,20 +36,20 @@ function getTyposByCode(code, data) {
const pos = el.position;

if (pos.length) {
comment.push(chalk.cyan(pos[0].line + ':' + pos[0].column));
comment.push(pico.cyan(pos[0].line + ':' + pos[0].column));
}

if (el.count > 1) {
comment.push(chalk.cyan('count: ' + el.count));
comment.push(pico.cyan('count: ' + el.count));
}

if (hasEngRusLetters(el.word)) {
comment.push(chalk.red('en: ' + replaceRusLettersWithAsterisk(el.word)));
comment.push(chalk.green('ru: ' + replaceEngLettersWithAsterisk(el.word)));
comment.push(pico.red('en: ' + replaceRusLettersWithAsterisk(el.word)));
comment.push(pico.green('ru: ' + replaceEngLettersWithAsterisk(el.word)));
}

if (el.suggest) {
comment.push(chalk.cyan('suggest: ' + el.suggest.join(', ')));
comment.push(pico.cyan('suggest: ' + el.suggest.join(', ')));
}

typos.push(num + '. ' + el.word + (comment.length ? ' (' + comment.join(', ') + ')' : ''));
Expand All @@ -70,32 +70,32 @@ module.exports = {
consoleError(data);
} else {
if (hasManyErrors(data.data)) {
errors.push(chalk.red('Too many errors\n'));
errors.push(pico.red('Too many errors\n'));
}

yaspeller.errors.forEach(function(el) {
const typos = getTyposByCode(el.code, data.data);
if (typos.length) {
errors.push(chalk.red(el.title + ': ' +
errors.push(pico.red(el.title + ': ' +
typos.length + '\n') +
typos.join('\n') + '\n');
}
});

const time = data.time ? ' ' + chalk.magenta(data.time + ' ms') : '';
const separator = chalk.red('-----\n');
const time = data.time ? ' ' + pico.magenta(data.time + ' ms') : '';
const separator = pico.red('-----\n');

let res = data.resource;

if (isUrl(res)) {
res = chalk.underline(res);
res = pico.underline(res);
}

if (errors.length) {
console.error(chalk.red(errorSymbol) + ' ' + res + time + '\n' +
console.error(pico.red(errorSymbol) + ' ' + res + time + '\n' +
separator + errors.join('\n') + separator);
} else {
console.log(chalk.green(okSymbol) + ' ' + res + time);
console.log(pico.green(okSymbol) + ' ' + res + time);
}
}
},
Expand Down
5 changes: 2 additions & 3 deletions lib/yaspeller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ const fetch = require('node-fetch');
const pth = require('path');
const xml2js = require('xml2js');
const yaspellerApi = require('yandex-speller');
const MarkdownIt = require('markdown-it');
const md = new MarkdownIt({ html: true });
const marked = require('marked');

const eyo = require('./plugins/eyo');
const { getFormat, getApiFormat } = require('./helpers/format');
Expand Down Expand Up @@ -63,7 +62,7 @@ function checkText(originalText, callback, settings) {

if (format === 'html' || format === 'markdown') {
if (format === 'markdown') {
text = md.render(text);
text = marked(text);
}

if (apiSettings.ignoreTags) {
Expand Down

0 comments on commit 7839f1a

Please sign in to comment.