Skip to content
Snippets Groups Projects

dcc-js

A typed JavaScript library for parsing and writing DCCs


Heads-Up

This library does not validate the given DCC. It expects them to be valid against the supported DCC schema. If you are looking for a way to validate xml against a xsd in the browser, have a look at the GEMIMEG Tool.

Getting Started

The module is currently published to a private registry on this GitLab instance. To install it you have to create a .npmrc in the root of your project with the following content.

@d-ptb:registry=https://gitlab1.ptb.de/api/v4/packages/npm/

# the following auth token is a public read only one
//gitlab1.ptb.de/api/v4/projects/:_authToken=yyhHC6-HhSZ8zxu4BS-_
//gitlab1.ptb.de/api/v4/packages/npm/:_authToken=yyhHC6-HhSZ8zxu4BS-_
//gitlab1.ptb.de/api/v4/projects/105/packages/npm/:_authToken=yyhHC6-HhSZ8zxu4BS-_

After that you can run npm install @d-ptb/dcc-js.

Example

import { DCCDocument } from "@d-ptb/dcc-js";

// parse the xml
const xml = "<valid dcc xml>";
const doc = DCCDocument.fromXml(xml);

// access the properties of the DCC
// _attr contains all the attributes of a given element
doc.digitalCalibrationCertificate._attr.schemaVersion // => 3.1.2
// _text is used to access the value of the given element
doc.digitalCalibrationCertificate.administrativeData.coreData.uniqueIdentifier._text

// serialize the DCC
console.log(doc.toXML()); // => <valid dcc xml>