diff options
Diffstat (limited to 'std/_util/assert.ts')
-rw-r--r-- | std/_util/assert.ts | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/std/_util/assert.ts b/std/_util/assert.ts new file mode 100644 index 000000000..d797591fe --- /dev/null +++ b/std/_util/assert.ts @@ -0,0 +1,15 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. + +export class DenoStdInternalError extends Error { + constructor(message: string) { + super(message); + this.name = "DenoStdInternalError"; + } +} + +/** Make an assertion, if not `true`, then throw. */ +export function assert(expr: unknown, msg = ""): asserts expr { + if (!expr) { + throw new DenoStdInternalError(msg); + } +} |