# @rdfjs/prefix-map

> A Map for RDF/JS prefixes

Latest version **0.1.2** (published 2024-06-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install @rdfjs/prefix-map
pnpm add @rdfjs/prefix-map
yarn add @rdfjs/prefix-map
bun add @rdfjs/prefix-map
```

## Health

**Score 43/100 (D)** — status: abandoned.

Positive: has types package; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2024-06-02 |
| First published | 2021-12-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/rdfjs__prefix-map) |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 13.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Thomas Bergwinkl |
| Maintainers | bergos |
| Keywords | map, prefix, rdf, rdfjs |

## Links

- npm: https://www.npmjs.com/package/@rdfjs/prefix-map
- Repository: https://github.com/rdfjs-base/prefix-map
- Issues: https://github.com/rdfjs-base/prefix-map/issues
- npm.io page: https://npm.io/package/@rdfjs/prefix-map

## Dependencies (1)

- [readable-stream](https://npm.io/package/readable-stream.md) ^4.3.0

## Recent versions

- 0.1.2 (latest) — 2024-06-02
- 0.1.1 — 2023-01-08
- 0.1.0 — 2021-12-25

## README

# @rdfjs/prefix-map

[![build status](https://img.shields.io/github/actions/workflow/status/rdfjs-base/prefix-map/test.yaml?branch=master)](https://github.com/rdfjs-base/prefix-map/actions/workflows/test.yaml)
[![npm version](https://img.shields.io/npm/v/@rdfjs/prefix-map.svg)](https://www.npmjs.com/package/@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:

```javascript
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
```

---
_Source: https://npm.io/package/@rdfjs/prefix-map · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
