diff --git a/build/badgee.js b/build/badgee.js index eedcdb9..1f94763 100644 --- a/build/badgee.js +++ b/build/badgee.js @@ -1,2 +1,2 @@ var n=function(){},t=function(n,t){for(var r in n)t(n[r],r)},r=function(n,t){for(var r in t)n[r]=t[r];return n},u=function(n){return r({},n)},e=function(n,t){return r(u(n),t)},i=("undefined"!=typeof window?window:global).console||{},o=["debug","error","group","groupCollapsed","info","log","warn"],l=["clear","dir","groupEnd"],c=function(n){t(o,n)},f=function(n){t(l,n)},a=function(n){c(n),f(n)};a(function(t){i[t]=i[t]||n});var d={enabled:!0,styled:!0},s=u(d),b=function(n){return n&&(s=e(d,n)),s},p={},g={"border-radius":"2px",padding:"1px 3px",margin:"0 1px",color:"white"},v=function(n,t){if(null!=n&&null!=t)t=e(g,t),p[n]=t;else if(null!=n)return p[n];return Object.keys(p)},h=function(n){return null!=n&&(g=n),g},y=function(n){var r="";return t(p[n],function(n,t){r+=t+":"+n+";"}),r},w=function(n,t){return e(n,{background:t})};t(["green","red"],function(n){v(n,w({},n))}),v("orange",w({color:"black"},"orange"));var x=null,k=null,j=function(n){return null!=x&&!x.test(n)||null!=k&&k.test(n)},m=function(n){return{none:function(){return x=null,k=null,n(),this},include:function(t){return t!==x&&(x=t,n()),this},exclude:function(t){return t!==k&&(k=t,n()),this}}},C={},E=function(n,t,r){var u=[];if(r){var e=C[r],i=e[0],o=e[1],l=e[2];u=E(i.label,o,l)}if(n){var c=t?"%c"+n:"["+n+"]";u[0]=""+(u[0]||"")+c}return t&&u.push(y(t)),u},O=function(t,r){var u=this,e=E(this.label,!!s.styled&&t,r);!s.enabled||j(e[0])?a(function(t){return u[t]=n}):(c(function(n){u[n]=(t=i[n]).bind.apply(t,[i].concat(e));var t}),f(function(n){u[n]=i[n].bind(i)}))},S=function(n,t,r){this.label=n,O.bind(this,t,r)(),C[n]=[this,t,r]};S.prototype.define=function(n,t){return new S(n,t,this.label)};var q=function(){t(C,function(n){var t=n[0],r=n[1],u=n[2];O.bind(t,r,u)()})},z=new S;z.get=function(n){return(C[n]||{})[0]};try{z.log()}catch(n){z=e(i,{define:function(){return z},get:function(){return z}})}z.style=v,z.defaultStyle=h,z.filter=m(q),z.config=function(n){return n&&"object"==typeof n&&(b(n),q()),s};var A=z;module.exports=A; -//# sourceMappingURL=badgee.js.map \ No newline at end of file +//# sourceMappingURL=build/badgee.js.map \ No newline at end of file diff --git a/build/badgee.js.map b/build/badgee.js.map index 2a2eaac..fb2903b 100644 --- a/build/badgee.js.map +++ b/build/badgee.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/utils.js","../src/console.js","../src/config.js","../src/styles.js","../src/filter.js","../src/badgee.js"],"names":["const","noop","each","items","fn","i","_extend","dest","obj","clone","extend","console","this","methods","unformatableMethods","eachFormatableMethod","eachUnformatableMethod","eachMethod","method","defaults","enabled","styled","config","configure","conf","store","defaultsStyle","border-radius","padding","margin","color","styles","name","style","Object","keys","defaultStyle","style2Str","let","res","k","buildStyle","base","bkgColor","background","include","exclude","isFiltered","str","test","getFilter","onFilterChange","none","matcher","argsForBadgee","label","parentName","args","ref","badgee","parent","formatedLabel","push","_defineMethods","bind","apply","concat","Badgee","prototype","define","redefineMethodsForAllBadges","b","get","log","e","filter","b$1"],"mappings":"AAAOA,GAAMC,GAAO,aAEPC,EAAO,SAACC,EAAOC,GAC1B,IAAKJ,GAAMK,KAAKF,GACdC,EAAGD,EAAME,GAAIA,IAIXC,EAAU,SAACC,EAAMC,GACrB,IAAKR,GAAMK,KAAKG,GAAKD,EAAKF,GAAKG,EAAIH,EACnC,OAAOE,IAEIE,EAAQ,SAACD,GAAK,MAAGF,MAAYE,IAC7BE,EAAS,SAACH,EAAMC,GAAK,MAAGF,GAAQG,EAAMF,GAAOC,ICRpDG,GAAUC,mBAAAA,QAAAA,OAAAA,QAAKD,YASfE,GAAuB,QAAS,QAAS,QAAS,iBAAkB,OAAQ,MAAO,QACnFC,GAAuB,QAAS,MAAO,YAEhCC,EAAyB,SAACX,GAASF,EAAKW,E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AAM,SAACjB,GAAO,OAAI9B,EAAM8B,QAAc,GAIxC,KACEgB,EAAEE,MACF,MAAOC,GACPH,EAAI7D,EAAOC,GACT0D,OAAS,WAAG,MAAGE,IACfC,IAAS,WAAG,MAAGD,MAKnBA,EAAEtC,MAAQF,EACVwC,EAAEnC,aAAgBA,EAClBmC,EAAEI,OAASzB,EAAUoB,GACrBC,EAAEjD,OAAS,SAASE,GAMlB,MAJIA,IAAsB,gBAAPA,KACjBD,EAAUC,GACV8C,KAEKhD,EAGT,IAAAsD,GAAeL","file":"badgee.js","sourcesContent":["export const noop = () => {}\n\nexport const each = (items, fn) => {\n for (const i in items) {\n fn(items[i], i)\n }\n}\n\nconst _extend = (dest, obj) => {\n for (const i in obj) dest[i] = obj[i]\n return dest\n}\nexport const clone = (obj) => _extend({}, obj)\nexport const extend = (dest, obj) => _extend(clone(dest), obj)\n","import { noop, each } from './utils.js'\n// Homogeneisation of the console API on different browsers\n// - add compat console object if not available\n// - some methods might not be defined. fake them with `noop` function\n\nconst console = this.console || {};\n\n// For the record, every single console methods and properties :\n// [\"memory\", \"exception\", \"debug\", \"error\", \"info\", \"log\", \"warn\", \"dir\",\n// \"dirxml\", \"table\", \"trace\", \"assert\", \"count\", \"markTimeline\", \"profile\",\n// \"profileEnd\", \"time\", \"timeEnd\", \"timeStamp\", \"timeline\", \"timelineEnd\",\n// \"group\", \"groupCollapsed\", \"groupEnd\", \"clear\"]\n//\n// Focus on logging methods and ignore profiling/timeline methods or less used methods\nconst methods = ['debug', 'error', 'group', 'groupCollapsed', 'info', 'log', 'warn'];\nconst unformatableMethods = ['clear', 'dir', 'groupEnd'];\n\nexport const eachFormatableMethod = (fn) => { each(methods, fn) }\nexport const eachUnformatableMethod = (fn) => { each(unformatableMethods, fn) }\nexport const eachMethod = (fn) => {\n eachFormatableMethod(fn)\n eachUnformatableMethod(fn)\n}\n\neachMethod((method) => {\n console[method] = console[method] || noop;\n})\n\nexport default console\n","import { clone, extend } from './utils';\n\n// default configuration\nconst defaults = {\n enabled : true,\n styled : true\n};\n\nlet config = clone(defaults);\n\nconst configure = function(conf) {\n // update conf\n if (conf) {\n config = extend(defaults, conf);\n }\n\n // return current conf\n return config;\n};\n\n// export default configure\nexport { config, configure }\n","import { each, extend } from './utils';\n\n// Create store to save styles\nconst store = {};\n\n// Default properties for styles\nlet defaultsStyle = {\n 'border-radius': '2px',\n 'padding' : '1px 3px',\n 'margin' : '0 1px',\n 'color' : 'white'\n};\n\n// define a new style or list existing ones\nexport const styles = (name, style) => {\n if (name != null && style != null) {\n style = extend(defaultsStyle, style);\n store[name] = style;\n }\n else if (name != null) {\n return store[name];\n }\n return Object.keys(store);\n}\n\nexport const defaultStyle = (style) => {\n if (style != null) {\n defaultsStyle = style;\n }\n return defaultsStyle;\n}\n\nexport const style2Str = (name) => {\n let res = ''\n each(store[name], (style, k) => {\n res += `${k}:${style};`\n })\n return res\n}\n\n// define a few styles\nconst buildStyle = (base, bkgColor) => extend(base, {'background': bkgColor})\n\neach(['green', 'red'], (color) => {\n styles(color, buildStyle({}, color))\n})\nstyles('orange', buildStyle({'color': 'black'}, 'orange'));\n","let include = null\nlet exclude = null\n\nexport const isFiltered = (str) => {\n return ((include != null) && !include.test(str)) //isntIncluded\n || ((exclude != null) && exclude.test(str)) // isExcluded\n}\n\nexport const getFilter = (onFilterChange) => {\n return {\n none() {\n include = null\n exclude = null\n\n onFilterChange()\n return this;\n },\n\n include(matcher) {\n if (matcher !== include) {\n include = matcher\n onFilterChange()\n }\n return this\n },\n\n exclude(matcher) {\n if (matcher !== exclude) {\n exclude = matcher\n onFilterChange()\n }\n return this\n }\n };\n}\n","/* eslint-disable no-console */\n/*! badgee v1.2.0 - MIT license */\nimport { noop, extend, each } from './utils.js'\nimport console, {\n eachMethod, eachFormatableMethod, eachUnformatableMethod\n} from './console.js'\nimport { config, configure } from './config.js';\nimport { styles, defaultStyle, style2Str } from './styles.js';\nimport { getFilter, isFiltered } from './filter.js';\n\nconst store = {};\n\n// Given a label, style and parentName, generate the full list of arguments to\n// pass to console method to get a foramted output\nconst argsForBadgee = function(label, style, parentName) {\n let args = [];\n\n if (parentName) {\n const [badgee, style, parent] = store[parentName];\n args = argsForBadgee(badgee.label, style, parent);\n }\n\n if (label) {\n // concat formated label for badges output\n // (i.e. \"%cbadge1%cbadge2\" with style or \"[badge1][badge2] without style\")\n const formatedLabel = !style ? `[${label}]` : `%c${label}`\n args[0] = `${args[0] || ''}${formatedLabel}`\n }\n\n if (style) {\n args.push(style2Str(style));\n }\n\n return args;\n};\n\n// Define Badgee methods form console object\n// Intended to be called in a 'Badgee' instance context (e.g. with 'bind()')\nconst _defineMethods = function(style, parentName) {\n // get arguments to pass to console object\n const args = argsForBadgee(this.label, config.styled ? style : false, parentName);\n\n if (!config.enabled || isFiltered(args[0])) {\n // disable everything\n eachMethod((method) => this[method] = noop)\n }\n else {\n // Define Badgee 'formatable' methods form console object\n eachFormatableMethod((method) => {\n this[method] = console[method].bind(console, ...args);\n });\n\n // Define Badgee 'unformatable' methods form console object\n eachUnformatableMethod((method) => {\n this[method] = console[method].bind(console);\n });\n }\n\n};\n\n// ==================================\n\nclass Badgee {\n\n constructor(label, style, parentName) {\n // Define Badgee methods form console object\n this.label = label;\n _defineMethods.bind(this, style, parentName)();\n\n // Store instance for later reference\n store[label] = [this, style, parentName];\n }\n\n // Defines a new Badgee instance with @ as parent Badge\n define(label, style) {\n return new Badgee(label, style, this.label);\n }\n}\n\n// ==================================\n\nconst redefineMethodsForAllBadges = () => {\n each(store, ([badgee, style, parent]) => {\n _defineMethods.bind(badgee, style, parent)()\n })\n}\n\n// Create public Badgee instance\nlet b = new Badgee;\n\n// Augment public instance with getter method\nb.get = (label) => (store[label] || {})[0];\n\n// Some browsers don't allow to use bind on console object anyway\n// fallback to default if needed\ntry {\n b.log();\n} catch (e) {\n b = extend(console, {\n define : () => b,\n get : () => b,\n });\n}\n\n// Augment public instance with a few utility methods\nb.style = styles;\nb.defaultStyle = defaultStyle;\nb.filter = getFilter(redefineMethodsForAllBadges)\nb.config = function(conf) {\n // when conf is updated, redefine every badgee method\n if (conf && typeof conf==='object') {\n configure(conf)\n redefineMethodsForAllBadges();\n }\n return config;\n};\n\nexport default b;\n"]} \ No newline at end of file +{"version":3,"sources":["../src/utils.js","../src/console.js","../src/config.js","../src/styles.js","../src/filter.js","../src/badgee.js"],"names":["const","noop","each","items","fn","i","_extend","dest","obj","clone","extend","console","this","methods","unformatableMethods","eachFormatableMethod","eachUnformatableMethod","eachMethod","method","defaults","enabled","styled","config","configure","conf","store","defaultsStyle","border-radius","padding","margin","color","styles","name","style","Object","keys","defaultStyle","style2Str","let","res","k","buildStyle","base","bkgColor","background","include","exclude","isFiltered","str","test","getFilter","onFilterChange","none","matcher","argsForBadgee","label","parentName","args","ref","badgee","parent","formatedLabel","push","_defineMethods","bind","apply","concat","Badgee","prototype","define","redefineMethodsForAllBadges","b","get","log","e","filter","b$1"],"mappings":"AAAOA,IAAMC,EAAO,aAEPC,EAAO,SAACC,EAAOC,GAC1B,IAAKJ,IAAMK,KAAKF,EACdC,EAAGD,EAAME,GAAIA,IAIXC,EAAU,SAACC,EAAMC,GACrB,IAAKR,IAAMK,KAAKG,EAAKD,EAAKF,GAAKG,EAAIH,GACnC,OAAOE,GAEIE,EAAQ,SAACD,GAAK,OAAGF,KAAYE,IAC7BE,EAAS,SAACH,EAAMC,GAAK,OAAGF,EAAQG,EAAMF,GAAOC,ICRpDG,GAAUC,oBAAAA,OAAAA,OAAAA,QAAKD,YASfE,GAAuB,QAAS,QAAS,QAAS,iBAAkB,OAAQ,MAAO,QACnFC,GAAuB,QAAS,MAAO,YAEhCC,EAAyB,SAACX,GAASF,EAAKW,EAAST,IACjDY,EAAyB,SAACZ,GAASF,EAAKY,EAAqBV,IAC7Da,EAAa,SAACb,GACzBW,EAAqBX,GACrBY,EAAuBZ,IAGzBa,EAAW,SAACC,GACVP,EAAQO,GAAUP,EAAQO,IAAWjB,ICtBvCD,IAAMmB,GACJC,SAAU,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aAAgBA,EAClBmC,EAAEI,OAASzB,EAAUoB,GACrBC,EAAEjD,OAAS,SAASE,GAMlB,OAJIA,GAAsB,iBAAPA,IACjBD,EAAUC,GACV8C,KAEKhD,GAGT,IAAAsD,EAAeL","sourcesContent":["export const noop = () => {}\n\nexport const each = (items, fn) => {\n for (const i in items) {\n fn(items[i], i)\n }\n}\n\nconst _extend = (dest, obj) => {\n for (const i in obj) dest[i] = obj[i]\n return dest\n}\nexport const clone = (obj) => _extend({}, obj)\nexport const extend = (dest, obj) => _extend(clone(dest), obj)\n","import { noop, each } from './utils.js'\n// Homogeneisation of the console API on different browsers\n// - add compat console object if not available\n// - some methods might not be defined. fake them with `noop` function\n\nconst console = this.console || {};\n\n// For the record, every single console methods and properties :\n// [\"memory\", \"exception\", \"debug\", \"error\", \"info\", \"log\", \"warn\", \"dir\",\n// \"dirxml\", \"table\", \"trace\", \"assert\", \"count\", \"markTimeline\", \"profile\",\n// \"profileEnd\", \"time\", \"timeEnd\", \"timeStamp\", \"timeline\", \"timelineEnd\",\n// \"group\", \"groupCollapsed\", \"groupEnd\", \"clear\"]\n//\n// Focus on logging methods and ignore profiling/timeline methods or less used methods\nconst methods = ['debug', 'error', 'group', 'groupCollapsed', 'info', 'log', 'warn'];\nconst unformatableMethods = ['clear', 'dir', 'groupEnd'];\n\nexport const eachFormatableMethod = (fn) => { each(methods, fn) }\nexport const eachUnformatableMethod = (fn) => { each(unformatableMethods, fn) }\nexport const eachMethod = (fn) => {\n eachFormatableMethod(fn)\n eachUnformatableMethod(fn)\n}\n\neachMethod((method) => {\n console[method] = console[method] || noop;\n})\n\nexport default console\n","import { clone, extend } from './utils';\n\n// default configuration\nconst defaults = {\n enabled : true,\n styled : true\n};\n\nlet config = clone(defaults);\n\nconst configure = function(conf) {\n // update conf\n if (conf) {\n config = extend(defaults, conf);\n }\n\n // return current conf\n return config;\n};\n\n// export default configure\nexport { config, configure }\n","import { each, extend } from './utils';\n\n// Create store to save styles\nconst store = {};\n\n// Default properties for styles\nlet defaultsStyle = {\n 'border-radius': '2px',\n 'padding' : '1px 3px',\n 'margin' : '0 1px',\n 'color' : 'white'\n};\n\n// define a new style or list existing ones\nexport const styles = (name, style) => {\n if (name != null && style != null) {\n style = extend(defaultsStyle, style);\n store[name] = style;\n }\n else if (name != null) {\n return store[name];\n }\n return Object.keys(store);\n}\n\nexport const defaultStyle = (style) => {\n if (style != null) {\n defaultsStyle = style;\n }\n return defaultsStyle;\n}\n\nexport const style2Str = (name) => {\n let res = ''\n each(store[name], (style, k) => {\n res += `${k}:${style};`\n })\n return res\n}\n\n// define a few styles\nconst buildStyle = (base, bkgColor) => extend(base, {'background': bkgColor})\n\neach(['green', 'red'], (color) => {\n styles(color, buildStyle({}, color))\n})\nstyles('orange', buildStyle({'color': 'black'}, 'orange'));\n","let include = null\nlet exclude = null\n\nexport const isFiltered = (str) => {\n return ((include != null) && !include.test(str)) //isntIncluded\n || ((exclude != null) && exclude.test(str)) // isExcluded\n}\n\nexport const getFilter = (onFilterChange) => {\n return {\n none() {\n include = null\n exclude = null\n\n onFilterChange()\n return this;\n },\n\n include(matcher) {\n if (matcher !== include) {\n include = matcher\n onFilterChange()\n }\n return this\n },\n\n exclude(matcher) {\n if (matcher !== exclude) {\n exclude = matcher\n onFilterChange()\n }\n return this\n }\n };\n}\n","/* eslint-disable no-console */\n/*! badgee v1.2.0 - MIT license */\nimport { noop, extend, each } from './utils.js'\nimport console, {\n eachMethod, eachFormatableMethod, eachUnformatableMethod\n} from './console.js'\nimport { config, configure } from './config.js';\nimport { styles, defaultStyle, style2Str } from './styles.js';\nimport { getFilter, isFiltered } from './filter.js';\n\nconst store = {};\n\n// Given a label, style and parentName, generate the full list of arguments to\n// pass to console method to get a foramted output\nconst argsForBadgee = function(label, style, parentName) {\n let args = [];\n\n if (parentName) {\n const [badgee, style, parent] = store[parentName];\n args = argsForBadgee(badgee.label, style, parent);\n }\n\n if (label) {\n // concat formated label for badges output\n // (i.e. \"%cbadge1%cbadge2\" with style or \"[badge1][badge2] without style\")\n const formatedLabel = !style ? `[${label}]` : `%c${label}`\n args[0] = `${args[0] || ''}${formatedLabel}`\n }\n\n if (style) {\n args.push(style2Str(style));\n }\n\n return args;\n};\n\n// Define Badgee methods form console object\n// Intended to be called in a 'Badgee' instance context (e.g. with 'bind()')\nconst _defineMethods = function(style, parentName) {\n // get arguments to pass to console object\n const args = argsForBadgee(this.label, config.styled ? style : false, parentName);\n\n if (!config.enabled || isFiltered(args[0])) {\n // disable everything\n eachMethod((method) => this[method] = noop)\n }\n else {\n // Define Badgee 'formatable' methods form console object\n eachFormatableMethod((method) => {\n this[method] = console[method].bind(console, ...args);\n });\n\n // Define Badgee 'unformatable' methods form console object\n eachUnformatableMethod((method) => {\n this[method] = console[method].bind(console);\n });\n }\n\n};\n\n// ==================================\n\nclass Badgee {\n\n constructor(label, style, parentName) {\n // Define Badgee methods form console object\n this.label = label;\n _defineMethods.bind(this, style, parentName)();\n\n // Store instance for later reference\n store[label] = [this, style, parentName];\n }\n\n // Defines a new Badgee instance with @ as parent Badge\n define(label, style) {\n return new Badgee(label, style, this.label);\n }\n}\n\n// ==================================\n\nconst redefineMethodsForAllBadges = () => {\n each(store, ([badgee, style, parent]) => {\n _defineMethods.bind(badgee, style, parent)()\n })\n}\n\n// Create public Badgee instance\nlet b = new Badgee;\n\n// Augment public instance with getter method\nb.get = (label) => (store[label] || {})[0];\n\n// Some browsers don't allow to use bind on console object anyway\n// fallback to default if needed\ntry {\n b.log();\n} catch (e) {\n b = extend(console, {\n define : () => b,\n get : () => b,\n });\n}\n\n// Augment public instance with a few utility methods\nb.style = styles;\nb.defaultStyle = defaultStyle;\nb.filter = getFilter(redefineMethodsForAllBadges)\nb.config = function(conf) {\n // when conf is updated, redefine every badgee method\n if (conf && typeof conf==='object') {\n configure(conf)\n redefineMethodsForAllBadges();\n }\n return config;\n};\n\nexport default b;\n"]} \ No newline at end of file diff --git a/build/badgee.umd.js b/build/badgee.umd.js index 945d40d..d2cb00c 100644 --- a/build/badgee.umd.js +++ b/build/badgee.umd.js @@ -1,2 +1,2 @@ -!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):n.badgee=t()}(this,function(){var n=function(){},t=function(n,t){for(var e in n)t(n[e],e)},e=function(n,t){for(var e in t)n[e]=t[e];return n},r=function(n){return e({},n)},u=function(n,t){return e(r(n),t)},o=("undefined"!=typeof window?window:global).console||{},i=["debug","error","group","groupCollapsed","info","log","warn"],f=["clear","dir","groupEnd"],c=function(n){t(i,n)},l=function(n){t(f,n)},a=function(n){c(n),l(n)};a(function(t){o[t]=o[t]||n});var d={enabled:!0,styled:!0},s=r(d),p=function(n){return n&&(s=u(d,n)),s},b={},g={"border-radius":"2px",padding:"1px 3px",margin:"0 1px",color:"white"},h=function(n,t){if(null!=n&&null!=t)t=u(g,t),b[n]=t;else if(null!=n)return b[n];return Object.keys(b)},v=function(n){return null!=n&&(g=n),g},y=function(n){var e="";return t(b[n],function(n,t){e+=t+":"+n+";"}),e},w=function(n,t){return u(n,{background:t})};t(["green","red"],function(n){h(n,w({},n))}),h("orange",w({color:"black"},"orange"));var x=null,m=null,j=function(n){return null!=x&&!x.test(n)||null!=m&&m.test(n)},k={},C=function(n,t,e){var r=[];if(e){var u=k[e],o=u[0],i=u[1],f=u[2];r=C(o.label,i,f)}if(n){var c=t?"%c"+n:"["+n+"]";r[0]=""+(r[0]||"")+c}return t&&r.push(y(t)),r},E=function(t,e){var r=this,u=C(this.label,!!s.styled&&t,e);!s.enabled||j(u[0])?a(function(t){return r[t]=n}):(c(function(n){r[n]=(t=o[n]).bind.apply(t,[o].concat(u));var t}),l(function(n){r[n]=o[n].bind(o)}))},O=function(n,t,e){this.label=n,E.bind(this,t,e)(),k[n]=[this,t,e]};O.prototype.define=function(n,t){return new O(n,t,this.label)};var S=function(){t(k,function(n){var t=n[0],e=n[1],r=n[2];E.bind(t,e,r)()})},q=new O;q.get=function(n){return(k[n]||{})[0]};try{q.log()}catch(n){q=u(o,{define:function(){return q},get:function(){return q}})}return q.style=h,q.defaultStyle=v,q.filter=function(n){return{none:function(){return x=null,m=null,n(),this},include:function(t){return t!==x&&(x=t,n()),this},exclude:function(t){return t!==m&&(m=t,n()),this}}}(S),q.config=function(n){return n&&"object"==typeof n&&(p(n),S()),s},q}); -//# sourceMappingURL=badgee.umd.js.map \ No newline at end of file +!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):n.badgee=t()}(this,function(){var n=function(){},t=function(n,t){for(var e in n)t(n[e],e)},e=function(n,t){for(var e in t)n[e]=t[e];return n},r=function(n){return e({},n)},u=function(n,t){return e(r(n),t)},o=("undefined"!=typeof window?window:global).console||{},i=["debug","error","group","groupCollapsed","info","log","warn"],f=["clear","dir","groupEnd"],c=function(n){t(i,n)},l=function(n){t(f,n)},a=function(n){c(n),l(n)};a(function(t){o[t]=o[t]||n});var d={enabled:!0,styled:!0},s=r(d),p=function(n){return n&&(s=u(d,n)),s},b={},g={"border-radius":"2px",padding:"1px 3px",margin:"0 1px",color:"white"},h=function(n,t){if(null!=n&&null!=t)t=u(g,t),b[n]=t;else if(null!=n)return b[n];return Object.keys(b)},v=function(n){var e="";return t(b[n],function(n,t){e+=t+":"+n+";"}),e},y=function(n,t){return u(n,{background:t})};t(["green","red"],function(n){h(n,y({},n))}),h("orange",y({color:"black"},"orange"));var w=null,x=null,m=function(n){return null!=w&&!w.test(n)||null!=x&&x.test(n)},j={},k=function(n,t,e){var r=[];if(e){var u=j[e],o=u[0],i=u[1],f=u[2];r=k(o.label,i,f)}if(n){var c=t?"%c"+n:"["+n+"]";r[0]=""+(r[0]||"")+c}return t&&r.push(v(t)),r},C=function(t,e){var r=this,u=k(this.label,!!s.styled&&t,e);!s.enabled||m(u[0])?a(function(t){return r[t]=n}):(c(function(n){r[n]=(t=o[n]).bind.apply(t,[o].concat(u));var t}),l(function(n){r[n]=o[n].bind(o)}))},E=function(n,t,e){this.label=n,C.bind(this,t,e)(),j[n]=[this,t,e]};E.prototype.define=function(n,t){return new E(n,t,this.label)};var O=function(){t(j,function(n){var t=n[0],e=n[1],r=n[2];C.bind(t,e,r)()})},S=new E;S.get=function(n){return(j[n]||{})[0]};try{S.log()}catch(n){S=u(o,{define:function(){return S},get:function(){return S}})}return S.style=h,S.defaultStyle=function(n){return null!=n&&(g=n),g},S.filter=function(n){return{none:function(){return w=null,x=null,n(),this},include:function(t){return t!==w&&(w=t,n()),this},exclude:function(t){return t!==x&&(x=t,n()),this}}}(O),S.config=function(n){return n&&"object"==typeof n&&(p(n),O()),s},S}); +//# sourceMappingURL=build/badgee.umd.js.map \ No newline at end of file diff --git a/build/badgee.umd.js.map b/build/badgee.umd.js.map index b1050e7..05ed1ab 100644 --- a/build/badgee.umd.js.map +++ b/build/badgee.umd.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/utils.js","../src/console.js","../src/config.js","../src/styles.js","../src/filter.js","../src/badgee.js"],"names":["const","noop","each","items","fn","i","_extend","dest","obj","clone","extend","console","this","methods","unformatableMethods","eachFormatableMethod","eachUnformatableMethod","eachMethod","method","defaults","enabled","styled","config","configure","conf","store","defaultsStyle","border-radius","padding","margin","color","styles","name","style","Object","keys","defaultStyle","style2Str","let","res","k","buildStyle","base","bkgColor","background","include","exclude","isFiltered","str","test","argsForBadgee","label","parentName","args","ref","badgee","parent","formatedLabel","push","_defineMethods","bind","apply","concat","Badgee","prototype","define","redefineMethodsForAllBadges","b","get","log","e","filter","onFilterChange","none","matcher"],"mappings":"qKAAOA,GAAMC,GAAO,aAEPC,EAAO,SAACC,EAAOC,GAC1B,IAAKJ,GAAMK,KAAKF,GACdC,EAAGD,EAAME,GAAIA,IAIXC,EAAU,SAACC,EAAMC,GACrB,IAAKR,GAAMK,KAAKG,GAAKD,EAAKF,GAAKG,EAAIH,EACnC,OAAOE,IAEIE,EAAQ,SAACD,GAAK,MAAGF,MAAYE,IAC7BE,EAAS,SAACH,EAAMC,GAAK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Ac,GAIxC,KACEgB,EAAEE,MACF,MAAOC,GACPH,EAAIzD,EAAOC,GACTsD,OAAS,WAAG,MAAGE,IACfC,IAAS,WAAG,MAAGD,YAKnBA,GAAElC,MAAQF,EACVoC,EAAE/B,aAAgBA,EAClB+B,EAAEI,ODnGuB,SAACC,GACxB,OACEC,KAAI,WAKF,MAJA5B,GAAU,KACVC,EAAU,KAEV0B,IACO5D,MAGTiC,QAAO,SAAC6B,GAKN,MAJIA,KAAY7B,IACdA,EAAU6B,EACVF,KAEK5D,MAGTkC,QAAO,SAAC4B,GAKN,MAJIA,KAAY5B,IACdA,EAAU4B,EACVF,KAEK5D,QC4EQsD,GACrBC,EAAE7C,OAAS,SAASE,GAMlB,MAJIA,IAAsB,gBAAPA,KACjBD,EAAUC,GACV0C,KAEK5C,GAGM6C","file":"badgee.umd.js","sourcesContent":["export const noop = () => {}\n\nexport const each = (items, fn) => {\n for (const i in items) {\n fn(items[i], i)\n }\n}\n\nconst _extend = (dest, obj) => {\n for (const i in obj) dest[i] = obj[i]\n return dest\n}\nexport const clone = (obj) => _extend({}, obj)\nexport const extend = (dest, obj) => _extend(clone(dest), obj)\n","import { noop, each } from './utils.js'\n// Homogeneisation of the console API on different browsers\n// - add compat console object if not available\n// - some methods might not be defined. fake them with `noop` function\n\nconst console = this.console || {};\n\n// For the record, every single console methods and properties :\n// [\"memory\", \"exception\", \"debug\", \"error\", \"info\", \"log\", \"warn\", \"dir\",\n// \"dirxml\", \"table\", \"trace\", \"assert\", \"count\", \"markTimeline\", \"profile\",\n// \"profileEnd\", \"time\", \"timeEnd\", \"timeStamp\", \"timeline\", \"timelineEnd\",\n// \"group\", \"groupCollapsed\", \"groupEnd\", \"clear\"]\n//\n// Focus on logging methods and ignore profiling/timeline methods or less used methods\nconst methods = ['debug', 'error', 'group', 'groupCollapsed', 'info', 'log', 'warn'];\nconst unformatableMethods = ['clear', 'dir', 'groupEnd'];\n\nexport const eachFormatableMethod = (fn) => { each(methods, fn) }\nexport const eachUnformatableMethod = (fn) => { each(unformatableMethods, fn) }\nexport const eachMethod = (fn) => {\n eachFormatableMethod(fn)\n eachUnformatableMethod(fn)\n}\n\neachMethod((method) => {\n console[method] = console[method] || noop;\n})\n\nexport default console\n","import { clone, extend } from './utils';\n\n// default configuration\nconst defaults = {\n enabled : true,\n styled : true\n};\n\nlet config = clone(defaults);\n\nconst configure = function(conf) {\n // update conf\n if (conf) {\n config = extend(defaults, conf);\n }\n\n // return current conf\n return config;\n};\n\n// export default configure\nexport { config, configure }\n","import { each, extend } from './utils';\n\n// Create store to save styles\nconst store = {};\n\n// Default properties for styles\nlet defaultsStyle = {\n 'border-radius': '2px',\n 'padding' : '1px 3px',\n 'margin' : '0 1px',\n 'color' : 'white'\n};\n\n// define a new style or list existing ones\nexport const styles = (name, style) => {\n if (name != null && style != null) {\n style = extend(defaultsStyle, style);\n store[name] = style;\n }\n else if (name != null) {\n return store[name];\n }\n return Object.keys(store);\n}\n\nexport const defaultStyle = (style) => {\n if (style != null) {\n defaultsStyle = style;\n }\n return defaultsStyle;\n}\n\nexport const style2Str = (name) => {\n let res = ''\n each(store[name], (style, k) => {\n res += `${k}:${style};`\n })\n return res\n}\n\n// define a few styles\nconst buildStyle = (base, bkgColor) => extend(base, {'background': bkgColor})\n\neach(['green', 'red'], (color) => {\n styles(color, buildStyle({}, color))\n})\nstyles('orange', buildStyle({'color': 'black'}, 'orange'));\n","let include = null\nlet exclude = null\n\nexport const isFiltered = (str) => {\n return ((include != null) && !include.test(str)) //isntIncluded\n || ((exclude != null) && exclude.test(str)) // isExcluded\n}\n\nexport const getFilter = (onFilterChange) => {\n return {\n none() {\n include = null\n exclude = null\n\n onFilterChange()\n return this;\n },\n\n include(matcher) {\n if (matcher !== include) {\n include = matcher\n onFilterChange()\n }\n return this\n },\n\n exclude(matcher) {\n if (matcher !== exclude) {\n exclude = matcher\n onFilterChange()\n }\n return this\n }\n };\n}\n","/* eslint-disable no-console */\n/*! badgee v1.2.0 - MIT license */\nimport { noop, extend, each } from './utils.js'\nimport console, {\n eachMethod, eachFormatableMethod, eachUnformatableMethod\n} from './console.js'\nimport { config, configure } from './config.js';\nimport { styles, defaultStyle, style2Str } from './styles.js';\nimport { getFilter, isFiltered } from './filter.js';\n\nconst store = {};\n\n// Given a label, style and parentName, generate the full list of arguments to\n// pass to console method to get a foramted output\nconst argsForBadgee = function(label, style, parentName) {\n let args = [];\n\n if (parentName) {\n const [badgee, style, parent] = store[parentName];\n args = argsForBadgee(badgee.label, style, parent);\n }\n\n if (label) {\n // concat formated label for badges output\n // (i.e. \"%cbadge1%cbadge2\" with style or \"[badge1][badge2] without style\")\n const formatedLabel = !style ? `[${label}]` : `%c${label}`\n args[0] = `${args[0] || ''}${formatedLabel}`\n }\n\n if (style) {\n args.push(style2Str(style));\n }\n\n return args;\n};\n\n// Define Badgee methods form console object\n// Intended to be called in a 'Badgee' instance context (e.g. with 'bind()')\nconst _defineMethods = function(style, parentName) {\n // get arguments to pass to console object\n const args = argsForBadgee(this.label, config.styled ? style : false, parentName);\n\n if (!config.enabled || isFiltered(args[0])) {\n // disable everything\n eachMethod((method) => this[method] = noop)\n }\n else {\n // Define Badgee 'formatable' methods form console object\n eachFormatableMethod((method) => {\n this[method] = console[method].bind(console, ...args);\n });\n\n // Define Badgee 'unformatable' methods form console object\n eachUnformatableMethod((method) => {\n this[method] = console[method].bind(console);\n });\n }\n\n};\n\n// ==================================\n\nclass Badgee {\n\n constructor(label, style, parentName) {\n // Define Badgee methods form console object\n this.label = label;\n _defineMethods.bind(this, style, parentName)();\n\n // Store instance for later reference\n store[label] = [this, style, parentName];\n }\n\n // Defines a new Badgee instance with @ as parent Badge\n define(label, style) {\n return new Badgee(label, style, this.label);\n }\n}\n\n// ==================================\n\nconst redefineMethodsForAllBadges = () => {\n each(store, ([badgee, style, parent]) => {\n _defineMethods.bind(badgee, style, parent)()\n })\n}\n\n// Create public Badgee instance\nlet b = new Badgee;\n\n// Augment public instance with getter method\nb.get = (label) => (store[label] || {})[0];\n\n// Some browsers don't allow to use bind on console object anyway\n// fallback to default if needed\ntry {\n b.log();\n} catch (e) {\n b = extend(console, {\n define : () => b,\n get : () => b,\n });\n}\n\n// Augment public instance with a few utility methods\nb.style = styles;\nb.defaultStyle = defaultStyle;\nb.filter = getFilter(redefineMethodsForAllBadges)\nb.config = function(conf) {\n // when conf is updated, redefine every badgee method\n if (conf && typeof conf==='object') {\n configure(conf)\n redefineMethodsForAllBadges();\n }\n return config;\n};\n\nexport default b;\n"]} \ No newline at end of file +{"version":3,"sources":["../src/utils.js","../src/console.js","../src/config.js","../src/styles.js","../src/filter.js","../src/badgee.js"],"names":["const","noop","each","items","fn","i","_extend","dest","obj","clone","extend","console","this","methods","unformatableMethods","eachFormatableMethod","eachUnformatableMethod","eachMethod","method","defaults","enabled","styled","config","configure","conf","store","defaultsStyle","border-radius","padding","margin","color","styles","name","style","Object","keys","style2Str","let","res","k","buildStyle","base","bkgColor","background","include","exclude","isFiltered","str","test","argsForBadgee","label","parentName","args","ref","badgee","parent","formatedLabel","push","_defineMethods","bind","apply","concat","Badgee","prototype","define","redefineMethodsForAllBadges","b","get","log","e","defaultStyle","filter","onFilterChange","none","matcher","getFilter"],"mappings":"qKAAOA,IAAMC,EAAO,aAEPC,EAAO,SAACC,EAAOC,GAC1B,IAAKJ,IAAMK,KAAKF,EACdC,EAAGD,EAAME,GAAIA,IAIXC,EAAU,SAACC,EAAMC,GACrB,IAAKR,IAAMK,KAAKG,EAAKD,EAAKF,GAAKG,EAAIH,GACnC,OAAOE,GAEIE,EAAQ,SAACD,GAAK,OAAGF,KAAYE,IAC7BE,EAAS,SAACH,EAAMC,GAAK,OAAGF,EAAQG,EAAMF,GAAOC,ICRpDG,GAAUC,oBAAAA,OAAAA,OAAAA,QAAKD,YASfE,GAAuB,QAAS,QAAS,QAAS,iBAAkB,OAAQ,MAAO,QACnFC,GAAuB,QAAS,MAAO,YAEhCC,EAAyB,SAACX,GAASF,EAAKW,EAAST,IACjDY,EAAyB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U,KACVC,EAAU,KAEV2B,IACO5D,MAGTgC,QAAO,SAAC8B,GAKN,OAJIA,IAAY9B,IACdA,EAAU8B,EACVF,KAEK5D,MAGTiC,QAAO,SAAC6B,GAKN,OAJIA,IAAY7B,IACdA,EAAU6B,EACVF,KAEK5D,OC4EF+D,CAAUV,GACrBC,EAAE5C,OAAS,SAASE,GAMlB,OAJIA,GAAsB,iBAAPA,IACjBD,EAAUC,GACVyC,KAEK3C,GAGM4C","sourcesContent":["export const noop = () => {}\n\nexport const each = (items, fn) => {\n for (const i in items) {\n fn(items[i], i)\n }\n}\n\nconst _extend = (dest, obj) => {\n for (const i in obj) dest[i] = obj[i]\n return dest\n}\nexport const clone = (obj) => _extend({}, obj)\nexport const extend = (dest, obj) => _extend(clone(dest), obj)\n","import { noop, each } from './utils.js'\n// Homogeneisation of the console API on different browsers\n// - add compat console object if not available\n// - some methods might not be defined. fake them with `noop` function\n\nconst console = this.console || {};\n\n// For the record, every single console methods and properties :\n// [\"memory\", \"exception\", \"debug\", \"error\", \"info\", \"log\", \"warn\", \"dir\",\n// \"dirxml\", \"table\", \"trace\", \"assert\", \"count\", \"markTimeline\", \"profile\",\n// \"profileEnd\", \"time\", \"timeEnd\", \"timeStamp\", \"timeline\", \"timelineEnd\",\n// \"group\", \"groupCollapsed\", \"groupEnd\", \"clear\"]\n//\n// Focus on logging methods and ignore profiling/timeline methods or less used methods\nconst methods = ['debug', 'error', 'group', 'groupCollapsed', 'info', 'log', 'warn'];\nconst unformatableMethods = ['clear', 'dir', 'groupEnd'];\n\nexport const eachFormatableMethod = (fn) => { each(methods, fn) }\nexport const eachUnformatableMethod = (fn) => { each(unformatableMethods, fn) }\nexport const eachMethod = (fn) => {\n eachFormatableMethod(fn)\n eachUnformatableMethod(fn)\n}\n\neachMethod((method) => {\n console[method] = console[method] || noop;\n})\n\nexport default console\n","import { clone, extend } from './utils';\n\n// default configuration\nconst defaults = {\n enabled : true,\n styled : true\n};\n\nlet config = clone(defaults);\n\nconst configure = function(conf) {\n // update conf\n if (conf) {\n config = extend(defaults, conf);\n }\n\n // return current conf\n return config;\n};\n\n// export default configure\nexport { config, configure }\n","import { each, extend } from './utils';\n\n// Create store to save styles\nconst store = {};\n\n// Default properties for styles\nlet defaultsStyle = {\n 'border-radius': '2px',\n 'padding' : '1px 3px',\n 'margin' : '0 1px',\n 'color' : 'white'\n};\n\n// define a new style or list existing ones\nexport const styles = (name, style) => {\n if (name != null && style != null) {\n style = extend(defaultsStyle, style);\n store[name] = style;\n }\n else if (name != null) {\n return store[name];\n }\n return Object.keys(store);\n}\n\nexport const defaultStyle = (style) => {\n if (style != null) {\n defaultsStyle = style;\n }\n return defaultsStyle;\n}\n\nexport const style2Str = (name) => {\n let res = ''\n each(store[name], (style, k) => {\n res += `${k}:${style};`\n })\n return res\n}\n\n// define a few styles\nconst buildStyle = (base, bkgColor) => extend(base, {'background': bkgColor})\n\neach(['green', 'red'], (color) => {\n styles(color, buildStyle({}, color))\n})\nstyles('orange', buildStyle({'color': 'black'}, 'orange'));\n","let include = null\nlet exclude = null\n\nexport const isFiltered = (str) => {\n return ((include != null) && !include.test(str)) //isntIncluded\n || ((exclude != null) && exclude.test(str)) // isExcluded\n}\n\nexport const getFilter = (onFilterChange) => {\n return {\n none() {\n include = null\n exclude = null\n\n onFilterChange()\n return this;\n },\n\n include(matcher) {\n if (matcher !== include) {\n include = matcher\n onFilterChange()\n }\n return this\n },\n\n exclude(matcher) {\n if (matcher !== exclude) {\n exclude = matcher\n onFilterChange()\n }\n return this\n }\n };\n}\n","/* eslint-disable no-console */\n/*! badgee v1.2.0 - MIT license */\nimport { noop, extend, each } from './utils.js'\nimport console, {\n eachMethod, eachFormatableMethod, eachUnformatableMethod\n} from './console.js'\nimport { config, configure } from './config.js';\nimport { styles, defaultStyle, style2Str } from './styles.js';\nimport { getFilter, isFiltered } from './filter.js';\n\nconst store = {};\n\n// Given a label, style and parentName, generate the full list of arguments to\n// pass to console method to get a foramted output\nconst argsForBadgee = function(label, style, parentName) {\n let args = [];\n\n if (parentName) {\n const [badgee, style, parent] = store[parentName];\n args = argsForBadgee(badgee.label, style, parent);\n }\n\n if (label) {\n // concat formated label for badges output\n // (i.e. \"%cbadge1%cbadge2\" with style or \"[badge1][badge2] without style\")\n const formatedLabel = !style ? `[${label}]` : `%c${label}`\n args[0] = `${args[0] || ''}${formatedLabel}`\n }\n\n if (style) {\n args.push(style2Str(style));\n }\n\n return args;\n};\n\n// Define Badgee methods form console object\n// Intended to be called in a 'Badgee' instance context (e.g. with 'bind()')\nconst _defineMethods = function(style, parentName) {\n // get arguments to pass to console object\n const args = argsForBadgee(this.label, config.styled ? style : false, parentName);\n\n if (!config.enabled || isFiltered(args[0])) {\n // disable everything\n eachMethod((method) => this[method] = noop)\n }\n else {\n // Define Badgee 'formatable' methods form console object\n eachFormatableMethod((method) => {\n this[method] = console[method].bind(console, ...args);\n });\n\n // Define Badgee 'unformatable' methods form console object\n eachUnformatableMethod((method) => {\n this[method] = console[method].bind(console);\n });\n }\n\n};\n\n// ==================================\n\nclass Badgee {\n\n constructor(label, style, parentName) {\n // Define Badgee methods form console object\n this.label = label;\n _defineMethods.bind(this, style, parentName)();\n\n // Store instance for later reference\n store[label] = [this, style, parentName];\n }\n\n // Defines a new Badgee instance with @ as parent Badge\n define(label, style) {\n return new Badgee(label, style, this.label);\n }\n}\n\n// ==================================\n\nconst redefineMethodsForAllBadges = () => {\n each(store, ([badgee, style, parent]) => {\n _defineMethods.bind(badgee, style, parent)()\n })\n}\n\n// Create public Badgee instance\nlet b = new Badgee;\n\n// Augment public instance with getter method\nb.get = (label) => (store[label] || {})[0];\n\n// Some browsers don't allow to use bind on console object anyway\n// fallback to default if needed\ntry {\n b.log();\n} catch (e) {\n b = extend(console, {\n define : () => b,\n get : () => b,\n });\n}\n\n// Augment public instance with a few utility methods\nb.style = styles;\nb.defaultStyle = defaultStyle;\nb.filter = getFilter(redefineMethodsForAllBadges)\nb.config = function(conf) {\n // when conf is updated, redefine every badgee method\n if (conf && typeof conf==='object') {\n configure(conf)\n redefineMethodsForAllBadges();\n }\n return config;\n};\n\nexport default b;\n"]} \ No newline at end of file diff --git a/package.json b/package.json index 8f92771..08252d4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "badgee", "author": "Olivier Audard ", - "version": "2.0.2", + "version": "2.0.3", "description": "a browser console improvement", "main": "build/badgee.js", "module": "build/badgee.es.js",