pax_global_header00006660000000000000000000000064127774320100014515gustar00rootroot0000000000000052 comment=696f343617dce122ae03dc95e47050e48e87e3d4 debug-fabulous-0.0.4/000077500000000000000000000000001277743201000144225ustar00rootroot00000000000000debug-fabulous-0.0.4/.editorconfig000066400000000000000000000005661277743201000171060ustar00rootroot00000000000000# EditorConfig helps developers define and maintain consistent # coding styles between different editors and IDEs # editorconfig.org root = true [*] # Change these settings to your own preference indent_style = space indent_size = 2 # We recommend you to keep these unchanged end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true debug-fabulous-0.0.4/.eslintrc000066400000000000000000000005311277743201000162450ustar00rootroot00000000000000{ "ecmaFeatures": { "arrowFunctions": true }, "globals": { "expect": true, "describe": true, "it": true, "xit": true, "spyOn": true }, "rules": { "no-unused-vars": ["error", { "vars": "all", "args": "after-used" }] }, "env": { "browser": true, "node": true }, "parser": "babel-eslint" } debug-fabulous-0.0.4/.gitignore000066400000000000000000000002321277743201000164070ustar00rootroot00000000000000*/*.iml *.iml .idea */log/* log/ logs/ tmp/ .log #OSX .DS_Store nohup.out *.xml coverage/ node_modules/ build/ npm-debug.log bower_components/ .versions debug-fabulous-0.0.4/.npmignore000066400000000000000000000001151277743201000164160ustar00rootroot00000000000000.* test/ *.json .gitignore travis.yml *.md node_modules/ .versions .DS_Store debug-fabulous-0.0.4/LICENSE000066400000000000000000000020741277743201000154320ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2016 Nicholas McCready Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. debug-fabulous-0.0.4/README.md000066400000000000000000000014241277743201000157020ustar00rootroot00000000000000# debug-fabulous ## Install `npm install --save debug-fabulous` # Purpose Wrapper / Extension around [visionmedia's debug](https://github.com/visionmedia/debug) to allow lazy evaluation of debugging via closure handling. This library essentially wraps two things: - [lazy-debug](https://github.com/apihlaja/lazy-debug) for easy namespace naming by files - [lazy-eval](./src/lazy-eval.js) debug closure handling ## Use For thorough usage see the [tests](./test). ## lazy-eval ```js var debug = require('')(); // force namespace to be enabled otherwise it assumes process.env.DEBUG is setup // debug.save('myNamespace'); // debug.enable(debug.load()) debug = debug('debug-fabulous'); debug(function(){return 'ya something to log' + someLargeHarryString;}); debug('small out'); ``` debug-fabulous-0.0.4/index.js000066400000000000000000000003571277743201000160740ustar00rootroot00000000000000var wrapLazyEval = require('./src/lazy-eval'), wrapLazy = require('./src/lazy-debug'); module.exports = function (debug) { debug = debug ? debug : require('debug') debug = wrapLazyEval(debug); wrapLazy(debug); return debug; } debug-fabulous-0.0.4/package.json000066400000000000000000000012251277743201000167100ustar00rootroot00000000000000{ "name": "debug-fabulous", "version": "0.0.4", "description": "visionmedia debug extensions rolled into one", "main": "index.js", "scripts": { "test": "mocha ./test/**/*test.js" }, "repository": { "type": "git", "url": "http://www.github.com/nmccready/debug-fabulous" }, "keywords": [ "debug", "lazy", "lazy-eval" ], "author": "Nicholas McCready", "license": "MIT", "dependencies": { "debug": "2.X", "lazy-debug-legacy": "0.0.X", "object-assign": "4.1.0" }, "devDependencies": { "babel-eslint": "7.X", "chai": "3.X", "eslint": "3.X", "hook-std": "0.X", "mocha": "3.X" } } debug-fabulous-0.0.4/src/000077500000000000000000000000001277743201000152115ustar00rootroot00000000000000debug-fabulous-0.0.4/src/lazy-debug.js000066400000000000000000000003501277743201000176100ustar00rootroot00000000000000var lazyDebug = require('lazy-debug-legacy'); function wrapLazy(debug){ debug.get = lazyDebug.get; debug.getModuleDebugName = lazyDebug.getModuleDebugName; debug.configure = lazyDebug.configure; } module.exports = wrapLazy; debug-fabulous-0.0.4/src/lazy-eval.js000066400000000000000000000020451277743201000174540ustar00rootroot00000000000000 var slice = [].slice, objectAssign = require('object-assign'); function _resolveOutput(func, bindThis) { var wrapped = function() { var args; args = 1 <= arguments.length ? slice.call(arguments, 0) : []; // lazy function eval to keep output memory pressure down, if not used if (typeof args[0] === 'function') { args[0] = args[0](); } return func.apply(bindThis, args); }; objectAssign(wrapped, func); return wrapped; }; function wrapEval(debug) { var debugOrig = debug, noop = function(){}; debug = function (namespace) { var instance = debugOrig(namespace); // if we're not enabled then don't attempt to log anything // if a debug namespace wraps its debug in a closure then it never allocates anything but the function itself if (!instance.enabled){ objectAssign(noop, instance); instance = noop; } else { instance = _resolveOutput(instance); } return instance; } objectAssign(debug, debugOrig); return debug; } module.exports = wrapEval; debug-fabulous-0.0.4/test/000077500000000000000000000000001277743201000154015ustar00rootroot00000000000000debug-fabulous-0.0.4/test/lazy-debug/000077500000000000000000000000001277743201000174445ustar00rootroot00000000000000debug-fabulous-0.0.4/test/lazy-debug/dir1/000077500000000000000000000000001277743201000203035ustar00rootroot00000000000000debug-fabulous-0.0.4/test/lazy-debug/dir1/index.js000066400000000000000000000000661277743201000217520ustar00rootroot00000000000000 module.exports = function () { return __filename; }debug-fabulous-0.0.4/test/lazy-debug/dir1/submodule1.js000066400000000000000000000000661277743201000227230ustar00rootroot00000000000000 module.exports = function () { return __filename; }debug-fabulous-0.0.4/test/lazy-debug/lazy-debug-test.js000066400000000000000000000025301277743201000230220ustar00rootroot00000000000000var expect = require('chai').expect; var path = require('path'); var fileNamespace = path.basename(__filename).replace(path.extname(__filename), '') describe('lazy-debug-legacy', function () { var lazyDebug = require('../../index.js')() describe('#get(filename, submoduleName)', function () { it('returns named debug instance', function () { lazyDebug.get(__filename)('it works, I hope'); }); }); describe('#getModuleDebugName(filename, submoduleName)', function () { it('gives debug name for file', function () { var name = lazyDebug.getModuleDebugName(__filename); expect(name).to.equal('test:' + 'lazy-debug:' + fileNamespace); }); it('attaches submodule name if given', function () { var name = lazyDebug.getModuleDebugName(__filename, 'test2'); expect(name).to.equal('test:' + 'lazy-debug:' + fileNamespace + ':test2'); }); }); describe('#configure', function () { it('can set filter function', function () { lazyDebug.configure({ filter: function (pathArr) { if ( pathArr && pathArr.length > 0 ) { if ( pathArr[0] === 'test' ) pathArr.shift(); } return pathArr; } }); var name = lazyDebug.getModuleDebugName(__filename); expect(name).to.equal('lazy-debug:' + fileNamespace); }); }); }); debug-fabulous-0.0.4/test/lazy-eval/000077500000000000000000000000001277743201000173055ustar00rootroot00000000000000debug-fabulous-0.0.4/test/lazy-eval/lazy-eval-test.js000066400000000000000000000027401277743201000225270ustar00rootroot00000000000000var expect = require('chai').expect; hook = require('hook-std') describe('lazy-eval', function () { var debug; describe('enabled', function () { before(function () { debug = require('../../')(); debug.save('enabled'); debug.enable(debug.load()) debug = debug('enabled'); }) it('handles functions', function () { unhook = hook.stderr(function (str) { expect(str.match(/crap/)).to.be.ok; expect(str.match(/enabled/)).to.be.ok; }); debug(function () {return 'crap';}); unhook(); }); it('normal', function () { unhook = hook.stderr(function (str) { expect(str.match(/crap/)).to.be.ok; expect(str.match(/enabled/)).to.be.ok; }); debug('crap'); unhook(); }); }); describe('disabled', function () { before(function () { debug = require('../../')(); debug.save(null); debug.enable(debug.load()) debug = debug('disabled'); }) it('handles functions', function () { var called = false; unhook = hook.stderr(function () { called = true; }); debug(function () { called = true; return 'crap'; }); unhook(); expect(called).to.not.be.ok; }); it('normal', function () { var called = false; unhook = hook.stderr(function () { called = true; }); debug('crap'); unhook(); expect(called).to.not.be.ok; }); }); });