forked from nozzlegear/logspect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
35 lines (27 loc) · 1.08 KB
/
index.ts
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
import isBrowser from "is-in-browser";
import { yellow } from "chalk";
declare const require;
let util: { inspect: (input: string, options?: { colors?: boolean; }) => string };
let inBrowserTimezoneWarningShown = false;
if (isBrowser) {
util = { inspect: (input, options) => input };
} else {
util = require("util");
}
export const defaults = {
locale: "en-US",
timeZone: "America/Chicago",
}
export function inspect(...args) {
if (isBrowser && !inBrowserTimezoneWarningShown) {
inBrowserTimezoneWarningShown = true;
// Ref: https://stackoverflow.com/q/30377607
console.warn("logspect warning: Timezones are not supported in all browsers. Timestamp will default to the browser's current timezone.");
}
const time = yellow(new Date().toLocaleTimeString(defaults.locale, {
timeZone: isBrowser ? undefined : defaults.timeZone,
timeZoneName: "short"
}));
console.log(time, ...args.map(a => typeof(a) === "string" ? a : util.inspect(a, { colors: true })));
}
export default inspect;