A comprehensive library for performing various string manipulations. This library provides utility functions that simplify and enhance string operations for JavaScript projects.
To use this library, first install it:
npm install 'text-trans';
Add the file containing the exported functions to your project and import the desired utilities.
import { capitalize, reverse, truncate, ... } from 'text-trans';
- Description: Capitalizes the first letter of a string.
-
Arguments:
-
str
(string): The input string.
-
- Returns: A new string with the first letter capitalized.
-
Example:
capitalize("hello world"); // Output: "Hello world"
- Description: Reverses the given string.
-
Arguments:
-
str
(string): The input string.
-
- Returns: The reversed string.
-
Example:
reverse("hello"); // Output: "olleh"
-
Description: Truncates a string to the specified length and appends an ellipsis (
...
) if necessary. -
Arguments:
-
str
(string): The input string. -
length
(number): The maximum length of the string.
-
- Returns: The truncated string with an ellipsis if it exceeds the length.
-
Example:
truncate("This is a long string", 10); // Output: "This is a..."
- Description: Converts a string to camelCase.
-
Arguments:
-
str
(string): The input string.
-
- Returns: The camelCase formatted string.
-
Example:
toCamelCase("hello world example"); // Output: "helloWorldExample"
- Description: Converts a string to PascalCase.
-
Arguments:
-
str
(string): The input string.
-
- Returns: The PascalCase formatted string.
-
Example:
toPascalCase("hello world example"); // Output: "HelloWorldExample"
- Description: Converts a string to kebab-case.
-
Arguments:
-
str
(string): The input string.
-
- Returns: The kebab-case formatted string.
-
Example:
toKebabCase("Hello World Example"); // Output: "hello-world-example"
- Description: Converts a string to snake_case.
-
Arguments:
-
str
(string): The input string.
-
- Returns: The snake_case formatted string.
-
Example:
toSnakeCase("Hello World Example"); // Output: "hello_world_example"
- Description: Converts a string to Title Case.
-
Arguments:
-
str
(string): The input string.
-
- Returns: The Title Case formatted string.
-
Example:
toTitleCase("hello world example"); // Output: "Hello World Example"
- Description: Counts the number of words in a string.
-
Arguments:
-
str
(string): The input string.
-
- Returns: The word count as a number.
-
Example:
wordCount("This is a sample sentence."); // Output: 5
- Description: Checks if a string is a palindrome.
-
Arguments:
-
str
(string): The input string.
-
- Returns: A boolean value indicating whether the string is a palindrome.
-
Example:
isPalindrome("A man, a plan, a canal: Panama"); // Output: true isPalindrome("hello"); // Output: false
This library is open-source and can be used freely in personal and commercial projects.
For any inquiries, feedback, or support:
- Phone: WhatsApp
- Email: pgbadgujar007@gmail.com
- Portfolio: My Portfolio
Inspired by NPM && Created with 💝 by Piyush