summaryrefslogtreecommitdiff
path: root/tools/eslint/node_modules/longest-streak/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/eslint/node_modules/longest-streak/index.js')
-rw-r--r--tools/eslint/node_modules/longest-streak/index.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/tools/eslint/node_modules/longest-streak/index.js b/tools/eslint/node_modules/longest-streak/index.js
new file mode 100644
index 0000000000..719d516860
--- /dev/null
+++ b/tools/eslint/node_modules/longest-streak/index.js
@@ -0,0 +1,51 @@
+'use strict';
+
+/**
+ * Get the count of the longest repeating streak of
+ * `character` in `value`.
+ *
+ * @example
+ * longestStreak('` foo `` bar `', '`') // 2
+ *
+ * @param {string} value - Content, coerced to string.
+ * @param {string} character - Single character to look
+ * for.
+ * @return {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.
+ */
+function longestStreak(value, character) {
+ var count = 0;
+ var maximum = 0;
+ var index = -1;
+ var length;
+
+ value = String(value);
+ length = value.length;
+
+ if (typeof character !== 'string' || character.length !== 1) {
+ throw new Error('Expected character');
+ }
+
+ while (++index < length) {
+ if (value.charAt(index) === character) {
+ count++;
+
+ if (count > maximum) {
+ maximum = count;
+ }
+ } else {
+ count = 0;
+ }
+ }
+
+ return maximum;
+}
+
+/*
+ * Expose.
+ */
+
+module.exports = longestStreak;