@eslint-react/jsx 5.24.0 → 5.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +366 -69
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -5,9 +5,6 @@ import { getStaticValue } from "@typescript-eslint/utils/ast-utils";
|
|
|
5
5
|
import { P, match } from "ts-pattern";
|
|
6
6
|
|
|
7
7
|
//#region ../../.pkgs/eff/dist/index.js
|
|
8
|
-
function or(a, b) {
|
|
9
|
-
return (data) => a(data) || b(data);
|
|
10
|
-
}
|
|
11
8
|
/**
|
|
12
9
|
* Applies a `pipe` method's variadic arguments to an initial value from left
|
|
13
10
|
* to right.
|
|
@@ -40,7 +37,7 @@ function or(a, b) {
|
|
|
40
37
|
* (n) => n + 2,
|
|
41
38
|
* (n) => n * 3
|
|
42
39
|
* )
|
|
43
|
-
*
|
|
40
|
+
* result // => 21
|
|
44
41
|
* ```
|
|
45
42
|
*
|
|
46
43
|
* @category combinators
|
|
@@ -97,16 +94,6 @@ const Class = (function() {
|
|
|
97
94
|
return PipeableBase;
|
|
98
95
|
})();
|
|
99
96
|
/**
|
|
100
|
-
* Provides small helpers for defining and reusing TypeScript functions.
|
|
101
|
-
*
|
|
102
|
-
* The main helpers are `pipe` and `flow` for left-to-right composition and
|
|
103
|
-
* `dual` for APIs that support both direct and pipe-friendly call styles. The
|
|
104
|
-
* module also contains small identity, constant, tuple, type-level, and
|
|
105
|
-
* memoization helpers used across the library.
|
|
106
|
-
*
|
|
107
|
-
* @since 2.0.0
|
|
108
|
-
*/
|
|
109
|
-
/**
|
|
110
97
|
* Creates a function that can be called in data-first style or data-last
|
|
111
98
|
* (`pipe`-friendly) style.
|
|
112
99
|
*
|
|
@@ -131,8 +118,8 @@ const Class = (function() {
|
|
|
131
118
|
* (self: number, that: number) => number
|
|
132
119
|
* >(2, (self, that) => self + that)
|
|
133
120
|
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
121
|
+
* sum(2, 3) // => 5
|
|
122
|
+
* pipe(2, sum(3)) // => 5
|
|
136
123
|
* ```
|
|
137
124
|
*
|
|
138
125
|
* **Example** (Defining overloads with call signatures)
|
|
@@ -145,8 +132,8 @@ const Class = (function() {
|
|
|
145
132
|
* (self: number, that: number): number
|
|
146
133
|
* } = Function.dual(2, (self: number, that: number): number => self + that)
|
|
147
134
|
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
135
|
+
* sum(2, 3) // => 5
|
|
136
|
+
* pipe(2, sum(3)) // => 5
|
|
150
137
|
* ```
|
|
151
138
|
*
|
|
152
139
|
* **Example** (Selecting data-first or data-last style with a predicate)
|
|
@@ -162,8 +149,8 @@ const Class = (function() {
|
|
|
162
149
|
* (self, that) => self + that
|
|
163
150
|
* )
|
|
164
151
|
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
152
|
+
* sum(2, 3) // => 5
|
|
153
|
+
* pipe(2, sum(3)) // => 5
|
|
167
154
|
* ```
|
|
168
155
|
*
|
|
169
156
|
* @category combinators
|
|
@@ -208,9 +195,8 @@ const dual = function(arity, body) {
|
|
|
208
195
|
*
|
|
209
196
|
* ```ts
|
|
210
197
|
* import { identity } from "effect"
|
|
211
|
-
* import * as assert from "node:assert"
|
|
212
198
|
*
|
|
213
|
-
*
|
|
199
|
+
* identity(5) // => 5
|
|
214
200
|
* ```
|
|
215
201
|
*
|
|
216
202
|
* @category combinators
|
|
@@ -248,12 +234,11 @@ const cast = identity;
|
|
|
248
234
|
*
|
|
249
235
|
* ```ts
|
|
250
236
|
* import { Function } from "effect"
|
|
251
|
-
* import * as assert from "node:assert"
|
|
252
237
|
*
|
|
253
238
|
* const constNull = Function.constant(null)
|
|
254
239
|
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
240
|
+
* constNull() // => null
|
|
241
|
+
* constNull() // => null
|
|
257
242
|
* ```
|
|
258
243
|
*
|
|
259
244
|
* @category constructors
|
|
@@ -271,9 +256,8 @@ const constant = (value) => () => value;
|
|
|
271
256
|
*
|
|
272
257
|
* ```ts
|
|
273
258
|
* import { Function } from "effect"
|
|
274
|
-
* import * as assert from "node:assert"
|
|
275
259
|
*
|
|
276
|
-
*
|
|
260
|
+
* Function.constTrue() // => true
|
|
277
261
|
* ```
|
|
278
262
|
*
|
|
279
263
|
* @category constants
|
|
@@ -291,9 +275,8 @@ const constTrue = constant(true);
|
|
|
291
275
|
*
|
|
292
276
|
* ```ts
|
|
293
277
|
* import { Function } from "effect"
|
|
294
|
-
* import * as assert from "node:assert"
|
|
295
278
|
*
|
|
296
|
-
*
|
|
279
|
+
* Function.constFalse() // => false
|
|
297
280
|
* ```
|
|
298
281
|
*
|
|
299
282
|
* @category constants
|
|
@@ -311,9 +294,8 @@ const constFalse = constant(false);
|
|
|
311
294
|
*
|
|
312
295
|
* ```ts
|
|
313
296
|
* import { Function } from "effect"
|
|
314
|
-
* import * as assert from "node:assert"
|
|
315
297
|
*
|
|
316
|
-
*
|
|
298
|
+
* Function.constNull() // => null
|
|
317
299
|
* ```
|
|
318
300
|
*
|
|
319
301
|
* @category constants
|
|
@@ -331,9 +313,8 @@ const constNull = constant(null);
|
|
|
331
313
|
*
|
|
332
314
|
* ```ts
|
|
333
315
|
* import { Function } from "effect"
|
|
334
|
-
* import * as assert from "node:assert"
|
|
335
316
|
*
|
|
336
|
-
*
|
|
317
|
+
* Function.constUndefined() // => undefined
|
|
337
318
|
* ```
|
|
338
319
|
*
|
|
339
320
|
* @category constants
|
|
@@ -352,12 +333,11 @@ const constUndefined = constant(void 0);
|
|
|
352
333
|
*
|
|
353
334
|
* ```ts
|
|
354
335
|
* import { Function } from "effect"
|
|
355
|
-
* import * as assert from "node:assert"
|
|
356
336
|
*
|
|
357
337
|
* const increment = (n: number) => n + 1
|
|
358
338
|
* const square = (n: number) => n * n
|
|
359
339
|
*
|
|
360
|
-
*
|
|
340
|
+
* Function.compose(increment, square)(2) // => 9
|
|
361
341
|
* ```
|
|
362
342
|
*
|
|
363
343
|
* @see {@link flow} for composing a left-to-right sequence of functions
|
|
@@ -420,7 +400,6 @@ const absurd = (_) => {
|
|
|
420
400
|
* name: hole<string>()
|
|
421
401
|
* })
|
|
422
402
|
*
|
|
423
|
-
* console.log(typeof buildUser) // "function"
|
|
424
403
|
* ```
|
|
425
404
|
*
|
|
426
405
|
* @category utility types
|
|
@@ -428,56 +407,374 @@ const absurd = (_) => {
|
|
|
428
407
|
*/
|
|
429
408
|
const hole = cast(absurd);
|
|
430
409
|
/**
|
|
431
|
-
*
|
|
410
|
+
* Creates a predicate that returns `true` only if both predicates are `true`.
|
|
411
|
+
*
|
|
412
|
+
* **When to use**
|
|
413
|
+
*
|
|
414
|
+
* Use when you want to combine `Predicate`s with AND, accepting values that
|
|
415
|
+
* satisfy multiple conditions, including refinements that narrow to an
|
|
416
|
+
* intersection.
|
|
417
|
+
*
|
|
418
|
+
* **Details**
|
|
419
|
+
*
|
|
420
|
+
* Evaluation short-circuits on the first `false`. For refinements, the output
|
|
421
|
+
* type is an intersection.
|
|
422
|
+
*
|
|
423
|
+
* **Example** (Checking both conditions)
|
|
424
|
+
*
|
|
425
|
+
* ```ts
|
|
426
|
+
* import { Predicate } from "effect"
|
|
427
|
+
*
|
|
428
|
+
* const hasAAndB = Predicate.and(
|
|
429
|
+
* Predicate.hasProperty("a"),
|
|
430
|
+
* Predicate.hasProperty("b")
|
|
431
|
+
* )
|
|
432
|
+
*
|
|
433
|
+
* const input: unknown = JSON.parse(`{"a":1,"b":"ok"}`)
|
|
434
|
+
* if (hasAAndB(input)) {
|
|
435
|
+
* // input has both properties at this point
|
|
436
|
+
* const a = input.a
|
|
437
|
+
* const b = input.b
|
|
438
|
+
*
|
|
439
|
+
* const values = [a, b] // => [1, "ok"]
|
|
440
|
+
* }
|
|
441
|
+
* ```
|
|
442
|
+
*
|
|
443
|
+
* @see {@link or}
|
|
444
|
+
* @see {@link not}
|
|
445
|
+
* @category combinators
|
|
446
|
+
* @since 2.0.0
|
|
447
|
+
*/
|
|
448
|
+
const and = dual(2, (a, b) => (data) => a(data) && b(data));
|
|
449
|
+
/**
|
|
450
|
+
* Creates a predicate that returns `true` if either predicate is `true`.
|
|
451
|
+
*
|
|
452
|
+
* **When to use**
|
|
453
|
+
*
|
|
454
|
+
* Use when you want to combine `Predicate`s with OR, accepting values that
|
|
455
|
+
* satisfy at least one condition, including refinements that narrow to a union.
|
|
456
|
+
*
|
|
457
|
+
* **Details**
|
|
458
|
+
*
|
|
459
|
+
* Evaluation short-circuits on the first `true`. For refinements, the output
|
|
460
|
+
* type is a union.
|
|
432
461
|
*
|
|
433
|
-
*
|
|
462
|
+
* **Example** (Checking either condition)
|
|
434
463
|
*
|
|
435
|
-
* @param pred - The predicate to test each element with.
|
|
436
|
-
* @returns A new array without the matching prefix.
|
|
437
|
-
* @example
|
|
438
464
|
* ```ts
|
|
439
|
-
* import
|
|
440
|
-
* import { dropWhile, pipe } from "@local/eff"
|
|
465
|
+
* import { Predicate } from "effect"
|
|
441
466
|
*
|
|
442
|
-
*
|
|
443
|
-
* assert.deepStrictEqual(dropWhile([1, 2, 3, 2, 1], (n: number) => n < 3), [3, 2, 1])
|
|
467
|
+
* const isStringOrNumber = Predicate.or(Predicate.isString, Predicate.isNumber)
|
|
444
468
|
*
|
|
445
|
-
* //
|
|
446
|
-
* assert.deepStrictEqual(pipe([1, 2, 3, 2, 1], dropWhile((n: number) => n < 3)), [3, 2, 1])
|
|
469
|
+
* isStringOrNumber("a") // => true
|
|
447
470
|
* ```
|
|
448
|
-
*
|
|
471
|
+
*
|
|
472
|
+
* @see {@link and}
|
|
473
|
+
* @see {@link xor}
|
|
474
|
+
* @category combinators
|
|
475
|
+
* @since 2.0.0
|
|
449
476
|
*/
|
|
450
|
-
const
|
|
451
|
-
|
|
477
|
+
const or = dual(2, (a, b) => (data) => a(data) || b(data));
|
|
478
|
+
/**
|
|
479
|
+
* Creates a predicate that returns `true` if exactly one predicate is `true`.
|
|
480
|
+
*
|
|
481
|
+
* **When to use**
|
|
482
|
+
*
|
|
483
|
+
* Use when you want to combine two `Predicate`s with exclusive-or semantics.
|
|
484
|
+
*
|
|
485
|
+
* **Details**
|
|
486
|
+
*
|
|
487
|
+
* Returns `true` when results differ.
|
|
488
|
+
*
|
|
489
|
+
* **Example** (Checking exclusive-or conditions)
|
|
490
|
+
*
|
|
491
|
+
* ```ts
|
|
492
|
+
* import { Predicate } from "effect"
|
|
493
|
+
*
|
|
494
|
+
* const isEven = (n: number) => n % 2 === 0
|
|
495
|
+
* const isPositive = (n: number) => n > 0
|
|
496
|
+
* const either = Predicate.xor(isEven, isPositive)
|
|
497
|
+
*
|
|
498
|
+
* either(-2) // => true
|
|
499
|
+
* ```
|
|
500
|
+
*
|
|
501
|
+
* @see {@link or}
|
|
502
|
+
* @see {@link and}
|
|
503
|
+
* @category combinators
|
|
504
|
+
* @since 2.0.0
|
|
505
|
+
*/
|
|
506
|
+
const xor = dual(2, (a, b) => (data) => a(data) !== b(data));
|
|
507
|
+
/**
|
|
508
|
+
* Creates a predicate that returns `true` when both predicates agree.
|
|
509
|
+
*
|
|
510
|
+
* **When to use**
|
|
511
|
+
*
|
|
512
|
+
* Use when you want to check equivalence of two `Predicate`s.
|
|
513
|
+
*
|
|
514
|
+
* **Details**
|
|
515
|
+
*
|
|
516
|
+
* Returns `true` when both results are equal.
|
|
517
|
+
*
|
|
518
|
+
* **Example** (Defining equivalence)
|
|
519
|
+
*
|
|
520
|
+
* ```ts
|
|
521
|
+
* import { Predicate } from "effect"
|
|
522
|
+
*
|
|
523
|
+
* const isEven = (n: number) => n % 2 === 0
|
|
524
|
+
* const same = Predicate.eqv(isEven, isEven)
|
|
525
|
+
*
|
|
526
|
+
* same(3) // => true
|
|
527
|
+
* ```
|
|
528
|
+
*
|
|
529
|
+
* @see {@link xor}
|
|
530
|
+
* @category combinators
|
|
531
|
+
* @since 2.0.0
|
|
532
|
+
*/
|
|
533
|
+
const eqv = dual(2, (a, b) => (data) => a(data) === b(data));
|
|
534
|
+
/**
|
|
535
|
+
* Creates a predicate representing logical implication: if `antecedent`, then `consequent`.
|
|
536
|
+
*
|
|
537
|
+
* **When to use**
|
|
538
|
+
*
|
|
539
|
+
* Use when you need to encode logical implication between `Predicate` rules,
|
|
540
|
+
* where one rule only applies when a precondition holds.
|
|
541
|
+
*
|
|
542
|
+
* **Details**
|
|
543
|
+
*
|
|
544
|
+
* Models constraints like "if A then B" and returns `true` when the antecedent
|
|
545
|
+
* is `false`.
|
|
546
|
+
*
|
|
547
|
+
* **Example** (Checking implication)
|
|
548
|
+
*
|
|
549
|
+
* ```ts
|
|
550
|
+
* import { Predicate } from "effect"
|
|
551
|
+
*
|
|
552
|
+
* const isAdult = (age: number) => age >= 18
|
|
553
|
+
* const canVote = (age: number) => age >= 18
|
|
554
|
+
* const implies = Predicate.implies(isAdult, canVote)
|
|
555
|
+
*
|
|
556
|
+
* implies(16) // => true
|
|
557
|
+
* ```
|
|
558
|
+
*
|
|
559
|
+
* @see {@link and}
|
|
560
|
+
* @see {@link or}
|
|
561
|
+
* @category combinators
|
|
562
|
+
* @since 2.0.0
|
|
563
|
+
*/
|
|
564
|
+
const implies = dual(2, (antecedent, consequent) => (data) => !antecedent(data) || consequent(data));
|
|
565
|
+
/**
|
|
566
|
+
* Creates a predicate that returns `true` when neither predicate is `true`.
|
|
567
|
+
*
|
|
568
|
+
* **When to use**
|
|
569
|
+
*
|
|
570
|
+
* Use when you want to combine two `Predicate`s with logical NOR semantics.
|
|
571
|
+
*
|
|
572
|
+
* **Details**
|
|
573
|
+
*
|
|
574
|
+
* Returns the negation of `or`.
|
|
575
|
+
*
|
|
576
|
+
* **Example** (Checking NOR conditions)
|
|
577
|
+
*
|
|
578
|
+
* ```ts
|
|
579
|
+
* import { Predicate } from "effect"
|
|
580
|
+
*
|
|
581
|
+
* const neither = Predicate.nor(Predicate.isString, Predicate.isNumber)
|
|
582
|
+
*
|
|
583
|
+
* neither(true) // => true
|
|
584
|
+
* ```
|
|
585
|
+
*
|
|
586
|
+
* @see {@link or}
|
|
587
|
+
* @see {@link not}
|
|
588
|
+
* @category combinators
|
|
589
|
+
* @since 2.0.0
|
|
590
|
+
*/
|
|
591
|
+
const nor = dual(2, (a, b) => (data) => !a(data) && !b(data));
|
|
592
|
+
/**
|
|
593
|
+
* Creates a predicate that returns `true` unless both predicates are `true`.
|
|
594
|
+
*
|
|
595
|
+
* **When to use**
|
|
596
|
+
*
|
|
597
|
+
* Use when you want to combine two `Predicate`s with logical NAND semantics.
|
|
598
|
+
*
|
|
599
|
+
* **Details**
|
|
600
|
+
*
|
|
601
|
+
* Returns the negation of `and`.
|
|
602
|
+
*
|
|
603
|
+
* **Example** (Checking NAND conditions)
|
|
604
|
+
*
|
|
605
|
+
* ```ts
|
|
606
|
+
* import { Predicate } from "effect"
|
|
607
|
+
*
|
|
608
|
+
* const notBoth = Predicate.nand(Predicate.isString, Predicate.isNumber)
|
|
609
|
+
*
|
|
610
|
+
* notBoth("a") // => true
|
|
611
|
+
* ```
|
|
612
|
+
*
|
|
613
|
+
* @see {@link and}
|
|
614
|
+
* @see {@link not}
|
|
615
|
+
* @category combinators
|
|
616
|
+
* @since 2.0.0
|
|
617
|
+
*/
|
|
618
|
+
const nand = dual(2, (a, b) => (data) => !a(data) || !b(data));
|
|
619
|
+
/**
|
|
620
|
+
* Checks whether a value is a `function`.
|
|
621
|
+
*
|
|
622
|
+
* **When to use**
|
|
623
|
+
*
|
|
624
|
+
* Use when you need a `Predicate` guard to narrow an `unknown` value to a
|
|
625
|
+
* callable function.
|
|
626
|
+
*
|
|
627
|
+
* **Details**
|
|
628
|
+
*
|
|
629
|
+
* Uses `typeof input === "function"`.
|
|
630
|
+
*
|
|
631
|
+
* **Example** (Guarding functions)
|
|
632
|
+
*
|
|
633
|
+
* ```ts
|
|
634
|
+
* import { Predicate } from "effect"
|
|
635
|
+
*
|
|
636
|
+
* const data: unknown = () => 1
|
|
637
|
+
*
|
|
638
|
+
* if (Predicate.isFunction(data)) {
|
|
639
|
+
* data() // => 1
|
|
640
|
+
* }
|
|
641
|
+
* ```
|
|
642
|
+
*
|
|
643
|
+
* @see {@link isObjectKeyword}
|
|
644
|
+
* @category guards
|
|
645
|
+
* @since 2.0.0
|
|
646
|
+
*/
|
|
647
|
+
function isFunction(input) {
|
|
648
|
+
return typeof input === "function";
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Checks whether a value is an `object` in the JavaScript sense (objects, arrays, functions).
|
|
652
|
+
*
|
|
653
|
+
* **When to use**
|
|
654
|
+
*
|
|
655
|
+
* Use when you need a `Predicate` guard that accepts arrays and functions as
|
|
656
|
+
* well as objects.
|
|
657
|
+
*
|
|
658
|
+
* **Details**
|
|
659
|
+
*
|
|
660
|
+
* Returns `true` for arrays and functions, and `false` for `null`.
|
|
661
|
+
*
|
|
662
|
+
* **Example** (Checking object keywords)
|
|
663
|
+
*
|
|
664
|
+
* ```ts
|
|
665
|
+
* import { Predicate } from "effect"
|
|
666
|
+
*
|
|
667
|
+
* Predicate.isObjectKeyword(() => 1) // => true
|
|
668
|
+
* Predicate.isObjectKeyword(null) // => false
|
|
669
|
+
* ```
|
|
670
|
+
*
|
|
671
|
+
* @see {@link isObject}
|
|
672
|
+
* @see {@link isObjectOrArray}
|
|
673
|
+
* @category guards
|
|
674
|
+
* @since 4.0.0
|
|
675
|
+
*/
|
|
676
|
+
function isObjectKeyword(input) {
|
|
677
|
+
return typeof input === "object" && input !== null || isFunction(input);
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Checks whether a value has a given property key.
|
|
681
|
+
*
|
|
682
|
+
* **When to use**
|
|
683
|
+
*
|
|
684
|
+
* Use when you need a `Predicate` guard for property access on `unknown`
|
|
685
|
+
* values with a simple structural object check.
|
|
686
|
+
*
|
|
687
|
+
* **Details**
|
|
688
|
+
*
|
|
689
|
+
* Uses the `in` operator and `isObjectKeyword`. This does not check property
|
|
690
|
+
* value types.
|
|
691
|
+
*
|
|
692
|
+
* **Example** (Guarding object properties)
|
|
693
|
+
*
|
|
694
|
+
* ```ts
|
|
695
|
+
* import { Predicate } from "effect"
|
|
696
|
+
*
|
|
697
|
+
* const hasName = Predicate.hasProperty("name")
|
|
698
|
+
* const data: unknown = { name: "Ada" }
|
|
699
|
+
*
|
|
700
|
+
* if (hasName(data)) {
|
|
701
|
+
* data.name // => "Ada"
|
|
702
|
+
* }
|
|
703
|
+
* ```
|
|
704
|
+
*
|
|
705
|
+
* @see {@link isTagged}
|
|
706
|
+
* @see {@link isObjectKeyword}
|
|
707
|
+
* @category guards
|
|
708
|
+
* @since 2.0.0
|
|
709
|
+
*/
|
|
710
|
+
const hasProperty = dual(2, (data, property) => isObjectKeyword(data) && property in data);
|
|
711
|
+
/**
|
|
712
|
+
* Drops elements from the start while the predicate holds, returning the rest.
|
|
713
|
+
*
|
|
714
|
+
* **When to use**
|
|
715
|
+
*
|
|
716
|
+
* Use to remove a leading prefix of elements that satisfy a predicate.
|
|
717
|
+
*
|
|
718
|
+
* **Details**
|
|
719
|
+
*
|
|
720
|
+
* The predicate receives `(element, index)`.
|
|
721
|
+
*
|
|
722
|
+
* **Example** (Dropping while condition holds)
|
|
723
|
+
*
|
|
724
|
+
* ```ts
|
|
725
|
+
* import { Array } from "effect"
|
|
726
|
+
*
|
|
727
|
+
* Array.dropWhile([1, 2, 3, 4, 5], (x) => x < 4) // => [4, 5]
|
|
728
|
+
* ```
|
|
729
|
+
*
|
|
730
|
+
* @see {@link takeWhile} — keep the matching prefix instead
|
|
731
|
+
* @see {@link drop} — drop a fixed count
|
|
732
|
+
*
|
|
733
|
+
* @category getters
|
|
734
|
+
* @since 2.0.0
|
|
735
|
+
*/
|
|
736
|
+
const dropWhile = dual(2, (self, predicate) => {
|
|
737
|
+
const input = Array.isArray(self) ? self : Array.from(self);
|
|
738
|
+
const len = input.length;
|
|
452
739
|
let idx = 0;
|
|
453
|
-
while (idx < len &&
|
|
454
|
-
return
|
|
740
|
+
while (idx < len && predicate(input[idx], idx)) idx++;
|
|
741
|
+
return input.slice(idx);
|
|
455
742
|
});
|
|
456
743
|
/**
|
|
457
|
-
* Takes
|
|
744
|
+
* Takes elements from the start while the predicate holds, stopping at the
|
|
745
|
+
* first element that fails.
|
|
746
|
+
*
|
|
747
|
+
* **When to use**
|
|
458
748
|
*
|
|
459
|
-
*
|
|
749
|
+
* Use to keep the leading elements of an iterable while each element satisfies
|
|
750
|
+
* a predicate, returning the retained prefix as an array.
|
|
460
751
|
*
|
|
461
|
-
*
|
|
462
|
-
* @returns A new array containing only the matching prefix.
|
|
463
|
-
* @example
|
|
464
|
-
* ```ts
|
|
465
|
-
* import * as assert from "node:assert"
|
|
466
|
-
* import { pipe, takeWhile } from "@local/eff"
|
|
752
|
+
* **Details**
|
|
467
753
|
*
|
|
468
|
-
*
|
|
469
|
-
*
|
|
754
|
+
* Supports refinements for type narrowing. The predicate receives
|
|
755
|
+
* `(element, index)`.
|
|
470
756
|
*
|
|
471
|
-
*
|
|
472
|
-
*
|
|
757
|
+
* **Example** (Taking while condition holds)
|
|
758
|
+
*
|
|
759
|
+
* ```ts
|
|
760
|
+
* import { Array } from "effect"
|
|
761
|
+
*
|
|
762
|
+
* Array.takeWhile([1, 3, 2, 4, 1, 2], (x) => x < 4) // => [1, 3, 2]
|
|
473
763
|
* ```
|
|
474
|
-
*
|
|
764
|
+
*
|
|
765
|
+
* @see {@link take} for keeping a fixed number of leading elements
|
|
766
|
+
* @see {@link dropWhile} for removing the matching prefix and keeping the rest
|
|
767
|
+
* @see {@link span} for splitting the matching prefix from the remaining elements
|
|
768
|
+
*
|
|
769
|
+
* @category getters
|
|
770
|
+
* @since 2.0.0
|
|
475
771
|
*/
|
|
476
|
-
const takeWhile = dual(2, (
|
|
477
|
-
const
|
|
772
|
+
const takeWhile = dual(2, (self, predicate) => {
|
|
773
|
+
const input = Array.isArray(self) ? self : Array.from(self);
|
|
774
|
+
const len = input.length;
|
|
478
775
|
let idx = 0;
|
|
479
|
-
while (idx < len &&
|
|
480
|
-
return
|
|
776
|
+
while (idx < len && predicate(input[idx], idx)) idx++;
|
|
777
|
+
return input.slice(0, idx);
|
|
481
778
|
});
|
|
482
779
|
|
|
483
780
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/jsx",
|
|
3
|
-
"version": "5.24.
|
|
3
|
+
"version": "5.24.1",
|
|
4
4
|
"description": "ESLint React's TSESTree JSX utility module for static analysis of JSX patterns.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@eslint-react/ast": "5.24.
|
|
33
|
-
"@eslint-react/eslint": "5.24.
|
|
34
|
-
"@eslint-react/var": "5.24.
|
|
32
|
+
"@eslint-react/ast": "5.24.1",
|
|
33
|
+
"@eslint-react/eslint": "5.24.1",
|
|
34
|
+
"@eslint-react/var": "5.24.1",
|
|
35
35
|
"@typescript-eslint/types": "^8.71.0",
|
|
36
36
|
"@typescript-eslint/utils": "^8.71.0",
|
|
37
37
|
"ts-pattern": "^5.9.0"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@local/configs": "0.0.0",
|
|
41
41
|
"@local/eff": "0.0.0",
|
|
42
42
|
"@local/testkit": "0.0.0",
|
|
43
|
-
"eslint": "^10.
|
|
43
|
+
"eslint": "^10.12.0",
|
|
44
44
|
"tsdown": "^0.23.0",
|
|
45
45
|
"typescript": "6.0.3"
|
|
46
46
|
},
|