Dashboard sipadu mbip
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.

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 'use strict';
  2. module.exports = function search(valueOrFunction, strict) {
  3. var _this = this;
  4. var valueFn = valueOrFunction;
  5. if (typeof valueOrFunction === 'function') {
  6. valueFn = this.items.find(function (value, key) {
  7. return valueOrFunction(value, key);
  8. });
  9. }
  10. var index = false;
  11. if (Array.isArray(this.items)) {
  12. var itemKey = this.items.filter(function (item) {
  13. if (strict === true) {
  14. return item === valueFn;
  15. }
  16. return item === Number(valueFn) || item === String(valueFn);
  17. })[0];
  18. index = this.items.indexOf(itemKey);
  19. } else {
  20. return Object.keys(this.items).filter(function (prop) {
  21. if (strict === true) {
  22. return _this.items[prop] === valueFn;
  23. }
  24. return _this.items[prop] === Number(valueFn) || _this.items[prop] === valueFn.toString();
  25. })[0] || false;
  26. }
  27. if (index === -1) {
  28. return false;
  29. }
  30. return index;
  31. };