@eslint-react/core
Advanced tools
+159
-1
| import * as ast from "@eslint-react/ast"; | ||
| import { constFalse, dual, flip, getOrElseUpdate, identity } from "@eslint-react/eff"; | ||
| import { AST_NODE_TYPES } from "@typescript-eslint/types"; | ||
@@ -10,2 +9,161 @@ import { findVariable, getStaticValue } from "@typescript-eslint/utils/ast-utils"; | ||
| //#region ../../.pkgs/eff/dist/index.js | ||
| /** | ||
| * Returns its argument. | ||
| * | ||
| * @param x - The value to return. | ||
| * @returns The input value unchanged. | ||
| */ | ||
| function identity(x) { | ||
| return x; | ||
| } | ||
| /** | ||
| * Creates a function that can be used in a data-last (aka `pipe`able) or | ||
| * data-first style. | ||
| * | ||
| * The first parameter to `dual` is either 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. | ||
| * | ||
| * Using the arity is the most common use case, but there are some cases where | ||
| * you may want to use a predicate. For example, if you have a function that | ||
| * takes an optional argument, you can use a predicate to determine if the | ||
| * function is being used in a data-first or data-last style. | ||
| * | ||
| * You can pass either the arity of the uncurried function or a predicate | ||
| * which determines if the function is being used in a data-first or | ||
| * data-last style. | ||
| * | ||
| * **Example** (Using arity to determine data-first or data-last style) | ||
| * | ||
| * ```ts | ||
| * import { dual, pipe } from "effect/Function" | ||
| * | ||
| * const sum = dual< | ||
| * (that: number) => (self: number) => number, | ||
| * (self: number, that: number) => number | ||
| * >(2, (self, that) => self + that) | ||
| * | ||
| * console.log(sum(2, 3)) // 5 | ||
| * console.log(pipe(2, sum(3))) // 5 | ||
| * ``` | ||
| * | ||
| * **Example** (Using call signatures to define the overloads) | ||
| * | ||
| * ```ts | ||
| * import { dual, pipe } from "effect/Function" | ||
| * | ||
| * const sum: { | ||
| * (that: number): (self: number) => number | ||
| * (self: number, that: number): number | ||
| * } = dual(2, (self: number, that: number): number => self + that) | ||
| * | ||
| * console.log(sum(2, 3)) // 5 | ||
| * console.log(pipe(2, sum(3))) // 5 | ||
| * ``` | ||
| * | ||
| * **Example** (Using a predicate to determine data-first or data-last style) | ||
| * | ||
| * ```ts | ||
| * import { dual, pipe } from "effect/Function" | ||
| * | ||
| * const sum = dual< | ||
| * (that: number) => (self: number) => number, | ||
| * (self: number, that: number) => number | ||
| * >( | ||
| * (args) => args.length === 2, | ||
| * (self, that) => self + that | ||
| * ) | ||
| * | ||
| * console.log(sum(2, 3)) // 5 | ||
| * console.log(pipe(2, sum(3))) // 5 | ||
| * ``` | ||
| * | ||
| * @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. | ||
| * @param body - The function to be curried. | ||
| * @since 1.0.0 | ||
| */ | ||
| const dual = function(arity, body) { | ||
| if (typeof arity === "function") return function() { | ||
| return arity(arguments) ? body.apply(this, arguments) : ((self) => body(self, ...arguments)); | ||
| }; | ||
| switch (arity) { | ||
| case 0: | ||
| case 1: throw new RangeError(`Invalid arity ${arity}`); | ||
| case 2: return function(a, b) { | ||
| if (arguments.length >= 2) return body(a, b); | ||
| return function(self) { | ||
| return body(self, a); | ||
| }; | ||
| }; | ||
| case 3: return function(a, b, c) { | ||
| if (arguments.length >= 3) return body(a, b, c); | ||
| return function(self) { | ||
| return body(self, a, b); | ||
| }; | ||
| }; | ||
| default: return function() { | ||
| if (arguments.length >= arity) return body.apply(this, arguments); | ||
| const args = arguments; | ||
| return function(self) { | ||
| return body(self, ...args); | ||
| }; | ||
| }; | ||
| } | ||
| }; | ||
| /** | ||
| * Do nothing and return `false`. | ||
| * | ||
| * @returns false | ||
| */ | ||
| function constFalse() { | ||
| return false; | ||
| } | ||
| /** | ||
| * Reverses the order of arguments for a curried function. | ||
| * | ||
| * @param f - The function to flip. | ||
| * @returns A new function with the argument order reversed. | ||
| * @example | ||
| * ```ts | ||
| * import * as assert from "node:assert" | ||
| * import { flip } from "effect/Function" | ||
| * | ||
| * const f = (a: number) => (b: string) => a - b.length | ||
| * | ||
| * assert.deepStrictEqual(flip(f)('aaa')(2), -1) | ||
| * ``` | ||
| * | ||
| * @since 1.0.0 | ||
| */ | ||
| const flip = (f) => (...b) => (...a) => f(...a)(...b); | ||
| /** | ||
| * 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`. | ||
| * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`. | ||
| * | ||
| * @param self - The first function to apply (or the composed function in data-last style). | ||
| * @param bc - The second function to apply. | ||
| * @returns A composed function that applies both functions in sequence. | ||
| * @example | ||
| * ```ts | ||
| * import * as assert from "node:assert" | ||
| * import { compose } from "effect/Function" | ||
| * | ||
| * const increment = (n: number) => n + 1; | ||
| * const square = (n: number) => n * n; | ||
| * | ||
| * assert.strictEqual(compose(increment, square)(2), 9); | ||
| * ``` | ||
| * | ||
| * @since 1.0.0 | ||
| */ | ||
| const compose = dual(2, (ab, bc) => (a) => bc(ab(a))); | ||
| function getOrElseUpdate(map, key, callback) { | ||
| if (map.has(key)) return map.get(key); | ||
| const value = callback(); | ||
| map.set(key, value); | ||
| return value; | ||
| } | ||
| //#endregion | ||
| //#region src/api/find-import-source.ts | ||
@@ -12,0 +170,0 @@ /** |
+7
-7
| { | ||
| "name": "@eslint-react/core", | ||
| "version": "3.0.0-beta.71", | ||
| "version": "3.0.0-beta.74", | ||
| "description": "ESLint React's ESLint utility module for static analysis of React core APIs and patterns.", | ||
@@ -37,6 +37,6 @@ "homepage": "https://github.com/Rel1cx/eslint-react", | ||
| "ts-pattern": "^5.9.0", | ||
| "@eslint-react/ast": "3.0.0-beta.71", | ||
| "@eslint-react/shared": "3.0.0-beta.71", | ||
| "@eslint-react/eff": "3.0.0-beta.71", | ||
| "@eslint-react/var": "3.0.0-beta.71" | ||
| "@eslint-react/ast": "3.0.0-beta.74", | ||
| "@eslint-react/var": "3.0.0-beta.74", | ||
| "@local/eff": "3.0.0-beta.72", | ||
| "@eslint-react/shared": "3.0.0-beta.74" | ||
| }, | ||
@@ -48,4 +48,4 @@ "devDependencies": { | ||
| "peerDependencies": { | ||
| "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", | ||
| "typescript": ">=4.8.4 <6.0.0" | ||
| "eslint": "^10.0.0", | ||
| "typescript": "*" | ||
| }, | ||
@@ -52,0 +52,0 @@ "engines": { |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
100106
4.61%2373
7.08%+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed