typescript-util
Version:
JS/TS 的简单工具
37 lines • 1.03 kB
JavaScript
import { AssertException } from '../exception/AssertException';
/**
* Assert
* @author LL
* @date 2022-01-22 上午 12:50
**/
export class Assert {
/**
* 断言 true
* @param {boolean} status
* @param {string} msg
*/
static isTrue(status, msg) {
// noinspection SuspiciousTypeOfGuard
if (typeof status !== 'boolean') {
throw new TypeError('期望 boolean 类型, 实际获得 ' + status);
}
if (!status) {
throw new AssertException(msg ?? '断言错误: 期望 true');
}
}
/**
* 断言 false
* @param {boolean} status
* @param {string} msg
*/
static isFalse(status, msg) {
// noinspection SuspiciousTypeOfGuard
if (typeof status !== 'boolean') {
throw new TypeError('期望 boolean 类型, 实际获得 ' + status);
}
if (status) {
throw new AssertException(msg ?? '断言错误: 期望 false');
}
}
}
//# sourceMappingURL=Assert.js.map