UNPKG

@visactor/vchart

Version:

charts lib based @visactor/VGrammar

46 lines (39 loc) 1.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.transformFunctionAttribute = exports.functionTransform = exports.specTransform = void 0; const vutils_1 = require("@visactor/vutils"); 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 (0, vutils_1.isArray)(spec) ? spec.map((s => specTransform(s, special))) : spec; } function functionTransform(value, registry) { var _a; if (!value) return value; if ((0, vutils_1.isString)(value)) return null !== (_a = registry.getFunction(value)) && void 0 !== _a ? _a : value; if ((0, vutils_1.isPlainObject)(value)) { const result = {}; for (const key in value) Object.prototype.hasOwnProperty.call(value, key) && (result[key] = functionTransform(value[key], registry)); return result; } return (0, vutils_1.isArray)(value) ? value.map((item => functionTransform(item, registry))) : value; } function transformFunctionAttribute(att, ...args) { return (0, vutils_1.isFunction)(att) ? att(...args) : att; } exports.specTransform = specTransform, exports.functionTransform = functionTransform, exports.transformFunctionAttribute = transformFunctionAttribute; //# sourceMappingURL=transform.js.map