OSS TanbouSign in with GitHub

compose small structs to validate JavaScript and TypeScript data at runtime

About these scores

OSS scale score is an unbounded metric that log-compresses and weights Stars, Watchers, Forks, and Contributors. Discovery score is the current OSS scale score minus the score at discovery. Update pace is commits in the last 30 days, growth momentum is the OSS scale score difference within the recent observation window, and OSS health is a 0–100 rating based on available recency, Community Health, and release data.

Stars
7,127
Primary language
TypeScript
License
MIT
Repository last updated
Oct 1, 2024
On this page

Overview

Superstruct composes object, array, string, number, and other structs into runtime validators. assert, is, and validate support different error-handling styles, while custom types and coercion extend validation for application-specific data. TypeScript values are narrowed after successful checks.

Features and best fit

Based on official documentation; not hands-on tested · Content checked:

Key features

Compose object, array, and primitive structs into schemas

object, array, string, number, and related helpers define runtime shapes for REST, GraphQL, and other data. Smaller structs can be reused as building blocks for larger models.

Sources: [1]

Choose assert, is, or validate for error handling

assert throws on invalid input, is returns a boolean and acts as a TypeScript type guard, and validate supports result-oriented handling without relying on exceptions.

Sources: [1]

Extend validation with custom types and coercion

define can add application-specific validators such as email or UUID checks, while create and defaulted can coerce data and add defaults before validation.

Sources: [1]

Best fit

Fits frontends and APIs that want small composable runtime validation

It suits projects that prefer JavaScript/TypeScript-native schema definitions in application code rather than depending on an external schema specification.

Sources: [1]

Before adoption

Coercion changes values before validation completes

APIs such as create and other coercion helpers can add defaults or transform input. Keep those flows separate from assert, is, and validate when a boundary is expected to validate without mutation.

Sources: [1]

The v2.0.2 release tag and package manifest have an upstream version mismatch

GitHub's latest release is v2.0.2, while package.json inside that tag still reports 2.0.1. The reviewed main manifest reports 2.0.2. Use the published 2.0.2 package as the adoption baseline rather than relying only on the tag manifest.

Sources: [2][3][4]

Official sources

  1. [1]Superstruct v2.0.2 README(2026-10-05)
  2. [2]Superstruct v2.0.2 release(2026-10-05)
  3. [3]Superstruct package metadata at v2.0.2 tag(2026-10-05)
  4. [4]Superstruct package metadata at reviewed main commit(2026-10-05)
  5. [5]Superstruct MIT license(2026-10-05)
Supplemental curator note

Use assert, is, or validate for validation-only flows, and create when defaults or coercion are intended. Separating transformation from pure validation makes API-boundary behavior easier to reason about.

Try it in 3 steps

  1. 1

    Install Superstruct 2.0.2 in an isolated project

    Pin the package corresponding to the latest GitHub release.

    demo=$(mktemp -d "${TMPDIR:-/tmp}/superstruct.XXXXXX") && cd "$demo" && npm init -y >/dev/null && npm install --save-exact superstruct@2.0.2
  2. 2

    Create an object struct and check valid and invalid data

    Use the README's object and is APIs and require the correct value to pass while the wrong field type fails.

    printf "%s\n" "import {is, object, number, string} from 'superstruct';" "const User = object({id: number(), name: string()});" "if (!is({id: 1, name: 'Ada'}, User)) process.exit(1);" "if (is({id: '1', name: 'Ada'}, User)) process.exit(1);" "console.log('validated');" > demo.mjs
  3. 3

    Run the validation with Node.js

    Confirm the non-throwing is validation flow behaves as expected.

    node demo.mjs
Check the official README

Growth

Growth trends · Last 30 days

7,127 Stars

Trend data is still being collected.

Development activity

Last 90 days · weekly

Commits (last 30 days)
0
Open PRs
22

Development activity is still being collected.

Built with

Categories and tags

GitHub data

GitHub dataView detailed GitHub data

GitHub Topics

  • validation
  • types
  • interface
  • structs
  • schema
  • javascript
  • typescript
Stars
7,127
Forks
223
Watchers
43
Open issues
82
Contributors
66
Owner type
User
Primary language
TypeScript
License
MIT
Repository last updated
Oct 1, 2024
Write a related article

Share a guide or use case for this OSS in Markdown. Articles are published after administrator approval.

Report incorrect information

Tell us if any listing information is incorrect or outdated.

After reading this page, do you know what to do next?