isIn.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = isIn;
  6. var _assertString = _interopRequireDefault(require("./util/assertString"));
  7. var _toString = _interopRequireDefault(require("./util/toString"));
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. 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); }
  10. function isIn(str, options) {
  11. (0, _assertString.default)(str);
  12. var i;
  13. if (Object.prototype.toString.call(options) === '[object Array]') {
  14. var array = [];
  15. for (i in options) {
  16. // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
  17. // istanbul ignore else
  18. if ({}.hasOwnProperty.call(options, i)) {
  19. array[i] = (0, _toString.default)(options[i]);
  20. }
  21. }
  22. return array.indexOf(str) >= 0;
  23. } else if (_typeof(options) === 'object') {
  24. return options.hasOwnProperty(str);
  25. } else if (options && typeof options.indexOf === 'function') {
  26. return options.indexOf(str) >= 0;
  27. }
  28. return false;
  29. }
  30. module.exports = exports.default;
  31. module.exports.default = exports.default;