1 | ;
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = verify;
|
7 | /**
|
8 | * A convenience assertion utility, typically used to validate
|
9 | * pre-conditions of a routine.
|
10 | *
|
11 | * **Advanced**: verify.prefix(msgPrefix) returns a higher-order
|
12 | * verify() function where all messaged are prefixed.
|
13 | *
|
14 | * @param {truthy} condition - a "truthy" condition which
|
15 | * must be satisfied.
|
16 | *
|
17 | * @param {string} msg - a message clarifying the condition being
|
18 | * checked.
|
19 | *
|
20 | * @throws {Error} an Error is thrown when the supplied condition is
|
21 | * NOT met.
|
22 | *
|
23 | * @private
|
24 | */
|
25 | function verify(condition, msg) {
|
26 | if (!condition) {
|
27 | throw new Error(msg);
|
28 | }
|
29 | }
|
30 |
|
31 | verify.prefix = function (msgPrefix) {
|
32 | return function (condition, msg) {
|
33 | return verify(condition, msgPrefix + msg);
|
34 | };
|
35 | }; |
\ | No newline at end of file |