-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(testament): avoid circular deps
- Loading branch information
1 parent
8b582bc
commit 459faa4
Showing
7 changed files
with
114 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class Logger { | ||
id: string; | ||
level: number; | ||
|
||
constructor(id = "testament", level = 0) { | ||
this.id = id; | ||
this.level = level; | ||
} | ||
|
||
fine(...args: any[]): void { | ||
this.level <= 0 && this.log("FINE", args); | ||
} | ||
|
||
debug(...args: any[]): void { | ||
this.level <= 1 && this.log("DEBUG", args); | ||
} | ||
|
||
info(...args: any[]): void { | ||
this.level <= 2 && this.log("INFO", args); | ||
} | ||
|
||
warn(...args: any[]): void { | ||
this.level <= 3 && this.log("WARN", args); | ||
} | ||
|
||
severe(...args: any[]): void { | ||
this.level <= 4 && this.log("SEVERE", args); | ||
} | ||
|
||
protected log(_: string, args: any[]) { | ||
// console.log(`[${level}] ${this.id}:`, ...args); | ||
console.log(...args); | ||
} | ||
} | ||
|
||
export let LOGGER = new Logger(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { Fn0, Fn2, Timestamp } from "./api"; | ||
|
||
/** | ||
* @remarks | ||
* Copied from thi.ng/checks to avoid circular deps | ||
* | ||
* @param x | ||
* | ||
* @internal | ||
*/ | ||
export const isString = (x: any): x is string => typeof x === "string"; | ||
|
||
/** | ||
* If available, returns wrapper for `process.hrtime.bigint()` else | ||
* falls back to `Date.now()`. In all cases, returns a nanosec-scale | ||
* timestamp, either as `bigint` or `number`. | ||
* | ||
* @remarks | ||
* Copied from thi.ng/bench to avoid circular deps | ||
*/ | ||
export const now: Fn0<Timestamp> = | ||
typeof BigInt !== "undefined" | ||
? typeof process !== "undefined" && | ||
typeof process.hrtime !== "undefined" && | ||
typeof process.hrtime.bigint === "function" | ||
? () => process.hrtime.bigint() | ||
: () => BigInt(Date.now() * 1e6) | ||
: () => Date.now() * 1e6; | ||
|
||
/** | ||
* Returns the difference in milliseconds between 2 given | ||
* {@link Timestamp}s. | ||
* | ||
* @remarks | ||
* Copied from thi.ng/bench to avoid circular deps | ||
* | ||
* @param a | ||
* @param b | ||
*/ | ||
export const timeDiff: Fn2<Timestamp, Timestamp, number> = (a, b) => | ||
(typeof BigInt !== "undefined" | ||
? Number(<bigint>b - <bigint>a) | ||
: <number>b - <number>a) * 1e-6; |