{"library":"spel2js","title":"SpEL2JS Parser","type":"library","description":"spel2js is a JavaScript library designed to parse and evaluate Spring Expression Language (SpEL) expressions within a defined context. Its primary purpose is to allow single-page applications to mirror server-side authorization logic, reducing duplication and inconsistencies in UI-related permissions. The library provides a JavaScript implementation of the SpEL parser, aiming to mimic the behavior documented for Spring Framework. It exports a singleton object containing `StandardContext` for creating evaluation contexts (which manage `authentication` and `principal` objects) and `SpelExpressionEvaluator` for compiling and executing SpEL expressions. The latest published version is 0.2.9, but significant development activity appears to have ceased around 2016 (judging by the release notes and `bower` references), indicating it is not actively maintained. It targets Node.js environments `>=8` but its age suggests potential compatibility challenges with modern JavaScript ecosystems and build tools.","language":"javascript","status":"abandoned","last_verified":"Sun Apr 19","install":{"commands":["npm install spel2js"],"cli":null},"imports":["import spel2js from 'spel2js';","import { StandardContext, SpelExpressionEvaluator } from 'spel2js';","const spel2js = require('spel2js');"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/benmarch/spel2js","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/spel2js","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import { StandardContext, SpelExpressionEvaluator } from 'spel2js';\n\n// Mock Spring Security Authentication object and a principal object\nconst mockAuthentication = {\n  details: {\n    name: 'Darth Vader'\n  },\n  isAuthenticated: true\n};\n\nconst mockPrincipal = {\n  username: 'dvader',\n  roles: ['SITH_LORD', 'EMPIRE_ADMIRAL']\n};\n\n// Locals represent specific objects in the expression context\nconst locals = {\n  toDoList: {\n    owner: 'Darth Vader',\n    items: ['Destroy Alderaan', 'Build Death Star']\n  }\n};\n\nconst expression = '#toDoList.owner == authentication.details.name && authentication.isAuthenticated';\n\n// Create an evaluation context with mock data\nconst spelContext = StandardContext.create(mockAuthentication, mockPrincipal);\n\n// Evaluate the expression directly\nconst result = SpelExpressionEvaluator.eval(expression, spelContext, locals);\n\nconsole.log(`Expression: \"${expression}\"`);\nconsole.log(`Result: ${result}`); // Expected: true\n\n// Example of pre-compiling an expression for reuse\nconst compiledExpression = SpelExpressionEvaluator.compile('#toDoList.items.size() > 1');\nconst compiledResult = compiledExpression.eval(spelContext, locals);\nconsole.log(`Compiled expression result: ${compiledResult}`); // Expected: true","lang":"javascript","description":"This quickstart demonstrates how to set up an evaluation context, define local variables, and then evaluate a Spring Expression Language (SpEL) expression using `SpelExpressionEvaluator.eval()` or a pre-compiled expression.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}