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 🙏

© 2025 – Pkg Stats / Ryan Hefner

mime_message_composer

v2.0.0

Published

multipart message composer for nodejs and browser

Readme

Mime Message Composer

Mime / Multipart message composer is a package that helps to encode the request body in a multipart message format. This composer helps to create the multipart encoded body like multipart/alternative.

Install using NPM

npm i mime_message_composer

Info

This package works on a concept of content type. Every mutipart message hava a content type that describe what content it holds. This package exposes two classes:

  • BranchableCT (Branchable Content Type)

    BranchableCT are those content type which have its boundary defined and will have multiple child content types within itself. Example of BranchableCT are: multipart/alternative, multipart/mixed, and others

  • BodyCT (Body Content Type)

    BodyCT are those content type which contains body/value in as its body with required headers and cannot have additional content types in its body. Example of BodyCT are: text/plain, application/json, and others


Docs

Classes

BranchableCT

Represents a multipart content type (e.g., multipart/alternative, multipart/mixed) that can contain multiple child content types.

Constructor:

new BranchableCT({
  contentType: string, // e.g., "multipart/alternative"
  boundary: string, // required boundary string
  inlineHeader: HeaderType, // optional inline header
});

Methods:

  • appendHeaders(headers: HeaderType[]): this Appends additional headers to the content type.

  • addBranches(branches: ContentTypeI[]): this Adds child content types (branches) to this multipart content.

  • compile(): string Compiles the content type, headers, and branches into a MIME-formatted string.


BodyCT

Represents a leaf/sub content type (e.g., text/plain, application/json) that contains only a body and headers.

Constructor:

new BodyCT({
  contentType: string, // e.g., "text/plain"
  inlineHeader: HeaderType, // optional inline header
});

Methods:

  • appendHeaders(headers: HeaderType[]): this Appends additional headers to the content type.

  • setBody(body: string): this Sets the body content for this content type.

  • getBody(): string Returns the body content.

  • compile(): string Compiles the content type, headers, and body into a MIME-formatted string.


HeaderType

type HeaderType = {
  name: string;
  value: string;
};

ContentTypeHeader

type ContentTypeHeader = {
  contentType: string;
  boundary?: string;
  inlineHeader?: HeaderType;
};

Example Usage

const textPlain = new BodyCT({
  contentType: "text/plain",
  inlineHeader: {
    name: "charset",
    value: "UTF-8",
  },
})
  .appendHeaders([
    {
      name: "Content-Transfer-Encoding",
      value: "7bit",
    },
  ])
  .setBody("this is plain text body");

const textHtml = new BodyCT({
  contentType: "text/html",
  inlineHeader: {
    name: "charset",
    value: "UTF-8",
  },
})
  .appendHeaders([
    {
      name: "Content-Transfer-Encoding",
      value: "7bit",
    },
  ])
  .setBody("<b>this is plain text body</b>");

const alternative = new BranchableCT({
  contentType: "multipart/alternative",
  boundary: "foo-bar",
})
  .appendHeaders([
    {
      name: "Encoding",
      value: "7bit",
    },
  ])
  .addBranches([textPlain, textHtml]);

console.log(alternative.compile());

Output:

Content-Type: multipart/alternative; boundary="foo-bar"
Encoding: 7bit

--foo-bar
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit

this is plain text body
--foo-bar
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: 7bit

<b>this is plain text body</b>
--foo-bar--

Links