vcard4
Version:
An RFC 6350 compliant JavaScript library for generating and parsing version 4.0 vCards. Can also generate RFC 6351 compliant XML vCards and RFC 7095 compliant jCards. TypeScript type declarations are provided.
45 lines (34 loc) • 1.11 kB
JavaScript
import { BaseValue } from "./BaseValue.js";
import { MissingArgument, InvalidArgument } from "../errors/index.js";
export class URIType extends BaseValue {
static type = "URI";
static identifier = "URIType";
#uriValue;
#validate(uriValue) {
if (typeof uriValue === "undefined")
throw new MissingArgument("Value for URIType must be supplied");
else if (typeof uriValue !== "string")
throw new TypeError("Value for URIType should be of type string");
else if (!URL.canParse(uriValue))
throw new InvalidArgument("Invalid URI");
}
get value() {
return this.#uriValue;
}
get valueXML() {
return `<${this.constructor.type.toLowerCase()}>${
this.#uriValue
}</${this.constructor.type.toLowerCase()}>`;
}
get valueJSON() {
return [this.constructor.type.toLowerCase(), this.#uriValue];
}
constructor(uriValue) {
super();
this.#validate(uriValue);
this.#uriValue = uriValue;
this.checkAbstractPropertiesAndMethods();
Object.freeze(this);
}
}
Object.freeze(URIType);