-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
114 lines (102 loc) · 3.03 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
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
const clr = require('colors/safe');
const theme = require('./src/theme'),
{ log, use, isValidName, updateTheme, restoreTheme } = require('./src/lib');
/**
* @fileoverview Set of functions for coloured logs.
* @module
*/
/**
* @description Print an error.
* @param {...*} data Data to print
* @example error('Something wrong happened with', new Error(this));
* @see log
* @returns {boolean} Did it happened?
*/
const error = (...data) => log(clr.error(data.join(' ')) + '\n');
/**
* @description Print an information.
* @param {...*} data Data to print
* @example info('Welcome John');
* @see log
* @returns {boolean} Did it happened?
*/
const info = (...data) => log(clr.info(data.join(' ')) + '\n');
/**
* @description Print a debug message.
* @param {...*} data Data to print
* @example dbg('i=', i);
* @see log
* @returns {boolean} Did it happened?
*/
const dbg = (...data) => log(clr.dbg(data.join(' ')) + '\n');
/**
* @description Print an output.
* @param {...*} data Data to print
* @example out(`1 + 1 = ${rpc('1 1 +')}`);
* @see log
* @returns {boolean} Did it happened?
*/
const out = (...data) => log(clr.out(data.join(' ')) + '\n');
/**
* @description Print an input.
* @param {...*} data Data to print
* @example inp(name);
* @see log
* @returns {boolean} Did it happened?
*/
const inp = (...data) => log(clr.inp(data.join(' ')) + '\n');
/**
* @description Print a warning.
* @param {...*} data Data to print
* @example warn('The following function is deprecated');
* @see log
* @returns {boolean} Did it happened?
*/
const warn = (...data) => log(clr.warn(data.join(' ')) + '\n');
/**
* @description Print a question.
* @param {...*} data Data to print
* @example quest('What is your username?');
* @see log
* @returns {boolean} Did it happened?
*/
const quest = (...data) => log(clr.quest(data.join(' ')) + '\n');
/**
* @description Print a success log.
* @param {...*} data Data to print
* @example succ('Achievement unlocked');
* @see log
* @returns {boolean} Did it happened?
*/
const succ = (...data) => log(clr.succ(data.join(' ')) + '\n');
/**
* @description Extend the current theme.
* @param {{string: (string|string[])}} extension Theme to add
* @example <caption>Using extensions as methods:</caption>
* const nclr = require('nclr');
* nclr.extend({
* suc: ['green', 'underline'],
* data: 'magenta'
* });
* nclr.suc('Yay!');
* nclr.data(42);
* @example <caption>Using extensions as functions:</caption>
* const nclr = require('nclr');
* nclr.extend({
* suc: ['green', 'underline'],
* data: 'magenta'
* });
* const { suc, data } = nclr;
* suc('Yay!');
* data(42);
* @throws {Error} Invalid extension key
*/
const extend = (extension) => {
for (let key in extension) {
if (!isValidName(key)) throw new Error(`Invalid extension key "${key}"`);
theme[key] = extension[key];
module.exports[key] = (...data) => log(clr[key](data.join(' ')) + '\n');
}
updateTheme();
};
module.exports = { error, info, dbg, out, inp, warn, quest, succ, log, extend, use, restore: restoreTheme }