peasytext
v0.2.2
Published
Pure TypeScript text processing toolkit — 15 tools for case conversion, slug generation, word counting, line sorting, Base64/URL/HTML encoding, find & replace, deduplication, line numbering, pattern extraction, text diffing, Lorem Ipsum generation, JSON f
Downloads
474
Maintainers
Readme
peasytext
Pure TypeScript text processing toolkit — 15 tools for case conversion, slug generation, word counting, line sorting, Base64/URL/HTML encoding, find & replace, deduplication, line numbering, pattern extraction, text diffing, Lorem Ipsum generation, JSON formatting, and text reversal. Zero dependencies. Tree-shakeable ESM.
Extracted from the client-side engines at peasytext.com, where all 15 text tools run entirely in the browser. This package provides the same functionality for Node.js, Deno, Bun, and browser environments.
Try the interactive tools at peasytext.com — text case conversion, word counting, slug generation, Base64 encoding, JSON formatting, and 10 more tools
Table of Contents
- Install
- Quick Start
- What You Can Do
- API Reference
- TypeScript Types
- REST API Client
- Learn More
- Also Available
- Peasy Developer Tools
- License
Install
npm install peasytextQuick Start
import { toCase, slugify, countText, extract } from "peasytext";
// Convert text between 13 case formats
console.log(toCase("hello world", "pascal")); // "HelloWorld"
console.log(toCase("hello world", "snake")); // "hello_world"
console.log(toCase("hello world", "constant")); // "HELLO_WORLD"
// Generate URL-friendly slugs with diacritic handling
console.log(slugify("Crème brûlée recipe!")); // "creme-brulee-recipe"
// Count words, sentences, reading time
const stats = countText("Hello world. How are you today?");
console.log(stats.words); // 6
console.log(stats.sentences); // 2
console.log(stats.readingTime); // "< 1 min"
// Extract patterns from text
const emails = extract("Contact [email protected] or [email protected]", "emails");
console.log(emails); // ["[email protected]", "[email protected]"]What You Can Do
Case Conversion
Convert text between 13 case formats — from basic upper/lower to programming conventions like camelCase, snake_case, and CONSTANT_CASE. Automatically handles camelCase and snake_case input by splitting on word boundaries.
| Case | Example | Use Case |
|------|---------|----------|
| upper | HELLO WORLD | Constants, emphasis |
| lower | hello world | Normalization |
| title | Hello World | Headings, titles |
| sentence | Hello world | Natural text |
| camel | helloWorld | JavaScript variables |
| pascal | HelloWorld | Class names |
| snake | hello_world | Python variables |
| kebab | hello-world | CSS classes, URLs |
| constant | HELLO_WORLD | Constants, env vars |
| dot | hello.world | Package names |
| path | hello/world | File paths |
| alternating | hElLo WoRlD | Sarcasm text |
| inverse | hELLO wORLD | Inversion |
import { toCase } from "peasytext";
// Programming case conversions
console.log(toCase("user full name", "camel")); // "userFullName"
console.log(toCase("user full name", "pascal")); // "UserFullName"
console.log(toCase("user full name", "snake")); // "user_full_name"
console.log(toCase("user full name", "constant")); // "USER_FULL_NAME"Learn more: Text Case Converter · Convert Case and Clean Text Guide · What is Case Conversion?
Slug Generation
Convert any text to a URL-friendly slug. Handles Unicode, diacritics, and special characters — essential for SEO-friendly URLs, file naming, and database keys.
import { slugify } from "peasytext";
// Diacritic stripping with NFD normalization
console.log(slugify("Crème Brûlée — The Recipe")); // "creme-brulee-the-recipe"
console.log(slugify("München Straße")); // "munchen-strasse"
// Custom separator and max length
console.log(slugify("Hello World", { separator: "_" })); // "hello_world"
console.log(slugify("A very long title here", { maxLength: 10 })); // "a-very"Learn more: Slug Generator · Slug Generation and URL-Safe Strings · What is a Slug?
Text Statistics
Count characters, words, sentences, paragraphs, and lines. Estimates reading time based on configurable words-per-minute — useful for blog posts, content management, and SEO metadata.
import { countText } from "peasytext";
const stats = countText("Hello world. This is a test.\n\nNew paragraph here.");
console.log(stats.words); // 9
console.log(stats.sentences); // 3
console.log(stats.paragraphs); // 2
console.log(stats.readingTime); // "< 1 min"Learn more: Text Counter · Word Character Line Counting Best Practices · What is Word Count?
Line Sorting
Sort lines alphabetically, by length, numerically, or reverse order. The shuffle mode uses Fisher-Yates for uniform random distribution.
import { sortLines } from "peasytext";
const text = "banana\napple\ncherry";
console.log(sortLines(text, "alpha")); // apple\nbanana\ncherry
console.log(sortLines(text, "length")); // apple\nbanana\ncherry
console.log(sortLines("10\n2\n30", "numeric")); // 2\n10\n30Learn more: Sort Lines Tool · How to Sort Text Lines · What is Line Ending?
Base64 Encoding
Encode and decode Base64 with full UTF-8 support — handles emoji, CJK characters, and all Unicode. Works in both browser (using btoa/atob + TextEncoder) and Node.js (using Buffer).
import { base64Encode, base64Decode } from "peasytext";
const encoded = base64Encode("Hello, 世界! 🌍");
console.log(encoded); // "SGVsbG8sIOS4lueVjCEg8J+MjQ=="
console.log(base64Decode(encoded)); // "Hello, 世界! 🌍"Learn more: Base64 Encode Decode Tool · Base64 Encoding Guide · How to Encode Decode Base64
URL & HTML Encoding
import { urlEncode, urlDecode, htmlEncode, htmlDecode } from "peasytext";
// URL encoding with optional plus-for-spaces
console.log(urlEncode("hello world")); // "hello%20world"
console.log(urlEncode("hello world", true)); // "hello+world"
console.log(urlDecode("hello%20world")); // "hello world"
// HTML entity encoding — prevents XSS in user-generated content
console.log(htmlEncode('<script>alert("xss")</script>'));
// "<script>alert("xss")</script>"Learn more: URL Encode Decode Tool · HTML Entity Encoder · What is an Escape Character?
Find & Replace
Plain text and regex find & replace with case sensitivity options.
import { findReplace } from "peasytext";
// Case-insensitive replace
console.log(findReplace("Hello World", "world", "TypeScript", { caseSensitive: false }));
// "Hello TypeScript"
// Regex mode — replace all numbers
console.log(findReplace("abc123def456", "\\d+", "NUM", { regex: true }));
// "abcNUMdefNUM"Learn more: Find and Replace Tool · How to Find and Replace with Regex · Regex Cheat Sheet Essential Patterns
Deduplication
Remove duplicate lines while preserving original order.
import { dedupeLines } from "peasytext";
console.log(dedupeLines("apple\nbanana\napple\ncherry\nbanana"));
// "apple\nbanana\ncherry"Learn more: Remove Duplicate Lines Tool · How to Remove Duplicate Lines
Line Numbers
Add or remove line numbers from text.
import { addLineNumbers, removeLineNumbers } from "peasytext";
console.log(addLineNumbers("first\nsecond\nthird"));
// "1: first\n2: second\n3: third"
console.log(removeLineNumbers("1: first\n2: second\n3: third"));
// "first\nsecond\nthird"Learn more: Line Numbers Tool · What is Plain Text? · What is Whitespace?
Pattern Extraction
Extract emails, URLs, phone numbers, IP addresses, hashtags, and @mentions from any text using built-in regex patterns.
import { extract } from "peasytext";
const text = "Contact [email protected], visit https://example.com, call +1-555-0123";
console.log(extract(text, "emails")); // ["[email protected]"]
console.log(extract(text, "urls")); // ["https://example.com,"]
console.log(extract(text, "phones")); // ["+1-555-0123"]Learn more: Text Extractor Tool · How to Extract Data from Text · Regex Practical Guide
Text Diffing
Compare two texts line by line and measure similarity.
import { diffTexts } from "peasytext";
const result = diffTexts("apple\nbanana\ncherry", "banana\ncherry\ndate");
console.log(result.added); // ["date"]
console.log(result.removed); // ["apple"]
console.log(result.similarity); // 0.6667Learn more: Text Diff Tool · What is Text Diff? · What is String Distance?
Lorem Ipsum
Generate placeholder text by words, sentences, or paragraphs.
import { loremIpsum } from "peasytext";
console.log(loremIpsum(10, "words")); // 10 lorem ipsum words
console.log(loremIpsum(3, "paragraphs")); // 3 paragraphs of textLearn more: Lorem Ipsum Generator · Lorem Ipsum Placeholder Text Guide · What is Lorem Ipsum?
JSON Formatting
Format, minify, and validate JSON strings.
import { jsonFormat, jsonMinify, jsonValidate } from "peasytext";
console.log(jsonFormat('{"a":1,"b":2}')); // Pretty-printed with 2-space indent
console.log(jsonMinify('{ "a": 1 }')); // '{"a":1}'
console.log(jsonValidate('{"key": "ok"}')); // trueLearn more: JSON Formatter Tool · What is Text Encoding? · JSON Format Reference
Text Reversal
Reverse text by characters, words, or lines.
import { reverseText } from "peasytext";
console.log(reverseText("hello", "characters")); // "olleh"
console.log(reverseText("hello world", "words")); // "world hello"
console.log(reverseText("a\nb\nc", "lines")); // "c\nb\na"Learn more: Reverse Text Tool · What is ROT13? · What is Unicode?
API Reference
| Function | Description |
|----------|-------------|
| toCase(text, target) | Convert between 13 case formats |
| slugify(text, options?) | Generate URL-friendly slug |
| countText(text, wpm?) | Count words, chars, sentences, reading time |
| sortLines(text, mode?) | Sort lines by alpha, length, numeric, etc. |
| base64Encode(text) | Encode text to Base64 (UTF-8 safe) |
| base64Decode(text) | Decode Base64 to text (UTF-8 safe) |
| urlEncode(text, plus?) | URL-encode text |
| urlDecode(text) | URL-decode text |
| htmlEncode(text) | Encode HTML entities |
| htmlDecode(text) | Decode HTML entities |
| findReplace(text, find, replace?, opts?) | Find and replace with regex support |
| dedupeLines(text, caseSensitive?) | Remove duplicate lines |
| addLineNumbers(text, opts?) | Add line numbers |
| removeLineNumbers(text) | Remove line numbers |
| extract(text, patternType?) | Extract emails, URLs, phones, etc. |
| diffTexts(textA, textB) | Compare two texts |
| loremIpsum(count?, unit?) | Generate Lorem Ipsum |
| reverseText(text, mode?) | Reverse by chars, words, or lines |
| jsonFormat(text, indent?) | Pretty-print JSON |
| jsonMinify(text) | Minify JSON |
| jsonValidate(text) | Validate JSON |
TypeScript Types
All types are exported for full type safety:
import type {
CaseType, // "upper" | "lower" | "title" | "sentence" | "camel" | ...
SortMode, // "alpha" | "alpha-desc" | "length" | "numeric" | "reverse" | "shuffle"
ExtractType, // "emails" | "urls" | "phones" | "numbers" | "ips" | "hashtags" | "mentions"
LoremUnit, // "words" | "sentences" | "paragraphs"
ReverseMode, // "characters" | "words" | "lines"
TextStats, // { characters, words, sentences, paragraphs, lines, readingTime }
DiffResult, // { added, removed, unchanged, similarity }
SlugifyOptions, // { separator?, lowercase?, maxLength? }
} from "peasytext";REST API Client
The API client connects to the PeasyText developer API for tool discovery and content.
import { PeasyTextClient } from "peasytext";
const client = new PeasyTextClient();
// List available tools
const tools = await client.listTools();
console.log(tools.results);
// Search across all content
const results = await client.search("case");
console.log(results);
// Browse the glossary
const glossary = await client.listGlossary({ search: "format" });
for (const term of glossary.results) {
console.log(`${term.term}: ${term.definition}`);
}
// Discover guides
const guides = await client.listGuides({ category: "text" });
for (const guide of guides.results) {
console.log(`${guide.title} (${guide.audience_level})`);
}Full API documentation at peasytext.com/developers/.
Learn More
- Tools: Text Counter · Text Case Converter · Sort Lines · Lorem Ipsum Generator · Slug Generator · Find and Replace · Remove Duplicate Lines · Base64 Encode Decode · URL Encode Decode · JSON Formatter · HTML Entity Encoder · Reverse Text · Line Numbers · Text Diff · Text Extractor · All Tools
- Guides: Text Encoding UTF-8 ASCII · Regex Cheat Sheet Essential Patterns · Lorem Ipsum Placeholder Text Guide · Regex Practical Guide · Base64 Encoding Guide · Convert Case and Clean Text · Word Character Line Counting Best Practices · How to Find and Replace with Regex · Slug Generation URL-Safe Strings · Troubleshooting Line Endings CRLF LF · Troubleshooting Character Encoding · All Guides
- Glossary: ASCII · BOM · Case Conversion · Diacritics · Escape Character · Line Ending · Lorem Ipsum · Normalization · Plain Text · Slug · Text Encoding · Unicode · Whitespace · Word Count · All Terms
- Formats: TXT · CSV · JSON · HTML · Markdown · XML · YAML · All Formats
- API: REST API Docs · OpenAPI Spec
Also Available
| Language | Package | Install |
|----------|---------|---------|
| Python | peasytext | pip install "peasytext[all]" |
| Go | peasytext-go | go get github.com/peasytools/peasytext-go |
| Rust | peasytext | cargo add peasytext |
| Ruby | peasytext | gem install peasytext |
Peasy Developer Tools
Part of the Peasy Tools open-source developer ecosystem.
| Package | PyPI | npm | Description | |---------|------|-----|-------------| | peasy-pdf | PyPI | npm | PDF merge, split, rotate, compress, 21 operations — peasypdf.com | | peasy-image | PyPI | npm | Image resize, crop, convert, compress — peasyimage.com | | peasy-audio | PyPI | npm | Audio trim, merge, convert, normalize — peasyaudio.com | | peasy-video | PyPI | npm | Video trim, resize, thumbnails, GIF — peasyvideo.com | | peasy-css | PyPI | npm | CSS minify, format, analyze — peasycss.com | | peasy-compress | PyPI | npm | ZIP, TAR, gzip compression — peasytools.com | | peasy-document | PyPI | npm | Markdown, HTML, CSV, JSON conversion — peasyformats.com | | peasytext | PyPI | npm | Text case conversion, slugify, word count — peasytext.com |
License
MIT
