-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
83 lines (72 loc) · 1.53 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*!
* json-colorz <https://github.com/akileez/json-colorz>
*
* Copyright (c) 2015-2016 Keith Williams.
* Licensed under the ISC license.
*
* Original Code:
* jsome <https://github.com/Javascipt/Jsome>
* Copyright (c) 2015 Khalid REHIOUI <[email protected]> (http://github.com/javascipt)
* Licensed under he MIT License (MIT)
*/
var colors = {
num : 'cyan',
str : 'magenta',
bool : 'red',
regex : 'blue',
undef : 'grey',
null : 'grey',
attr : 'green',
quot : 'yellow',
punc : 'yellow',
brack : 'yellow',
func : 'grey'
}
var display = {
func: false,
date: false,
xarr: true
}
var level = {
show : false,
char : '.',
color : 'red',
spaces : 2,
start : 0
}
var params = {
colored: true,
async: false
}
var options = {
colors : colors,
display: display,
level : level,
params : params
}
var engine = require('./lib/engine').setOptions(options)
function colorize (engine) {
// main function: jclrz
function jclrz (json, cb) {
if (!jclrz.params.async) {
process.stdout.write(engine.gen(json, options.level.start) + '\n')
} else {
process.nextTick(function () {
process.stdout.write(engine.gen(json, options.level.start) + '\n')
cb && cb()
})
}
return json
}
// parse
jclrz.parse = function (jsonString, cb) {
return jclrz(JSON.parse(jsonString), cb)
}
// options
jclrz.colors = colors
jclrz.display = display
jclrz.level = level
jclrz.params = params
return jclrz
}
module.exports = colorize(engine)