What is longest-streak?
The 'longest-streak' npm package is designed to calculate the longest streak of consecutive characters in a given string. It is useful for analyzing text patterns, such as finding the most repeated character in a row in a text.
What are longest-streak's main functionalities?
Calculate longest consecutive character streak
This feature allows you to determine the length of the longest sequence of a repeated character in a string. In the provided code sample, the function returns '10' because the character 'e' repeats consecutively ten times, which is the longest streak in the string.
const longestStreak = require('longest-streak');
console.log(longestStreak('aaaabbaaccdeeeeeeeeee')); // Output: 10
0
longest-streak
Count the longest repeating streak of a character.
Install
This package is ESM only: Node 12+ is needed to use it and it must be import
ed
instead of require
d.
npm:
npm install longest-streak
Use
import {longestStreak} from 'longest-streak'
longestStreak('` foo `` bar `', '`')
API
This package exports the following identifiers: longestStreak
.
There is no default export.
longestStreak(value, character)
Get the count of the longest repeating streak of character
in value
.
Parameters
value
(string
) — Content, coerced to string.character
(string
) — Single character to look for.
Returns
number
— Count of most frequent adjacent character
s in value
Throws
Error
— when character
is not a single character string.
License
MIT © Titus Wormer