js data type checker

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 发布文章使用:只允许注册用户才可以访问!


js data type checker的更多相关文章

  1. 解析$(this).data('type');

    html: <button type="button" class="layui-btn layui-btn-sm" data-type="ad ...

  2. PHP 笔记一(systax/variables/echo/print/Data Type)

    PHP stands for "Hypertext Preprocessor" ,it is a server scripting language. What Can PHP D ...

  3. JAVA 1.2(原生数据类型 Primitive Data Type)

    1. Java的数据类型分为2类 >> 原生数据类型(primitive data type) >> 引用数据类型(reference data type) 3. 常量和变量 ...

  4. salesforce 零基础开发入门学习(四)多表关联下的SOQL以及表字段Data type详解

    建立好的数据表在数据库中查看有很多方式,本人目前采用以下两种方式查看数据表. 1.采用schema Builder查看表结构以及多表之间的关联关系,可以登录后点击setup在左侧搜索框输入schema ...

  5. The conversion of a varchar data type to a datetime data type resulted in an out-of-range value

    刚刚有在程序中,传递一个空值至MS SQL Server数据库,这个值的数据类型为DATETIME执行时,它却发生了如标题提示的异常:The conversion of a varchar data ...

  6. XML Data Type Methods(一)

    XML Data Type Methods(一) /*XML Data Type Methods: 1.The query('XQuery') method retrieves(vt.检索,重新得到) ...

  7. include pointers as a primitive data type

    Computer Science An Overview _J. Glenn Brookshear _11th Edition Many modern programming languages in ...

  8. Extended Data Type Properties [AX 2012]

    Extended Data Type Properties [AX 2012] This topic has not yet been rated - Rate this topic Updated: ...

  9. org.hibernate.id.IdentifierGenerationException: Unknown integral data type for ids : java.lang.String

    org.hibernate.id.IdentifierGenerationException: Unknown integral data type for ids : java.lang.Strin ...

随机推荐

  1. 手写Netty之多路复用Select小案例

    注意:本文只是将上文多路复用器Select.Poll.Epoll区别梳理中提出的概念与Netty中的步骤联系起来,方便后面回顾,代码中注释很多,对于大家来说如果不是怀有同样的目的,不一定有用. 单线程 ...

  2. call by value reference name python既不是按值传递也不是按引用传递 python复制原理 创建新对象 与 改变原对象

    按名调用 Algol 按值调用 Java https://docs.python.org/3.6/faq/programming.html#how-do-i-write-a-function-with ...

  3. Python学习【第8篇】:python中的函数

    1.python中函数定义方法 def test(x): "This istest" y = x*2+1 return y vaule = test(2)print(vaule)运 ...

  4. SpringBoot配置文件 application.properties,yaml配置

    SpringBoot配置文件 application.properties,yaml配置 1.Spring Boot 的配置文件 application.properties 1.1 位置问题 1.2 ...

  5. Mysql 5.5升级5.8

    前言,因为升级跳板机,需要将mariadb 升级到10.2,也就是对应MySQL的5.8,废话不多说下面开始进行mariadb 5.5 的升级 Welcome to the MariaDB monit ...

  6. jquery的ajax提交时加载处理方法

    1.定义全局的,就是所有的ajax的请求的加载都会出现相同的提示 $(function(){ //加载成功显示的状态 $("#showLoading").ajaxSuccess(f ...

  7. Go语言学习-main和init

    main 函数和 init 函数Go里面有两个保留的函数: init 函数(能够应用于所有的 package )和 main 函数(只能应用于 package main ).这两个函数在定义时不能有任 ...

  8. 枚举--让盗版美国总统wcc给你整明白哈哈

    1.为什么要有枚举 Java中的枚举其实是一种语法糖,在 JDK 1.5之后出现,用来表示固定且有限个的对象.比如一个季节类有春.夏.秋.冬四个对象:一个星期有星期一到星期日七个对象.这些明显都是固定 ...

  9. Maven三种打包方式jar war pom

    1.pom工程 用在父级工程或聚合工程中.用来做jar包的版本控制.必须指明这个聚合工程的打包方式为pom 2.war工程 将会打包成war,发布在服务器上的工程.如网站或服务.在SpringBoot ...

  10. C - C(换钱问题)

    换钱问题: 给出n种钱,m个站点,现在有第 s种钱,身上有v 这么多: 下面 m行 站点有a,b两种钱,rab a->b的汇率,cab a-->b的手续费, 相反rba cba :  问在 ...