mof-json

A middleware wrapper of JSON parsing for floodesh

Usage no npm install needed!

<script type="module">
  import mofJson from 'https://cdn.skypack.dev/mof-json';
</script>

README

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