-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
assertString.js
29 lines (25 loc) · 1.03 KB
/
assertString.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
exports.default = assertString;
function assertString(input) {
var isString = typeof input === 'string' || input instanceof String;
if (!isString) {
var invalidType = void 0;
if (input === null) {
invalidType = 'null';
} else {
invalidType = typeof input === 'undefined' ? 'undefined' : _typeof(input);
if (invalidType === 'object' && input.constructor && input.constructor.hasOwnProperty('name')) {
invalidType = input.constructor.name;
} else {
invalidType = 'a ' + invalidType;
}
}
var message = 'Expected string but received ' + invalidType + '.';
throw new TypeError(message);
}
}
module.exports = exports['default'];