UNPKG

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.

47 lines (35 loc) 1.11 kB
import { BaseValue } from "./BaseValue.js"; import { MissingArgument } from "../errors/index.js"; export class FloatType extends BaseValue { static type = "FLOAT"; static identifier = "FloatType"; #floatValue; #validate(floatValue) { if (typeof floatValue === "undefined") throw new MissingArgument("Value for FloatType must be supplied"); if ( (!(typeof floatValue === "number") && !/\./.test(floatValue)) || !/^[-+]?\d+\.\d+$/.test(floatValue) ) throw new TypeError("Invalid value for FloatType"); } get value() { return `${this.#floatValue}`; } get valueXML() { return `<${this.constructor.type.toLowerCase()}>${ this.#floatValue }</${this.constructor.type.toLowerCase()}>`; } get valueJSON() { return [this.constructor.type.toLowerCase(), this.#floatValue]; } constructor(floatValue) { super(); this.#validate(floatValue); this.#floatValue = floatValue; this.checkAbstractPropertiesAndMethods(); Object.freeze(this); } } Object.freeze(FloatType);