1.0.0 • Published 4 years ago

superagent-jsonparse v1.0.0

Weekly downloads
35
License
MIT
Repository
-
Last release
4 years ago

superagent-jsonparse

Provide a streaming parser for superagent based on jsonparse.

Installation

npm install superagent-jsonparse
yarn add superagent-jsonparse

Usage

const request = require('superagent');
const jsonParser = require('superagent-jsonparse');
const Decimal = require('decimal.js-light');

{body} = await request
    .get('https://example.com/data.json')
    .accept('json')
    .use(jsonParser( (text) => new Decimal(text) ))
// body contains arbitrary-precision Decimal for all JSON numbers

Description

This package is a superagent plugin which replaces the default JSON parser (JSON.parse) with a streaming parser.

Optionally, you may provide a reviver for parsed numbers, which allows to implement arbitray-precision (big-number, big-decimal) parsing of JSON numbers. The default reviver for numbers is (text) => new Number(text), which provides functionality similar to JSON.parse.

1.0.0

4 years ago