Play State Utils
Get
Get data with path field, if it doesn't exist throw an error, or emit error on state (root) in case state is given
const get = var cmd = const data = foo: bar: 'Hell Yeah' console // Returns data objectconsole // returns {bar: 'Hell Yeah'}console // returns 'Hell Yeah' // throws Error: 'field: "foo.error" doesn\'t exist'
The field path can also contain fallback fields. These are seperated with ||
const get = var cmd = const data = foo: bar: 'Hell Yeah' console // returns 'Hell Yeah'
get.date
Get a date from data with path filed, if it doesn't exist or is not a date (all moment compatible inputs are valid).
const getDate = const data = foo: bar: 'Hell Yeah' date: console // Returns Date()console // throws Error: '"Hell Yeah" on field: "foo.bar" is not of type "date"'
get.number
Get a number like value from data with path field, if it doesn't exist or is not a number, throw an error, or emit error on state
const getNumber =
get.string
Get a string from data with path field, if it doesn't exist or is not a string, throw an error, or emit error on state
const getString = const data = foo: bar: 'Hell Yeah' number: 1 console // Returns 'Hell Yeah'console // throws Error: '"1" on field: "foo.number" is not of type "string"'
get.url
Get a url from data with path filed, if it doesn't exist or is not a url (including protocol: http
, https
or ws
).
const getDate = const data = foo: bar: 'Hell Yeah' url: 'http://www.vigour.io' console // Returns http://www.vigour.ioconsole // throws Error: '"Hell Yeah" on field: "foo.bar" is not of type "date"'
Source
Setup a Source to retrieve data
Request
Retrieve data from a API via http
or https
.
const Request = const httpRequest = hostname: 'www.http-server' urlPath: '/api' // use urlPath instead of path httpRequest