UNPKG

635 BJavaScriptView Raw
1/*
2 * Error type & handling, assertions
3 */
4
5class InputError extends Error {
6 constructor(description, node) {
7 super(description);
8
9 Object.assign(this, {
10 description,
11 node,
12 inputError: true
13 });
14 }
15}
16
17export function assertInput(condition, description, node) {
18 if (!condition) {
19 throw new InputError(description, node);
20 }
21}
22
23export function assertUnique(map, description, node) {
24 const dupes = Object.keys(map).filter(
25 key => map[key] > 1
26 );
27 assertInput(dupes.length === 0,
28 `${description}: ${dupes}`,
29 node
30 );
31}