debug-fabulous 0.0.2 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -9
- package/index.js +2 -11
- package/package.json +8 -4
- package/src/debugFabFactory.js +18 -0
- package/src/formatArgs.js +24 -0
- package/src/lazy-eval.js +13 -13
- package/src/spawn.js +34 -0
- package/src/lazy-debug.js +0 -9
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
## debug-fabulous [![NPM version][npm-image]][npm-url] [![build status][travis-image]][travis-url]
|
|
2
2
|
|
|
3
3
|
## Install
|
|
4
4
|
`npm install --save debug-fabulous`
|
|
@@ -9,21 +9,29 @@ Wrapper / Extension around [visionmedia's debug](https://github.com/visionmedia/
|
|
|
9
9
|
|
|
10
10
|
This library essentially wraps two things:
|
|
11
11
|
|
|
12
|
-
- [lazy-
|
|
13
|
-
- [
|
|
12
|
+
- [lazy-eval](./src/lazy-eval.js): debug closure handling
|
|
13
|
+
- [spawn](./src/spawn.js): spawns off existing namespaces for a sub namespace.
|
|
14
14
|
|
|
15
|
-
## Use
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
## Example:
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
For usage see the [tests](./test) or the example below.
|
|
20
19
|
|
|
21
20
|
```js
|
|
22
21
|
var debug = require('')();
|
|
23
22
|
// force namespace to be enabled otherwise it assumes process.env.DEBUG is setup
|
|
24
|
-
// debug.save('
|
|
23
|
+
// debug.save('namespace');
|
|
25
24
|
// debug.enable(debug.load())
|
|
26
|
-
debug = debug('
|
|
25
|
+
debug = debug('namespace'); // debugger in the namespace
|
|
27
26
|
debug(function(){return 'ya something to log' + someLargeHarryString;});
|
|
28
|
-
debug('small out');
|
|
27
|
+
debug('small out'); // prints namespace small out
|
|
28
|
+
var childDbg = debug.spawn('child'); // debugger in the namespace:child
|
|
29
|
+
childDbg('small out'); // prints namespace:child small out
|
|
30
|
+
var grandChildDbg = debug.spawn('grandChild'); // debugger in the namespace:child:grandChild
|
|
31
|
+
grandChildDbg('small out'); // prints namespace:child:grandChild small out
|
|
29
32
|
```
|
|
33
|
+
|
|
34
|
+
[npm-image]: https://img.shields.io/npm/v/debug-fabulous.svg
|
|
35
|
+
[npm-url]: https://www.npmjs.com/package/debug-fabulous
|
|
36
|
+
[travis-image]: https://img.shields.io/travis/nmccready/debug-fabulous.svg
|
|
37
|
+
[travis-url]: https://travis-ci.org/nmccready/debug-fabulous
|
package/index.js
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
module.exports = function (debug) {
|
|
5
|
-
debug = debug ? debug : require('debug')
|
|
6
|
-
|
|
7
|
-
debug = wrapLazyEval(debug);
|
|
8
|
-
wrapLazy(debug);
|
|
9
|
-
|
|
10
|
-
return debug;
|
|
11
|
-
}
|
|
1
|
+
module.exports = require('./src/debugFabFactory');
|
|
2
|
+
module.exports.spawnable = require('./src/spawn');
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "debug-fabulous",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "visionmedia debug extensions rolled into one",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"
|
|
7
|
+
"lint": "eslint !./node_modules *.js ./**/*.js",
|
|
8
|
+
"mocha": "mocha",
|
|
9
|
+
"test": "npm run lint && mocha ./test/**/*test.js ./test/*.test.js"
|
|
8
10
|
},
|
|
9
11
|
"repository": {
|
|
10
12
|
"type": "git",
|
|
@@ -18,13 +20,15 @@
|
|
|
18
20
|
"author": "Nicholas McCready",
|
|
19
21
|
"license": "MIT",
|
|
20
22
|
"dependencies": {
|
|
21
|
-
"debug": "2.
|
|
22
|
-
"
|
|
23
|
+
"debug": "2.3.0",
|
|
24
|
+
"memoizee": "^0.4.5",
|
|
23
25
|
"object-assign": "4.1.0"
|
|
24
26
|
},
|
|
25
27
|
"devDependencies": {
|
|
26
28
|
"chai": "3.X",
|
|
27
29
|
"eslint": "3.X",
|
|
30
|
+
"hook-std": "0.X",
|
|
31
|
+
"memwatch-next": "^0.3.0",
|
|
28
32
|
"mocha": "3.X"
|
|
29
33
|
}
|
|
30
34
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module.exports = function debugFactory(_debugApi, _options) {
|
|
2
|
+
var wrapLazyEval = require('./lazy-eval');
|
|
3
|
+
var formatArgs = require('./formatArgs');
|
|
4
|
+
|
|
5
|
+
var options = _options || {
|
|
6
|
+
formatArgs: true
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
var debugApi = _debugApi ? _debugApi : require('debug');
|
|
10
|
+
debugApi = wrapLazyEval(debugApi);
|
|
11
|
+
|
|
12
|
+
debugApi = formatArgs({
|
|
13
|
+
debugApi: debugApi,
|
|
14
|
+
options: options
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
return debugApi;
|
|
18
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module.exports = function formatArgs(args) {
|
|
2
|
+
var debugApi = args.debugApi;
|
|
3
|
+
var options = args.options;
|
|
4
|
+
|
|
5
|
+
if(options.formatArgs == true){
|
|
6
|
+
/*
|
|
7
|
+
fixing it so we don't get redundant timestamps on prod
|
|
8
|
+
https://github.com/visionmedia/debug/issues/161
|
|
9
|
+
*/
|
|
10
|
+
debugApi.formatArgs = function() {
|
|
11
|
+
if (this.useColors)
|
|
12
|
+
arguments[0] = ' \u001b[9' + this.color + 'm' + this.namespace + ' ' + '\u001b[0m' + arguments[0];
|
|
13
|
+
else
|
|
14
|
+
arguments[0] = ' ' + this.namespace + ' ' + arguments[0];
|
|
15
|
+
|
|
16
|
+
return arguments;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
else if ( typeof options.formatArgs === 'function'){
|
|
20
|
+
debugApi.formatArgs = options.formatArgs;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return debugApi;
|
|
24
|
+
}
|
package/src/lazy-eval.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var slice = [].slice,
|
|
4
|
-
objectAssign = require('object-assign');
|
|
5
|
-
|
|
1
|
+
var objectAssign = require('object-assign');
|
|
2
|
+
var memoize = require('memoizee');
|
|
6
3
|
|
|
7
4
|
function _resolveOutput(func, bindThis) {
|
|
8
5
|
var wrapped = function() {
|
|
9
|
-
var
|
|
10
|
-
args =
|
|
6
|
+
var i = arguments.length;
|
|
7
|
+
var args = [];
|
|
8
|
+
while (i--) args[i] = arguments[i];
|
|
11
9
|
|
|
12
10
|
// lazy function eval to keep output memory pressure down, if not used
|
|
13
11
|
if (typeof args[0] === 'function') {
|
|
@@ -21,12 +19,12 @@ function _resolveOutput(func, bindThis) {
|
|
|
21
19
|
};
|
|
22
20
|
|
|
23
21
|
|
|
24
|
-
function wrapEval(
|
|
22
|
+
function wrapEval(_debug) {
|
|
25
23
|
|
|
26
|
-
var debugOrig =
|
|
27
|
-
|
|
24
|
+
var debugOrig = _debug;
|
|
25
|
+
var noop = function(){};
|
|
28
26
|
|
|
29
|
-
|
|
27
|
+
function debug(namespace) {
|
|
30
28
|
|
|
31
29
|
var instance = debugOrig(namespace);
|
|
32
30
|
|
|
@@ -42,9 +40,11 @@ function wrapEval(debug) {
|
|
|
42
40
|
return instance;
|
|
43
41
|
}
|
|
44
42
|
|
|
45
|
-
|
|
43
|
+
var debugMemoized = memoize(debug);
|
|
44
|
+
|
|
45
|
+
objectAssign(debugMemoized, debugOrig);
|
|
46
46
|
|
|
47
|
-
return
|
|
47
|
+
return debugMemoized;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
module.exports = wrapEval;
|
package/src/spawn.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
function spawnFactory(_namespace, _debugFabFactory) {
|
|
2
|
+
var memoize = require('memoizee');
|
|
3
|
+
var namespace = _namespace || '';
|
|
4
|
+
var debugFabFactory = _debugFabFactory;
|
|
5
|
+
|
|
6
|
+
if(!debugFabFactory){
|
|
7
|
+
debugFabFactory = require('./debugFabFactory')();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function Debugger(_base, _ns){
|
|
11
|
+
var base = _base || '';
|
|
12
|
+
var ns = _ns || '';
|
|
13
|
+
|
|
14
|
+
var newNs = ns ? [base, ns].join(':') : base;
|
|
15
|
+
var debug = debugFabFactory(newNs);
|
|
16
|
+
|
|
17
|
+
this.debug = debug;
|
|
18
|
+
this.debug.spawn = this.spawn;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
Debugger.prototype.spawn = function(ns) {
|
|
22
|
+
var dbg = new Debugger(this.namespace, ns);
|
|
23
|
+
|
|
24
|
+
return dbg.debug;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
Debugger.prototype.spawn = memoize(Debugger.prototype.spawn);
|
|
28
|
+
|
|
29
|
+
var rootDebug = (new Debugger(namespace)).debug;
|
|
30
|
+
|
|
31
|
+
return rootDebug;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
module.exports = spawnFactory;
|
package/src/lazy-debug.js
DELETED