mirror of
https://github.com/Tonejs/Tone.js
synced 2024-12-31 22:18:44 +00:00
42 lines
733 B
TypeScript
42 lines
733 B
TypeScript
/**
|
|
* Assert that the statement is true, otherwise invoke an error with the given message.
|
|
*/
|
|
export function assert(statement: boolean, error: string): void {
|
|
if (!statement) {
|
|
throw new Error(error);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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
|
|
*/
|
|
export function setLogger(logger: Logger): void {
|
|
defaultLogger = logger;
|
|
}
|
|
|
|
/**
|
|
* Log anything
|
|
*/
|
|
export function log(...args: any[]): void {
|
|
defaultLogger.log(...args);
|
|
}
|
|
|
|
/**
|
|
* Warn anything
|
|
*/
|
|
export function warn(...args: any[]): void {
|
|
defaultLogger.warn(...args);
|
|
}
|