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.
Installation
npm:
npm install longest-streak
Usage
var longestStreak = require('longest-streak');
longestStreak('` foo `` bar `', '`')
API
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
— Number of characters at the place where character
occurs in
its longest streak in value
.
Throws
Error
— when character
is not a single character string.
License
MIT © Titus Wormer