# rdf-loaders-registry

> Registry for JavaScript native types loader based on RDF descriptions

Latest version **1.0.3** (published 2024-02-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install rdf-loaders-registry
pnpm add rdf-loaders-registry
yarn add rdf-loaders-registry
bun add rdf-loaders-registry
```

## Health

**Score 30/100 (F)** — status: abandoned.

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2024-02-15 |
| First published | 2019-08-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Thomas Bergwinkl |
| Maintainers | ludovicm67, zazuko-bot |

## Links

- npm: https://www.npmjs.com/package/rdf-loaders-registry
- Repository: https://github.com/zazuko/rdf-loaders-registry
- Issues: https://github.com/zazuko/rdf-loaders-registry/issues
- npm.io page: https://npm.io/package/rdf-loaders-registry

## Dependencies (2)

- [is-graph-pointer](https://npm.io/package/is-graph-pointer.md) ^2.1.0
- [@rdfjs/data-model](https://npm.io/package/@rdfjs/data-model.md) ^2

## Recent versions

- 1.0.3 (latest) — 2024-02-15
- 1.0.2 — 2024-01-16
- 1.0.1 — 2023-12-07
- 1.0.0 — 2023-12-07
- 0.3.0 — 2021-03-05
- 0.2.0 — 2019-11-03
- 0.1.0 — 2019-08-07

## README

# Load native code based on RDF descriptions

This package implements a loader registry, which can be used to load code declared in RDF triples.

The registry cannot really do anything on its own. You will need actual loaders. One package which provides them is 
[rdf-loader-code](https://github.com/zazuko/rdf-loader-code) which lets you load JavaScript code.

## Installation

```
npm i --save rdf-loaders-registry
```

## Usage

1. Import and create the registry
1. Register a loader to handle a specific 'rdf:type' or `rdf:datatype`
1. Call the `load` method

```js
const LoaderRegistry = require('rdf-loaders-registry')
const loader = require('./lolcode-loader')

const registry = new LoaderRegistry()

// register to load `<> a <http://example.com/Lolcode>`
registry.registerNodeLoader('http://example.com/Lolcode', loader)

// register to load `"some code"^^<http://example.com/LolcodeInline>`
registry.registerLiteralLoader('http://example.com/LolcodeInline', loader)

// somewhere else in code
registry.load(node, {
  // some additional options
})
```

The first parameter of `register` can also be an `@rdfjs/data-model` IRI term.

## Implementing a loader

A loader is a function which implements the following signature:

```typescript
(
  node: { term, dataset, graph }, 
  {
    loaderRegistry: LoaderRegistry,
    ...
  }
) => any
```

It is possible to combine multiple loaders by recursively calling `loaderRegistry.load` from the loader code.

## Example

The examples folder contains a simple example based on nebular data.
It shows how to implement both types of loaders, nested loaders and how to use the registry.
You can run the example with the following command:

```
node examples/ngc2392.js
```

---
_Source: https://npm.io/package/rdf-loaders-registry · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
