Package Exports
- isbox
- isbox/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (isbox) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Function Inside
"is"
"isWindow"
"isNumber"
"isDef"
"isUnDef"
"isObject"
"isEmpty"
"isDate"
"isNull"
"isNullAndUnDef"
"isNullOrUnDef"
"isPromise"
"isString"
"isFunction"
"isBoolean"
"isRegExp"
"isArray"
"isWindow"
"isElement"
"isServer"
"isClient"
"isUrl"Usage
- Please use
npm/yarninstall this package
npm i ibox --save
# or
yarn i ibox --saveimportorrequirewhat you need
// in node.js
const isbox = require('isbox')
isbox.isWindow(window)
// false
isbox.isWindow(null)
// false
isbox.isWindow('')
// false
// in frontend
import { isWindow } from 'isbox'
isWindow(window)
// true
isWindow(null)
// false
isWindow('')
// false"is"
- Example 1: Base on
call()ing constructor - 方法一: 基本数据类型判断,基于构造类名判断
import { is } from 'isbox'
is(123, 'Number')
// true
is(null, 'Null')
// true
is(null, 'Object')
// false
is([], 'Array')
// true
is([], 'Object')
// false
is('', 'String')
// true
is(new Set(), 'Set')
// true- Example 2: Using
constructordirectly. - 方法二: 通过判断
constructor
const arr = [1,2,3]
console.log(arr.constructor === Array)
// true
console.log(new Set().constructor === Set)
// true"isServer"
- 判断当前环境是不是服务端
- Check if this is server side.
- type:
Boolean - value:
trueorfalse
// 在Nodeh环境执行
// execute in Node env
console.log(isbox.isServer)
// true
// 在浏览器环境执行
// execute in Broswer env
console.log(isbox.isServer)
// false
"isClient"
- 判断当前环境是不是客户端,与isServer互相对立
- If current env is Client, is the
oppositeofisServer - type:
Boolean - value:
trueorfalse
// 在Nodeh环境执行
// execute in Node env
console.log(isbox.isClient)
// false
// 在浏览器环境执行
// execute in Broswer env
console.log(isbox.isClient)
// true
"isNumber"
// in node.js
const isbox = require('isbox')
isbox.isNumber(NaN)
// true
isbox.isNumber(123)
// true
isbox.isNumber(null)
// false
isbox.isNumber('')
// false
import { isNumber } from 'isbox'
isNumber(123)
// true
isNumber(null)
// false
isNumber('')
// false"isObject"
import { isObject } from 'isbox'
isObject(123)
// false
isObject(null)
// true
isObject({a: 234})
// true
isObject('')
// false"isEmpty"
import { isEmpty } from 'isbox'
isEmpty(123)
// false
isEmpty({})
// true
isEmpty([])
// true
isEmpty('')
// true