str4matter
v1.2.0
Published
Lightweight string formatting and sanitization utilities for Node.js
Downloads
173
Maintainers
Readme
str4matter
A lightweight string formatting and sanitization library for Node.js.
Installation
npm install str4matterUsage
const { stripHtml, escapeHtml, slugify, truncate } = require("str4matter");
stripHtml("<p>Hello <b>world</b></p>"); // "Hello world"
escapeHtml('<img src="x">'); // "<img src="x">"
slugify("Hello World! It's great."); // "hello-world-its-great"
truncate("A very long string...", 10); // "A very lo…"API
| Function | Description |
| --------------------- | -------------------------------------------- |
| stripHtml(str) | Remove all HTML tags |
| escapeHtml(str) | Escape & < > " ' to HTML entities |
| normalizeWhitespace | Collapse whitespace, trim |
| stripControlChars | Remove non-printable control characters |
| slugify(str) | URL-friendly slug |
| truncate(str, n) | Truncate with ellipsis |
License
ISC
