@visactor/vchart
Version:
charts lib based @visactor/VGrammar
37 lines (33 loc) • 1.32 kB
JavaScript
import { isArray, isFunction, isPlainObject, isString } from "@visactor/vutils";
export function specTransform(spec, special = {
data: v => v
}) {
if (!spec) return spec;
if (spec.constructor === Object) {
const result = {};
for (const key in spec) if (Object.prototype.hasOwnProperty.call(spec, key)) {
if (special[key]) {
result[key] = special[key](spec[key]);
continue;
}
result[key] = specTransform(spec[key], special);
}
return result;
}
return isArray(spec) ? spec.map((s => specTransform(s, special))) : spec;
}
export function functionTransform(value, registry) {
var _a;
if (!value) return value;
if (isString(value)) return null !== (_a = registry.getFunction(value)) && void 0 !== _a ? _a : value;
if (isPlainObject(value)) {
const result = {};
for (const key in value) Object.prototype.hasOwnProperty.call(value, key) && (result[key] = functionTransform(value[key], registry));
return result;
}
return isArray(value) ? value.map((item => functionTransform(item, registry))) : value;
}
export function transformFunctionAttribute(att, ...args) {
return isFunction(att) ? att(...args) : att;
}
//# sourceMappingURL=transform.js.map