@stackone/expressions 0.1.0

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/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # @stackone/expressions
2
+ ## Description
3
+
4
+ This package can be used to parse and evaluate string expressions with support for variables replacement, functions and operators.
5
+
6
+ This package uses the tech stack provided by the **Connect Monorepo** global setup. Please check the [root README](../../README.md) for more information.
7
+
8
+ ## Requirements
9
+
10
+ Please check the [root README](../../README.md) for requirements.
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ # install dependencies
16
+ $ npm run install
17
+ ```
18
+
19
+ ## Available commands
20
+
21
+ ```bash
22
+ # clean build output
23
+ $ npm run clean
24
+ ```
25
+
26
+ ```bash
27
+ # build package
28
+ $ npm run build
29
+ ```
30
+
31
+ ```bash
32
+ # run tests
33
+ $ npm run test
34
+ ```
35
+
36
+ ```bash
37
+ # run tests on watch mode
38
+ $ npm run test:watch
39
+ ```
40
+
41
+ ```bash
42
+ # run linter
43
+ $ npm run lint
44
+ ```
45
+
46
+ ```bash
47
+ # run linter and try to fix any error
48
+ $ npm run lint:fix
49
+ ```
@@ -0,0 +1 @@
1
+ import{isObject as r}from"@stackone/utils";import*as t from"jexl";const e=(r=()=>new t.Jexl)=>r(),n=r=>r.replace(/\$\./g,"").trim(),l=(r,t)=>{try{return r.compile(t)}catch(r){return null}},o=(t,o)=>{const c=r(o)?o:{},a=e(),u=n(t),s=l(a,u);return s?s.evalSync(c):null},c=r=>{const t=e(),o=n(r);return!!l(t,o)};export{o as evaluate,c as isValidExpression};
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";var e=require("@stackone/utils");function r(e){var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var t=r(require("jexl"));const n=(e=()=>new t.Jexl)=>e(),c=e=>e.replace(/\$\./g,"").trim(),u=(e,r)=>{try{return e.compile(r)}catch(e){return null}};exports.evaluate=(r,t)=>{const l=e.isObject(t)?t:{},a=n(),i=c(r),o=u(a,i);return o?o.evalSync(l):null},exports.isValidExpression=e=>{const r=n(),t=c(e);return!!u(r,t)};
@@ -0,0 +1 @@
1
+ export declare const evaluateExpression: (expression: string, context?: unknown) => unknown;
@@ -0,0 +1,39 @@
1
+ export declare const createExpressionHandler: (instanceBuilder?: () => {
2
+ addBinaryOp(operator: string, precedence: number, fn: (left: any, right: any) => any): void;
3
+ addUnaryOp(operator: string, fn: (right: any) => any): void;
4
+ addTransform(name: string, fn: (value: any, ...args: any[]) => any): void;
5
+ addTransforms(map: {
6
+ [key: string]: (value: any, ...args: any[]) => any;
7
+ }): void;
8
+ getTransform(name: string): (value: any, ...args: any[]) => any;
9
+ addFunction(name: string, fn: (value: any, ...args: any[]) => any): void;
10
+ addFunctions(map: {
11
+ [key: string]: (value: any, ...args: any[]) => any;
12
+ }): void;
13
+ getFunction(name: string): (value: any, ...args: any[]) => any;
14
+ eval(expression: string, context?: import("jexl/Expression").Context): Promise<any>;
15
+ evalSync(expression: string, context?: import("jexl/Expression").Context): any;
16
+ compile(expression: string): import("jexl/Expression").default;
17
+ createExpression(expression: string): import("jexl/Expression").default;
18
+ removeOp(operator: string): void;
19
+ _grammar: import("jexl/Grammar").default;
20
+ }) => {
21
+ addBinaryOp(operator: string, precedence: number, fn: (left: any, right: any) => any): void;
22
+ addUnaryOp(operator: string, fn: (right: any) => any): void;
23
+ addTransform(name: string, fn: (value: any, ...args: any[]) => any): void;
24
+ addTransforms(map: {
25
+ [key: string]: (value: any, ...args: any[]) => any;
26
+ }): void;
27
+ getTransform(name: string): (value: any, ...args: any[]) => any;
28
+ addFunction(name: string, fn: (value: any, ...args: any[]) => any): void;
29
+ addFunctions(map: {
30
+ [key: string]: (value: any, ...args: any[]) => any;
31
+ }): void;
32
+ getFunction(name: string): (value: any, ...args: any[]) => any;
33
+ eval(expression: string, context?: import("jexl/Expression").Context): Promise<any>;
34
+ evalSync(expression: string, context?: import("jexl/Expression").Context): any;
35
+ compile(expression: string): import("jexl/Expression").default;
36
+ createExpression(expression: string): import("jexl/Expression").default;
37
+ removeOp(operator: string): void;
38
+ _grammar: import("jexl/Grammar").default;
39
+ };
@@ -0,0 +1,2 @@
1
+ export { evaluateExpression as evaluate } from './evaluate';
2
+ export { isValidExpression } from './validate';
@@ -0,0 +1,3 @@
1
+ export type ExpressionContext = {
2
+ [key: string]: unknown;
3
+ };
@@ -0,0 +1,5 @@
1
+ import Expression from 'jexl/Expression';
2
+ export declare const cleanExpression: (expression: string) => string;
3
+ export declare const compileExpression: (expressionHandler: {
4
+ compile: (expr: string) => Expression;
5
+ }, expression: string) => Expression | null;
@@ -0,0 +1 @@
1
+ export declare const isValidExpression: (expression: string) => boolean;
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@stackone/expressions",
3
+ "version": "0.1.0",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.es.js",
7
+ "types": "dist/types/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "package.json",
11
+ "README.md"
12
+ ],
13
+ "scripts": {
14
+ "clean": "rimraf dist",
15
+ "prebuild": "npm run clean",
16
+ "build": "rollup -c --environment NODE_ENV:production",
17
+ "prebuild:dev": "npm run clean",
18
+ "build:dev": "rollup -c --environment NODE_ENV:development",
19
+ "code:format": "biome format ./src ./*.mjs",
20
+ "code:format:fix": "biome format --write ./src ./*.mjs",
21
+ "code:lint": "biome lint --error-on-warnings ./src ./*.mjs",
22
+ "code:lint:fix": "biome lint --write ./src ./*.mjs",
23
+ "code:check": "biome check ./src ./*.mjs",
24
+ "code:check:fix": "biome check --write ./src ./*.mjs",
25
+ "lint": "npm run code:check",
26
+ "lint:fix": "npm run code:check:fix",
27
+ "test": "vitest run",
28
+ "test:watch": "vitest watch",
29
+ "publish-release": "npm publish --access=public"
30
+ },
31
+ "keywords": [],
32
+ "author": "StackOne",
33
+ "license": "ISC",
34
+ "dependencies": {
35
+ "jexl": "^2.3.0",
36
+ "@stackone/utils": "*"
37
+ },
38
+ "devDependencies": {
39
+ "@types/jexl": "^2.3.4"
40
+ }
41
+ }