@splitsoftware/splitio-commons
Version:
Split JavaScript SDK common components
26 lines (25 loc) • 1.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateAttributesDeep = exports.validateAttributes = void 0;
var lang_1 = require("../lang");
var attribute_1 = require("./attribute");
var constants_1 = require("../../logger/constants");
function validateAttributes(log, maybeAttrs, method) {
// Attributes are optional
if (maybeAttrs == undefined || (0, lang_1.isObject)(maybeAttrs)) // eslint-disable-line eqeqeq
return maybeAttrs;
log.error(constants_1.ERROR_NOT_PLAIN_OBJECT, [method, 'attributes']);
return false;
}
exports.validateAttributes = validateAttributes;
function validateAttributesDeep(log, maybeAttributes, method) {
if (!validateAttributes(log, maybeAttributes, method))
return false;
var result = true;
Object.keys(maybeAttributes).forEach(function (attributeKey) {
if (!(0, attribute_1.validateAttribute)(log, attributeKey, maybeAttributes[attributeKey], method))
result = false;
});
return result;
}
exports.validateAttributesDeep = validateAttributesDeep;