jsonld
Version:
A JSON-LD Processor and API implementation in JavaScript.
40 lines (35 loc) • 871 B
JavaScript
/*
* Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
*/
;
const xhrLoader = require('./documentLoaders/xhr');
const api = {};
module.exports = api;
/**
* Setup browser document loaders.
*
* @param jsonld the jsonld api.
*/
api.setupDocumentLoaders = function(jsonld) {
if(typeof XMLHttpRequest !== 'undefined') {
jsonld.documentLoaders.xhr = xhrLoader;
// use xhr document loader by default
jsonld.useDocumentLoader('xhr');
}
};
/**
* Setup browser globals.
*
* @param jsonld the jsonld api.
*/
api.setupGlobals = function(jsonld) {
// setup browser global JsonLdProcessor
if(typeof globalThis.JsonLdProcessor === 'undefined') {
Object.defineProperty(globalThis, 'JsonLdProcessor', {
writable: true,
enumerable: false,
configurable: true,
value: jsonld.JsonLdProcessor
});
}
};