Sha256: 2f1df6fafcf53bb8593070f72410f9244c649dc7348e8f7051d6fc12938385a0
Contents?: true
Size: 1.13 KB
Versions: 10
Compression:
Stored size: 1.13 KB
Contents
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = builder; function _clone() { const data = _interopRequireDefault(require("lodash/clone")); _clone = function () { return data; }; return data; } var _definitions = require("../definitions"); var _validate = _interopRequireDefault(require("../validators/validate")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function builder(type, ...args) { const keys = _definitions.BUILDER_KEYS[type]; const countArgs = args.length; if (countArgs > keys.length) { throw new Error(`${type}: Too many arguments passed. Received ${countArgs} but can receive no more than ${keys.length}`); } const node = { type }; let i = 0; keys.forEach(key => { const field = _definitions.NODE_FIELDS[type][key]; let arg; if (i < countArgs) arg = args[i]; if (arg === undefined) arg = (0, _clone().default)(field.default); node[key] = arg; i++; }); for (const key of Object.keys(node)) { (0, _validate.default)(node, key, node[key]); } return node; }
Version data entries
10 entries across 10 versions & 3 rubygems