# @shexjs/visitor

> Shape Expressions Visitor and schema index generator.

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

## Install

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

## 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.33 |
| Published | 2026-09-14 |
| First published | 2021-06-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=18 |
| Dependencies | 3 |
| Unpacked size | 49.9 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/visitor
- 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/visitor

## Dependencies (3)

- [@rdfjs/types](https://npm.io/package/@rdfjs/types.md) ^2.0.1
- [@shexjs/term](https://npm.io/package/@shexjs/term.md) ^1.0.0-alpha.28
- [@types/shexj](https://npm.io/package/@types/shexj.md) ^2.1.7

## 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.33 (latest) — 2026-09-14
- 1.0.0-alpha.31 — 2026-09-06
- 1.0.0-alpha.30 — 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.22 — 2022-08-18
- 1.0.0-alpha.21 — 2022-03-08
- 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/visitor

[![npm version](https://img.shields.io/npm/v/@shexjs/visitor)](https://www.npmjs.com/package/@shexjs/visitor)
[![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)

Visitor pattern for traversing [ShExJ](https://shex.io/shex-semantics/#shexj) schemas

## Install

``` shell
npm install @shexjs/visitor
```

## Quick start
The default behavior is to return a copy of the passed schema:
``` sh
node -e 'console.log(JSON.stringify(new (require("@shexjs/visitor").ShExVisitor)()
  .visitSchema(
    {
      "type": "Schema",
      "shapes": [
        {
          "id": "http://a.example/S1",
          "type": "ShapeDecl",
          "shapeExpr": {
            "type": "Shape",
            "expression": {
              "type": "TripleConstraint",
              "predicate": "http://a.example/p1",
              "valueExpr": {
                "type": "NodeConstraint",
                "values": [
                  {
                    "value": "1",
                    "type": "http://www.w3.org/2001/XMLSchema#integer"
                  },
                  {
                    "value": "2",
                    "type": "http://www.w3.org/2001/XMLSchema#integer"
                  }
                ]
              }
            }
          }
        }
      ]
    }), null, 2))'
```
The result will look identical to the input schema.

## Strategy
The ShExJ format is defined in [JSG](http://shex.io/shex-semantics/index.html#shexj) or [Typescript](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/shexj/index.d.ts). The visitor API reflects both the names of the ShExJ attributes and their types. For example, by default, the `visitShapeAnd` calls `visitShapeExpr` on each of the conjuncts. Likewise, `visitTripleConstraint` calls `visitValueExpr` on the `.valueExpr` attribute, which in turn calls `visitShapeExpr` because that is the type of `.valueExpr`.

## Methods

* visitSchema(schema, ...args
* visitPrefixes(prefixes, ...args
* visitIRI(i, ...args
* visitImports(imports, ...args
* visitStartActs(startActs, ...args
* visitSemActs([semActs], ...args
* visitSemAct(semAct, label, ...args
* visitAnnotations([annotations], ...args
* TODO visitAnnotation(annotation, ...args
* visitShapes(shapes, ...args
* visitShapeDecl(decl, ...args
* visitShapeExpr(expr, ...args - calls one of the following
  * visitShapeOr(shapeExpr, ...args
  * visitShapeAnd(shapeExpr, ...args
  * visitShapeNot(expr, ...args
  * visitShapeRef(reference, ...args
  * visitShapeExternal(expr, ...args
  * visitNodeConstraint(shape, ...args
  * visitShape(shape, ...args
* visitExtra([extra], ...args
* visitExpression(expr, ...args - calls visitTripleExpr
* visitTripleExpr(expr, ...args - calls one of the following
  * visitOneOf(tripleExpr, ...args
  * visitEachOf(tripleExpr, ...args
  * visitTripleConstraint(expr, ...args
* visitValueExpr(shapeExpr, ...args
* visitValues(values, ...args
* visitValueExpr(shapeExpr, ...args
* visitStemRange(t, ...args
* visitExclusion(c, ...args
* visitInclusion(inclusion, ...args

### simple value visitors
* visitBase
* visitStart
* visitClosed
* "visit@context"
* visitInverse
* visitPredicate
* visitName
* visitId
* visitCode
* visitMin
* visitMax
* visitType
* visitNodeKind
* visitDatatype
* visitPattern
* visitFlags
* visitLength
* visitMinlength
* visitMaxlength
* visitMininclusive
* visitMinexclusive
* visitMaxinclusive
* visitMaxexclusive
* visitTotaldigits
* visitFractiondigits
* visitInclude

## index(schema)

`ShExIndexVisitor.index(schema)` creates a visitor and overrides `visitTripleExpr` and `visitShapeDecl` to provide an index composed of two maps:
* **shapeExprs** - map from shape declaration name to definition in `schema`,
* **tripleExprs** - map from triple expression name to definition in `schema`.

---

`@shexjs/visitor` 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/visitor · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
