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 🙏

© 2025 – Pkg Stats / Ryan Hefner

json-schema-meta-type

v1.0.0

Published

JSON Schema meta object type definition

Readme

JSON Schema Meta Type

JSON Schema 2020-12 元模式的 TypeScript 类型定义。

简介

本项目提供了 JSON Schema 2020-12 规范的完整 TypeScript 类型定义,包括所有官方词汇表(vocabularies)。这些类型定义可以帮助您在 TypeScript 项目中以类型安全的方式使用 JSON Schema。

特性

  • ✅ 完整的 JSON Schema 2020-12 规范支持
  • ✅ 包含所有官方词汇表:
    • Core: 核心标识和引用机制($id, $ref, $schema 等)
    • Applicator: 应用器,定义如何应用子模式(properties, items, allOf 等)
    • Unevaluated: 处理未求值位置(unevaluatedItems, unevaluatedProperties
    • Validation: 验证约束(type, minimum, maxLength 等)
    • Meta-Data: 元数据注解(title, description, examples 等)
    • Format: 格式注解(format
    • Content: 内容编码(contentEncoding, contentMediaType 等)
  • ✅ 支持已弃用的属性以保持向后兼容
  • ✅ 完整的 TypeScript 类型提示和文档注释

安装

npm install json-schema-meta-type

使用方法

基本用法

import type { JSONSchemaMeta202012 } from 'json-schema-meta-type';

// 布尔模式
const alwaysValid: JSONSchemaMeta202012 = true;
const alwaysFail: JSONSchemaMeta202012 = false;

// 空对象模式(允许任何值)
const anyValue: JSONSchemaMeta202012 = {};

// 完整的 Schema 定义
const userSchema: JSONSchemaMeta202012 = {
  $schema: "https://json-schema.org/draft/2020-12/schema",
  $id: "https://example.com/user.schema.json",
  title: "User",
  description: "用户信息模式",
  type: "object",
  properties: {
    name: {
      type: "string",
      minLength: 1,
      maxLength: 100
    },
    age: {
      type: "integer",
      minimum: 0,
      maximum: 150
    },
    email: {
      type: "string",
      format: "email"
    }
  },
  required: ["name", "email"],
  additionalProperties: false
};

使用特定词汇表

您也可以单独导入特定的词汇表类型:

import type { JSONSchemaMetaCore202012 } from 'json-schema-meta-type/typings/json_schema_meta_core_2020-12';
import type { JSONSchemaMetaValidation202012 } from 'json-schema-meta-type/typings/json_schema_meta_validation_2020-12';

高级示例

import type { JSONSchemaMeta202012 } from 'json-schema-meta-type';

// 使用 $ref 引用
const addressSchema: JSONSchemaMeta202012 = {
  $defs: {
    address: {
      type: "object",
      properties: {
        street: { type: "string" },
        city: { type: "string" },
        country: { type: "string" }
      },
      required: ["street", "city", "country"]
    }
  },
  type: "object",
  properties: {
    billingAddress: { $ref: "#/$defs/address" },
    shippingAddress: { $ref: "#/$defs/address" }
  }
};

// 使用组合关键字
const polymorphicSchema: JSONSchemaMeta202012 = {
  oneOf: [
    { type: "string" },
    { type: "number" },
    {
      type: "object",
      properties: {
        value: { type: "string" }
      }
    }
  ]
};

// 使用模式属性
const configSchema: JSONSchemaMeta202012 = {
  type: "object",
  properties: {
    name: { type: "string" },
    version: { type: "string" }
  },
  patternProperties: {
    "^x-": { type: "string" }  // 扩展字段
  },
  additionalProperties: false
};

API 文档

主要类型

JSONSchemaMeta202012

完整的 JSON Schema 2020-12 元模式类型,包含所有词汇表。

type JSONSchemaMeta202012 = boolean | {
  // Core 词汇表
  $id?: string;
  $schema?: string;
  $ref?: string;
  $defs?: Record<string, JSONSchemaMeta202012>;

  // Validation 词汇表
  type?: string | string[];
  enum?: any[];
  const?: any;

  // Applicator 词汇表
  properties?: Record<string, JSONSchemaMeta202012>;
  items?: JSONSchemaMeta202012;
  allOf?: JSONSchemaMeta202012[];

  // Meta-Data 词汇表
  title?: string;
  description?: string;
  examples?: any[];

  // ... 更多属性
};

词汇表类型

  • JSONSchemaMetaCore202012: 核心词汇表
  • JSONSchemaMetaApplicator202012: 应用器词汇表
  • JSONSchemaMetaValidation202012: 验证词汇表
  • JSONSchemaMetaMetaData202012: 元数据词汇表
  • JSONSchemaMetaFormatAnnotation202012: 格式注解词汇表
  • JSONSchemaMetaContent202012: 内容词汇表
  • JSONSchemaMetaUnevaluated202012: 未求值词汇表

兼容性

  • TypeScript 4.0+

相关资源

许可证

ISC

贡献

欢迎提交 Issue 和 Pull Request!

仓库

https://github.com/ww-k/json-schema-meta-type