console-locale-timestamp
Advanced tools
Comparing version 1.0.11 to 1.0.12
@@ -7,4 +7,2 @@ /** | ||
* All public methods have the same functionality as the `Console`<https://console.spec.whatwg.org/>. | ||
* | ||
* @version 1.0.11 | ||
*/ | ||
@@ -141,15 +139,15 @@ export default class ConsoleLocaleTimestamp { | ||
* | ||
* @param {any[]} data - Argument of console.group() | ||
* @param {any[]} label - Argument of console.group() | ||
* | ||
* @see console.group() <https://console.spec.whatwg.org/#group> | ||
*/ | ||
group(...data: any[]): void; | ||
group(...label: any[]): void; | ||
/** | ||
* Wrapper of console.groupCollapsed() | ||
* | ||
* @param {any[]} data - Argument of console.groupCollapsed() | ||
* @param {any[]} label - Argument of console.groupCollapsed() | ||
* | ||
* @see console.groupCollapsed() <https://console.spec.whatwg.org/#groupcollapsed> | ||
*/ | ||
groupCollapsed(...data: any[]): void; | ||
groupCollapsed(...label: any[]): void; | ||
/** | ||
@@ -156,0 +154,0 @@ * Wrapper of console.groupEnd() |
@@ -7,4 +7,2 @@ /** | ||
* All public methods have the same functionality as the `Console`<https://console.spec.whatwg.org/>. | ||
* | ||
* @version 1.0.11 | ||
*/ | ||
@@ -24,2 +22,8 @@ export default class ConsoleLocaleTimestamp { | ||
this.#separator = ' '; | ||
this.#LOG_LEVEL = { | ||
log: 'log', | ||
info: 'info', | ||
warn: 'warn', | ||
error: 'error', | ||
}; // https://console.spec.whatwg.org/#loglevel-severity | ||
if (locales !== undefined) { | ||
@@ -62,2 +66,3 @@ if (Object.prototype.toString.call(locales) !== '[object String]') { | ||
#separator; | ||
#LOG_LEVEL; // https://console.spec.whatwg.org/#loglevel-severity | ||
/** | ||
@@ -72,12 +77,15 @@ * Print a timestamp to the console. | ||
switch (logLevel) { | ||
case 'log': | ||
case 'info': | ||
case 'warn': | ||
case this.#LOG_LEVEL.log: | ||
case this.#LOG_LEVEL.info: | ||
case this.#LOG_LEVEL.warn: { | ||
process.stdout.write(timestamp); | ||
break; | ||
case 'error': | ||
} | ||
case this.#LOG_LEVEL.error: { | ||
process.stderr.write(timestamp); | ||
break; | ||
default: | ||
} | ||
default: { | ||
throw new Error('An undefined `logLevel` was specified as an argument. `logLevel` must be one of the groups defined below. <https://console.spec.whatwg.org/#loglevel-severity>'); | ||
} | ||
} | ||
@@ -103,3 +111,3 @@ } | ||
if (!condition) { | ||
this._printTimestamp('error'); | ||
this._printTimestamp(this.#LOG_LEVEL.error); | ||
} | ||
@@ -124,3 +132,3 @@ console.assert(condition, ...data); | ||
debug(...data) { | ||
this._printTimestamp('log'); | ||
this._printTimestamp(this.#LOG_LEVEL.log); | ||
console.debug(...data); | ||
@@ -136,3 +144,3 @@ } | ||
error(...data) { | ||
this._printTimestamp('error'); | ||
this._printTimestamp(this.#LOG_LEVEL.error); | ||
console.error(...data); | ||
@@ -148,3 +156,3 @@ } | ||
info(...data) { | ||
this._printTimestamp('info'); | ||
this._printTimestamp(this.#LOG_LEVEL.info); | ||
console.info(...data); | ||
@@ -160,3 +168,3 @@ } | ||
log(...data) { | ||
this._printTimestamp('log'); | ||
this._printTimestamp(this.#LOG_LEVEL.log); | ||
console.log(...data); | ||
@@ -173,3 +181,3 @@ } | ||
table(tabularData, properties) { | ||
this._printlnTimestamp('log'); | ||
this._printlnTimestamp(this.#LOG_LEVEL.log); | ||
console.table(tabularData, properties); | ||
@@ -185,3 +193,3 @@ } | ||
trace(...data) { | ||
this._printTimestamp('log'); | ||
this._printTimestamp(this.#LOG_LEVEL.log); | ||
console.trace(...data); | ||
@@ -197,3 +205,3 @@ } | ||
warn(...data) { | ||
this._printTimestamp('warn'); | ||
this._printTimestamp(this.#LOG_LEVEL.warn); | ||
console.warn(...data); | ||
@@ -210,3 +218,3 @@ } | ||
dir(item, options) { | ||
this._printTimestamp('log'); | ||
this._printTimestamp(this.#LOG_LEVEL.log); | ||
console.dir(item, options); | ||
@@ -222,3 +230,3 @@ } | ||
dirxml(...data) { | ||
this._printTimestamp('log'); | ||
this._printTimestamp(this.#LOG_LEVEL.log); | ||
console.dirxml(...data); | ||
@@ -234,3 +242,3 @@ } | ||
count(label) { | ||
this._printTimestamp('info'); | ||
this._printTimestamp(this.#LOG_LEVEL.info); | ||
console.count(label); | ||
@@ -251,11 +259,11 @@ } | ||
* | ||
* @param {any[]} data - Argument of console.group() | ||
* @param {any[]} label - Argument of console.group() | ||
* | ||
* @see console.group() <https://console.spec.whatwg.org/#group> | ||
*/ | ||
group(...data) { | ||
if (data.length > 0) { | ||
this._printTimestamp('log'); | ||
group(...label) { | ||
if (label.length > 0) { | ||
this._printTimestamp(this.#LOG_LEVEL.log); | ||
} | ||
console.group(...data); | ||
console.group(...label); | ||
} | ||
@@ -265,11 +273,11 @@ /** | ||
* | ||
* @param {any[]} data - Argument of console.groupCollapsed() | ||
* @param {any[]} label - Argument of console.groupCollapsed() | ||
* | ||
* @see console.groupCollapsed() <https://console.spec.whatwg.org/#groupcollapsed> | ||
*/ | ||
groupCollapsed(...data) { | ||
if (data.length > 0) { | ||
this._printTimestamp('log'); | ||
groupCollapsed(...label) { | ||
if (label.length > 0) { | ||
this._printTimestamp(this.#LOG_LEVEL.log); | ||
} | ||
console.groupCollapsed(...data); | ||
console.groupCollapsed(...label); | ||
} | ||
@@ -303,3 +311,3 @@ /** | ||
timeLog(label, ...data) { | ||
this._printTimestamp('log'); | ||
this._printTimestamp(this.#LOG_LEVEL.log); | ||
console.timeLog(label, ...data); | ||
@@ -315,3 +323,3 @@ } | ||
timeEnd(label) { | ||
this._printTimestamp('info'); | ||
this._printTimestamp(this.#LOG_LEVEL.info); | ||
console.timeEnd(label); | ||
@@ -318,0 +326,0 @@ } |
{ | ||
"name": "console-locale-timestamp", | ||
"version": "1.0.11", | ||
"description": "Provides a console debugging facilities with a timestamp. Timestamps are written using Date.prototype.toLocaleTimeString().", | ||
"version": "1.0.12", | ||
"description": "Provides a console debugging facilities with a timestamp. Timestamps are written using `Date.prototype.toLocaleTimeString()`.", | ||
"keywords": [ | ||
@@ -28,12 +28,17 @@ "console" | ||
"build": "tsc -w", | ||
"test": "node test.js" | ||
"sample": "node sample.js", | ||
"test": "jest --coverage" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^14.14.21", | ||
"@typescript-eslint/eslint-plugin": "^4.13.0", | ||
"@typescript-eslint/parser": "^4.13.0", | ||
"eslint": "^7.17.0", | ||
"eslint-config-prettier": "^7.1.0", | ||
"eslint-plugin-jsdoc": "^30.7.13", | ||
"typescript": "^4.1.3" | ||
"@types/jest": "^26.0.20", | ||
"@types/node": "^14.14.31", | ||
"@typescript-eslint/eslint-plugin": "^4.15.1", | ||
"@typescript-eslint/parser": "^4.15.1", | ||
"coveralls": "^3.1.0", | ||
"eslint": "^7.20.0", | ||
"eslint-config-prettier": "^7.2.0", | ||
"eslint-plugin-jsdoc": "^32.0.2", | ||
"jest": "^26.6.3", | ||
"ts-jest": "^26.5.1", | ||
"typescript": "^4.1.5" | ||
}, | ||
@@ -40,0 +45,0 @@ "publishConfig": { |
@@ -13,3 +13,3 @@ # Console Locale Timestamp | ||
``` | ||
```JavaScript | ||
import Console from 'console-locale-timestamp'; | ||
@@ -55,3 +55,3 @@ | ||
``` | ||
```TypeScript | ||
constructor(locales?: string, options?: object, quote?: string[], separator?: string) | ||
@@ -58,0 +58,0 @@ ``` |
@@ -0,1 +1,3 @@ | ||
type LogLevel = 'log' | 'info' | 'warn' | 'error'; // https://console.spec.whatwg.org/#loglevel-severity | ||
/** | ||
@@ -7,12 +9,17 @@ * Console Locale Timestamp | ||
* All public methods have the same functionality as the `Console`<https://console.spec.whatwg.org/>. | ||
* | ||
* @version 1.0.11 | ||
*/ | ||
export default class ConsoleLocaleTimestamp { | ||
#locales: string | undefined = undefined; | ||
#options: Intl.DateTimeFormatOptions | undefined = undefined; | ||
#openQuote: string = ''; | ||
#closeQuote: string = ''; | ||
#separator: string = ' '; | ||
readonly #locales: string | undefined = undefined; | ||
readonly #options: Intl.DateTimeFormatOptions | undefined = undefined; | ||
readonly #openQuote: string = ''; | ||
readonly #closeQuote: string = ''; | ||
readonly #separator: string = ' '; | ||
readonly #LOG_LEVEL = { | ||
log: <LogLevel>'log', | ||
info: <LogLevel>'info', | ||
warn: <LogLevel>'warn', | ||
error: <LogLevel>'error', | ||
}; // https://console.spec.whatwg.org/#loglevel-severity | ||
/** | ||
@@ -69,18 +76,21 @@ * @param {string} locales - The specified value will be used as the first argument of `Date.prototype.toLocaleTimeString()`. (e.g. 'en-US' => '12:00:00 AM', 'ja-JP' => '0:00:00' ) | ||
*/ | ||
private _printTimestamp(logLevel: string, separator: string = this.#separator): void { | ||
private _printTimestamp(logLevel: LogLevel, separator: string = this.#separator): void { | ||
const timestamp = `${this.#openQuote}${new Date().toLocaleTimeString(this.#locales, this.#options)}${this.#closeQuote}${separator}`; | ||
switch (logLevel) { | ||
case 'log': | ||
case 'info': | ||
case 'warn': | ||
case this.#LOG_LEVEL.log: | ||
case this.#LOG_LEVEL.info: | ||
case this.#LOG_LEVEL.warn: { | ||
process.stdout.write(timestamp); | ||
break; | ||
case 'error': | ||
} | ||
case this.#LOG_LEVEL.error: { | ||
process.stderr.write(timestamp); | ||
break; | ||
default: | ||
} | ||
default: { | ||
throw new Error( | ||
'An undefined `logLevel` was specified as an argument. `logLevel` must be one of the groups defined below. <https://console.spec.whatwg.org/#loglevel-severity>' | ||
); | ||
} | ||
} | ||
@@ -94,3 +104,3 @@ } | ||
*/ | ||
private _printlnTimestamp(logLevel: string): void { | ||
private _printlnTimestamp(logLevel: LogLevel): void { | ||
this._printTimestamp(logLevel, '\n'); | ||
@@ -109,3 +119,3 @@ } | ||
if (!condition) { | ||
this._printTimestamp('error'); | ||
this._printTimestamp(this.#LOG_LEVEL.error); | ||
} | ||
@@ -132,3 +142,3 @@ console.assert(condition, ...data); | ||
debug(...data: any[]): void { | ||
this._printTimestamp('log'); | ||
this._printTimestamp(this.#LOG_LEVEL.log); | ||
console.debug(...data); | ||
@@ -145,3 +155,3 @@ } | ||
error(...data: any[]): void { | ||
this._printTimestamp('error'); | ||
this._printTimestamp(this.#LOG_LEVEL.error); | ||
console.error(...data); | ||
@@ -158,3 +168,3 @@ } | ||
info(...data: any[]): void { | ||
this._printTimestamp('info'); | ||
this._printTimestamp(this.#LOG_LEVEL.info); | ||
console.info(...data); | ||
@@ -171,3 +181,3 @@ } | ||
log(...data: any[]): void { | ||
this._printTimestamp('log'); | ||
this._printTimestamp(this.#LOG_LEVEL.log); | ||
console.log(...data); | ||
@@ -185,3 +195,3 @@ } | ||
table(tabularData?: any, properties?: string[]): void { | ||
this._printlnTimestamp('log'); | ||
this._printlnTimestamp(this.#LOG_LEVEL.log); | ||
console.table(tabularData, properties); | ||
@@ -198,3 +208,3 @@ } | ||
trace(...data: any[]): void { | ||
this._printTimestamp('log'); | ||
this._printTimestamp(this.#LOG_LEVEL.log); | ||
console.trace(...data); | ||
@@ -211,3 +221,3 @@ } | ||
warn(...data: any[]): void { | ||
this._printTimestamp('warn'); | ||
this._printTimestamp(this.#LOG_LEVEL.warn); | ||
console.warn(...data); | ||
@@ -225,3 +235,3 @@ } | ||
dir(item?: any, options?: any): void { | ||
this._printTimestamp('log'); | ||
this._printTimestamp(this.#LOG_LEVEL.log); | ||
console.dir(item, options); | ||
@@ -238,3 +248,3 @@ } | ||
dirxml(...data: any[]): void { | ||
this._printTimestamp('log'); | ||
this._printTimestamp(this.#LOG_LEVEL.log); | ||
console.dirxml(...data); | ||
@@ -251,3 +261,3 @@ } | ||
count(label?: string): void { | ||
this._printTimestamp('info'); | ||
this._printTimestamp(this.#LOG_LEVEL.info); | ||
console.count(label); | ||
@@ -270,11 +280,11 @@ } | ||
* | ||
* @param {any[]} data - Argument of console.group() | ||
* @param {any[]} label - Argument of console.group() | ||
* | ||
* @see console.group() <https://console.spec.whatwg.org/#group> | ||
*/ | ||
group(...data: any[]): void { | ||
if (data.length > 0) { | ||
this._printTimestamp('log'); | ||
group(...label: any[]): void { | ||
if (label.length > 0) { | ||
this._printTimestamp(this.#LOG_LEVEL.log); | ||
} | ||
console.group(...data); | ||
console.group(...label); | ||
} | ||
@@ -285,11 +295,11 @@ | ||
* | ||
* @param {any[]} data - Argument of console.groupCollapsed() | ||
* @param {any[]} label - Argument of console.groupCollapsed() | ||
* | ||
* @see console.groupCollapsed() <https://console.spec.whatwg.org/#groupcollapsed> | ||
*/ | ||
groupCollapsed(...data: any[]): void { | ||
if (data.length > 0) { | ||
this._printTimestamp('log'); | ||
groupCollapsed(...label: any[]): void { | ||
if (label.length > 0) { | ||
this._printTimestamp(this.#LOG_LEVEL.log); | ||
} | ||
console.groupCollapsed(...data); | ||
console.groupCollapsed(...label); | ||
} | ||
@@ -326,3 +336,3 @@ | ||
timeLog(label?: string, ...data: any[]): void { | ||
this._printTimestamp('log'); | ||
this._printTimestamp(this.#LOG_LEVEL.log); | ||
console.timeLog(label, ...data); | ||
@@ -339,5 +349,5 @@ } | ||
timeEnd(label?: string): void { | ||
this._printTimestamp('info'); | ||
this._printTimestamp(this.#LOG_LEVEL.info); | ||
console.timeEnd(label); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
105265
793
11