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.
- Wide range of string manipulation functions.
- Easy integration into any JavaScript project.
- Optimized for performance.
npm install stringwiz
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
Below are some of the key functions available in StringWiz:
This function obfuscates an email address for privacy (e.g., for display purposes).
obfuscateEmail('[email protected]'); // t**t@example.com
Generates an acronym from the given string.
generateAcronym('For your information'); // 'FYI'
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'
Truncates a string in the middle to a specified length.
truncateMiddle('Hello World', 7); // 'He...ld'
Removes HTML tags from a string.
stripHtmlTags('<p>Hello World</p>'); // 'Hello World'
Encodes a string to Base64.
encodeBase64('Hello World');
// 'SGVsbG8gV29ybGQ='
Decodes a Base64 string.
decodeBase64('SGVsbG8gV29ybGQ=');
// 'Hello World'
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'
Reverses the given string.
reverseString('Hello World'); // 'dlroW olleH'
Capitalizes the first letter of each word in a string.
capitalizeWords('hello world'); // 'Hello World'
Converts a string to constant case.
toConstantCase('Hello World'); // 'HELLO_WORLD'
Converts a string to dot case.
toDotCase('Hello World'); // 'hello.world'
Converts a string to Pascal case.
toPascalCase('hello world'); // 'HelloWorld'
Converts a string to snake case.
toSnakeCase('Hello World'); // 'hello_world'
Checks if a string is a palindrome.
isPalindrome('racecar'); // true
isPalindrome('hello'); // false
Converts a string to HTTP header case.
toHeaderCase('content type'); // 'Content-Type'
Replaces all occurrences of a substring within a string.
replaceAllOccurrences('Hello World', 'o', 'a'); // 'Hella Warld'
Counts the number of words in a string.
countWords('Hello World'); // 2
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'
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'
Extracts email addresses from a string.
extractEmails('Contact us at [email protected] and [email protected]');
// ['[email protected]', '[email protected]']
Removes extra spaces from a string.
removeExtraSpaces(' Hello World ');
// 'Hello World'
Checks if a string is numeric.
isNumeric('1234');
// true
isNumeric('1234a');
// false
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'
Contributions are always welcome! Feel free to fork the repository and submit pull requests.
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.
I use commitizen
to help write good commit messages. To commit your changes, please follow these steps:
-
Stage Changes: Use
git add
to stage changes for commit. -
Run Commit Command: Use the
npm run commit
command to start the commit process. This will launchcommitizen
. -
Follow Prompts:
commitizen
will prompt you to fill out any required commit fields. -
Push Changes: After committing, push your changes to the repository with
npm run acp
.
Each commit message should follow this format: <type>(<scope>): <subject>
-
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.
-
Scope (optional): A scope may be provided to a commit’s type, to provide additional contextual information and is contained within parenthesis.
-
Subject: A brief description of the change.
feat(Functions): add two new string functions
docs(readme): update installation instructions
Before committing, ensure that all tests pass. Tests are mandatory for this package to maintain code quality and stability.