|
@@ -129,23 +129,16 @@ function assertProp (
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-/**
|
|
|
|
|
- * Assert the type of a value
|
|
|
|
|
- */
|
|
|
|
|
|
|
+const simpleCheckRE = /^(String|Number|Boolean|Function|Symbol)$/
|
|
|
|
|
+
|
|
|
function assertType (value: any, type: Function): {
|
|
function assertType (value: any, type: Function): {
|
|
|
- valid: boolean,
|
|
|
|
|
- expectedType: ?string
|
|
|
|
|
|
|
+ valid: boolean;
|
|
|
|
|
+ expectedType: string;
|
|
|
} {
|
|
} {
|
|
|
let valid
|
|
let valid
|
|
|
- let expectedType = getType(type)
|
|
|
|
|
- if (expectedType === 'String') {
|
|
|
|
|
- valid = typeof value === (expectedType = 'string')
|
|
|
|
|
- } else if (expectedType === 'Number') {
|
|
|
|
|
- valid = typeof value === (expectedType = 'number')
|
|
|
|
|
- } else if (expectedType === 'Boolean') {
|
|
|
|
|
- valid = typeof value === (expectedType = 'boolean')
|
|
|
|
|
- } else if (expectedType === 'Function') {
|
|
|
|
|
- valid = typeof value === (expectedType = 'function')
|
|
|
|
|
|
|
+ const expectedType = getType(type)
|
|
|
|
|
+ if (simpleCheckRE.test(expectedType)) {
|
|
|
|
|
+ valid = typeof value === expectedType.toLowerCase()
|
|
|
} else if (expectedType === 'Object') {
|
|
} else if (expectedType === 'Object') {
|
|
|
valid = isPlainObject(value)
|
|
valid = isPlainObject(value)
|
|
|
} else if (expectedType === 'Array') {
|
|
} else if (expectedType === 'Array') {
|
|
@@ -166,7 +159,7 @@ function assertType (value: any, type: Function): {
|
|
|
*/
|
|
*/
|
|
|
function getType (fn) {
|
|
function getType (fn) {
|
|
|
const match = fn && fn.toString().match(/^\s*function (\w+)/)
|
|
const match = fn && fn.toString().match(/^\s*function (\w+)/)
|
|
|
- return match && match[1]
|
|
|
|
|
|
|
+ return match ? match[1] : ''
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function isType (type, fn) {
|
|
function isType (type, fn) {
|