B2G/gaia/apps/sms/js/contacts.js
/**
   * isMatch
   *
   * Validate a contact record against a list of terms by specified fields
   *
   * @param {Object} contact a contact record object.
   *
   * @param {Object} criteria fields and terms to validate a contact.
   *        - fields (fields of a contact record).
   *        - terms (terms to validate against contact record field values).
   */
isMatch
Validate a contact record against a list of terms by specified fields

@param {Object} contact a contact record object.

@param {Object} criteria fields and terms to validate a contact.
- fields (fields of a contact record).
- terms (terms to validate against contact record field values).
isMatch Validate a contact record against a list of terms by specified fields @param { Object } contact a contact record object . @param { Object } criteria fields and terms to validate a contact . - fields ( fields of a contact record ) . - terms ( terms to validate against contact record field values ) .
function isMatch(contact, criteria) {
    var found = {};
    outer:
    for (var i = 0, ilen = criteria.terms.length; i < ilen; i++) {
      var term = criteria.terms[i];
      for (var j = 0, jlen = criteria.fields.length; j < jlen; j++) {
        var field = criteria.fields[j];
        for (var k = 0, klen = contact[field].length; k < klen; k++) {
          var value = contact[field][k];
          if (found[term] = value.toLowerCase().startsWith(term)) {
            continue outer;
          }
        }
      }
    }
    return Object.keys(found).every(function(key) {
      return found[key];
    });
  }
function isMatch ( contact , criteria ) { var found = { } ; outer : for ( var i = 0 , ilen = criteria . terms . length ; i < ilen ; i ++ ) { var term = criteria . terms [ i ] ; for ( var j = 0 , jlen = criteria . fields . length ; j < jlen ; j ++ ) { var field = criteria . fields [ j ] ; for ( var k = 0 , klen = contact [ field ] . length ; k < klen ; k ++ ) { var value = contact [ field ] [ k ] ; if ( found [ term ] = value . toLowerCase ( ) . startsWith ( term ) ) { continue outer ; } } } } return Object . keys ( found ) . every ( function ( key ) { return found [ key ] ; } ) ; }
isMatch
 Validate a contact record against a list of terms by specified fields
isMatch Validate a contact record against a list of terms by specified fields
/**
     * Validation Strategy
     *
     * 1. Let _found_ be a register of confirmed terms
     * 2. Let _contact_ be a contact record.
     * 3. For each _term_ [...input list], with the label _outer_
     *   - For each _field_ of [givenName, familyName]
     *     - For each _value_ in _contact_[ _field_ ]
     *       - Let _found_[ _term_ ] be the result of calling
     *           _value_.startsWith( _term_ )
     *         - If _found_[ _term_ ] is **true**, continue to
     *           loop labelled _outer_
     * 4. If every value of _key_ in _found_ is **true** return **true**,
     *    else return **false**
    */ // The outer loop is specifically labelled to allow the // nested condition a way out of the second and third loop. // Pending the publication of a list of ES6 features available in Firefox // and deemed "safe enough" for FirefoxOS development, the above code is a // stand-in for what should be written as: // outer: // for (var term of criteria.terms) { //   for (var field of criteria.fields) { //     for (var value of contact[field]) { //       if (found[term] = value.toLowerCase().startsWith(term)) { //         continue outer; //       } //     } //   } // }