1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.assertOptions = void 0;
|
4 | function assertOptions(options, defaults) {
|
5 | if (options !== null && options !== undefined && typeof options !== 'object') {
|
6 | throw new TypeError('Invalid "options" parameter: ' + JSON.stringify(options));
|
7 | }
|
8 | var isArray = Array.isArray(defaults);
|
9 | if (!isArray && (!defaults || typeof defaults !== 'object')) {
|
10 | throw new TypeError('Invalid "defaults" parameter: ' + JSON.stringify(defaults));
|
11 | }
|
12 | if (options) {
|
13 | for (var _i = 0, _a = Object.keys(options); _i < _a.length; _i++) {
|
14 | var a = _a[_i];
|
15 | if ((isArray && defaults.indexOf(a) === -1) || (!isArray && !(a in defaults))) {
|
16 | throw new Error('Option "' + a + '" is not recognized.');
|
17 | }
|
18 | }
|
19 | }
|
20 | else {
|
21 | options = {};
|
22 | }
|
23 | if (!isArray) {
|
24 | var defs = defaults;
|
25 | for (var _b = 0, _c = Object.keys(defs); _b < _c.length; _b++) {
|
26 | var d = _c[_b];
|
27 | if (options[d] === undefined && defs[d] !== undefined) {
|
28 | options[d] = defs[d];
|
29 | }
|
30 | }
|
31 | }
|
32 | return options;
|
33 | }
|
34 | exports.assertOptions = assertOptions;
|