]>
git.r.bdr.sh - rbdr/cologne/blob - lib/utilities.js
4 kCircularString: '[Circular]',
6 // Get High Res time depending on platform. Currently only supporting node.
10 return process
.hrtime
.bigint();
14 // Initialise relative time.
16 internals
.initialTimestamp
= BigInt(Date
.now()) * 1000000n
;
17 internals
.initialHighResTime
= internals
.getHighResTime();
20 * Container object for utilities used by loggers.
27 * Returns the current timestamp in nanoseconds as a bigint.
31 * @return {bigint} current time in nanoseconds, including fractions.
35 return internals
.initialTimestamp
+ internals
.getHighResTime() - internals
.initialHighResTime
;
39 * Stringifies objects, avoiding circular references.
43 * @param {Object} object the object to stringify
44 * @return {String} the stringified object
48 const cache
= new Set();
50 return JSON
.stringify(object
, (key
, value
) => {
52 if (typeof value
=== 'bigint') {
53 return String(value
) + 'n';
56 if (typeof value
=== 'object' && value
!== null) {
57 if (cache
.has(value
)) {
58 return internals
.kCircularString
;
69 * Given an ansi keyword, it will return the appropriate code.
71 * @function getAnsiCode
73 * @param {String} ansiString the name of the desired code
74 * @return {String} the ansi code
76 getAnsiCode(ansiString
) {
97 case 'strikethrough_off':
135 case 'reset': // for informative purpouses
142 * Given a level, it will return the appropriate ansi keyword related
145 * @function getLevelAnsi
146 * @memberof Utilities
147 * @param {number} level the level of the log
148 * @return {String} the ansi keyword
150 getLevelAnsi(level
) {