# rdf-validate-shacl

> RDF SHACL validator

Latest version **0.6.5** (published 2025-05-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install rdf-validate-shacl
pnpm add rdf-validate-shacl
yarn add rdf-validate-shacl
bun add rdf-validate-shacl
```

## Health

**Score 50/100 (C)** — status: stable.

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

Warnings: low downloads; pre 1.0.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 0.6.5 |
| Published | 2025-05-30 |
| First published | 2020-04-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 12 |
| Unpacked size | 98.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 125 |
| Author | Zazuko |
| Maintainers | tpluscode, ludovicm67, zazuko-bot |
| Keywords | rdf, shacl, validation |

## Links

- npm: https://www.npmjs.com/package/rdf-validate-shacl
- Repository: https://github.com/zazuko/rdf-validate-shacl
- Homepage: https://github.com/zazuko/rdf-validate-shacl#readme
- Issues: https://github.com/zazuko/rdf-validate-shacl/issues
- npm.io page: https://npm.io/package/rdf-validate-shacl

## Dependencies (12)

- [debug](https://npm.io/package/debug.md) ^4.3.2
- [clownface](https://npm.io/package/clownface.md) ^2.0.3
- [rdf-literal](https://npm.io/package/rdf-literal.md) ^2.0.0
- [@rdfjs/types](https://npm.io/package/@rdfjs/types.md) 1 - 2
- [@rdfjs/dataset](https://npm.io/package/@rdfjs/dataset.md) ^2.0.2
- [@vocabulary/sh](https://npm.io/package/@vocabulary/sh.md) ^1.1.6
- [@rdfjs/term-set](https://npm.io/package/@rdfjs/term-set.md) ^2.0.3
- [rdf-dataset-ext](https://npm.io/package/rdf-dataset-ext.md) ^1.1.0
- [@rdfjs/namespace](https://npm.io/package/@rdfjs/namespace.md) ^2.0.1
- [@rdfjs/data-model](https://npm.io/package/@rdfjs/data-model.md) ^2.1.0
- [@rdfjs/environment](https://npm.io/package/@rdfjs/environment.md) ^1.0.0
- [rdf-validate-datatype](https://npm.io/package/rdf-validate-datatype.md) ^0.2.2

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.6.5 (latest) — 2025-05-30
- 0.6.4 — 2025-05-30
- 0.6.3 — 2025-05-16
- 0.6.2 — 2025-04-23
- 0.6.1 — 2025-04-04
- 0.5.10 — 2025-04-04
- 0.5.9 — 2025-04-04
- 0.6.0 — 2025-04-04
- 0.5.8 — 2025-04-03
- 0.5.7 — 2025-03-27
- 0.5.6 — 2024-07-23
- 0.5.5 — 2024-05-07
- 0.5.4 — 2024-04-11
- 0.5.3 — 2024-01-19
- 0.5.2 — 2024-01-18
- … 23 more at https://npm.io/package/rdf-validate-shacl/versions

## README

# rdf-validate-shacl

Validate RDF data purely in JavaScript. An implementation of the [W3C SHACL](https://www.w3.org/TR/shacl/)
specification on top of the [RDFJS](https://rdf.js.org/) stack.

[![npm version](https://badge.fury.io/js/rdf-validate-shacl.svg)](https://badge.fury.io/js/rdf-validate-shacl)

We provide a [SHACL playground](https://zazuko.github.io/shacl-playground/) based on this library.

## Usage

The library only handles SHACL validation and not data loading/parsing.
The following example uses [rdf-utils-fs](https://github.com/rdf-ext/rdf-utils-fs)
for this purpose. For more information about handling RDF data in JavaScript,
check out [Get started with RDF in JavaScript](https://zazuko.com/get-started/developers/).

The validation function returns a `ValidationReport` object that can be used
to inspect conformance and results. The `ValidationReport` also has a
`.dataset` property, which provides the report as RDF data.

```javascript
import rdf from '@zazuko/env-node'
import SHACLValidator from 'rdf-validate-shacl'

async function main() {
  const shapes = await rdf.dataset().import(rdf.fromFile('my-shapes.ttl'))
  const data = await rdf.dataset().import(rdf.fromFile('my-data.ttl'))

  const validator = new SHACLValidator(shapes, { factory: rdf })
  const report = await validator.validate(data)

  // Check conformance: `true` or `false`
  console.log(report.conforms)

  for (const result of report.results) {
    // See https://www.w3.org/TR/shacl/#results-validation-result for details
    // about each property
    console.log(result.message)
    console.log(result.path)
    console.log(result.focusNode)
    console.log(result.severity)
    console.log(result.sourceConstraintComponent)
    console.log(result.sourceShape)
  }

  // Validation report as RDF dataset
  console.log(await report.dataset.serialize({ format: 'text/n3' }))
}

main();
```

### Validator options

The `SHACLValidator` constructor accepts an optional options object as second
parameter. The available options are:

| Parameter              | type                                                                              |                                                                                                                                |
|------------------------|-----------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|
| `factory`              | [`DatasetFactory`](https://rdf.js.org/dataset-spec/#datasetcorefactory-interface) |                                                                                                                                |
| `maxErrors`            | `number`                                                                          | max number of errors after which the validation process should stop. By default, it only stops after all the errors are found. |
| `allowNamedNodeInList` | `boolean`                                                                         | SHACL only allows blank nodes in property lists. To allow named nodes to occur in property lists, set this value to `true`.    |
| `importGraph`          | `(url: NamedNode) => DatasetCore \| Promise<DatasetCore>`                         | function to load imported shape graphs.                                                                                        |

## Running the tests

```
$ npm test
```

## Limitations

*rdf-validate-shacl* does not support [SHACL-SPARQL constraints](https://www.w3.org/TR/shacl/#sparql-constraints)


## About

*rdf-validate-shacl* was originally a fork of
[shacl-js](https://github.com/TopQuadrant/shacl-js) meant to make it compatible
with [RDF/JS](https://rdf.js.org/) libraries.
Since then, we dropped support for the SHACL-JS extension and adapted the API
to suit our needs.

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