diff --git a/README.md b/README.md index 08e597a..1fcc435 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ can download it from here. > `ulog.min.js` lazy loads `ulog.lazy.min.js` on demand, so make sure to include both files in your download -* [full.min.js](https://unpkg.com/ulog@2.0.0-beta.18/full.min.js) (~5.7kB minified and gzipped) +* [full.min.js](https://unpkg.com/ulog@2.0.0-beta.18/full.min.js) (~5.6kB minified and gzipped) > Full bundle, no lazy loading diff --git a/mods/formats/index.js b/mods/formats/index.js index bdb4598..0315961 100644 --- a/mods/formats/index.js +++ b/mods/formats/index.js @@ -2,8 +2,7 @@ var parse = require('kurly/parse') var pipe = require('kurly/pipe') var grab = require('../../core/grab') var console = require('../channels/console') -var makeStatic = require('./utils').makeStatic -var makeStaticPipe = require('./utils').makeStaticPipe +var firefox = require('../colors/utils').firefox var applyFormatting = require('./apply-formatting') var applyAlignment = require('./apply-alignment') @@ -64,9 +63,8 @@ module.exports = { .map(toTag) .filter(skip) .reduce(function(r,fmt){ - var msg = makeStatic(fmt) - return applyFormatting(rec, fmt, msg, r) - }, ['']) + return applyFormatting(rec, fmt, fmt, r)} + , ['']) // apply alignment if needed applyAlignment(rec, args) // bind the output and arguments to the log method @@ -77,7 +75,19 @@ module.exports = { } else { return makeDynamicPipe(output, method, rec, line) } - } + } + + function makeStaticPipe(output, method, rec, args) { + return Object.defineProperty({}, 'out', { + get: function(){ + return method.bind.apply(method, + [output].concat(firefox && (rec.level === 'trace') ? [] : args.map(function(arg){ + return typeof arg == 'function' ? arg() : arg + }) + )) + } + }).out + } function makeDynamicPipe(output, method, rec, line) { // set up a dynamic pipeline as a function @@ -101,11 +111,12 @@ module.exports = { }})(rec) } - function toTag(node) {return ( - !node || !node.tag ? node : - node.tag - )} + function toTag(node) { + return !node || !node.tag ? node : node.tag + } - function skip(tag){return (typeof tag != 'string') || tag.trim().length} + function skip(tag){ + return (typeof tag != 'string') || tag.trim().length + } }, } diff --git a/mods/formats/utils.browser.js b/mods/formats/utils.browser.js deleted file mode 100644 index 8d96284..0000000 --- a/mods/formats/utils.browser.js +++ /dev/null @@ -1,19 +0,0 @@ -// Detect V8 in browsers to compensate for a bug where toString is called twice -var bug = (typeof Intl != 'undefined') && Intl.v8BreakIterator -var firefox = require('../colors/utils').firefox - -module.exports.makeStatic = function(fmt){ - if (bug && (typeof fmt == 'function') && (fmt.toString === fmt)) { - var skip = bug - fmt.toString = function(){ - if (skip) return skip = '' - skip = bug - return fmt() - } - } - return fmt -} - -module.exports.makeStaticPipe = function(output, method, rec, args) { - return method.bind.apply(method, [output].concat(firefox && (rec.level === 'trace') ? [] : args)) -} diff --git a/mods/formats/utils.js b/mods/formats/utils.js deleted file mode 100644 index 5a47887..0000000 --- a/mods/formats/utils.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports.makeStatic = function(fmt){ - fmt.toString = fmt - return fmt -} - -module.exports.makeStaticPipe = function(output, method, rec, args) { - return method.bind.apply(method, [output].concat(args)) -} diff --git a/package-lock.json b/package-lock.json index 23e92aa..240e384 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "ulog", - "version": "2.0.0-beta.17", + "version": "2.0.0-beta.18", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index cc799ef..05a0b07 100644 --- a/package.json +++ b/package.json @@ -35,8 +35,7 @@ "./mods/config/watch.js": "./mods/config/watch.browser.js", "./mods/levels/default.js": "./mods/levels/default.browser.js", "./mods/formats/aligned.js": "./mods/formats/aligned.browser.js", - "./mods/formats/default.js": "./mods/formats/default.browser.js", - "./mods/formats/utils.js": "./mods/formats/utils.browser.js" + "./mods/formats/default.js": "./mods/formats/default.browser.js" }, "keywords": [ "ulog",