A collection of methods related to substrings in JavaScript
npm install substring-methods
In your code
const { firstLetter } = require('substring-methods');
console.log(firstLetter("Test string"));
Get the first letter of a string
const s = firstLetter("Hello");
// returns "H"
Get the last letter of a string
const s = lastLetter("Hello");
// returns "o"
Get a random letter of a string
const s = randomLetter("Hello");
Count the number of times a substring occurs inside a string
const s = numberOfOccurrences("The heater he ordered for them was hefty", "he");
// returns 5
Gets all possible contiguous substrings inside a string
const s = allPossibleSubstrings("cat");
// returns [ 'c', 'a', 't', 'ca', 'at', 'cat' ]
Gets all possible contiguous substrings of a given length inside a string
const s = allSubstringsOfLength("word", 2);
// returns [ 'wo', 'or', 'rd' ]