js data type checker Object.prototype.toString js data types TypedArray & ArrayBuffer
js 数据类型检测
"use strict";
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2020-06-09
* @modified
*
* @description js data type checker & js 数据类型检测
* @augments
* @example
* @link
*
*/
const log = console.log;
// Generator
const dataTypeChecker = (data, debug = false) => {
const log = console.log;
let result = ``;
const typeString = Object.prototype.toString.call(data);
// const typeString = Object.prototype.toString.apply(data);
result = typeString.replace(/\[object /gi, ``).replace(/\]/gi, ``);
if(!debug) {
log(`true type`, result)
}
return result;
};
export default dataTypeChecker;
export {
dataTypeChecker,
};
/*
const obj = {};
const func = () => {};
dataTypeChecker(NaN)
//"[object Number]"
dataTypeChecker(undefined)
//"[object Undefined]"
dataTypeChecker(true)
//"[object Boolean]"
dataTypeChecker({})
//"[object Object]"
dataTypeChecker(func)
//"[object Function]"
dataTypeChecker(obj)
//"[object Object]"
dataTypeChecker(Symbol())
//"[object Symbol]"
dataTypeChecker(null)
//"[object Null]"
dataTypeChecker(123)
//"[object Number]"
dataTypeChecker(BigInt(1n))
//"[object BigInt]"
// true type Number
// true type Undefined
// true type Boolean
// true type Object
// true type Function
// true type Object
// true type Symbol
// true type Null
// true type Number
// true type BigInt
*/
TypedArray & ArrayBuffer
// Generator
const dataTypeChecker = (data, debug = false) => {
const log = console.log;
let result = ``;
const typeString = Object.prototype.toString.call(data);
// const typeString = Object.prototype.toString.apply(data);
result = typeString.replace(/\[object /gi, ``).replace(/\]/gi, ``);
if(!debug) {
log(`true type`, result)
}
return result;
};
const typedArray = new Int8Array(8);
dataTypeChecker(typedArray);
// Int8Array
const buffer = new ArrayBuffer(8);
dataTypeChecker(buffer);
// ArrayBuffer