2019-08-10 22:07:02 +00:00
|
|
|
/**
|
2019-09-14 20:39:18 +00:00
|
|
|
* Assert that the statement is true, otherwise invoke an error with the given message.
|
2019-08-10 22:07:02 +00:00
|
|
|
*/
|
|
|
|
export function assert(statement: boolean, error: string): void {
|
|
|
|
if (!statement) {
|
|
|
|
throw new Error(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-20 04:31:43 +00:00
|
|
|
/**
|
|
|
|
* A basic logging interface
|
|
|
|
*/
|
|
|
|
interface Logger {
|
|
|
|
log: (args?: any[]) => void;
|
|
|
|
warn: (args?: any[]) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The default logger is the console
|
|
|
|
*/
|
|
|
|
let defaultLogger: Logger = console;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the logging interface
|
|
|
|
*/
|
2019-09-20 21:49:54 +00:00
|
|
|
export function setLogger(logger: Logger): void {
|
|
|
|
defaultLogger = logger;
|
2019-09-20 04:31:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log anything
|
|
|
|
*/
|
2019-08-10 22:07:02 +00:00
|
|
|
export function log(...args: any[]): void {
|
2019-09-20 04:31:43 +00:00
|
|
|
defaultLogger.log(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Warn anything
|
|
|
|
*/
|
|
|
|
export function warn(...args: any[]): void {
|
|
|
|
defaultLogger.warn(...args);
|
2019-08-10 22:07:02 +00:00
|
|
|
}
|