strtoolkit
strtoolkit
is a lightweight toolkit for common string manipulation tasks, offering functions to truncate strings and check for the presence of special characters or numbers.
Installation
Install the package using npm:
npm i strtoolkit
Usage
Truncate a String
import { strTruncator } from "strtoolkit";
const truncatedString = strTruncator("Lorem ipsum dolor sit amet", 10);
console.log(truncatedString);
The strTruncator
function truncates a given string to a specified maximum length, appending "..." if the original string exceeds the limit.
Check for Special Characters or Numbers
const { hasCharOrNumber } = require("strtoolkit");
const hasSpecialCharOrNumber = hasCharOrNumber("Hello@World123");
console.log(hasSpecialCharOrNumber);
The hasCharOrNumber
function checks whether a string contains either special characters or numbers.
API
strTruncator(str: string, maxLength: number): string
Truncate a given string to a specified maximum length.
str
: The input string to be truncated.maxLength
: The maximum length of the truncated string.
Returns the truncated string with an appended "..." if the original string exceeds the limit.
hasCharOrNumber(str: string): boolean
Check if a string contains either special characters or numbers.
str
: The input string to be checked.
Returns true
if the string contains either special characters or numbers; otherwise, returns false
.
Contributing
Feel free to contribute by opening issues or submitting pull requests on GitHub.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Make sure to replace "Etzshally" with your actual GitHub username, and adjust the paths and details as needed for your project.