-
Notifications
You must be signed in to change notification settings - Fork 24
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
1 changed file
with
11 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,6 +108,15 @@ var otherTypes = { | |
} | ||
}, | ||
|
||
quacksLike (type) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
dcousens
Author
Owner
|
||
function quacksLike (value, strict) { | ||
return type === getValueTypeName(value) | ||
} | ||
quacksLike.toJSON = () => type | ||
|
||
return quacksLike | ||
}, | ||
|
||
value (expected) { | ||
return function value (actual) { | ||
return actual === expected | ||
|
@@ -123,7 +132,7 @@ function compile (type) { | |
return otherTypes.maybe(compile(type)) | ||
} | ||
|
||
return nativeTypes[type] || type | ||
return nativeTypes[type] || otherTypes.quacksLike(type) | ||
|
||
} else if (nativeTypes.Object(type)) { | ||
if (nativeTypes.Array(type)) { | ||
|
@@ -150,11 +159,7 @@ function typeforce (type, value, strict) { | |
} | ||
|
||
// JIT | ||
type = compile(type) | ||
if (!nativeTypes.String(type)) return typeforce(type, value, strict) | ||
if (type === getValueTypeName(value)) return true | ||
|
||
throw new TypeError(tfErrorString(type, value)) | ||
return typeforce(compile(type), value, strict) | ||
} | ||
|
||
// assign all types to typeforce function | ||
|
I was expecting this to iterate the own property of the expected type and check that the value has the same set of properties.