1.2.0 • Published 5 years ago

@tangleid/jsonld v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

@tangleid/jsonld

Utilities for processing JSON-LD format.

Installation

Install using npm:

npm install @tangleid/jsonld

or using yarn:

yarn add @tangleid/jsonld

API Reference

jsonld~createDocumentLoader(documents)

ParamTypeDefaultDescription
documentsobject{}JSON-LD documents in initial cache.

Create JSON-LD document loader with cache.

jsonld~compact(document, context, options)

ParamTypeDefaultDescription
documentobjectJSON-LD document to compacted.
contextcontextthe context to compact with.
optionsobject{}Options of the compaction.
options.basestringthe base IRI to use.
options.compactArraysbooleantruetrue to compact arrays to single values when appropriate, false not to (default: true).
options.compactToRelativebooleantruetrue to compact IRIs to be relative to document base, false to keep absolute (default: true)
options.graphbooleanfalsetrue to always output a top-level graph (default: false).
options.expandContextcontexta context to expand with.
options.skipExpansionbooleanfalsetrue to assume the document is expanded and skip expansion, false not to, defaults to false.
options.documentLoaderdocumentLoaderthe document loader.
options.expansionMapexpansionMapa function that can be used to custom map unmappable values (or to throw an error when they are detected); if this function returns undefined then the default behavior will be used.
options.framingbooleanfalsetrue if compaction is occuring during a framing operation.
options.compactionMapcompactionMapa function that can be used to custom map unmappable values (or to throw an error when they are detected); if this function returns undefined then the default behavior will be used.

Compact JSON-LD document with context.

Returns: Promise.<object> - Promise that resolves to the compacted document.

jsonld~expand(document, options)

ParamTypeDefaultDescription
documentobjectJSON-LD document to expand.
optionsobject{}the options of the expansion.
options.basestringthe base IRI to use.
options.expandContextobjecta context to expand with.
options.keepFreeFloatingNodesbooleanfalsetrue to keep free-floating nodes, false not to
options.documentLoaderdocumentLoaderthe document loader.
options.expansionMapexpansionMapa function that can be used to custom map unmappable values (or to throw an error when they are detected); if this function returns undefined then the default behavior will be used.

Expand JSON-LD document and removes the context.

Returns: Promise.<object> - Promise that resolves to the expanded document.

jsonld~canonize(input, options)

ParamTypeDefaultDescription
inputobjectthe input to normalize as JSON-LD or as a format specified by the 'inputFormat' option.
optionsobject{}the options to use:
options.algorithmstring"URDNA2015"the normalization algorithm to use, URDNA2015 or URGNA2012.
options.basestringthe base IRI to use.
options.expandContextcontexta context to expand with.
options.skipExpansionbooleanfalsetrue to assume the input is expanded and skip expansion, false not to, defaults to false.
options.inputFormatstringthe format if input is not JSON-LD: 'application/n-quads' for N-Quads.
options.formatstringthe format if output is a string: 'application/n-quads' for N-Quads.
options.documentLoaderdocumentLoaderthe document loader.
options.useNativebooleanfalsetrue to use a native canonize algorithm

Performs RDF dataset normalization on the given input. The input is JSON-LD unless the 'inputFormat' option is used. The output is an RDF dataset unless the 'format' option is used.

Returns: Promise.<string> - a Promise that resolves to the normalized output.

jsonld~flatten(input, context, options)

ParamTypeDefaultDescription
inputobjectthe JSON-LD to flatten.
contextcontextthe context to use to compact the flattened output, or null.
optionsobject{}the options to use:
options.basestringthe base IRI to use.
options.expandContextcontexta context to expand with.
options.documentLoaderdocumentLoaderthe document loader.

Performs JSON-LD flattening.

Returns: Promise.<object> - Promise that resolves to the flattened output.

jsonld~frame(input, frame, options)

ParamTypeDefaultDescription
inputobjectthe JSON-LD input to frame.
frameobjectthe JSON-LD frame to use.
optionsobject{}the framing options.
options.basestringthe base IRI to use.
options.expandContextcontexta context to expand with.
options.embedstring"'@last'"default @embed flag: '@last', '@always', '@never', '@link' (default: '@last').
options.explicitbooleanfalsedefault @explicit flag (default: false).
options.requireAllbooleantruedefault @requireAll flag (default: true).
options.omitDefaultbooleanfalsedefault @omitDefault flag (default: false).
options.documentLoaderdocumentLoaderthe document loader.

Performs JSON-LD framing.

Returns: Promise.<object> - Promise that resolves to the framed output.

jsonld~findNodeById(document, id)

ParamTypeDescription
documentobjectthe JSON-LD document to find.
idstringString that specifies the ID value.

Returns the first node with the specified value of the ID attribute.

Returns: Promise.<(object|null)> - Promise that resolves to the node.

jsonld~generateRsaKeyPair(options)

ParamTypeDescription
optionsobjectGenerate key pair options.
options.bitsnumberKey length.

Generate RSA key pair in PEM-formatted.

Returns: object - RSA Key pair.

jsonld~signRsaSignature(document, publicKey, privateKeyPem, options)

ParamTypeDescription
documentobjectJSON-LD document to be signed.
publicKeyPublicKeyMetaPublic key metadata.
privateKeyPemstringPEM-formatted private key.
optionsobjectOptions for signing the document.
options.documentLoaderobjectLoader that retrieve external documents.

Sign JSON-LD document with RSA crypto suite.

Returns: Promise.<object> - Promise object represents signed JSON-LD document.

jsonld~verifyRsaSignature(document, options)

ParamTypeDescription
documentobjectJSON-LD document to be verify.
optionsobjectOptions for verifying the signature.
options.documentLoaderobjectLoader that retrieve external documents.

Verify JSON-LD document signature.

Returns: Promise.<boolean> - Promise object represents verification result.