mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-07 17:02:29 +01:00
32 lines
779 B
JavaScript
32 lines
779 B
JavaScript
export default class assert {
|
|
/**
|
|
* @param {*} object
|
|
* @param {Function} type
|
|
* @param {string} [msg]
|
|
* @return {*}
|
|
* @throws {TypeError}
|
|
*/
|
|
static type(object, type, msg) {
|
|
if (!(object instanceof type)) throw new TypeError(msg || `assertion failed - unexpected type for ${object.toString()}`);
|
|
return object;
|
|
}
|
|
|
|
/**
|
|
* @param {*} object
|
|
* @param {string} [msg]
|
|
* @return {*}
|
|
* @throws {TypeError}
|
|
*/
|
|
static truthy(object, msg) {
|
|
if (!object) throw new TypeError(msg || `assertion failed - object is not truthy`);
|
|
return object;
|
|
}
|
|
|
|
/**
|
|
* @param {string} msg
|
|
* @throws {TypeError}
|
|
*/
|
|
static fail(msg) {
|
|
throw new TypeError(msg);
|
|
}
|
|
}
|