Skip to content

Commit

Permalink
update v1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
unadlib committed Sep 28, 2017
1 parent 5cf094f commit 707d1fb
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 87 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ be.Negative(-1); // true

#### Default built-in type check:

| Interface | Spec |
| :------------ | --------------:|
| Function | plain function |
| Object | plain object |
| String | basic string |
| Number | basic number |
| Boolean | basic boolean |
| NaN | strict equality to `NaN`|
| Nil | `null` or `null` |
| Empty | none length |
| Infinity | strict equality to `Infinity`|
| Interface | Spec |
| :------------ | -----------------------------------------:|
| Function | plain function |
| Object | plain object |
| String | basic string |
| Number | basic number |
| Boolean | basic boolean |
| NaN | strict equality to `NaN` |
| Nil | `null` or `undefined` |
| Empty | none length |
| Infinity | strict equality to `Infinity` |
| Finite | basic number and not `NaN` or `Infinity` |
| Native | pristine native function |
| SafeInteger | based on Number.isSafeInteger |
| Integer | based on Number.isInteger |
| Element | HTML Element |
| Native | pristine native function |
| SafeInteger | based on Number.isSafeInteger |
| Integer | based on Number.isInteger |
| Element | HTML Element |
2 changes: 2 additions & 0 deletions __tests___/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,5 @@ test(`be 1001 type isn't Test`, () => {
1001
)).toEqual(false)
})


31 changes: 19 additions & 12 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 71 additions & 0 deletions lib/defaultCheckType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import be from './index'

const FUNCTION = 'function'
const OBJECT = 'object'
const STRING = 'string'
const NUMBER = 'number'
const BOOLEAN = 'boolean'
const ELEMENT_NODE_TYPE = 1
const reRegExpChar = /[\\^$.*+?()[\]{}|]/g
const reRegExpCharFn = /hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g

class CheckType {
Function(value){
return typeof value === FUNCTION
}
Object(value){
return typeof value === OBJECT
}
String(value){
return be.string(value) && typeof value === STRING
}
Number(value){
return be.number(value) && typeof value === NUMBER
}
Boolean(value){
return be.boolean(value) && typeof value === BOOLEAN
}
NaN(value) {
return be.number(value) && isNaN(value)
}
Nil(value) {
return be.undefined(value) || be.null(value)
}
Empty(value){
return (
(typeof value === OBJECT && !be.null(value) && Object.keys(value).length === 0) ||
be.Boolean(value) ||
be.Function(value) ||
be.Nil(value) ||
value === '' ||
value === 0
)
}
Infinity(value){
return Infinity === value
}
Finite(value){
return be.Number(value) && !be.Infinity(value) && !be.NaN(value)
}
Native(value){
const reIsNative = new RegExp(`^${
Function.prototype.toString.call(Object.prototype.hasOwnProperty)
.replace(reRegExpChar, '\\$&')
.replace(reRegExpCharFn, '$1.*?')
}$`)
return be.Function(value) && reIsNative.test(value)
}
SafeInteger(value){
return Number.isInteger(value) && value <= Number.MAX_SAFE_INTEGER && value >= Number.MIN_SAFE_INTEGER
}
Integer(value){
return Number.isInteger(value)
}
Element(value){
return be.Object(value) && !be.object(value) && value.nodeType === ELEMENT_NODE_TYPE
}
}

export {
CheckType as default
}

0 comments on commit 707d1fb

Please sign in to comment.