A lightweight, zero-dependency NPM Package for elegant string manipulations. It provides a comprehensive range of text utilities for JavaScript and Node.js applications including transformations, validations, analysis, and formatting.
- 💪 Powerful - Transform, validate, analyze, and format strings with minimal code
- 🪶 Lightweight - Zero dependencies, tiny footprint
- 🧩 Modular - Import only what you need with organized namespaces
- 🚀 Fast - Optimized for performance
- ✅ Tested - Reliable and robust
- 🎯 Comprehensive - 4 specialized modules for all string needs
# Using npm
npm install stringzy
# Using yarn
yarn add stringzy
# Using pnpm
pnpm add stringzy
// Import the entire library
import stringzy from 'stringzy';
// Or import specific functions
import { toUpperCase, isEmail, wordCount, formatPhone } from 'stringzy';
// Or import by namespace
import { transform, validate, analyze, format } from 'stringzy';
// Transform your strings
const slug = stringzy.toSlug('Hello World!'); // 'hello-world'
const isValid = stringzy.validate.isEmail('user@example.com'); // true
const count = stringzy.analyze.wordCount('Hello world'); // 2
- truncateText - Truncates text to a specified maximum length
- toSlug - Converts a string to a URL-friendly slug
- capitalizeWords - Capitalizes the first letter of each word
- removeSpecialChars - Removes special characters from a string
- camelCase - Converts the given string to Camel Case
- pascaslCase - Converts the given string to Pascal Case
- snakeCase - Converts the given string to Snake Case
- kebabCase - Converts the given string to Kebab Case
- titleCase - Converts the given string to Title Case
- constantCase - Converts the given string to Constant Case
- isURL - Checks if a string is a valid URL
- isEmail - Checks if a string is a valid email address
- isEmpty - Checks if a string is empty or contains only whitespace
- wordCount - Counts the number of words in a string
- characterCount - Counts the number of characters in a string
- characterFrequency - Analyzes character frequency in a string
- capitalize - Capitalizes the first letter of each word
- formatNumber - Formats a number string with thousand separators
- formatPhone - Formats a phone number string to standard format
Functions for transforming and manipulating strings.
Truncates text to a specified maximum length, adding a suffix if truncated.
import { truncateText } from 'stringzy';
truncateText('This is a long sentence that needs truncating', 10);
// Returns: 'This is a...'
truncateText('This is a long sentence', 10, ' →');
// Returns: 'This is a →'
truncateText('Short', 10);
// Returns: 'Short' (no truncation needed)
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to truncate |
maxLength | number | required | Maximum length of the output string (excluding suffix) |
suffix | string | '...' | String to append if truncation occurs |
Converts a string to a URL-friendly slug.
import { toSlug } from 'stringzy';
toSlug('Hello World!');
// Returns: 'hello-world'
toSlug('This is a TEST string 123');
// Returns: 'this-is-a-test-string-123'
toSlug('Special $#@! characters');
// Returns: 'special-characters'
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to convert to a slug |
Capitalizes the first letter of each word in a string.
import { capitalizeWords } from 'stringzy';
capitalizeWords('hello world');
// Returns: 'Hello World'
capitalizeWords('javascript string manipulation');
// Returns: 'Javascript String Manipulation'
capitalizeWords('already Capitalized');
// Returns: 'Already Capitalized'
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to capitalize |
Removes special characters from a string, optionally replacing them.
import { removeSpecialChars } from 'stringzy';
removeSpecialChars('Hello, world!');
// Returns: 'Hello world'
removeSpecialChars('email@example.com');
// Returns: 'emailexamplecom'
removeSpecialChars('Phone: (123) 456-7890', '-');
// Returns: 'Phone-123-456-7890'
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to process |
replacement | string | '' | String to replace special characters with |
Converts the given string to Camel Case.
import { camelCase } from 'stringzy';
camelCase('hello world'); // 'helloWorld'
camelCase('this is a test'); // 'thisIsATest'
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to convert to Camel Case |
Converts the given string to Pascal Case.
import { pascalCase } from 'stringzy';
pascalCase('hello world'); // 'HelloWorld'
pascalCase('this is a test'); // 'ThisIsATest'
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to convert to Pascal Case |
Converts the given string to Snake Case.
import { snakeCase } from 'stringzy';
snakeCase('hello world'); // 'hello_world'
snakeCase('this is a test'); // 'this_is_a_test'
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to convert to Snake Case |
Converts the given string to Kebab Case.
import { kebabCase } from 'stringzy';
kebabCase('hello world'); // 'hello-world'
kebabCase('this is a test'); // 'this-is-a-test'
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to convert to Kebab Case |
Converts the given string to Title Case.
import { titleCase } from 'stringzy';
titleCase('hello world'); // 'Hello World'
titleCase('this is a test'); // 'This Is A Test'
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to convert to Title Case |
Converts the given string to Constant Case.
import { constantCase } from 'stringzy';
constantCase('hello world'); // 'HELLO_WORLD'
constantCase('this is a test'); // 'THIS_IS_A_TEST'
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to convert to Constant Case |
Functions for validating string formats and content.
Checks if a string is a valid URL.
isURL('https://example.com'); // true
isURL('not-a-url'); // false
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to validate as URL |
Checks if a string is a valid email address.
isEmail('user@example.com'); // true
isEmail('invalid-email'); // false
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to validate as email |
Checks if a string is empty or contains only whitespace.
isEmpty(' '); // true
isEmpty('hello'); // false
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to check for emptiness |
Functions for analyzing string content and structure.
Counts the number of words in a string.
wordCount('Hello world'); // 2
wordCount(''); // 0
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to count words in |
Counts the number of characters in a string.
characterCount('Hello'); // 5
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to count characters in |
Analyzes character frequency in a string (excluding spaces).
characterFrequency('hello'); // { h: 1, e: 1, l: 2, o: 1 }
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to analyze character frequency |
Functions for formatting strings into specific patterns.
Capitalizes the first letter of each word.
capitalize('hello world'); // 'Hello World'
capitalize('javaScript programming'); // 'Javascript Programming'
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to capitalize |
Formats a number string with thousand separators.
formatNumber('1234567'); // '1,234,567'
formatNumber('1234567', '.'); // '1.234.567'
Parameter | Type | Default | Description |
---|---|---|---|
number | string|number | required | The number to format |
separator | string | ',' | The separator to use for thousands |
Formats a phone number string to standard format.
formatPhone('1234567890'); // '(123) 456-7890'
formatPhone('11234567890', 'international'); // '+1 (123) 456-7890'
Parameter | Type | Default | Description |
---|---|---|---|
phone | string | required | The phone number string to format |
format | string | 'us' | Format type: 'us' or 'international' |
import { isEmail, wordCount, capitalize } from 'stringzy';
const email = 'user@example.com';
if (isEmail(email)) {
console.log('Valid email!');
}
import { validate, analyze, format } from 'stringzy';
// Organized by functionality
const emailValid = validate.isEmail('test@example.com');
const words = analyze.wordCount('Hello world');
const formatted = format.capitalize('hello world');
import stringzy from 'stringzy';
// Access any function
stringzy.toUpperCase('hello');
stringzy.validate.isEmail('test@example.com');
stringzy.analyze.wordCount('Hello world');
stringzy.format.capitalize('hello world');
import React from 'react';
import { truncate, capitalize, wordCount, isEmpty } from 'stringzy';
function ArticlePreview({ title, content }) {
const displayTitle = isEmpty(title) ? 'Untitled' : capitalize(title);
const previewText = truncate(content, 150);
const readingTime = Math.ceil(wordCount(content) / 200);
return (
<div className="article-preview">
<h2>{displayTitle}</h2>
<p>{previewText}</p>
<small>{readingTime} min read</small>
</div>
);
}
import { validate } from 'stringzy';
function validateForm(formData) {
const errors = {};
if (!validate.isEmail(formData.email)) {
errors.email = 'Please enter a valid email address';
}
if (!validate.isURL(formData.website)) {
errors.website = 'Please enter a valid URL';
}
if (validate.isEmpty(formData.name)) {
errors.name = 'Name is required';
}
return errors;
}
import { analyze } from 'stringzy';
function getContentStats(text) {
return {
words: analyze.wordCount(text),
characters: analyze.characterCount(text),
frequency: analyze.characterFrequency(text),
readingTime: Math.ceil(analyze.wordCount(text) / 200)
};
}
import { format } from 'stringzy';
function formatUserData(userData) {
return {
name: format.capitalize(userData.name),
phone: format.formatPhone(userData.phone),
revenue: format.formatNumber(userData.revenue)
};
}
The package includes TypeScript type definitions for all functions.
import { validate, analyze, format } from 'stringzy';
// TypeScript will provide proper type checking
const isValid: boolean = validate.isEmail('test@example.com');
const count: number = analyze.wordCount('Hello world');
const formatted: string = format.capitalize('hello world');
stringzy is organized into four specialized modules:
-
transformations.js
- Core string transformations -
validations.js
- String validation utilities -
analysis.js
- String analysis and metrics -
formatting.js
- String formatting functions
Each module can be imported individually or accessed through the main entry point.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Thank you to all contributors and users of this package!
- Inspired by the need for comprehensive yet simple string manipulation utilities.
Made with ❤️ by Samarth Ruia