@skhemata/skhemata-form
Version:
Skhemata Form Web Component. This web component can be used as base web component when working with forms and inputs.
19 lines (17 loc) • 562 B
JavaScript
export default function assertString(input) {
const isString = (typeof input === 'string' || input instanceof String);
if (!isString) {
let invalidType;
if (input === null) {
invalidType = 'null';
} else {
invalidType = typeof input;
if (invalidType === 'object' && input.constructor && input.constructor.hasOwnProperty('name')) {
invalidType = input.constructor.name;
} else {
invalidType = `a ${invalidType}`;
}
}
throw new TypeError(`Expected string but received ${invalidType}.`);
}
}