Package Exports
- @rdfjs/prefix-map
- @rdfjs/prefix-map/Factory.js
- @rdfjs/prefix-map/PrefixMap.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@rdfjs/prefix-map) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@rdfjs/prefix-map
A Map for RDF/JS prefixes.
This package implements the JavaScript Map interface for RDF prefixes. Key-Value pairs are stored with the prefix as the key as a string and the namespaces as the value in an RDF/JS NamedNode object. There are some additional convenience methods to handle CURIEs and prefix events of RDF/JS Quad streams.
Usage
The package exports the constructor of the PrefixMap.
New instances with initial pairs can be created just like JavaScript Map
s but require an additional factory
argument:
import rdf from '@rdfjs/data-model'
import PrefixMap from '@rdfjs/prefix-map'
// create a PrefixMap, fill it with some initial values, and hand over the data model factory
const prefixes = new PrefixMap([
['rdf', rdf.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#')],
['schema', rdf.namedNode('http://schema.org')]
], { factory: rdf })
// create two NamedNodes, one with a CURIE and one with a full IRI
const personShort = rdf.namedNode('schema:Person')
const typeLong = rdf.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type')
// convert the CURIE to a full IRI and vice versa
const personLong = prefixes.resolve(personShort)
const typeShort = prefixes.shrink(typeLong)
// write the result to the console
console.log(personLong.value) // -> http://schema.org/Person
console.log(typeShort.value) // -> rdf:type