Socket
Socket
Sign inDemoInstall

longest-streak

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

longest-streak - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

68

index.js
'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.
*/
/* Expose. */
module.exports = longestStreak;
/* Get the count of the longest repeating streak of
* `character` in `value`. */
function longestStreak(value, character) {
var count = 0;
var maximum = 0;
var index = -1;
var length;
var count = 0;
var maximum = 0;
var expected = 0;
var index;
value = String(value);
length = value.length;
if (typeof character !== 'string' || character.length !== 1) {
throw new Error('Expected character');
}
if (typeof character !== 'string' || character.length !== 1) {
throw new Error('Expected character');
}
value = String(value);
index = value.indexOf(character, expected);
while (++index < length) {
if (value.charAt(index) === character) {
count++;
while (index !== -1) {
count++;
if (count > maximum) {
maximum = count;
}
} else {
count = 0;
}
if (index === expected) {
if (count > maximum) {
maximum = count;
}
} else {
count = 1;
}
return maximum;
expected = index + 1;
index = value.indexOf(character, expected);
}
return maximum;
}
/*
* Expose.
*/
module.exports = longestStreak;
{
"name": "longest-streak",
"version": "1.0.0",
"version": "2.0.0",
"description": "Count the longest repeating streak of a character",

@@ -14,39 +14,46 @@ "license": "MIT",

],
"repository": "https://github.com/wooorm/afinn-111",
"bugs": "https://github.com/wooorm/afinn-111/issues",
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)"
],
"files": [
"index.js",
"LICENSE"
"index.js"
],
"repository": {
"type": "git",
"url": "https://github.com/wooorm/longest-streak.git"
},
"author": "Titus Wormer <tituswormer@gmail.com>",
"dependencies": {},
"devDependencies": {
"browserify": "^10.0.0",
"eslint": "^0.24.0",
"browserify": "^13.0.0",
"esmangle": "^1.0.0",
"istanbul": "^0.3.0",
"jscs": "^1.0.0",
"jscs-jsdoc": "^1.0.0",
"mdast": "^0.26.0",
"mdast-github": "^0.3.1",
"mdast-lint": "^0.4.1",
"mdast-yaml-config": "^0.2.0",
"mocha": "^2.0.0"
"nyc": "^8.4.0",
"remark-cli": "^2.1.0",
"remark-preset-wooorm": "^1.0.0",
"tape": "^4.6.2",
"xo": "^0.17.0"
},
"scripts": {
"test-api": "mocha --check-leaks test.js",
"test-coveralls": "istanbul cover _mocha --report lcovonly -- --check-leaks test.js",
"test-coverage": "istanbul cover _mocha -- --check-leaks test.js",
"test-travis": "npm run test-coveralls",
"test": "npm run test-api",
"lint-api": "eslint .",
"lint-style": "jscs --reporter inline .",
"lint": "npm run lint-api && npm run lint-style",
"make": "npm run lint && npm run test-coverage",
"build-md": "mdast . LICENSE --output --quiet",
"build-md": "remark . --quiet --frail",
"build-bundle": "browserify index.js --bare -s longestStreak > longest-streak.js",
"postbuild-bundle": "esmangle longest-streak.js > longest-streak.min.js",
"build": "npm run build-md && npm run build-bundle"
"build-mangle": "esmangle longest-streak.js > longest-streak.min.js",
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
"lint": "xo",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test": "npm run build && npm run lint && npm run test-coverage"
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
},
"xo": {
"space": true,
"ignores": [
"longest-streak.js"
]
},
"remarkConfig": {
"presets": "wooorm"
}
}

@@ -1,2 +0,2 @@

# longest-streak [![Build Status](https://img.shields.io/travis/wooorm/longest-streak.svg?style=flat)](https://travis-ci.org/wooorm/longest-streak) [![Coverage Status](https://img.shields.io/coveralls/wooorm/longest-streak.svg?style=flat)](https://coveralls.io/r/wooorm/longest-streak?branch=master)
# longest-streak [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov]

@@ -7,3 +7,3 @@ Count the longest repeating streak of a character.

[npm](https://docs.npmjs.com/cli/install):
[npm][]:

@@ -14,19 +14,8 @@ ```bash

**longest-streak** is also available for [bower](http://bower.io/#install-packages),
[component](https://github.com/componentjs/component), [duo](http://duojs.org/#getting-started),
and for AMD, CommonJS, and globals ([uncompressed](longest-streak.js) and
[compressed](longest-streak.min.js)).
## Usage
Dependencies.
```javascript
```js
var longestStreak = require('longest-streak');
```
Process:
```javascript
longestStreak('` foo `` bar `', '`') // 2
longestStreak('` foo `` bar `', '`') //=> 2
```

@@ -36,7 +25,7 @@

### longestStreak(value, character)
### `longestStreak(value, character)`
Get the count of the longest repeating streak of `character` in `value`.
Parameters:
###### Parameters

@@ -46,7 +35,9 @@ * `value` (`string`) — Content, coerced to string.

Returns: `number` — Number of characters at the place where `character`
occurs in its longest streak in `value`.
###### Returns
Throws:
`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.

@@ -56,2 +47,18 @@

[MIT](LICENSE) @ [Titus Wormer](http://wooorm.com)
[MIT][license] © [Titus Wormer][author]
<!-- Definitions -->
[travis-badge]: https://img.shields.io/travis/wooorm/longest-streak.svg
[travis]: https://travis-ci.org/wooorm/longest-streak
[codecov-badge]: https://img.shields.io/codecov/c/github/wooorm/longest-streak.svg
[codecov]: https://codecov.io/github/wooorm/longest-streak
[npm]: https://docs.npmjs.com/cli/install
[license]: LICENSE
[author]: http://wooorm.com
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc