Skip to content

Commit

Permalink
refactor: refactor assertString fn (#1454)
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthborderwala authored Nov 15, 2020
1 parent 03b60e2 commit a19ebff
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/lib/util/assertString.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
export default function assertString(input) {
const isString = (typeof input === 'string' || input instanceof String);
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}.`);
let invalidType = typeof input;
if (input === null) invalidType = 'null';
else if (invalidType === 'object') invalidType = input.constructor.name;

throw new TypeError(`Expected a string but received a ${invalidType}`);
}
}

0 comments on commit a19ebff

Please sign in to comment.