{"id":15012971,"url":"https://github.com/frog4js/schema","last_synced_at":"2026-01-20T14:02:43.759Z","repository":{"id":219952999,"uuid":"706029297","full_name":"frog4js/schema","owner":"frog4js","description":"JSONSchema (draft-03, draft-02, draft-01) Validation in Node.js (esm)","archived":false,"fork":false,"pushed_at":"2024-04-19T14:09:36.000Z","size":364,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-05T18:15:28.722Z","etag":null,"topics":["esmodule","javascript","jsonschema","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/frog4js.png","metadata":{"files":{"readme":"README-zh_CN.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-17T07:05:00.000Z","updated_at":"2024-02-28T13:13:54.000Z","dependencies_parsed_at":"2024-09-30T05:00:40.107Z","dependency_job_id":"210fa9be-43cd-4432-9793-cc70cd21a4df","html_url":"https://github.com/frog4js/schema","commit_stats":{"total_commits":25,"total_committers":2,"mean_commits":12.5,"dds":0.12,"last_synced_commit":"290aa7580c82e8a671592f896f9b75e3a2082cb9"},"previous_names":["frog4js/schema"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/frog4js/schema","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frog4js%2Fschema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frog4js%2Fschema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frog4js%2Fschema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frog4js%2Fschema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/frog4js","download_url":"https://codeload.github.com/frog4js/schema/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frog4js%2Fschema/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28604712,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T12:01:53.233Z","status":"ssl_error","status_checked_at":"2026-01-20T12:01:46.545Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["esmodule","javascript","jsonschema","nodejs"],"created_at":"2024-09-24T19:43:32.434Z","updated_at":"2026-01-20T14:02:43.744Z","avatar_url":"https://github.com/frog4js.png","language":"JavaScript","readme":"# @frog4js/schema\n\n-   [中文](README-zh_CN.md)\n-   [English](README.md)\n\n适用于 Node.js 和浏览器的 JSON Schema。即将支持所有的 draft(目前支持 draft-01,draft-02,draft-03,draft-04,draft-05,draft-06,draft-07)。\n\n## 功能\n\n-   使用函数式编程(esm + jsDoc + Function)\n-   会对 schema 进行预编译, 会占用额外的内存，单不会产生额外代码(和 ajv 有本质的区别)\n-   0 dependencies\n-   [x] 通过 JSON Schema test suite，包括可选的(部分跳过的如下)\n    -   (可选)none of the properties mentioned\n    -   (可选)valid leap second, large positive time-offset\n    -   (可选)valid leap second, large negative time-offset\n    -   (可选)a float is not an integer even without fractional part\n    -   (可选)refs to future drafts are processed as future drafts\n    -   (可选)format is iri, iri-reference, idn-email.json,idn-hostname\n-   [x] 基于词汇的验证\n-   [x] format assertions\n    -   [x] flag to enable in draft \u003c= 7\n    -   [ ] 自定义 format\n    -   [ ] 内置 format\n        -   [x] regex, uuid\n        -   [x] ipv4, ipv6\n        -   [x] hostname, email\n        -   [ ] idn-hostname, idn-email\n        -   [x] date, time, date-time\n        -   [x] json-pointer, relative-json-pointer\n        -   [x] uri, uri-reference, uri-template\n        -   [ ] iri, iri-reference\n        -   [ ] period\n-   [x] content assertions\n    -   [x] flag to enable in draft \u003c= 7\n    -   [x] contentEncoding\n        -   [x] base64\n        -   [ ] 自定义\n    -   [x] contentMediaType\n        -   [x] application/json\n        -   [ ] 自定义\n    -   [ ] contentSchema\n-   [ ] custom vocabulary\n-   [x] 引用的 schema 的可以是不同的 draft\n-   [x] 对 schema 更严格的检查\n    -   [x] default\n    -   [x] examples\n    -   [x] ref\n    -   [x] format\n\n## Installation\n\n```shell\nnpm install --save @frog4js/schema\n```\n\n## Quick Usage\n\n```javascript\nimport { contextManage } from \"@frog4js/schema/context\";\nimport { schemaManage } from \"@frog4js/schema/schema\";\nimport { vocabularyActuatorManage } from \"@frog4js/schema/vocabulary-actuator\";\n\nconst context = contextManage.create();\nschemaManage.setMainSchema(context, {\n    type: \"object\",\n});\nschemaManage.compile(context);\nconsole.log(vocabularyActuatorManage.validate(context, 1));\n```\n\n## 后续\n\n-   进行性能测试并优化性能\n-   支持 draft-2019-09, draft-2020-12\n-   完善 error\n-   支持剩余的 format\n-   检测无限循环陷阱\n-   自定义 format, vocabulary-actuator\n-   完善文档\n\n## API Reference\n\n### contextManage\n\n主要是用来创建 Context, Context 是用来挂载各种数据(如 schema,instance,errors 等等), 是执行过程的上下文数据。\n\n#### contextManage.create(defaultConfig?: DefaultConfig) =\u003e Context\n\n创建上下文, defaultConfig 是默认的一些配置。\n\n### schemaManage\n\n可以设置 main schema 和 ref schema。\n\n#### schemaManage.addReferenceSchema: (context: Context, schema: Schema) =\u003e void;\n\n添加被引用的 schema\n\n#### schemaManage.setMainSchema: (context: Context, schema: Schema) =\u003e void;\n\n设置 main schema\n\n#### schemaManage.compile: () =\u003e void;\n\n完成设置, 这里会检查$ref 指定的 schema 是否存在, 同时将禁止再修改 schema 相关的数据了\n\n### vocabularyActuatorManage\n\n验证 instance 是否符合 schema 的要求\n\n#### vocabularyActuatorManage.validate: (context: Context,instance: any,locale?: string) =\u003e {errors: ExecuteError[];valid: boolean;};\n\n验证通过 valid 为 true, 否则为 false, 同时 errors 中为具体失败的原因\n\n## Struct Definition\n\n### Context\n\n```ts\nexport type Context = {\n    errors: Array\u003cExecuteError\u003e;\n    locks: Array\u003c{\n        paths: Array\u003cstring\u003e;\n        errors: Array\u003cExecuteError\u003e;\n    }\u003e;\n    caches: Array\u003c{\n        schemaPaths: Array\u003cstring\u003e;\n        instancePaths: Array\u003cstring\u003e;\n        data: Record\u003cstring, any\u003e;\n    }\u003e;\n    startTime: number;\n    endTime: number;\n    instancePaths: Array\u003cstring | number\u003e;\n    schemaPaths: Array\u003cstring | number\u003e;\n    version: number;\n    schemaData: {\n        origin?: Schema;\n        main?: Schema;\n        current?: RefData;\n    };\n    instanceData: {\n        origin?: any;\n        current?: RefData;\n        locale?: string;\n    };\n    referenceSchemas: Record\u003cstring, Schema\u003e;\n    defaultConfig: DefaultConfig;\n    state: number;\n    phase?: number;\n    waitValidateRefs: {\n        $ref: string;\n        schema: Schema;\n    }[];\n};\n```\n\n### DefaultConfig\n\n```ts\nexport type DefaultConfig = {\n    $schema?: string;\n    baseURI?: string;\n    errorMessages?: Record\u003cstring, Record\u003cstring, string\u003e\u003e;\n    locale?: string;\n    strict?: boolean;\n};\n```\n\n### Schema\n\n```ts\ntype Reference = { $ref: string };\ntype CoreV3 = {\n    id?: string;\n};\n\ntype BasicTypeV3 = \"string\" | \"boolean\" | \"array\" | \"object\" | \"integer\" | \"null\" | \"any\" | \"number\";\ntype BasicTypeV4 = \"string\" | \"boolean\" | \"array\" | \"object\" | \"integer\" | \"null\" | \"number\";\n//  ============= v1\ntype ValidationV1 = {\n    type?: BasicTypeV3 | Array\u003cBasicTypeV3 | ChildSchemaV1\u003e;\n    default?: any;\n    optional?: boolean;\n    properties?: Record\u003cstring, ChildSchemaV1\u003e;\n    items?: ChildSchemaV1 | Array\u003cChildSchemaV1\u003e;\n    additionalProperties?: boolean | ChildSchemaV1;\n    requires?: string | ChildSchemaV1;\n    minimum?: number;\n    maximum?: number;\n    minimumCanEqual?: boolean;\n    maximumCanEqual?: boolean;\n    minItems?: number;\n    maxItems?: number;\n    format?: string;\n    pattern?: string;\n    maxLength?: number;\n    minLength?: number;\n    enum?: Array\u003cstring\u003e;\n    title?: string;\n    description?: string;\n    contentEncoding?: string;\n    maxDecimal?: number;\n    disallow?: BasicTypeV3 | Array\u003cBasicTypeV3\u003e;\n};\ntype ChildSchemaV1 = ValidationV1 | Reference;\ntype SchemaV1 = CoreV3 \u0026 ValidationV1 \u0026 { $schema: \"http://json-schema.org/draft-01/schema#\" };\n//  ============= v1\n\n//  ============= v2\ntype ValidationV2 = Exclude\u003cValidationV1, \"maxDecimal\"\u003e \u0026 {\n    type?: BasicTypeV3 | Array\u003cBasicTypeV3 | ChildSchemaV2\u003e;\n    properties?: Record\u003cstring, ChildSchemaV2\u003e;\n    items?: ChildSchemaV2 | Array\u003cChildSchemaV2\u003e;\n    additionalProperties?: boolean | ChildSchemaV2;\n    requires?: string | ChildSchemaV2;\n    divisibleBy?: number;\n    uniqueItems?: boolean;\n};\ntype ChildSchemaV2 = ValidationV2 | Reference;\ntype SchemaV2 = CoreV3 \u0026 ValidationV2 \u0026 { $schema: \"http://json-schema.org/draft-01/schema#\" };\n//  ============= v2\n\n//  ============= v3\ntype ValidationV3 = Exclude\u003cValidationV2, \"maximumCanEqual\" | \"minimumCanEqual\"\u003e \u0026 {\n    type?: BasicTypeV3 | Array\u003cBasicTypeV3 | ChildSchemaV3\u003e;\n    properties?: Record\u003cstring, ChildSchemaV3\u003e;\n    items?: ChildSchemaV3 | Array\u003cChildSchemaV3\u003e;\n    additionalProperties?: boolean | ChildSchemaV3;\n    requires?: string | ChildSchemaV3;\n    additionalItems?: boolean | ChildSchemaV3;\n    patternProperties?: Record\u003cstring, ChildSchemaV3\u003e;\n    dependencies?: Record\u003cstring, string | Array\u003cstring\u003e | ChildSchemaV3\u003e;\n    exclusiveMinimum?: boolean;\n    exclusiveMaximum?: boolean;\n};\ntype ChildSchemaV3 = ValidationV3 | Reference;\ntype SchemaV3 = CoreV3 \u0026 ValidationV3 \u0026 { $schema: \"http://json-schema.org/draft-01/schema#\" };\n//  ============= v3\n\n//  ============= v4\ntype CoreV4 = {\n    id?: string;\n    definitions?: Record\u003cstring, ChildSchemaV4\u003e;\n};\ntype ValidationV4 = Exclude\u003cValidationV3, \"contentEncoding\" | \"divisibleBy\"\u003e \u0026 {\n    type?: BasicTypeV4 | Array\u003cBasicTypeV4\u003e;\n    properties?: Record\u003cstring, ChildSchemaV4\u003e;\n    items?: ChildSchemaV4 | Array\u003cChildSchemaV4\u003e;\n    additionalProperties?: boolean | ChildSchemaV4;\n    additionalItems?: boolean | ChildSchemaV4;\n    patternProperties?: Record\u003cstring, ChildSchemaV4\u003e;\n    dependencies?: Record\u003cstring, Array\u003cstring\u003e | ChildSchemaV4\u003e;\n    anyOf?: Array\u003cChildSchemaV4\u003e;\n    oneOf?: Array\u003cChildSchemaV4\u003e;\n    allOf?: Array\u003cChildSchemaV4\u003e;\n    requires?: Array\u003cstring\u003e;\n    minProperties?: number;\n    maxProperties?: number;\n    multipleOf?: number;\n};\ntype ChildSchemaV4 = ValidationV4 | Reference;\ntype SchemaV4 = CoreV4 \u0026 ValidationV4 \u0026 { $schema: \"http://json-schema.org/draft-04/schema#\" };\n//  ============= v4\n\n//  ============= v5\ntype SchemaV5 = CoreV4 \u0026 ValidationV4 \u0026 { $schema: \"http://json-schema.org/draft-05/schema#\" };\n//  ============= v5\n\n//  ============= v6\ntype CoreV6 = {\n    $id?: string;\n    definitions?: Record\u003cstring, ChildSchemaV6\u003e;\n};\ntype ValidationV6 = ValidationV4 \u0026 {\n    properties?: Record\u003cstring, ChildSchemaV6\u003e;\n    items?: ChildSchemaV6 | Array\u003cChildSchemaV6\u003e;\n    additionalProperties?: boolean | ChildSchemaV6;\n    additionalItems?: boolean | ChildSchemaV6;\n    patternProperties?: Record\u003cstring, ChildSchemaV6\u003e;\n    dependencies?: Record\u003cstring, Array\u003cstring\u003e | ChildSchemaV6\u003e;\n    anyOf?: Array\u003cChildSchemaV6\u003e;\n    oneOf?: Array\u003cChildSchemaV6\u003e;\n    allOf?: Array\u003cChildSchemaV6\u003e;\n    propertyNames?: ChildSchemaV6;\n    const?: any;\n    examples?: Array\u003cany\u003e;\n    exclusiveMinimum?: number;\n    exclusiveMaximum?: number;\n};\ntype ChildSchemaV6 = ValidationV6 | Reference | boolean;\ntype SchemaV6 = CoreV6 \u0026 ValidationV6 \u0026 { $schema: \"http://json-schema.org/draft-06/schema#\" };\n//  ============= v6\n\n//  ============= v7\ntype CoreV7 = {\n    $schema?: \"http://json-schema.org/draft-07/schema#\";\n    $id?: string;\n    definitions?: Record\u003cstring, ChildSchemaV6\u003e;\n};\ntype ValidationV7 = ValidationV6 \u0026 {\n    properties?: Record\u003cstring, ChildSchemaV7\u003e;\n    items?: ChildSchemaV7 | Array\u003cChildSchemaV7\u003e;\n    additionalProperties?: boolean | ChildSchemaV7;\n    additionalItems?: boolean | ChildSchemaV7;\n    patternProperties?: Record\u003cstring, ChildSchemaV7\u003e;\n    dependencies?: Record\u003cstring, Array\u003cstring\u003e | ChildSchemaV7\u003e;\n    anyOf?: Array\u003cChildSchemaV7\u003e;\n    oneOf?: Array\u003cChildSchemaV7\u003e;\n    allOf?: Array\u003cChildSchemaV7\u003e;\n    propertyNames?: ChildSchemaV7;\n    if?: boolean | ChildSchemaV7;\n    then?: boolean | ChildSchemaV7;\n    else?: boolean | ChildSchemaV7;\n};\ntype ChildSchemaV7 = ValidationV7 | Reference | boolean;\ntype SchemaV7 = CoreV7 \u0026 ValidationV7;\n//  ============= v7\nexport type Schema = SchemaV1 | SchemaV2 | SchemaV3 | SchemaV4 | SchemaV5 | SchemaV6 | SchemaV7;\n```\n\n### Error\n\n```ts\nexport type ExecuteError = {\n    instancePath: string;\n    schemaPath: string;\n    currentSchemaKey: string;\n    currentSchemaValue: any;\n    currentInstanceKey: string;\n    currentInstanceValue: any;\n    message: string;\n};\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrog4js%2Fschema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrog4js%2Fschema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrog4js%2Fschema/lists"}