@eslint-react/core 5.24.0-beta.2 → 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.d.ts +1 -1
- package/dist/index.js +366 -66
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -427,7 +427,7 @@ export type FunctionSemanticNode = ClientFunctionSemanticNode | ServerFunctionSe
|
|
|
427
427
|
* @param node The function node to analyze.
|
|
428
428
|
* @returns The identifier node if found, `null` otherwise.
|
|
429
429
|
*/
|
|
430
|
-
export declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpressionWithBlockBody | TSESTree.ArrowFunctionExpressionWithExpressionBody | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.ImportExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.LogicalExpression | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.
|
|
430
|
+
export declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpressionWithBlockBody | TSESTree.ArrowFunctionExpressionWithExpressionBody | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.ImportExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.TemplateLiteral | TSESTree.LogicalExpression | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion | TSESTree.UnaryExpressionBitwiseNot | TSESTree.UnaryExpressionDelete | TSESTree.UnaryExpressionMinus | TSESTree.UnaryExpressionNot | TSESTree.UnaryExpressionPlus | TSESTree.UnaryExpressionTypeof | TSESTree.UnaryExpressionVoid | TSESTree.UpdateExpression | TSESTree.YieldNoStarExpression | TSESTree.YieldStarExpression | TSESTree.PrivateIdentifier | null;
|
|
431
431
|
/**
|
|
432
432
|
* Get the initialization path of a function node in the AST.
|
|
433
433
|
*
|
package/dist/index.js
CHANGED
|
@@ -862,7 +862,7 @@ function isFunctionComponentDefinition(context, node, hint) {
|
|
|
862
862
|
* (n) => n + 2,
|
|
863
863
|
* (n) => n * 3
|
|
864
864
|
* )
|
|
865
|
-
*
|
|
865
|
+
* result // => 21
|
|
866
866
|
* ```
|
|
867
867
|
*
|
|
868
868
|
* @category combinators
|
|
@@ -919,16 +919,6 @@ const Class = (function() {
|
|
|
919
919
|
return PipeableBase;
|
|
920
920
|
})();
|
|
921
921
|
/**
|
|
922
|
-
* Provides small helpers for defining and reusing TypeScript functions.
|
|
923
|
-
*
|
|
924
|
-
* The main helpers are `pipe` and `flow` for left-to-right composition and
|
|
925
|
-
* `dual` for APIs that support both direct and pipe-friendly call styles. The
|
|
926
|
-
* module also contains small identity, constant, tuple, type-level, and
|
|
927
|
-
* memoization helpers used across the library.
|
|
928
|
-
*
|
|
929
|
-
* @since 2.0.0
|
|
930
|
-
*/
|
|
931
|
-
/**
|
|
932
922
|
* Creates a function that can be called in data-first style or data-last
|
|
933
923
|
* (`pipe`-friendly) style.
|
|
934
924
|
*
|
|
@@ -953,8 +943,8 @@ const Class = (function() {
|
|
|
953
943
|
* (self: number, that: number) => number
|
|
954
944
|
* >(2, (self, that) => self + that)
|
|
955
945
|
*
|
|
956
|
-
*
|
|
957
|
-
*
|
|
946
|
+
* sum(2, 3) // => 5
|
|
947
|
+
* pipe(2, sum(3)) // => 5
|
|
958
948
|
* ```
|
|
959
949
|
*
|
|
960
950
|
* **Example** (Defining overloads with call signatures)
|
|
@@ -967,8 +957,8 @@ const Class = (function() {
|
|
|
967
957
|
* (self: number, that: number): number
|
|
968
958
|
* } = Function.dual(2, (self: number, that: number): number => self + that)
|
|
969
959
|
*
|
|
970
|
-
*
|
|
971
|
-
*
|
|
960
|
+
* sum(2, 3) // => 5
|
|
961
|
+
* pipe(2, sum(3)) // => 5
|
|
972
962
|
* ```
|
|
973
963
|
*
|
|
974
964
|
* **Example** (Selecting data-first or data-last style with a predicate)
|
|
@@ -984,8 +974,8 @@ const Class = (function() {
|
|
|
984
974
|
* (self, that) => self + that
|
|
985
975
|
* )
|
|
986
976
|
*
|
|
987
|
-
*
|
|
988
|
-
*
|
|
977
|
+
* sum(2, 3) // => 5
|
|
978
|
+
* pipe(2, sum(3)) // => 5
|
|
989
979
|
* ```
|
|
990
980
|
*
|
|
991
981
|
* @category combinators
|
|
@@ -1030,9 +1020,8 @@ const dual = function(arity, body) {
|
|
|
1030
1020
|
*
|
|
1031
1021
|
* ```ts
|
|
1032
1022
|
* import { identity } from "effect"
|
|
1033
|
-
* import * as assert from "node:assert"
|
|
1034
1023
|
*
|
|
1035
|
-
*
|
|
1024
|
+
* identity(5) // => 5
|
|
1036
1025
|
* ```
|
|
1037
1026
|
*
|
|
1038
1027
|
* @category combinators
|
|
@@ -1070,12 +1059,11 @@ const cast = identity;
|
|
|
1070
1059
|
*
|
|
1071
1060
|
* ```ts
|
|
1072
1061
|
* import { Function } from "effect"
|
|
1073
|
-
* import * as assert from "node:assert"
|
|
1074
1062
|
*
|
|
1075
1063
|
* const constNull = Function.constant(null)
|
|
1076
1064
|
*
|
|
1077
|
-
*
|
|
1078
|
-
*
|
|
1065
|
+
* constNull() // => null
|
|
1066
|
+
* constNull() // => null
|
|
1079
1067
|
* ```
|
|
1080
1068
|
*
|
|
1081
1069
|
* @category constructors
|
|
@@ -1093,9 +1081,8 @@ const constant = (value) => () => value;
|
|
|
1093
1081
|
*
|
|
1094
1082
|
* ```ts
|
|
1095
1083
|
* import { Function } from "effect"
|
|
1096
|
-
* import * as assert from "node:assert"
|
|
1097
1084
|
*
|
|
1098
|
-
*
|
|
1085
|
+
* Function.constTrue() // => true
|
|
1099
1086
|
* ```
|
|
1100
1087
|
*
|
|
1101
1088
|
* @category constants
|
|
@@ -1113,9 +1100,8 @@ const constTrue = constant(true);
|
|
|
1113
1100
|
*
|
|
1114
1101
|
* ```ts
|
|
1115
1102
|
* import { Function } from "effect"
|
|
1116
|
-
* import * as assert from "node:assert"
|
|
1117
1103
|
*
|
|
1118
|
-
*
|
|
1104
|
+
* Function.constFalse() // => false
|
|
1119
1105
|
* ```
|
|
1120
1106
|
*
|
|
1121
1107
|
* @category constants
|
|
@@ -1133,9 +1119,8 @@ const constFalse = constant(false);
|
|
|
1133
1119
|
*
|
|
1134
1120
|
* ```ts
|
|
1135
1121
|
* import { Function } from "effect"
|
|
1136
|
-
* import * as assert from "node:assert"
|
|
1137
1122
|
*
|
|
1138
|
-
*
|
|
1123
|
+
* Function.constNull() // => null
|
|
1139
1124
|
* ```
|
|
1140
1125
|
*
|
|
1141
1126
|
* @category constants
|
|
@@ -1153,9 +1138,8 @@ const constNull = constant(null);
|
|
|
1153
1138
|
*
|
|
1154
1139
|
* ```ts
|
|
1155
1140
|
* import { Function } from "effect"
|
|
1156
|
-
* import * as assert from "node:assert"
|
|
1157
1141
|
*
|
|
1158
|
-
*
|
|
1142
|
+
* Function.constUndefined() // => undefined
|
|
1159
1143
|
* ```
|
|
1160
1144
|
*
|
|
1161
1145
|
* @category constants
|
|
@@ -1174,12 +1158,11 @@ const constUndefined = constant(void 0);
|
|
|
1174
1158
|
*
|
|
1175
1159
|
* ```ts
|
|
1176
1160
|
* import { Function } from "effect"
|
|
1177
|
-
* import * as assert from "node:assert"
|
|
1178
1161
|
*
|
|
1179
1162
|
* const increment = (n: number) => n + 1
|
|
1180
1163
|
* const square = (n: number) => n * n
|
|
1181
1164
|
*
|
|
1182
|
-
*
|
|
1165
|
+
* Function.compose(increment, square)(2) // => 9
|
|
1183
1166
|
* ```
|
|
1184
1167
|
*
|
|
1185
1168
|
* @see {@link flow} for composing a left-to-right sequence of functions
|
|
@@ -1242,7 +1225,6 @@ const absurd = (_) => {
|
|
|
1242
1225
|
* name: hole<string>()
|
|
1243
1226
|
* })
|
|
1244
1227
|
*
|
|
1245
|
-
* console.log(typeof buildUser) // "function"
|
|
1246
1228
|
* ```
|
|
1247
1229
|
*
|
|
1248
1230
|
* @category utility types
|
|
@@ -1250,56 +1232,374 @@ const absurd = (_) => {
|
|
|
1250
1232
|
*/
|
|
1251
1233
|
const hole = cast(absurd);
|
|
1252
1234
|
/**
|
|
1253
|
-
*
|
|
1235
|
+
* Creates a predicate that returns `true` only if both predicates are `true`.
|
|
1254
1236
|
*
|
|
1255
|
-
*
|
|
1237
|
+
* **When to use**
|
|
1238
|
+
*
|
|
1239
|
+
* Use when you want to combine `Predicate`s with AND, accepting values that
|
|
1240
|
+
* satisfy multiple conditions, including refinements that narrow to an
|
|
1241
|
+
* intersection.
|
|
1242
|
+
*
|
|
1243
|
+
* **Details**
|
|
1244
|
+
*
|
|
1245
|
+
* Evaluation short-circuits on the first `false`. For refinements, the output
|
|
1246
|
+
* type is an intersection.
|
|
1247
|
+
*
|
|
1248
|
+
* **Example** (Checking both conditions)
|
|
1249
|
+
*
|
|
1250
|
+
* ```ts
|
|
1251
|
+
* import { Predicate } from "effect"
|
|
1252
|
+
*
|
|
1253
|
+
* const hasAAndB = Predicate.and(
|
|
1254
|
+
* Predicate.hasProperty("a"),
|
|
1255
|
+
* Predicate.hasProperty("b")
|
|
1256
|
+
* )
|
|
1257
|
+
*
|
|
1258
|
+
* const input: unknown = JSON.parse(`{"a":1,"b":"ok"}`)
|
|
1259
|
+
* if (hasAAndB(input)) {
|
|
1260
|
+
* // input has both properties at this point
|
|
1261
|
+
* const a = input.a
|
|
1262
|
+
* const b = input.b
|
|
1263
|
+
*
|
|
1264
|
+
* const values = [a, b] // => [1, "ok"]
|
|
1265
|
+
* }
|
|
1266
|
+
* ```
|
|
1267
|
+
*
|
|
1268
|
+
* @see {@link or}
|
|
1269
|
+
* @see {@link not}
|
|
1270
|
+
* @category combinators
|
|
1271
|
+
* @since 2.0.0
|
|
1272
|
+
*/
|
|
1273
|
+
const and = dual(2, (a, b) => (data) => a(data) && b(data));
|
|
1274
|
+
/**
|
|
1275
|
+
* Creates a predicate that returns `true` if either predicate is `true`.
|
|
1276
|
+
*
|
|
1277
|
+
* **When to use**
|
|
1278
|
+
*
|
|
1279
|
+
* Use when you want to combine `Predicate`s with OR, accepting values that
|
|
1280
|
+
* satisfy at least one condition, including refinements that narrow to a union.
|
|
1281
|
+
*
|
|
1282
|
+
* **Details**
|
|
1283
|
+
*
|
|
1284
|
+
* Evaluation short-circuits on the first `true`. For refinements, the output
|
|
1285
|
+
* type is a union.
|
|
1286
|
+
*
|
|
1287
|
+
* **Example** (Checking either condition)
|
|
1288
|
+
*
|
|
1289
|
+
* ```ts
|
|
1290
|
+
* import { Predicate } from "effect"
|
|
1291
|
+
*
|
|
1292
|
+
* const isStringOrNumber = Predicate.or(Predicate.isString, Predicate.isNumber)
|
|
1293
|
+
*
|
|
1294
|
+
* isStringOrNumber("a") // => true
|
|
1295
|
+
* ```
|
|
1296
|
+
*
|
|
1297
|
+
* @see {@link and}
|
|
1298
|
+
* @see {@link xor}
|
|
1299
|
+
* @category combinators
|
|
1300
|
+
* @since 2.0.0
|
|
1301
|
+
*/
|
|
1302
|
+
const or = dual(2, (a, b) => (data) => a(data) || b(data));
|
|
1303
|
+
/**
|
|
1304
|
+
* Creates a predicate that returns `true` if exactly one predicate is `true`.
|
|
1305
|
+
*
|
|
1306
|
+
* **When to use**
|
|
1307
|
+
*
|
|
1308
|
+
* Use when you want to combine two `Predicate`s with exclusive-or semantics.
|
|
1309
|
+
*
|
|
1310
|
+
* **Details**
|
|
1311
|
+
*
|
|
1312
|
+
* Returns `true` when results differ.
|
|
1313
|
+
*
|
|
1314
|
+
* **Example** (Checking exclusive-or conditions)
|
|
1315
|
+
*
|
|
1316
|
+
* ```ts
|
|
1317
|
+
* import { Predicate } from "effect"
|
|
1318
|
+
*
|
|
1319
|
+
* const isEven = (n: number) => n % 2 === 0
|
|
1320
|
+
* const isPositive = (n: number) => n > 0
|
|
1321
|
+
* const either = Predicate.xor(isEven, isPositive)
|
|
1322
|
+
*
|
|
1323
|
+
* either(-2) // => true
|
|
1324
|
+
* ```
|
|
1325
|
+
*
|
|
1326
|
+
* @see {@link or}
|
|
1327
|
+
* @see {@link and}
|
|
1328
|
+
* @category combinators
|
|
1329
|
+
* @since 2.0.0
|
|
1330
|
+
*/
|
|
1331
|
+
const xor = dual(2, (a, b) => (data) => a(data) !== b(data));
|
|
1332
|
+
/**
|
|
1333
|
+
* Creates a predicate that returns `true` when both predicates agree.
|
|
1334
|
+
*
|
|
1335
|
+
* **When to use**
|
|
1336
|
+
*
|
|
1337
|
+
* Use when you want to check equivalence of two `Predicate`s.
|
|
1338
|
+
*
|
|
1339
|
+
* **Details**
|
|
1340
|
+
*
|
|
1341
|
+
* Returns `true` when both results are equal.
|
|
1342
|
+
*
|
|
1343
|
+
* **Example** (Defining equivalence)
|
|
1344
|
+
*
|
|
1345
|
+
* ```ts
|
|
1346
|
+
* import { Predicate } from "effect"
|
|
1347
|
+
*
|
|
1348
|
+
* const isEven = (n: number) => n % 2 === 0
|
|
1349
|
+
* const same = Predicate.eqv(isEven, isEven)
|
|
1350
|
+
*
|
|
1351
|
+
* same(3) // => true
|
|
1352
|
+
* ```
|
|
1353
|
+
*
|
|
1354
|
+
* @see {@link xor}
|
|
1355
|
+
* @category combinators
|
|
1356
|
+
* @since 2.0.0
|
|
1357
|
+
*/
|
|
1358
|
+
const eqv = dual(2, (a, b) => (data) => a(data) === b(data));
|
|
1359
|
+
/**
|
|
1360
|
+
* Creates a predicate representing logical implication: if `antecedent`, then `consequent`.
|
|
1361
|
+
*
|
|
1362
|
+
* **When to use**
|
|
1363
|
+
*
|
|
1364
|
+
* Use when you need to encode logical implication between `Predicate` rules,
|
|
1365
|
+
* where one rule only applies when a precondition holds.
|
|
1366
|
+
*
|
|
1367
|
+
* **Details**
|
|
1368
|
+
*
|
|
1369
|
+
* Models constraints like "if A then B" and returns `true` when the antecedent
|
|
1370
|
+
* is `false`.
|
|
1371
|
+
*
|
|
1372
|
+
* **Example** (Checking implication)
|
|
1373
|
+
*
|
|
1374
|
+
* ```ts
|
|
1375
|
+
* import { Predicate } from "effect"
|
|
1376
|
+
*
|
|
1377
|
+
* const isAdult = (age: number) => age >= 18
|
|
1378
|
+
* const canVote = (age: number) => age >= 18
|
|
1379
|
+
* const implies = Predicate.implies(isAdult, canVote)
|
|
1380
|
+
*
|
|
1381
|
+
* implies(16) // => true
|
|
1382
|
+
* ```
|
|
1383
|
+
*
|
|
1384
|
+
* @see {@link and}
|
|
1385
|
+
* @see {@link or}
|
|
1386
|
+
* @category combinators
|
|
1387
|
+
* @since 2.0.0
|
|
1388
|
+
*/
|
|
1389
|
+
const implies = dual(2, (antecedent, consequent) => (data) => !antecedent(data) || consequent(data));
|
|
1390
|
+
/**
|
|
1391
|
+
* Creates a predicate that returns `true` when neither predicate is `true`.
|
|
1392
|
+
*
|
|
1393
|
+
* **When to use**
|
|
1394
|
+
*
|
|
1395
|
+
* Use when you want to combine two `Predicate`s with logical NOR semantics.
|
|
1396
|
+
*
|
|
1397
|
+
* **Details**
|
|
1398
|
+
*
|
|
1399
|
+
* Returns the negation of `or`.
|
|
1400
|
+
*
|
|
1401
|
+
* **Example** (Checking NOR conditions)
|
|
1402
|
+
*
|
|
1403
|
+
* ```ts
|
|
1404
|
+
* import { Predicate } from "effect"
|
|
1405
|
+
*
|
|
1406
|
+
* const neither = Predicate.nor(Predicate.isString, Predicate.isNumber)
|
|
1407
|
+
*
|
|
1408
|
+
* neither(true) // => true
|
|
1409
|
+
* ```
|
|
1410
|
+
*
|
|
1411
|
+
* @see {@link or}
|
|
1412
|
+
* @see {@link not}
|
|
1413
|
+
* @category combinators
|
|
1414
|
+
* @since 2.0.0
|
|
1415
|
+
*/
|
|
1416
|
+
const nor = dual(2, (a, b) => (data) => !a(data) && !b(data));
|
|
1417
|
+
/**
|
|
1418
|
+
* Creates a predicate that returns `true` unless both predicates are `true`.
|
|
1419
|
+
*
|
|
1420
|
+
* **When to use**
|
|
1421
|
+
*
|
|
1422
|
+
* Use when you want to combine two `Predicate`s with logical NAND semantics.
|
|
1423
|
+
*
|
|
1424
|
+
* **Details**
|
|
1425
|
+
*
|
|
1426
|
+
* Returns the negation of `and`.
|
|
1427
|
+
*
|
|
1428
|
+
* **Example** (Checking NAND conditions)
|
|
1429
|
+
*
|
|
1430
|
+
* ```ts
|
|
1431
|
+
* import { Predicate } from "effect"
|
|
1432
|
+
*
|
|
1433
|
+
* const notBoth = Predicate.nand(Predicate.isString, Predicate.isNumber)
|
|
1434
|
+
*
|
|
1435
|
+
* notBoth("a") // => true
|
|
1436
|
+
* ```
|
|
1437
|
+
*
|
|
1438
|
+
* @see {@link and}
|
|
1439
|
+
* @see {@link not}
|
|
1440
|
+
* @category combinators
|
|
1441
|
+
* @since 2.0.0
|
|
1442
|
+
*/
|
|
1443
|
+
const nand = dual(2, (a, b) => (data) => !a(data) || !b(data));
|
|
1444
|
+
/**
|
|
1445
|
+
* Checks whether a value is a `function`.
|
|
1446
|
+
*
|
|
1447
|
+
* **When to use**
|
|
1448
|
+
*
|
|
1449
|
+
* Use when you need a `Predicate` guard to narrow an `unknown` value to a
|
|
1450
|
+
* callable function.
|
|
1451
|
+
*
|
|
1452
|
+
* **Details**
|
|
1453
|
+
*
|
|
1454
|
+
* Uses `typeof input === "function"`.
|
|
1455
|
+
*
|
|
1456
|
+
* **Example** (Guarding functions)
|
|
1256
1457
|
*
|
|
1257
|
-
* @param pred - The predicate to test each element with.
|
|
1258
|
-
* @returns A new array without the matching prefix.
|
|
1259
|
-
* @example
|
|
1260
1458
|
* ```ts
|
|
1261
|
-
* import
|
|
1262
|
-
* import { dropWhile, pipe } from "@local/eff"
|
|
1459
|
+
* import { Predicate } from "effect"
|
|
1263
1460
|
*
|
|
1264
|
-
*
|
|
1265
|
-
* assert.deepStrictEqual(dropWhile([1, 2, 3, 2, 1], (n: number) => n < 3), [3, 2, 1])
|
|
1461
|
+
* const data: unknown = () => 1
|
|
1266
1462
|
*
|
|
1267
|
-
*
|
|
1268
|
-
*
|
|
1463
|
+
* if (Predicate.isFunction(data)) {
|
|
1464
|
+
* data() // => 1
|
|
1465
|
+
* }
|
|
1269
1466
|
* ```
|
|
1270
|
-
*
|
|
1467
|
+
*
|
|
1468
|
+
* @see {@link isObjectKeyword}
|
|
1469
|
+
* @category guards
|
|
1470
|
+
* @since 2.0.0
|
|
1271
1471
|
*/
|
|
1272
|
-
|
|
1273
|
-
|
|
1472
|
+
function isFunction(input) {
|
|
1473
|
+
return typeof input === "function";
|
|
1474
|
+
}
|
|
1475
|
+
/**
|
|
1476
|
+
* Checks whether a value is an `object` in the JavaScript sense (objects, arrays, functions).
|
|
1477
|
+
*
|
|
1478
|
+
* **When to use**
|
|
1479
|
+
*
|
|
1480
|
+
* Use when you need a `Predicate` guard that accepts arrays and functions as
|
|
1481
|
+
* well as objects.
|
|
1482
|
+
*
|
|
1483
|
+
* **Details**
|
|
1484
|
+
*
|
|
1485
|
+
* Returns `true` for arrays and functions, and `false` for `null`.
|
|
1486
|
+
*
|
|
1487
|
+
* **Example** (Checking object keywords)
|
|
1488
|
+
*
|
|
1489
|
+
* ```ts
|
|
1490
|
+
* import { Predicate } from "effect"
|
|
1491
|
+
*
|
|
1492
|
+
* Predicate.isObjectKeyword(() => 1) // => true
|
|
1493
|
+
* Predicate.isObjectKeyword(null) // => false
|
|
1494
|
+
* ```
|
|
1495
|
+
*
|
|
1496
|
+
* @see {@link isObject}
|
|
1497
|
+
* @see {@link isObjectOrArray}
|
|
1498
|
+
* @category guards
|
|
1499
|
+
* @since 4.0.0
|
|
1500
|
+
*/
|
|
1501
|
+
function isObjectKeyword(input) {
|
|
1502
|
+
return typeof input === "object" && input !== null || isFunction(input);
|
|
1503
|
+
}
|
|
1504
|
+
/**
|
|
1505
|
+
* Checks whether a value has a given property key.
|
|
1506
|
+
*
|
|
1507
|
+
* **When to use**
|
|
1508
|
+
*
|
|
1509
|
+
* Use when you need a `Predicate` guard for property access on `unknown`
|
|
1510
|
+
* values with a simple structural object check.
|
|
1511
|
+
*
|
|
1512
|
+
* **Details**
|
|
1513
|
+
*
|
|
1514
|
+
* Uses the `in` operator and `isObjectKeyword`. This does not check property
|
|
1515
|
+
* value types.
|
|
1516
|
+
*
|
|
1517
|
+
* **Example** (Guarding object properties)
|
|
1518
|
+
*
|
|
1519
|
+
* ```ts
|
|
1520
|
+
* import { Predicate } from "effect"
|
|
1521
|
+
*
|
|
1522
|
+
* const hasName = Predicate.hasProperty("name")
|
|
1523
|
+
* const data: unknown = { name: "Ada" }
|
|
1524
|
+
*
|
|
1525
|
+
* if (hasName(data)) {
|
|
1526
|
+
* data.name // => "Ada"
|
|
1527
|
+
* }
|
|
1528
|
+
* ```
|
|
1529
|
+
*
|
|
1530
|
+
* @see {@link isTagged}
|
|
1531
|
+
* @see {@link isObjectKeyword}
|
|
1532
|
+
* @category guards
|
|
1533
|
+
* @since 2.0.0
|
|
1534
|
+
*/
|
|
1535
|
+
const hasProperty = dual(2, (data, property) => isObjectKeyword(data) && property in data);
|
|
1536
|
+
/**
|
|
1537
|
+
* Drops elements from the start while the predicate holds, returning the rest.
|
|
1538
|
+
*
|
|
1539
|
+
* **When to use**
|
|
1540
|
+
*
|
|
1541
|
+
* Use to remove a leading prefix of elements that satisfy a predicate.
|
|
1542
|
+
*
|
|
1543
|
+
* **Details**
|
|
1544
|
+
*
|
|
1545
|
+
* The predicate receives `(element, index)`.
|
|
1546
|
+
*
|
|
1547
|
+
* **Example** (Dropping while condition holds)
|
|
1548
|
+
*
|
|
1549
|
+
* ```ts
|
|
1550
|
+
* import { Array } from "effect"
|
|
1551
|
+
*
|
|
1552
|
+
* Array.dropWhile([1, 2, 3, 4, 5], (x) => x < 4) // => [4, 5]
|
|
1553
|
+
* ```
|
|
1554
|
+
*
|
|
1555
|
+
* @see {@link takeWhile} — keep the matching prefix instead
|
|
1556
|
+
* @see {@link drop} — drop a fixed count
|
|
1557
|
+
*
|
|
1558
|
+
* @category getters
|
|
1559
|
+
* @since 2.0.0
|
|
1560
|
+
*/
|
|
1561
|
+
const dropWhile = dual(2, (self, predicate) => {
|
|
1562
|
+
const input = Array.isArray(self) ? self : Array.from(self);
|
|
1563
|
+
const len = input.length;
|
|
1274
1564
|
let idx = 0;
|
|
1275
|
-
while (idx < len &&
|
|
1276
|
-
return
|
|
1565
|
+
while (idx < len && predicate(input[idx], idx)) idx++;
|
|
1566
|
+
return input.slice(idx);
|
|
1277
1567
|
});
|
|
1278
1568
|
/**
|
|
1279
|
-
* Takes
|
|
1569
|
+
* Takes elements from the start while the predicate holds, stopping at the
|
|
1570
|
+
* first element that fails.
|
|
1280
1571
|
*
|
|
1281
|
-
*
|
|
1572
|
+
* **When to use**
|
|
1282
1573
|
*
|
|
1283
|
-
*
|
|
1284
|
-
*
|
|
1285
|
-
*
|
|
1286
|
-
*
|
|
1287
|
-
* import * as assert from "node:assert"
|
|
1288
|
-
* import { pipe, takeWhile } from "@local/eff"
|
|
1574
|
+
* Use to keep the leading elements of an iterable while each element satisfies
|
|
1575
|
+
* a predicate, returning the retained prefix as an array.
|
|
1576
|
+
*
|
|
1577
|
+
* **Details**
|
|
1289
1578
|
*
|
|
1290
|
-
*
|
|
1291
|
-
*
|
|
1579
|
+
* Supports refinements for type narrowing. The predicate receives
|
|
1580
|
+
* `(element, index)`.
|
|
1292
1581
|
*
|
|
1293
|
-
*
|
|
1294
|
-
*
|
|
1582
|
+
* **Example** (Taking while condition holds)
|
|
1583
|
+
*
|
|
1584
|
+
* ```ts
|
|
1585
|
+
* import { Array } from "effect"
|
|
1586
|
+
*
|
|
1587
|
+
* Array.takeWhile([1, 3, 2, 4, 1, 2], (x) => x < 4) // => [1, 3, 2]
|
|
1295
1588
|
* ```
|
|
1296
|
-
*
|
|
1589
|
+
*
|
|
1590
|
+
* @see {@link take} for keeping a fixed number of leading elements
|
|
1591
|
+
* @see {@link dropWhile} for removing the matching prefix and keeping the rest
|
|
1592
|
+
* @see {@link span} for splitting the matching prefix from the remaining elements
|
|
1593
|
+
*
|
|
1594
|
+
* @category getters
|
|
1595
|
+
* @since 2.0.0
|
|
1297
1596
|
*/
|
|
1298
|
-
const takeWhile = dual(2, (
|
|
1299
|
-
const
|
|
1597
|
+
const takeWhile = dual(2, (self, predicate) => {
|
|
1598
|
+
const input = Array.isArray(self) ? self : Array.from(self);
|
|
1599
|
+
const len = input.length;
|
|
1300
1600
|
let idx = 0;
|
|
1301
|
-
while (idx < len &&
|
|
1302
|
-
return
|
|
1601
|
+
while (idx < len && predicate(input[idx], idx)) idx++;
|
|
1602
|
+
return input.slice(0, idx);
|
|
1303
1603
|
});
|
|
1304
1604
|
|
|
1305
1605
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/core",
|
|
3
|
-
"version": "5.24.
|
|
3
|
+
"version": "5.24.1",
|
|
4
4
|
"description": "ESLint React's ESLint utility module for static analysis of React core APIs and patterns.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@eslint-react/ast": "5.24.
|
|
33
|
-
"@eslint-react/eslint": "5.24.
|
|
34
|
-
"@eslint-react/shared": "5.24.
|
|
35
|
-
"@eslint-react/var": "5.24.
|
|
32
|
+
"@eslint-react/ast": "5.24.1",
|
|
33
|
+
"@eslint-react/eslint": "5.24.1",
|
|
34
|
+
"@eslint-react/shared": "5.24.1",
|
|
35
|
+
"@eslint-react/var": "5.24.1",
|
|
36
36
|
"@typescript-eslint/types": "^8.71.0",
|
|
37
37
|
"@typescript-eslint/utils": "^8.71.0",
|
|
38
38
|
"ts-pattern": "^5.9.0"
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@local/eff": "0.0.0",
|
|
43
43
|
"@local/testkit": "0.0.0",
|
|
44
44
|
"@typescript-eslint/typescript-estree": "^8.71.0",
|
|
45
|
-
"eslint": "^10.
|
|
45
|
+
"eslint": "^10.12.0",
|
|
46
46
|
"tsdown": "^0.23.0",
|
|
47
47
|
"typescript": "6.0.3",
|
|
48
48
|
"vitest": "^5.0.3"
|