@equinor/fusion-framework-cli
Version:
--- title: Fusion Framework CLI ---
29 lines • 1.42 kB
JavaScript
import assert, { AssertionError } from 'node:assert';
export { assert, AssertionError };
export function assertNumber(value, message) {
assert(!Number.isNaN(value), new AssertionError({
message,
actual: value,
expected: '<number>',
}));
}
export function assertObject(value, message) {
assert(typeof value === 'object', message);
}
function assertObjectEntryValue(value, prop, message) {
assert(!!value, message !== null && message !== void 0 ? message : `missing value of property ${prop}`);
}
export function assertObjectEntries(
// extends Record<string, unknown> = unknown>(
value, options) {
var _a, _b, _c;
const preMessage = (_a = options === null || options === void 0 ? void 0 : options.preMessage) !== null && _a !== void 0 ? _a : '';
assert(typeof value === 'object', `${preMessage} to be an <object>`);
const assertion = (_b = options === null || options === void 0 ? void 0 : options.assertion) !== null && _b !== void 0 ? _b : assertObjectEntryValue;
const props = (_c = options === null || options === void 0 ? void 0 : options.props) !== null && _c !== void 0 ? _c : Object.keys(value);
for (const prop of props) {
assert(prop in value, `${preMessage} to have property [${String(prop)}]`);
assertion(value[prop], prop, `${preMessage} property [${String(prop)}] to have value`);
}
}
//# sourceMappingURL=assert.js.map