UNPKG

1.75 kBJavaScriptView Raw
1import { __assign } from "tslib";
2/**
3 * Merge new and old settings, giving priority to new settings.
4 * New settings is optional in which case oldSettings is returned as-is.
5 * @param oldSettings - Old settings to fall back to.
6 * @param newSettings - New settings that will be merged over oldSettings.
7 * @returns Merged settings.
8 */
9export function mergeSettings(oldSettings, newSettings) {
10 if (oldSettings === void 0) { oldSettings = {}; }
11 var mergeSettingsWith = _isSettingsFunction(newSettings) ? newSettings : _settingsMergeWith(newSettings);
12 return mergeSettingsWith(oldSettings);
13}
14export function mergeScopedSettings(oldSettings, newSettings) {
15 if (oldSettings === void 0) { oldSettings = {}; }
16 var mergeSettingsWith = _isSettingsFunction(newSettings) ? newSettings : _scopedSettingsMergeWith(newSettings);
17 return mergeSettingsWith(oldSettings);
18}
19function _isSettingsFunction(settings) {
20 return typeof settings === 'function';
21}
22function _settingsMergeWith(newSettings) {
23 return function (settings) { return (newSettings ? __assign(__assign({}, settings), newSettings) : settings); };
24}
25function _scopedSettingsMergeWith(scopedSettingsFromProps) {
26 if (scopedSettingsFromProps === void 0) { scopedSettingsFromProps = {}; }
27 return function (oldScopedSettings) {
28 var newScopedSettings = __assign({}, oldScopedSettings);
29 for (var scopeName in scopedSettingsFromProps) {
30 if (scopedSettingsFromProps.hasOwnProperty(scopeName)) {
31 newScopedSettings[scopeName] = __assign(__assign({}, oldScopedSettings[scopeName]), scopedSettingsFromProps[scopeName]);
32 }
33 }
34 return newScopedSettings;
35 };
36}
37//# sourceMappingURL=mergeSettings.js.map
\No newline at end of file