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

mime_message_composer

v1.0.2

Published

multipare encoded content composer

Downloads

325

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.

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)
    Those content type which have its boundary defined and have multiple child content types.
    Example of BranchableCT are: multipart/alternative, multipart/mixed, and others
  • BodyCT (Body Content Type)
    Those content type which do not have additional with in itself.
    Example of BodyCT are: text/plain, application/json, and others

Docs

BranchableCT

  • Constructor:
BranchableCT(ContentType:String, Boundary:String) - E.g: BranchableCT("multipart/alternative","alt_part1")
  • Methods:
appendHeaders(headers: HeaderType[]):this - E.g appendHeaders([{name:"Content-Transfer-Encoding",value:"base64"}])

- HeaderType is a Object that has name and value property.
- Used to add headers to the content type.
addBranches(branches: ContentTypeI[]):this - E.g: addBranches([new BranchableCT(..), new BodyCT(..)])

- Add subBranch of this content type
- ContentTypeI interface is implemented by both Branchable and Body Interface.
compile():string - E.g: compile()

- Generate the compiled Mime message of this content type by combining with headers and branches.

BodyCT

  • Constructor:
BodyCT(ContentType:String, additionalCT: HeaderType) - E.g BodyCT("application/json",{name:"name",value:"package.json"})
  • Methods:
appendHeaders(headers: HeaderType[]):this - E.g appendHeaders([{name:"Content-Transfer-Encoding",value:"base64"}])

- HeaderType is a Object that has name and value property.
- Used to add headers to the content type.
getBody():string - eg getBody()

- Get Body data added to this content type class
setBody(data: string):this - E.g: setBody("any data depending on headers")

- Add body data to the content type.
compile():string - E.g: compile()

- Generate the compiled Mime message of this content type by combining with headers and branches.

Usage

const textPlain = new BodyCT({
  contentType: "text/plain",
  additionalCT: {
    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",
  additionalCT: {
    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