Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

badgee

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

badgee - npm Package Compare versions

Comparing version 2.0.0-beta to 2.0.0-beta-1

src/filter.js

345

build/badgee.es.js
var noop = function () {};
var extend = function (destObj) {
var args = [], len = arguments.length - 1;
while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ];
for (var i in args) {
var obj = args[i];
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
var val = obj[key];
destObj[key] = val;
}
}
var each = function (items, fn) {
for (var i in items) {
fn(items[i], i);
}
return destObj
};
var _extend = function (dest, obj) {
for (var i in obj) { dest[i] = obj[i]; }
return dest
};
var clone = function (obj) { return _extend({}, obj); };
var extend = function (dest, obj) { return _extend(clone(dest), obj); };
// Homogeneisation of the console API on different browsers
// - add compat console object if not available
// - some methods might not be defined. fake them with `noop` function
// - some "methods" might not be functions but properties (eg. profile & profileEnd in IE11)
var console = window.console || {};
var checkConsoleMethods = function (methodList) {
var ret = [];
for (var i in methodList) {
var method = methodList[i];
if (!console[method]) {
console[method] = noop;
ret.push(method);
} else if (typeof console[method] !== 'function') {
properties.push(method);
} else {
ret.push(method);
}
}
return ret;
};
// For the record, every single console methods and properties
// For the record, every single console methods and properties :
// ["memory", "exception", "debug", "error", "info", "log", "warn", "dir",

@@ -47,16 +27,17 @@ // "dirxml", "table", "trace", "assert", "count", "markTimeline", "profile",

// "group", "groupCollapsed", "groupEnd", "clear"]
var properties = [
'memory'
];
//
// Focus on logging methods and ignore profiling/timeline methods or less used methods
var methods = ['debug', 'error', 'group', 'groupCollapsed', 'info', 'log', 'warn'];
var unformatableMethods = ['clear', 'dir', 'groupEnd'];
var methods = checkConsoleMethods([
'debug', 'dirxml', 'error', 'group',
'groupCollapsed', 'info', 'log', 'warn'
]);
var eachFormatableMethod = function (fn) { each(methods, fn); };
var eachUnformatableMethod = function (fn) { each(unformatableMethods, fn); };
var eachMethod = function (fn) {
eachFormatableMethod(fn);
eachUnformatableMethod(fn);
};
var unformatableMethods = checkConsoleMethods([
'assert', 'clear', 'count', 'dir', 'exception', 'groupEnd', 'markTimeline',
'profile', 'profileEnd', 'table', 'trace', 'time', 'timeEnd', 'timeStamp',
'timeline', 'timelineEnd'
]);
eachMethod(function (method) {
console[method] = console[method] || noop;
});

@@ -69,8 +50,8 @@ // default configuration

var config = extend({}, defaults);
var config = clone(defaults);
var configure$1 = function(conf) {
var configure = function(conf) {
// update conf
if (typeof conf === 'object') {
config = extend({}, defaults, conf);
config = extend(defaults, conf);
}

@@ -82,31 +63,4 @@

var Store = function Store() {
this._store = {};
};
// Add object to store
Store.prototype.add = function add (name, obj) {
this._store[name] = obj;
};
// get obj from store
Store.prototype.get = function get (name) {
return this._store[name] || null
};
Store.prototype.list = function list () {
return Object.keys(this._store);
};
Store.prototype.each = function each (func) {
var this$1 = this;
for (var name in this$1._store) {
var obj = this$1._store[name];
func(name, obj);
}
};
// Create store to save styles
var store$1 = new Store;
var store$1 = {};

@@ -125,9 +79,9 @@ // Default properties for styles

if (name != null && style$1 != null) {
style$1 = extend({}, defaultsStyle, style$1);
store$1.add(name, style$1);
style$1 = extend(defaultsStyle, style$1);
store$1[name] = style$1;
}
else if (name != null) {
return store$1.get(name);
return store$1[name];
}
return store$1.list();
return Object.keys(store$1);
},

@@ -143,15 +97,7 @@

stringForStyle: function stringForStyle(name) {
var style = store$1.get(name);
return ((function () {
var result = [];
for (var k in style) {
var v = style[k];
var item = (void 0);
if (style.hasOwnProperty(k)) {
item = k + ":" + v + ";";
}
result.push(item);
}
return result;
})()).join('');
var res = [];
each(store$1[name], function (style, k) {
res.push((k + ":" + style + ";"));
});
return res.join('');
}

@@ -162,23 +108,9 @@ };

// define a few styles
var empty = {};
var black = {'color': 'black'};
styles.style('black', extend({}, {'background': 'black'}));
styles.style('blue', extend({}, {'background': 'blue'}));
styles.style('brown', extend({}, {'background': 'brown'}));
styles.style('gray', extend({}, {'background': 'gray'}));
styles.style('green', extend({}, {'background': 'green'}));
styles.style('purple', extend({}, {'background': 'purple'}));
styles.style('red', extend({}, {'background': 'red'}));
styles.style('cyan', extend({}, black, {'background': 'cyan'}));
styles.style('magenta', extend({}, black, {'background': 'magenta'}));
styles.style('orange', extend({}, black, {'background': 'orange'}));
styles.style('pink', extend({}, black, {'background': 'pink'}));
styles.style('yellow', extend({}, black, {'background': 'yellow'}));
styles.style('green', extend(empty, {'background': 'green'}));
styles.style('red', extend(empty, {'background': 'red'}));
styles.style('orange', extend(black, {'background': 'orange'}));
/* eslint-disable no-console */
/*! badgee v1.2.0 - MIT license */
var currentConf = configure$1();
var store = new Store;
var filter = {

@@ -189,10 +121,44 @@ include : null,

// concat foramted label for badges output
// (i.e. "%cbadge1%cbadge2" with style or "[badge1][badge2] without style")
var concatLabelToOutput = function(out, label, hasStyle){
if (out == null) { out = ''; }
if (hasStyle == null) { hasStyle = false; }
return ("" + out + (hasStyle ? '%c' : '[') + label + (!hasStyle ? ']' : ''));
};
function isFiltered(str) {
var isntIncluded = (filter.include != null) && !filter.include.test(str);
var isExcluded = (filter.exclude != null) && filter.exclude.test(str);
return isntIncluded || isExcluded
}
function getFilter(onFilterChange) {
return {
none: function none() {
filter.include = null;
filter.exclude = null;
onFilterChange();
return this;
},
include: function include(matcher) {
if ( matcher === void 0 ) matcher = null;
if (matcher !== filter.include) {
filter.include = matcher;
onFilterChange();
}
return this;
},
exclude: function exclude(matcher) {
if ( matcher === void 0 ) matcher = null;
if (matcher !== filter.exclude) {
filter.exclude = matcher;
onFilterChange();
}
return this;
}
};
}
/* eslint-disable no-console */
/*! badgee v1.2.0 - MIT license */
var store = {};
// Given a label, style and parentName, generate the full list of arguments to

@@ -203,5 +169,5 @@ // pass to console method to get a foramted output

if (!currentConf.styled) { style = false; }
if (!config.styled) { style = false; }
if (parentName) {
var parent = store.get(parentName);
var parent = store[parentName];
args = argsForBadgee(parent.badgee.label, parent.style, parent.parent);

@@ -211,3 +177,6 @@ }

if (label) {
args[0] = concatLabelToOutput(args[0], label, !!style);
// concat formated label for badges output
// (i.e. "%cbadge1%cbadge2" with style or "[badge1][badge2] without style")
var formatedLabel = !style ? ("[" + label + "]") : ("%c" + label);
args[0] = "" + (args[0] || '') + formatedLabel;
}

@@ -222,18 +191,2 @@

// Define empty Badgee methods
// Intended to be called in a 'Badgee' instance context (e.g. with 'bind()')
var _disable = function() {
var this$1 = this;
for (var i in methods) {
var method = methods[i];
this$1[method] = noop;
}
for (var i$1 in unformatableMethods) {
var method$1 = unformatableMethods[i$1];
this$1[method$1] = noop;
}
};
// Define Badgee methods form console object

@@ -244,39 +197,21 @@ // Intended to be called in a 'Badgee' instance context (e.g. with 'bind()')

// get arguments to pass to console object
var args = argsForBadgee(this.label, style, parentName);
if (!currentConf.enabled) {
return _disable.bind(this)();
} else {
// get arguments to pass to console object
var args = argsForBadgee(this.label, style, parentName);
if (!config.enabled || isFiltered(args[0])) {
// disable everything
eachMethod(function (method) { return this$1[method] = noop; });
return
}
// Reset style for FF :
// Defining a last style to an unknown property seems to reset to the default
// behavior on FF
if (style && (args.length > 1)) {
args[0] += '%c';
args.push('p:a');
}
// Define Badgee 'formatable' methods form console object
eachFormatableMethod(function (method) {
this$1[method] = (ref = console[method]).bind.apply(ref, [ console ].concat( args ));
var ref;
});
var isntInclusive = (filter.include != null) && !filter.include.test(args[0]);
var isExclusive = filter.exclude != null ? filter.exclude.test(args[0]) : undefined;
if (isntInclusive || isExclusive) {
_disable.bind(this)();
} else {
// Define Badgee 'formatable' methods form console object
for (var i in methods) {
var method = methods[i];
this$1[method] = (ref = console[method]).bind.apply(ref, [ console ].concat( Array.from(args) ));
}
// Define Badgee 'unformatable' methods form console object
for (var i$1 in unformatableMethods) {
var method$1 = unformatableMethods[i$1];
this$1[method$1] = console[method$1].bind(console);
}
}
// Define Badgee properties from console object
return properties.map(function (prop) { return (this$1[prop] = console[prop]); });
}
var ref;
// Define Badgee 'unformatable' methods form console object
eachUnformatableMethod(function (method) {
this$1[method] = console[method].bind(console);
});
};

@@ -292,7 +227,7 @@

// Store instance for later reference
store.add(this.label, {
store[this.label] = {
badgee: this,
style: style,
parent: parentName
});
};
};

@@ -307,47 +242,24 @@

var redefineMethodsForAllBadges = function () {
each(store, function (b) {
_defineMethods.bind(b.badgee, b.style, b.parent)();
});
};
// Create public Badgee instance
var b = new Badgee;
var redefineMethodsForAllBadges = function () { return store.each(function (label, b) { return _defineMethods.bind(b.badgee, b.style, b.parent)(); }); };
// Augment public instance with utility methods
b.style = styles.style;
b.style = styles.style;
b.defaultStyle = styles.defaults;
b.get = function (label) { return __guard__(store.get(label), function (x) { return x.badgee; }); };
b.filter = {
none: function none() {
filter = {
include : null,
exclude : null
};
redefineMethodsForAllBadges();
return b.filter;
},
b.get = function (label) { return (store[label] || {}).badgee; };
b.filter = getFilter(redefineMethodsForAllBadges);
include: function include(matcher) {
if (matcher == null) { matcher = null; }
if (matcher !== filter.include) {
filter.include = matcher;
redefineMethodsForAllBadges();
}
return b.filter;
},
exclude: function exclude(matcher) {
if (matcher == null) { matcher = null; }
if (matcher !== filter.exclude) {
filter.exclude = matcher;
redefineMethodsForAllBadges();
}
return b.filter;
}
};
b.config = function(conf) {
currentConf = configure$1(conf);
b.config = function(conf) {
// when conf is updated, redefine every badgee method
if (conf) {
configure(conf);
redefineMethodsForAllBadges();
}
return currentConf;
return config;
};

@@ -360,10 +272,10 @@

} catch (e) {
var fallback = console;
fallback.define = function () { return console; };
fallback.style = b.style;
fallback.styleDefaults = b.styleDefaults;
fallback.filter = b.filter;
fallback.get = function () { return console; };
fallback.config = function () { return b.config; };
b = fallback;
b = extend(console, {
define : function () { return b; },
style : b.style,
defaultStyle : b.defaultStyle,
filter : b.filter,
get : function () { return b; },
config : function () { return b.config; },
});
}

@@ -373,8 +285,3 @@

function __guard__(value, transform) {
return (typeof value !== 'undefined' && value !== null) ? transform(value) : undefined;
}
export default b$1;
//# sourceMappingURL=badgee.es.js.map

@@ -1,2 +0,2 @@

function n(n,e){return void 0!==n&&null!==n?e(n):void 0}var e=function(){},r=function(n){for(var e=[],r=arguments.length-1;r-- >0;)e[r]=arguments[r+1];for(var t in e){var l=e[t];for(var u in l)if(l.hasOwnProperty(u)){var i=l[u];n[u]=i}}return n},t=window.console||{},l=function(n){var r=[];for(var l in n){var i=n[l];t[i]?"function"!=typeof t[i]?u.push(i):r.push(i):(t[i]=e,r.push(i))}return r},u=["memory"],i=l(["debug","dirxml","error","group","groupCollapsed","info","log","warn"]),o=l(["assert","clear","count","dir","exception","groupEnd","markTimeline","profile","profileEnd","table","trace","time","timeEnd","timeStamp","timeline","timelineEnd"]),a={enabled:!0,styled:!0},c=r({},a),s=function(n){return"object"==typeof n&&(c=r({},a,n)),c},d=function(){this._store={}};d.prototype.add=function(n,e){this._store[n]=e},d.prototype.get=function(n){return this._store[n]||null},d.prototype.list=function(){return Object.keys(this._store)},d.prototype.each=function(n){var e=this;for(var r in e._store){n(r,e._store[r])}};var f=new d,p={"border-radius":"2px",padding:"1px 3px",margin:"0 1px",color:"white"},y={style:function(n,e){if(null!=n&&null!=e)e=r({},p,e),f.add(n,e);else if(null!=n)return f.get(n);return f.list()},defaults:function(n){return null!=n&&(p=n),p},stringForStyle:function(n){var e=f.get(n);return function(){var n=[];for(var r in e){var t=e[r],l=void 0;e.hasOwnProperty(r)&&(l=r+":"+t+";"),n.push(l)}return n}().join("")}},g={color:"black"};y.style("black",r({},{background:"black"})),y.style("blue",r({},{background:"blue"})),y.style("brown",r({},{background:"brown"})),y.style("gray",r({},{background:"gray"})),y.style("green",r({},{background:"green"})),y.style("purple",r({},{background:"purple"})),y.style("red",r({},{background:"red"})),y.style("cyan",r({},g,{background:"cyan"})),y.style("magenta",r({},g,{background:"magenta"})),y.style("orange",r({},g,{background:"orange"})),y.style("pink",r({},g,{background:"pink"})),y.style("yellow",r({},g,{background:"yellow"}));var b=s(),v=new d,h={include:null,exclude:null},k=function(n,e,r){return null==n&&(n=""),null==r&&(r=!1),n+(r?"%c":"[")+e+(r?"":"]")},m=function(n,e,r){var t=[];if(b.styled||(e=!1),r){var l=v.get(r);t=m(l.badgee.label,l.style,l.parent)}return n&&(t[0]=k(t[0],n,!!e)),e&&t.push(y.stringForStyle(e)),t},w=function(){var n=this;for(var r in i){n[i[r]]=e}for(var t in o){n[o[t]]=e}},x=function(n,e){var r=this;if(b.enabled){var l=m(this.label,n,e);n&&l.length>1&&(l[0]+="%c",l.push("p:a"));var a=null!=h.include&&!h.include.test(l[0]),c=null!=h.exclude?h.exclude.test(l[0]):void 0;if(a||c)w.bind(this)();else{for(var s in i){var d=i[s];r[d]=(y=t[d]).bind.apply(y,[t].concat(Array.from(l)))}for(var f in o){var p=o[f];r[p]=t[p].bind(t)}}return u.map(function(n){return r[n]=t[n]})}return w.bind(this)();var y},_=function(n,e,r){this.label=n,x.bind(this,e,r)(),v.add(this.label,{badgee:this,style:e,parent:r})};_.prototype.define=function(n,e){return new _(n,e,this.label)};var E=new _,S=function(){return v.each(function(n,e){return x.bind(e.badgee,e.style,e.parent)()})};E.style=y.style,E.defaultStyle=y.defaults,E.get=function(e){return n(v.get(e),function(n){return n.badgee})},E.filter={none:function(){return h={include:null,exclude:null},S(),E.filter},include:function(n){return null==n&&(n=null),n!==h.include&&(h.include=n,S()),E.filter},exclude:function(n){return null==n&&(n=null),n!==h.exclude&&(h.exclude=n,S()),E.filter}},E.config=function(n){return b=s(n),n&&S(),b};try{E.log()}catch(n){var j=t;j.define=function(){return t},j.style=E.style,j.styleDefaults=E.styleDefaults,j.filter=E.filter,j.get=function(){return t},j.config=function(){return E.config},E=j}var O=E;module.exports=O;
function n(n){var e=null!=k.include&&!k.include.test(n),t=null!=k.exclude&&k.exclude.test(n);return e||t}function e(n){return{none:function(){return k.include=null,k.exclude=null,n(),this},include:function(e){return void 0===e&&(e=null),e!==k.include&&(k.include=e,n()),this},exclude:function(e){return void 0===e&&(e=null),e!==k.exclude&&(k.exclude=e,n()),this}}}var t=function(){},r=function(n,e){for(var t in n)e(n[t],t)},u=function(n,e){for(var t in e)n[t]=e[t];return n},l=function(n){return u({},n)},i=function(n,e){return u(l(n),e)},o=window.console||{},c=["debug","error","group","groupCollapsed","info","log","warn"],f=["clear","dir","groupEnd"],d=function(n){r(c,n)},a=function(n){r(f,n)},s=function(n){d(n),a(n)};s(function(n){o[n]=o[n]||t});var g={enabled:!0,styled:!0},b=l(g),y=function(n){return"object"==typeof n&&(b=i(g,n)),b},p={},v={"border-radius":"2px",padding:"1px 3px",margin:"0 1px",color:"white"},h={style:function(n,e){if(null!=n&&null!=e)e=i(v,e),p[n]=e;else if(null!=n)return p[n];return Object.keys(p)},defaults:function(n){return null!=n&&(v=n),v},stringForStyle:function(n){var e=[];return r(p[n],function(n,t){e.push(t+":"+n+";")}),e.join("")}},x={},w={color:"black"};h.style("green",i(x,{background:"green"})),h.style("red",i(x,{background:"red"})),h.style("orange",i(w,{background:"orange"}));var k={include:null,exclude:null},S={},j=function(n,e,t){var r=[];if(b.styled||(e=!1),t){var u=S[t];r=j(u.badgee.label,u.style,u.parent)}if(n){var l=e?"%c"+n:"["+n+"]";r[0]=""+(r[0]||"")+l}return e&&r.push(h.stringForStyle(e)),r},m=function(e,r){var u=this,l=j(this.label,e,r);if(!b.enabled||n(l[0]))return void s(function(n){return u[n]=t});d(function(n){u[n]=(e=o[n]).bind.apply(e,[o].concat(l));var e}),a(function(n){u[n]=o[n].bind(o)})},F=function(n,e,t){this.label=n,m.bind(this,e,t)(),S[this.label]={badgee:this,style:e,parent:t}};F.prototype.define=function(n,e){return new F(n,e,this.label)};var C=function(){r(S,function(n){m.bind(n.badgee,n.style,n.parent)()})},E=new F;E.style=h.style,E.defaultStyle=h.defaults,E.get=function(n){return(S[n]||{}).badgee},E.filter=e(C),E.config=function(n){return n&&(y(n),C()),b};try{E.log()}catch(n){E=i(o,{define:function(){return E},style:E.style,defaultStyle:E.defaultStyle,filter:E.filter,get:function(){return E},config:function(){return E.config}})}var O=E;module.exports=O;
//# sourceMappingURL=badgee.js.map

@@ -1,2 +0,2 @@

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e.badgee=n()}(this,function(){function e(e,n){return void 0!==e&&null!==e?n(e):void 0}var n=function(){},t=function(e){for(var n=[],t=arguments.length-1;t-- >0;)n[t]=arguments[t+1];for(var r in n){var l=n[r];for(var u in l)if(l.hasOwnProperty(u)){var o=l[u];e[u]=o}}return e},r=window.console||{},l=function(e){var t=[];for(var l in e){var o=e[l];r[o]?"function"!=typeof r[o]?u.push(o):t.push(o):(r[o]=n,t.push(o))}return t},u=["memory"],o=l(["debug","dirxml","error","group","groupCollapsed","info","log","warn"]),i=l(["assert","clear","count","dir","exception","groupEnd","markTimeline","profile","profileEnd","table","trace","time","timeEnd","timeStamp","timeline","timelineEnd"]),a={enabled:!0,styled:!0},c=t({},a),f=function(e){return"object"==typeof e&&(c=t({},a,e)),c},d=function(){this._store={}};d.prototype.add=function(e,n){this._store[e]=n},d.prototype.get=function(e){return this._store[e]||null},d.prototype.list=function(){return Object.keys(this._store)},d.prototype.each=function(e){var n=this;for(var t in n._store){e(t,n._store[t])}};var s=new d,p={"border-radius":"2px",padding:"1px 3px",margin:"0 1px",color:"white"},y={style:function(e,n){if(null!=e&&null!=n)n=t({},p,n),s.add(e,n);else if(null!=e)return s.get(e);return s.list()},defaults:function(e){return null!=e&&(p=e),p},stringForStyle:function(e){var n=s.get(e);return function(){var e=[];for(var t in n){var r=n[t],l=void 0;n.hasOwnProperty(t)&&(l=t+":"+r+";"),e.push(l)}return e}().join("")}},g={color:"black"};y.style("black",t({},{background:"black"})),y.style("blue",t({},{background:"blue"})),y.style("brown",t({},{background:"brown"})),y.style("gray",t({},{background:"gray"})),y.style("green",t({},{background:"green"})),y.style("purple",t({},{background:"purple"})),y.style("red",t({},{background:"red"})),y.style("cyan",t({},g,{background:"cyan"})),y.style("magenta",t({},g,{background:"magenta"})),y.style("orange",t({},g,{background:"orange"})),y.style("pink",t({},g,{background:"pink"})),y.style("yellow",t({},g,{background:"yellow"}));var b=f(),v=new d,h={include:null,exclude:null},k=function(e,n,t){return null==e&&(e=""),null==t&&(t=!1),e+(t?"%c":"[")+n+(t?"":"]")},m=function(e,n,t){var r=[];if(b.styled||(n=!1),t){var l=v.get(t);r=m(l.badgee.label,l.style,l.parent)}return e&&(r[0]=k(r[0],e,!!n)),n&&r.push(y.stringForStyle(n)),r},x=function(){var e=this;for(var t in o){e[o[t]]=n}for(var r in i){e[i[r]]=n}},w=function(e,n){var t=this;if(b.enabled){var l=m(this.label,e,n);e&&l.length>1&&(l[0]+="%c",l.push("p:a"));var a=null!=h.include&&!h.include.test(l[0]),c=null!=h.exclude?h.exclude.test(l[0]):void 0;if(a||c)x.bind(this)();else{for(var f in o){var d=o[f];t[d]=(y=r[d]).bind.apply(y,[r].concat(Array.from(l)))}for(var s in i){var p=i[s];t[p]=r[p].bind(r)}}return u.map(function(e){return t[e]=r[e]})}return x.bind(this)();var y},_=function(e,n,t){this.label=e,w.bind(this,n,t)(),v.add(this.label,{badgee:this,style:n,parent:t})};_.prototype.define=function(e,n){return new _(e,n,this.label)};var j=new _,E=function(){return v.each(function(e,n){return w.bind(n.badgee,n.style,n.parent)()})};j.style=y.style,j.defaultStyle=y.defaults,j.get=function(n){return e(v.get(n),function(e){return e.badgee})},j.filter={none:function(){return h={include:null,exclude:null},E(),j.filter},include:function(e){return null==e&&(e=null),e!==h.include&&(h.include=e,E()),j.filter},exclude:function(e){return null==e&&(e=null),e!==h.exclude&&(h.exclude=e,E()),j.filter}},j.config=function(e){return b=f(e),e&&E(),b};try{j.log()}catch(e){var S=r;S.define=function(){return r},S.style=j.style,S.styleDefaults=j.styleDefaults,S.filter=j.filter,S.get=function(){return r},S.config=function(){return j.config},j=S}return j});
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):n.badgee=e()}(this,function(){function n(n){var e=null!=w.include&&!w.include.test(n),t=null!=w.exclude&&w.exclude.test(n);return e||t}var e=function(){},t=function(n,e){for(var t in n)e(n[t],t)},u=function(n,e){for(var t in e)n[t]=e[t];return n},r=function(n){return u({},n)},i=function(n,e){return u(r(n),e)},l=window.console||{},o=["debug","error","group","groupCollapsed","info","log","warn"],c=["clear","dir","groupEnd"],f=function(n){t(o,n)},d=function(n){t(c,n)},a=function(n){f(n),d(n)};a(function(n){l[n]=l[n]||e});var s={enabled:!0,styled:!0},g=r(s),y=function(n){return"object"==typeof n&&(g=i(s,n)),g},b={},p={"border-radius":"2px",padding:"1px 3px",margin:"0 1px",color:"white"},v={style:function(n,e){if(null!=n&&null!=e)e=i(p,e),b[n]=e;else if(null!=n)return b[n];return Object.keys(b)},defaults:function(n){return null!=n&&(p=n),p},stringForStyle:function(n){var e=[];return t(b[n],function(n,t){e.push(t+":"+n+";")}),e.join("")}},h={},x={color:"black"};v.style("green",i(h,{background:"green"})),v.style("red",i(h,{background:"red"})),v.style("orange",i(x,{background:"orange"}));var w={include:null,exclude:null},k={},S=function(n,e,t){var u=[];if(g.styled||(e=!1),t){var r=k[t];u=S(r.badgee.label,r.style,r.parent)}if(n){var i=e?"%c"+n:"["+n+"]";u[0]=""+(u[0]||"")+i}return e&&u.push(v.stringForStyle(e)),u},j=function(t,u){var r=this,i=S(this.label,t,u);if(!g.enabled||n(i[0]))return void a(function(n){return r[n]=e});f(function(n){r[n]=(e=l[n]).bind.apply(e,[l].concat(i));var e}),d(function(n){r[n]=l[n].bind(l)})},m=function(n,e,t){this.label=n,j.bind(this,e,t)(),k[this.label]={badgee:this,style:e,parent:t}};m.prototype.define=function(n,e){return new m(n,e,this.label)};var F=function(){t(k,function(n){j.bind(n.badgee,n.style,n.parent)()})},C=new m;C.style=v.style,C.defaultStyle=v.defaults,C.get=function(n){return(k[n]||{}).badgee},C.filter=function(n){return{none:function(){return w.include=null,w.exclude=null,n(),this},include:function(e){return void 0===e&&(e=null),e!==w.include&&(w.include=e,n()),this},exclude:function(e){return void 0===e&&(e=null),e!==w.exclude&&(w.exclude=e,n()),this}}}(F),C.config=function(n){return n&&(y(n),F()),g};try{C.log()}catch(n){C=i(l,{define:function(){return C},style:C.style,defaultStyle:C.defaultStyle,filter:C.filter,get:function(){return C},config:function(){return C.config}})}return C});
//# sourceMappingURL=badgee.umd.js.map
{
"name": "badgee",
"author": "Olivier Audard <audard@gmail.com>",
"version": "2.0.0-beta",
"version": "2.0.0-beta-1",
"description": "a browser console improvement",

@@ -33,3 +33,3 @@ "main": "build/badgee.js",

"version": "npm run build && git add -A build",
"postversion": "git push --tags origin master",
"postversion": "git push --tags",
"serve": "http-server -p 8000 .",

@@ -46,3 +46,3 @@ "open": "opener http://localhost:8000/test/",

"gzip-size-cli": "^2.0.0",
"http-server": "^0.9.0",
"http-server": "^0.10.0",
"jsdom": "^9.12.0",

@@ -49,0 +49,0 @@ "jsdom-global": "^2.1.1",

@@ -5,4 +5,3 @@ # badgee.js

[![npm version](https://img.shields.io/npm/v/badgee.svg)](https://www.npmjs.com/package/badgee)
[![Dependency Status](https://david-dm.org/dharFr/badgee.svg)](https://david-dm.org/dharFr/badgee)
[![devDependency Status](https://david-dm.org/dharFr/badgee/dev-status.svg)](https://david-dm.org/dharFr/badgee#info=devDependencies)
[![Greenkeeper badge](https://badges.greenkeeper.io/dharFr/badgee.svg)](https://greenkeeper.io/)

@@ -9,0 +8,0 @@ A browser console improvement

/* eslint-disable no-console */
/*! badgee v1.2.0 - MIT license */
import { noop } from './utils.js'
import { noop, extend, each } from './utils.js'
import console, {
properties, methods, unformatableMethods
eachMethod, eachFormatableMethod, eachUnformatableMethod
} from './console.js'
import config from './config';
import Store from './store';
import styles from './styles';
import { config, configure } from './config.js';
import styles from './styles.js';
import { getFilter, isFiltered } from './filter.js';
let currentConf = config();
const store = new Store;
const store = {};
let filter = {
include : null,
exclude : null
};
// concat foramted label for badges output
// (i.e. "%cbadge1%cbadge2" with style or "[badge1][badge2] without style")
const concatLabelToOutput = function(out, label, hasStyle){
if (out == null) { out = ''; }
if (hasStyle == null) { hasStyle = false; }
return `${out}${
hasStyle ? '%c' : '['
}${label}${
!hasStyle ? ']' : ''
}`;
};
// Given a label, style and parentName, generate the full list of arguments to
// pass to console method to get a foramted output
var argsForBadgee = function(label, style, parentName) {
const argsForBadgee = function(label, style, parentName) {
let args = [];
if (!currentConf.styled) { style = false; }
if (!config.styled) { style = false; }
if (parentName) {
const parent = store.get(parentName);
const parent = store[parentName];
args = argsForBadgee(parent.badgee.label, parent.style, parent.parent);

@@ -43,3 +25,6 @@ }

if (label) {
args[0] = concatLabelToOutput(args[0], label, !!style);
// concat formated label for badges output
// (i.e. "%cbadge1%cbadge2" with style or "[badge1][badge2] without style")
const formatedLabel = !style ? `[${label}]` : `%c${label}`
args[0] = `${args[0] || ''}${formatedLabel}`
}

@@ -54,55 +39,23 @@

// Define empty Badgee methods
// Intended to be called in a 'Badgee' instance context (e.g. with 'bind()')
const _disable = function() {
for (const i in methods) {
const method = methods[i]
this[method] = noop;
}
for (const i in unformatableMethods) {
const method = unformatableMethods[i];
this[method] = noop;
}
};
// Define Badgee methods form console object
// Intended to be called in a 'Badgee' instance context (e.g. with 'bind()')
const _defineMethods = function(style, parentName) {
// get arguments to pass to console object
const args = argsForBadgee(this.label, style, parentName);
if (!currentConf.enabled) {
return _disable.bind(this)();
} else {
// get arguments to pass to console object
const args = argsForBadgee(this.label, style, parentName);
if (!config.enabled || isFiltered(args[0])) {
// disable everything
eachMethod((method) => this[method] = noop)
return
}
// Reset style for FF :
// Defining a last style to an unknown property seems to reset to the default
// behavior on FF
if (style && (args.length > 1)) {
args[0] += '%c';
args.push('p:a');
}
// Define Badgee 'formatable' methods form console object
eachFormatableMethod((method) => {
this[method] = console[method].bind(console, ...args);
})
const isntInclusive = (filter.include != null) && !filter.include.test(args[0]);
const isExclusive = filter.exclude != null ? filter.exclude.test(args[0]) : undefined;
if (isntInclusive || isExclusive) {
_disable.bind(this)();
} else {
// Define Badgee 'formatable' methods form console object
for (const i in methods) {
const method = methods[i]
this[method] = console[method].bind(console, ...Array.from(args));
}
// Define Badgee 'unformatable' methods form console object
for (const i in unformatableMethods) {
const method = unformatableMethods[i];
this[method] = console[method].bind(console);
}
}
// Define Badgee properties from console object
return properties.map((prop) => (this[prop] = console[prop]));
}
// Define Badgee 'unformatable' methods form console object
eachUnformatableMethod((method) => {
this[method] = console[method].bind(console);
})
};

@@ -120,7 +73,7 @@

// Store instance for later reference
store.add(this.label, {
store[this.label] = {
badgee: this,
style,
parent: parentName
});
};
}

@@ -136,49 +89,24 @@

const redefineMethodsForAllBadges = () => {
each(store, (b) => {
_defineMethods.bind(b.badgee, b.style, b.parent)()
})
}
// Create public Badgee instance
let b = new Badgee;
const redefineMethodsForAllBadges = () =>
store.each((label, b) => _defineMethods.bind(b.badgee, b.style, b.parent)())
;
// Augment public instance with utility methods
b.style = styles.style;
b.style = styles.style;
b.defaultStyle = styles.defaults;
b.get = label => __guard__(store.get(label), x => x.badgee);
b.filter = {
none() {
filter = {
include : null,
exclude : null
};
redefineMethodsForAllBadges();
return b.filter;
},
b.get = label => (store[label] || {}).badgee;
b.filter = getFilter(redefineMethodsForAllBadges)
include(matcher) {
if (matcher == null) { matcher = null; }
if (matcher !== filter.include) {
filter.include = matcher;
redefineMethodsForAllBadges();
}
return b.filter;
},
exclude(matcher) {
if (matcher == null) { matcher = null; }
if (matcher !== filter.exclude) {
filter.exclude = matcher;
redefineMethodsForAllBadges();
}
return b.filter;
}
};
b.config = function(conf) {
currentConf = config(conf);
b.config = function(conf) {
// when conf is updated, redefine every badgee method
if (conf) {
configure(conf)
redefineMethodsForAllBadges();
}
return currentConf;
return config;
};

@@ -191,17 +119,12 @@

} catch (e) {
const fallback = console;
fallback.define = () => console;
fallback.style = b.style;
fallback.styleDefaults = b.styleDefaults;
fallback.filter = b.filter;
fallback.get = () => console;
fallback.config = () => b.config;
b = fallback;
b = extend(console, {
define : () => b,
style : b.style,
defaultStyle : b.defaultStyle,
filter : b.filter,
get : () => b,
config : () => b.config,
});
}
export default b;
function __guard__(value, transform) {
return (typeof value !== 'undefined' && value !== null) ? transform(value) : undefined;
}

@@ -1,2 +0,2 @@

import { extend } from './utils';
import { clone, extend } from './utils';

@@ -9,3 +9,3 @@ // default configuration

let config = extend({}, defaults);
let config = clone(defaults);

@@ -15,3 +15,3 @@ const configure = function(conf) {

if (typeof conf === 'object') {
config = extend({}, defaults, conf);
config = extend(defaults, conf);
}

@@ -23,2 +23,3 @@

export default configure
// export default configure
export { config, configure }

@@ -1,26 +0,9 @@

import { noop } from './utils.js'
import { noop, each } from './utils.js'
// Homogeneisation of the console API on different browsers
// - add compat console object if not available
// - some methods might not be defined. fake them with `noop` function
// - some "methods" might not be functions but properties (eg. profile & profileEnd in IE11)
const console = this.console || {};
const checkConsoleMethods = (methodList) => {
const ret = [];
for (const i in methodList) {
const method = methodList[i]
if (!console[method]) {
console[method] = noop;
ret.push(method);
} else if (typeof console[method] !== 'function') {
properties.push(method);
} else {
ret.push(method);
}
}
return ret;
};
// For the record, every single console methods and properties
// For the record, every single console methods and properties :
// ["memory", "exception", "debug", "error", "info", "log", "warn", "dir",

@@ -30,22 +13,18 @@ // "dirxml", "table", "trace", "assert", "count", "markTimeline", "profile",

// "group", "groupCollapsed", "groupEnd", "clear"]
const properties = [
'memory'
];
//
// Focus on logging methods and ignore profiling/timeline methods or less used methods
const methods = ['debug', 'error', 'group', 'groupCollapsed', 'info', 'log', 'warn'];
const unformatableMethods = ['clear', 'dir', 'groupEnd'];
const methods = checkConsoleMethods([
'debug', 'dirxml', 'error', 'group',
'groupCollapsed', 'info', 'log', 'warn'
]);
export const eachFormatableMethod = (fn) => { each(methods, fn) }
export const eachUnformatableMethod = (fn) => { each(unformatableMethods, fn) }
export const eachMethod = (fn) => {
eachFormatableMethod(fn)
eachUnformatableMethod(fn)
}
const unformatableMethods = checkConsoleMethods([
'assert', 'clear', 'count', 'dir', 'exception', 'groupEnd', 'markTimeline',
'profile', 'profileEnd', 'table', 'trace', 'time', 'timeEnd', 'timeStamp',
'timeline', 'timelineEnd'
]);
eachMethod((method) => {
console[method] = console[method] || noop;
})
export {
properties,
methods,
unformatableMethods
}
export default console

@@ -1,6 +0,5 @@

import Store from './store';
import { extend } from './utils';
import { each, extend } from './utils';
// Create store to save styles
const store = new Store;
const store = {};

@@ -19,9 +18,9 @@ // Default properties for styles

if (name != null && style != null) {
style = extend({}, defaultsStyle, style);
store.add(name, style);
style = extend(defaultsStyle, style);
store[name] = style;
}
else if (name != null) {
return store.get(name);
return store[name];
}
return store.list();
return Object.keys(store);
},

@@ -37,15 +36,7 @@

stringForStyle(name) {
const style = store.get(name);
return ((() => {
const result = [];
for (const k in style) {
const v = style[k];
let item;
if (style.hasOwnProperty(k)) {
item = `${k}:${v};`;
}
result.push(item);
}
return result;
})()).join('');
const res = []
each(store[name], (style, k) => {
res.push(`${k}:${style};`)
})
return res.join('');
}

@@ -56,19 +47,10 @@ };

// define a few styles
const empty = {};
const black = {'color': 'black'};
styles.style('black', extend({}, {'background': 'black'}));
styles.style('blue', extend({}, {'background': 'blue'}));
styles.style('brown', extend({}, {'background': 'brown'}));
styles.style('gray', extend({}, {'background': 'gray'}));
styles.style('green', extend({}, {'background': 'green'}));
styles.style('purple', extend({}, {'background': 'purple'}));
styles.style('red', extend({}, {'background': 'red'}));
styles.style('cyan', extend({}, black, {'background': 'cyan'}));
styles.style('magenta', extend({}, black, {'background': 'magenta'}));
styles.style('orange', extend({}, black, {'background': 'orange'}));
styles.style('pink', extend({}, black, {'background': 'pink'}));
styles.style('yellow', extend({}, black, {'background': 'yellow'}));
styles.style('green', extend(empty, {'background': 'green'}));
styles.style('red', extend(empty, {'background': 'red'}));
styles.style('orange', extend(black, {'background': 'orange'}));
export default styles;

@@ -1,14 +0,14 @@

export const noop = () => {};
export const noop = () => {}
export const extend = (destObj, ...args) => {
for (const i in args) {
const obj = args[i];
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
const val = obj[key];
destObj[key] = val;
}
}
export const each = (items, fn) => {
for (const i in items) {
fn(items[i], i)
}
return destObj
}
const _extend = (dest, obj) => {
for (const i in obj) dest[i] = obj[i]
return dest
}
export const clone = (obj) => _extend({}, obj)
export const extend = (dest, obj) => _extend(clone(dest), obj)

@@ -46,3 +46,3 @@ /* eslint-disable no-console */

expect(styles).to.be.an('array');
expect(styles).to.have.length.of.at.least(5);
expect(styles).to.have.length.of(3);
});

@@ -142,3 +142,2 @@

describe('badgee.get', () => {
it('should be a function', () => expect(badgee).to.respondTo('get'));

@@ -153,11 +152,8 @@

describe('console API:', () => {
// methods = ['log']
const methods = [
'debug', 'dirxml', 'error', 'group',
'debug', 'error', 'group',
'groupCollapsed', 'info', 'log', 'warn'
];
const unformatableMethods = [
'assert', 'clear', 'count', 'dir', 'exception', 'groupEnd', 'markTimeline', 'profile',
'profileEnd', 'table', 'trace', 'time', 'timeEnd', 'timeStamp', 'timeline',
'timelineEnd'
'clear', 'dir', 'groupEnd'
];

@@ -195,6 +191,6 @@

badgee[method](...Array.from(args || []));
badgee[method](...args);
expect(console[method].called).to.be.true;
expect(console[method].calledWithExactly(...Array.from(args || []))).to.be.true;
expect(console[method].calledWithExactly(...args)).to.be.true;
});

@@ -205,6 +201,6 @@

badge1.instance[method](...Array.from(args || []));
badge1.instance[method](...args);
expect(console[method].calledOnce).to.be.true;
expect(console[method].calledWithExactly(`${badge1.cName}%c`, badge1.cSytle, 'p:a', ...Array.from(args))).to.be.true;
expect(console[method].calledWithExactly(`${badge1.cName}`, badge1.cSytle, ...args)).to.be.true;
});

@@ -215,6 +211,6 @@

badge2.instance[method](...Array.from(args || []));
badge2.instance[method](...args);
expect(console[method].calledOnce).to.be.true;
expect(console[method].calledWithExactly(`${[badge1.cName,badge2.cName].join('')}%c`, badge1.cSytle, badge2.cSytle, 'p:a', ...Array.from(args))).to.be.true;
expect(console[method].calledWithExactly(`${[badge1.cName,badge2.cName].join('')}`, badge1.cSytle, badge2.cSytle, ...args)).to.be.true;
});

@@ -241,3 +237,3 @@ });

badgee[method](...Array.from(args || []));
badgee[method](...args);

@@ -250,3 +246,3 @@ expect(console[method].called).to.be.false;

badge1.instance[method](...Array.from(args || []));
badge1.instance[method](...args);

@@ -259,3 +255,3 @@ expect(console[method].called).to.be.false;

badge2.instance[method](...Array.from(args || []));
badge2.instance[method](...args);

@@ -286,6 +282,6 @@ expect(console[method].called).to.be.false;

badgee[method](...Array.from(args || []));
badgee[method](...args);
expect(console[method].called).to.be.true;
expect(console[method].calledWithExactly(...Array.from(args || []))).to.be.true;
expect(console[method].calledWithExactly(...args)).to.be.true;
});

@@ -296,6 +292,6 @@

badge1.instance[method](...Array.from(args || []));
badge1.instance[method](...args);
expect(console[method].calledOnce).to.be.true;
expect(console[method].calledWithExactly(...Array.from(args || []))).to.be.true;
expect(console[method].calledWithExactly(...args)).to.be.true;
});

@@ -306,6 +302,6 @@

badge2.instance[method](...Array.from(args || []));
badge2.instance[method](...args);
expect(console[method].calledOnce).to.be.true;
expect(console[method].calledWithExactly(...Array.from(args || []))).to.be.true;
expect(console[method].calledWithExactly(...args)).to.be.true;
});

@@ -332,3 +328,3 @@ });

badgee[method](...Array.from(args || []));
badgee[method](...args);

@@ -341,3 +337,3 @@ expect(console[method].called).to.be.false;

badge1.instance[method](...Array.from(args || []));
badge1.instance[method](...args);

@@ -350,3 +346,3 @@ expect(console[method].called).to.be.false;

badge2.instance[method](...Array.from(args || []));
badge2.instance[method](...args);

@@ -406,2 +402,3 @@ expect(console[method].called).to.be.false;

});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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