longest-streak
Advanced tools
Comparing version 3.0.1 to 3.1.0
/** | ||
* Get the count of the longest repeating streak of `character` in `value`. | ||
* Get the count of the longest repeating streak of `substring` in `value`. | ||
* | ||
* @param {string} value | ||
* Content to search in. | ||
* @param {string} character | ||
* Single character to look for. | ||
* @param {string} substring | ||
* Substring to look for, typically one character. | ||
* @returns {number} | ||
* Count of most frequent adjacent `character`s in `value`. | ||
* Count of most frequent adjacent `substring`s in `value`. | ||
*/ | ||
export function longestStreak(value: string, character: string): number | ||
export function longestStreak(value: string, substring: string): number |
20
index.js
/** | ||
* Get the count of the longest repeating streak of `character` in `value`. | ||
* Get the count of the longest repeating streak of `substring` in `value`. | ||
* | ||
* @param {string} value | ||
* Content to search in. | ||
* @param {string} character | ||
* Single character to look for. | ||
* @param {string} substring | ||
* Substring to look for, typically one character. | ||
* @returns {number} | ||
* Count of most frequent adjacent `character`s in `value`. | ||
* Count of most frequent adjacent `substring`s in `value`. | ||
*/ | ||
export function longestStreak(value, character) { | ||
export function longestStreak(value, substring) { | ||
const source = String(value) | ||
let index = source.indexOf(character) | ||
let index = source.indexOf(substring) | ||
let expected = index | ||
@@ -18,4 +18,4 @@ let count = 0 | ||
if (typeof character !== 'string' || character.length !== 1) { | ||
throw new Error('Expected character') | ||
if (typeof substring !== 'string') { | ||
throw new TypeError('Expected substring') | ||
} | ||
@@ -32,4 +32,4 @@ | ||
expected = index + 1 | ||
index = source.indexOf(character, expected) | ||
expected = index + substring.length | ||
index = source.indexOf(substring, expected) | ||
} | ||
@@ -36,0 +36,0 @@ |
{ | ||
"name": "longest-streak", | ||
"version": "3.0.1", | ||
"description": "Count the longest repeating streak of a character", | ||
"version": "3.1.0", | ||
"description": "Count the longest repeating streak of a substring", | ||
"license": "MIT", | ||
@@ -12,2 +12,3 @@ "keywords": [ | ||
"streak", | ||
"substring", | ||
"character" | ||
@@ -34,19 +35,17 @@ ], | ||
"devDependencies": { | ||
"@types/tape": "^4.0.0", | ||
"@types/node": "^18.0.0", | ||
"c8": "^7.0.0", | ||
"prettier": "^2.0.0", | ||
"remark-cli": "^10.0.0", | ||
"remark-cli": "^11.0.0", | ||
"remark-preset-wooorm": "^9.0.0", | ||
"rimraf": "^3.0.0", | ||
"tape": "^5.0.0", | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^4.0.0", | ||
"xo": "^0.45.0" | ||
"xo": "^0.52.0" | ||
}, | ||
"scripts": { | ||
"prepublishOnly": "npm run build && npm run format", | ||
"build": "rimraf \"test/**/*.d.ts\" \"*.d.ts\" && tsc && type-coverage", | ||
"prepack": "npm run build && npm run format", | ||
"build": "tsc --build --clean && tsc --build && type-coverage", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"test-api": "node --conditions development test.js", | ||
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api", | ||
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api", | ||
"test": "npm run build && npm run format && npm run test-coverage" | ||
@@ -53,0 +52,0 @@ }, |
@@ -8,10 +8,12 @@ # longest-streak | ||
Get the count of the longest repeating streak of `character` in `value`. | ||
Get the count of the longest repeating streak of `substring` in `value`. | ||
## Contents | ||
* [What is this?](#what-is-this) | ||
* [When should I use this?](#when-should-i-use-this) | ||
* [Install](#install) | ||
* [Use](#use) | ||
* [API](#api) | ||
* [`longestStreak(value, character)`](#longeststreakvalue-character) | ||
* [`longestStreak(value, substring)`](#longeststreakvalue-substring) | ||
* [Types](#types) | ||
@@ -24,6 +26,19 @@ * [Compatibility](#compatibility) | ||
## What is this? | ||
This is a tiny package that finds the count of the longest adjacent repeating | ||
substring. | ||
## When should I use this? | ||
This package is rather niche. | ||
I use it for serializing markdown ASTs (particularly fenced code and math). | ||
You can use [`ccount`][ccount] if you need the total count of substrings | ||
occuring in a value. | ||
## Install | ||
This package is [ESM only][esm]. | ||
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]: | ||
In Node.js (version 14.14+, 16.0+), install with [npm][]: | ||
@@ -34,13 +49,13 @@ ```sh | ||
In Deno with [Skypack][]: | ||
In Deno with [`esm.sh`][esmsh]: | ||
```js | ||
import {longestStreak} from 'https://cdn.skypack.dev/longest-streak@3?dts' | ||
import {longestStreak} from 'https://esm.sh/longest-streak@3' | ||
``` | ||
In browsers with [Skypack][]: | ||
In browsers with [`esm.sh`][esmsh]: | ||
```html | ||
<script type="module"> | ||
import {longestStreak} from 'https://cdn.skypack.dev/longest-streak@3?min' | ||
import {longestStreak} from 'https://esm.sh/longest-streak@3?bundle' | ||
</script> | ||
@@ -59,8 +74,8 @@ ``` | ||
This package exports the following identifiers: `longestStreak`. | ||
This package exports the identifier `longestStreak`. | ||
There is no default export. | ||
### `longestStreak(value, character)` | ||
### `longestStreak(value, substring)` | ||
Get the count of the longest repeating streak of `character` in `value`. | ||
Get the count of the longest repeating streak of `substring` in `value`. | ||
@@ -70,15 +85,12 @@ ###### Parameters | ||
* `value` (`string`) — content to search in | ||
* `character` (`string`) — single character to look for | ||
* `substring` (`string`) — substring to look for, typically one character | ||
###### Returns | ||
`number` — count of most frequent adjacent `character`s in `value`. | ||
Count of most frequent adjacent `substring`s in `value` (`number`). | ||
###### Throws | ||
* `Error` — when `character` is not a single character string | ||
## Types | ||
This package is fully typed with [TypeScript][]. | ||
It exports no additional types. | ||
@@ -88,3 +100,3 @@ ## Compatibility | ||
This package is at least compatible with all maintained versions of Node.js. | ||
As of now, that is Node.js 12.20+, 14.14+, and 16.0+. | ||
As of now, that is Node.js 14.14+ and 16.0+. | ||
It also works in Deno and modern browsers. | ||
@@ -99,3 +111,3 @@ | ||
* [`wooorm/ccount`](https://github.com/wooorm/ccount) | ||
— count characters | ||
— count the total number of `substring`s in `value` | ||
* [`wooorm/direction`](https://github.com/wooorm/direction) | ||
@@ -133,3 +145,3 @@ — detect directionality: left-to-right, right-to-left, or neutral | ||
[skypack]: https://www.skypack.dev | ||
[esmsh]: https://esm.sh | ||
@@ -145,1 +157,3 @@ [license]: license | ||
[contribute]: https://opensource.guide/how-to-contribute/ | ||
[ccount]: https://github.com/wooorm/ccount |
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
7661
8
151