api.js
function normalizeRequestParameters (defaultsObject, paramsName, requestParams) {
  var promise = new Promise(function (resolve, reject) {
    var defaultParams;
    var onlyOne;
  
    // First check if we have a default parameters object with this name
    if (typeof defaultsObject[paramsName] !== 'object') reject(new RequiredError(`No default parameters for '${paramsName}'`, paramsName, defaultsObject[paramsName]));
    
    // Create an empty object with default parameters
    defaultParams = extend(Object.create(null), defaultsObject[paramsName]);
    
    // Check if there is only one required parameter in defaults
    onlyOne = checkIfOnlyOneRequired(defaultParams);
    
    // If checked parameters are not an object
    if (typeof requestParams !== 'object') {
      // If they are a string or a valid number and there is only one required parameter in default parameters
      if ((typeof requestParams === 'string' || (typeof requestParams === 'number' && isNaN(requestParams))) && onlyOne !== false) {
        // Provide this value as a value in the default params
        defaultParams[onlyOne] = requestParams;
      } else {
        // Reject with error in other case
        reject(new RequiredError('No request parameters provided', 'requestParams', requestParams));
      }
    }
    
    for (var key in defaultParams) {
      if (checkRequiredParameter(requestParams[key]) && defaultParams[key] === '') {
        reject(new RequiredError(`Missing required parameter '${key}'`, key, requestParams[key]));
      } else if (!checkRequiredParameter(requestParams[key])) {
        defaultParams[key] = requestParams[key];
      }
      if (defaultParams[key] === '__optional') defaultParams[key] = '';
    }
    
    resolve(defaultParams);
    
  });
  
  return promise;
}
function normalizeRequestParameters (defaultsObject, paramsName, requestParams) {
  var promise = new Promise(function (resolve, reject) {
    var defaultParams;
    var onlyOne;
  
    // First check if we have a default parameters object with this name
    if (typeof defaultsObject[paramsName] !== 'object') reject(new RequiredError(`No default parameters for '${paramsName}'`, paramsName, defaultsObject[paramsName]));
    
    // Create an empty object with default parameters
    defaultParams = extend(Object.create(null), defaultsObject[paramsName]);
    
    // Check if there is only one required parameter in defaults
    onlyOne = checkIfOnlyOneRequired(defaultParams);
    
    // If checked parameters are not an object
    if (typeof requestParams !== 'object') {
      // If they are a string or a valid number and there is only one required parameter in default parameters
      if ((typeof requestParams === 'string' || (typeof requestParams === 'number' && isNaN(requestParams))) && onlyOne !== false) {
        // Provide this value as a value in the default params
        defaultParams[onlyOne] = requestParams;
      } else {
        // Reject with error in other case
        reject(new RequiredError('No request parameters provided', 'requestParams', requestParams));
      }
    }
    
    for (var key in defaultParams) {
      if (checkRequiredParameter(requestParams[key]) && defaultParams[key] === '') {
        reject(new RequiredError(`Missing required parameter '${key}'`, key, requestParams[key]));
      } else if (!checkRequiredParameter(requestParams[key])) {
        defaultParams[key] = requestParams[key];
      }
      if (defaultParams[key] === '__optional') defaultParams[key] = '';
    }
    
    resolve(defaultParams);
    
  });
  
  return promise;
}
function normalizeRequestParameters ( defaultsObject , paramsName , requestParams ) { var promise = new Promise ( function ( resolve , reject ) { var defaultParams ; var onlyOne ; // First check if we have a default parameters object with this name if ( typeof defaultsObject [ paramsName ] !== 'object' ) reject ( new RequiredError ( ` ${ paramsName } ` , paramsName , defaultsObject [ paramsName ] ) ) ; // Create an empty object with default parameters defaultParams = extend ( Object . create ( null ) , defaultsObject [ paramsName ] ) ; // Check if there is only one required parameter in defaults onlyOne = checkIfOnlyOneRequired ( defaultParams ) ; // If checked parameters are not an object if ( typeof requestParams !== 'object' ) { // If they are a string or a valid number and there is only one required parameter in default parameters if ( ( typeof requestParams === 'string' || ( typeof requestParams === 'number' && isNaN ( requestParams ) ) ) && onlyOne !== false ) { // Provide this value as a value in the default params defaultParams [ onlyOne ] = requestParams ; } else { // Reject with error in other case reject ( new RequiredError ( 'No request parameters provided' , 'requestParams' , requestParams ) ) ; } } for ( var key in defaultParams ) { if ( checkRequiredParameter ( requestParams [ key ] ) && defaultParams [ key ] === '' ) { reject ( new RequiredError ( ` ${ key } ` , key , requestParams [ key ] ) ) ; } else if ( ! checkRequiredParameter ( requestParams [ key ] ) ) { defaultParams [ key ] = requestParams [ key ] ; } if ( defaultParams [ key ] === '__optional' ) defaultParams [ key ] = '' ; } resolve ( defaultParams ) ; } ) ; return promise ; }
Return a promise with normalized request parameters or an error
Return a promise with normalized request parameters or an error