@simongrasinovski/str-utils
Version:
A lightweight utility library for effortless string manipulation. Simplify common tasks like case validation, conversion and formatting with easy-to-use functions that enhance your JavaScript applications
27 lines (24 loc) • 15.9 kB
Markdown
## API
### Functions
| Function Name | Description | Parameters | Returns |
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ |
| `reverse` | Reverses the given string. | `input` (String): The string to reverse. | (String): Reversed string. |
| `countVowels` | Counts the number of vowels in a string. | `input` (String): The string to analyze. | (Number): Count of vowels. |
| `countConsonants` | Counts the number of consonants in a string. | `input` (String): The string to analyze. | (Number): Count of consonants. |
| `uniqueCharacters` | Returns all unique characters from a string. | `input` (String): The string to analyze.<br>`options` (Object, Optional): Configuration object to control additional options.<br> - `caseSensitive` (Boolean, Optional, Default: `true`): Whether to treat characters case-sensitively.<br> - `removeSpaces` (Boolean, Optional, Default: `false`): Whether to remove spaces before processing.<br> - `shuffleCharacters` (Boolean, Optional, Default: `false`): Whether to shuffle the characters in the output string. | (String): String with unique characters. |
| `camelCase` | Converts a string to camelCase. | `input` (String): The string to convert. | (String): String in camelCase. |
| `titleCase` | Converts a string to Title Case. | `input` (String): The string to convert.<br>`options` (Object, Optional): An optional configuration object.<br> - `trimConsecutiveSpaces` (Boolean, Optional, Default: `true`): If `true`, consecutive spaces are trimmed. | (String): String in Title Case. |
| `snakeCase` | Converts a string to snake_case. | `input` (String): The string to convert. | (String): String in snake_case. |
| `kebabCase` | Converts a string to kebab-case. | `input` (String): The string to convert. | (String): String in kebab-case. |
| `countOccurrences` | Counts occurrences of a substring within a string. | `input` (String): The string to search.<br>`substring` (String): The substring to count. | (Number): Count of occurrences. |
| `extractNumber` | Extracts numbers (either integers or decimals) from a string. | `input` (String): The string to analyze.<br>`options` (Object, Optional): An optional configuration object.<br> - `decimals` (Boolean, Optional, Default: `false`): If `true`, extracts decimal numbers; if `false`, extracts only integers. | (Array): Array of matching numbers, or `null` if no numbers found. |
| `longestWord` | Finds the longest word in a string. | `input` (String): The string to analyze. | (String): Longest word found. |
| `shortestWord` | Finds the shortest word in a string. | `input` (String): The string to analyze. | (String): Shortest word found. |
| `truncate` | Truncates a string to a specified length, appending a suffix if necessary. | `input` (String): The string to truncate.<br>`length` (Number): The maximum length for the truncated string.<br>`suffix` (String, Optional, Default: `'...'`): The string to append to the truncated string (e.g., `'...'`). | (String): Truncated string with suffix. |
| `randomCharacters` | Generates a random string of a specified length, with optional character sets (lowercase, uppercase, numbers, symbols). | `length` (Number): The length of the random string.<br>`options` (Object, Optional): Configuration object to specify the character sets.<br> - `lowercase` (Boolean, Optional, Default: `true`): If `true`, includes lowercase letters.<br> - `uppercase` (Boolean, Optional, Default: `false`): If `true`, includes uppercase letters.<br> - `numbers` (Boolean, Optional, Default: `false`): If `true`, includes numbers.<br> - `symbols` (Boolean, Optional, Default: `false`): If `true`, includes symbols. | (String): Generated random string with selected characters. |
| `substringBetween` | Extracts a substring between two characters. | `input` (String): The string to search.<br>`startChar` (String): Start character.<br>`endChar` (String): End character. | (String): Extracted substring. |
| `removeConsecutiveSpaces` | Removes consecutive spaces from a string. | `input` (String): The string to process. | (String): String with stripped consecutive spaces. |
| `isValidURL` | Checks if a string is a valid URL. | `input` (String): The string to validate. | (Boolean): `true` if valid, `false` otherwise. |
| `isValidHex` | Checks if a string is a valid HEX color. | `input` (String): The string to validate. | (Boolean): `true` if valid, `false` otherwise. |
| `isValidDate` | Checks if a string is a valid date. | `input` (String): The string to validate. | (Boolean): `true` if valid, `false` otherwise. |
| `isValidEmail` | Checks if a string is a valid email. | `input` (String): The string to validate. | (Boolean): `true` if valid, `false` otherwise. |