type-diff
Simple, readable, structural type comparisons.
Quick Example
const Type = id: Number tags: String contacts: id: Number name: String contacted: tags: wharrgarbl: const value = id: 1 tags: 'good' 'cool' contacts: id: 2 name: 'John Doe' contacted: null 'wheee' id: '3' name: 'Jane Doe' contacted: tags: 'cool' assert
Usage
diff(Type, value)
Generate an object literal representation of the difference between your Type
and a given value
as shown above in the Quick Example.
Supported Built-ins
Number
String
Boolean
Object
Array
Date
Function
Helpers
Nullable(Type)
: Allows the corresponding value
to be either the correct Type
or null
.
Optional(Type)
: Allows the corresponding value
to be either the correct Type
or undefined
.
Any | Any()
: Requires that the corresponding value be anything but undefined
. Used in conjuction with Optional
if undefined
is allowed; as in Optional(Any)