@ivandt/json-rules
Advanced tools
@@ -22,3 +22,3 @@ import { Rule } from "../types"; | ||
| */ | ||
| evaluate<T>(rule: Rule, criteria: object | object[], trustRule?: boolean): Promise<T | boolean>; | ||
| evaluate<T>(rule: Rule, criteria: object | object[], trustRule?: boolean): T | boolean; | ||
| /** | ||
@@ -50,3 +50,3 @@ * Takes in a rule as a parameter and returns a ValidationResult | ||
| */ | ||
| static evaluate<T>(rule: Rule, criteria: object | object[], trustRule?: boolean): Promise<T | boolean>; | ||
| static evaluate<T>(rule: Rule, criteria: object | object[], trustRule?: boolean): T | boolean; | ||
| /** | ||
@@ -53,0 +53,0 @@ * Takes in a rule as a parameter and returns a ValidationResult |
| "use strict"; | ||
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
| function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
| return new (P || (P = Promise))(function (resolve, reject) { | ||
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
| function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
| function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
| step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
| }); | ||
| }; | ||
| var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
@@ -46,12 +37,10 @@ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
| */ | ||
| evaluate(rule_1, criteria_1) { | ||
| return __awaiter(this, arguments, void 0, function* (rule, criteria, trustRule = false) { | ||
| // Before we evaluate the rule, we should validate it. | ||
| // If `trustRuleset` is set to true, we will skip validation. | ||
| const validationResult = !trustRule && this.validate(rule); | ||
| if (!trustRule && !validationResult.isValid) { | ||
| throw new errors_1.RuleError(validationResult); | ||
| } | ||
| return __classPrivateFieldGet(this, _JsonRules_evaluator, "f").evaluate(rule, criteria); | ||
| }); | ||
| evaluate(rule, criteria, trustRule = false) { | ||
| // Before we evaluate the rule, we should validate it. | ||
| // If `trustRuleset` is set to true, we will skip validation. | ||
| const validationResult = !trustRule && this.validate(rule); | ||
| if (!trustRule && !validationResult.isValid) { | ||
| throw new errors_1.RuleError(validationResult); | ||
| } | ||
| return __classPrivateFieldGet(this, _JsonRules_evaluator, "f").evaluate(rule, criteria); | ||
| } | ||
@@ -88,6 +77,4 @@ /** | ||
| */ | ||
| static evaluate(rule_1, criteria_1) { | ||
| return __awaiter(this, arguments, void 0, function* (rule, criteria, trustRule = false) { | ||
| return __classPrivateFieldGet(_a, _a, "f", _JsonRules_jsonRules).evaluate(rule, criteria, trustRule); | ||
| }); | ||
| static evaluate(rule, criteria, trustRule = false) { | ||
| return __classPrivateFieldGet(_a, _a, "f", _JsonRules_jsonRules).evaluate(rule, criteria, trustRule); | ||
| } | ||
@@ -94,0 +81,0 @@ /** |
+2
-2
| { | ||
| "name": "@ivandt/json-rules", | ||
| "version": "2.1.1", | ||
| "version": "2.2.0", | ||
| "private": false, | ||
@@ -15,2 +15,3 @@ "description": "Rule parsing engine for JSON rules", | ||
| "test": "jest --testPathPattern=test --color --forceExit", | ||
| "test:watch": "jest --testPathPattern=test --color --watch", | ||
| "prepare": "npm run build", | ||
@@ -83,3 +84,2 @@ "prepublishOnly": "npm run build", | ||
| }, | ||
| "packageManager": "pnpm@8.15.4+sha1.c85a4305534f76d461407b59277b954bac97b5c4", | ||
| "dependencies": { | ||
@@ -86,0 +86,0 @@ "validator": "^13.15.15" |
+4
-4
@@ -75,3 +75,3 @@ [](https://badge.fury.io/js/@ivandt/json-rules) | ||
| const user = { age: 25, country: "US" }; | ||
| const result = await JsonRules.evaluate(rule, user); | ||
| const result = JsonRules.evaluate(rule, user); | ||
| console.log(result); // true | ||
@@ -217,3 +217,3 @@ ``` | ||
| const user = { age: 25, country: "US" }; | ||
| const result = await JsonRules.evaluate(rule, user); // true | ||
| const result = JsonRules.evaluate(rule, user); // true | ||
| ``` | ||
@@ -278,7 +278,7 @@ | ||
| ```typescript | ||
| static async evaluate<T>( | ||
| static evaluate<T>( | ||
| rule: Rule, | ||
| criteria: object | object[], | ||
| trustRule?: boolean | ||
| ): Promise<T | boolean> | ||
| ): T | boolean | ||
| ``` | ||
@@ -285,0 +285,0 @@ |
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
165027
-0.21%2685
-0.48%