@sreeshanth_00700/my-string-utils
v1.0.1
Published
A small utility library for common string transformations
Maintainers
Readme
@sreeshuu/my-string-utils
A lightweight, zero-dependency JavaScript utility library for common string transformations, slug generation, and reading time estimation.
Features
- Slugify: Convert strings into clean, URL-friendly slugs.
- Title Case: Capitalize the first letter of each word in a phrase.
- Reading Time: Estimate total reading time and word count based on standard reading speeds.
- Lightweight: Zero external runtime dependencies.
- Modern ES Modules: Fully compatible with Node.js ESM.
Installation
Install the package using npm:
npm install @sreeshuu/my-string-utilsUsage
Ensure your project uses ES modules (set "type": "module" in your package.json), then import the utility functions:
import { slugify, titleCase, readingTime } from '@sreeshuu/my-string-utils';
// 1. Convert text to a URL slug
const slug = slugify('Hello World! How Are You?');
console.log(slug);
// Output: 'hello-world-how-are-you'
// 2. Format a string to Title Case
const title = titleCase('hello from the other side');
console.log(title);
// Output: 'Hello From The Other Side'
// 3. Estimate reading time
const stats = readingTime('This is a short sample sentence to calculate words and duration.');
console.log(stats);
// Output: { words: 10, minutes: 1, text: '1 min read' }API Reference
slugify(text)
- Parameters:
text(string) — The raw text string. - Returns:
string— A lowercase, URL-safe hyphenated string.
titleCase(text)
- Parameters:
text(string) — The text to convert. - Returns:
string— Capitalized words.
readingTime(text, [wpm=200])
- Parameters:
text(string) — The body text.wpm(number, optional) — Average words per minute (defaults to200).
- Returns:
object—{ words: number, minutes: number, text: string }.
License
MIT
