# @rdfjs/parser-n3

> N3 parser that implements the RDF/JS Sink interface

Latest version **2.2.0** (published 2026-07-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install @rdfjs/parser-n3
pnpm add @rdfjs/parser-n3
yarn add @rdfjs/parser-n3
bun add @rdfjs/parser-n3
```

## Health

**Score 68/100 (B)** — status: active.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2026-07-05 |
| First published | 2018-09-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/rdfjs__parser-n3) |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 13.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Thomas Bergwinkl |
| Maintainers | bergos, matthieubosquet |
| Keywords | rdf, rdfjs, parser, n3, ntriples, turtle |

## Links

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

## Dependencies (5)

- [n3](https://npm.io/package/n3.md) ^2.1.1
- [duplex-to](https://npm.io/package/duplex-to.md) ^2.0.0
- [@rdfjs/sink](https://npm.io/package/@rdfjs/sink.md) ^2.0.1
- [readable-stream](https://npm.io/package/readable-stream.md) ^4.5.2
- [@rdfjs/data-model](https://npm.io/package/@rdfjs/data-model.md) ^2.0.2

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 2.2.0 (latest) — 2026-07-05
- 2.1.0 — 2025-03-14
- 2.0.2 — 2024-02-10
- 2.0.1 — 2022-11-21
- 2.0.0 — 2022-10-07
- 1.1.4 — 2020-03-31
- 1.1.3 — 2019-07-29
- 1.1.2 — 2018-09-03

## README

# @rdfjs/parser-n3
[![build status](https://img.shields.io/github/actions/workflow/status/rdfjs-base/parser-n3/test.yaml?branch=master)](https://github.com/rdfjs-base/parser-n3/actions/workflows/test.yaml)
[![npm version](https://img.shields.io/npm/v/@rdfjs/parser-n3.svg)](https://www.npmjs.com/package/@rdfjs/parser-n3)

N3 parser which implements the [RDF/JS Sink interface](http://rdf.js.org/) using the [N3.js](https://github.com/rdfjs/N3.js) library.

## Usage

The package exports the parser as a class, so an instance must be created before it can be used.
The `.import` method, as defined in the [RDFJS specification](http://rdf.js.org/#sink-interface), must be called to do the actual parsing.
It expects a Turtle, Trig, N-Triples or N-Quads string stream.
The method will return a stream which emits the parsed quads.
It also emits `prefix` events as defined in the [RDF/JS specification](http://rdf.js.org/#dom-stream-prefix).

The constructor accepts an `options` object with the following optional keys:

- `baseIRI`: Allows passing the base IRI manually to the `N3.js` library.
- `factory`: Use an alternative RDF/JS data factory.
  By default the [reference implementation](https://github.com/rdfjs-base/data-model/) is used.

It's also possible to pass options as second argument to the `.import` method.
The options from the constructor and the `.import` method will be merged together.

### Example

This example shows how to create a parser instance and how to feed it with a stream from a string.
The parsed quads and the prefixes are written to the console.

```javascript
import ParserN3 from '@rdfjs/parser-n3'
import { Readable } from 'readable-stream'

const parserN3 = new ParserN3()

const input = Readable.from(`
PREFIX s: <http://schema.org/>

[] a s:Person ;
  s:jobTitle "Professor" ;
  s:name "Jane Doe" ;
  s:telephone "(425) 123-4567" ;
  s:url <http://www.janedoe.com> .
`)

const output = parserN3.import(input)

output.on('data', quad => {
  console.log(`quad: ${quad.subject.value} - ${quad.predicate.value} - ${quad.object.value}`)
})

output.on('prefix', (prefix, ns) => {
  console.log(`prefix: ${prefix} ${ns.value}`)
})
```

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