@opra/common
Version:
Opra common package
38 lines (37 loc) • 1.19 kB
JavaScript
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 RpcHeader = 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.deprecated = initArgs.deprecated;
_this.required = initArgs.required;
};
/**
* @class RpcHeader
*/
class RpcHeaderClass extends Value {
toJSON() {
return omitUndefined({
...super.toJSON(),
name: this.name,
required: this.required,
deprecated: this.deprecated,
});
}
}
RpcHeader.prototype = RpcHeaderClass.prototype;