UNPKG

@splitsoftware/splitio-commons

Version:
30 lines (29 loc) 1.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateTrafficType = void 0; var constants_1 = require("../../logger/constants"); var lang_1 = require("../lang"); var CAPITAL_LETTERS_REGEX = /[A-Z]/; var item = 'traffic_type'; function validateTrafficType(log, maybeTT, method) { if (maybeTT == undefined) { // eslint-disable-line eqeqeq log.error(constants_1.ERROR_NULL, [method, item]); } else if (!(0, lang_1.isString)(maybeTT)) { log.error(constants_1.ERROR_INVALID, [method, item]); } else { if (maybeTT.length === 0) { log.error(constants_1.ERROR_EMPTY, [method, item]); } else { if (CAPITAL_LETTERS_REGEX.test(maybeTT)) { log.warn(constants_1.WARN_LOWERCASE_TRAFFIC_TYPE, [method]); maybeTT = maybeTT.toLowerCase(); } return maybeTT; } } return false; } exports.validateTrafficType = validateTrafficType;