Console with locale timestamp
Provides a console debugging facilities with a timestamp. Timestamps are written using Date.prototype.toLocaleTimeString()
.
All public methods have the same functionality as the Console
.
Sample
JavaScript
import Console from 'console-locale-timestamp';
const console1 = new Console();
console1.debug('Hello World!');
console1.table({
1001: { name: 'John Smith', age: '20' },
1002: { name: 'Taro Yamada', age: '25' },
});
const console2 = new Console('en-US', { minute: '2-digit', second: '2-digit' }, ['[', ']'], ' - ');
console2.debug('Hello World!');
console2.table({
1001: { name: 'John Smith', age: '20' },
1002: { name: 'Taro Yamada', age: '25' },
});
Console
0:00:00 Hello World!
0:00:01
┌─────────┬───────────────┬──────┐
│ (index) │ name │ age │
├─────────┼───────────────┼──────┤
│ 1001 │ 'John Smith' │ '20' │
│ 1002 │ 'Taro Yamada' │ '25' │
└─────────┴───────────────┴──────┘
[00:02] - Hello World!
[00:03]
┌─────────┬───────────────┬──────┐
│ (index) │ name │ age │
├─────────┼───────────────┼──────┤
│ 1001 │ 'John Smith' │ '20' │
│ 1002 │ 'Taro Yamada' │ '25' │
└─────────┴───────────────┴──────┘
Constructor arguments
constructor(locales?: string, options?: object, quote?: string[], separator?: string)
name | type | deault | example | Description |
---|
locales | string | undefined | 'en-US' | The specified value will be used as the first argument of Date.prototype.toLocaleTimeString() . |
options | object | undefined | { minute: '2-digit', second: '2-digit' } | The specified value will be used as the second argument of Date.prototype.toLocaleTimeString() . |
quote | string[] | [''] | ['[', ']'] | The characters that surround the timestamp. If you omit the second value, the same characters as the first are applied. |
separator | string | '' | ' - ' | Delimiter between the timestamp and the message that follows. |
Methods