@developaul/string-utils
A comprehensive string manipulation utility library built with TypeScript for modern JavaScript applications.
Features
- 🚀 Modern ESM support with full TypeScript types
- 📦 Multiple entry points for tree-shaking optimization
- 🔧 Comprehensive utilities for string formatting and validation
- 💪 Fully typed with excellent IDE support
- 🎯 Zero dependencies - lightweight and fast
Installation
npm install @developaul/string-utils
pnpm add @developaul/string-utils
yarn add @developaul/string-utils
Usage
Basic Import
import { kebabCase, capitalize, isEmail } from '@developaul/string-utils';
const slug = kebabCase('Hello World');
const title = capitalize('hello world');
const valid = isEmail('test@example.com');
Namespace Imports
import { formatters, validators } from '@developaul/string-utils';
const slug = formatters.slugify('Hello World!');
const camel = formatters.camelCase('hello-world');
const isValidEmail = validators.isEmail('test@example.com');
const hasLength = validators.hasMinLength('hello', 3);
Submodule Imports
import { kebabCase, titleCase } from '@developaul/string-utils/formatters';
import { isEmail, isUrl } from '@developaul/string-utils/validators';
API Reference
Formatters
kebabCase(str: string): string
Convert a string to kebab-case.
kebabCase('Hello World')
kebabCase('camelCase')
camelCase(str: string): string
Convert a string to camelCase.
camelCase('hello-world')
camelCase('snake_case')
capitalize(str: string): string
Capitalize the first letter of a string.
capitalize('hello world')
titleCase(str: string): string
Convert a string to Title Case.
titleCase('hello world')
titleCase('the quick brown fox')
slugify(str: string): string
Create a URL-friendly slug from a string.
slugify('Hello World!')
slugify('The Quick Brown Fox')
truncate(str: string, length: number, suffix?: string): string
Truncate a string to a specified length.
truncate('Hello World', 5)
truncate('Hello World', 5, '!')
Validators
isEmail(str: string): boolean
Check if a string is a valid email address.
isEmail('test@example.com')
isEmail('invalid-email')
isUrl(str: string): boolean
Check if a string is a valid URL.
isUrl('https://example.com')
isUrl('not-a-url')
isAlphanumeric(str: string): boolean
Check if a string contains only alphanumeric characters.
isAlphanumeric('abc123')
isAlphanumeric('abc-123')
isEmpty(str: string): boolean
Check if a string is empty or contains only whitespace.
isEmpty('')
isEmpty(' ')
isEmpty('hello')
hasMinLength(str: string, minLength: number): boolean
Check if a string has a minimum length.
hasMinLength('hello', 3)
hasMinLength('hi', 3)
matchesPattern(str: string, pattern: RegExp): boolean
Check if a string matches a pattern.
matchesPattern('123', /^\d+$/)
matchesPattern('abc', /^\d+$/)
Version History
This package follows Semantic Versioning.
Current version: 0.1.0-alpha.0
Contributing
This package is part of the @breaking monorepo for learning package publishing workflows.
License
MIT License - see LICENSE file for details.