@devcycle/js-cloud-server-sdk
Version:
The DevCycle JS Cloud Bucketing Server SDK used for feature management.
45 lines • 1.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkParamType = exports.typeEnum = exports.checkParamDefined = void 0;
exports.checkParamString = checkParamString;
exports.isValidServerSDKKey = isValidServerSDKKey;
const checkParamDefined = (name, param) => {
if (param === undefined || param === null) {
throw new Error(`Missing parameter: ${name}`);
}
return param;
};
exports.checkParamDefined = checkParamDefined;
var typeEnum;
(function (typeEnum) {
typeEnum["string"] = "string";
typeEnum["number"] = "number";
typeEnum["boolean"] = "boolean";
})(typeEnum || (exports.typeEnum = typeEnum = {}));
const typeEnumValues = Object.values(typeEnum);
const checkParamType = (name, param, type) => {
if (param === undefined || param === null) {
throw new Error(`${name} is invalid!`);
}
if (!typeEnumValues.includes(type)) {
throw new Error(`unknown type to check: ${type}`);
}
if (typeof param !== type) {
throw new Error(`${name} is not of type: ${type}`);
}
if (type === typeEnum.string && !param.length) {
throw new Error(`${name} is invalid string!`);
}
if (type === typeEnum.number && isNaN(param)) {
throw new Error(`${name} is invalid number!`);
}
};
exports.checkParamType = checkParamType;
function checkParamString(name, param) {
(0, exports.checkParamType)(name, param, typeEnum.string);
return param;
}
function isValidServerSDKKey(sdkKey) {
return (sdkKey === null || sdkKey === void 0 ? void 0 : sdkKey.startsWith('server')) || (sdkKey === null || sdkKey === void 0 ? void 0 : sdkKey.startsWith('dvc_server'));
}
//# sourceMappingURL=paramUtils.js.map