@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'
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 })
const personShort = rdf.namedNode('schema:Person')
const typeLong = rdf.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type')
const personLong = prefixes.resolve(personShort)
const typeShort = prefixes.shrink(typeLong)
console.log(personLong.value)
console.log(typeShort.value)