assertString.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = assertString;
  6. 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); }
  7. function assertString(input) {
  8. var isString = typeof input === 'string' || input instanceof String;
  9. if (!isString) {
  10. var invalidType;
  11. if (input === null) {
  12. invalidType = 'null';
  13. } else {
  14. invalidType = _typeof(input);
  15. if (invalidType === 'object' && input.constructor && input.constructor.hasOwnProperty('name')) {
  16. invalidType = input.constructor.name;
  17. } else {
  18. invalidType = "a ".concat(invalidType);
  19. }
  20. }
  21. throw new TypeError("Expected string but received ".concat(invalidType, "."));
  22. }
  23. }
  24. module.exports = exports.default;
  25. module.exports.default = exports.default;