UNPKG

@opra/common

Version:
37 lines (36 loc) 1.24 kB
import { omitUndefined } from '@jsopen/objects'; import { asMutable } from 'ts-gems'; import { DocumentElement } from './document-element.js'; export const Value = function (owner, initArgs) { if (!this) throw new TypeError('"this" should be passed to call class constructor'); DocumentElement.call(this, owner); // if (args.name && !PARAMETER_NAME_PATTERN.test(args.name)) // throw new TypeError(`"${args.name}" is not a valid parameter name`); const _this = asMutable(this); _this.description = initArgs.description; _this.type = initArgs.type; _this.examples = initArgs.examples; _this.isArray = initArgs.isArray; }; /** * @class Value */ class ValueClass extends DocumentElement { toJSON(options) { const typeName = this.type ? this.node.getDataTypeNameWithNs(this.type) : undefined; return omitUndefined({ type: this.type ? typeName ? typeName : this.type.toJSON(options) : 'any', description: this.description, isArray: this.isArray, examples: this.examples, }); } } Value.prototype = ValueClass.prototype;