@splitsoftware/splitio-commons
Version:
Split JavaScript SDK common components
37 lines (36 loc) • 1.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.keyParser = exports.getBucketing = exports.getMatching = void 0;
var lang_1 = require("../lang");
// function isSplitKeyObject(key: any): key is SplitIO.SplitKeyObject {
// return key !== undefined && key !== null && typeof key.matchingKey === 'string';
// }
// returns the matchingKey if the Key is defined as an object or the key itself if it is a string
function getMatching(key) {
return (0, lang_1.isObject)(key) ? key.matchingKey : key;
}
exports.getMatching = getMatching;
// if the key is a string, there's no bucketingKey (undefined)
function getBucketing(key) {
return (0, lang_1.isObject)(key) ? key.bucketingKey : undefined;
}
exports.getBucketing = getBucketing;
/**
* Verify type of key and return a valid object key used for get treatment for a
* specific split.
*/
function keyParser(key) {
if ((0, lang_1.isObject)(key)) {
return {
matchingKey: key.matchingKey,
bucketingKey: key.bucketingKey
};
}
else {
return {
matchingKey: key,
bucketingKey: key
};
}
}
exports.keyParser = keyParser;