@twin.org/data-json-ld 0.0.1-next.4 → 0.0.1-next.5

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.
@@ -1403,6 +1403,96 @@ class JsonLdHelper {
1403
1403
  }
1404
1404
  return validationFailures.length === 0;
1405
1405
  }
1406
+ }
1407
+
1408
+ // Copyright 2024 IOTA Stiftung.
1409
+ // SPDX-License-Identifier: Apache-2.0.
1410
+ /**
1411
+ * JSON-LD Processor.
1412
+ */
1413
+ class JsonLdProcessor {
1414
+ /**
1415
+ * The class name.
1416
+ * @internal
1417
+ */
1418
+ static _CLASS_NAME = "JsonLdProcessor";
1419
+ /**
1420
+ * Redirects to use during document resolution.
1421
+ */
1422
+ static _redirects = [];
1423
+ /**
1424
+ * The document loader to use.
1425
+ */
1426
+ static DOCUMENT_LOADER = async (url) => JsonLdProcessor.documentLoader(url);
1427
+ /**
1428
+ * Compact a document according to a particular context.
1429
+ * @param document The JSON-LD document to compact.
1430
+ * @param context The context to compact the document to, if not provided will try and gather from the object.
1431
+ * @returns The compacted JSON-LD document.
1432
+ */
1433
+ static async compact(document, context) {
1434
+ try {
1435
+ // There is a cast here because the jsonld types are not correct.
1436
+ // A context definition can be an array or an object, but the types only allow an object.
1437
+ if (core.Is.empty(context)) {
1438
+ context = {};
1439
+ if (core.Is.array(document)) {
1440
+ for (const node of document) {
1441
+ context = JsonLdProcessor.gatherContexts(node, context);
1442
+ }
1443
+ }
1444
+ else if (core.Is.array(document["@graph"])) {
1445
+ for (const node of document["@graph"]) {
1446
+ context = JsonLdProcessor.gatherContexts(node, context);
1447
+ }
1448
+ }
1449
+ else if (core.Is.object(document)) {
1450
+ context = JsonLdProcessor.gatherContexts(document, context);
1451
+ }
1452
+ }
1453
+ const compacted = await jsonLd.compact(document, context, {
1454
+ documentLoader: JsonLdProcessor.DOCUMENT_LOADER
1455
+ });
1456
+ return compacted;
1457
+ }
1458
+ catch (err) {
1459
+ if (core.Is.object(err) &&
1460
+ err.name === "jsonld.InvalidUrl") {
1461
+ throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
1462
+ }
1463
+ throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "compact", undefined, err);
1464
+ }
1465
+ }
1466
+ /**
1467
+ * Expand a document, removing its context.
1468
+ * @param compacted The compacted JSON-LD document to expand.
1469
+ * @returns The expanded JSON-LD document.
1470
+ */
1471
+ static async expand(compacted) {
1472
+ try {
1473
+ const expanded = await jsonLd.expand(compacted, {
1474
+ documentLoader: JsonLdProcessor.DOCUMENT_LOADER
1475
+ });
1476
+ return expanded;
1477
+ }
1478
+ catch (err) {
1479
+ if (core.Is.object(err) &&
1480
+ err.name === "jsonld.InvalidUrl") {
1481
+ throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
1482
+ }
1483
+ throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "expand", undefined, err);
1484
+ }
1485
+ }
1486
+ /**
1487
+ * Add a redirect to use during document resolution.
1488
+ * @param from The URL to redirect from.
1489
+ * @param to The URL to redirect to.
1490
+ */
1491
+ static addRedirect(from, to) {
1492
+ if (!this._redirects.some(r => r.from === from)) {
1493
+ this._redirects.push({ from, to });
1494
+ }
1495
+ }
1406
1496
  /**
1407
1497
  * Extract a property from the JSON-LD.
1408
1498
  * @param nodeObject The JSON-LD node object to extract from.
@@ -1426,7 +1516,7 @@ class JsonLdHelper {
1426
1516
  * @param context2 The second JSON-LD context to combine.
1427
1517
  * @returns The combined context.
1428
1518
  */
1429
- static async combineContexts(context1, context2) {
1519
+ static combineContexts(context1, context2) {
1430
1520
  const combinedContext = [];
1431
1521
  if (core.Is.string(context1)) {
1432
1522
  if (!combinedContext.includes(context1)) {
@@ -1474,77 +1564,31 @@ class JsonLdHelper {
1474
1564
  }
1475
1565
  return combinedContext;
1476
1566
  }
1477
- }
1478
-
1479
- // Copyright 2024 IOTA Stiftung.
1480
- // SPDX-License-Identifier: Apache-2.0.
1481
- /**
1482
- * JSON-LD Processor.
1483
- */
1484
- class JsonLdProcessor {
1485
1567
  /**
1486
- * The class name.
1487
- * @internal
1568
+ * Gather all the contexts from the element and it's children.
1569
+ * @param element The element to gather the contexts from.
1570
+ * @param initial The initial context.
1571
+ * @returns The combined contexts.
1488
1572
  */
1489
- static _CLASS_NAME = "JsonLdProcessor";
1490
- /**
1491
- * Redirects to use during document resolution.
1492
- */
1493
- static _redirects = [];
1494
- /**
1495
- * The document loader to use.
1496
- */
1497
- static DOCUMENT_LOADER = async (url) => JsonLdProcessor.documentLoader(url);
1498
- /**
1499
- * Compact a document according to a particular context.
1500
- * @param document The JSON-LD document to compact.
1501
- * @param context The context to compact the document to.
1502
- * @returns The compacted JSON-LD document.
1503
- */
1504
- static async compact(document, context) {
1505
- try {
1506
- const compacted = await jsonLd.compact(document, context ?? {}, {
1507
- documentLoader: JsonLdProcessor.DOCUMENT_LOADER
1508
- });
1509
- return compacted;
1573
+ static gatherContexts(element, initial) {
1574
+ let combinedContexts = initial;
1575
+ if (!core.Is.empty(element["@context"])) {
1576
+ combinedContexts = JsonLdProcessor.combineContexts(initial, element["@context"]);
1510
1577
  }
1511
- catch (err) {
1512
- if (core.Is.object(err) &&
1513
- err.name === "jsonld.InvalidUrl") {
1514
- throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
1578
+ for (const prop of Object.keys(element)) {
1579
+ const value = element[prop];
1580
+ if (core.Is.object(value)) {
1581
+ combinedContexts = this.gatherContexts(value, combinedContexts);
1515
1582
  }
1516
- throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "compact", undefined, err);
1517
- }
1518
- }
1519
- /**
1520
- * Expand a document, removing its context.
1521
- * @param compacted The compacted JSON-LD document to expand.
1522
- * @returns The expanded JSON-LD document.
1523
- */
1524
- static async expand(compacted) {
1525
- try {
1526
- const expanded = await jsonLd.expand(compacted, {
1527
- documentLoader: JsonLdProcessor.DOCUMENT_LOADER
1528
- });
1529
- return expanded;
1530
- }
1531
- catch (err) {
1532
- if (core.Is.object(err) &&
1533
- err.name === "jsonld.InvalidUrl") {
1534
- throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
1583
+ else if (core.Is.array(value)) {
1584
+ for (const item of value) {
1585
+ if (core.Is.object(item)) {
1586
+ combinedContexts = this.gatherContexts(item, combinedContexts);
1587
+ }
1588
+ }
1535
1589
  }
1536
- throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "expand", undefined, err);
1537
- }
1538
- }
1539
- /**
1540
- * Add a redirect to use during document resolution.
1541
- * @param from The URL to redirect from.
1542
- * @param to The URL to redirect to.
1543
- */
1544
- static addRedirect(from, to) {
1545
- if (!this._redirects.some(r => r.from === from)) {
1546
- this._redirects.push({ from, to });
1547
1590
  }
1591
+ return combinedContexts;
1548
1592
  }
1549
1593
  /**
1550
1594
  * Document loader which uses a caching mechanism.
@@ -1,5 +1,5 @@
1
1
  import { DataTypeHandlerFactory, DataTypeHelper } from '@twin.org/data-core';
2
- import { Is, ObjectHelper, GeneralError } from '@twin.org/core';
2
+ import { Is, GeneralError, ObjectHelper } from '@twin.org/core';
3
3
  import { FetchHelper, HttpMethod, MimeTypes } from '@twin.org/web';
4
4
  import jsonLd from 'jsonld';
5
5
 
@@ -1401,6 +1401,96 @@ class JsonLdHelper {
1401
1401
  }
1402
1402
  return validationFailures.length === 0;
1403
1403
  }
1404
+ }
1405
+
1406
+ // Copyright 2024 IOTA Stiftung.
1407
+ // SPDX-License-Identifier: Apache-2.0.
1408
+ /**
1409
+ * JSON-LD Processor.
1410
+ */
1411
+ class JsonLdProcessor {
1412
+ /**
1413
+ * The class name.
1414
+ * @internal
1415
+ */
1416
+ static _CLASS_NAME = "JsonLdProcessor";
1417
+ /**
1418
+ * Redirects to use during document resolution.
1419
+ */
1420
+ static _redirects = [];
1421
+ /**
1422
+ * The document loader to use.
1423
+ */
1424
+ static DOCUMENT_LOADER = async (url) => JsonLdProcessor.documentLoader(url);
1425
+ /**
1426
+ * Compact a document according to a particular context.
1427
+ * @param document The JSON-LD document to compact.
1428
+ * @param context The context to compact the document to, if not provided will try and gather from the object.
1429
+ * @returns The compacted JSON-LD document.
1430
+ */
1431
+ static async compact(document, context) {
1432
+ try {
1433
+ // There is a cast here because the jsonld types are not correct.
1434
+ // A context definition can be an array or an object, but the types only allow an object.
1435
+ if (Is.empty(context)) {
1436
+ context = {};
1437
+ if (Is.array(document)) {
1438
+ for (const node of document) {
1439
+ context = JsonLdProcessor.gatherContexts(node, context);
1440
+ }
1441
+ }
1442
+ else if (Is.array(document["@graph"])) {
1443
+ for (const node of document["@graph"]) {
1444
+ context = JsonLdProcessor.gatherContexts(node, context);
1445
+ }
1446
+ }
1447
+ else if (Is.object(document)) {
1448
+ context = JsonLdProcessor.gatherContexts(document, context);
1449
+ }
1450
+ }
1451
+ const compacted = await jsonLd.compact(document, context, {
1452
+ documentLoader: JsonLdProcessor.DOCUMENT_LOADER
1453
+ });
1454
+ return compacted;
1455
+ }
1456
+ catch (err) {
1457
+ if (Is.object(err) &&
1458
+ err.name === "jsonld.InvalidUrl") {
1459
+ throw new GeneralError(JsonLdProcessor._CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
1460
+ }
1461
+ throw new GeneralError(JsonLdProcessor._CLASS_NAME, "compact", undefined, err);
1462
+ }
1463
+ }
1464
+ /**
1465
+ * Expand a document, removing its context.
1466
+ * @param compacted The compacted JSON-LD document to expand.
1467
+ * @returns The expanded JSON-LD document.
1468
+ */
1469
+ static async expand(compacted) {
1470
+ try {
1471
+ const expanded = await jsonLd.expand(compacted, {
1472
+ documentLoader: JsonLdProcessor.DOCUMENT_LOADER
1473
+ });
1474
+ return expanded;
1475
+ }
1476
+ catch (err) {
1477
+ if (Is.object(err) &&
1478
+ err.name === "jsonld.InvalidUrl") {
1479
+ throw new GeneralError(JsonLdProcessor._CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
1480
+ }
1481
+ throw new GeneralError(JsonLdProcessor._CLASS_NAME, "expand", undefined, err);
1482
+ }
1483
+ }
1484
+ /**
1485
+ * Add a redirect to use during document resolution.
1486
+ * @param from The URL to redirect from.
1487
+ * @param to The URL to redirect to.
1488
+ */
1489
+ static addRedirect(from, to) {
1490
+ if (!this._redirects.some(r => r.from === from)) {
1491
+ this._redirects.push({ from, to });
1492
+ }
1493
+ }
1404
1494
  /**
1405
1495
  * Extract a property from the JSON-LD.
1406
1496
  * @param nodeObject The JSON-LD node object to extract from.
@@ -1424,7 +1514,7 @@ class JsonLdHelper {
1424
1514
  * @param context2 The second JSON-LD context to combine.
1425
1515
  * @returns The combined context.
1426
1516
  */
1427
- static async combineContexts(context1, context2) {
1517
+ static combineContexts(context1, context2) {
1428
1518
  const combinedContext = [];
1429
1519
  if (Is.string(context1)) {
1430
1520
  if (!combinedContext.includes(context1)) {
@@ -1472,77 +1562,31 @@ class JsonLdHelper {
1472
1562
  }
1473
1563
  return combinedContext;
1474
1564
  }
1475
- }
1476
-
1477
- // Copyright 2024 IOTA Stiftung.
1478
- // SPDX-License-Identifier: Apache-2.0.
1479
- /**
1480
- * JSON-LD Processor.
1481
- */
1482
- class JsonLdProcessor {
1483
1565
  /**
1484
- * The class name.
1485
- * @internal
1566
+ * Gather all the contexts from the element and it's children.
1567
+ * @param element The element to gather the contexts from.
1568
+ * @param initial The initial context.
1569
+ * @returns The combined contexts.
1486
1570
  */
1487
- static _CLASS_NAME = "JsonLdProcessor";
1488
- /**
1489
- * Redirects to use during document resolution.
1490
- */
1491
- static _redirects = [];
1492
- /**
1493
- * The document loader to use.
1494
- */
1495
- static DOCUMENT_LOADER = async (url) => JsonLdProcessor.documentLoader(url);
1496
- /**
1497
- * Compact a document according to a particular context.
1498
- * @param document The JSON-LD document to compact.
1499
- * @param context The context to compact the document to.
1500
- * @returns The compacted JSON-LD document.
1501
- */
1502
- static async compact(document, context) {
1503
- try {
1504
- const compacted = await jsonLd.compact(document, context ?? {}, {
1505
- documentLoader: JsonLdProcessor.DOCUMENT_LOADER
1506
- });
1507
- return compacted;
1571
+ static gatherContexts(element, initial) {
1572
+ let combinedContexts = initial;
1573
+ if (!Is.empty(element["@context"])) {
1574
+ combinedContexts = JsonLdProcessor.combineContexts(initial, element["@context"]);
1508
1575
  }
1509
- catch (err) {
1510
- if (Is.object(err) &&
1511
- err.name === "jsonld.InvalidUrl") {
1512
- throw new GeneralError(JsonLdProcessor._CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
1576
+ for (const prop of Object.keys(element)) {
1577
+ const value = element[prop];
1578
+ if (Is.object(value)) {
1579
+ combinedContexts = this.gatherContexts(value, combinedContexts);
1513
1580
  }
1514
- throw new GeneralError(JsonLdProcessor._CLASS_NAME, "compact", undefined, err);
1515
- }
1516
- }
1517
- /**
1518
- * Expand a document, removing its context.
1519
- * @param compacted The compacted JSON-LD document to expand.
1520
- * @returns The expanded JSON-LD document.
1521
- */
1522
- static async expand(compacted) {
1523
- try {
1524
- const expanded = await jsonLd.expand(compacted, {
1525
- documentLoader: JsonLdProcessor.DOCUMENT_LOADER
1526
- });
1527
- return expanded;
1528
- }
1529
- catch (err) {
1530
- if (Is.object(err) &&
1531
- err.name === "jsonld.InvalidUrl") {
1532
- throw new GeneralError(JsonLdProcessor._CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
1581
+ else if (Is.array(value)) {
1582
+ for (const item of value) {
1583
+ if (Is.object(item)) {
1584
+ combinedContexts = this.gatherContexts(item, combinedContexts);
1585
+ }
1586
+ }
1533
1587
  }
1534
- throw new GeneralError(JsonLdProcessor._CLASS_NAME, "expand", undefined, err);
1535
- }
1536
- }
1537
- /**
1538
- * Add a redirect to use during document resolution.
1539
- * @param from The URL to redirect from.
1540
- * @param to The URL to redirect to.
1541
- */
1542
- static addRedirect(from, to) {
1543
- if (!this._redirects.some(r => r.from === from)) {
1544
- this._redirects.push({ from, to });
1545
1588
  }
1589
+ return combinedContexts;
1546
1590
  }
1547
1591
  /**
1548
1592
  * Document loader which uses a caching mechanism.
@@ -1,6 +1,6 @@
1
1
  import { type IValidationFailure } from "@twin.org/core";
2
2
  import { type ValidationMode } from "@twin.org/data-core";
3
- import type { IJsonLdContextDefinitionRoot, IJsonLdDocument, IJsonLdNodeObject } from "../models/IJsonLdDocument";
3
+ import type { IJsonLdDocument } from "../models/IJsonLdDocument";
4
4
  /**
5
5
  * Class to help with JSON LD.
6
6
  */
@@ -13,19 +13,4 @@ export declare class JsonLdHelper {
13
13
  * @returns True if the document was valid.
14
14
  */
15
15
  static validate<T extends IJsonLdDocument = IJsonLdDocument>(document: T, validationFailures: IValidationFailure[], validationMode?: ValidationMode): Promise<boolean>;
16
- /**
17
- * Extract a property from the JSON-LD.
18
- * @param nodeObject The JSON-LD node object to extract from.
19
- * @param propertyNames The possible names for the property.
20
- * @param deleteProperty Delete the property from the object, defaults to true.
21
- * @returns The properties if available.
22
- */
23
- static extractProperty<T>(nodeObject: IJsonLdNodeObject, propertyNames: string[], deleteProperty?: boolean): T | undefined;
24
- /**
25
- * Combine contexts.
26
- * @param context1 The first JSON-LD context to combine.
27
- * @param context2 The second JSON-LD context to combine.
28
- * @returns The combined context.
29
- */
30
- static combineContexts(context1: IJsonLdContextDefinitionRoot | undefined, context2: IJsonLdContextDefinitionRoot | undefined): Promise<IJsonLdContextDefinitionRoot | undefined>;
31
16
  }
@@ -1,5 +1,5 @@
1
1
  import type { RemoteDocument, Url } from "jsonld/jsonld-spec";
2
- import type { IJsonLdContextDefinition, IJsonLdDocument } from "../models/IJsonLdDocument";
2
+ import type { IJsonLdContextDefinitionRoot, IJsonLdDocument, IJsonLdNodeObject } from "../models/IJsonLdDocument";
3
3
  /**
4
4
  * JSON-LD Processor.
5
5
  */
@@ -15,10 +15,10 @@ export declare class JsonLdProcessor {
15
15
  /**
16
16
  * Compact a document according to a particular context.
17
17
  * @param document The JSON-LD document to compact.
18
- * @param context The context to compact the document to.
18
+ * @param context The context to compact the document to, if not provided will try and gather from the object.
19
19
  * @returns The compacted JSON-LD document.
20
20
  */
21
- static compact(document: IJsonLdDocument, context?: IJsonLdContextDefinition): Promise<IJsonLdDocument>;
21
+ static compact(document: IJsonLdDocument, context?: IJsonLdContextDefinitionRoot): Promise<IJsonLdDocument>;
22
22
  /**
23
23
  * Expand a document, removing its context.
24
24
  * @param compacted The compacted JSON-LD document to expand.
@@ -31,4 +31,28 @@ export declare class JsonLdProcessor {
31
31
  * @param to The URL to redirect to.
32
32
  */
33
33
  static addRedirect(from: RegExp, to: string): void;
34
+ /**
35
+ * Extract a property from the JSON-LD.
36
+ * @param nodeObject The JSON-LD node object to extract from.
37
+ * @param propertyNames The possible names for the property.
38
+ * @param deleteProperty Delete the property from the object, defaults to true.
39
+ * @returns The properties if available.
40
+ */
41
+ static extractProperty<T>(nodeObject: IJsonLdNodeObject, propertyNames: string[], deleteProperty?: boolean): T | undefined;
42
+ /**
43
+ * Combine contexts.
44
+ * @param context1 The first JSON-LD context to combine.
45
+ * @param context2 The second JSON-LD context to combine.
46
+ * @returns The combined context.
47
+ */
48
+ static combineContexts(context1: IJsonLdContextDefinitionRoot | undefined, context2: IJsonLdContextDefinitionRoot | undefined): IJsonLdContextDefinitionRoot | undefined;
49
+ /**
50
+ * Gather all the contexts from the element and it's children.
51
+ * @param element The element to gather the contexts from.
52
+ * @param initial The initial context.
53
+ * @returns The combined contexts.
54
+ */
55
+ static gatherContexts(element: {
56
+ [id: string]: unknown;
57
+ }, initial?: IJsonLdContextDefinitionRoot): IJsonLdContextDefinitionRoot | undefined;
34
58
  }
package/docs/changelog.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @twin.org/data-json-ld - Changelog
2
2
 
3
- ## v0.0.1-next.4
3
+ ## v0.0.1-next.5
4
4
 
5
5
  - Initial Release
@@ -43,59 +43,3 @@ The validation mode to use, defaults to either.
43
43
  `Promise`\<`boolean`\>
44
44
 
45
45
  True if the document was valid.
46
-
47
- ***
48
-
49
- ### extractProperty()
50
-
51
- > `static` **extractProperty**\<`T`\>(`nodeObject`, `propertyNames`, `deleteProperty`): `undefined` \| `T`
52
-
53
- Extract a property from the JSON-LD.
54
-
55
- #### Type Parameters
56
-
57
- • **T**
58
-
59
- #### Parameters
60
-
61
- • **nodeObject**: [`IJsonLdNodeObject`](../interfaces/IJsonLdNodeObject.md)
62
-
63
- The JSON-LD node object to extract from.
64
-
65
- • **propertyNames**: `string`[]
66
-
67
- The possible names for the property.
68
-
69
- • **deleteProperty**: `boolean` = `true`
70
-
71
- Delete the property from the object, defaults to true.
72
-
73
- #### Returns
74
-
75
- `undefined` \| `T`
76
-
77
- The properties if available.
78
-
79
- ***
80
-
81
- ### combineContexts()
82
-
83
- > `static` **combineContexts**(`context1`, `context2`): `Promise`\<`undefined` \| [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)\>
84
-
85
- Combine contexts.
86
-
87
- #### Parameters
88
-
89
- • **context1**: `undefined` \| [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)
90
-
91
- The first JSON-LD context to combine.
92
-
93
- • **context2**: `undefined` \| [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)
94
-
95
- The second JSON-LD context to combine.
96
-
97
- #### Returns
98
-
99
- `Promise`\<`undefined` \| [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)\>
100
-
101
- The combined context.
@@ -42,9 +42,9 @@ Compact a document according to a particular context.
42
42
 
43
43
  The JSON-LD document to compact.
44
44
 
45
- • **context?**: [`IJsonLdContextDefinition`](../interfaces/IJsonLdContextDefinition.md)
45
+ • **context?**: [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)
46
46
 
47
- The context to compact the document to.
47
+ The context to compact the document to, if not provided will try and gather from the object.
48
48
 
49
49
  #### Returns
50
50
 
@@ -93,3 +93,83 @@ The URL to redirect to.
93
93
  #### Returns
94
94
 
95
95
  `void`
96
+
97
+ ***
98
+
99
+ ### extractProperty()
100
+
101
+ > `static` **extractProperty**\<`T`\>(`nodeObject`, `propertyNames`, `deleteProperty`): `undefined` \| `T`
102
+
103
+ Extract a property from the JSON-LD.
104
+
105
+ #### Type Parameters
106
+
107
+ • **T**
108
+
109
+ #### Parameters
110
+
111
+ • **nodeObject**: [`IJsonLdNodeObject`](../interfaces/IJsonLdNodeObject.md)
112
+
113
+ The JSON-LD node object to extract from.
114
+
115
+ • **propertyNames**: `string`[]
116
+
117
+ The possible names for the property.
118
+
119
+ • **deleteProperty**: `boolean` = `true`
120
+
121
+ Delete the property from the object, defaults to true.
122
+
123
+ #### Returns
124
+
125
+ `undefined` \| `T`
126
+
127
+ The properties if available.
128
+
129
+ ***
130
+
131
+ ### combineContexts()
132
+
133
+ > `static` **combineContexts**(`context1`, `context2`): `undefined` \| [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)
134
+
135
+ Combine contexts.
136
+
137
+ #### Parameters
138
+
139
+ • **context1**: `undefined` \| [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)
140
+
141
+ The first JSON-LD context to combine.
142
+
143
+ • **context2**: `undefined` \| [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)
144
+
145
+ The second JSON-LD context to combine.
146
+
147
+ #### Returns
148
+
149
+ `undefined` \| [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)
150
+
151
+ The combined context.
152
+
153
+ ***
154
+
155
+ ### gatherContexts()
156
+
157
+ > `static` **gatherContexts**(`element`, `initial`?): `undefined` \| [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)
158
+
159
+ Gather all the contexts from the element and it's children.
160
+
161
+ #### Parameters
162
+
163
+ • **element**
164
+
165
+ The element to gather the contexts from.
166
+
167
+ • **initial?**: [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)
168
+
169
+ The initial context.
170
+
171
+ #### Returns
172
+
173
+ `undefined` \| [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)
174
+
175
+ The combined contexts.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/data-json-ld",
3
- "version": "0.0.1-next.4",
3
+ "version": "0.0.1-next.5",
4
4
  "description": "Models which define the structure of JSON LD",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@twin.org/core": "next",
18
- "@twin.org/data-core": "0.0.1-next.4",
18
+ "@twin.org/data-core": "0.0.1-next.5",
19
19
  "@twin.org/entity": "next",
20
20
  "@twin.org/nameof": "next",
21
21
  "@twin.org/web": "next",