Skip to content

Commit

Permalink
Update documentation.
Browse files Browse the repository at this point in the history
- Update supported Node.js version in README.
- Add notes about document being cloned.
- Add docs for `addStatic`.
- Update changelog with more details about cloning and potential need
  for a polyfill.
  • Loading branch information
davidlehn committed Jun 6, 2024
1 parent 2f03bea commit b0bc444
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# jsonld-document-loader

## 2.0.1 -
## 2.1.0 - 2024-xx-xx

### Changed
- `addStatic` deep clones documents to avoid mutation.
- Use of [structuredClone](https://developer.mozilla.org/en-US/docs/Web/API/structuredClone) might require polyfill.
- `addStatic` deep clones documents to avoid shared document mutation issues.
- The clone adds potential time and memory use considerations depending on
the frequency of `addStatic` calls and on document size. For expected use
cases this should be minimal.
- [structuredClone](https://developer.mozilla.org/en-US/docs/Web/API/structuredClone)
is used and may not be available in old browsers and Node.js before v17.
Use a polyfill if needed.

## 2.0.0 - 2023-02-06

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ TBD

## Install

- Node.js >= 16 is required.
- Node.js >= 18 is required.

### NPM

Expand Down Expand Up @@ -57,7 +57,7 @@ const loader = new JsonLdDocumentLoader();

The `addStatic()` method allows developers to load fixed static contexts and
documents, to ensure known versions and contents, without going out to the
network.
network. The context is cloned when added.

For example, to add support for the DID Core context, the VC context, and crypto
suite specific contexts:
Expand Down
9 changes: 9 additions & 0 deletions lib/JsonLdDocumentLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ export class JsonLdDocumentLoader {
this.protocolHandlers = new Map();
}

/**
* Adds a URL to document mapping to the loader.
*
* The document will be cloned.
*
* @param {string} url - The URL of a document,
* etc.
* @param {object} document -The document.
*/
addStatic(url, document) {
if(!_isString(url)) {
throw new TypeError('The first parameter (url) must be a string.');
Expand Down

0 comments on commit b0bc444

Please sign in to comment.