js data type checker All In One
js data type checker All In One
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
refs
https://www.cnblogs.com/xgqfrms/p/13576577.html
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/13080932.html
未经授权禁止转载,违者必究!