]>
git.r.bdr.sh - rbdr/cologne/blob - lib/utilities.js
4 kCircularString: '[Circular]',
13 underline_off: '[24m',
15 strikethrough_off: '[29m',
37 // Get High Res time depending on platform. Currently only supporting node.
41 return process
.hrtime
.bigint();
45 // Initialise relative time.
47 internals
.initialTimestamp
= BigInt(Date
.now()) * 1000000n
;
48 internals
.initialHighResTime
= internals
.getHighResTime();
51 * Container object for utilities used by loggers.
58 * Returns the current timestamp in nanoseconds as a bigint.
62 * @return {bigint} current time in nanoseconds, including fractions.
66 return internals
.initialTimestamp
+ internals
.getHighResTime() - internals
.initialHighResTime
;
70 * Stringifies objects, avoiding circular references.
74 * @param {Object} object the object to stringify
75 * @return {String} the stringified object
79 const cache
= new Set();
81 return JSON
.stringify(object
, (key
, value
) => {
83 if (typeof value
=== 'bigint') {
84 return String(value
) + 'n';
87 if (typeof value
=== 'object' && value
!== null) {
88 if (cache
.has(value
)) {
89 return internals
.kCircularString
;
100 * Given an ansi keyword, it will return the appropriate code.
102 * @function getAnsiCode
103 * @memberof Utilities
104 * @param {String} ansiString the name of the desired code
105 * @return {String} the ansi code
107 getAnsiCode(ansiString
) {
109 return internals
.kAnsiCodes
[ansiString
] || internals
.kAnsiCodes
.reset
;
113 * Given a level, it will return the appropriate ansi keyword related
116 * @function getLevelAnsi
117 * @memberof Utilities
118 * @param {number} level the level of the log
119 * @return {String} the ansi keyword
121 getLevelAnsi(level
) {