npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@step-nc/p21-parser

v1.0.0

Published

Zero-dependency TypeScript parser for ISO 10303-21 (STEP Part 21) exchange structure files.

Readme

@step-nc/p21-parser

Parser sin dependencias para archivos ISO 10303-21 (STEP Part 21). Tokeniza y parsea el exchange structure en un AST tipado (P21DocumentNode) con diagnósticos y posiciones de fuente completas.

Para la arquitectura del paquete (pipeline, lexer, parser, AST y visitor), véase ARCHITECTURE.md. Para el estado y el roadmap, véase ROADMAP.md.

Uso mínimo

import { parseP21 } from '@step-nc/p21-parser';

const source = `
ISO-10303-21;
HEADER;
  FILE_DESCRIPTION(('Example'), '2;1');
ENDSEC;
DATA;
  #1 = CARTESIAN_POINT('Origin', 0.0, 0.0, 0.0);
ENDSEC;
END-ISO-10303-21;
`;

const result = parseP21(source);

// AST raíz: documento P21 con header, data, etc.
const ast = result.ast;

// Diagnósticos (errores y advertencias de lexer y parser)
const diagnostics = result.diagnostics;

API principal

  • parseP21(source, options?) — Parsea una cadena P21 y devuelve un ParseResult con ast (raíz P21DocumentNode) y diagnostics.
  • lexP21(source) — Solo tokenización; devuelve LexResult con tokens y diagnostics de lexer.
  • ParseResult{ ast: P21DocumentNode; diagnostics: P21ParseDiagnostic[] }.
  • LexResult{ tokens: P21Token[]; diagnostics: P21LexDiagnostic[] }.
  • Tipos del AST — Todos los nodos se exportan: P21DocumentNode, HeaderSectionNode, DataSectionNode, EntityInstanceNode, ParameterNode, AnchorSectionNode, ReferenceSectionNode, SignatureSectionNode, etc. Cada nodo tiene type, span (posición en el texto) y campos específicos.
  • Helpers de spantokenStart, tokenEnd, spanBetween, spanOfToken, spanFromTokens para construir spans desde tokens.
  • ParserContext — Contexto del parser (tokens, posición, consume, expect, etc.) para uso avanzado.
  • getChildren(node) — Devuelve los hijos de un nodo del AST para recorridos manuales.

Recorrido del AST

  • visit(ast, visitor) — Recorrido en pre-order con handlers opcionales por tipo de nodo (onP21Document, onHeaderSection, onDataSection, onSimpleEntityInstance, etc.). Retornar 'skip' para no visitar los hijos de ese nodo.
  • walk(ast, callback, options?) — Recorrido de todos los nodos; orden 'pre' (por defecto) o 'post' según options.order.

Ejemplo con visit (listar instancias de entidad en DATA):

import { parseP21, visit } from '@step-nc/p21-parser';

const result = parseP21(source);
const ids: number[] = [];
visit(result.ast, {
  onSimpleEntityInstance(node) {
    ids.push(node.id);
  },
  onComplexEntityInstance(node) {
    ids.push(node.id);
  },
});

Ejemplo con walk (contar nodos):

import { parseP21, walk } from '@step-nc/p21-parser';

const result = parseP21(source);
let count = 0;
walk(result.ast, () => count++);
console.log('Total nodes:', count);

Conformance classes (ISO 10303-21)

El parser soporta las cuatro clases de conformidad:

| Clase | Secciones | Estado | |-------|------------|--------| | CC1 | HEADER + DATA | ✅ | | CC2 | Múltiples DATA | ✅ | | CC3 | ANCHOR + REFERENCE | ✅ | | CC4 | SIGNATURE | ✅ |

Requisitos

  • Node.js >= 20
  • TypeScript 5.x (para desarrollo)

Scripts

pnpm --filter @step-nc/p21-parser build    # Compilar
pnpm --filter @step-nc/p21-parser test     # Tests
pnpm --filter @step-nc/p21-parser coverage # Cobertura
pnpm --filter @step-nc/p21-parser clean    # Borrar dist