js/Utils.js
/* Licensed Materials - Property of IBM
* 5725-I43 (C) Copyright IBM Corp. 2018. All Rights Reserved.
* US Government Users Restricted Rights - Use, duplication or
* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
*/
/* author - Yash Soni | yashsoni21@in.ibm.com */
/**
* @ignore
*/
const _mandatoryParam = function(parameterName) {
throw new Error('Error: Missing parameter ' + parameterName);
};
/**
* @ignore
*/
const _checkParamClassType = function(parameter, classType) {
// this function checks class types like Array, JsonStoreQuery, JsonStoreQueryParts
if (parameter instanceof classType == false) {
throw new Error(`${parameter} is not an instance of class ${classType}`);
}
};
/**
* @ignore
*/
const _checkParamType = function(parameter, type) {
// this function checks native types like string, boolean, number
if (typeof parameter !== type) {
throw new Error(`${parameter} is not of type ${type}`);
}
};
/**
* @ignore
*/
const _isNativeType = function(value) {
if (typeof value !== 'boolean' && typeof value !== 'string' && typeof value !== 'number') {
return false;
}
return true;
};
/**
* @ignore
*/
const _checkIfNativeType = function(value) {
if (!_isNativeType(value)) {
throw new Error(`${value} is not of either type in ['boolean', 'string', 'number']`);
}
}
/**
* @ignore
*/
const ParamTypes = {
STRING: 'string',
NUMBER: 'number',
BOOLEAN: 'boolean'
}
export { _mandatoryParam, _checkParamClassType, _checkParamType, ParamTypes, _checkIfNativeType }