Class: FormatterManager

FormatterManager


new FormatterManager()

constructor
Source:
Example
class SampleFormatter {
  static pack(payload) {
    const boundary = 'Boundary-' + Date.now();
    const args = JSON.stringify(payload.args);

    const body = new FormData();
    body.append('arguments', args);

    return {
      method: 'POST',
      body,
      mode: 'cors',
      credentails: 'include'
    };
  }

  static unpack(response) {
    return response.json();
  }
}

export default SampleFormatter;

Methods


addFormatter(format, formatter)

Add formatter to the formatters object
Parameters:
Name Type Description
format String name of the format
formatter Object formatter object
Source:
Throws:
  • Will throw an error when the provided pormatter doesn't implement pack() and unpack()
    Type
    TypeError
  • Will throw an error when attempting to replace an existing formatter
    Type
    Error

getFormatter(format)

Get formatter based on format name
Parameters:
Name Type Description
format String name of the format
Source:
Returns:
Type
Object