.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / longest-streak / index.js
1 'use strict'
2
3 module.exports = longestStreak
4
5 // Get the count of the longest repeating streak of `character` in `value`.
6 function longestStreak(value, character) {
7   var count = 0
8   var maximum = 0
9   var expected
10   var index
11
12   if (typeof character !== 'string' || character.length !== 1) {
13     throw new Error('Expected character')
14   }
15
16   value = String(value)
17   index = value.indexOf(character)
18   expected = index
19
20   while (index !== -1) {
21     count++
22
23     if (index === expected) {
24       if (count > maximum) {
25         maximum = count
26       }
27     } else {
28       count = 1
29     }
30
31     expected = index + 1
32     index = value.indexOf(character, expected)
33   }
34
35   return maximum
36 }