UNPKG

react-native-ibm-mobilefirst-jsonstore

Version:

React Native SDK for IBM JSONStore. Works with IBM Mobile First

82 lines (73 loc) 2.2 kB
/* 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 _checkParamArrayType = function(parameter, classType) { // this function checks whether the object passed is an Array and that every item // in the array is of the specified class type. if (parameter instanceof Array == false) { throw new Error(`${parameter} is not an instance of Array`); return; } for (var p in parameter) { if (parameter[p] instanceof classType == false) { throw new Error(`${parameter[p]} is not an instance of class ${classType}`); return; } } }; /** * @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, _checkParamArrayType }