1.0.2 • Published 6 years ago

mignon v1.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

Mignon

Rapid promise digestion.

Mignon allows you to synchronize batches of async calls into delectable "meals"


Install

npm install mignon

or

yarn add mignon

Example:

This example prepares a meal that digests it's promises to make an html file from a http request.

const mignon = require('mignon');
const fetch = require('node-fetch');
const marked = require('marked');
const fs = require('fs');

mignon(function *() {
  let data = 'https://jsonplaceholder.typicode.com/posts/1',
      res  = yield fetch(data),
      post = yield res.json(),
      h1   = marked(`# ${post.id}`),
      p    = marked(post.title),
      listItems = post.body.split('\n').map((elem) => { return elem = `* ${elem}`; }),
      ul = marked(listItems.join('\n')),
      html = `${h1}${p}${ul}`;
  console.log(`Your new html file:\n${html}`);
  fs.writeFile("index.html", html, (err) => { if (err) { return console.log(err); }; console.log("index.html was saved!"); });
});

or if you prefer to separate your generator:

function* letsMakeAWebpage(){
  let data = 'https://jsonplaceholder.typicode.com/posts/1',
      res  = yield fetch(data),
      post = yield res.json(),
      h1   = marked(`# ${post.id}`),
      p    = marked(post.title),
      listItems = post.body.split('\n').map((elem) => { return elem = `* ${elem}`; }),
      ul = marked(listItems.join('\n')),
      html = `${h1}${p}${ul}`;
  console.log(`Your new html file:\n${html}`);
  fs.writeFile("index.html", html, (err) => { if (err) { return console.log(err); }; console.log("index.html was saved!"); });
}

mignon(letsMakeAWebpage);

Have fun!

Future Goals

  • [] chain-able meals via promise, async/await, or callbacks.

Acknowledgments

I'd like to thank Michael Vann for being a helpful ear while I was developing this concept. Without his feedback this module wouldn't have been possible. I Look forward to us collaborating on the future of Mignon.