WizardConnect/packages/core/src/primitives.ts

24 lines
675 B
TypeScript
Raw Normal View History

2026-02-26 11:19:47 +01:00
// Copyright (C) 2026 Whiterun LLC,
// This software is licensed under the GNU Lesser General Public License (LGPL), version 3.0 or later.
// A copy of the license can be found in the LICENSE file or at https://www.gnu.org/licenses/lgpl-3.0.html
/**
* Minimal primitives shim — replaces @riftenlabs/primitives.
*/
export const throwUnless = (x: boolean, what: string): void => {
if (!x) {
throw Error(`Internal application error: ${what}`);
}
};
export function unwrap<T>(value: string | Error | T): T {
if (typeof value === "string") {
throw new Error(`unwrap: ${value}`);
}
if (value instanceof Error) {
throw value;
}
return value as T;
}