Flux Standard Action JSON serialization
Flux Standard Action JSON serialization utilities.
npm install --save flux-standard-action-json
Usage
;
stringify(action, ?options)
Returns a JSON string if action
is FSA compliant. Otherwise, throws an error.
NOTE: Symbol
action types should have a key. For example:
fsaJSON; // throws an error
fsaJSON; // returns '{"type":"Symbol(ACTION_TYPE)"}'
?options
error
: (Object) Error serialization options. Applies only ifpayload
is anError
object. We depend on Errio so the same options apply.
Example:
fsaJSON; // returns '{"type":"ACTION_TYPE","error":true,"payload":{"name":"Error","message":"Where?","stack":"<a full error stack>"}}'
parse(json, ?options)
Returns an FSA compliant action parsed from a JSON string,
parsing Symbol
type and Error
payload where applies.
Examples:
fsaJSON; // throws an error
fsaJSON; // returns {type: Symbol.for('ACTION_TYPE')}
fsaJSON; // returns {type: 'TYPE', error: true, payload: new Error('Invalid something')}
NOTE: Symbol
action types should have a key. For example:
fsaJSON; // throws an error
?options
error
: (Object) Error deserialization options. Applies only ifpayload
is anError
object. We depend on Errio so the same options apply.