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

tempo-email-parser

v0.7.7

Published

Processes HTML email for display. Extracts quotations and more.

Downloads

486

Readme

tempo-email-parser

Parse and extract main message from an HTML email. Also runs several transformations to the email so that it can be displayed safely and correctly inside a browser or Electron iframe for example.

  • Extract quotations (replies), signatures
  • Remove scripts, trackers
  • Convert text links into anchor tags
  • Remove trailing whitespaces
  • Block remote content

Usage

import prepareMessage, {
	blockRemoteContent,
	linkify,
} from 'tempo-email-parser';

const emailHtml = `
<div>Hello there</div>
`;

const remoteContentReplacements = {
	image: 'replacement-image-url', // Remote image URLs replacement. Default to 1x100 transparent image
	other: '#', // Other URLs replacements
};

// All options default to false.
const OPTIONS = {
	noQuotations: true,
	autolink: true,
	forceViewport: '<meta name="viewport" content="width=device-width" />',
	noRemoteContent: true,
	remoteContentReplacements,
	includeStyle: `
		.custom-style {
			color: red;
		}
	`,
};

const {
	// The extracted message
	messageHtml,
	// The whole message processed, including quotations and signature
	completeHtml,
	// Did we removed quotes or signature
	didFindQuotation,
} = prepareMessage(emailHtml, OPTIONS);

Autolinking and remote-content blocking are available as separate functions as well.

const withLinks = linkify(messageHtml);

const noRemoteContent = blockRemoteContent(
	messageHtml,
	remoteContentReplacements
);

Development

For tests

yarn run test

The main function prepareMessage has a list of fixtures used for tests. The input HTML are files named xxx.input.html. The expected outputs are named xxx.output-complete.html and xxx.output-message.html.

yarn run generate:fixtures

This script generates the respective outputs files for any .input.html file found without corresponding outputs.

To easily add a fixture from a real-world email, you can put the input HTML at /src/tests/prepareMessage/my-test.input.html, and then run yarn run generate:fixtures to generate the output files based on what prepareMessage produced. You now only have to check that the outputs look good and make adjustments if necessary.

Benchmarks

There are benchmarks to ensure the tool remains fast to not alter UI performance, and also to compare some external libraries. See the benchmark folder.