Skip to content

Commit

Permalink
style: update after linter change
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Aug 20, 2018
1 parent fb2df54 commit 76396ce
Show file tree
Hide file tree
Showing 40 changed files with 602 additions and 600 deletions.
10 changes: 5 additions & 5 deletions art.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';
"use strict";

var object = require('es5-ext/object/valid-object')
, stringifiable = require('es5-ext/object/validate-stringifiable-value')
, forOf = require('es6-iterator/for-of');
var object = require("es5-ext/object/valid-object")
, stringifiable = require("es5-ext/object/validate-stringifiable-value")
, forOf = require("es6-iterator/for-of");

module.exports = function (text, style) {
var result = '';
var result = "";
text = stringifiable(text);
object(style);
forOf(text, function (char) { result += style[char] || char; });
Expand Down
46 changes: 23 additions & 23 deletions bare.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
'use strict';
"use strict";

var d = require('d')
, assign = require('es5-ext/object/assign')
, forEach = require('es5-ext/object/for-each')
, map = require('es5-ext/object/map')
, primitiveSet = require('es5-ext/object/primitive-set')
, setPrototypeOf = require('es5-ext/object/set-prototype-of')
, memoize = require('memoizee')
, memoizeMethods = require('memoizee/methods')
var d = require("d")
, assign = require("es5-ext/object/assign")
, forEach = require("es5-ext/object/for-each")
, map = require("es5-ext/object/map")
, primitiveSet = require("es5-ext/object/primitive-set")
, setPrototypeOf = require("es5-ext/object/set-prototype-of")
, memoize = require("memoizee")
, memoizeMethods = require("memoizee/methods")

, sgr = require('./lib/sgr')
, sgr = require("./lib/sgr")
, mods = sgr.mods

, join = Array.prototype.join, defineProperty = Object.defineProperty
, max = Math.max, min = Math.min
, variantModes = primitiveSet('_fg', '_bg')
, variantModes = primitiveSet("_fg", "_bg")
, xtermMatch, getFn;

// Some use cli-color as: console.log(clc.red('Error!'));
// Which is inefficient as on each call it configures new clc object
// with memoization we reuse once created object
var memoized = memoize(function (scope, mod) {
return defineProperty(getFn(), '_cliColorData', d(assign({}, scope._cliColorData, mod)));
return defineProperty(getFn(), "_cliColorData", d(assign({}, scope._cliColorData, mod)));
});

var proto = Object.create(Function.prototype, assign(map(mods, function (mod) {
Expand All @@ -30,35 +30,35 @@ var proto = Object.create(Function.prototype, assign(map(mods, function (mod) {
// xterm (255) color
xterm: d(function (code) {
code = isNaN(code) ? 255 : min(max(code, 0), 255);
return defineProperty(getFn(), '_cliColorData',
return defineProperty(getFn(), "_cliColorData",
d(assign({}, this._cliColorData, {
_fg: [xtermMatch ? xtermMatch[code] : ('38;5;' + code), 39]
_fg: [xtermMatch ? xtermMatch[code] : "38;5;" + code, 39]
})));
}),
bgXterm: d(function (code) {
code = isNaN(code) ? 255 : min(max(code, 0), 255);
return defineProperty(getFn(), '_cliColorData',
return defineProperty(getFn(), "_cliColorData",
d(assign({}, this._cliColorData, {
_bg: [xtermMatch ? (xtermMatch[code] + 10) : ('48;5;' + code), 49]
_bg: [xtermMatch ? xtermMatch[code] + 10 : "48;5;" + code, 49]
})));
})
})));

var getEndRe = memoize(function (code) {
return new RegExp('\x1b\\[' + code + 'm', 'g');
return new RegExp("\x1b\\[" + code + "m", "g");
}, { primitive: true });

if (process.platform === 'win32') xtermMatch = require('./lib/xterm-match');
if (process.platform === "win32") xtermMatch = require("./lib/xterm-match");

getFn = function () {
return setPrototypeOf(function self(/*…msg*/) {
var start = '', end = '', msg = join.call(arguments, ' '), conf = self._cliColorData
return setPrototypeOf(function self(/* …msg*/) {
var start = "", end = "", msg = join.call(arguments, " "), conf = self._cliColorData
, hasAnsi = sgr.hasCSI(msg);
forEach(conf, function (mod, key) {
end = sgr(mod[1]) + end;
end = sgr(mod[1]) + end;
start += sgr(mod[0]);
if (hasAnsi) {
msg = msg.replace(getEndRe(mod[1]), variantModes[key] ? sgr(mod[0]) : '');
msg = msg.replace(getEndRe(mod[1]), variantModes[key] ? sgr(mod[0]) : "");
}
}, null, true);
return start + msg + end;
Expand All @@ -67,5 +67,5 @@ getFn = function () {

module.exports = Object.defineProperties(getFn(), {
xtermSupported: d(!xtermMatch),
_cliColorData: d('', {})
_cliColorData: d("", {})
});
4 changes: 2 additions & 2 deletions beep.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
'use strict';
"use strict";

module.exports = '\x07';
module.exports = "\x07";
14 changes: 7 additions & 7 deletions erase.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';
"use strict";

module.exports = {
screen: '\x1b[2J',
screenLeft: '\x1b[1J',
screenRight: '\x1b[J',
line: '\x1b[2K',
lineLeft: '\x1b[1K',
lineRight: '\x1b[K'
screen: "\x1b[2J",
screenLeft: "\x1b[1J",
screenRight: "\x1b[J",
line: "\x1b[2K",
lineLeft: "\x1b[1K",
lineRight: "\x1b[K"
};
6 changes: 3 additions & 3 deletions examples/art.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';
"use strict";

var clc = require('../');
var clc = require("../");

var text = '.........\n' + '. Hello .\n' + '.........\n';
var text = ".........\n" + ". Hello .\n" + ".........\n";
var style = { ".": clc.yellowBright("X") };

process.stdout.write(clc.art(text, style));
28 changes: 14 additions & 14 deletions examples/basic.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
'use strict';
"use strict";

var clc = require('../');
var clc = require("../");

console.log('Output colored text:');
console.log(clc.red('Text in red'));
console.log("Output colored text:");
console.log(clc.red("Text in red"));

console.log('Styles can be mixed:');
console.log(clc.red.bgWhite.underline('Underlined red text on white background.'));
console.log("Styles can be mixed:");
console.log(clc.red.bgWhite.underline("Underlined red text on white background."));

console.log('Styled text can be mixed with unstyled:');
console.log(clc.red('red') + ' plain ' + clc.blue('blue'));
console.log("Styled text can be mixed with unstyled:");
console.log(clc.red("red") + " plain " + clc.blue("blue"));

console.log('Styled text can be nested:');
console.log(clc.red('red ' + clc.blue('blue') + ' red'));
console.log("Styled text can be nested:");
console.log(clc.red("red " + clc.blue("blue") + " red"));

console.log('Best way is to predefine needed stylings and then use it:');
console.log("Best way is to predefine needed stylings and then use it:");

var error = clc.red.bold;
var warn = clc.yellow;
var notice = clc.blue;

console.log(error('Error!'));
console.log(warn('Warning'));
console.log(notice('Notice'));
console.log(error("Error!"));
console.log(warn("Warning"));
console.log(notice("Notice"));
12 changes: 6 additions & 6 deletions examples/erase.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
'use strict';
"use strict";

var clc = require('../');
var clc = require("../");

console.log('Erasing screen ..');
console.log("Erasing screen ..");

setTimeout(function () {
process.stdout.write(clc.erase.screen);

console.log('This a line of text that should not be cleared');
process.stdout.write('This line will be cleared but cursor will be here ->');
console.log("This a line of text that should not be cleared");
process.stdout.write("This line will be cleared but cursor will be here ->");

setTimeout(function () {
process.stdout.write(clc.erase.line);
process.stdout.write('\nMoving cursor backwards and deleting (from here): to the right');
process.stdout.write("\nMoving cursor backwards and deleting (from here): to the right");

setTimeout(function () {
process.stdout.write(clc.move(-13, 0));
Expand Down
16 changes: 8 additions & 8 deletions examples/styles.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';
"use strict";

var clc = require('../');
var clc = require("../");

console.log(clc.bold('Bold text'));
console.log(clc.italic('Italic text'));
console.log(clc.underline('Underlined text'));
console.log(clc.blink('Blinking text (might not work for your font)'));
console.log(clc.inverse('Inverse text'));
console.log(clc.strike('Strikethrough text'));
console.log(clc.bold("Bold text"));
console.log(clc.italic("Italic text"));
console.log(clc.underline("Underlined text"));
console.log(clc.blink("Blinking text (might not work for your font)"));
console.log(clc.inverse("Inverse text"));
console.log(clc.strike("Strikethrough text"));
6 changes: 3 additions & 3 deletions examples/throbber.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';
"use strict";

var setupThrobber = require('../throbber');
var setupThrobber = require("../throbber");

var throbber = setupThrobber(function (str) {
process.stdout.write(str);
}, 200);

process.stdout.write('Throbbing for 3 seconds here -> ');
process.stdout.write("Throbbing for 3 seconds here -> ");
throbber.start();

setTimeout(function () {
Expand Down
6 changes: 3 additions & 3 deletions examples/xterm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
"use strict";

var clc = require('../');
var clc = require("../");

var msg = clc.xterm(202).bgXterm(236);
console.log(msg('Orange text on dark gray background'));
console.log(msg("Orange text on dark gray background"));
5 changes: 3 additions & 2 deletions get-stripped-length.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict';
"use strict";

/*
* get actual length of ANSI-formatted string
*/

var strip = require('./strip');
var strip = require("./strip");

module.exports = function (str) {
return strip(str).length;
Expand Down
28 changes: 14 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
'use strict';
"use strict";

var d = require('d');
var d = require("d");

module.exports = Object.defineProperties(require('./bare'), {
windowSize: d(require('./window-size')),
erase: d(require('./erase')),
move: d(require('./move')),
beep: d(require('./beep')),
columns: d(require('./columns')),
strip: d(require('./strip')),
getStrippedLength: d(require('./get-stripped-length')),
slice: d(require('./slice')),
throbber: d(require('./throbber')),
reset: d(require('./reset')),
art: d(require('./art'))
module.exports = Object.defineProperties(require("./bare"), {
windowSize: d(require("./window-size")),
erase: d(require("./erase")),
move: d(require("./move")),
beep: d(require("./beep")),
columns: d(require("./columns")),
strip: d(require("./strip")),
getStrippedLength: d(require("./get-stripped-length")),
slice: d(require("./slice")),
throbber: d(require("./throbber")),
reset: d(require("./reset")),
art: d(require("./art"))
});
37 changes: 19 additions & 18 deletions lib/sgr.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
'use strict';
"use strict";

/* CSI - control sequence introducer */
/* SGR - set graphic rendition */

var assign = require('es5-ext/object/assign')
, includes = require('es5-ext/string/#/contains')
, forOwn = require('es5-ext/object/for-each')
, onlyKey = require('es5-ext/object/first-key')
, forEachRight = require('es5-ext/array/#/for-each-right')
, uniq = require('es5-ext/array/#/uniq.js');
var assign = require("es5-ext/object/assign")
, includes = require("es5-ext/string/#/contains")
, forOwn = require("es5-ext/object/for-each")
, onlyKey = require("es5-ext/object/first-key")
, forEachRight = require("es5-ext/array/#/for-each-right")
, uniq = require("es5-ext/array/#/uniq.js");

var CSI = '\x1b[';
var CSI = "\x1b[";

var sgr = function (code) {
return CSI + code + 'm';
return CSI + code + "m";
};

sgr.CSI = CSI;

var mods = assign({
// Style
bold: { _bold: [1, 22] },
italic: { _italic: [3, 23] },
bold: { _bold: [1, 22] },
italic: { _italic: [3, 23] },
underline: { _underline: [4, 24] },
blink: { _blink: [5, 25] },
inverse: { _inverse: [7, 27] },
strike: { _strike: [9, 29] }
blink: { _blink: [5, 25] },
inverse: { _inverse: [7, 27] },
strike: { _strike: [9, 29] }

// Color
}, ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white']
}, ["black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"]
.reduce(function (obj, color, index) {
// foreground
obj[color] = { _fg: [30 + index, 39] };
obj[color + 'Bright'] = { _fg: [90 + index, 39] };
obj[color + "Bright"] = { _fg: [90 + index, 39] };

// background
obj['bg' + color[0].toUpperCase() + color.slice(1)] = { _bg: [40 + index, 49] };
obj['bg' + color[0].toUpperCase() + color.slice(1) + 'Bright'] = { _bg: [100 + index, 49] };
obj["bg" + color[0].toUpperCase() + color.slice(1)] = { _bg: [40 + index, 49] };
obj["bg" + color[0].toUpperCase() + color.slice(1) + "Bright"] = { _bg: [100 + index, 49] };

return obj;
}, {}));
Expand Down
2 changes: 1 addition & 1 deletion lib/xterm-colors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
"use strict";

module.exports = [
"000000", "800000", "008000", "808000", "000080", "800080", "008080", "c0c0c0",
Expand Down
6 changes: 3 additions & 3 deletions lib/xterm-match.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';
"use strict";

var push = Array.prototype.push, reduce = Array.prototype.reduce, abs = Math.abs
, colors, match, result, i;

colors = require('./xterm-colors').map(function (color) {
colors = require("./xterm-colors").map(function (color) {
return {
r: parseInt(color.slice(0, 2), 16),
g: parseInt(color.slice(2, 4), 16),
Expand All @@ -26,7 +26,7 @@ while (i < 8) {
push.apply(result, colors.slice(16).map(function (data) {
var index, diff = Infinity;
match.every(function (match, i) {
var ndiff = reduce.call('rgb', function (diff, channel) {
var ndiff = reduce.call("rgb", function (diff, channel) {
diff += abs(match[channel] - data[channel]);
return diff;
}, 0);
Expand Down
Loading

0 comments on commit 76396ce

Please sign in to comment.