@frogcat/ttl2jsonld 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +4 -5
  2. package/ttl2jsonld.js +5 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frogcat/ttl2jsonld",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "Turtle to JSON-LD converter for node.js and browser, no library dependencies",
5
5
  "main": "ttl2jsonld.js",
6
6
  "files": [
@@ -11,7 +11,7 @@
11
11
  "ttl2jsonld": "./bin/cli.js"
12
12
  },
13
13
  "scripts": {
14
- "test": "mocha",
14
+ "test": "tape test/*.js",
15
15
  "build": "pegjs -o ttl2jsonld.js --format umd --export-var ttl2jsonld spec/ttl2jsonld.pegjs",
16
16
  "spec-turtle": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/turtle/manifest.ttl -c .rdf-test-suite-cache/"
17
17
  },
@@ -32,10 +32,9 @@
32
32
  },
33
33
  "homepage": "https://github.com/frogcat/ttl2jsonld#readme",
34
34
  "devDependencies": {
35
- "chai": "^4.3.6",
36
35
  "jsonld-streaming-parser": "^2.4.3",
37
- "mocha": "^9.2.2",
38
36
  "pegjs": "^0.10.0",
39
- "rdf-test-suite": "^1.18.0"
37
+ "rdf-test-suite": "^1.18.0",
38
+ "tape": "^5.6.3"
40
39
  }
41
40
  }
package/ttl2jsonld.js CHANGED
@@ -4586,7 +4586,9 @@
4586
4586
  }
4587
4587
 
4588
4588
 
4589
- var URL = typeof require === 'undefined' ? URL : require("url").URL;
4589
+ var isBrowser=new Function("try {return this===window;}catch(e){ return false;}");
4590
+ var URL = isBrowser() ? window.URL : require("url").URL;
4591
+ var isIRI = function(a){return a.match(/^[a-z](.*?):(.+?)/g);};
4590
4592
  function createObject(property,value){var a={};a[property]=value;return a;}
4591
4593
  var context = {
4592
4594
  base : [],
@@ -4614,7 +4616,7 @@
4614
4616
  const prefix = Object.keys(context.data).find(key=>pname.indexOf(key+":")===0);
4615
4617
  if(prefix!==undefined) {
4616
4618
  const list = context.data[prefix];
4617
- if(list.length===1 && force!==true) return pname;
4619
+ if(list.length===1 && force!==true && isIRI(list[0].uri)) return pname;
4618
4620
  const uri = list[list.length-1].uri;
4619
4621
  return pname.replace(prefix+":",uri);
4620
4622
  }else{
@@ -4641,6 +4643,7 @@
4641
4643
  Object.keys(context.data).forEach(key=>{
4642
4644
  const head = context.data[key][0];
4643
4645
  if(head.uri==="http://www.w3.org/2001/XMLSchema#" && head.count < 1) return;
4646
+ if(!isIRI(head.uri)) return;
4644
4647
  if(root["@context"]===undefined) root["@context"] = {};
4645
4648
  root["@context"][key] = head.uri;
4646
4649
  });