-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
110 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,3 +140,5 @@ test(`be 1001 type isn't Test`, () => { | |
1001 | ||
)).toEqual(false) | ||
}) | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.