chalk
Advanced tools
Comparing version 0.5.0 to 0.5.1
33
index.js
@@ -10,2 +10,13 @@ 'use strict'; | ||
function build(_styles) { | ||
var builder = function builder() { | ||
return applyStyle.apply(builder, arguments); | ||
}; | ||
builder._styles = _styles; | ||
// __proto__ is used because we must return a function, but there is | ||
// no way to create a function with a different prototype. | ||
builder.__proto__ = proto; | ||
return builder; | ||
} | ||
var styles = (function () { | ||
@@ -21,4 +32,3 @@ var ret = {}; | ||
get: function () { | ||
this._styles.push(key); | ||
return this; | ||
return build(this._styles.concat(key)); | ||
} | ||
@@ -31,5 +41,15 @@ }; | ||
var proto = defineProps(function chalk() {}, styles); | ||
function applyStyle() { | ||
// support varags, but simply cast to string in case there's only one arg | ||
var str = arguments.length === 1 ? String(arguments[0]) : [].slice.call(arguments).join(' '); | ||
var args = arguments; | ||
var argsLen = args.length; | ||
var str = argsLen !== 0 && String(arguments[0]); | ||
if (argsLen > 1) { | ||
// don't slice `arguments`, it prevents v8 optimizations | ||
for (var a = 1; a < argsLen; a++) { | ||
str += ' ' + args[a]; | ||
} | ||
} | ||
@@ -40,3 +60,4 @@ if (!chalk.enabled || !str) { | ||
var nestedStyles = applyStyle._styles; | ||
/*jshint validthis: true*/ | ||
var nestedStyles = this._styles; | ||
@@ -58,7 +79,5 @@ for (var i = 0; i < nestedStyles.length; i++) { | ||
Object.keys(styles).forEach(function (name) { | ||
var style = defineProps(applyStyle, styles); | ||
ret[name] = { | ||
get: function () { | ||
style._styles = []; | ||
return style[name]; | ||
return build([name]); | ||
} | ||
@@ -65,0 +84,0 @@ }; |
{ | ||
"name": "chalk", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "Terminal string styling done right. Created because the `colors` module does some really horrible things.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
7589
77
1