npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

stringwiz

v1.3.0

Published

StringWiz: A Simple and Efficient JavaScript String Manipulation Library. Provides a range of easy-to-use functions for common string operations.

Downloads

5

Readme

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('[email protected]'); // t**[email protected]

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 [email protected] and [email protected]');
// ['[email protected]', '[email protected]']

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.