You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.0 KiB

4 years ago
  1. 'use strict';
  2. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  3. var values = require('../helpers/values');
  4. var _require = require('../helpers/is'),
  5. isFunction = _require.isFunction;
  6. module.exports = function contains(key, value) {
  7. if (value !== undefined) {
  8. if (Array.isArray(this.items)) {
  9. return this.items.filter(function (items) {
  10. return items[key] !== undefined && items[key] === value;
  11. }).length > 0;
  12. }
  13. return this.items[key] !== undefined && this.items[key] === value;
  14. }
  15. if (isFunction(key)) {
  16. return this.items.filter(function (item, index) {
  17. return key(item, index);
  18. }).length > 0;
  19. }
  20. if (Array.isArray(this.items)) {
  21. return this.items.indexOf(key) !== -1;
  22. }
  23. var keysAndValues = values(this.items);
  24. keysAndValues.push.apply(keysAndValues, _toConsumableArray(Object.keys(this.items)));
  25. return keysAndValues.indexOf(key) !== -1;
  26. };