@lde/docgen 0.6.15 → 0.6.16
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.
- package/dist/parse.d.ts.map +1 -1
- package/dist/parse.js +25 -1
- package/package.json +1 -1
package/dist/parse.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAOpD,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAqB7E"}
|
package/dist/parse.js
CHANGED
|
@@ -2,6 +2,7 @@ import { rdfDereferencer } from 'rdf-dereference';
|
|
|
2
2
|
import jsonld from 'jsonld';
|
|
3
3
|
import { rdfSerializer } from 'rdf-serialize';
|
|
4
4
|
import streamToString from 'stream-to-string';
|
|
5
|
+
const XSD_STRING = 'http://www.w3.org/2001/XMLSchema#string';
|
|
5
6
|
export async function parseRdfToJsonLd(filePath) {
|
|
6
7
|
const { data } = await rdfDereferencer.dereference(filePath, {
|
|
7
8
|
localFiles: true,
|
|
@@ -11,7 +12,30 @@ export async function parseRdfToJsonLd(filePath) {
|
|
|
11
12
|
contentType: 'application/n-quads',
|
|
12
13
|
});
|
|
13
14
|
const nqString = await streamToString(nq);
|
|
14
|
-
|
|
15
|
+
const expanded = await jsonld.fromRDF(nqString, {
|
|
15
16
|
useNativeTypes: true, // Convert xsd:integer to Number etc.
|
|
16
17
|
});
|
|
18
|
+
// jsonld v9 emits @type: xsd:string on every plain string literal; v8 omitted
|
|
19
|
+
// it because xsd:string is the JSON-LD default datatype. Without this strip,
|
|
20
|
+
// framing yields { @value, @type } objects that templates render as
|
|
21
|
+
// ‘[object Object]’. See https://github.com/ldelements/lde/issues/369.
|
|
22
|
+
return stripDefaultStringType(expanded);
|
|
23
|
+
}
|
|
24
|
+
function stripDefaultStringType(value) {
|
|
25
|
+
if (Array.isArray(value)) {
|
|
26
|
+
return value.map(stripDefaultStringType);
|
|
27
|
+
}
|
|
28
|
+
if (value && typeof value === 'object') {
|
|
29
|
+
const record = value;
|
|
30
|
+
if (record['@value'] !== undefined && record['@type'] === XSD_STRING) {
|
|
31
|
+
const { ['@type']: _, ...rest } = record;
|
|
32
|
+
return rest;
|
|
33
|
+
}
|
|
34
|
+
const result = {};
|
|
35
|
+
for (const key of Object.keys(record)) {
|
|
36
|
+
result[key] = stripDefaultStringType(record[key]);
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
17
41
|
}
|