gengojs-debug
Advanced tools
Comparing version 1.1.1 to 2.0.0
@@ -0,3 +1,7 @@ | ||
'use strict'; | ||
import debug from 'debug'; | ||
import { install as map } from 'source-map-support'; | ||
import chalk from 'chalk'; | ||
import _ from 'lodash'; | ||
import 'source-map-support/register'; | ||
/** | ||
@@ -7,25 +11,51 @@ * Debug is a debug wrapper for gengo.js | ||
class Debug { | ||
constructor (namespace, level, args) { | ||
map(); | ||
this.namespace = namespace; | ||
this.level = level; | ||
this.args = args; | ||
this.debug = (()=>{ | ||
var obj = {}; | ||
var gengo = 'gengo'; | ||
var namespaces = ['core','parser', 'router', | ||
'backend', 'api', 'localize', 'header']; | ||
var levels = ['debug', 'warn', 'error', 'info', 'verbose', 'silly']; | ||
namespaces.forEach(function(namespace) { | ||
levels.forEach(function(level) { | ||
var key = gengo + '.' + namespace + ':' + level; | ||
obj[key] = debug(gengo + '.' + namespace + ':' + level); | ||
}, this); | ||
}, this); | ||
return obj; | ||
})(); | ||
} | ||
log () { | ||
this.debug['gengo' + '.' + this.namespace.toLowerCase() + ':' + | ||
this.level.toLowerCase()].apply(null, this.args); | ||
constructor(namespace) { | ||
// Set the namespace | ||
this.namespace = namespace; | ||
// Set the levels | ||
var levels = ['debug', 'warn', 'error', 'info', 'verbose', 'silly']; | ||
// Set up our personal console which | ||
// will be build the log functions by type | ||
this.console = (() => { | ||
var obj = {}; | ||
var gengo = 'gengo'; | ||
var namespaces = ['core', 'parser', 'router', | ||
'backend', 'api', 'localize', 'header' | ||
]; | ||
// Build it! | ||
namespaces.forEach(function(namespace) { | ||
levels.forEach(function(level) { | ||
var key = gengo + '.' + namespace + ':' + level; | ||
obj[key] = debug(gengo + '.' + namespace + ':' + level); | ||
}, this); | ||
}, this); | ||
return obj; | ||
})(); | ||
// Apply color to the arguments if necessary and output them! | ||
levels.forEach(level => { | ||
this[level] = (...args) => { | ||
var namespace = 'gengo' + '.' + this.namespace.toLowerCase() + ':' + level; | ||
args = args.map(a => { | ||
var temp; | ||
try { | ||
if (!_.isFunction(a) || !_.isString(a)) | ||
temp = JSON.stringify(a, null, 2); | ||
} catch (error) {} | ||
return temp || a; | ||
}); | ||
if (level === 'error') args = args.map(a => { | ||
return chalk.red(a); | ||
}); | ||
if (level === 'warn') args = args.map(a => { | ||
return chalk.yellow(a); | ||
}); | ||
if (level === 'info') args = args.map(a => { | ||
return chalk.green(a); | ||
}); | ||
this.console[namespace].apply(null, args); | ||
return this; | ||
}; | ||
}); | ||
} | ||
@@ -37,9 +67,7 @@ } | ||
* @param {string} namespace - The namespace of the gengo to debug. | ||
* @param {string} level - The level of debug to output. | ||
* @param {*} args - The arguments to output. | ||
* @example | ||
* debugify('core.plugins', 'warn', 'Hello world') | ||
* debugify('core.plugins').warn('hello') | ||
*/ | ||
export default (namespace, level, ...args) => { | ||
(new Debug(namespace, level, args)).log(); | ||
export default (namespace) => { | ||
return new Debug(namespace); | ||
}; |
{ | ||
"name": "gengojs-debug", | ||
"version": "1.1.1", | ||
"version": "2.0.0", | ||
"description": "The debugger console for gengo.js", | ||
"main": "index.js", | ||
"main": "src/index.js", | ||
"scripts": { | ||
@@ -26,7 +26,20 @@ "test": "echo \"Error: no test specified\" && exit 1" | ||
"homepage": "https://github.com/iwatakeshi/gengojs-debug#readme", | ||
"devDependencies": {}, | ||
"devDependencies": { | ||
"gulp": "^3.9.0", | ||
"gulp-babel": "^5.2.1", | ||
"gulp-changelog": "^1.0.0", | ||
"gulp-gh-pages": "^0.5.2", | ||
"gulp-jsbeautify": "^0.1.1", | ||
"gulp-jshint": "^1.11.2", | ||
"gulp-shell": "^0.4.3", | ||
"gulp-sourcemaps": "^1.6.0", | ||
"jshint-stylish": "^2.0.1", | ||
"rimraf": "^2.4.3" | ||
}, | ||
"dependencies": { | ||
"chalk": "^1.1.1", | ||
"debug": "^2.2.0", | ||
"lodash": "^3.10.1", | ||
"source-map-support": "^0.3.2" | ||
} | ||
} |
# gengojs-debug | ||
The debugger console for [gengo.js](http://github.com/iwatakeshi/gengojs) | ||
The debugger console for [gengo.js](http://github.com/gengojs/gengojs) | ||
@@ -10,3 +10,3 @@ ## Usage | ||
debug(namespace:string, level:string, args:*); | ||
debug(namespace:string).[level](args:*); | ||
``` | ||
@@ -17,5 +17,15 @@ #### ES5 | ||
debug(namespace:string, level:string, args:*); | ||
debug(namespace:string).[level](args:*); | ||
``` | ||
It's even possible to chain the methods: | ||
```javascript | ||
/* Example */ | ||
debug('core') | ||
.warn('This is a warning') | ||
.error('This is an error!'); | ||
``` | ||
In terminal: | ||
@@ -63,2 +73,2 @@ | ||
DEBUG=gengo.parser:debug gengo.router:* | ||
``` | ||
``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14780
9
274
72
4
10
1
+ Addedchalk@^1.1.1
+ Addedlodash@^3.10.1
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedlodash@3.10.1(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)