Package Exports
- string-utils-basic
- string-utils-basic/src/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (string-utils-basic) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
String Utilities Basic
A collection of basic string manipulation functions written in JavaScript. These functions provide a variety of utilities for validating, formatting, and transforming strings.
Functions Overview
- basicValidation Validates if the input is a string.
Returns "Give valid string" if the input is not a string. Returns an empty string if the input is an empty string. Returns "ok" for valid string inputs.
- removeAllWhiteSpacesExceptOnesInBetween Removes all unnecessary whitespace characters, except for single spaces between words.
Returns "Give valid string" or an empty string if the validation fails. Trims and reduces multiple spaces to a single space.
- removeNonAlphaNumericExceptSpacesInBetween Removes all non-alphanumeric characters except spaces.
Returns "Give valid string" or an empty string if the validation fails. Utilizes removeAllWhiteSpacesExceptOnesInBetween to clean up the string.
- capitalizeString Capitalizes the first letter of each word in the string.
Returns "Give valid string" or an empty string if the validation fails.
- countWordsInString Counts the number of words in a string.
Returns "Give valid string" if the input is invalid. Returns 0 for an empty string. Utilizes removeAllWhiteSpacesExceptOnesInBetween to ensure proper word counting.
- reverseString Reverses the entire string.
Returns "Give valid string" or an empty string if the validation fails.
- reverseWordsInString Reverses the order of words in the string.
Returns "Give valid string" or an empty string if the validation fails.
- truncateString Truncates the string to a specified length and appends "..." if truncated.
Returns "Give valid string" or an empty string if the validation fails.
Default truncation length is 20.
- snakeString Converts the string to snake_case.
Returns "Give valid string" or an empty string if the validation fails. Utilizes removeNonAlphaNumericExceptSpacesInBetween for cleaning the string.
- kebabString Converts the string to kebab-case.
Returns "Give valid string" or an empty string if the validation fails. Utilizes removeNonAlphaNumericExceptSpacesInBetween for cleaning the string.
- camelString Converts the string to camelCase.
Returns "Give valid string" or an empty string if the validation fails. Utilizes removeNonAlphaNumericExceptSpacesInBetween for cleaning the string. Converts the first word to lowercase and capitalizes subsequent words.
Usage To use these functions in your project, require the module and call the desired function:
const { basicValidation, removeAllWhiteSpacesExceptOnesInBetween, removeNonAlphaNumericExceptSpacesInBetween, capitalizeString, countWordsInString, reverseString, reverseWordsInString, truncateString, snakeString, kebabString, camelString } = require('string-utils-basic');
// Example usage:
console.log(capitalizeString("hello world"));
// Outputs: "Hello World"
Installation-
Clone the repository:
git clone https://github.com/your-username/string-utils-basic.git
Navigate to the project directory:
cd string-utils-basic
Install the dependencies:
npm install
Running Tests Run the tests to ensure everything is working correctly:
npm test
Project By
Apoorv Shrivastava
Contributing
Feel free to submit issues or pull requests if you have suggestions or improvements.
License
This project is licensed under the MIT License.
This summary provides a clear overview of the functionality provided by your string utility functions, along with instructions on how to use, install, and test them.