Gathering detailed insights and metrics for stringzy
Gathering detailed insights and metrics for stringzy
Gathering detailed insights and metrics for stringzy
Gathering detailed insights and metrics for stringzy
A lightweight, zero-dependency NPM package for elegant string manipulations.
npm install stringzy
Typescript
Module System
Node Version
NPM Version
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
19 Stars
175 Commits
16 Forks
1 Watchers
6 Branches
13 Contributors
Updated on Jul 08, 2025
Latest Version
3.0.0
Package Id
stringzy@3.0.0
Unpacked Size
129.57 kB
Size
27.99 kB
File Count
145
NPM Version
10.8.2
Node Version
20.19.2
Published on
Jun 26, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
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.
1# Using npm 2npm install stringzy 3 4# Using yarn 5yarn add stringzy 6 7# Using pnpm 8pnpm add stringzy
1// Import the entire library 2import stringzy from 'stringzy'; 3 4// Or import specific functions 5import { isEmail, wordCount, formatPhone } from 'stringzy'; 6 7// Or import by namespace 8import { transform, validate, analyze, format } from 'stringzy'; 9 10// Transform your strings 11const slug = stringzy.toSlug('Hello World!'); // 'hello-world' 12const isValid = stringzy.validate.isEmail('user@example.com'); // true 13const count = stringzy.analyze.wordCount('Hello world'); // 2
Functions for transforming and manipulating strings.
truncateText(text, maxLength, suffix = '...')
Truncates text to a specified maximum length, adding a suffix if truncated.
1import { truncateText } from 'stringzy'; 2 3truncateText('This is a long sentence that needs truncating', 10); 4// Returns: 'This is a...' 5 6truncateText('This is a long sentence', 10, ' →'); 7// Returns: 'This is a →' 8 9truncateText('Short', 10); 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 |
toSlug(text)
Converts a string to a URL-friendly slug.
1import { toSlug } from 'stringzy'; 2 3toSlug('Hello World!'); 4// Returns: 'hello-world' 5 6toSlug('This is a TEST string 123'); 7// Returns: 'this-is-a-test-string-123' 8 9toSlug('Special $#@! characters'); 10// Returns: 'special-characters'
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to convert to a slug |
capitalizeWords(text)
Capitalizes the first letter of each word in a string.
1import { capitalizeWords } from 'stringzy'; 2 3capitalizeWords('hello world'); 4// Returns: 'Hello World' 5 6capitalizeWords('javascript string manipulation'); 7// Returns: 'Javascript String Manipulation' 8 9capitalizeWords('already Capitalized'); 10// Returns: 'Already Capitalized'
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to capitalize |
removeSpecialChars(text, replacement = '')
Removes special characters from a string, optionally replacing them.
1import { removeSpecialChars } from 'stringzy'; 2 3removeSpecialChars('Hello, world!'); 4// Returns: 'Hello world' 5 6removeSpecialChars('email@example.com'); 7// Returns: 'emailexamplecom' 8 9removeSpecialChars('Phone: (123) 456-7890', '-'); 10// 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 |
removeWords(text, wordsToRemove)
Removes specified words from a string
1import { removeWords } from 'stringzy'; 2 3removeWords('Hello world this is a test', ['this', 'is']); 4// Returns: 'Hello world a test' 5 6removeWords('Remove The Quick BROWN fox', ['the', 'brown']); 7// Returns: 'Remove Quick fox' 8 9removeWords('JavaScript is awesome and JavaScript rocks', ['JavaScript']); 10// Returns: 'is awesome and rocks'
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to process |
wordsToRemove | string[] | required | Array of words to remove from the string |
removeDuplicates(text)
Removes duplicate case-sensitive words from a given text.
1import { removeDuplicates } from 'stringzy'; 2 3removeDuplicates('Hello world this is a is a test'); 4// Returns: 'Hello world this is a test' 5 6removeDuplicates('Remove me me me me or Me'); 7// Returns: 'Remove me or Me' 8 9removeDuplicates('JavaScript is not bad and not awesome'); 10// Returns: 'JavaScript is not bad and awesome'
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to process |
initials(text, limit)
Extracts initials from a text string.
1import { initials } from 'stringzy'; 2 3initials('John Doe'); 4// Returns: 'JD' 5 6initials('Alice Bob Charlie', 2); 7// Returns: 'AB' 8 9initials('Hello World Test Case'); 10// Returns: 'HWTC' 11 12initials('single'); 13// Returns: 's' 14 15initials(' Multiple Spaces Between '); 16// Returns: 'MSB'
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to extract initials from |
limit | number | undefined | Maximum number of initials to return (optional) |
camelCase(text)
Converts the given string to Camel Case.
1import { camelCase } from 'stringzy'; 2 3camelCase('hello world'); // 'helloWorld' 4camelCase('this is a test'); // 'thisIsATest'
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to convert to Camel Case |
pascalCase(text)
Converts the given string to Pascal Case.
1import { pascalCase } from 'stringzy'; 2 3 4pascalCase('hello world'); // 'HelloWorld' 5pascalCase('this is a test'); // 'ThisIsATest'
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to convert to Pascal Case |
snakeCase(text)
Converts the given string to Snake Case.
1import { snakeCase } from 'stringzy'; 2snakeCase('hello world'); // 'hello_world' 3snakeCase('this is a test'); // 'this_is_a_test'
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to convert to Snake Case |
kebabCase(text)
Converts the given string to Kebab Case.
1import { kebabCase } from 'stringzy'; 2 3 4kebabCase('hello world'); // 'hello-world' 5kebabCase('this is a test'); // 'this-is-a-test'
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to convert to Kebab Case |
titleCase(text)
Converts the given string to Title Case.
1import { titleCase } from 'stringzy'; 2 3 4titleCase('hello world'); // 'Hello World' 5titleCase('this is a test'); // 'This Is A Test'
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to convert to Title Case |
constantCase(text)
Converts the given string to Constant Case.
1import { constantCase } from 'stringzy'; 2 3 4constantCase('hello world'); // 'HELLO_WORLD' 5constantCase('this is a test'); // 'THIS_IS_A_TEST' 6
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to convert to Constant Case |
escapeHTML(text)
Escapes HTML special characters to prevent XSS attacks by converting them to their HTML entities.
1import { escapeHTML } from 'stringzy'; 2 3escapeHTML('Tom & Jerry'); 4// Returns: 'Tom & Jerry' 5 6escapeHTML('<script>alert("XSS")</script>'); 7// Returns: '<script>alert("XSS")</script>' 8 9escapeHTML('<div class="test">content</div>'); 10// Returns: '<div class="test">content</div>' 11 12escapeHTML('Say "Hello" & it\'s < 5 > 2'); 13// Returns: 'Say "Hello" & it's < 5 > 2'
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to escape HTML characters from |
maskSegment(text, maskStart, maskEnd, maskChar?)
Masks a segment of a string by replacing characters between two indices with a specified character (default is '*').
1import { maskSegment } from 'stringzy'; 2 3maskSegment('1234567890', 2, 6); 4// Returns: '12****7890' 5 6maskSegment('abcdef', 1, 4, '#'); 7// Returns: 'a###ef' 8 9maskSegment('token'); 10// Returns: '*****' 11
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to apply the masking to |
maskStart | number | 0 | The start index (inclusive) of the segment to mask |
maskEnd | number | text.length | The end index (exclusive) of the segment to mask |
maskChar | string | '*' | The character to use for masking (must be one character) |
Removes accents and diacritics from letters in a string (e.g. déjà vu → deja vu).
1import { deburr } from 'stringzy'; 2 3deburr('déjà vu'); 4// Returns: 'deja vu' 5 6deburr('Élève São Paulo'); 7// Returns: 'Eleve Sao Paulo' 8 9deburr('über cool'); 10// Returns: 'uber cool' 11
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to strip diacritics from |
Functions for validating string formats and content.
isURL(text)
Checks if a string is a valid URL.
1isURL('https://example.com'); // true 2isURL('not-a-url'); // false
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to validate as URL |
isEmail(text)
Checks if a string is a valid email address.
1isEmail('user@example.com'); // true 2isEmail('invalid-email'); // false
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to validate as email |
isDate(text)
Checks if a string is a valid date.
1import { isDate } from 'stringzy'; 2 3isDate('2023-12-25', DateFormat.YYYMMDD); // true 4isDate('12/25/2023', DateFormat.MMDDYYY, '/'); // true 5isDate('20-12-25', DateFormat.YYYMMDD); // false 6isDate('2023-12-1', DateFormat.YYYMMDD); // false 7isDate('invalid-date', DateFormat.YYYMMDD); // false 8isDate('2023-13-45', DateFormat.YYYMMDD); // false
Parameter | Type | Default | Description |
---|---|---|---|
input | string | required | The input string to validate as date |
format | DateFormats | required | The date format to validate against |
separator | string | optional | The separator to be used if it is not "-" |
isEmpty(text)
Checks if a string is empty or contains only whitespace.
1isEmpty(' '); // true 2isEmpty('hello'); // false
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to check for emptiness |
isSlug(text)
Checks if a string is a valid slug.
1isSlug("hello-world"); // true 2isSlug("test-product-123"); // true 3isSlug("Hello-World"); // false (uppercase letters) 4isSlug("hello--world"); // false (consecutive hyphens) 5isSlug("-hello-world"); // false (starts with hyphen) 6isSlug("hello_world"); // false (underscore not allowed)
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to validate as slug |
isIPv4(text)
Checks if a string is a valid IPv4 address.
1import { isIPv4 } from 'stringzy'; 2 3isIPv4('192.168.1.1'); // true 4isIPv4('0.0.0.0'); // true 5isIPv4('256.1.1.1'); // false (out of range) 6isIPv4('192.168.1'); // false (incomplete) 7isIPv4('192.168.01.1'); // false (leading zeros) 8isIPv4('192.168.1.a'); // false (non-numeric)
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to validate as IPv4 address |
isHexColor(text)
Checks if a string is a valid Hex color.
1import { isHexColor } from 'stringzy'; 2 3isHexColor('#fff'); // true 4isHexColor('fff'); // true 5isHexColor('#a1b2c3'); // true 6isHexColor('123abc'); // true 7isHexColor('#1234'); // false 8isHexColor('blue'); // false
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to validate as Hex color |
Functions for analyzing string content and structure.
readingDuration(text, readingSpeed = 230)
Calculates the estimated reading duration for a given text based on an average reading speed.
1import { readingDuration } from 'stringzy'; 2 3readingDuration('This is a sample text with twenty-three words to test the reading duration function.'); 4// Returns: 0 (23 words / 230 words per minute ≈ 0 minutes) 5 6readingDuration('This text contains fifty words. It is designed to test the reading duration function with a larger input.', 200); 7// Returns: 1 (50 words / 200 words per minute ≈ 1 minute) 8 9readingDuration(Array(9999).fill('Word').join(' ')); 10// Returns: 43 (9999 words / 230 words per minute ≈ 43 minutes)
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input text for which the reading duration is to be calculated |
readingSpeed | number | 230 | The reading speed in words per minute. Defaults to 230 (average reading speed) |
wordCount(text)
Counts the number of words in a string.
1wordCount('Hello world'); // 2 2wordCount(''); // 0
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to count words in |
characterCount(text)
Counts the number of characters in a string.
1characterCount('Hello'); // 5
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to count characters in |
characterFrequency(text)
Analyzes character frequency in a string (excluding spaces).
1characterFrequency('hello'); // { h: 1, e: 1, l: 2, o: 1 }
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to analyze character frequency |
stringSimilarity(textA, textB, algorithm = 'Levenshtein')
Calculates the percentage similarity between two texts using the selected algorithm. Method returns a percentage (0–100) value indicating how similar the two strings are.
1stringSimilarity('kitten', 'sitting'); // Returns: 57.14 2 3stringSimilarity('hello', 'hello'); // Returns: 100 4 5stringSimilarity('flaw', 'lawn', 'Damerau-Levenshtein'); // Returns: 50
Parameter | Type | Default | Description |
---|---|---|---|
textA | string | required | The first text to compare. |
textB | string | required | The second text to compare. |
algorithm | string | 'Levenshtein' | The algorithm to use: 'Levenshtein' or 'Damerau-Levenshtein'. |
Functions for formatting strings into specific patterns.
capitalize(text)
Capitalizes the first letter of each word.
1capitalize('hello world'); // 'Hello World' 2capitalize('javaScript programming'); // 'Javascript Programming'
Parameter | Type | Default | Description |
---|---|---|---|
text | string | required | The input string to capitalize |
formatNumber(number, separator = ',')
Formats a number string with thousand separators.
1formatNumber('1234567'); // '1,234,567' 2formatNumber('1234567', '.'); // '1.234.567'
Parameter | Type | Default | Description |
---|---|---|---|
number | string|number | required | The number to format |
separator | string | ',' | The separator to use for thousands |
formatPhone(phone, format = 'us')
Formats a phone number string to standard format.
1formatPhone('1234567890'); // '(123) 456-7890' 2formatPhone('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' |
1import { isEmail, wordCount, capitalize } from 'stringzy'; 2 3const email = 'user@example.com'; 4if (isEmail(email)) { 5 console.log('Valid email!'); 6}
1import { validate, analyze, format } from 'stringzy'; 2 3// Organized by functionality 4const emailValid = validate.isEmail('test@example.com'); 5const words = analyze.wordCount('Hello world'); 6const formatted = format.capitalize('hello world');
1import stringzy from 'stringzy'; 2 3// Access any function 4stringzy.toUpperCase('hello'); 5stringzy.validate.isEmail('test@example.com'); 6stringzy.analyze.wordCount('Hello world'); 7stringzy.format.capitalize('hello world');
1import React from 'react'; 2import { truncateText, capitalize, wordCount, isEmpty } from 'stringzy'; 3 4function ArticlePreview({ title, content }) { 5 const displayTitle = isEmpty(title) ? 'Untitled' : capitalize(title); 6 const previewText = truncateText(content, 150); 7 const readingTime = Math.ceil(wordCount(content) / 200); 8 9 return ( 10 <div className="article-preview"> 11 <h2>{displayTitle}</h2> 12 <p>{previewText}</p> 13 <small>{readingTime} min read</small> 14 </div> 15 ); 16}
1import { validate } from 'stringzy'; 2 3function validateForm(formData) { 4 const errors = {}; 5 6 if (!validate.isEmail(formData.email)) { 7 errors.email = 'Please enter a valid email address'; 8 } 9 10 if (!validate.isURL(formData.website)) { 11 errors.website = 'Please enter a valid URL'; 12 } 13 14 if (validate.isEmpty(formData.name)) { 15 errors.name = 'Name is required'; 16 } 17 18 return errors; 19}
1import { analyze } from 'stringzy'; 2 3function getContentStats(text) { 4 return { 5 words: analyze.wordCount(text), 6 characters: analyze.characterCount(text), 7 frequency: analyze.characterFrequency(text), 8 readingTime: Math.ceil(analyze.wordCount(text) / 200) 9 }; 10}
1import { format } from 'stringzy'; 2 3function formatUserData(userData) { 4 return { 5 name: format.capitalize(userData.name), 6 phone: format.formatPhone(userData.phone), 7 revenue: format.formatNumber(userData.revenue) 8 }; 9}
The package includes TypeScript type definitions for all functions.
1import { validate, analyze, format } from 'stringzy'; 2 3// TypeScript will provide proper type checking 4const isValid: boolean = validate.isEmail('test@example.com'); 5const count: number = analyze.wordCount('Hello world'); 6const formatted: string = format.capitalize('hello world');
stringzy is organized into four specialized modules:
transformations.js
- Core string transformationsvalidations.js
- String validation utilitiesanalysis.js
- String analysis and metricsformatting.js
- String formatting functionsEach module can be imported individually or accessed through the main entry point.
Contributions are welcome! Please read our contribution guidelines before submitting a pull request.
Contributors
Samarth Ruia |
John Cervantes |
Hardik Srivastav |
Ahmed Semih Erkan |
Michael van der Bend |
mamphis |
Stanisław Kumor |
Ali Medhat |
Soham Powar |
Abdul Arham |
Have questions, ideas, or want to contribute? Join our Discord server to chat with the community, discuss features, and help shape the future of the project.
This project is licensed under the MIT License - see the LICENSE file for details.
If you have contributed to this project and your image is not here, please let us know, and we'll be happy to add it!
Made with ❤️ by Samarth Ruia
No vulnerabilities found.
No security vulnerabilities found.