-
Notifications
You must be signed in to change notification settings - Fork 546
/
Copy pathassert.ts
25 lines (24 loc) · 1.04 KB
/
assert.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/
/**
* A browser friendly assert library.
* Use this instead of the 'assert' package, which has a big impact on bundle sizes.
* @param condition - The condition that should be true, if the condition is false an error will be thrown.
* Only use this API when `false` indicates a logic error in the problem and thus a bug that should be fixed.
* @param message - The message to include in the error when the condition does not hold.
* A number should not be specified manually: use a string.
* Before a release, policy-check should be run, which will convert any asserts still using strings to
* use numbered error codes instead.
*
* @deprecated Moved to the `@fluidframework/core-utils` package.
* @internal
*/
export function assert(condition: boolean, message: string | number): asserts condition {
if (!condition) {
throw new Error(
typeof message === "number" ? `0x${message.toString(16).padStart(3, "0")}` : message,
);
}
}