UNPKG

openapi-ts-generator

Version:

Based on swagger-ts-generator, this is a type script model generator specifically for services with OpenApi spec documentation.

39 lines (38 loc) 1.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getEnum = exports.getEnumDisplayText = exports.getEnumKey = void 0; /** * Retrieves the key of an enum value from a list of enum values. * * @param data - An array of enum values implementing the `IEnumValue` interface. * @param lookupValue - The value to look up in the enum, which can be a number or a string. * @returns The key of the enum value if found, otherwise `undefined`. */ function getEnumKey(data, lookupValue) { var _a; return (_a = getEnum(data, lookupValue)) === null || _a === void 0 ? void 0 : _a.key; } exports.getEnumKey = getEnumKey; /** * Retrieves the display text for a given enum value. * * @param data - An array of enum values implementing the `IEnumValue` interface. * @param lookupValue - The value to look up in the enum, which can be a number or a string. * @returns The display text associated with the given enum value, or `undefined` if not found. */ function getEnumDisplayText(data, lookupValue) { var _a; return (_a = getEnum(data, lookupValue)) === null || _a === void 0 ? void 0 : _a.displayText; } exports.getEnumDisplayText = getEnumDisplayText; /** * Retrieves an enum value from a list of enum values based on a lookup value. * * @param data - An array of enum values to search within. * @param lookupValue - The value to look up, which can be either a number or a string. * @returns The matching enum value, or `undefined` if no match is found. */ function getEnum(data, lookupValue) { return data.find(function (f) { return f.name === lookupValue || f.key === lookupValue; }); } exports.getEnum = getEnum;