-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelp.js
155 lines (127 loc) · 4.06 KB
/
help.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
const pkg = require('./package')
const console = require('./')();
(function(){
// shortcut
const col = console.col
// title
console
.spacer()
._(pkg.name, col('─ v'+pkg.version, 'grey'))
._('---')
._(col(pkg.repository.url, 'grey'))
.spacer()
// desc
console
._('Description', 'bold')
._('---')
._(pkg.description)
.spacer()
// install
console
._('Installation', 'white')
.title('npm install --save console2')
.spacer()
// reference
const ref = console
._('Reference', 'white')
._('Open README.md for complete reference')
._()
.box()
ref.over()
// reference
const lineArgs = '['+col('line', 'white')+'], ['+console.col('option', 'white')+']'
const docs = {
beep: ['Beep noise, outputs "BEEP"', '['+console.col('title', 'white')+']'],
box: ['Create a sub box', lineArgs],
build: 'Returns current stack as Promise(string)',
col: ['Colorize a string', col('input', 'white')+', {…'+col('color', 'white')+'}'],
dir: '~log',
error: ['Displays text in '+col('red','red'), lineArgs],
flush: '~out',
getParent: ['Return a specific parent box', '['+col('generations', 'white')+'=1]'],
help: 'Display these information',
info: ['Displays text in '+col('green','green'), lineArgs],
line: ['Add a new line', lineArgs],
log: ['Alias for .line AND .out', lineArgs],
options: ['Set option/s', col('object', 'white')],
out: ['Print current stack', lineArgs],
over: ['Mark box printable for out()', lineArgs],
pad: ['Pad a string', col('string', 'white')+', '+col('length', 'white')+', ['+col('string', 'white')+']'],
spacer: 'Add empty line',
strip: ['Remove colors from a string', col('string', 'white')],
time: ['Display timer', '['+col('timerName', 'white')+'], ['+col('reset', 'white')+']'],
timeEnd: '~time',
title: ['Display text inside a box', lineArgs],
trace: ['Beautified console.trace', '['+col('message')+']'],
warn: ['Displays text in '+col('yellow','yellow'), lineArgs]
}
// insert docs
Object.keys(console).sort().forEach(function(key){
if(key.substr(0,1) === '_'
|| ['Console','assert','overrideConsole'].indexOf(key) > -1
|| typeof console[key] !== 'function') return;
let doc = docs[key];
let line = col(key, 'cyan')
+ '('+(Array.isArray(doc) ? doc[1] : '')+')'
if(!doc) return
// alias
if(typeof doc === 'string' && doc.substr(0,1) === '~')
doc = 'Alias for '+doc.substr(1)
// add desc
line += console.pad(' ', 35 - console.strip(line).length)
+ ' - '
+ (Array.isArray(doc) ? doc[0] : doc||'')
ref._(line)
})
/**
* Example 1
*/
const example1 = function(){
console.line('New Line')
const red = console.box('Red Box Title', 'red')
red.line('Red Box Line').over()
const yellow = red
.box('Yellow Box Title', {over:true,color:'yellow',colorText:'yellow',border:2})
.line('Yellow Box Line')
yellow.box({color:'green'}).over().line('Hello World')
red.line('Red Box Bottom')
}
// example
console.spacer().title('Example 1: Box tree', 'bold')
console.line(example1).line()
example1()
/**
* Example 2
*/
const example2 = function(){
console.line({user: 'RienNeVaPlus',id: 123,date: new Date(),attr:{items:2432,top:[1,2],note:null},online:true})
}
// example
console.spacer().title('Example 2: Object inspection', 'bold')
console.line(example2).line()
example2()
/**
* Example 3
*/
const example3 = function(){
console.time('CustomTimer') // create new timer
console.time() // global timer
console.time('CustomTimer') // output created timer
}
// example
console.spacer().title('Example 3: Stopwatch', 'bold')
console.line(example3).line()
example3()
/**
* Example 4
*/
const example4 = function(){
console.trace()
}
// example
console.spacer().title('Example 4: Stack trace', 'bold')
console.line(example4).line()
example4()
console.spacer().title(console.col('Have fun!', 'rainbow'))
console.out();
})();