@tangleid/jsonld v1.2.0
@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)
Param | Type | Default | Description |
---|---|---|---|
documents | object | {} | JSON-LD documents in initial cache. |
Create JSON-LD document loader with cache.
jsonld~compact(document, context, options)
Param | Type | Default | Description |
---|---|---|---|
document | object | JSON-LD document to compacted. | |
context | context | the context to compact with. | |
options | object | {} | Options of the compaction. |
options.base | string | the base IRI to use. | |
options.compactArrays | boolean | true | true to compact arrays to single values when appropriate, false not to (default: true). |
options.compactToRelative | boolean | true | true to compact IRIs to be relative to document base, false to keep absolute (default: true) |
options.graph | boolean | false | true to always output a top-level graph (default: false). |
options.expandContext | context | a context to expand with. | |
options.skipExpansion | boolean | false | true to assume the document is expanded and skip expansion, false not to, defaults to false. |
options.documentLoader | documentLoader | the document loader. | |
options.expansionMap | expansionMap | a 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.framing | boolean | false | true if compaction is occuring during a framing operation. |
options.compactionMap | compactionMap | a 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)
Param | Type | Default | Description |
---|---|---|---|
document | object | JSON-LD document to expand. | |
options | object | {} | the options of the expansion. |
options.base | string | the base IRI to use. | |
options.expandContext | object | a context to expand with. | |
options.keepFreeFloatingNodes | boolean | false | true to keep free-floating nodes, false not to |
options.documentLoader | documentLoader | the document loader. | |
options.expansionMap | expansionMap | a 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)
Param | Type | Default | Description |
---|---|---|---|
input | object | the input to normalize as JSON-LD or as a format specified by the 'inputFormat' option. | |
options | object | {} | the options to use: |
options.algorithm | string | "URDNA2015" | the normalization algorithm to use, URDNA2015 or URGNA2012 . |
options.base | string | the base IRI to use. | |
options.expandContext | context | a context to expand with. | |
options.skipExpansion | boolean | false | true to assume the input is expanded and skip expansion, false not to, defaults to false. |
options.inputFormat | string | the format if input is not JSON-LD: 'application/n-quads' for N-Quads. | |
options.format | string | the format if output is a string: 'application/n-quads' for N-Quads. | |
options.documentLoader | documentLoader | the document loader. | |
options.useNative | boolean | false | true 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)
Param | Type | Default | Description |
---|---|---|---|
input | object | the JSON-LD to flatten. | |
context | context | the context to use to compact the flattened output, or null. | |
options | object | {} | the options to use: |
options.base | string | the base IRI to use. | |
options.expandContext | context | a context to expand with. | |
options.documentLoader | documentLoader | the document loader. |
Performs JSON-LD flattening.
Returns: Promise.<object> - Promise that resolves to the flattened output.
jsonld~frame(input, frame, options)
Param | Type | Default | Description |
---|---|---|---|
input | object | the JSON-LD input to frame. | |
frame | object | the JSON-LD frame to use. | |
options | object | {} | the framing options. |
options.base | string | the base IRI to use. | |
options.expandContext | context | a context to expand with. | |
options.embed | string | "'@last'" | default @embed flag: '@last', '@always', '@never', '@link' (default: '@last'). |
options.explicit | boolean | false | default @explicit flag (default: false). |
options.requireAll | boolean | true | default @requireAll flag (default: true). |
options.omitDefault | boolean | false | default @omitDefault flag (default: false). |
options.documentLoader | documentLoader | the document loader. |
Performs JSON-LD framing.
Returns: Promise.<object> - Promise that resolves to the framed output.
jsonld~findNodeById(document, id)
Param | Type | Description |
---|---|---|
document | object | the JSON-LD document to find. |
id | string | String 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)
Param | Type | Description |
---|---|---|
options | object | Generate key pair options. |
options.bits | number | Key length. |
Generate RSA key pair in PEM-formatted.
Returns: object - RSA Key pair.
jsonld~signRsaSignature(document, publicKey, privateKeyPem, options)
Param | Type | Description |
---|---|---|
document | object | JSON-LD document to be signed. |
publicKey | PublicKeyMeta | Public key metadata. |
privateKeyPem | string | PEM-formatted private key. |
options | object | Options for signing the document. |
options.documentLoader | object | Loader 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)
Param | Type | Description |
---|---|---|
document | object | JSON-LD document to be verify. |
options | object | Options for verifying the signature. |
options.documentLoader | object | Loader that retrieve external documents. |
Verify JSON-LD document signature.
Returns: Promise.<boolean> - Promise object represents verification result.