lib/mock/edit-collection.js
function getResourceNameByName (data, schema) {
  /** @name PropertyInfo */
  let propInfo = {
    name: "",
    schema: {
      type: ""
    },
    value: undefined
  };

  // Get a list of all existing and possible properties of the resource
  let propNames = _.union(_.keys(schema.properties), _.keys(data));

  // Lowercase property names, for comparison
  let lowercasePropNames = propNames.map((propName) => { return propName.toLowerCase(); });

  // These properties are assumed to be unique IDs.
  // If we find any of them in the schema, then use it as the REST resource's name.
  let nameProperties = ["id", "key", "slug", "code", "number", "num", "nbr", "username", "name"];
  let foundMatch = nameProperties.some((lowercasePropName) => {
    let index = lowercasePropNames.indexOf(lowercasePropName);
    if (index >= 0) {
      // We found a property that appears to be the resource's name. Get its info.
      propInfo.name = propNames[index];
      propInfo.value = data ? data[propInfo.name] : undefined;

      if (schema.properties[propInfo.name]) {
        propInfo.schema = schema.properties[propInfo.name];
      }
      else if (_.isDate(data[propInfo.name])) {
        propInfo.schema = {
          type: "string",
          format: "date-time"
        };
      }
      else {
        propInfo.schema.type = typeof (data[propInfo.name]);
      }

      // If the property is valid, then we're done
      return isValidResourceName(propInfo);
    }
  });

  return foundMatch ? propInfo : undefined;
}
function getResourceNameByName (data, schema) {
  /** @name PropertyInfo */
  let propInfo = {
    name: "",
    schema: {
      type: ""
    },
    value: undefined
  };

  // Get a list of all existing and possible properties of the resource
  let propNames = _.union(_.keys(schema.properties), _.keys(data));

  // Lowercase property names, for comparison
  let lowercasePropNames = propNames.map((propName) => { return propName.toLowerCase(); });

  // These properties are assumed to be unique IDs.
  // If we find any of them in the schema, then use it as the REST resource's name.
  let nameProperties = ["id", "key", "slug", "code", "number", "num", "nbr", "username", "name"];
  let foundMatch = nameProperties.some((lowercasePropName) => {
    let index = lowercasePropNames.indexOf(lowercasePropName);
    if (index >= 0) {
      // We found a property that appears to be the resource's name. Get its info.
      propInfo.name = propNames[index];
      propInfo.value = data ? data[propInfo.name] : undefined;

      if (schema.properties[propInfo.name]) {
        propInfo.schema = schema.properties[propInfo.name];
      }
      else if (_.isDate(data[propInfo.name])) {
        propInfo.schema = {
          type: "string",
          format: "date-time"
        };
      }
      else {
        propInfo.schema.type = typeof (data[propInfo.name]);
      }

      // If the property is valid, then we're done
      return isValidResourceName(propInfo);
    }
  });

  return foundMatch ? propInfo : undefined;
}
function getResourceNameByName ( data , schema ) { /** @name PropertyInfo */ let propInfo = { name : "" , schema : { type : "" } , value : undefined } ; // Get a list of all existing and possible properties of the resource let propNames = _ . union ( _ . keys ( schema . properties ) , _ . keys ( data ) ) ; // Lowercase property names, for comparison let lowercasePropNames = propNames . map ( ( propName ) => { return propName . toLowerCase ( ) ; } ) ; // These properties are assumed to be unique IDs. // If we find any of them in the schema, then use it as the REST resource's name. let nameProperties = [ "id" , "key" , "slug" , "code" , "number" , "num" , "nbr" , "username" , "name" ] ; let foundMatch = nameProperties . some ( ( lowercasePropName ) => { let index = lowercasePropNames . indexOf ( lowercasePropName ) ; if ( index >= 0 ) { // We found a property that appears to be the resource's name. Get its info. propInfo . name = propNames [ index ] ; propInfo . value = data ? data [ propInfo . name ] : undefined ; if ( schema . properties [ propInfo . name ] ) { propInfo . schema = schema . properties [ propInfo . name ] ; } else if ( _ . isDate ( data [ propInfo . name ] ) ) { propInfo . schema = { type : "string" , format : "date-time" } ; } else { propInfo . schema . type = typeof ( data [ propInfo . name ] ) ; } // If the property is valid, then we're done return isValidResourceName ( propInfo ) ; } } ) ; return foundMatch ? propInfo : undefined ; }
Tries to find the REST resource's name by searching for commonly-used property names like "id", "key", etc.

@param   {*}         data   - The parsed resource data.
@param   {object}    schema - The JSON schema for the data.
@returns {PropertyInfo|undefined}
Tries to find the REST resource s name by searching for commonly - used property names like id key etc .