diff --git a/docs/_layouts/redirect.html b/docs/_layouts/redirect.html new file mode 100644 index 0000000..b07ec26 --- /dev/null +++ b/docs/_layouts/redirect.html @@ -0,0 +1,14 @@ + + +
+ + + +API documentation for latest version
+ + \ No newline at end of file diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..5a06173 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,4 @@ +--- +layout: redirect +target: ./v3.4 +--- diff --git a/docs/v3.0/.nojekyll b/docs/v3.0/.nojekyll new file mode 100644 index 0000000..e2ac661 --- /dev/null +++ b/docs/v3.0/.nojekyll @@ -0,0 +1 @@ +TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false. \ No newline at end of file diff --git a/docs/v3.0/assets/highlight.css b/docs/v3.0/assets/highlight.css new file mode 100644 index 0000000..e40c908 --- /dev/null +++ b/docs/v3.0/assets/highlight.css @@ -0,0 +1,78 @@ +:root { + --light-hl-0: #001080; + --dark-hl-0: #9CDCFE; + --light-hl-1: #000000; + --dark-hl-1: #D4D4D4; + --light-hl-2: #0000FF; + --dark-hl-2: #569CD6; + --light-hl-3: #0070C1; + --dark-hl-3: #4FC1FF; + --light-hl-4: #795E26; + --dark-hl-4: #DCDCAA; + --light-hl-5: #A31515; + --dark-hl-5: #CE9178; + --light-hl-6: #008000; + --dark-hl-6: #6A9955; + --light-hl-7: #098658; + --dark-hl-7: #B5CEA8; + --light-code-background: #FFFFFF; + --dark-code-background: #1E1E1E; +} + +@media (prefers-color-scheme: light) { :root { + --hl-0: var(--light-hl-0); + --hl-1: var(--light-hl-1); + --hl-2: var(--light-hl-2); + --hl-3: var(--light-hl-3); + --hl-4: var(--light-hl-4); + --hl-5: var(--light-hl-5); + --hl-6: var(--light-hl-6); + --hl-7: var(--light-hl-7); + --code-background: var(--light-code-background); +} } + +@media (prefers-color-scheme: dark) { :root { + --hl-0: var(--dark-hl-0); + --hl-1: var(--dark-hl-1); + --hl-2: var(--dark-hl-2); + --hl-3: var(--dark-hl-3); + --hl-4: var(--dark-hl-4); + --hl-5: var(--dark-hl-5); + --hl-6: var(--dark-hl-6); + --hl-7: var(--dark-hl-7); + --code-background: var(--dark-code-background); +} } + +:root[data-theme='light'] { + --hl-0: var(--light-hl-0); + --hl-1: var(--light-hl-1); + --hl-2: var(--light-hl-2); + --hl-3: var(--light-hl-3); + --hl-4: var(--light-hl-4); + --hl-5: var(--light-hl-5); + --hl-6: var(--light-hl-6); + --hl-7: var(--light-hl-7); + --code-background: var(--light-code-background); +} + +:root[data-theme='dark'] { + --hl-0: var(--dark-hl-0); + --hl-1: var(--dark-hl-1); + --hl-2: var(--dark-hl-2); + --hl-3: var(--dark-hl-3); + --hl-4: var(--dark-hl-4); + --hl-5: var(--dark-hl-5); + --hl-6: var(--dark-hl-6); + --hl-7: var(--dark-hl-7); + --code-background: var(--dark-code-background); +} + +.hl-0 { color: var(--hl-0); } +.hl-1 { color: var(--hl-1); } +.hl-2 { color: var(--hl-2); } +.hl-3 { color: var(--hl-3); } +.hl-4 { color: var(--hl-4); } +.hl-5 { color: var(--hl-5); } +.hl-6 { color: var(--hl-6); } +.hl-7 { color: var(--hl-7); } +pre, code { background: var(--code-background); } diff --git a/docs/v3.0/assets/main.js b/docs/v3.0/assets/main.js new file mode 100644 index 0000000..abd0485 --- /dev/null +++ b/docs/v3.0/assets/main.js @@ -0,0 +1,54 @@ +"use strict"; +"use strict";(()=>{var Qe=Object.create;var ae=Object.defineProperty;var Pe=Object.getOwnPropertyDescriptor;var Ce=Object.getOwnPropertyNames;var Oe=Object.getPrototypeOf,Re=Object.prototype.hasOwnProperty;var _e=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Me=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Ce(e))!Re.call(t,i)&&i!==n&&ae(t,i,{get:()=>e[i],enumerable:!(r=Pe(e,i))||r.enumerable});return t};var De=(t,e,n)=>(n=t!=null?Qe(Oe(t)):{},Me(e||!t||!t.__esModule?ae(n,"default",{value:t,enumerable:!0}):n,t));var de=_e((ce,he)=>{(function(){var t=function(e){var n=new t.Builder;return n.pipeline.add(t.trimmer,t.stopWordFilter,t.stemmer),n.searchPipeline.add(t.stemmer),e.call(n,n),n.build()};t.version="2.3.9";t.utils={},t.utils.warn=function(e){return function(n){e.console&&console.warn&&console.warn(n)}}(this),t.utils.asString=function(e){return e==null?"":e.toString()},t.utils.clone=function(e){if(e==null)return e;for(var n=Object.create(null),r=Object.keys(e),i=0;iGenerated using TypeDoc
Generated using TypeDoc
Create a new ROCrate object using a default template or from a valid jsonld object.
+a valid jsonld object
+Always return property of an Entity as an array (eg when using getEntity() method)
+Allow duplicate values in a property that has multiple values
+Resolve linked node as nested object
+When replacing or updating an entity, merge the values and the properties instead of full replace
+When importing from json, a subsequent duplicate entity always replaces the existing one
+Import Utils class directly
+Static
defaultsThe context part of the crate. An alias for '@context'. +Calling this method before and after resolveContext may give different result.
+An array of all nodes in the graph. An alias for '@graph'
+ +Add an entity to the crate.
+ +true if the entity is successfully added.
+A valid RO-Crate entity described in plain object.
+Optional
replace: boolean = ...If true, replace existing entity with the same id.
+Optional
recurse: booleanIf true, nested entities will be added as well.
+Add a new identifier as a PropertyValue to the root DataSet. +identifier and name are required
+ +The added identifier or undefined
+This silently fails if the item has no
+ +or already exists - this is probably sub-optimal
+ +Use addEntity
+Add one or more value to a property of an entity. +If the specified property does not exists, a new one will be set. +If the property already exists, the new value will be added to the property array.
+The id or the entity to add the property to
+The name of the property
+The value of the property
+Optional
duplicate: booleanIf true, allow a property to have duplicate values in the array
+Use updateEntityId
+Use union, eg: union([sg1, sg2])
+Delete an entity from the graph
+ +If success, return the raw data of deleted entity
+Entity Identifier or the entity object itself
+Optional
deleteRefs: booleanSet true to delete all references to the deleted entity
+Get an entity from the graph. +If config.link is true, any reference (object with just "@id" property) +is resolved as a nested object.
+ +A wrapper for entity that resolves properties as linked objects
+An entity identifier
+Use getGraph with argument set to true
+Get an array of all nodes in the graph. Each node in the array is an Entity instance. +If config.link is true, any link to other node will be made into nested object.
+ +If true, return the internal representation as plain object.
+Use toJSON
+Use getIdentifier
+Use getTree with the following argument: { root, depth, allowCycle: true }
Use rootDataset
+Use rootId
+Return a JSON.stringify-ready tree structure starting from the specified item
+with all values (apart from @id) as arrays
+and string-values expressed like: {"@value": "string-value"}
the root entity
+The number of nesting the tree will have. Must be 0 or positive integer.
+Create a simple tree-like object - but don't make circular structures
+ +Use getTree with the valueObject argument set to false`
+null, or an array of items
+A JSON-LD item or array of [item]
+An array of objects that represents a 'path' through the graph.
+ Object must have a "property" to follow, eg:
+ resolve(item, {"property": "miltaryService"});
+ and optionally a condition "includes", eg:
+ "includes": {"@type", "Action"}}
+ and optionally, a function "matchFn" which takes an item
+ as argument and returns a boolean, eg:
+ "matchFn": (item) => item['@id'].match(/anzsrc-for/)
Optional
subgraph: any[]If present and true, all intervening items during + the traversal will be stored. If an array is passed, the intervening items will be + stored in the array.
+Use getGraph and pass true as the argument
+Set a property of an entity with the given value. +If a property with the same name exists, its existing value will be replaced with the specified value. +If values contain nested non-empty entities, they will be processed recursively.
+The id of the entity to add the property to
+The name of the property
+A value or an array of values
+Optional
duplicate: booleanIf true, allow a property to have duplicate values
+Update an entity by replacing the object with the same id.
+This operations will remove all properties of the existing entity and
+add the new ones contained in data
, unless merge
argument is true.
false if there is no existing entity with the same id or data is empty.
+Optional
merge: boolean = ...If true, new properties will be merged. Defaults to config.merge
.
Optional
recurse: booleanIf true, nested entities will be updated as well.
+Generated using TypeDoc
Utility functions for JSON-LD
+Static
addStatic
addStatic
asStatic
asStatic
cloneStatic
countStatic
existsStatic
hasStatic
hasStatic
isStatic
isStatic
unionGenerated using TypeDoc
This is a JavaScript library to create and manipulate Research Object Crate.
+ + +Install the library:
+npm install rocrate
+
+
+
+ Import the ROCrate
class and create a new empty crate with default configurations:
const {ROCrate} = require('ro-crate');
const crate = new ROCrate();
+
+The ROCrate
constructor accepts two optional arguments:
const fs = require('fs');
// load existing metadata
const data = JSON.parse(fs.readFileSync('ro-crate-metadata.json', 'utf8'));
// create a crate using the existing data and
// configure the crate to return a property of an Entity as an array and resolve linked entity as nested object
const crate = new ROCrate(data, { array: true, link: true });
+
+To add an Entity to the crate:
+// A license
const license = {
'@id': 'https://creativecommons.org/licenses/by/4.0/',
'@type': 'CreativeWork',
'description': 'Attribution 4.0 International (CC BY 4.0) ...',
'name': 'CC BY 4.0'
};
// add the license as an unconnected Entity
crate.addEntity(license);
// add the license to the root dataset
crate.rootDataset.license = {'@id': license['@id']};
// or alternatively, add a new entity directly into a property of other entity :
crate.rootDataset.license = license;
+
+Use an entity just like a normal object:
+let lic = create.getEntity(license['@id']);
console.log(lic.name); // prints 'CC BY 4.0';
// set a property directly
lic.name = 'CC BY 4.0 dummy';
// or with the setProperty method
crate.setProperty(license['@id'], 'name', 'CC BY 4.0 dummy');
console.log(lic.name); // prints 'CC BY 4.0 dummy';
+
+Modifying an array of values in the property is not supported yet:
+lic.test = [1,2,3];
lic.test.push(4); // this does not work
console.log(lic.test); // prints '[1,2,3]';
// use this instead
lic.test = lic.test.concat(4);
// or this
crate.addValues(license['@id'], 'test', 4);
+
+Root Dataset is a special entity that is mandated by the standard:
+const rootDataset = crate.rootDataset;
rootDataset.name = 'Tutorial Crate';
rootDataset.description = 'This is an example crate for educational purposes.'
const today = new Date().toISOString().split('T')[0]
rootDataset.datePublished = today;
+
+The value of the returned property can be set to be always as an array:
+const crate1 = new ROCrate();
const crate2 = new ROCrate({array: true});
crate1.rootDataset.name = 'Tutorial Crate';
crate1.rootDataset.test = ['test1', 'test2'];
crate2.rootDataset.name = 'Tutorial Crate';
crate2.rootDataset.test = ['test1', 'test2'];
console.log(crate1.rootDataset.name); // return 'Tutorial Crate'
console.log(crate1.rootDataset.name); // return ['test1', 'test2']
console.log(crate2.rootDataset.name); // return ['Tutorial Crate']
console.log(crate2.rootDataset.name); // return ['test1', 'test2']
+
+Linked entities can be automatically resolved as nested objects:
+const crate1 = new ROCrate();
const crate2 = new ROCrate({link: true});
const crate3 = new ROCrate({link: true, array: true});
crate1.rootDataset.license = license;
crate2.rootDataset.license = license;
crate3.rootDataset.license = license;
console.log(crate1.rootDataset.license.name); // return undefined
console.log(crate1.rootDataset.license); // return {'@id': 'https://creativecommons.org/licenses/by/4.0/'}
console.log(crate2.rootDataset.license.name); // return 'CC BY 4.0'
console.log(crate3.rootDataset.license.name); // return undefined, property license is a array
console.log(crate3.rootDataset.license[0].name); // return 'CC BY 4.0'
+
+To save the rocrate data to a file, use JSON.stringify
:
// Write pretty-printed JSONLD into the directory
fs.writeFileSync('ro-crate-metadata.json', JSON.stringify(crate, null, 2));
+
+For more details, refer to the full API documentation.
For more usage examples, see the test files under the test directory.
Use the RO-Crate-HTML to generate a HTML preview from the RO-Crate Metadata File ro-crate-metadata.json
.
There is a script included with this library that can check crates.
+Check a crate:
+roccheck /path/to/crate/directory
This is produce a simple report.
+Generated using TypeDoc
Generated using TypeDoc
Generated using TypeDoc
Generated using TypeDoc
Generated using TypeDoc
Generated using TypeDoc
Class for building, navigating, testing and rendering ROCrates
+ +import validation and rendering from Calcyte
+Create a new ROCrate object using a default template or from a valid jsonld object.
+a valid jsonld object
+Always return property of an Entity as an array (eg when using getEntity() method)
+Allow duplicate values in a property that has multiple values
+Resolve linked node as nested object
+When replacing or updating an entity, merge the values and the properties instead of full replace
+When importing from json, a subsequent duplicate entity always replaces the existing one
+Import Utils class directly
+Static
defaultsThe context part of the crate. An alias for '@context'. +This returns the original context information.
+An array of all nodes in the graph. An alias for '@graph'
+ +Add an entity to the crate.
+ +true if the entity is successfully added.
+A valid RO-Crate entity described in plain object.
+Optional
replace: boolean = ...If true, replace existing entity with the same id.
+Optional
recurse: booleanIf true, nested entities will be added as well.
+Add a new identifier as a PropertyValue to the root DataSet. +identifier and name are required
+ +The added identifier or undefined
+This silently fails if the item has no
+ +or already exists - this is probably sub-optimal
+ +Use addEntity
+Add one or more value to a property of an entity. +If the specified property does not exists, a new one will be set. +If the property already exists, the new value will be added to the property array.
+The id or the entity to add the property to
+The name of the property
+The value of the property
+Optional
duplicate: booleanIf true, allow a property to have duplicate values in the array
+Use updateEntityId
+Use union, eg: union([sg1, sg2])
+Delete an entity from the graph
+ +If success, return the raw data of deleted entity
+Entity Identifier or the entity object itself
+Optional
deleteRefs: booleanSet true to delete all references to the deleted entity
+Get an entity from the graph. +If config.link is true, any reference (object with just "@id" property) +is resolved as a nested object.
+ +A wrapper for entity that resolves properties as linked objects
+An entity identifier
+Use getGraph with argument set to true
+Get an array of all nodes in the graph. Each node in the array is an Entity instance. +If config.link is true, any link to other node will be made into nested object.
+ +If true, return the internal representation as plain object.
+Use toJSON
+Use getIdentifier
+Use getTree with the following argument: { root, depth, allowCycle: true }
Use rootDataset
+Use rootId
+Return a JSON.stringify-ready tree structure starting from the specified item
+with all values (apart from @id) as arrays
+and string-values expressed like: {"@value": "string-value"}
the root entity
+The number of nesting the tree will have. Must be 0 or positive integer.
+Create a simple tree-like object - but don't make circular structures
+ +Use getTree with the valueObject argument set to false`
+null, or an array of items
+A JSON-LD item or array of [item]
+An array of objects that represents a 'path' through the graph.
+ Object must have a "property" to follow, eg:
+ resolve(item, {"property": "miltaryService"});
+ and optionally a condition "includes", eg:
+ "includes": {"@type", "Action"}}
+ and optionally, a function "matchFn" which takes an item
+ as argument and returns a boolean, eg:
+ "matchFn": (item) => item['@id'].match(/anzsrc-for/)
Optional
subgraph: any[]If present and true, all intervening items during + the traversal will be stored. If an array is passed, the intervening items will be + stored in the array.
+Use getGraph and pass true as the argument
+Set a property of an entity with the given value. +If a property with the same name exists, its existing value will be replaced with the specified value. +If values contain nested non-empty entities, they will be processed recursively.
+The id of the entity to add the property to
+The name of the property
+A value or an array of values
+Optional
duplicate: booleanIf true, allow a property to have duplicate values
+Update an entity by replacing the object with the same id.
+This operations will remove all properties of the existing entity and
+add the new ones contained in data
, unless merge
argument is true.
false if there is no existing entity with the same id or data is empty.
+Optional
merge: boolean = ...If true, new properties will be merged. Defaults to config.merge
.
Optional
recurse: booleanIf true, nested entities will be updated as well.
+Generated using TypeDoc
Utility functions for JSON-LD
+Static
addStatic
addStatic
asStatic
asStatic
cloneStatic
countStatic
existsStatic
hasStatic
hasStatic
isStatic
isStatic
unionGenerated using TypeDoc
This is a JavaScript library to create and manipulate Research Object Crate.
+ + +Install the library:
+npm install ro-crate
+
+
+
+ Import the ROCrate
class and create a new empty crate with default configurations:
const {ROCrate} = require('ro-crate');
const crate = new ROCrate();
+
+The ROCrate
constructor accepts two optional arguments:
const fs = require('fs');
// load existing metadata
const data = JSON.parse(fs.readFileSync('ro-crate-metadata.json', 'utf8'));
// create a crate using the existing data and
// configure the crate to return a property of an Entity as an array and resolve linked entity as nested object
const crate = new ROCrate(data, { array: true, link: true });
+
+To add an Entity to the crate:
+// A license
const license = {
'@id': 'https://creativecommons.org/licenses/by/4.0/',
'@type': 'CreativeWork',
'description': 'Attribution 4.0 International (CC BY 4.0) ...',
'name': 'CC BY 4.0'
};
// add the license as an unconnected Entity
crate.addEntity(license);
// add the license to the root dataset
crate.rootDataset.license = {'@id': license['@id']};
// or alternatively, add a new entity directly into a property of other entity :
crate.rootDataset.license = license;
+
+Use an entity just like a normal object:
+let lic = create.getEntity(license['@id']);
console.log(lic.name); // prints 'CC BY 4.0';
// set a property directly
lic.name = 'CC BY 4.0 dummy';
// or with the setProperty method
crate.setProperty(license['@id'], 'name', 'CC BY 4.0 dummy');
console.log(lic.name); // prints 'CC BY 4.0 dummy';
+
+Modifying an array of values in the property is not supported yet:
+lic.test = [1,2,3];
lic.test.push(4); // this does not work
console.log(lic.test); // prints '[1,2,3]';
// use this instead
lic.test = lic.test.concat(4);
// or this
crate.addValues(license['@id'], 'test', 4);
+
+Root Dataset is a special entity that is mandated by the standard:
+const rootDataset = crate.rootDataset;
rootDataset.name = 'Tutorial Crate';
rootDataset.description = 'This is an example crate for educational purposes.'
const today = new Date().toISOString().split('T')[0]
rootDataset.datePublished = today;
+
+The value of the returned property can be set to be always as an array:
+const crate1 = new ROCrate();
const crate2 = new ROCrate({array: true});
crate1.rootDataset.name = 'Tutorial Crate';
crate1.rootDataset.test = ['test1', 'test2'];
crate2.rootDataset.name = 'Tutorial Crate';
crate2.rootDataset.test = ['test1', 'test2'];
console.log(crate1.rootDataset.name); // return 'Tutorial Crate'
console.log(crate1.rootDataset.name); // return ['test1', 'test2']
console.log(crate2.rootDataset.name); // return ['Tutorial Crate']
console.log(crate2.rootDataset.name); // return ['test1', 'test2']
+
+Linked entities can be automatically resolved as nested objects:
+const crate1 = new ROCrate();
const crate2 = new ROCrate({link: true});
const crate3 = new ROCrate({link: true, array: true});
crate1.rootDataset.license = license;
crate2.rootDataset.license = license;
crate3.rootDataset.license = license;
console.log(crate1.rootDataset.license.name); // return undefined
console.log(crate1.rootDataset.license); // return {'@id': 'https://creativecommons.org/licenses/by/4.0/'}
console.log(crate2.rootDataset.license.name); // return 'CC BY 4.0'
console.log(crate3.rootDataset.license.name); // return undefined, property license is a array
console.log(crate3.rootDataset.license[0].name); // return 'CC BY 4.0'
+
+To save the rocrate data to a file, use JSON.stringify
:
// Write pretty-printed JSONLD into the directory
fs.writeFileSync('ro-crate-metadata.json', JSON.stringify(crate, null, 2));
+
+For more details, refer to the full API documentation.
For more usage examples, see the test files under the test directory.
Use the RO-Crate-HTML to generate a HTML preview from the RO-Crate Metadata File ro-crate-metadata.json
.
There is a script included with this library that can check crates.
+Check a crate:
+roccheck /path/to/crate/directory
This is produce a simple report.
+Generated using TypeDoc
Generated using TypeDoc
Generated using TypeDoc
Generated using TypeDoc
Generated using TypeDoc
Generated using TypeDoc
Generated using TypeDoc
Class for building, navigating, testing and rendering ROCrates
+ +import validation and rendering from Calcyte
+Create a new ROCrate object using a default template or from a valid jsonld object.
+a valid jsonld object
+Optional
config: { array: boolean; defaultType: string; duplicate: boolean; link: boolean; merge: boolean; replace: boolean }Always return property of an Entity as an array (eg when using getEntity() method)
+The default value for @type
to be used when adding a new entity and the property is not specified. Default to 'Thing'
Allow duplicate values in a property that has multiple values
+Resolve linked node as nested object
+When replacing or updating an entity, merge the values and the properties instead of full replace
+When importing from json, a subsequent duplicate entity always replaces the existing one
+Import Utils class directly
+Static
defaultsThe context part of the crate. An alias for '@context'. +This returns the original context information.
+An array of all nodes in the graph. An alias for '@graph'
+ +The root identifier of the RO Crate
+ +Add an entity to the crate.
+ +true if the entity is successfully added.
+A valid RO-Crate entity described in plain object.
+Optional
replace: boolean = ...If true, replace existing entity with the same id.
+Optional
recurse: booleanIf true, nested entities will be added as well.
+Add a new identifier as a PropertyValue to the root DataSet. +identifier and name are required
+ +The added identifier or undefined
+This silently fails if the item has no
+ +or already exists - this is probably sub-optimal
+ +Use addEntity
+Add one or more value to a property of an entity. +If the specified property does not exists, a new one will be set. +If the property already exists, the new value will be added to the property array.
+The id or the entity to add the property to
+The name of the property
+The value of the property
+Optional
duplicate: booleanIf true, allow a property to have duplicate values in the array
+Use updateEntityId
+Use union, eg: union([sg1, sg2])
+Delete an entity from the graph
+ +True if any existing entity was deleted
+Entity Identifier or the entity object itself
+Set true to delete all references to the deleted entity
+Get an entity from the graph. +If config.link is true, any reference (object with just "@id" property) +is resolved as a nested object.
+ +A wrapper for entity that resolves properties as linked objects
+An entity identifier
+Use getGraph with argument set to true
+Get an array of all nodes in the graph. Each node in the array is an Entity instance. +If config.link is true, any link to other node will be made into nested object.
+ +If true, return the copy of entity as a plain object.
+Use toJSON
+Use getIdentifier
+Use getTree with the following argument: { root, depth, allowCycle: true }
Use rootDataset
+Use rootId
+Return a JSON.stringify-ready tree structure starting from the specified item
+with all values (apart from @id) as arrays
+and string-values expressed like: {"@value": "string-value"}
the root entity
+The number of nesting the tree will have. Must be 0 or positive integer.
+Create a simple tree-like object - but don't make circular structures
+ +Use getTree with the valueObject argument set to false`
+null, or an array of items
+A JSON-LD item or array of [item]
+An array of objects that represents a 'path' through the graph.
+ Object must have a "property" to follow, eg:
+ resolve(item, {"property": "miltaryService"});
+ and optionally a condition "includes", eg:
+ "includes": {"@type", "Action"}}
+ and optionally, a function "matchFn" which takes an item
+ as argument and returns a boolean, eg:
+ "matchFn": (item) => item['@id'].match(/anzsrc-for/)
Optional
subgraph: any[]If present and true, all intervening items during + the traversal will be stored. If an array is passed, the intervening items will be + stored in the array.
+Use getGraph and pass true as the argument
+Set a property of an entity with the given value. +If a property with the same name exists, its existing value will be replaced with the specified value. +If values contain nested non-empty entities, they will be processed recursively.
+The id of the entity to add the property to
+The name of the property
+A value or an array of values
+Optional
duplicate: booleanIf true, allow a property to have duplicate values
+Update an entity by replacing the object with the same id.
+This operations will remove all properties of the existing entity and
+add the new ones contained in data
, unless merge
argument is true.
false if there is no existing entity with the same id or data is empty.
+Optional
merge: boolean = ...If true, new properties will be merged. Defaults to config.merge
.
Optional
recurse: booleanIf true, nested entities will be updated as well.
+Generated using TypeDoc
Utility functions for JSON-LD
+Static
addStatic
addStatic
asStatic
asStatic
cloneStatic
countStatic
existsStatic
hasStatic
hasStatic
isStatic
isStatic
unionGenerated using TypeDoc
This is a JavaScript library to create and manipulate Research Object Crate.
+ + +Install the library:
+npm install ro-crate
+
+Note: The minimum Node.js version is 16.11.0.
+ + +Import the ROCrate
class and create a new empty crate with default configurations:
const {ROCrate} = require('ro-crate');
const crate = new ROCrate();
+
+The ROCrate
constructor accepts two optional arguments:
const fs = require('fs');
// load existing metadata
const data = JSON.parse(fs.readFileSync('ro-crate-metadata.json', 'utf8'));
// create a crate using the existing data and
// configure the crate to return a property of an Entity as an array and resolve linked entity as nested object
const crate = new ROCrate(data, { array: true, link: true });
+
+To add an Entity to the crate:
+// A license
const license = {
'@id': 'https://creativecommons.org/licenses/by/4.0/',
'@type': 'CreativeWork',
'description': 'Attribution 4.0 International (CC BY 4.0) ...',
'name': 'CC BY 4.0'
};
// add the license as an unconnected Entity
crate.addEntity(license);
// add the license to the root dataset
crate.rootDataset.license = {'@id': license['@id']};
// or alternatively, add a new entity directly into a property of other entity :
crate.rootDataset.license = license;
+
+Use an entity just like a normal object:
+let lic = create.getEntity(license['@id']);
console.log(lic.name); // prints 'CC BY 4.0';
// set a property directly
lic.name = 'CC BY 4.0 dummy';
// or with the setProperty method
crate.setProperty(license['@id'], 'name', 'CC BY 4.0 dummy');
console.log(lic.name); // prints 'CC BY 4.0 dummy';
+
+Modifying an array of values in the property is not supported yet:
+lic.test = [1,2,3];
lic.test.push(4); // this does not work
console.log(lic.test); // prints '[1,2,3]';
// use this instead
lic.test = lic.test.concat(4);
// or this
crate.addValues(license['@id'], 'test', 4);
+
+Root Dataset is a special entity that is mandated by the standard:
+const rootDataset = crate.rootDataset;
rootDataset.name = 'Tutorial Crate';
rootDataset.description = 'This is an example crate for educational purposes.'
const today = new Date().toISOString().split('T')[0]
rootDataset.datePublished = today;
+
+The value of the returned property can be set to be always as an array:
+const crate1 = new ROCrate();
const crate2 = new ROCrate({array: true});
crate1.rootDataset.name = 'Tutorial Crate';
crate1.rootDataset.test = ['test1', 'test2'];
crate2.rootDataset.name = 'Tutorial Crate';
crate2.rootDataset.test = ['test1', 'test2'];
console.log(crate1.rootDataset.name); // return 'Tutorial Crate'
console.log(crate1.rootDataset.name); // return ['test1', 'test2']
console.log(crate2.rootDataset.name); // return ['Tutorial Crate']
console.log(crate2.rootDataset.name); // return ['test1', 'test2']
+
+Linked entities can be automatically resolved as nested objects:
+const crate1 = new ROCrate();
const crate2 = new ROCrate({link: true});
const crate3 = new ROCrate({link: true, array: true});
crate1.rootDataset.license = license;
crate2.rootDataset.license = license;
crate3.rootDataset.license = license;
console.log(crate1.rootDataset.license.name); // return undefined
console.log(crate1.rootDataset.license); // return {'@id': 'https://creativecommons.org/licenses/by/4.0/'}
console.log(crate2.rootDataset.license.name); // return 'CC BY 4.0'
console.log(crate3.rootDataset.license.name); // return undefined, property license is a array
console.log(crate3.rootDataset.license[0].name); // return 'CC BY 4.0'
+
+To save the rocrate data to a file, use JSON.stringify
:
// Write pretty-printed JSONLD into the directory
fs.writeFileSync('ro-crate-metadata.json', JSON.stringify(crate, null, 2));
+
+For more usage examples, see the test files under the test directory.
+For more details, refer to the full API documentation.
+ + +Use the RO-Crate-HTML to generate a HTML preview from the RO-Crate Metadata File ro-crate-metadata.json
.
There is a script included with this library that can check crates.
+Check a crate:
+roccheck /path/to/crate/directory
This is produce a simple report.
+Generated using TypeDoc
Generated using TypeDoc
Generated using TypeDoc
Generated using TypeDoc
Generated using TypeDoc
Generated using TypeDoc
Generated using TypeDoc
Class for building, navigating, testing and rendering ROCrates
+import validation and rendering from Calcyte
+Create a new ROCrate object using a default template or from a valid jsonld object.
+a valid jsonld object
+Optional
config: { Always return property of an Entity as an array (eg when using getEntity() method)
+The default value for @type
to be used when adding a new entity and the property is not specified. Default to 'Thing'
Allow duplicate values in a property that has multiple values
+Resolve linked node as nested object
+When replacing or updating an entity, merge the values and the properties instead of full replace
+When importing from json, a subsequent duplicate entity always replaces the existing one
+Internal representation of the context
+Index of all context contents or terms
+Lookup table to index nodes by their properties
+Lookup table to get a reference to existing and non-existing nodes. +This is needed to avoid searching for the whole graph for every "@reverse" lookup +as an entity referenced by other entities may not exist yet in the graph.
+Import Utils class directly
+Static
defaultsThe context part of the crate. An alias for '@context'. +This returns the original context information.
+An array of all nodes in the graph. An alias for '@graph'
+The root identifier of the RO Crate
+Create a new node or return an existing node with the given data
+Identifier of the node (@id)
+Optional
ref: NodeRefAn immutable and unique reference to node that contains id and reverse information only
+a newly created or existing node that matches the id
+ +Init a new node or update existing one
+Update the node with the given data
+If true, create an entity even if the data is empty
+If false and if node already exists, remove all existing properties not in the specified data
+Process nested objects recursively
+If false and if node already exists, do nothing to the node
+A set to keep track of cyclic reference in the input
+Return true if node is changed
+ +Append the specified string or object directly as an entry into the RO-Crate JSON-LD Context array. +It does not check for duplicates or overlapping content if the context is an object.
+A URL or an Object that contains the context mapping
+Add an entity to the crate.
+A valid RO-Crate entity described in plain object.
+If true, nested entities will be added as well.
+If true, replace existing entity with the same id.
+true if the entity is successfully added.
+ +Add a new identifier as a PropertyValue to the root DataSet. +identifier and name are required parameters
+The added identifier or undefined
+ +Add one or more value to a property of an entity. +If the specified property does not exists, a new one will be set. +If the property already exists, the new value will be added to the property array.
+The id or the entity to add the property to
+The name of the property
+The value of the property
+If true, allow a property to have duplicate values in the array
+Use updateEntityId
+Use union, eg: union([sg1, sg2])
+Delete an entity from the graph
+Entity Identifier or the entity object itself
+Set true to delete all references to the deleted entity
+True if any existing entity was deleted
+ +The raw data of deleted entity
+ +Use deleteEntity
+Delete one or more values from a property.
+Returns a new iterator object that contains the entities in the graph.
+Filter the result based on the values of the properties defined in this object.
+If true, return the copy of entity as a plain object.
+Get an entity from the graph. +If config.link is true, any reference (object with just "@id" property) +is resolved as a nested object.
+An entity identifier
+A wrapper for entity that resolves properties as linked objects
+ +Use getGraph with argument set to true
+Get an array of all nodes in the graph. Each node in the array is an Entity instance. +If config.link is true, any link to other node will be made into nested object.
+If true, return the copy of entity as a plain object.
+Use toJSON
+Use getIdentifier
+Use getTree with the following argument: { root, depth, allowCycle: true }
Use rootDataset
+Use rootId
+Return a JSON.stringify-ready tree structure starting from the specified item
+with all values (apart from @id) as arrays
+and string-values expressed like: {"@value": "string-value"}
The number of nesting the tree will have. Must be 0 or positive integer.
+the root entity
+ +Create a simple tree-like object - but don't make circular structures
+Use getTree with the valueObject argument set to false`
+Add a value to an item's property array
+Use addValues
+A JSON-LD item or array of [item]
+An array of objects that represents a 'path' through the graph.
+ Object must have a "property" to follow, eg:
+ resolve(item, {"property": "miltaryService"});
+ and optionally a condition "includes", eg:
+ "includes": {"@type", "Action"}}
+ and optionally, a function "matchFn" which takes an item
+ as argument and returns a boolean, eg:
+ "matchFn": (item) => item['@id'].match(/anzsrc-for/)
Optional
subgraph: any[]If present and true, all intervening items during + the traversal will be stored. If an array is passed, the intervening items will be + stored in the array.
+null, or an array of items
+ +Use getGraph and pass true as the argument
+Set a property of an entity with the given value. +If a property with the same name exists, its existing value will be replaced with the specified value. +If values contain nested non-empty entities, they will be processed recursively.
+The id of the entity to add the property to
+The name of the property
+A value or an array of values
+If true, allow a property to have duplicate values
+Update an entity by replacing the object with the same id.
+This operations will remove all properties of the existing entity and
+add the new ones contained in data
, unless merge
argument is true.
If true, new properties will be merged. Defaults to config.merge
.
If true, nested entities will be updated as well.
+false if there is no existing entity with the same id or data is empty.
+ +Generated using TypeDoc
Utility functions for JSON-LD
+Static
addStatic
addStatic
asStatic
asStatic
cloneStatic
countStatic
existsStatic
hasStatic
hasStatic
isStatic
isStatic
unionGenerated using TypeDoc
This is a JavaScript library to create and manipulate Research Object Crate.
+Install the library:
+npm install ro-crate
+
+Note: The minimum Node.js version is 16.11.0.
+Import the ROCrate
class and create a new empty crate with default configurations:
const {ROCrate} = require('ro-crate');
const crate = new ROCrate();
+
+The ROCrate
constructor accepts two optional arguments:
const fs = require('fs');
// load existing metadata
const data = JSON.parse(fs.readFileSync('ro-crate-metadata.json', 'utf8'));
// create a crate using the existing data and
// configure the crate to return a property of an Entity as an array and resolve linked entity as nested object
const crate = new ROCrate(data, { array: true, link: true });
+
+To add an Entity to the crate:
+// A license
const license = {
'@id': 'https://creativecommons.org/licenses/by/4.0/',
'@type': 'CreativeWork',
'description': 'Attribution 4.0 International (CC BY 4.0) ...',
'name': 'CC BY 4.0'
};
// add the license as an unconnected Entity
crate.addEntity(license);
// add the license to the root dataset
crate.rootDataset.license = {'@id': license['@id']};
// or alternatively, add a new entity directly into a property of other entity :
crate.rootDataset.license = license;
+
+Use an entity just like a normal object:
+let lic = create.getEntity(license['@id']);
console.log(lic.name); // prints 'CC BY 4.0';
// set a property directly
lic.name = 'CC BY 4.0 dummy';
// or with the setProperty method
crate.setProperty(license['@id'], 'name', 'CC BY 4.0 dummy');
console.log(lic.name); // prints 'CC BY 4.0 dummy';
+
+Modifying an array of values in the property is not supported yet:
+lic.test = [1,2,3];
lic.test.push(4); // this does not work
console.log(lic.test); // prints '[1,2,3]';
// use this instead
lic.test = lic.test.concat(4);
// or this
crate.addValues(license['@id'], 'test', 4);
+
+Root Dataset is a special entity that is mandated by the standard:
+const rootDataset = crate.rootDataset;
rootDataset.name = 'Tutorial Crate';
rootDataset.description = 'This is an example crate for educational purposes.'
const today = new Date().toISOString().split('T')[0]
rootDataset.datePublished = today;
+
+The value of the returned property can be set to be always as an array:
+const crate1 = new ROCrate();
const crate2 = new ROCrate({array: true});
crate1.rootDataset.name = 'Tutorial Crate';
crate1.rootDataset.test = ['test1', 'test2'];
crate2.rootDataset.name = 'Tutorial Crate';
crate2.rootDataset.test = ['test1', 'test2'];
console.log(crate1.rootDataset.name); // return 'Tutorial Crate'
console.log(crate1.rootDataset.name); // return ['test1', 'test2']
console.log(crate2.rootDataset.name); // return ['Tutorial Crate']
console.log(crate2.rootDataset.name); // return ['test1', 'test2']
+
+Linked entities can be automatically resolved as nested objects:
+const crate1 = new ROCrate();
const crate2 = new ROCrate({link: true});
const crate3 = new ROCrate({link: true, array: true});
crate1.rootDataset.license = license;
crate2.rootDataset.license = license;
crate3.rootDataset.license = license;
console.log(crate1.rootDataset.license.name); // return undefined
console.log(crate1.rootDataset.license); // return {'@id': 'https://creativecommons.org/licenses/by/4.0/'}
console.log(crate2.rootDataset.license.name); // return 'CC BY 4.0'
console.log(crate3.rootDataset.license.name); // return undefined, property license is a array
console.log(crate3.rootDataset.license[0].name); // return 'CC BY 4.0'
+
+To save the rocrate data to a file, use JSON.stringify
:
// Write pretty-printed JSONLD into the directory
fs.writeFileSync('ro-crate-metadata.json', JSON.stringify(crate, null, 2));
+
+For more usage examples, see the test files under the test directory.
+For more details, refer to the full API documentation.
+Use the RO-Crate-HTML to generate a HTML preview from the RO-Crate Metadata File ro-crate-metadata.json
.
There is a script included with this library that can check crates.
+Check a crate:
+roccheck /path/to/crate/directory
This is produce a simple report.
+Generated using TypeDoc
Generated using TypeDoc
Generated using TypeDoc
Generated using TypeDoc
Generated using TypeDoc
Generated using TypeDoc
Generated using TypeDoc
Class for building, navigating, testing and rendering ROCrates
+import validation and rendering from Calcyte
+Create a new ROCrate object using a default template or from a valid jsonld object.
+a valid jsonld object
+Optional
config: { Always return property of an Entity as an array (eg when using getEntity() method)
+The default value for @type
to be used when adding a new entity and the property is not specified. Default to 'Thing'
Allow duplicate values in a property that has multiple values
+Resolve linked node as nested object
+When replacing or updating an entity, merge the values and the properties instead of full replace
+When importing from json, a subsequent duplicate entity always replaces the existing one
+Internal representation of the context
+Index of all context contents or terms
+Lookup table to index nodes by their properties
+Lookup table to get a reference to existing and non-existing nodes. +This is needed to avoid searching for the whole graph for every "@reverse" lookup +as an entity referenced by other entities may not exist yet in the graph.
+Import Utils class directly
+Static
defaultsThe context part of the crate. An alias for '@context'. +This returns the original context information.
+An array of all nodes in the graph. An alias for '@graph'
+The root identifier of the RO Crate
+Create a new node or return an existing node with the given data
+Identifier of the node (@id)
+Optional
ref: NodeRefAn immutable and unique reference to node that contains id and reverse information only
+a newly created or existing node that matches the id
+ +Init a new node or update existing one
+Update the node with the given data
+If true, create an entity even if the data is empty
+If false and if node already exists, remove all existing properties not in the specified data
+Process nested objects recursively
+If false and if node already exists, do nothing to the node
+A set to keep track of cyclic reference in the input
+Return true if node is changed
+ +Append the specified string or object directly as an entry into the RO-Crate JSON-LD Context array. +It does not check for duplicates or overlapping content if the context is an object.
+A URL or an Object that contains the context mapping
+Add an entity to the crate.
+A valid RO-Crate entity described in plain object.
+If true, nested entities will be added as well.
+If true, replace existing entity with the same id.
+true if the entity is successfully added.
+ +Add a new identifier as a PropertyValue to the root DataSet. +identifier and name are required parameters
+The added identifier or undefined
+ +Add one or more value to a property of an entity. +If the specified property does not exists, a new one will be set. +If the property already exists, the new value will be added to the property array.
+The id or the entity to add the property to
+The name of the property
+The value of the property
+If true, allow a property to have duplicate values in the array
+Use updateEntityId
+Use union, eg: union([sg1, sg2])
+Delete an entity from the graph
+Entity Identifier or the entity object itself
+Set true to delete all references to the deleted entity
+True if any existing entity was deleted
+ +The raw data of deleted entity
+ +Use deleteEntity
+Delete one or more values from a property.
+Returns a new iterator object that contains the entities in the graph.
+Filter the result based on the values of the properties defined in this object.
+If true, return the copy of entity as a plain object.
+Get an entity from the graph. +If config.link is true, any reference (object with just "@id" property) +is resolved as a nested object.
+An entity identifier
+A wrapper for entity that resolves properties as linked objects
+ +Use getGraph with argument set to true
+Get an array of all nodes in the graph. Each node in the array is an Entity instance. +If config.link is true, any link to other node will be made into nested object.
+If true, return the copy of entity as a plain object.
+Use toJSON
+Use getIdentifier
+Use getTree with the following argument: { root, depth, allowCycle: true }
Use rootDataset
+Use rootId
+Return a JSON.stringify-ready tree structure starting from the specified item
+with all values (apart from @id) as arrays
+and string-values expressed like: {"@value": "string-value"}
The number of nesting the tree will have. Must be 0 or positive integer.
+the root entity
+ +Create a simple tree-like object - but don't make circular structures
+Use getTree with the valueObject argument set to false`
+Add a value to an item's property array
+Use addValues
+A JSON-LD item or array of [item]
+An array of objects that represents a 'path' through the graph.
+ Object must have a "property" to follow, eg:
+ resolve(item, {"property": "miltaryService"});
+ and optionally a condition "includes", eg:
+ "includes": {"@type", "Action"}}
+ and optionally, a function "matchFn" which takes an item
+ as argument and returns a boolean, eg:
+ "matchFn": (item) => item['@id'].match(/anzsrc-for/)
Optional
subgraph: any[]If present and true, all intervening items during + the traversal will be stored. If an array is passed, the intervening items will be + stored in the array.
+null, or an array of items
+ +Use getGraph and pass true as the argument
+Set a property of an entity with the given value. +If a property with the same name exists, its existing value will be replaced with the specified value. +If values contain nested non-empty entities, they will be processed recursively.
+The id of the entity to add the property to
+The name of the property
+A value or an array of values
+If true, allow a property to have duplicate values
+Update an entity by replacing the object with the same id.
+This operations will remove all properties of the existing entity and
+add the new ones contained in data
, unless merge
argument is true.
If true, new properties will be merged. Defaults to config.merge
.
If true, nested entities will be updated as well.
+false if there is no existing entity with the same id or data is empty.
+ +Generated using TypeDoc
Utility functions for JSON-LD
+Static
addStatic
addStatic
asStatic
asStatic
cloneStatic
countStatic
existsStatic
hasStatic
hasStatic
isStatic
isStatic
unionGenerated using TypeDoc
This is a JavaScript library to create and manipulate Research Object Crate.
+Install the library:
+npm install ro-crate
+
+Note: The minimum Node.js version is 16.11.0.
+Import the ROCrate
class and create a new empty crate with default configurations:
const {ROCrate} = require('ro-crate');
const crate = new ROCrate();
+
+The ROCrate
constructor accepts two optional arguments:
const fs = require('fs');
// load existing metadata
const data = JSON.parse(fs.readFileSync('ro-crate-metadata.json', 'utf8'));
// create a crate using the existing data and
// configure the crate to return a property of an Entity as an array and resolve linked entity as nested object
const crate = new ROCrate(data, { array: true, link: true });
+
+To add an Entity to the crate:
+// A license
const license = {
'@id': 'https://creativecommons.org/licenses/by/4.0/',
'@type': 'CreativeWork',
'description': 'Attribution 4.0 International (CC BY 4.0) ...',
'name': 'CC BY 4.0'
};
// add the license as an unconnected Entity
crate.addEntity(license);
// add the license to the root dataset
crate.rootDataset.license = {'@id': license['@id']};
// or alternatively, add a new entity directly into a property of other entity :
crate.rootDataset.license = license;
+
+Use an entity just like a normal object:
+let lic = create.getEntity(license['@id']);
console.log(lic.name); // prints 'CC BY 4.0';
// set a property directly
lic.name = 'CC BY 4.0 dummy';
// or with the setProperty method
crate.setProperty(license['@id'], 'name', 'CC BY 4.0 dummy');
console.log(lic.name); // prints 'CC BY 4.0 dummy';
+
+Modifying an array of values in the property is not supported yet:
+lic.test = [1,2,3];
lic.test.push(4); // this does not work
console.log(lic.test); // prints '[1,2,3]';
// use this instead
lic.test = lic.test.concat(4);
// or this
crate.addValues(license['@id'], 'test', 4);
+
+Root Dataset is a special entity that is mandated by the standard:
+const rootDataset = crate.rootDataset;
rootDataset.name = 'Tutorial Crate';
rootDataset.description = 'This is an example crate for educational purposes.'
const today = new Date().toISOString().split('T')[0]
rootDataset.datePublished = today;
+
+The value of the returned property can be set to be always as an array:
+const crate1 = new ROCrate();
const crate2 = new ROCrate({array: true});
crate1.rootDataset.name = 'Tutorial Crate';
crate1.rootDataset.test = ['test1', 'test2'];
crate2.rootDataset.name = 'Tutorial Crate';
crate2.rootDataset.test = ['test1', 'test2'];
console.log(crate1.rootDataset.name); // return 'Tutorial Crate'
console.log(crate1.rootDataset.name); // return ['test1', 'test2']
console.log(crate2.rootDataset.name); // return ['Tutorial Crate']
console.log(crate2.rootDataset.name); // return ['test1', 'test2']
+
+Linked entities can be automatically resolved as nested objects:
+const crate1 = new ROCrate();
const crate2 = new ROCrate({link: true});
const crate3 = new ROCrate({link: true, array: true});
crate1.rootDataset.license = license;
crate2.rootDataset.license = license;
crate3.rootDataset.license = license;
console.log(crate1.rootDataset.license.name); // return undefined
console.log(crate1.rootDataset.license); // return {'@id': 'https://creativecommons.org/licenses/by/4.0/'}
console.log(crate2.rootDataset.license.name); // return 'CC BY 4.0'
console.log(crate3.rootDataset.license.name); // return undefined, property license is a array
console.log(crate3.rootDataset.license[0].name); // return 'CC BY 4.0'
+
+To save the rocrate data to a file, use JSON.stringify
:
// Write pretty-printed JSONLD into the directory
fs.writeFileSync('ro-crate-metadata.json', JSON.stringify(crate, null, 2));
+
+For more usage examples, see the test files under the test directory.
+For more details, refer to the full API documentation.
+Use the RO-Crate-HTML to generate a HTML preview from the RO-Crate Metadata File ro-crate-metadata.json
.
There is a script included with this library that can check crates.
+Check a crate:
+roccheck /path/to/crate/directory
This is produce a simple report.
+Generated using TypeDoc
Generated using TypeDoc
Generated using TypeDoc
Generated using TypeDoc
Generated using TypeDoc
Class for building, navigating, testing and rendering ROCrates
+ +Todo
import validation and rendering from Calcyte
+