flux-standard-action-json

    1.1.0 • Public • Published

    Flux Standard Action JSON serialization

    build status npm version

    Flux Standard Action JSON serialization utilities.

    npm install --save flux-standard-action-json
    

    Usage

    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

    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

    Install

    npm i flux-standard-action-json

    DownloadsWeekly Downloads

    3

    Version

    1.1.0

    License

    MIT

    Last publish

    Collaborators

    • avatar