longest-streak
Advanced tools
Comparing version 2.0.4 to 3.0.0
35
index.js
@@ -1,11 +0,14 @@ | ||
'use strict' | ||
module.exports = longestStreak | ||
// Get the count of the longest repeating streak of `character` in `value`. | ||
function longestStreak(value, character) { | ||
/** | ||
* Get the count of the longest repeating streak of `character` in `value`. | ||
* | ||
* @param {string} value Content. | ||
* @param {string} character Single character to look for | ||
* @returns {number} Count of most frequent adjacent `character`s in `value` | ||
*/ | ||
export function longestStreak(value, character) { | ||
var source = String(value) | ||
var index = source.indexOf(character) | ||
var expected = index | ||
var count = 0 | ||
var maximum = 0 | ||
var expected | ||
var index | ||
var max = 0 | ||
@@ -16,12 +19,6 @@ if (typeof character !== 'string' || character.length !== 1) { | ||
value = String(value) | ||
index = value.indexOf(character) | ||
expected = index | ||
while (index !== -1) { | ||
count++ | ||
if (index === expected) { | ||
if (count > maximum) { | ||
maximum = count | ||
if (++count > max) { | ||
max = count | ||
} | ||
@@ -33,6 +30,6 @@ } else { | ||
expected = index + 1 | ||
index = value.indexOf(character, expected) | ||
index = source.indexOf(character, expected) | ||
} | ||
return maximum | ||
return max | ||
} |
{ | ||
"name": "longest-streak", | ||
"version": "2.0.4", | ||
"version": "3.0.0", | ||
"description": "Count the longest repeating streak of a character", | ||
@@ -24,31 +24,30 @@ "license": "MIT", | ||
], | ||
"sideEffects": false, | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.d.ts", | ||
"index.js" | ||
], | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"browserify": "^16.0.0", | ||
"nyc": "^15.0.0", | ||
"prettier": "^1.0.0", | ||
"remark-cli": "^7.0.0", | ||
"remark-preset-wooorm": "^6.0.0", | ||
"tape": "^4.0.0", | ||
"tinyify": "^2.0.0", | ||
"xo": "^0.25.0" | ||
"@types/tape": "^4.0.0", | ||
"c8": "^7.0.0", | ||
"prettier": "^2.0.0", | ||
"remark-cli": "^9.0.0", | ||
"remark-preset-wooorm": "^8.0.0", | ||
"rimraf": "^3.0.0", | ||
"tape": "^5.0.0", | ||
"typescript": "^4.0.0", | ||
"xo": "^0.38.0" | ||
}, | ||
"scripts": { | ||
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", | ||
"build-bundle": "browserify . -s longestStreak -o longest-streak.js", | ||
"build-mangle": "browserify . -s longestStreak -p tinyify -o longest-streak.min.js", | ||
"build": "npm run build-bundle && npm run build-mangle", | ||
"prepublishOnly": "npm run build", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"prebuild": "rimraf \"*.d.ts\"", | ||
"build": "tsc", | ||
"test-api": "node test", | ||
"test-coverage": "nyc --reporter lcov tape test.js", | ||
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js", | ||
"test": "npm run format && npm run build && npm run test-coverage" | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
"lines": 100, | ||
"functions": 100, | ||
"branches": 100 | ||
}, | ||
"prettier": { | ||
@@ -64,6 +63,6 @@ "tabWidth": 2, | ||
"prettier": true, | ||
"esnext": false, | ||
"ignores": [ | ||
"longest-streak.js" | ||
] | ||
"rules": { | ||
"no-var": "off", | ||
"prefer-arrow-callback": "off" | ||
} | ||
}, | ||
@@ -70,0 +69,0 @@ "remarkConfig": { |
@@ -12,2 +12,5 @@ # longest-streak | ||
This package is ESM only: Node 12+ is needed to use it and it must be `import`ed | ||
instead of `require`d. | ||
[npm][]: | ||
@@ -22,3 +25,3 @@ | ||
```js | ||
var longestStreak = require('longest-streak') | ||
import {longestStreak} from 'longest-streak' | ||
@@ -30,2 +33,5 @@ longestStreak('` foo `` bar `', '`') // => 2 | ||
This package exports the following identifiers: `longestStreak`. | ||
There is no default export. | ||
### `longestStreak(value, character)` | ||
@@ -42,4 +48,3 @@ | ||
`number` — Number of characters at the place where `character` occurs in | ||
its longest streak in `value`. | ||
`number` — Count of most frequent adjacent `character`s in `value` | ||
@@ -56,5 +61,5 @@ ###### Throws | ||
[build-badge]: https://img.shields.io/travis/wooorm/longest-streak.svg | ||
[build-badge]: https://github.com/wooorm/longest-streak/workflows/main/badge.svg | ||
[build]: https://travis-ci.org/wooorm/longest-streak | ||
[build]: https://github.com/wooorm/longest-streak/actions | ||
@@ -61,0 +66,0 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/longest-streak.svg |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5729
5
37
78
Yes
9