1
0
mirror of synced 2024-11-25 14:56:03 +03:00
This commit is contained in:
1on 2021-09-21 10:32:18 +03:00
parent 9792a1863c
commit 8c7d71467f
3 changed files with 25 additions and 13 deletions

View File

@ -66,6 +66,15 @@ var TYPE;
TYPE["UNDEFINED"] = "UNDEFINED"; TYPE["UNDEFINED"] = "UNDEFINED";
TYPE["NULL"] = "NULL"; TYPE["NULL"] = "NULL";
})(TYPE || (TYPE = {})); })(TYPE || (TYPE = {}));
const constructorOf = (value) => {
return Object.getPrototypeOf(value).constructor;
};
function isRecord(value) {
return constructorOf(value) === Object && Object.keys(Object.getPrototypeOf(value)).length === 0;
}
function isRecordLike(value) {
return typeof value === 'object' && value !== null && (isRecord(value) || Array.isArray(value));
}
function typeOf(value) { function typeOf(value) {
switch (typeof value) { switch (typeof value) {
case 'bigint': case 'bigint':
@ -92,16 +101,13 @@ function typeOf(value) {
if (Array.isArray(value)) { if (Array.isArray(value)) {
return TYPE.ARRAY; return TYPE.ARRAY;
} }
if (value.constructor.name === 'Object') { if (isRecord(value)) {
return TYPE.RECORD; return TYPE.RECORD;
} }
return 'InstanceOf<' + value.constructor.name + '>'; return 'InstanceOf<' + constructorOf(value).name + '>';
} }
throw new Error(); throw new Error();
} }
function isRecordLike(value) {
return typeof value === 'object' && value !== null && ['Array', 'Object'].includes(value.constructor.name);
}
function isScalar(value) { function isScalar(value) {
switch (typeof value) { switch (typeof value) {
case 'bigint': case 'bigint':

File diff suppressed because one or more lines are too long

View File

@ -71,6 +71,15 @@
TYPE["UNDEFINED"] = "UNDEFINED"; TYPE["UNDEFINED"] = "UNDEFINED";
TYPE["NULL"] = "NULL"; TYPE["NULL"] = "NULL";
})(TYPE || (TYPE = {})); })(TYPE || (TYPE = {}));
const constructorOf = (value) => {
return Object.getPrototypeOf(value).constructor;
};
function isRecord(value) {
return constructorOf(value) === Object && Object.keys(Object.getPrototypeOf(value)).length === 0;
}
function isRecordLike(value) {
return typeof value === 'object' && value !== null && (isRecord(value) || Array.isArray(value));
}
function typeOf(value) { function typeOf(value) {
switch (typeof value) { switch (typeof value) {
case 'bigint': case 'bigint':
@ -97,16 +106,13 @@
if (Array.isArray(value)) { if (Array.isArray(value)) {
return TYPE.ARRAY; return TYPE.ARRAY;
} }
if (value.constructor.name === 'Object') { if (isRecord(value)) {
return TYPE.RECORD; return TYPE.RECORD;
} }
return 'InstanceOf<' + value.constructor.name + '>'; return 'InstanceOf<' + constructorOf(value).name + '>';
} }
throw new Error(); throw new Error();
} }
function isRecordLike(value) {
return typeof value === 'object' && value !== null && ['Array', 'Object'].includes(value.constructor.name);
}
function isScalar(value) { function isScalar(value) {
switch (typeof value) { switch (typeof value) {
case 'bigint': case 'bigint':