{"id":20822664,"url":"https://github.com/moongoal/happy-chappy","last_synced_at":"2026-04-24T06:31:17.841Z","repository":{"id":57261233,"uuid":"448131069","full_name":"moongoal/happy-chappy","owner":"moongoal","description":"JSON object validation module for JavaScript and TypeScript","archived":false,"fork":false,"pushed_at":"2023-10-18T02:06:19.000Z","size":912,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-27T14:31:44.569Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moongoal.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2022-01-14T23:06:15.000Z","updated_at":"2022-01-14T23:06:33.000Z","dependencies_parsed_at":"2023-02-08T08:40:18.291Z","dependency_job_id":"29adb0dc-3678-46a9-bcf3-df102d6383cd","html_url":"https://github.com/moongoal/happy-chappy","commit_stats":{"total_commits":21,"total_committers":2,"mean_commits":10.5,"dds":0.04761904761904767,"last_synced_commit":"891f4dea99a90abe9577a0bbce316465deb0014e"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/moongoal/happy-chappy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moongoal%2Fhappy-chappy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moongoal%2Fhappy-chappy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moongoal%2Fhappy-chappy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moongoal%2Fhappy-chappy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moongoal","download_url":"https://codeload.github.com/moongoal/happy-chappy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moongoal%2Fhappy-chappy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32212805,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T03:15:14.334Z","status":"ssl_error","status_checked_at":"2026-04-24T03:15:11.608Z","response_time":64,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":[],"created_at":"2024-11-17T22:15:42.513Z","updated_at":"2026-04-24T06:31:17.825Z","avatar_url":"https://github.com/moongoal.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# happy-chappy\n\nHappy-chappy is a compact, dependency-free JSON object validator package for JavaScript and TypeScript.\n\n## Usage\n\n```typescript\nimport { Schema, createValidator, validate } from \"happy-chappy\";\n\nconst MY_OBJECT_SCHEMA: Schema = {\n    object: {\n        members: {\n            firstField: \"number\",\n\n            secondField: {\n                number: {},\n                optional: true\n            },\n\n            thirdField: \"string\",\n\n            fourthField: {\n                enum: [1, 2, 3, \"four\", 5]\n            }\n        }\n    }\n};\n\nconst validateMyObject = createValidator(MY_OBJECT_SCHEMA);\nconst myObject = { firstField: 5, thirdField: \"hey\", fourthField: \"four\" };\n\nvalidateMyObject(myObject) === true;\n\n// Or alternatively\nvalidate(myObject, MY_OBJECT_SCHEMA) === true;\n```\n\nMany more examples available in the test folder.\n\n## Data types\n\nSupported data types are:\n\n* String\n* Number\n* Boolean\n* Array\n* Object\n* Enumeration\n\nEach of these can be further restricted using matcher functions or specific configuration.\n\n### String options\n\nText string validation is supported using multiple types of matcher. A string can be matched by:\n\n* An exact value\n* A regular expression\n* A matcher function\n\n### Number options\n\nNumber validation options allow to restrict the available range as follows:\n\n* Exact value matching (checked with the strict equality operator or matcher)\n* Minimum threshold\n* Maximum threshold\n* Integer vs floating point\n* Epsilon (custom floating point comparison constant)\n\n### Array options\n\nArrays can be further scoped by setting the following:\n\n* Exact length\n* Minimum length\n* Maximum length\n* Matcher function\n\n### Object options\n\nObject specification can be customised by allowing extra memebrs not to be taken into account during validation or by specifying a matcher function.\n\n### Enumerations\n\nEnumerated values can be any string or number, matched with the strict equality operator.\n\n## Matchers\n\nMatchers allow more complex logic to be included in the validation model. For example:\n\n```typescript\nconst isPersonWithAgeTuple = (v: any[]) =\u003e (\n    v.length === 2\n    \u0026\u0026 typeof v[0] === \"string\"\n    \u0026\u0026 typeof v[1] === \"number\"\n    \u0026\u0026 Number.isInteger(v[1])\n); // Enforces [Name: string, Age: integer]\n\nconst schema: Schema = {\n    array: { matcher: isPersonWithAgeTuple }\n};\n\nvalidate([\"Dummy\", 5], schema) === true;\nvalidate([5, \"Dummy\"], schema) === false;\n```\n\n## Typing Aids\n\nVersion 2 brings in typing aids for objects and enumerations to streamline the schema ceration process. When you define a schema for an object or enumeration you can provide a type that will be used to assist in constraining object members and enumerated values.\n\n```typescript\ninterface MyRequest {\n    a: number\n    b: string\n}\n\nconst MY_REQUEST_SCHEMA: Schema\u003cMyRequest\u003e = {\n    object: {\n        members: {\n            a: { ... },\n            b: { ... },\n            c: { ... }, // TypeScript error!\n        }\n    }\n};\n```\n\n```typescript\nenum MyEnum {\n    first = 1,\n    second = 2\n}\n\nconst MY_REQUEST_SCHEMA: Schema\u003cMyEnum\u003e = {\n    enum: [\n        MyEnum.first,\n        2,\n        3 // TypeScript error!\n    ]\n};\n```\n\n```typescript\ntype MyEnum = \"first\" | \"second\";\n\nconst MY_REQUEST_SCHEMA: Schema\u003cMyEnum\u003e = {\n    enum: [\n        \"first\",\n        \"second\",\n        \"third\" // TypeScript error!\n    ]\n};\n```\n\n## Changelog\n\nRead the changelog [here](./CHANGELOG.md).\n\n## License\n\nThis package is licensed under the [ISC license](./LICENSE).\n\n## Bugs and feedback\n\nYou can find the [repostiory for this package](https://github.com/moongoal/happy-chappy) on GitHub.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoongoal%2Fhappy-chappy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoongoal%2Fhappy-chappy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoongoal%2Fhappy-chappy/lists"}