eslint-plugin-react-web-api 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.
Files changed (2) hide show
  1. package/dist/index.js +401 -84
  2. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -27,7 +27,7 @@ var __exportAll = (all, no_symbols) => {
27
27
  //#endregion
28
28
  //#region package.json
29
29
  var name$1 = "eslint-plugin-react-web-api";
30
- var version = "5.24.0";
30
+ var version = "5.24.1";
31
31
 
32
32
  //#endregion
33
33
  //#region src/utils/create-rule.ts
@@ -38,22 +38,6 @@ const createRule = ESLintUtils.RuleCreator(getDocsUrl);
38
38
 
39
39
  //#endregion
40
40
  //#region ../../.pkgs/eff/dist/index.js
41
- function and(a, b) {
42
- return (data) => a(data) && b(data);
43
- }
44
- function or(a, b) {
45
- return (data) => a(data) || b(data);
46
- }
47
- /**
48
- * A function that checks if the passed parameter is a string and narrows its type accordingly.
49
- *
50
- * @param data - The variable to check.
51
- * @returns True if the passed input is a string, false otherwise.
52
- * @category guards
53
- */
54
- function isString(data) {
55
- return typeof data === "string";
56
- }
57
41
  /**
58
42
  * Applies a `pipe` method's variadic arguments to an initial value from left
59
43
  * to right.
@@ -86,7 +70,7 @@ function isString(data) {
86
70
  * (n) => n + 2,
87
71
  * (n) => n * 3
88
72
  * )
89
- * console.log(result) // 21
73
+ * result // => 21
90
74
  * ```
91
75
  *
92
76
  * @category combinators
@@ -143,16 +127,6 @@ const Class = (function() {
143
127
  return PipeableBase;
144
128
  })();
145
129
  /**
146
- * Provides small helpers for defining and reusing TypeScript functions.
147
- *
148
- * The main helpers are `pipe` and `flow` for left-to-right composition and
149
- * `dual` for APIs that support both direct and pipe-friendly call styles. The
150
- * module also contains small identity, constant, tuple, type-level, and
151
- * memoization helpers used across the library.
152
- *
153
- * @since 2.0.0
154
- */
155
- /**
156
130
  * Creates a function that can be called in data-first style or data-last
157
131
  * (`pipe`-friendly) style.
158
132
  *
@@ -177,8 +151,8 @@ const Class = (function() {
177
151
  * (self: number, that: number) => number
178
152
  * >(2, (self, that) => self + that)
179
153
  *
180
- * console.log(sum(2, 3)) // 5
181
- * console.log(pipe(2, sum(3))) // 5
154
+ * sum(2, 3) // => 5
155
+ * pipe(2, sum(3)) // => 5
182
156
  * ```
183
157
  *
184
158
  * **Example** (Defining overloads with call signatures)
@@ -191,8 +165,8 @@ const Class = (function() {
191
165
  * (self: number, that: number): number
192
166
  * } = Function.dual(2, (self: number, that: number): number => self + that)
193
167
  *
194
- * console.log(sum(2, 3)) // 5
195
- * console.log(pipe(2, sum(3))) // 5
168
+ * sum(2, 3) // => 5
169
+ * pipe(2, sum(3)) // => 5
196
170
  * ```
197
171
  *
198
172
  * **Example** (Selecting data-first or data-last style with a predicate)
@@ -208,8 +182,8 @@ const Class = (function() {
208
182
  * (self, that) => self + that
209
183
  * )
210
184
  *
211
- * console.log(sum(2, 3)) // 5
212
- * console.log(pipe(2, sum(3))) // 5
185
+ * sum(2, 3) // => 5
186
+ * pipe(2, sum(3)) // => 5
213
187
  * ```
214
188
  *
215
189
  * @category combinators
@@ -254,9 +228,8 @@ const dual = function(arity, body) {
254
228
  *
255
229
  * ```ts
256
230
  * import { identity } from "effect"
257
- * import * as assert from "node:assert"
258
231
  *
259
- * assert.deepStrictEqual(identity(5), 5)
232
+ * identity(5) // => 5
260
233
  * ```
261
234
  *
262
235
  * @category combinators
@@ -294,12 +267,11 @@ const cast = identity;
294
267
  *
295
268
  * ```ts
296
269
  * import { Function } from "effect"
297
- * import * as assert from "node:assert"
298
270
  *
299
271
  * const constNull = Function.constant(null)
300
272
  *
301
- * assert.deepStrictEqual(constNull(), null)
302
- * assert.deepStrictEqual(constNull(), null)
273
+ * constNull() // => null
274
+ * constNull() // => null
303
275
  * ```
304
276
  *
305
277
  * @category constructors
@@ -317,9 +289,8 @@ const constant = (value) => () => value;
317
289
  *
318
290
  * ```ts
319
291
  * import { Function } from "effect"
320
- * import * as assert from "node:assert"
321
292
  *
322
- * assert.deepStrictEqual(Function.constTrue(), true)
293
+ * Function.constTrue() // => true
323
294
  * ```
324
295
  *
325
296
  * @category constants
@@ -337,9 +308,8 @@ const constTrue = constant(true);
337
308
  *
338
309
  * ```ts
339
310
  * import { Function } from "effect"
340
- * import * as assert from "node:assert"
341
311
  *
342
- * assert.deepStrictEqual(Function.constFalse(), false)
312
+ * Function.constFalse() // => false
343
313
  * ```
344
314
  *
345
315
  * @category constants
@@ -357,9 +327,8 @@ const constFalse = constant(false);
357
327
  *
358
328
  * ```ts
359
329
  * import { Function } from "effect"
360
- * import * as assert from "node:assert"
361
330
  *
362
- * assert.deepStrictEqual(Function.constNull(), null)
331
+ * Function.constNull() // => null
363
332
  * ```
364
333
  *
365
334
  * @category constants
@@ -377,9 +346,8 @@ const constNull = constant(null);
377
346
  *
378
347
  * ```ts
379
348
  * import { Function } from "effect"
380
- * import * as assert from "node:assert"
381
349
  *
382
- * assert.deepStrictEqual(Function.constUndefined(), undefined)
350
+ * Function.constUndefined() // => undefined
383
351
  * ```
384
352
  *
385
353
  * @category constants
@@ -398,12 +366,11 @@ const constUndefined = constant(void 0);
398
366
  *
399
367
  * ```ts
400
368
  * import { Function } from "effect"
401
- * import * as assert from "node:assert"
402
369
  *
403
370
  * const increment = (n: number) => n + 1
404
371
  * const square = (n: number) => n * n
405
372
  *
406
- * assert.strictEqual(Function.compose(increment, square)(2), 9)
373
+ * Function.compose(increment, square)(2) // => 9
407
374
  * ```
408
375
  *
409
376
  * @see {@link flow} for composing a left-to-right sequence of functions
@@ -466,13 +433,347 @@ const absurd = (_) => {
466
433
  * name: hole<string>()
467
434
  * })
468
435
  *
469
- * console.log(typeof buildUser) // "function"
470
436
  * ```
471
437
  *
472
438
  * @category utility types
473
439
  * @since 2.0.0
474
440
  */
475
441
  const hole = cast(absurd);
442
+ /**
443
+ * Creates a predicate that returns `true` only if both predicates are `true`.
444
+ *
445
+ * **When to use**
446
+ *
447
+ * Use when you want to combine `Predicate`s with AND, accepting values that
448
+ * satisfy multiple conditions, including refinements that narrow to an
449
+ * intersection.
450
+ *
451
+ * **Details**
452
+ *
453
+ * Evaluation short-circuits on the first `false`. For refinements, the output
454
+ * type is an intersection.
455
+ *
456
+ * **Example** (Checking both conditions)
457
+ *
458
+ * ```ts
459
+ * import { Predicate } from "effect"
460
+ *
461
+ * const hasAAndB = Predicate.and(
462
+ * Predicate.hasProperty("a"),
463
+ * Predicate.hasProperty("b")
464
+ * )
465
+ *
466
+ * const input: unknown = JSON.parse(`{"a":1,"b":"ok"}`)
467
+ * if (hasAAndB(input)) {
468
+ * // input has both properties at this point
469
+ * const a = input.a
470
+ * const b = input.b
471
+ *
472
+ * const values = [a, b] // => [1, "ok"]
473
+ * }
474
+ * ```
475
+ *
476
+ * @see {@link or}
477
+ * @see {@link not}
478
+ * @category combinators
479
+ * @since 2.0.0
480
+ */
481
+ const and = dual(2, (a, b) => (data) => a(data) && b(data));
482
+ /**
483
+ * Creates a predicate that returns `true` if either predicate is `true`.
484
+ *
485
+ * **When to use**
486
+ *
487
+ * Use when you want to combine `Predicate`s with OR, accepting values that
488
+ * satisfy at least one condition, including refinements that narrow to a union.
489
+ *
490
+ * **Details**
491
+ *
492
+ * Evaluation short-circuits on the first `true`. For refinements, the output
493
+ * type is a union.
494
+ *
495
+ * **Example** (Checking either condition)
496
+ *
497
+ * ```ts
498
+ * import { Predicate } from "effect"
499
+ *
500
+ * const isStringOrNumber = Predicate.or(Predicate.isString, Predicate.isNumber)
501
+ *
502
+ * isStringOrNumber("a") // => true
503
+ * ```
504
+ *
505
+ * @see {@link and}
506
+ * @see {@link xor}
507
+ * @category combinators
508
+ * @since 2.0.0
509
+ */
510
+ const or = dual(2, (a, b) => (data) => a(data) || b(data));
511
+ /**
512
+ * Creates a predicate that returns `true` if exactly one predicate is `true`.
513
+ *
514
+ * **When to use**
515
+ *
516
+ * Use when you want to combine two `Predicate`s with exclusive-or semantics.
517
+ *
518
+ * **Details**
519
+ *
520
+ * Returns `true` when results differ.
521
+ *
522
+ * **Example** (Checking exclusive-or conditions)
523
+ *
524
+ * ```ts
525
+ * import { Predicate } from "effect"
526
+ *
527
+ * const isEven = (n: number) => n % 2 === 0
528
+ * const isPositive = (n: number) => n > 0
529
+ * const either = Predicate.xor(isEven, isPositive)
530
+ *
531
+ * either(-2) // => true
532
+ * ```
533
+ *
534
+ * @see {@link or}
535
+ * @see {@link and}
536
+ * @category combinators
537
+ * @since 2.0.0
538
+ */
539
+ const xor = dual(2, (a, b) => (data) => a(data) !== b(data));
540
+ /**
541
+ * Creates a predicate that returns `true` when both predicates agree.
542
+ *
543
+ * **When to use**
544
+ *
545
+ * Use when you want to check equivalence of two `Predicate`s.
546
+ *
547
+ * **Details**
548
+ *
549
+ * Returns `true` when both results are equal.
550
+ *
551
+ * **Example** (Defining equivalence)
552
+ *
553
+ * ```ts
554
+ * import { Predicate } from "effect"
555
+ *
556
+ * const isEven = (n: number) => n % 2 === 0
557
+ * const same = Predicate.eqv(isEven, isEven)
558
+ *
559
+ * same(3) // => true
560
+ * ```
561
+ *
562
+ * @see {@link xor}
563
+ * @category combinators
564
+ * @since 2.0.0
565
+ */
566
+ const eqv = dual(2, (a, b) => (data) => a(data) === b(data));
567
+ /**
568
+ * Creates a predicate representing logical implication: if `antecedent`, then `consequent`.
569
+ *
570
+ * **When to use**
571
+ *
572
+ * Use when you need to encode logical implication between `Predicate` rules,
573
+ * where one rule only applies when a precondition holds.
574
+ *
575
+ * **Details**
576
+ *
577
+ * Models constraints like "if A then B" and returns `true` when the antecedent
578
+ * is `false`.
579
+ *
580
+ * **Example** (Checking implication)
581
+ *
582
+ * ```ts
583
+ * import { Predicate } from "effect"
584
+ *
585
+ * const isAdult = (age: number) => age >= 18
586
+ * const canVote = (age: number) => age >= 18
587
+ * const implies = Predicate.implies(isAdult, canVote)
588
+ *
589
+ * implies(16) // => true
590
+ * ```
591
+ *
592
+ * @see {@link and}
593
+ * @see {@link or}
594
+ * @category combinators
595
+ * @since 2.0.0
596
+ */
597
+ const implies = dual(2, (antecedent, consequent) => (data) => !antecedent(data) || consequent(data));
598
+ /**
599
+ * Creates a predicate that returns `true` when neither predicate is `true`.
600
+ *
601
+ * **When to use**
602
+ *
603
+ * Use when you want to combine two `Predicate`s with logical NOR semantics.
604
+ *
605
+ * **Details**
606
+ *
607
+ * Returns the negation of `or`.
608
+ *
609
+ * **Example** (Checking NOR conditions)
610
+ *
611
+ * ```ts
612
+ * import { Predicate } from "effect"
613
+ *
614
+ * const neither = Predicate.nor(Predicate.isString, Predicate.isNumber)
615
+ *
616
+ * neither(true) // => true
617
+ * ```
618
+ *
619
+ * @see {@link or}
620
+ * @see {@link not}
621
+ * @category combinators
622
+ * @since 2.0.0
623
+ */
624
+ const nor = dual(2, (a, b) => (data) => !a(data) && !b(data));
625
+ /**
626
+ * Creates a predicate that returns `true` unless both predicates are `true`.
627
+ *
628
+ * **When to use**
629
+ *
630
+ * Use when you want to combine two `Predicate`s with logical NAND semantics.
631
+ *
632
+ * **Details**
633
+ *
634
+ * Returns the negation of `and`.
635
+ *
636
+ * **Example** (Checking NAND conditions)
637
+ *
638
+ * ```ts
639
+ * import { Predicate } from "effect"
640
+ *
641
+ * const notBoth = Predicate.nand(Predicate.isString, Predicate.isNumber)
642
+ *
643
+ * notBoth("a") // => true
644
+ * ```
645
+ *
646
+ * @see {@link and}
647
+ * @see {@link not}
648
+ * @category combinators
649
+ * @since 2.0.0
650
+ */
651
+ const nand = dual(2, (a, b) => (data) => !a(data) || !b(data));
652
+ /**
653
+ * Checks whether a value is a `string`.
654
+ *
655
+ * **When to use**
656
+ *
657
+ * Use when you need a `Predicate` guard to narrow an `unknown` value to a
658
+ * string.
659
+ *
660
+ * **Details**
661
+ *
662
+ * Uses `typeof input === "string"`.
663
+ *
664
+ * **Example** (Guarding strings)
665
+ *
666
+ * ```ts
667
+ * import { Predicate } from "effect"
668
+ *
669
+ * const data: unknown = "hi"
670
+ *
671
+ * if (Predicate.isString(data)) {
672
+ * data.toUpperCase() // => "HI"
673
+ * }
674
+ * ```
675
+ *
676
+ * @see {@link isNumber}
677
+ * @see {@link isBoolean}
678
+ * @see {@link Refinement}
679
+ * @category guards
680
+ * @since 2.0.0
681
+ */
682
+ function isString(input) {
683
+ return typeof input === "string";
684
+ }
685
+ /**
686
+ * Checks whether a value is a `function`.
687
+ *
688
+ * **When to use**
689
+ *
690
+ * Use when you need a `Predicate` guard to narrow an `unknown` value to a
691
+ * callable function.
692
+ *
693
+ * **Details**
694
+ *
695
+ * Uses `typeof input === "function"`.
696
+ *
697
+ * **Example** (Guarding functions)
698
+ *
699
+ * ```ts
700
+ * import { Predicate } from "effect"
701
+ *
702
+ * const data: unknown = () => 1
703
+ *
704
+ * if (Predicate.isFunction(data)) {
705
+ * data() // => 1
706
+ * }
707
+ * ```
708
+ *
709
+ * @see {@link isObjectKeyword}
710
+ * @category guards
711
+ * @since 2.0.0
712
+ */
713
+ function isFunction(input) {
714
+ return typeof input === "function";
715
+ }
716
+ /**
717
+ * Checks whether a value is an `object` in the JavaScript sense (objects, arrays, functions).
718
+ *
719
+ * **When to use**
720
+ *
721
+ * Use when you need a `Predicate` guard that accepts arrays and functions as
722
+ * well as objects.
723
+ *
724
+ * **Details**
725
+ *
726
+ * Returns `true` for arrays and functions, and `false` for `null`.
727
+ *
728
+ * **Example** (Checking object keywords)
729
+ *
730
+ * ```ts
731
+ * import { Predicate } from "effect"
732
+ *
733
+ * Predicate.isObjectKeyword(() => 1) // => true
734
+ * Predicate.isObjectKeyword(null) // => false
735
+ * ```
736
+ *
737
+ * @see {@link isObject}
738
+ * @see {@link isObjectOrArray}
739
+ * @category guards
740
+ * @since 4.0.0
741
+ */
742
+ function isObjectKeyword(input) {
743
+ return typeof input === "object" && input !== null || isFunction(input);
744
+ }
745
+ /**
746
+ * Checks whether a value has a given property key.
747
+ *
748
+ * **When to use**
749
+ *
750
+ * Use when you need a `Predicate` guard for property access on `unknown`
751
+ * values with a simple structural object check.
752
+ *
753
+ * **Details**
754
+ *
755
+ * Uses the `in` operator and `isObjectKeyword`. This does not check property
756
+ * value types.
757
+ *
758
+ * **Example** (Guarding object properties)
759
+ *
760
+ * ```ts
761
+ * import { Predicate } from "effect"
762
+ *
763
+ * const hasName = Predicate.hasProperty("name")
764
+ * const data: unknown = { name: "Ada" }
765
+ *
766
+ * if (hasName(data)) {
767
+ * data.name // => "Ada"
768
+ * }
769
+ * ```
770
+ *
771
+ * @see {@link isTagged}
772
+ * @see {@link isObjectKeyword}
773
+ * @category guards
774
+ * @since 2.0.0
775
+ */
776
+ const hasProperty = dual(2, (data, property) => isObjectKeyword(data) && property in data);
476
777
  function getOrInsertComputed(map, key, callback) {
477
778
  if (map.has(key)) return map.get(key);
478
779
  const value = callback(key);
@@ -480,56 +781,72 @@ function getOrInsertComputed(map, key, callback) {
480
781
  return value;
481
782
  }
482
783
  /**
483
- * Drops the longest prefix of elements from an array that satisfy the given predicate.
784
+ * Drops elements from the start while the predicate holds, returning the rest.
785
+ *
786
+ * **When to use**
484
787
  *
485
- * Supports both data-first and data-last (`pipe`-friendly) call styles.
788
+ * Use to remove a leading prefix of elements that satisfy a predicate.
486
789
  *
487
- * @param pred - The predicate to test each element with.
488
- * @returns A new array without the matching prefix.
489
- * @example
490
- * ```ts
491
- * import * as assert from "node:assert"
492
- * import { dropWhile, pipe } from "@local/eff"
790
+ * **Details**
791
+ *
792
+ * The predicate receives `(element, index)`.
793
+ *
794
+ * **Example** (Dropping while condition holds)
493
795
  *
494
- * // data-first
495
- * assert.deepStrictEqual(dropWhile([1, 2, 3, 2, 1], (n: number) => n < 3), [3, 2, 1])
796
+ * ```ts
797
+ * import { Array } from "effect"
496
798
  *
497
- * // data-last
498
- * assert.deepStrictEqual(pipe([1, 2, 3, 2, 1], dropWhile((n: number) => n < 3)), [3, 2, 1])
799
+ * Array.dropWhile([1, 2, 3, 4, 5], (x) => x < 4) // => [4, 5]
499
800
  * ```
500
- * @category array
801
+ *
802
+ * @see {@link takeWhile} — keep the matching prefix instead
803
+ * @see {@link drop} — drop a fixed count
804
+ *
805
+ * @category getters
806
+ * @since 2.0.0
501
807
  */
502
- const dropWhile = dual(2, (xs, pred) => {
503
- const len = xs.length;
808
+ const dropWhile = dual(2, (self, predicate) => {
809
+ const input = Array.isArray(self) ? self : Array.from(self);
810
+ const len = input.length;
504
811
  let idx = 0;
505
- while (idx < len && pred(xs[idx])) idx++;
506
- return xs.slice(idx);
812
+ while (idx < len && predicate(input[idx], idx)) idx++;
813
+ return input.slice(idx);
507
814
  });
508
815
  /**
509
- * Takes the longest prefix of elements from an array that satisfy the given predicate.
816
+ * Takes elements from the start while the predicate holds, stopping at the
817
+ * first element that fails.
510
818
  *
511
- * Supports both data-first and data-last (`pipe`-friendly) call styles.
819
+ * **When to use**
512
820
  *
513
- * @param pred - The predicate to test each element with.
514
- * @returns A new array containing only the matching prefix.
515
- * @example
516
- * ```ts
517
- * import * as assert from "node:assert"
518
- * import { pipe, takeWhile } from "@local/eff"
821
+ * Use to keep the leading elements of an iterable while each element satisfies
822
+ * a predicate, returning the retained prefix as an array.
823
+ *
824
+ * **Details**
825
+ *
826
+ * Supports refinements for type narrowing. The predicate receives
827
+ * `(element, index)`.
519
828
  *
520
- * // data-first
521
- * assert.deepStrictEqual(takeWhile([1, 2, 3, 2, 1], (n: number) => n < 3), [1, 2])
829
+ * **Example** (Taking while condition holds)
830
+ *
831
+ * ```ts
832
+ * import { Array } from "effect"
522
833
  *
523
- * // data-last
524
- * assert.deepStrictEqual(pipe([1, 2, 3, 2, 1], takeWhile((n: number) => n < 3)), [1, 2])
834
+ * Array.takeWhile([1, 3, 2, 4, 1, 2], (x) => x < 4) // => [1, 3, 2]
525
835
  * ```
526
- * @category array
836
+ *
837
+ * @see {@link take} for keeping a fixed number of leading elements
838
+ * @see {@link dropWhile} for removing the matching prefix and keeping the rest
839
+ * @see {@link span} for splitting the matching prefix from the remaining elements
840
+ *
841
+ * @category getters
842
+ * @since 2.0.0
527
843
  */
528
- const takeWhile = dual(2, (xs, pred) => {
529
- const len = xs.length;
844
+ const takeWhile = dual(2, (self, predicate) => {
845
+ const input = Array.isArray(self) ? self : Array.from(self);
846
+ const len = input.length;
530
847
  let idx = 0;
531
- while (idx < len && pred(xs[idx])) idx++;
532
- return xs.slice(0, idx);
848
+ while (idx < len && predicate(input[idx], idx)) idx++;
849
+ return input.slice(0, idx);
533
850
  });
534
851
 
535
852
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-web-api",
3
- "version": "5.24.0",
3
+ "version": "5.24.1",
4
4
  "description": "ESLint React's ESLint plugin for interacting with Web APIs",
5
5
  "keywords": [
6
6
  "react",
@@ -37,11 +37,11 @@
37
37
  "dist"
38
38
  ],
39
39
  "dependencies": {
40
- "@eslint-react/ast": "5.24.0",
41
- "@eslint-react/core": "5.24.0",
42
- "@eslint-react/eslint": "5.24.0",
43
- "@eslint-react/shared": "5.24.0",
44
- "@eslint-react/var": "5.24.0",
40
+ "@eslint-react/ast": "5.24.1",
41
+ "@eslint-react/core": "5.24.1",
42
+ "@eslint-react/eslint": "5.24.1",
43
+ "@eslint-react/shared": "5.24.1",
44
+ "@eslint-react/var": "5.24.1",
45
45
  "@typescript-eslint/types": "^8.71.0",
46
46
  "@typescript-eslint/utils": "^8.71.0",
47
47
  "ts-pattern": "^5.9.0"
@@ -53,7 +53,7 @@
53
53
  "@types/react": "^19.3.0",
54
54
  "@types/react-dom": "^19.3.0",
55
55
  "dedent": "^1.7.2",
56
- "eslint": "^10.11.0",
56
+ "eslint": "^10.12.0",
57
57
  "tsdown": "^0.23.0",
58
58
  "typescript": "6.0.3"
59
59
  },