@ansible/react-json-chart-builder
Version:
A chart builder component in react, which uses JSON for schema.
34 lines • 1.19 kB
JavaScript
var replaceStyleFunction = function (style, functions) {
var functionNames = Object.keys(functions);
Object.keys(style).forEach(function (topKey) {
Object.entries(style[topKey]).forEach(function (_a) {
var stylingKey = _a[0], value = _a[1];
if (typeof value === 'string') {
if (functionNames.includes(value)) {
style[topKey][stylingKey] = functions[value];
}
}
});
});
return style;
};
var recursiveReplace = function (item, functions) {
Object.keys(item).forEach(function (key) {
if (key === 'style') {
item[key] = replaceStyleFunction(item[key], functions);
}
else if (item[key] && typeof item[key] === 'object') {
item[key] = recursiveReplace(item[key], functions);
}
});
return item;
};
export var replaceStringsWithFunctions = function (schema, functions) {
if (Object.keys(functions).length < 1)
return schema;
var newSchema = schema.map(function (item) {
return recursiveReplace(item, functions);
});
return newSchema;
};
//# sourceMappingURL=stylePreprocess.js.map