Skip to main content
Version: 1.0.0

Setup

You can follow this whole tutorial without installing anything — the live editors in each chapter run ontouml-js in your browser. But to build real projects you'll want it locally.

Install​

ontouml-js runs on Node.js 18+. Add it to a project:

npm install ontouml-js

A first script​

Create model.ts (or .js) and import from the package:

import { class Project
An OntoUML project: the top-level container of an ontology and the entry point of this library. A project holds every element of a model — classes, relations, generalizations, packages, properties, notes — as well as the diagrams and views that depict them, and provides typed access to these elements by id or by kind. New elements are created through the fluent builders exposed by the project (e.g., classBuilder , binaryRelationBuilder ), which register the created elements in the project. A project is also described by the metadata fields of the OntoUML/UFO Catalog Metadata Vocabulary, such as publisher, license, keywords, themes, and designed-for tasks.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
} from 'ontouml-js';
const const project: Projectproject = new new Project(): Project
An OntoUML project: the top-level container of an ontology and the entry point of this library. A project holds every element of a model — classes, relations, generalizations, packages, properties, notes — as well as the diagrams and views that depict them, and provides typed access to these elements by id or by kind. New elements are created through the fluent builders exposed by the project (e.g., classBuilder , binaryRelationBuilder ), which register the created elements in the project. A project is also described by the metadata fields of the OntoUML/UFO Catalog Metadata Vocabulary, such as publisher, license, keywords, themes, and designed-for tasks.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
();
const project: Projectproject.NamedElement.name: LanguageString
The name of this element, possibly in multiple languages.
name
.LanguageString.add(value: string, language?: string): void
Adds a text value in the given language, replacing any existing value for that language.
@paramvalue - the text to add.@paramlanguage - language tag of `value`; defaults to defaultLanguage.@throwsan error if `language` is not a valid language tag.
add
('My first project');
var console: Consoleconsole.Console.log(...data: any[]): void
The **`console.log()`** static method outputs a message to the console. [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
log
(const project: Projectproject.NamedElement.name: LanguageString
The name of this element, possibly in multiple languages.
name
.LanguageString.get(language?: string): string | null
Returns the text value for the given language. If no language is provided, returns the value of the first language in languagePreference for which a value exists. If no such value exists, returns the first value it finds. If no values are defined, returns `null`.
@paramlanguage - language tag of the desired value (e.g., `"en"`).@throwsan error if `language` is provided but invalid or has no value.
get
());

Run it with your favourite TypeScript runner (tsx, ts-node) or compile with tsc. If you see My first project, you're ready.

TypeScript recommended

ontouml-js is written in TypeScript and ships full type definitions. Using it from TypeScript means your editor autocompletes stereotypes and builder methods, and catches mistakes before you run anything. Every example in this tutorial is type-checked, so what you read is guaranteed to compile.

Next: build a complete model, end to end →.