ko-typed
ko-typed provides observable extensions for restricting and converting observable values based on type. Supports validation.
Installation
Node
npm install ko-typed
Web
bower install ko-typed
Usage
node
var ko = ; var typed = kovar convert = typed
web (global)
web (amd)
require;;
API
extenders
ko extenders are used to wrap a given observable and provide a typed interface.
extenders-type
Create a computed observable which only accepts a specified list of types. Does not perform conversions.
Supports:
- Generic types
- Custom types
- Overrides
Example
var base = ko;var typed = base; ; // good. undefined is of a supported type.; // good. undefined is of a supported type.; // good. 'string' is of a supported type. ; ; // bad. 10 is not of a supported type.; // bad. 10 is not of a supported type.
See examples/type for more examples. See test/coverage/type for detailed tests.
extenders-convert
Create a computed observable which converts to and from internal and external types.
Supports:
- Type restriction
- Custom conversions
- Default conversions
- Overrides
Example
var base = ko;var typed = base;var converted = typed; ;assert;;assert;;assert; ;assert;;assert;;assert;
See examples/convert for more examples. See test/coverage/convert for detailed tests.
converters
Converters between all common types are provided where conversion is common and unambiguous.