1.0.3 • Published 10 months ago

@nikita-naredi/string-utility v1.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

@nikita-naredi/string-utility

A utility package to parse strings

Installation

Using npm:

npm install --save @nikita-naredi/string-utility

Using yarn:

yarn add @nikita-naredi/string-utility

Usage

To use the string-utility package in your project, first import it:

const stringUtility = require('@nikita-naredi/string-utility');

Or if you're using ES6 modules:

import stringUtility from '@nikita-naredi/string-utility';

API Reference

FunctionDescriptionExampleOutput
toUpperSnakeCaseConverts the input string to upper snake case.stringUtility.toUpperSnakeCase('Hello World');'HELLO_WORLD'
toReverseCaseReverses the case of each character in the input string.stringUtility.toReverseCase('Hello World');'hELLO wORLD'
toAlternatingCaseConverts the input string to alternating case.stringUtility.toAlternatingCase('hello world');'HeLlO wOrLd'
toCamelCaseConverts the input string to camel case.stringUtility.toCamelCase('hello world');'helloWorld'
toPascalCaseConverts the input string to pascal case.stringUtility.toPascalCase('hello world');'HelloWorld'
toKebabCaseConverts the input string to kebab case.stringUtility.toKebabCase('hello world');'hello-world'
toSnakeCaseConverts the input string to snake case.stringUtility.toSnakeCase('hello world');'hello_world'
toCapitalizedCaseCapitalizes the first letter of each word in the input string.stringUtility.toCapitalizedCase('hello world');'Hello World'
toSentenceCaseConverts the input string to sentence case.stringUtility.toSentenceCase('hello world');'Hello world'
toTitleCaseConverts the input string to title case.stringUtility.toTitleCase('hello world');'Hello World'
removeNonAlphaRemoves all non-alphabetic characters from the input string.stringUtility.removeNonAlpha('Hello, World! 123');'HelloWorld'
containsOnlyAlphaChecks if the input string contains only alphabetic characters.stringUtility.containsOnlyAlpha('Hello');true
removeDuplicatesRemoves duplicate characters from the input string.stringUtility.removeDuplicates('Hello');'Helo'
findSubstringOccurrencesCounts the number of occurrences of a substring within the input string.stringUtility.findSubstringOccurrences('Hello, World! 123', 'el');1
replaceSpecificOccurrenceReplaces the nth occurrence of a substring with a new substring in the input string.stringUtility.replaceSpecificOccurrence('Hello, World! 123', 'l', 'i', '1');'Helio, World! 123'
replaceAllOccurrencesReplaces all occurrences of a substring with a new substring in the input string.stringUtility.replaceAllOccurrences('Hello, World! 123', 'l', 'i');'Heiio, Worid! 123'
caseStringConverts the input string to the specified case type (e.g., 'upper', 'lower', 'title').stringUtility.caseString('Hello, World!', 'alternate');'hELLo, wORLD'
countWordsCounts the number of words in the input string.stringUtility.countWords('Hello world');2
countCharactersCounts the total number of characters in the input string.stringUtility.countCharacters('Hello, World!');13
countUniqueCharactersCounts the number of unique characters in the input string.stringUtility.countUniqueCharacters('Hello');4
countVowelsCounts the number of vowels in the input string.stringUtility.countVowels('Hello world');3
countConsonantsCounts the number of consonants in the input string.stringUtility.countConsonants('Hello world');7
countSpecialCharactersCounts the number of special characters in the input string.stringUtility.countSpecialCharacters('Hello, World!');2
countDigitsCounts the number of digits in the input string.stringUtility.countDigits('Hello123World');3
countOccurrencesCounts the number of occurrences of a specific substring in the input string.stringUtility.countOccurrences('Hello world', 'o');2
countSentencesCounts the number of sentences in the input string.stringUtility.countSentences('Hello world. How are you? I am fine.');3
countParagraphsCounts the number of paragraphs in the input string.stringUtility.countParagraphs('Paragraph 1.\n\nParagraph 2.\n\nParagraph 3.');3
countLinesCounts the number of lines in the input string.stringUtility.countLines('Line 1\nLine 2\nLine 3');3
countUniqueWordsCounts the number of unique words in the input string.stringUtility.countUniqueWords('The quick brown fox jumps over the lazy dog');8
countSubstringsCounts the number of occurrences of a substring in the input string.stringUtility.countSubstrings('hello hello world', 'hello');2
generateRandomStringGenerates a random string of specified length and character set.stringUtility.generateRandomString(10, 'alphanumeric');'a2b3c4d5e6'
removeNonAlphaRemoves all non-alphabetic characters from the input string.stringUtility.removeNonAlpha('Hello, World! 123');'HelloWorld'
removeSubstringRemoves all occurrences of a specified substring from the input string.stringUtility.removeSubstring('Hello World', 'o');'Hell Wrld'
removeDuplicatesRemoves duplicate characters from the input string, keeping only the first occurrence.stringUtility.removeDuplicates('hello');'helo'
replaceFirstOccurrenceReplaces the first occurrence of a substring with a new string.stringUtility.replaceFirstOccurrence('Hello World', 'o', '0');'Hell0 World'
replaceLastOccurrenceReplaces the last occurrence of a substring with a new string.stringUtility.replaceLastOccurrence('Hello World', 'o', '0');'Hello W0rld'
isAlphaChecks if the input string contains only alphabetic characters.stringUtility.isAlpha('HelloWorld');true
stringUtility.isAlpha('Hello123');false
isPalindromeChecks if the input string is a palindrome (reads the same forwards and backwards).stringUtility.isPalindrome('racecar');true
stringUtility.isPalindrome('hello');false
isAnagramChecks if two input strings are anagrams of each other.stringUtility.isAnagram('listen', 'silent');true
stringUtility.isAnagram('hello', 'world');false
isPangramChecks if the input string is a pangram (contains all letters of the alphabet).stringUtility.isPangram('The quick brown fox jumps over the lazy dog');true
stringUtility.isPangram('Hello world');false

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1-alpha.1

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago