Skip to content

StringWiz is a powerful and easy-to-use JavaScript library for efficient string manipulation. It offers a wide range of functions to handle common string operations, making it an ideal choice for developers working on JavaScript projects that require extensive string handling.

Notifications You must be signed in to change notification settings

rukywe/stringWiz

Repository files navigation

StringWiz

StringWiz is a powerful and easy-to-use JavaScript library for efficient string manipulation. It offers a wide range of functions to handle common string operations, making it an ideal choice for developers working on JavaScript projects that require extensive string handling.

Features

  • Wide range of string manipulation functions.
  • Easy integration into any JavaScript project.
  • Optimized for performance.

Installation

npm install stringwiz

Usage

Here's a quick example of how to use StringWiz:

import { reverseString } from 'stringwiz';

const reversed = reverseString('Hello World');
console.log(reversed); // Outputs: dlroW olleH

API Reference

Below are some of the key functions available in StringWiz:

obfuscateEmail(email: string): string

This function obfuscates an email address for privacy (e.g., for display purposes).

obfuscateEmail('test@example.com'); // t**t@example.com

generateAcronym(str: string): string

Generates an acronym from the given string.

generateAcronym('For your information'); // 'FYI'

maskSensitiveData(str: string, visibleCount: number = 4): string

Masks all but the last specified number of characters of a string. This function is commonly used for masking sensitive data like API keys or credit card numbers.

maskSensitiveData('1234567890123456'); // '************3456'
maskSensitiveData('12345678', 3); // '*****678'
maskSensitiveData('MySecretPassword', 5); // '*********sword'

truncateMiddle(str: string, maxLength: number, separator: string = '...'): string

Truncates a string in the middle to a specified length.

truncateMiddle('Hello World', 7); // 'He...ld'

stripHtmlTags(str: string): string

Removes HTML tags from a string.

stripHtmlTags('<p>Hello World</p>'); // 'Hello World'

encodeBase64(str: string): string

Encodes a string to Base64.

encodeBase64('Hello World');
// 'SGVsbG8gV29ybGQ='

decodeBase64(str: string): string

Decodes a Base64 string.

decodeBase64('SGVsbG8gV29ybGQ=');
// 'Hello World'

formatCurrency(amount: number, currencySymbol: string = '$', decimalPlaces: number = 2): string

This function formats a numeric amount as a currency string, allowing customization for the currency symbol and the number of decimal places.

formatCurrency('1234.56'); // '$1,234.56'
formatCurrency('1234.56', '£'); // '£1,234.56'

reverseString(str: string): string

Reverses the given string.

reverseString('Hello World'); // 'dlroW olleH'

capitalizeWords(str: string): string

Capitalizes the first letter of each word in a string.

capitalizeWords('hello world'); // 'Hello World'

toConstantCase(str: string): string

Converts a string to constant case.

toConstantCase('Hello World'); // 'HELLO_WORLD'

toDotCase(str: string): string

Converts a string to dot case.

toDotCase('Hello World'); // 'hello.world'

toPascalCase(str: string): string

Converts a string to Pascal case.

toPascalCase('hello world'); // 'HelloWorld'

toSnakeCase(str: string): string

Converts a string to snake case.

toSnakeCase('Hello World'); // 'hello_world'

isPalindrome(str: string): boolean

Checks if a string is a palindrome.

isPalindrome('racecar'); // true
isPalindrome('hello'); // false

toHeaderCase(str: string): string

Converts a string to HTTP header case.

toHeaderCase('content type'); // 'Content-Type'

replaceAllOccurrences(str: string, search: string, replacement: string): string

Replaces all occurrences of a substring within a string.

replaceAllOccurrences('Hello World', 'o', 'a'); // 'Hella Warld'

countWords(str: string): number

Counts the number of words in a string.

countWords('Hello World'); // 2

snakeToCamelCase(str: string): string

Converts a string from snake_case to camelCase. It does not alter strings that are already in camelCase.

snakeToCamelCase('hello_world'); // 'helloWorld'
snakeToCamelCase('helloWorld'); // 'helloWorld'

camelToSnakeCase(str: string): string

Converts a string from camelCase to snake_case. It handles strings that are already in snake_case without further modification.

camelToSnakeCase('helloWorld'); // 'hello_world'
camelToSnakeCase('hello_world'); // 'hello_world'

extractEmails(str: string): string[]

Extracts email addresses from a string.

extractEmails('Contact us at test@example.com and admin@example.com');
// ['test@example.com', 'admin@example.com']

removeExtraSpaces(str: string): string

Removes extra spaces from a string.

removeExtraSpaces('  Hello   World  ');
// 'Hello World'

isNumeric(str: string): boolean

Checks if a string is numeric.

isNumeric('1234');
// true
isNumeric('1234a');
// false

sanitizeForURL(str: string): string

Sanitizes a string by encoding non-URL-friendly characters, making it safe for use in URLs.

sanitizeForURL('Hello World!'); // 'hello-world%21'
sanitizeForURL('  JavaScript & Web Dev @2021  '); // 'javascript-%26-web-dev-%402021'

Contributing

Contributions are always welcome! Feel free to fork the repository and submit pull requests.

Commit Guide

This project uses semantic-release for automating the versioning and release process. To comply with semantic-release, following the Conventional Commits specification for commit messages.

Committing Changes

I use commitizen to help write good commit messages. To commit your changes, please follow these steps:

  1. Stage Changes: Use git add to stage changes for commit.

  2. Run Commit Command: Use the npm run commit command to start the commit process. This will launch commitizen.

  3. Follow Prompts: commitizen will prompt you to fill out any required commit fields.

  4. Push Changes: After committing, push your changes to the repository with npm run acp.

Commit Message Format

Each commit message should follow this format: <type>(<scope>): <subject>

  1. Type: This indicates the type of change you're making. Common types include:

    • feat: A new feature.
    • fix: A bug fix.
    • docs: Changes to documentation.
    • test: Adding or updating tests.
    • refactor: Code change that neither fixes a bug nor adds a feature.
  2. Scope (optional): A scope may be provided to a commit’s type, to provide additional contextual information and is contained within parenthesis.

  3. Subject: A brief description of the change.

Examples

  • feat(Functions): add two new string functions
  • docs(readme): update installation instructions

Mandatory Tests

Before committing, ensure that all tests pass. Tests are mandatory for this package to maintain code quality and stability.

About

StringWiz is a powerful and easy-to-use JavaScript library for efficient string manipulation. It offers a wide range of functions to handle common string operations, making it an ideal choice for developers working on JavaScript projects that require extensive string handling.

Resources

Stars

Watchers

Forks

Packages

No packages published