企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] # 插件 -is 类型侦测器 ## 使用 ```javascript v.is.number(10) //true v.is.array([])// true ``` ## 这一段看源码吧 ```javascript let is = (function() { return { plain:function(obj){ return is.object(obj) && !is.window(obj) && Object.getPrototypeOf(obj) === Object.prototype }, window:(obj) => obj !== null && obj === obj.window, array: (a) => Array.isArray(a), object: function(a) { return Object.prototype.toString.call(a).indexOf('Object') > -1 }, html: function(a) { return (a instanceof NodeList || a instanceof HTMLCollection) }, node: function(a) { return a.nodeType }, svg: function(a) { return a instanceof SVGElement }, number: function(a) { return !isNaN(parseInt(a)) }, string: function(a) { return typeof a === 'string' }, func: function(a) { return typeof a === 'function' }, undef: function(a) { return typeof a === 'undefined' }, null: function(a) { return a === null }, hex: function(a) { return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(a) }, rgb: function(a) { return /^rgb/.test(a) }, rgba: function(a) { return /^rgba/.test(a) }, hsl: function(a) { return /^hsl/.test(a) }, color: function(a) { return (is.hex(a) || is.rgb(a) || is.rgba(a) || is.hsl(a)) } } })(); ```