UNPKG

@splitsoftware/splitio-commons

Version:
21 lines (20 loc) 1.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateAttribute = void 0; var lang_1 = require("../../utils/lang"); function validateAttribute(log, attributeKey, attributeValue, method) { if (!(0, lang_1.isString)(attributeKey) || attributeKey.length === 0) { log.warn("".concat(method, ": you passed an invalid attribute name, attribute name must be a non-empty string.")); return false; } var isStringVal = (0, lang_1.isString)(attributeValue); var isFiniteVal = (0, lang_1.isFiniteNumber)(attributeValue); var isBoolVal = (0, lang_1.isBoolean)(attributeValue); var isArrayVal = Array.isArray(attributeValue); if (!(isStringVal || isFiniteVal || isBoolVal || isArrayVal)) { // If it's not of valid type. log.warn("".concat(method, ": you passed an invalid attribute value for ").concat(attributeKey, ". Acceptable types are: string, number, boolean and array of strings.")); return false; } return true; } exports.validateAttribute = validateAttribute;