Build a YAML vocabulary into consistent HTML, JSON-LD, JSON-LD context, and
Turtle files. This package provides a small wrapper around
yml2vocab.
- Node.js 24 or newer.
- An ES module project with a YAML vocabulary and HTML template.
-
Install the package:
npm install --save-dev @digitalbazaar/vocabulary-to-context
-
Add these files to the vocabulary project:
vocabulary.yaml(orvocabulary.yml)template.html
-
Create a build script:
// build.js import {buildVocab} from '@digitalbazaar/vocabulary-to-context'; await buildVocab();
-
Run the script:
node build.js
The build reads the YAML vocabulary, alphabetizes its class and property
definitions, and passes the vocabulary and template to yml2vocab. It writes:
vocabulary.htmlvocabulary.context.jsonldvocabulary.jsonldvocabulary.ttl
Use baseDir for a vocabulary in another directory, or explicitly provide the
YAML and template paths:
await buildVocab({
baseDir: './vocabulary',
// yamlFilePath: './vocabulary/vocabulary.yaml',
// templateFilePath: './vocabulary/template.html'
});By default, the generated context adds id: "@id" and type: "@type" at
the top level and in nested contexts. This is an opinionated convenience that
lets consumers use id and type without the @ prefix.
Disable the aliases:
await buildVocab({jsonLdAliases: false});Or replace them with your own names:
await buildVocab({
jsonLdAliases: {
identifier: '@id',
kind: '@type'
}
});Custom aliases replace the defaults and are applied recursively. Alias names should not collide with vocabulary terms.
Run npm test and npm run lint. The project uses
@digitalbazaar/eslint-config.