To add OCL.js to your project install it via npm as follows and you are good to go:
$ npm install @stekoe/ocl.js --save
As alternative, you can also download the ocl.min.js file from GitHub and include that to your code.
When adding OCL.js via npm, you can start using it via importing the OCLEngine that is provided by “@stekoe/ocl.js”.
import OCLEngine from "@stekoe/ocl.js"// Or of you prefer require:// const OCLEngine = require('@stekoe/ocl.js');const myOclExpression = `context Personinv: self.parents->forAll(p | p <> self)`;// Instantiate the OclEngine hereconst oclEngine = new OclEngine();// Add your first OCL expression hereoclEngine.addOclExpression(myOclExpression);// Evaluate an object obj against all know OCL expressionsconst oclResult = oclEngine.evaluate(obj);
oclResult object contains three fields:
result contains the actual result of the evaluation run as a boolean value
namesOfFailedInvs contains the names of failed invariants or
anonymous if none has been provided
evaluatedContexts contains all
ContextExpressions that have been evaluated