Update to latest jsonld.js.
--- a/playground/jsonld.js Fri Feb 15 15:41:38 2013 -0500
+++ b/playground/jsonld.js Fri Feb 15 15:57:13 2013 -0500
@@ -35,8 +35,12 @@
*/
(function() {
-// define jsonld API
-var jsonld = {};
+// determine if in-browser or using node.js
+var _nodejs = (typeof module !== 'undefined');
+var _browser = !_nodejs;
+
+// attaches jsonld API to the given object
+var wrapper = function(jsonld) {
/* Core API */
@@ -1295,16 +1299,7 @@
delete _rdfParsers[contentType];
};
-// determine if in-browser or using node.js
-var _nodejs = (typeof module !== 'undefined');
-var _browser = !_nodejs;
-
-// export nodejs API
if(_nodejs) {
- module.exports = jsonld;
- // use node URL client by default
- jsonld.useUrlClient('node');
-
// needed for serialization of XML literals
if(typeof XMLSerializer === 'undefined') {
var XMLSerializer = null;
@@ -1327,17 +1322,6 @@
}
}
-// export AMD API
-if(typeof define === 'function' && define.amd) {
- define('jsonld', [], function() {
- return jsonld;
- });
-}
-// export simple browser API
-else if(_browser) {
- window.jsonld = window.jsonld || jsonld;
-}
-
// constants
var XSD_BOOLEAN = 'http://www.w3.org/2001/XMLSchema#boolean';
var XSD_DOUBLE = 'http://www.w3.org/2001/XMLSchema#double';
@@ -6143,4 +6127,37 @@
};
}
+if(_nodejs) {
+ // use node URL client by default
+ jsonld.useUrlClient('node');
+}
+
+// end of jsonld API factory
+return jsonld;
+};
+
+// external APIs:
+
+// used to generate a new jsonld API instance
+var factory = function() {
+ return wrapper({});
+};
+// the shared global jsonld API instance
+wrapper(factory);
+
+// export nodejs API
+if(_nodejs) {
+ module.exports = factory;
+}
+// export AMD API
+if(typeof define === 'function' && define.amd) {
+ define('jsonld', [], function() {
+ return factory;
+ });
+}
+// export simple browser API
+else if(_browser) {
+ window.jsonld = window.jsonld || factory;
+}
+
})();