@eslint-react/ast 3.0.0-next.71 → 3.0.0-next.76

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 +121 -1
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/types";
2
- import { dual, or } from "@eslint-react/eff";
3
2
  import { ASTUtils } from "@typescript-eslint/utils";
4
3
  import { simpleTraverse } from "@typescript-eslint/typescript-estree";
5
4
  import { delimiterCase, replace, toLowerCase } from "string-ts";
@@ -71,6 +70,127 @@ function isDirectiveKind(kind) {
71
70
  return kind === "use client" || kind === "use server" || kind === "use memo" || kind === "use no memo";
72
71
  }
73
72
 
73
+ //#endregion
74
+ //#region ../../../.pkgs/eff/dist/index.js
75
+ function or(a, b) {
76
+ return (data) => a(data) || b(data);
77
+ }
78
+ /**
79
+ * Creates a function that can be used in a data-last (aka `pipe`able) or
80
+ * data-first style.
81
+ *
82
+ * The first parameter to `dual` is either the arity of the uncurried function
83
+ * or a predicate that determines if the function is being used in a data-first
84
+ * or data-last style.
85
+ *
86
+ * Using the arity is the most common use case, but there are some cases where
87
+ * you may want to use a predicate. For example, if you have a function that
88
+ * takes an optional argument, you can use a predicate to determine if the
89
+ * function is being used in a data-first or data-last style.
90
+ *
91
+ * You can pass either the arity of the uncurried function or a predicate
92
+ * which determines if the function is being used in a data-first or
93
+ * data-last style.
94
+ *
95
+ * **Example** (Using arity to determine data-first or data-last style)
96
+ *
97
+ * ```ts
98
+ * import { dual, pipe } from "effect/Function"
99
+ *
100
+ * const sum = dual<
101
+ * (that: number) => (self: number) => number,
102
+ * (self: number, that: number) => number
103
+ * >(2, (self, that) => self + that)
104
+ *
105
+ * console.log(sum(2, 3)) // 5
106
+ * console.log(pipe(2, sum(3))) // 5
107
+ * ```
108
+ *
109
+ * **Example** (Using call signatures to define the overloads)
110
+ *
111
+ * ```ts
112
+ * import { dual, pipe } from "effect/Function"
113
+ *
114
+ * const sum: {
115
+ * (that: number): (self: number) => number
116
+ * (self: number, that: number): number
117
+ * } = dual(2, (self: number, that: number): number => self + that)
118
+ *
119
+ * console.log(sum(2, 3)) // 5
120
+ * console.log(pipe(2, sum(3))) // 5
121
+ * ```
122
+ *
123
+ * **Example** (Using a predicate to determine data-first or data-last style)
124
+ *
125
+ * ```ts
126
+ * import { dual, pipe } from "effect/Function"
127
+ *
128
+ * const sum = dual<
129
+ * (that: number) => (self: number) => number,
130
+ * (self: number, that: number) => number
131
+ * >(
132
+ * (args) => args.length === 2,
133
+ * (self, that) => self + that
134
+ * )
135
+ *
136
+ * console.log(sum(2, 3)) // 5
137
+ * console.log(pipe(2, sum(3))) // 5
138
+ * ```
139
+ *
140
+ * @param arity - The arity of the uncurried function or a predicate that determines if the function is being used in a data-first or data-last style.
141
+ * @param body - The function to be curried.
142
+ * @since 1.0.0
143
+ */
144
+ const dual = function(arity, body) {
145
+ if (typeof arity === "function") return function() {
146
+ return arity(arguments) ? body.apply(this, arguments) : ((self) => body(self, ...arguments));
147
+ };
148
+ switch (arity) {
149
+ case 0:
150
+ case 1: throw new RangeError(`Invalid arity ${arity}`);
151
+ case 2: return function(a, b) {
152
+ if (arguments.length >= 2) return body(a, b);
153
+ return function(self) {
154
+ return body(self, a);
155
+ };
156
+ };
157
+ case 3: return function(a, b, c) {
158
+ if (arguments.length >= 3) return body(a, b, c);
159
+ return function(self) {
160
+ return body(self, a, b);
161
+ };
162
+ };
163
+ default: return function() {
164
+ if (arguments.length >= arity) return body.apply(this, arguments);
165
+ const args = arguments;
166
+ return function(self) {
167
+ return body(self, ...args);
168
+ };
169
+ };
170
+ }
171
+ };
172
+ /**
173
+ * Composes two functions, `ab` and `bc` into a single function that takes in an argument `a` of type `A` and returns a result of type `C`.
174
+ * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.
175
+ *
176
+ * @param self - The first function to apply (or the composed function in data-last style).
177
+ * @param bc - The second function to apply.
178
+ * @returns A composed function that applies both functions in sequence.
179
+ * @example
180
+ * ```ts
181
+ * import * as assert from "node:assert"
182
+ * import { compose } from "effect/Function"
183
+ *
184
+ * const increment = (n: number) => n + 1;
185
+ * const square = (n: number) => n * n;
186
+ *
187
+ * assert.strictEqual(compose(increment, square)(2), 9);
188
+ * ```
189
+ *
190
+ * @since 1.0.0
191
+ */
192
+ const compose = dual(2, (ab, bc) => (a) => bc(ab(a)));
193
+
74
194
  //#endregion
75
195
  //#region src/node-is.ts
76
196
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/ast",
3
- "version": "3.0.0-next.71",
3
+ "version": "3.0.0-next.76",
4
4
  "description": "ESLint React's TSESTree AST utility module.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {
@@ -34,15 +34,15 @@
34
34
  "@typescript-eslint/typescript-estree": "canary",
35
35
  "@typescript-eslint/utils": "canary",
36
36
  "string-ts": "^2.3.1",
37
- "@eslint-react/eff": "3.0.0-next.71"
37
+ "@local/eff": "3.0.0-beta.72"
38
38
  },
39
39
  "devDependencies": {
40
40
  "tsdown": "^0.21.0-beta.2",
41
41
  "@local/configs": "0.0.0"
42
42
  },
43
43
  "peerDependencies": {
44
- "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0",
45
- "typescript": ">=4.8.4 <6.0.0"
44
+ "eslint": "^10.0.0",
45
+ "typescript": "*"
46
46
  },
47
47
  "engines": {
48
48
  "node": ">=22.0.0"