1.0.1 • Published 4 years ago
@piousdeer/is v1.0.1
@piousdeer/is
Type assertion helper with TypeScript support.
export default function is(value, type) {
if (typeof type === "string") {
return typeof value === type;
}
return value instanceof type;
}
Example
import is from "@piousdeer/is";
let a: unknown;
if (is(a, "number")) {
console.log(a + 1);
}
if (is(a, Set)) {
a.clear();
}