isMatch.js 447 B

1234567891011121314151617
  1. define(['./keys'], function (keys) {
  2. // Returns whether an object has a given set of `key:value` pairs.
  3. function isMatch(object, attrs) {
  4. var _keys = keys(attrs), length = _keys.length;
  5. if (object == null) return !length;
  6. var obj = Object(object);
  7. for (var i = 0; i < length; i++) {
  8. var key = _keys[i];
  9. if (attrs[key] !== obj[key] || !(key in obj)) return false;
  10. }
  11. return true;
  12. }
  13. return isMatch;
  14. });