-
Notifications
You must be signed in to change notification settings - Fork 24
/
script.js
78 lines (64 loc) · 1.61 KB
/
script.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
var colors = {
'num' : 'cyan'
, 'str' : 'magenta'
, 'bool' : 'red'
, 'regex' : 'blue'
, 'undef' : 'grey'
, 'null' : 'grey'
, 'attr' : 'green'
, 'quot' : 'yellow'
, 'punc' : 'yellow'
, 'brack' : 'yellow'
}
, level = {
'show' : false
, 'char' : '.'
, 'color' : 'red'
, 'spaces' : 2
, 'start' : 0
}
, params = {
'colored' : true
, 'async' : false
, 'lintable': false
}
module.exports = (function () {
function jsome (json, callBack) {
return jsome.parse(stringify(json), callBack);
}
jsome.colors = colors;
jsome.level = level;
jsome.params = params;
var generator = require("./lib/generator").setJsomeRef(jsome)
, stringify = require('json-stringify-safe');
jsome.parse = function (jsonString, callBack) {
var json = JSON.parse(jsonString);
if (!jsome.params.async) {
var output = generator.gen(json, jsome.level.start);
if(Array.isArray(output)) {
console.log.apply(console, output);
} else {
console.log(output);
}
} else {
setTimeout(function () {
console.log(generator.gen(json, jsome.level.start));
callBack && callBack();
});
}
return json;
}
jsome.getColoredString = function(jsonString, callBack){
var json = JSON.parse(stringify(jsonString));
if (!jsome.params.async) {
var output = generator.gen(json, jsome.level.start);
return output
} else {
setTimeout(function () {
var output = generator.gen(json, jsome.level.start)
callBack && callBack(output);
});
}
}
return jsome;
})();