Skip to content

tiaanduplessis/micro-parsers

Repository files navigation

micro-parsers

Body parsers extracted from Micro



Built with ❤︎ by tiaanduplessis and contributors

Table of Contents

Table of Contents
  • About
  • Install
  • Usage
  • Contribute
  • License
  • About

    The buffer, text and json body parsers extracted from Micro.

    Install

    $ npm install micro-parsers
    # OR
    $ yarn add micro-parsers

    Usage

    Example extracted from from Micro README. See it for more usage examples.

    const {buffer, text, json} = require('micro-parsers')
    
    module.exports = async (req, res) => {
      const buf = await buffer(req)
      console.log(buf)
      // <Buffer 7b 22 70 72 69 63 65 22 3a 20 39 2e 39 39 7d>
      const txt = await text(req)
      // '{"price": 9.99}'
      const js = await json(req)
      // { price: 9.99 }
      console.log(js.price)
      return ''
    }

    Contributing

    Contributions are welcome!

    1. Fork it.
    2. Create your feature branch: git checkout -b my-new-feature
    3. Commit your changes: git commit -am 'Add some feature'
    4. Push to the branch: git push origin my-new-feature
    5. Submit a pull request :D

    Or open up a issue.

    License

    Licensed under the MIT License.