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

@jasonwarrenuk/schema-forge

v0.3.0

Published

XSD-driven schema system for dynamic validation, XML generation and CSV-to-schema mapping

Readme

schema-forge

An XSD-driven schema system for dynamic validation, XML generation and CSV-to-schema mapping.

Parse XSD files into queryable registries, then use those registries to validate data, map CSV rows to nested schema objects and generate valid XML.

Requirements

schema-forge ships raw TypeScript with no build step. It requires a runtime or bundler that consumes .ts directly: Bun, Vite or SvelteKit. It will not work under plain Node or tsc-compiled projects.

Installation

bun add @jasonwarrenuk/schema-forge

Usage

Everything is exported from the package root. Deep imports into src/ are not a supported interface.

Build a registry from an XSD

import { buildSchemaRegistry } from "@jasonwarrenuk/schema-forge";

const xsdContent = await Bun.file("schema.xsd").text();
const registry = buildSchemaRegistry(xsdContent);

registry.elementsByPath.get("Message.Learner.ULN");
// → SchemaElement { name: 'ULN', baseType: 'string', constraints: { ... } }

buildSchemaRegistry is synchronous. It throws if the XSD has no root element, or more than one.

Validate a value against an element

import { validateValue } from "@jasonwarrenuk/schema-forge";

const element = registry.elementsByPath.get("Message.Learner.ULN");
const issues = validateValue("1234567890", element, { rowIndex: 0, sourceField: "ULN" });
// → [] when valid, otherwise SchemaValidationIssue[]

Validate CSV rows

import { parseCSVContent, validateRows } from "@jasonwarrenuk/schema-forge";

const { headers, rows } = parseCSVContent(csvString);

// Note: validateRows takes a MappingConfig, not a bare array
const result = validateRows(rows, headers, registry, { mappings });

Map CSV rows to nested objects

import { mapCsvToSchema } from "@jasonwarrenuk/schema-forge";

const mappings = [
	{ csvColumn: "Student ID", xsdPath: "Message.Learner.LearnRefNumber" },
	{ csvColumn: "Postcode", xsdPath: "Message.Learner.Postcode", transform: "postcode" },
];

const nested = mapCsvToSchema(csvRow, mappings, registry);
// → { Message: { Learner: { LearnRefNumber: "ABC123", Postcode: "E1 6AN" } } }

Column matching is case-insensitive. mapCsvToSchema takes the mappings array directly, unlike validateRows.

Generate XML

import { generateFromSchema } from "@jasonwarrenuk/schema-forge";

const { xml, warnings } = generateFromSchema(data, registry);

Generation always produces output. Missing required elements and type mismatches are reported as warnings, not thrown.

Supported XSD features

| Feature | Details | |---|---| | Base types | string, int, integer, long, decimal, date, dateTime, boolean | | Constraints | pattern, length, minLength, maxLength, minInclusive, maxInclusive, minExclusive, maxExclusive, totalDigits, fractionDigits, enumeration | | Complex types | xs:sequence with nested elements | | Cardinality | minOccurs, maxOccurs (including unbounded) | | Named types | Simple type reuse and inheritance | | Namespaces | targetNamespace extraction and preservation |

Requirements and limitations

The parser expects a specific XSD shape and throws when it is not met:

  • Elements must use the literal xs: prefix throughout
  • Exactly one top-level element
  • A targetNamespace must be present

The following are not supported. buildSchemaRegistry throws when it meets one, naming the construct and the element path, rather than building a registry with the content silently missing:

  • xs:choice, xs:all, xs:group, xs:any
  • xs:complexContent / xs:extension, xs:simpleContent
  • xs:attribute, xs:attributeGroup
  • xs:element ref
  • xs:include, xs:import (single-document schemas only)
  • Named xs:complexType references (inline xs:complexType only)

Only the first xs:pattern on a restriction is honoured. A pattern that cannot be compiled as a JavaScript regex produces a warning-severity issue rather than being skipped, since XSD's regex grammar is not a subset of JavaScript's.

Built-in transforms

21 named transforms, plus parameterised constant(value) and normalizeAddress(n).

Type conversions: stringToInt, stringToIntOptional, stringToIntStrict, stringToFloat, stringToFloatStrict, stringToBoolean, boolToInt

String: trim, uppercase, lowercase, uppercaseTrim, uppercaseNoSpaces, postcode, removeSpaces, digitsOnly, normalizeAddress

Date/time: passthroughDate, passthroughDateTime

Conditional: nullIfEmpty

Prefer the Strict variants for numeric conversion. stringToInt and stringToFloat are parseInt(v, 10) || 0, so a genuine "0" and unparseable input both yield 0; the strict variants return undefined instead.

isoDate and isoDateTime are deprecated aliases for the passthrough transforms. Neither ever parsed or reformatted anything, and the names implied otherwise.

Two transforms carry assumptions from their original use: normalizeAddress defaults to truncating at 50 characters (pass normalizeAddress(n) for your own schema's limit), and digitsOnly strips a leading +, which loses an international dialling prefix.

Provenance

schema-forge was extracted from foundersandcoders/iris, an ILR toolkit, where the engine originally lived. This repository is now the canonical home; iris consumes it as a dependency.

Dependencies

Licence

MIT