UNPKG

option-t

Version:

A toolkit of Nullable/Option/Result type implementation in ECMAScript. Their APIs are inspired by Rust's `Option<T>` and `Result<T, E>`.

21 lines (20 loc) 640 B
import { ERR_MSG_INPUT_IS_FROZEN_NOT_CAST_TO_MUTABLE } from './error_message.js'; export function isCurrentRealmErrorInstance(input) { const ok = input instanceof Error; return ok; } export function assertIsErrorInstance(input, message) { if (isCurrentRealmErrorInstance(input)) { return; } // We don't throw Node's AssertionError because the code size will be larger. const e = new TypeError(message, { cause: input, }); throw e; } export function assertIsNotFrozen(input) { if (Object.isFrozen(input)) { throw new TypeError(ERR_MSG_INPUT_IS_FROZEN_NOT_CAST_TO_MUTABLE); } }