decova-dotnet
Version:
This package provides fundumentals that a .net developer may miss while working with Typescript, whether they are missing functinalities or funcionalities provided in a non-elegant design in javascript. Bad naming, bad design of optional parameters, non-c
59 lines • 1.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Is = exports.TypeInfo = void 0;
const Exceptions_1 = require("../Exceptions/Exceptions");
class TypeInfo {
constructor(Type) {
this.Type = Type;
}
static Of(type) {
return type.Type ? type : new TypeInfo(type);
}
IsAssignableFrom(type) {
var _a;
const typeConstructor = (_a = type.Type) !== null && _a !== void 0 ? _a : type;
let stepConstructor = this.Type;
do {
if (typeConstructor === stepConstructor) {
return true;
}
stepConstructor = Object.getPrototypeOf(stepConstructor);
} while (stepConstructor);
return false;
}
static OfObject(obj) {
let type = obj.constructor;
while (!!type && !type.name) {
type = Object.getPrototypeOf(type);
}
return new TypeInfo(type);
}
}
exports.TypeInfo = TypeInfo;
class ObjInvestigator {
constructor(obj) {
this.obj = obj;
}
OfType(type) {
var _a;
let proto = Object.getPrototypeOf(this.obj);
if (!proto)
throw new Exceptions_1.Exception(`xIs() failed: Object.getPrototypeOf(${(_a = this.constructor) === null || _a === void 0 ? void 0 : _a.name}) is undefined!`);
while (proto) {
if (proto.constructor === type)
return true;
}
return false;
}
Array() {
return Array.isArray(this.obj);
}
Primitive() {
return this.obj !== Object(this.obj);
}
}
function Is(obj) {
return new ObjInvestigator(obj);
}
exports.Is = Is;
//# sourceMappingURL=Type.js.map