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

@winglet/json-schema

v0.13.2

Published

Powerful utility library for JSON Schema manipulation featuring schema traversal, validation, reference resolution, and filtering with TypeScript support and visitor pattern implementation

Readme

@winglet/json-schema

Typescript Json Schema


Overview

@winglet/json-schema is a powerful utility library for working with JSON Schema and JSON data. It provides key functionalities such as JSON Schema structure traversal, validation, reference resolution, and filtering. Written in TypeScript to ensure type safety, it offers various features for structured processing of JSON Schema.


Installation

# Using npm
npm install @winglet/json-schema

# Using yarn
yarn add @winglet/json-schema

Sub-path Imports

This package supports sub-path imports to enable more granular imports and optimize bundle size. You can import specific modules directly without importing the entire package:

// Main exports (all utilities and type definitions)
import { JsonSchemaScanner, isObjectSchema } from '@winglet/json-schema';

// Synchronous schema scanner
import { JsonSchemaScanner } from '@winglet/json-schema/scanner';

// Asynchronous schema scanner
import { JsonSchemaScannerAsync } from '@winglet/json-schema/async-scanner';

// Schema type checking utilities
import {
  isArraySchema,
  isObjectSchema,
  isStringSchema,
  isNumberSchema,
  isBooleanSchema,
  isNullSchema
} from '@winglet/json-schema/filter';

Available Sub-paths

Based on the package.json exports configuration:

  • @winglet/json-schema - Main exports (all utilities, scanners, and type definitions)
  • @winglet/json-schema/scanner - Synchronous JSON Schema scanner (JsonSchemaScanner)
  • @winglet/json-schema/async-scanner - Asynchronous JSON Schema scanner (JsonSchemaScannerAsync)
  • @winglet/json-schema/filter - Schema type checking and filtering utilities (isArraySchema, isObjectSchema, etc.)

Compatibility

Supported environments:

  • Node.js 16.11.0 or later
  • Modern browsers (Chrome 94+, Firefox 93+, Safari 15+)

For legacy environment support: Please use a transpiler like Babel to transform the code for your target environment.

Target packages

  • @winglet/json-schema
  • @winglet/common-utils

Key Features

1. Schema Traversal and Validation

  • JsonSchemaScanner: A class that traverses JSON schema using depth-first search (DFS) approach, implements the Visitor pattern, and resolves $ref references
  • JsonSchemaScannerAsync: An extension of JsonSchemaScanner that supports asynchronous operations

2. Type Validation and Filtering

3. JSON Schema Type Definitions


Usage Examples

Using JsonSchemaScanner

import { JsonSchemaScanner } from '@winglet/json-schema';

// Schema definition
const schema = {
  type: 'object',
  properties: {
    name: { type: 'string' },
    age: { type: 'number' },
    address: {
      type: 'object',
      properties: {
        city: { type: 'string' },
        zipCode: { type: 'string' },
      },
    },
  },
};

// Using Visitor pattern to traverse schema
const scanner = new JsonSchemaScanner({
  visitor: {
    enter: (entry, context) => {
      console.log(`Enter: ${entry.path}`);
    },
    exit: (entry, context) => {
      console.log(`Exit: ${entry.path}`);
    },
  },
  options: {
    maxDepth: 5, // Set maximum traversal depth
    filter: (entry, context) => {
      // Filter nodes based on specific conditions
      return true;
    },
    mutate: (entry, context) => {
      // Mutate schema based on specific conditions
      return entry.schema;
    },
  },
});

// Scan the schema
scanner.scan(schema);

// Get the processed schema
const processedSchema = scanner.getValue();

Checking Schema Types

import {
  isArraySchema,
  isObjectSchema,
  isStringSchema,
} from '@winglet/json-schema';

const schema = {
  type: 'object',
  properties: {
    /* ... */
  },
};

if (isObjectSchema(schema)) {
  // Process object schema
  const properties = schema.properties;
  // ...
} else if (isArraySchema(schema)) {
  // Process array schema
  const items = schema.items;
  // ...
}

Development Environment Setup

# Clone repository
dir=your-albatrion && git clone https://github.com/vincent-kk/albatrion.git "$dir" && cd "$dir"

# Install dependencies
nvm use && yarn install && yarn run:all build

# Development build
yarn jsonSchema build

# Run tests
yarn jsonSchema test

API Reference

Main Classes and Functions

JsonSchemaScanner

A class for traversing JSON schema and resolving references.

class JsonSchemaScanner<ContextType = void> {
  constructor(props?: {
    visitor?: SchemaVisitor<ContextType>;
    options?: JsonScannerOptions<ContextType>;
  });
  scan(schema: UnknownSchema): this;
  getValue<Schema extends UnknownSchema>(): Schema | undefined;
}

JsonSchemaScannerAsync

An extension of JsonSchemaScanner that supports asynchronous operations.

class JsonSchemaScannerAsync<
  ContextType = void,
> extends JsonSchemaScanner<ContextType> {
  scanAsync(schema: UnknownSchema): Promise<this>;
  getValueAsync<Schema extends UnknownSchema>(): Promise<Schema | undefined>;
}

Type Validation Functions

function isArraySchema(schema: UnknownSchema): schema is ArraySchema;
function isNumberSchema(schema: UnknownSchema): schema is NumberSchema;
function isObjectSchema(schema: UnknownSchema): schema is ObjectSchema;
function isStringSchema(schema: UnknownSchema): schema is StringSchema;
function isBooleanSchema(schema: UnknownSchema): schema is BooleanSchema;
function isNullSchema(schema: UnknownSchema): schema is NullSchema;

Main Type Definitions

// Basic JSON Schema types
type JsonSchema<Options extends Dictionary = object> =
  | NumberSchema<Options, JsonSchema>
  | StringSchema<Options, JsonSchema>
  | BooleanSchema<Options, JsonSchema>
  | ArraySchema<Options, JsonSchema>
  | ObjectSchema<Options, JsonSchema>
  | NullSchema<Options, JsonSchema>;

// Value types
type BooleanValue = boolean;
type NumberValue = number;
type StringValue = string;
type ArrayValue = any[];
type ObjectValue = Record<string, any>;
type NullValue = null;

License

This repository is provided under the MIT License. For details, please refer to the LICENSE file.


Contact

For inquiries or suggestions related to the project, please create an issue.