Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jul 12, 2015
0 parents commit 58968eb
Show file tree
Hide file tree
Showing 18 changed files with 538 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{json,mdastrc,eslintrc,sh}]
indent_size = 2

[*.md]
trim_trailing_whitespace = false
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build/
components/
coverage/
build.js
longest-streak.js
longest-streak.min.js
9 changes: 9 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"env": {
"node": true,
"browser": true
},
"rules": {
"quotes": [2, "single"]
}
}
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
*.log
build/
bower_components/
components/
coverage/
node_modules/
build.js
151 changes: 151 additions & 0 deletions .jscs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
{
"excludeFiles": [
"build/",
"components/",
"coverage/",
"node_modules/",
"build.js",
"lib/expression.js",
"longest-streak.js",
"longest-streak.min.js"
],
"plugins": [
"jscs-jsdoc"
],
"jsDoc": {
"checkAnnotations": "jsdoc3",
"checkParamNames": true,
"requireParamTypes": true,
"checkRedundantParams": true,
"checkReturnTypes": true,
"checkRedundantReturns": true,
"requireReturnTypes": true,
"checkTypes": "strictNativeCase",
"checkRedundantAccess": true,
"enforceExistence": true,
"requireHyphenBeforeDescription": true
},
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch"
],
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"return",
"try",
"catch"
],
"requireSpaceBeforeBlockStatements": true,
"requireParenthesesAroundIIFE": true,
"requireSpacesInConditionalExpression": true,
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
},
"requireSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
},
"requireBlocksOnNewline": true,
"disallowSpacesInsideObjectBrackets": true,
"disallowSpacesInsideArrayBrackets": true,
"disallowSpacesInsideParentheses": true,
"requireSpacesInsideObjectBrackets": "all",
"disallowDanglingUnderscores": true,
"disallowSpaceAfterObjectKeys": true,
"requireCommaBeforeLineBreak": true,
"requireOperatorBeforeLineBreak": [
"?",
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
"!==",
">",
">=",
"<",
"<="
],
"requireSpaceBeforeBinaryOperators": [
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
"!=="
],
"requireSpaceAfterBinaryOperators": [
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
"!=="
],
"disallowSpaceAfterPrefixUnaryOperators": [
"++",
"--",
"+",
"-",
"~",
"!"
],
"disallowSpaceBeforePostfixUnaryOperators": [
"++",
"--"
],
"disallowImplicitTypeConversion": [
"numeric",
"boolean",
"binary",
"string"
],
"requireCamelCaseOrUpperCaseIdentifiers": true,
"disallowKeywords": [
"with"
],
"disallowMultipleLineStrings": true,
"disallowMultipleLineBreaks": true,
"validateLineBreaks": "LF",
"validateQuoteMarks": "'",
"disallowMixedSpacesAndTabs": true,
"disallowTrailingWhitespace": true,
"disallowTrailingComma": true,
"disallowKeywordsOnNewLine": [
"else"
],
"requireLineFeedAtFileEnd": true,
"maximumLineLength": 78,
"requireCapitalizedConstructors": true,
"safeContextKeyword": "self",
"requireDotNotation": true,
"disallowYodaConditions": true,
"validateJSDoc": {
"checkParamNames": true,
"checkRedundantParams": true,
"requireParamTypes": true
}
}
1 change: 1 addition & 0 deletions .mdastignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
components
10 changes: 10 additions & 0 deletions .mdastrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"plugins": [
"lint",
"github",
"yaml-config"
],
"settings": {
"bullet": "*"
}
}
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: node_js
script: npm run-script test-travis
node_js:
- '0.10'
- '0.11'
- '0.12'
- iojs
sudo: false
after_script: npm install coveralls@2.11.2 && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(The MIT License)

Copyright (c) 2015 Titus Wormer <mailto:tituswormer@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 changes: 36 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "longest-streak",
"main": "longest-streak.js",
"description": "Count the longest repeating streak of a character",
"license": "MIT",
"keywords": [
"count",
"length",
"longest",
"repeating",
"streak",
"character"
],
"repository": {
"type": "git",
"url": "https://github.com/wooorm/longest-streak.git"
},
"authors": [
"Titus Wormer <tituswormer@gmail.com>"
],
"ignore": [
".*",
"*.log",
"*.md",
"build/",
"components/",
"coverage/",
"node_modules/",
"build.js",
"example.js",
"index.js",
"test.js",
"component.json",
"package.json"
]
}
18 changes: 18 additions & 0 deletions component.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "longest-streak",
"version": "0.0.0",
"description": "Count the longest repeating streak of a character",
"license": "MIT",
"keywords": [
"count",
"length",
"longest",
"repeating",
"streak",
"character"
],
"repository": "wooorm/longest-streak",
"scripts": [
"index.js"
]
}
6 changes: 6 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
mdast:
setext: true
---

<!--lint disable no-multiple-toplevel-headings -->
51 changes: 51 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -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;
Loading

0 comments on commit 58968eb

Please sign in to comment.