Files
NapCatQQ/.pnpm-store/v3/files/82/2bfb5a64c6e881b79d713b409442fd6016c8f7cc3adba3d4f56f6c77289a9bb8fea2c53441acba39fb7281c746307945f645e337be29756915a9f61a675d74
T
TanTan e311ca3275
Build NapCat Artifacts / Windows Loader Test (push) Canceled after 0s
Build NapCat Artifacts / Type Check & Test (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Framework (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Shell (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

36 lines
1.3 KiB
Plaintext

/**
* assert that condition is true or throw error (with message)
*/
export function assert(condition, msg) {
if (!condition) {
throw new Error(msg);
}
}
/**
* assert that value cannot exist = type `never`. throw runtime error if it does.
*/
export function assertNever(value, msg) {
throw new Error(msg !== null && msg !== void 0 ? msg : 'Unexpected object: ' + value);
}
const FLOAT32_MAX = 3.4028234663852886e+38, FLOAT32_MIN = -3.4028234663852886e+38, UINT32_MAX = 0xFFFFFFFF, INT32_MAX = 0X7FFFFFFF, INT32_MIN = -0X80000000;
export function assertInt32(arg) {
if (typeof arg !== "number")
throw new Error('invalid int 32: ' + typeof arg);
if (!Number.isInteger(arg) || arg > INT32_MAX || arg < INT32_MIN)
throw new Error('invalid int 32: ' + arg);
}
export function assertUInt32(arg) {
if (typeof arg !== "number")
throw new Error('invalid uint 32: ' + typeof arg);
if (!Number.isInteger(arg) || arg > UINT32_MAX || arg < 0)
throw new Error('invalid uint 32: ' + arg);
}
export function assertFloat32(arg) {
if (typeof arg !== "number")
throw new Error('invalid float 32: ' + typeof arg);
if (!Number.isFinite(arg))
return;
if (arg > FLOAT32_MAX || arg < FLOAT32_MIN)
throw new Error('invalid float 32: ' + arg);
}