npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tangleid/jsonld

v1.2.0

Published

Utilities for processing JSON-LD format

Downloads

2

Readme

@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.