isIn.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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) { 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. if ({}.hasOwnProperty.call(options, i)) {
  17. array[i] = (0, _toString.default)(options[i]);
  18. }
  19. }
  20. return array.indexOf(str) >= 0;
  21. } else if (_typeof(options) === 'object') {
  22. return options.hasOwnProperty(str);
  23. } else if (options && typeof options.indexOf === 'function') {
  24. return options.indexOf(str) >= 0;
  25. }
  26. return false;
  27. }
  28. module.exports = exports.default;
  29. module.exports.default = exports.default;