longest-streak

Count the longest repeating streak of a character

Usage no npm install needed!

<script type="module">
  import longestStreak from 'https://cdn.skypack.dev/longest-streak';
</script>

README

longest-streak

Build Coverage Downloads Size

Get the count of the longest repeating streak of character in value.

Contents

Install

This package is ESM only. In Node.js (version 12.20+, 14.14+, or 16.0+), install with npm:

npm install longest-streak

In Deno with Skypack:

import {longestStreak} from 'https://cdn.skypack.dev/longest-streak@3?dts'

In browsers with Skypack:

<script type="module">
  import {longestStreak} from 'https://cdn.skypack.dev/longest-streak@3?min'
</script>

Use

import {longestStreak} from 'longest-streak'

longestStreak('` foo `` bar `', '`') // => 2

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 to search in
  • character (string) — single character to look for
Returns

number — count of most frequent adjacent characters in value.

Throws
  • Error — when character is not a single character string

Types

This package is fully typed with TypeScript.

Compatibility

This package is at least compatible with all maintained versions of Node.js. As of now, that is Node.js 12.20+, 14.14+, and 16.0+. It also works in Deno and modern browsers.

Security

This package is safe.

Related

Contribute

Yes please! See How to Contribute to Open Source.

License

MIT © Titus Wormer