Skip to content

OCL.jsOCL for JavaScript and TypeScript

Parse and evaluate OCL constraints in JavaScript and TypeScript — in the browser or Node.js.

What is OCL?

The Object Constraint Language (OCL) is a language for describing rules that apply to MOF-conform modelling languages like UML. It is a text-based language that provides constraint and object query expressions that cannot be expressed by a meta-modelling language.

Since implementations exist in Java (e.g. Eclipse Modelling Framework) but not in JavaScript, OCL.js fills that gap. This library does not claim to be fully compliant with the OMG OCL specification and may have slight differences.

Quick Start

bash
npm install @stekoe/ocl.js
typescript
import { OclEngine } from '@stekoe/ocl.js';

const oclEngine = OclEngine.create();

oclEngine.addOclExpression(`
  context Person inv: self.parents->forAll(p | p <> self)
`);

const result = oclEngine.evaluate(new Person());
console.log(result.getResult()); // true

Released under the MIT License.