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

mbuilder

v0.0.2

Published

Markup and HTML builder tools

Downloads

2

Readme

Pull requests Build status Dep tracker Codebase license

Markup Builder

Markdown and HTML markup building tools. Built on XSS, Remarkable, DOMParser and Markup tools.

Installation

Node.js

npm install mbuilder --save

Use as:

const mbuilder = require('mbuilder');

Browser

<script src="https://unpkg.com/mbuilder/dist/mbuilder.min.js"></script>

Usage

Text tools

mbuilder.build comes with 5 functions:

const t = "**Lorem ipsum dolor sit amet**, consectetuer adipiscing elit. Aenean <i>commodo ligula eget</i> dolor. Aenean massa. Cum @sociis natoque #penatibus et magnis dis parturient montes,<script>alert('Quisque rutrum.')</script> nascetur ridiculus mus. Donec quam felis, https://www.youtube.com/watch?v=sO_YEdTcVXc https://travis-ci.org/markupjs/mbuilder";
//options object the configurations for the 'xss' module
//Find out more: https://www.npmjs.com/package/xss#custom-filter-rules
const 
// only tag a and its attributes href, title, target are allowed
var options = {
  whiteList: {
    a: ["href", "title", "target"]
  }
};
// With the configuration specified above, the following HTML:
// <a href="#" onclick="hello()"><i>Hello</i></a>
// would become:
// <a href="#">Hello</a>

mbuilder.build.text(text, options);

Returns the text version of a markdown or HTML string input;

options is optional configurations object for xss.

var text = mbuilder.build.text(t, options);
console.log(text);

// " Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum @sociis natoque #penatibus et magnis dis parturient montes,&lt;script&gt;alert(\'Quisque rutrum.\')&lt;/script&gt; nascetur ridiculus mus. Donec quam felis, https://www.youtube.com/watch?v=sO_YEdTcVXc https://travis-ci.org/markupjs/mbuilder\n "

mbuilder.build.html(text, options);

Returns the html version of a markdown or HTML string input;

options is optional configurations object for xss.

//inside async function
var html = await mbuilder.build.html(t, options);
console.log(html);

//With promise API
mbuilder.build.html(t).then(function(html, options){
    console.log(html);
});

// "<p><strong>Lorem ipsum dolor sit amet</strong>, consectetuer adipiscing elit. Aenean <i>commodo ligula eget</i> dolor. Aenean massa. Cum @sociis natoque #penatibus et magnis dis parturient montes,&lt;script&gt;alert(\'Quisque rutrum.\')&lt;/script&gt; nascetur ridiculus mus. Donec quam felis, https://www.youtube.com/watch?v=sO_YEdTcVXc https://travis-ci.org/markupjs/mbuilder</p>\n"

mbuilder.build.summary(text, count, options);

Returns the text version of a markdown or HTML string input, trimmed to count or a default of 160 characters;

//inside async function
var summary = await mbuilder.build.summary(t/* , options */);
console.log(summary);

//With promise API
mbuilder.build.summary(t).then(function(summary/* , options */){
    console.log(summary);
});

// "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum @sociis natoque #penatibus et magnis dis parturien..."

mbuilder.build.content(text, config, options);

Returns the full html version of a markdown or HTML string input; parsing hashtag, mentions, naked image links and naked youtube link.

var config = {};
config.video = true; //default: true
config.account_scheme = '/@'; //default is: '/user'
config.hashtag_scheme = '/trends'; //default: '/trending'

//'options' object is xss configurations

Example:

//inside async function
var content = await mbuilder.build.content(t /*,config, options*/ );   //with about options object
console.log(content);

//With promise API
mbuilder.build.content(t /*,config, options*/).then(function(content){   //options is optional, using defaults
    console.log(content);
});

// "<p><strong>Lorem ipsum dolor sit amet</strong>, consectetuer adipiscing elit. Aenean <i>commodo ligula eget</i> dolor. Aenean massa. Cum <a target="_blank" href="/user/sociis">@sociis</a> natoque <a target="_blank" href="/trending/penatibus"> #penatibus </a> et magnis dis parturient montes,&lt;script&gt;alert(\'Quisque rutrum.\')&lt;/script&gt; nascetur ridiculus mus. Donec quam felis, <a href="https://www.youtube.com/watch?v=sO_YEdTcVXc">https://www.youtube.com/watch?v=sO_YEdTcVXc</a> <a href="https://travis-ci.org/markupjs/mbuilder">https://travis-ci.org/markupjs/mbuilder</a></p>\n';

mbuilder.build.sanitize(text, options);

Returns the sanitized version of the input string;

options is optional configurations object for xss and can be either true || false. Default is true

//inside async function
var clean = await mbuilder.build.sanitize(t/* , options */);
console.log(clean);

//With promise API
mbuilder.build.sanitize(t/* , options */).then(function(clean){
    console.log(clean);
});

// "**Lorem ipsum dolor sit amet**, consectetuer adipiscing elit. Aenean <i>commodo ligula eget</i> dolor. Aenean massa. Cum @sociis natoque #penatibus et magnis dis parturient montes,&lt;script&gt;alert(\'Quisque rutrum.\')&lt;/script&gt; nascetur ridiculus mus. Donec quam felis, https://www.youtube.com/watch?v=sO_YEdTcVXc https://travis-ci.org/markupjs/mbuilder"

Dependencies

Accessing dependencies:

const remarkable = mbuilder.dep.Remarkable;
const xss = mbuilder.dep.xss;
const domparser = mbuilder.dep.DomParser;
const mtools = mbuilder.dep.mtools

Contributions

Are welcome.