@react-md/utils
Version:
General utils for react-md.
33 lines • 1.25 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
/**
* This is normally used for reusable shareable configs that have multiple
* shared options with default values that should be used. This basically works
* just like `defaultProps` in react.
*
* @internal
* @param optional - The original object that has the optional/omitted values
* @param required - The required default values that should be used to fill the
* optional object with
* @returns a new object with both the values of the optional and required
* objects but use the optional values if they were defined.
*/
export function defaults(optional, required) {
var keys = Object.keys(required);
return keys.reduce(function (result, key) {
if (typeof result[key] === "undefined") {
result[key] = required[key];
}
return result;
}, __assign({}, optional));
}
//# sourceMappingURL=defaults.js.map