-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
39 lines (32 loc) · 1003 Bytes
/
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
'use strict';
var parseThemedText = require('./lib/parse-themed-text');
var applyTheme = require('./lib/apply-theme');
function themingLog(theme, logger, lineSep) {
if (typeof logger === 'boolean') {
lineSep = logger;
logger = console.log;
} else if (typeof logger !== 'function') {
logger = console.log;
}
return function (text /*, ...args */) {
text = applyTheme(parseThemedText(text), theme, arguments);
if (lineSep) {
var lines = text.split(/\r\n|\r|\n/);
for (var i = 0, n = lines.length; i < n; i++) {
logger(lines[i]);
}
return;
}
logger(text);
};
}
function format(theme, text /* , ...args */) {
var args = Array.prototype.slice.call(arguments, 1);
return applyTheme(parseThemedText(text), theme, args);
}
function formatLines(/* theme, text, ...args */) {
return format.apply(this, arguments).split(/\r\n|\r|\n/);
}
themingLog.format = format;
themingLog.formatLines = formatLines;
module.exports = themingLog;