@soos-io/api-client
Advanced tools
Comparing version 0.1.5 to 0.1.6-pre.1
declare const isNil: (value: unknown) => value is null | undefined; | ||
declare const ensureValue: <T>(value: T | null | undefined, propertyName: string) => T; | ||
declare const ensureValueIsOneOf: <T extends string>(options: T[], value: string | undefined, opts?: { | ||
caseSensitive?: boolean; | ||
}) => T | undefined; | ||
declare const ensureEnumValue: <T extends string, TEnumObject extends Record<string, T> = Record<string, T>>(enumObject: TEnumObject, value: string | undefined) => T | undefined; | ||
declare const ensureEnumValue: <T, TEnumObject extends Record<string, T> = Record<string, T>>(enumObject: TEnumObject, inputValue: string | null | undefined, ignoreCase?: boolean, excludeDefault?: boolean) => T | undefined; | ||
declare const sleep: (ms: number) => Promise<unknown>; | ||
@@ -12,2 +9,2 @@ declare const isUrlAvailable: (url: string) => Promise<boolean>; | ||
declare const getEnvVariable: (name: string) => string | null; | ||
export { isNil, ensureValue, ensureValueIsOneOf, ensureEnumValue, sleep, isUrlAvailable, obfuscateProperties, convertStringToBase64, getEnvVariable, }; | ||
export { isNil, ensureValue, ensureEnumValue, sleep, isUrlAvailable, obfuscateProperties, convertStringToBase64, getEnvVariable, }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getEnvVariable = exports.convertStringToBase64 = exports.obfuscateProperties = exports.isUrlAvailable = exports.sleep = exports.ensureEnumValue = exports.ensureValueIsOneOf = exports.ensureValue = exports.isNil = void 0; | ||
exports.getEnvVariable = exports.convertStringToBase64 = exports.obfuscateProperties = exports.isUrlAvailable = exports.sleep = exports.ensureEnumValue = exports.ensureValue = exports.isNil = void 0; | ||
const tslib_1 = require("tslib"); | ||
@@ -15,18 +15,21 @@ const axios_1 = tslib_1.__importStar(require("axios")); | ||
exports.ensureValue = ensureValue; | ||
const ensureValueIsOneOf = (options, value, opts = {}) => { | ||
if (value === undefined) | ||
const ensureEnumValue = (enumObject, inputValue, ignoreCase = true, excludeDefault = true) => { | ||
if (isNil(inputValue)) { | ||
return undefined; | ||
const match = options.find((option) => { | ||
return opts.caseSensitive | ||
? option === value | ||
: option.toLocaleLowerCase() === value.toLocaleLowerCase(); | ||
} | ||
const options = Object.entries(enumObject); | ||
const option = options.find(([, value]) => { | ||
const stringValue = value.toLocaleString(); | ||
return ignoreCase | ||
? stringValue.toLocaleLowerCase() === inputValue.toLocaleLowerCase() | ||
: stringValue === inputValue; | ||
}); | ||
if (!isNil(match)) | ||
return match; | ||
throw new Error(`Invalid enum value '${value}'. Valid options are: ${options.join(", ")}.`); | ||
if (isNil(option) || excludeDefault) { | ||
throw new Error(`Invalid enum value '${inputValue}'. Valid options are: ${options | ||
.map(([, value]) => value) | ||
.join(", ")}.`); | ||
} | ||
const [key] = option; | ||
return enumObject[key]; | ||
}; | ||
exports.ensureValueIsOneOf = ensureValueIsOneOf; | ||
const ensureEnumValue = (enumObject, value) => { | ||
return ensureValueIsOneOf(Object.values(enumObject), value); | ||
}; | ||
exports.ensureEnumValue = ensureEnumValue; | ||
@@ -33,0 +36,0 @@ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); |
{ | ||
"name": "@soos-io/api-client", | ||
"version": "0.1.5", | ||
"version": "0.1.6-pre.1", | ||
"description": "This is the SOOS API Client for registered clients leveraging the various integrations to the SOOS platform.", | ||
@@ -17,4 +17,3 @@ "main": "dist/index.js", | ||
"test:coverage": "npm run test -- --reporter xunit --reporter-option output=ResultsFile.xml", | ||
"check": "npm run format && npm run typecheck && npm outdated", | ||
"outdated": "npm outdated" | ||
"check": "npm run format && npm run typecheck && npm outdated" | ||
}, | ||
@@ -21,0 +20,0 @@ "publishConfig": { |
@@ -0,0 +0,0 @@ # [About SOOS](https://soos.io/) |
Sorry, the diff of this file is not supported yet
34843