earljs
Version:
Ergonomic, modern and type-safe assertion library
45 lines (44 loc) • 1.34 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.AMatcher = void 0;
const Base_1 = require("./Base");
class AMatcher extends Base_1.Matcher {
constructor(clazz) {
super();
this.clazz = clazz;
}
check(v) {
if (this.clazz === String) {
return typeof v === 'string' || v instanceof String;
}
if (this.clazz === Number) {
return (typeof v === 'number' && !isNaN(v)) || v instanceof Number;
}
if (this.clazz === Boolean) {
return typeof v === 'boolean' || v instanceof Boolean;
}
if (this.clazz === BigInt) {
return typeof v === 'bigint' || v instanceof BigInt;
}
if (this.clazz === Function) {
return typeof v === 'function' || v instanceof Function;
}
if (this.clazz === Object) {
return typeof v === 'object' && v !== null;
}
if (this.clazz === Symbol) {
return typeof v === 'symbol';
}
if (this.clazz === Array) {
return Array.isArray(v);
}
return v instanceof this.clazz;
}
toString() {
return `[A: ${this.clazz.name}]`;
}
static make(clazz) {
return new AMatcher(clazz);
}
}
exports.AMatcher = AMatcher;
;