UNPKG

@opra/common

Version:
47 lines (46 loc) 1.61 kB
import { omitUndefined } from '@jsopen/objects'; import { asMutable, } from 'ts-gems'; import { Value } from '../common/value.js'; import { parseRegExp } from '../utils/parse-regexp.util.js'; export const HttpParameter = function (owner, initArgs) { if (!this) throw new TypeError('"this" should be passed to call class constructor'); Value.call(this, owner, initArgs); const _this = asMutable(this); if (initArgs.name) { _this.name = initArgs.name instanceof RegExp ? initArgs.name : initArgs.name.startsWith('/') ? parseRegExp(initArgs.name, { includeFlags: 'i', excludeFlags: 'm', }) : initArgs.name; } _this.location = initArgs.location; _this.deprecated = initArgs.deprecated; _this.required = initArgs.required; if (_this.required == null && initArgs.location === 'path') _this.required = true; _this.arraySeparator = initArgs.arraySeparator; _this.keyParam = initArgs.keyParam; _this.parser = initArgs.parser; }; /** * @class HttpParameter */ class HttpParameterClass extends Value { toJSON(options) { return omitUndefined({ ...super.toJSON(options), name: this.name, location: this.location, arraySeparator: this.arraySeparator, keyParam: this.keyParam, required: this.required, deprecated: this.deprecated, }); } } HttpParameter.prototype = HttpParameterClass.prototype;