isIn.js 1.1 KB

12345678910111213141516171819202122232425262728
  1. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  2. import assertString from './util/assertString';
  3. import toString from './util/toString';
  4. export default function isIn(str, options) {
  5. assertString(str);
  6. var i;
  7. if (Object.prototype.toString.call(options) === '[object Array]') {
  8. var array = [];
  9. for (i in options) {
  10. // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
  11. // istanbul ignore else
  12. if ({}.hasOwnProperty.call(options, i)) {
  13. array[i] = toString(options[i]);
  14. }
  15. }
  16. return array.indexOf(str) >= 0;
  17. } else if (_typeof(options) === 'object') {
  18. return options.hasOwnProperty(str);
  19. } else if (options && typeof options.indexOf === 'function') {
  20. return options.indexOf(str) >= 0;
  21. }
  22. return false;
  23. }