UNPKG

@splitsoftware/splitio-commons

Version:
31 lines (30 loc) 1.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateSplit = void 0; var constants_1 = require("../../logger/constants"); var lang_1 = require("../lang"); // include BOM and nbsp var TRIMMABLE_SPACES_REGEX = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/; function validateSplit(log, maybeSplit, method, item) { if (item === void 0) { item = 'feature flag name'; } if (maybeSplit == undefined) { // eslint-disable-line eqeqeq log.error(constants_1.ERROR_NULL, [method, item]); } else if (!(0, lang_1.isString)(maybeSplit)) { log.error(constants_1.ERROR_INVALID, [method, item]); } else { if (TRIMMABLE_SPACES_REGEX.test(maybeSplit)) { log.warn(constants_1.WARN_TRIMMING, [method, item, maybeSplit]); maybeSplit = maybeSplit.trim(); } if (maybeSplit.length > 0) { return maybeSplit; } else { log.error(constants_1.ERROR_EMPTY, [method, item]); } } return false; } exports.validateSplit = validateSplit;