assertString.js 761 B

123456789101112
  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. export default function assertString(input) {
  3. var isString = typeof input === 'string' || input instanceof String;
  4. if (!isString) {
  5. var invalidType = _typeof(input);
  6. if (input === null) invalidType = 'null';else if (invalidType === 'object') invalidType = input.constructor.name;
  7. throw new TypeError("Expected a string but received a ".concat(invalidType));
  8. }
  9. }