1.1.0 • Published 9 years ago
flux-standard-action-json v1.1.0
Flux Standard Action JSON serialization
Flux Standard Action JSON serialization utilities.
npm install --save flux-standard-action-jsonUsage
import fsaJSON from 'flux-standard-action-json';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.stringify({type: Symbol()});
// throws an error fsaJSON.stringify({type: Symbol('ACTION_TYPE')});
// returns '{"type":"Symbol(ACTION_TYPE)"}'?options
error: (Object) Error serialization options. Applies only ifpayloadis anErrorobject. We depend on Errio so the same options apply.
Example:
fsaJSON.stringify({
type: 'ACTION_TYPE',
error: true,
new Error('Where?'))
}, {error: {stack: true}});
// 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.parse('{}');
// throws an error fsaJSON.parse('{"type":"Symbol(ACTION_TYPE)"}');
// returns {type: Symbol.for('ACTION_TYPE')} fsaJSON.parse('{"type":"TYPE","error":true,"payload":"Invalid something"}');
// returns {type: 'TYPE', error: true, payload: new Error('Invalid something')}NOTE: Symbol action types should have a key. For example:
fsaJSON.parse('{"type":"Symbol()"}');
// throws an error?options
error: (Object) Error deserialization options. Applies only ifpayloadis anErrorobject. We depend on Errio so the same options apply.