@rdfdev/collections
TypeScript icon, indicating that this package has built-in type declarations

1.2.5 • Public • Published

js.rdf.dev/collections

Read the Docs npm (tag) npm bundle size

Utilities for reading and manipulating different kinds of RDF collections (rdf:Seq, rdf:List)

Example

import rdf from "@ontologies/core";
import { arrayToList, arrayToSeq, firstTermOfList, lastTermOfList, firstTermOfSeq, lastTermOfSeq, listToArray, seqToArray, Store } from "@rdfdev/collections";

const myArray = ["one", 2, rdf.namedNode("https://three.example/")];
const myStore: Store; // This can be the LinkedRenderStore from link-lib or your own.

// Converting an array to an rdf Sequence
const [ seqData, seqIRI ] =  arrayToSeq(myArray);
myStore.addQuads(seqData);
/**
 * The `seqData` would contain the following quads;
 * <seqIRI> a rdf:Seq .
 *      rdf:_0 "one" .
 *      rdf:_1 "2"^^http://www.w3.org/2001/XMLSchema#number .
 *      rdf:_2 <https://three.example/> ;
 */

// Reading
seqToArray(seqIRI); // [rdf.literal("one"), rdf.literal(2), rdf.namedNode("https://three.example/")]
firstTermOfSeq(myStore, listIRI); // rdf.literal("one")
lastTermOfSeq(myStore, listIRI); // rdf.namedNode("https://three.example/")

const [ listData, listIRI ] = arrayToList(myArray);
myStore.addQuads(listData);
/**
 * The `seqData` would contain the following quads;
 * <listIRI> rdf:first "one" .
 * <listIRI> rdf:rest _:0 .
 * _:0 rdf:first "2"^^http://www.w3.org/2001/XMLSchema#number .
 * _:0 rdf:rest _:1 .
 * _:1 rdf:first <https://three.example/> ;
 * _:1 rdf:rest rdf:nil ;
 */

// Reading
listToArray(listIRI); // [rdf.literal("one"), rdf.literal(2), rdf.namedNode("https://three.example/")]
firstTermOfList(myStore, listIRI); // rdf.literal("one")
lastTermOfList(myStore, listIRI); // rdf.namedNode("https://three.example/")

Getting started

Just install the package and its peer dependencies.

npm i @rdfdev/collections @ontologies/core @ontologies/ld @ontologies/rdf @ontologies/rdfs

yarn add @rdfdev/collections @ontologies/core @ontologies/ld @ontologies/rdf @ontologies/rdfs

Documentation

See the js.rdf.dev/collections documentation

See the complete js.rdf.dev documentation

Need help with linked data?

This package is brought to you by Ontola. We build production-grade linked data solutions and can help you from advice to building custom web services.

Package Sidebar

Install

npm i @rdfdev/collections

Weekly Downloads

10

Version

1.2.5

License

MIT

Unpacked Size

61.3 kB

Total Files

14

Last publish

Collaborators

  • fletcher91