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