Tools and libraries I would use in my JavaScript projects. This is kind of my personal “Awesome” list.
Markdown and HTML
1. Turndown
HTML to Markdown converter.
- Environment: Works in Node.js, Edge runtime, and browser.
- Lightweight: Turndown is just
4.33 kB
minified and gzipped. - Customizable: It has support for custom rules and plugins that allows to extend its functionality.
Installation:
npm install turndown
Basic usage:
// For Node.js
var TurndownService = require('turndown')
var turndownService = new TurndownService()
var markdown = turndownService.turndown('<h1>Hello world!</h1>')
//=> # Hello world!
2. Markdown-it
Markdown to HTML converter. Supports CommonMark and GitHub-Flavored Markdown.
Installation:
npm install markdown-it
Basic usage:
import markdownit from 'markdown-it'
const md = markdownit()
const result = md.render('# Hello world!');
console.log(result)
//=> <h1>Hello world!</h1>
3. Cheerio
The fast, flexible, and elegant library for parsing and manipulating HTML and XML. It can be large for some projects, but it is invaluable for web scraping and DOM manipulation in Node.js.
Installation:
npm install cheerio
Basic usage:
import * as cheerio from 'cheerio';
const $ = cheerio.load('<h2 class="title">Hello world</h2>');
$('h2.title').text('Hello there!');
$('h2').addClass('welcome');
$.html();
//=> <html><head></head><body><h2 class="title welcome">Hello there!</h2></body></html>
4. DOMPurify
DOMPurify is a fast, tolerant XSS sanitizer for HTML, MathML, and SVG. It is a great library to sanitize user input before rendering it in the DOM.
I am still building this list