UNPKG

1.54 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3function isObject(val) {
4 if (val === null) {
5 return false;
6 }
7 return typeof val === 'function' || typeof val === 'object';
8}
9/**
10 * Given a config option that could evalutate to true, config, or null; return a config.
11 * e.g.
12 * `polyfill: true` returns the `config`
13 * `polyfill: {}` returns `{}`
14 *
15 * @category utils
16 */
17function enableWithPropertyOrConfig(prop, config, merge = false) {
18 // Value is truthy.
19 if (prop) {
20 if (isObject(prop)) {
21 if (merge) {
22 if (config == null || typeof config !== 'object') {
23 throw new Error('enableWithPropertyOrConfig cannot merge config: ' + config);
24 }
25 return Object.assign(Object.assign({}, config), prop);
26 }
27 // Return property
28 return prop;
29 }
30 // Value is truthy but not a replacement config, thus return the default config.
31 return config;
32 }
33 // Return falsey.
34 return prop;
35}
36exports.enableWithPropertyOrConfig = enableWithPropertyOrConfig;
37/**
38 * Used for features that are enabled by default unless specified otherwise.
39 *
40 * @category utils
41 */
42function overrideWithPropertyOrConfig(prop, config, merge = false) {
43 if (prop === undefined) {
44 return config;
45 }
46 return enableWithPropertyOrConfig(prop, config, merge);
47}
48exports.overrideWithPropertyOrConfig = overrideWithPropertyOrConfig;
49//# sourceMappingURL=config.js.map
\No newline at end of file