A simple and flexible package that provides various string utilities including converting strings to uppercase, lowercase, and counting words.
npm install incognito-js-helperA lightweight and powerful JavaScript utility library that provides over 50+ functions for working with strings and arrays.
Install via npm:
``bash`
npm install incognito-js-helper
Import the package in your JavaScript project:
`javascript`
const utils = require('incognito-js-helper');
---
javascript
console.log(utils.toUpperCase("hello world")); // "HELLO WORLD"
`$3
Converts a string to lowercase.
`javascript
console.log(utils.toLowerCase("HELLO WORLD")); // "hello world"
`$3
Capitalizes the first letter of a string.
`javascript
console.log(utils.capitalize("hello")); // "Hello"
`$3
Reverses the characters in a string.
`javascript
console.log(utils.reverseString("hello")); // "olleh"
`$3
Removes leading and trailing whitespace from a string.
`javascript
console.log(utils.removeWhitespace(" hello ")); // "hello"
`$3
Replaces all occurrences of a substring.
`javascript
console.log(utils.replaceAll("apple banana apple", "apple", "orange")); // "orange banana orange"
`$3
Counts the number of words in a string.
`javascript
console.log(utils.countWords("Hello world!")); // 2
`$3
Checks if a string contains another substring.
`javascript
console.log(utils.contains("hello world", "world")); // true
`$3
Truncates a string to a given length.
`javascript
console.log(utils.truncate("Hello, this is a long text", 10)); // "Hello, thi..."
`$3
Converts a string to camelCase.
`javascript
console.log(utils.camelCase("hello world")); // "helloWorld"
`$3
Splits a string into an array based on a delimiter.
`javascript
console.log(utils.explode("apple,banana,grape", ",")); // ["apple", "banana", "grape"]
`$3
Joins an array into a single string.
`javascript
console.log(utils.implode(["apple", "banana", "grape"], "-")); // "apple-banana-grape"
`
$3
checks in string if it starts with the specified string
`javascript
console.log(utils.startsWith("Hello, world!", "Hello")); // true
`
$3
checks in string if it ends with the specified string
`javascript
console.log(arrayUtils.endsWith("Hello, world!", "world!")); // true
`
$3
Converts a string to snake_case.
`javascript
console.log(arrayUtils.snakeCase("Hello World Example"));
// Output: "hello_world_example"
`
$3
Converts a string to kebab-case.
`javascript
console.log(arrayUtils.kebabCase("Hello World Example"));
// Output: "hello-world-example"
`$3
Generates a random alphanumeric string of the given length.
`javascript
console.log(arrayUtils.randomString(10));
// Output: "aB3dE9fGhJ" (random output)
`$3
Converts a string to Title Case.
`javascript
console.log(arrayUtils.titleCase("hello world example"));
// Output: "Hello World Example"
`$3
Checks if a string is a palindrome.
`javascript
console.log(arrayUtils.isPalindrome("madam"));
// Output: trueconsole.log(arrayUtils.isPalindrome("hello"));
// Output: false
`$3
Splits a string into an array based on the given delimiter.
`javascript
console.log(arrayUtils.explode(",", "apple,banana,grape"));
// Output: ["apple", "banana", "grape"]
`$3
Joins an array into a string using the given delimiter.
`javascript
console.log(arrayUtils.implode("-", ["apple", "banana", "grape"]));
// Output: "apple-banana-grape"
`---
🔹 Array Functions
$3
Removes duplicate values from an array.
`javascript
console.log(utils.uniqueArray([1, 2, 2, 3, 4, 4, 5])); // [1, 2, 3, 4, 5]
`$3
Flattens a nested array.
`javascript
console.log(utils.flattenArray([1, [2, [3, 4], 5]])); // [1, 2, 3, 4, 5]
`$3
Splits an array into chunks of a given size.
`javascript
console.log(utils.chunkArray([1, 2, 3, 4, 5], 2)); // [[1, 2], [3, 4], [5]]
`$3
Randomly shuffles elements in an array.
`javascript
console.log(utils.shuffleArray([1, 2, 3, 4, 5]));
`$3
Finds common elements between two arrays.
`javascript
console.log(utils.arrayIntersection([1, 2, 3], [2, 3, 4])); // [2, 3]
`$3
Finds elements unique to the first array.
`javascript
console.log(utils.arrayDifference([1, 2, 3], [2, 3, 4])); // [1]
`$3
Sorts an array of numbers in ascending order.
`javascript
console.log(utils.sortNumeric([5, 1, 4, 2])); // [1, 2, 4, 5]
`$3
Sorts an array of strings alphabetically.
`javascript
console.log(utils.sortAlphabetic(["banana", "apple", "cherry"])); // ["apple", "banana", "cherry"]
`$3
Returns a random element from an array.
`javascript
console.log(utils.randomElement(["apple", "banana", "cherry"]));
`$3
Adds an element to an array at a specific index.
`javascript
let arr = [1, 2, 3, 5];
console.log(arrayUtils.addElement(arr, 4, 3));
// Output: [1, 2, 3, 4, 5]console.log(arrayUtils.addElement(arr, 6)); // Adds 6 at the end
// Output: [1, 2, 3, 4, 5, 6]
`---
🏆 Full List of Functions
$3
- toUpperCase
- toLowerCase
- capitalize
- reverseString
- removeWhitespace
- replaceAll
- countWords
- contains
- startsWith
- endsWith
- truncate
- camelCase
- snakeCase
- kebabCase
- titleCase
- randomString
- isPalindrome
- explode
- implode$3
- uniqueArray
- flattenArray
- chunkArray
- shuffleArray
- arrayIntersection
- arrayDifference
- sortNumeric
- sortAlphabetic
- randomElement
- addElement`---
---
This README now includes all the functions you wanted with proper descriptions and examples. Let me know if you need any refinements! 🚀