mof-json

1.0.3 • Public • Published

mof-json

mof-json is a middleware of floodesh, it automatically parses response to JSON as long as one of below conditions is met:

  1. Content-Type is kind of 'json'
  2. Current url matches the provided RegExp p

Install

npm install mof-json

Usage

const json = require('mof-json');
const request = require('mof-request');
const Worker = require("floodesh/worker");

const worker = new Worker();

worker.use(co.wrap(request(worker.config.downloader))); // make sure the ctx existing before using json

// default parse only Content-Type is json
worker.use(json());

// parse when Content-Type is json or url matches pattern
const options = {p: /\/path\/to\/page/};
worker.use(json(options));

Test

npm test

Package Sidebar

Install

npm i mof-json

Weekly Downloads

4

Version

1.0.3

License

ISC

Unpacked Size

5.79 kB

Total Files

6

Last publish

Collaborators

  • mike442144