node-lancer
v1.1.0
Published
An node logger for colorful with line info supported.
Downloads
192
Readme
Lancer (node util for funny)
【騎士道(きしどう)の剣(けん)に誉(ほま)れあれ! 俺(おれ)は、お前(まえ)と出会(であ)えてよかった!】 ---Lancer [Fate/zero night]
自古枪兵幸运E.
Install
run this command: npm install --save
Usage
- Example
var util = require('node-lancer');
var logger = require('node-lancer/logger');
var debug = logger('myPkg');
var colors = require('node-lancer/color');
var timestamp = require('node-lancer/timestamp');
var type = require('node-lancer/type');
Basic methods
- md5
var md5str = util.md5('out put md5 string');
- escapeHTML
var escapedHTML = util.escapeHTML('<div></div>');
- unescapeHTML
var unescapedHTML =util.unescapeHTML(escapedHTML);
- random
var randomNum = util.random(10);
var randomNum = util.random(-1, 20);
- tripBOM
var noBOMBuffer = util.tripBOM(buffer);
forEach, map, every, some, filter
same as the Array.prototype.{METHOD};
var list = util.{forEach|map|every|some|filter}(callback, /*context*/);
- toArray, arrayOf
var arr = util.{toArray|arrayOf}(arguments); /*same as Array.of*/
- extend, merge, clone
util.merge is same as util.extend, util.clone is link util.extend(true, {}, target); Same as jQuery.extend;
- specialValueToNormalValue
trip special values to normal. 'NaN' => NaN 'Infinity'=> Infinity 'Null'=> null 'null'=> null 'false'=> false 'true'=> true
- camelCase
var camelVar = util.camelCase('this-should-be-camel-cased');
- namespace
var data = {};
var namespace = 'a.b.c';
// get val;
var val = util.namespace(data, namespace);
// overwrite old value.
util.namespace(data, namespace, 'set value')
// extend new scope data.
util.namespace(data, 'a.b', {d:'don\'t overwrite data',e:'and add this'}, true);
- inspect, format
Copied from the node/util
- timestamp
'YYYY': y, 'M': M, 'MM': pad(M), 'D': d, 'DD': pad(d), 'h': H%12, 'hh': pad(H%12), 'H': H, 'HH': pad(H), 'm': m, 'mm': pad(m), 's': s, 'ss':pad(s), 'S': SSS/100 | 0, 'SS': SSS/10 | 0, 'SSS': SSS, 'P': date > new Date(y,m,d,12,0,0,0) ? 'AM':'PM'
Example
var time = util.timestamp();
// output 2016-03-05 13:57:54
- line
var lineInfo = util.line(/*number*/);
~~ Colors ~~
now using chalk instead.