@protorians/core
Version:
Protorians Core
49 lines (48 loc) • 1.39 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.revealType = revealType;
function revealType(value) {
if (value === null)
return 'null';
if (value === undefined)
return 'undefined';
if (typeof value === 'string') {
const val = value.trim().toLowerCase();
if (val === 'null')
return 'null';
if (val === 'undefined')
return 'undefined';
if (val === 'true' || val === 'false')
return 'boolean';
if (!isNaN(Number(val)) && val !== '')
return 'number';
if (/^\d+n$/.test(val))
return 'bigint';
try {
const parsed = JSON.parse(value);
return revealType(parsed);
}
catch (_a) {
}
return 'string';
}
if (typeof value === 'boolean')
return 'boolean';
if (typeof value === 'number')
return 'number';
if (typeof value === 'bigint')
return 'bigint';
if (typeof value === 'symbol')
return 'symbol';
if (typeof value === 'function')
return 'function';
if (Array.isArray(value))
return 'array';
if (value instanceof Date)
return 'date';
if (value instanceof RegExp)
return 'regexp';
if (typeof value === 'object')
return 'object';
return typeof value;
}