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

regevbr-textversionjs

v1.0.3

Published

A tool for generating the text version of an html email.

Downloads

3

Readme

textversionjs

Generate the text version of your HTML email in a second.

This tool is an open source project. Feel free to use it any time in your projects!

htmlToPlainText

The function that generates plain text from email htmls.

Params

Param | Type | Required | Default value | Description --- |--- |--- |--- |--- htmlText | string | Yes | | The html version of the email styleConfig | json | No | | Options for converting

styleConfig

Param | Type | Required | Default value | Description --- |--- |--- |--- |--- linkProcess | function | No | | Callback function to customize links appearance imgProcess | function | No | | Callback function to customize image appearance headingStyle | string | No | "underline" | Define heading appearance, options: "underline", "linebreak", "hashify" listStyle | string | No | "indention" | Define list appearance, options: "indention", "linebreak" uIndentionChar | string | No | "-" | If listStyle is indention, uIndentionChar is the character that fills the indention for unordered lists oIndentionChar | string | No | "-" | If listStyle is indention, oIndentionChar is the character that fills the indention for ordered lists after the heading number listIndentionTabs | int | No | 3 | If listStyle is indention, listIndentionTabs is the width of the indention keepNbsps | boolean | No | false | Define the behaviour of the non-braking spaces. If set to true, nbsps are not collapsed to single space.

linkProcess

Param | Type | Required | Default value | Description --- |--- |--- |--- |--- href | string | Yes | | The destination (href property) of the link linkText | string | Yes | | The text of the link

imgProcess

Param | Type | Required | Default value | Description --- |--- |--- |--- |--- src | string | Yes | | The source (src property) of the image alt | string | Yes | | The alternative text (alt property) of the image

Examples

Simple conversion with default style

var textVersion = require("textversionjs");
var htmlText = "<html>" +
					"<body>" +
						"Lorem ipsum <a href=\"http://foo.foo\">dolor</a> sic <strong>amet</strong><br />" +
						"Lorem ipsum <img src=\"http://foo.jpg\" alt=\"foo\" /> sic <pre>amet</pre>" +
						"<p>Lorem ipsum dolor <br /> sic amet</p>" +
						"<script>" +
							"alert(\"nothing\");" +
						"</script>" +
					"</body>" +
				"</html>";

var plainText = textVersion(htmlText);
// returns
// "Lorem ipsum [dolor] (http://foo.foo) sic amet
// Lorem ipsum ![foo] (http://foo.jpg) sic amet
// Lorem ipsum dolor
// sic amet"

Customize link appearance

var textVersion = require("textversionjs");
var htmlText = "<p>Lorem <a href=\"http://foo.foo\">ipsum</a> dolor sic amet</p>";

var styleConfig: {
	linkStyle: function(href, linkText){
		return linkText + " " + "(" + href + ")";
	}
};

var plainText = textVersion(htmlText, styleConfig);
// returns "Lorem ipsum (http://foo.foo) dolor sic amet"

Customize headings

var textVersion = require("textversionjs");

var htmlText = "<h1>Lorem ipsum</h1>" +
				"<p>Lorem ipsum dolor sic amet</p>";

var styleConfig: {
	headingStyle: "hashify"
};

var plainText = textVersion(htmlText, styleConfig);
// returns
// "# Lorem ipsum
//
// Lorem ipsum dolor sic amet"

Customize lists

var textVersion = require("textversionjs");
var htmlText = "<ul>" +
					"<li>Lorem</li>" +
					"<li>ipsum</li>" +
				"</ul>" +
				"<ol>" +
					"<li start=\"3\">Lorem</li>" +
					"<li>ipsum</li>" +
				"</ol>";

var styleConfig: {
	headingStyle: "indention",
	uIndentionChar: ".";
	listIndentionTabs: 2;
};

var plainText = textVersion(htmlText, styleConfig);
// returns "
// ..Lorem
// ..ipsum
// 3.Lorem
// 4.ipsum"

Try it online in our Demo page!

Don't forget to check out our other open source projects at EDMdesigner.

Follow us on github and twitter!