How to use the loopback-datasource-juggler/lib/utils.isPlainObject function in loopback-datasource-juggler

To help you get started, we’ve selected a few loopback-datasource-juggler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github EdgeVerve / oe-cloud / lib / loopback-datasource-juggler-wrapper / coerce.js View on Github external
function coerceArray(val) {
  if (Array.isArray(val)) {
    return val;
  }

  if (!utils.isPlainObject(val)) {
    throw new Error(g.f('Value is not an {{array}} or {{object}} with sequential numeric indices'));
  }

  var arrayVal = new Array(Object.keys(val).length);
  for (var i = 0; i < arrayVal.length; ++i) {
    if (!val.hasOwnProperty(i)) {
      throw new Error(g.f('Value is not an {{array}} or {{object}} with sequential numeric indices'));
    }

    arrayVal[i] = val[i];
  }

  return arrayVal;
}
/* eslint-disable new-cap */