UNPKG

@caidrive/shared

Version:

caidrive.shared.components

98 lines (97 loc) 1.65 kB
"use strict"; /** * What it does. * * @param name - Parameter description. * @returns Type and description of the returned object. * * @example * ``` * Write me later. * ``` */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Enum = void 0; const result_1 = require("./result"); /** * */ class Enum { /** * */ /** * * */ constructor(_name, _value) { this._name = _name; this._value = _value; Enum._values.push(this); } /** * */ toString() { /* */ return `${this._name}`; } /** * */ get value() { /* */ return this._value; } /** * */ get name() { /* */ return this.toString(); } /** * */ equals(other) { /* */ return this.value === other.value && this.name === other.name; } /** * */ static find(criteria) { /** * */ let found = Enum._values.find((v) => v.name === criteria); if (!found) { /* * */ found = Enum._values.find((v) => v.value === criteria); } if (!found) { /** */ return result_1.Result.fail("Not found"); } return result_1.Result.ok(found); } /** * */ static contains(criteria) { /** * */ const result = Enum.find(criteria); return result.isSuccess; } } exports.Enum = Enum; Enum._values = new Array();