# @shexjs/term

> Shape Expressions triple expression evaluator - simple regexp returning 1 error.

Latest version **1.0.0-alpha.29** (published 2026-09-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install @shexjs/term
pnpm add @shexjs/term
yarn add @shexjs/term
bun add @shexjs/term
```

## Health

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

Positive: has types; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.0.0-alpha.29 |
| Published | 2026-09-06 |
| First published | 2021-06-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=18 |
| Dependencies | 4 |
| Unpacked size | 37 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 62 |
| Author | Eric Prud'hommeaux |
| Maintainers | ericprud, justinwb |
| Keywords | shex, shape expressions, rdf, query, parser |

## Links

- npm: https://www.npmjs.com/package/@shexjs/term
- Repository: https://github.com/shexjs/shex.js
- Homepage: https://github.com/shexjs/shex.js#readme
- Issues: https://github.com/shexSpec/grammar/issues
- npm.io page: https://npm.io/package/@shexjs/term

## Dependencies (4)

- [@rdfjs/types](https://npm.io/package/@rdfjs/types.md) ^2.0.1
- [@types/shexj](https://npm.io/package/@types/shexj.md) ^2.1.7
- [relativize-url](https://npm.io/package/relativize-url.md) ^0.1.0
- [rdf-data-factory](https://npm.io/package/rdf-data-factory.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

- 1.0.0-alpha.29 (latest) — 2026-09-06
- 1.0.0-alpha.28 — 2026-08-31
- 1.0.0-alpha.27 — 2023-10-23
- 1.0.0-alpha.25 — 2023-03-21
- 1.0.0-alpha.24 — 2022-09-16
- 1.0.0-alpha.21 — 2022-03-08
- 1.0.0-alpha.20 — 2022-01-12
- 1.0.0-alpha.19 — 2021-12-22
- 1.0.0-alpha.15 — 2021-07-18
- 1.0.0-alpha.12 — 2021-06-03

## README

# @shexjs/term

[![npm version](https://img.shields.io/npm/v/@shexjs/term)](https://www.npmjs.com/package/@shexjs/term)
[![CI](https://github.com/shexjs/shex.js/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/shexjs/shex.js/actions/workflows/ci.yml)

RDF terms as ShEx uses them: conversions between [RDF/JS terms](https://rdf.js.org/data-model-spec/), [ShExJ](https://shex.io/shex-semantics/#shexj)'s JSON-LD-style values, and Turtle lexical forms — plus the `Start` sentinel and the string-unescaping shared by the ShExC and ShapeMap parsers.

## Install

``` shell
npm install @shexjs/term
```

## Quick start

``` js
const Term = require("@shexjs/term");
const {DataFactory} = require("n3");

// RDF/JS term → ShExJ value (an IRI is a string; a literal is an object)
Term.rdfJsTerm2Ld(DataFactory.namedNode("http://a.example/n1"));
// 'http://a.example/n1'
Term.rdfJsTerm2Ld(DataFactory.literal("chat", "fr"));
// { value: 'chat', language: 'fr' }

// … and back
Term.ld2RdfJsTerm({value: "chat", language: "fr"});
// a Literal RDF/JS term for "chat"@fr

// either form → Turtle lexical form
Term.rdfJsTerm2Turtle(DataFactory.literal("chat", "fr"));   // '"chat"@fr'
Term.shExJsTerm2Turtle("http://a.example/n1");              // '<http://a.example/n1>'
```

## What's here

* **`rdfJsTerm2Ld(term)` / `ld2RdfJsTerm(ld)`** — between RDF/JS terms and the values ShExJ writes (IRI as string, `_:`‑prefixed blank node, literal as `{value, type?, language?}`).
* **`rdfJsTerm2Turtle(term, meta?)` / `shExJsTerm2Turtle(term, meta?)`** — render a term in Turtle, abbreviating with `meta`'s `base` and `prefixes` when given.
* **`Start` / `isStart(x)`** — the sentinel a [shape map](https://shexspec.github.io/shape-map/) uses to say "the schema's start shape": `{node, shape: Start}`. There is one frozen `Start` object; `isStart` also recognizes a structural clone (`{term: "START"}`), which is what survives a `postMessage` across a worker boundary.
* **`unescapeText(string, replacements)`** — the `\uXXXX`/`\U…` (and caller-supplied) escape decoding that the ShExC and ShapeMap grammars share.
* **`RdfLangString`, `XsdString`** — the two implicit literal datatypes.
* **`Terminals`** — regular expressions for RDF terminal productions (`IRIREF`, `PNAME_LN`, …).
* Types used across the suite: `SchemaIndex`, `ShapeMapEntry`, `Meta` and friends.

This package sits under everything else in the suite (the parsers, the validator, the neighborhoods), so it is versioned independently and depends on nothing else in it.

---

`@shexjs/term` is one of the [shex.js](https://github.com/shexjs/shex.js#readme) packages; installing [`shex`](https://www.npmjs.com/package/shex) pulls in the whole suite, and [its README](https://github.com/shexjs/shex.js/tree/main/packages/shex#the-shexjs-packages) maps them.

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