substring-methods

1.8.3 • Public • Published

Substring Methods

A collection of methods related to substrings in JavaScript

Usage

npm install substring-methods

In your code

const { firstLetter } = require('substring-methods');

console.log(firstLetter("Test string"));

Methods

firstLetter

Get the first letter of a string

const s = firstLetter("Hello"); 
// returns "H"

lastLetter

Get the last letter of a string

const s = lastLetter("Hello"); 
// returns "o"

randomLetter

Get a random letter of a string

const s = randomLetter("Hello"); 

numberOfOccurrences

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

allPossibleSubstrings

Gets all possible contiguous substrings inside a string

const s = allPossibleSubstrings("cat");
// returns [ 'c', 'a', 't', 'ca', 'at', 'cat' ]

allSubstringsOfLength

Gets all possible contiguous substrings of a given length inside a string

const s = allSubstringsOfLength("word", 2);
// returns [ 'wo', 'or', 'rd' ]

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.8.3
    1
    • latest

Version History

Package Sidebar

Install

npm i substring-methods

Weekly Downloads

1

Version

1.8.3

License

ISC

Unpacked Size

3.17 kB

Total Files

3

Last publish

Collaborators

  • softwarecradle