npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

Iโ€™ve always been into building performant and accessible sites, but lately Iโ€™ve been taking it extremely seriously. So much so that Iโ€™ve been building a tool to help me optimize and monitor the sites that I build to make sure that Iโ€™m making an attempt to offer the best experience to those who visit them. If youโ€™re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, ๐Ÿ‘‹, Iโ€™m Ryan Hefnerย  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If youโ€™re interested in other things Iโ€™m working on, follow me on Twitter or check out the open source projects Iโ€™ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soonโ€“ish.

Open Software & Tools

This site wouldnโ€™t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you ๐Ÿ™

ยฉ 2024 โ€“ย Pkg Stats / Ryan Hefner

@macchiatojs/body

v0.7.0

Published

A full-featured macchiatojs body parser (with raw Node.js support) ๐ŸŽณ.

Downloads

12

Readme

@macchiatojs/body

A full-featured @macchiatojs body parser middleware. Supports multipart, urlencoded, and json request bodies. Provides the same functionality as Express's bodyParser - multer.

Features

  • ๐Ÿฆ„ Based on top of [co-body] and [formidable].
  • ๐Ÿš€ Isomorphic to the moon.
  • ๐Ÿ”ฅ Blaze and lightweight parser.
  • ๐Ÿ“Œ Support for form.
  • ๐ŸŽฏ Support for json.
  • ๐Ÿฅž Support for multipart.
  • ๐Ÿช Support for file upload.
  • ๐Ÿ“‹ Support for text (raw text, html, xml).
  • โœจ Asynchronous support (async/await).
  • ๐Ÿข Raw Node.js (http) support.
  • ๐ŸŽ‰ TypeScript support.

Installation

# npm
$ npm install @macchiatojs/body
# yarn
$ yarn add @macchiatojs/body

When use this module with raw Node.js should insall an additional module type-is.

Usage

with Macchiato.js

import Macchiato from "@macchiatojs/kernel";
import requestBody from "@macchiatojs/body";

const app = new Macchiato();

app.use(requestBody(bodyOpts));
app.use((request: Request, response: Response) => {
  response.body = request["body"];
});

app.start(1111);

with raw Node.js

import http from "http";
import requestBody from "@macchiatojs/body";

const server = http.createServer(async (request, response) => {
  try {
    await requestBody()(request);
    response.statusCode = 200;
    response.write(request?.body);
    response.end();
    return;
  } catch (error) {
    response.statusCode = 500;
    response.end("some thing long ...");
    return;
  }
});

server.listen(1111);

Note

If you want to use [email protected] you should replace you're import from

import requestBody from "@macchiatojs/body"

to

import requestBody from "@macchiatojs/body/v1"

When we release the 1.0.0 we will drop support for [email protected].

Options

Options available for @macchiatojs/body. Four custom options, and others are from raw-body and formidable.

  • expressify {Boolean} Only with Macchiato.js; Choose the right middleware style (false ==> koaify / true ==> expressify), default true
  • jsonLimit {String|Integer} The byte (if integer) limit of the JSON body, default 1mb
  • formLimit {String|Integer} The byte (if integer) limit of the form body, default 56kb
  • textLimit {String|Integer} The byte (if integer) limit of the text body, default 56kb
  • encoding {String} Sets encoding for incoming form fields, default utf-8
  • multipart {Boolean} Parse multipart bodies, default false
  • urlencoded {Boolean} Parse urlencoded bodies, default true
  • text {Boolean} Parse text bodies, such as XML, default true
  • json {Boolean} Parse JSON bodies, default true
  • jsonStrict {Boolean} Toggles co-body strict mode; if set to true - only parses arrays or objects, default true
  • formidable {Object} Options to pass to the formidable multipart parser
  • parsedMethods {String[]} Declares the HTTP methods where bodies will be parsed, default ['POST', 'PUT', 'PATCH'].

A note about parsedMethods

see http://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-19#section-6.3

  • GET, HEAD, and DELETE requests have no defined semantics for the request body, but this doesn't mean they may not be valid in certain use cases.
  • @macchiatojs/body is strict by default, parsing only POST, PUT, and PATCH requests.

Some options for formidable

See node-formidable for a full list of options

  • maxFields {Integer} Limits the number of fields that the querystring parser will decode, default 1000
  • maxFieldsSize {Integer} Limits the amount of memory all fields together (except files) can allocate in bytes. If this value is exceeded, an 'error' event is emitted, default 2mb (2 * 1024 * 1024)
  • uploadDir {String} Sets the directory for placing file uploads in, default os.tmpDir()
  • keepExtensions {Boolean} Files written to uploadDir will include the extensions of the original files, default false
  • hashAlgorithm (hash with [email protected]) {String} If you want checksums calculated for incoming files, set this to either 'sha1' or 'md5', default false
  • multiples {Boolean} Multiple file uploads or no, default true
  • onFileBegin {Function} Special callback on file begin. The function is executed directly by formidable. It can be used to rename files before saving them to disk. See the docs

Support

If you have any problem or suggestion please open an issue.

License


MIT ยฉ Imed Jaberi