stringzy

2.0.1 • Public • Published

stringzy

NPM Version Downloads License Bundle Size

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.

✨ Features

  • 💪 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

📦 Installation

# Using npm
npm install stringzy

# Using yarn
yarn add stringzy

# Using pnpm
pnpm add stringzy

🚀 Quick Start

// 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

📋 Table of Contents

Transformations

  • 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

Validations

  • 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

Analysis

Formatting

  • 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

📋 API Reference

🔄 Transformations

Functions for transforming and manipulating strings.

truncateText(text, maxLength, suffix = '...')

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

toSlug(text)

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

capitalizeWords(text)

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

removeSpecialChars(text, replacement = '')

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

camelCase(text)

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

pascalCase(text)

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

snakeCase(text)

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

kebabCase(text)

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

titleCase(text)

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

constantCase(text)

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

✅ Validations

Functions for validating string formats and content.

isURL(text)

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

isEmail(text)

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

isEmpty(text)

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

📊 Analysis

Functions for analyzing string content and structure.

wordCount(text)

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

characterCount(text)

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

characterFrequency(text)

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

🎨 Formatting

Functions for formatting strings into specific patterns.

capitalize(text)

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

formatNumber(number, separator = ',')

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

formatPhone(phone, format = 'us')

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'

🔧 Usage Patterns

Individual Function Imports

import { isEmail, wordCount, capitalize } from 'stringzy';

const email = 'user@example.com';
if (isEmail(email)) {
  console.log('Valid email!');
}

Namespace Imports

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');

Default Import (All Functions)

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');

🛠️ Usage Examples

In a React component

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>
  );
}

Form Validation

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;
}

Content Analysis Dashboard

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)
  };
}

Data Formatting

import { format } from 'stringzy';

function formatUserData(userData) {
  return {
    name: format.capitalize(userData.name),
    phone: format.formatPhone(userData.phone),
    revenue: format.formatNumber(userData.revenue)
  };
}

🔄 TypeScript Support

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');

🏗️ Architecture

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.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • 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

Package Sidebar

Install

npm i stringzy

Weekly Downloads

127

Version

2.0.1

License

MIT

Unpacked Size

27.7 kB

Total Files

9

Last publish

Collaborators

  • samarth1176