@eslint-react/shared
Advanced tools
+52
-0
@@ -432,2 +432,54 @@ import module from "node:module"; | ||
| } | ||
| /** | ||
| * Drops the longest prefix of elements from an array that satisfy the given predicate. | ||
| * | ||
| * Supports both data-first and data-last (`pipe`-friendly) call styles. | ||
| * | ||
| * @param pred - The predicate to test each element with. | ||
| * @returns A new array without the matching prefix. | ||
| * @example | ||
| * ```ts | ||
| * import * as assert from "node:assert" | ||
| * import { dropWhile, pipe } from "@local/eff" | ||
| * | ||
| * // data-first | ||
| * assert.deepStrictEqual(dropWhile([1, 2, 3, 2, 1], (n: number) => n < 3), [3, 2, 1]) | ||
| * | ||
| * // data-last | ||
| * assert.deepStrictEqual(pipe([1, 2, 3, 2, 1], dropWhile((n: number) => n < 3)), [3, 2, 1]) | ||
| * ``` | ||
| * @category array | ||
| */ | ||
| const dropWhile = dual(2, (xs, pred) => { | ||
| const len = xs.length; | ||
| let idx = 0; | ||
| while (idx < len && pred(xs[idx])) idx++; | ||
| return xs.slice(idx); | ||
| }); | ||
| /** | ||
| * Takes the longest prefix of elements from an array that satisfy the given predicate. | ||
| * | ||
| * Supports both data-first and data-last (`pipe`-friendly) call styles. | ||
| * | ||
| * @param pred - The predicate to test each element with. | ||
| * @returns A new array containing only the matching prefix. | ||
| * @example | ||
| * ```ts | ||
| * import * as assert from "node:assert" | ||
| * import { pipe, takeWhile } from "@local/eff" | ||
| * | ||
| * // data-first | ||
| * assert.deepStrictEqual(takeWhile([1, 2, 3, 2, 1], (n: number) => n < 3), [1, 2]) | ||
| * | ||
| * // data-last | ||
| * assert.deepStrictEqual(pipe([1, 2, 3, 2, 1], takeWhile((n: number) => n < 3)), [1, 2]) | ||
| * ``` | ||
| * @category array | ||
| */ | ||
| const takeWhile = dual(2, (xs, pred) => { | ||
| const len = xs.length; | ||
| let idx = 0; | ||
| while (idx < len && pred(xs[idx])) idx++; | ||
| return xs.slice(0, idx); | ||
| }); | ||
@@ -434,0 +486,0 @@ //#endregion |
+3
-3
| { | ||
| "name": "@eslint-react/shared", | ||
| "version": "5.17.0", | ||
| "version": "5.17.1", | ||
| "description": "ESLint React's Shared constants and functions.", | ||
@@ -35,3 +35,3 @@ "homepage": "https://github.com/Rel1cx/eslint-react", | ||
| "zod": "^3.25.0 || ^4.0.0", | ||
| "@eslint-react/eslint": "5.17.0" | ||
| "@eslint-react/eslint": "5.17.1" | ||
| }, | ||
@@ -43,3 +43,3 @@ "devDependencies": { | ||
| "eslint": "^10.7.0", | ||
| "tsdown": "^0.22.7", | ||
| "tsdown": "^0.22.8", | ||
| "typescript": "6.0.3", | ||
@@ -46,0 +46,0 @@ "@local/configs": "0.0.0", |
27844
5.89%840
6.6%+ Added
- Removed
Updated