shorted-theme
Version:
Shorted theme references for Styled Components.
33 lines (32 loc) • 1.28 kB
JavaScript
;
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.functionify = void 0;
var traverse_1 = require("./traverse");
/**
* Convert all properties in a object to interpolated theme functions that return their values.
* @param target The target object.
* @param path The path to the property to convert into a function.
*/
exports.functionify = function (target, path) {
if (path === void 0) { path = []; }
return Object.keys(target).reduce(function (p, key) {
var fullPath = __spreadArrays(path, [key]);
if (typeof target[key] === 'function') {
p[key] = target[key];
}
else if (['string', 'number', 'boolean'].includes(typeof target[key])) {
p[key] = function (props) { return traverse_1.traverse(props.theme, fullPath); };
}
else {
p[key] = exports.functionify(target[key], fullPath);
}
return p;
}, {});
};