{"id":13683398,"url":"https://github.com/typeetfunc/runtypes-generate","last_synced_at":"2025-04-30T13:30:35.884Z","repository":{"id":73279331,"uuid":"81419044","full_name":"typeetfunc/runtypes-generate","owner":"typeetfunc","description":"Transform runtypes type to jsverify arbitrary for generate sample of data","archived":false,"fork":false,"pushed_at":"2017-08-25T18:18:30.000Z","size":17,"stargazers_count":41,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-19T06:41:04.517Z","etag":null,"topics":["property-based-testing","runtime-typechecking","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/typeetfunc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-02-09T06:48:07.000Z","updated_at":"2023-04-18T05:22:13.000Z","dependencies_parsed_at":"2023-06-10T01:03:43.562Z","dependency_job_id":null,"html_url":"https://github.com/typeetfunc/runtypes-generate","commit_stats":{"total_commits":22,"total_committers":1,"mean_commits":22.0,"dds":0.0,"last_synced_commit":"a413f695d2e9e9aa4c824d20d15cb07bab868de1"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typeetfunc%2Fruntypes-generate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typeetfunc%2Fruntypes-generate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typeetfunc%2Fruntypes-generate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typeetfunc%2Fruntypes-generate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/typeetfunc","download_url":"https://codeload.github.com/typeetfunc/runtypes-generate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251712831,"owners_count":21631447,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["property-based-testing","runtime-typechecking","typescript"],"created_at":"2024-08-02T13:02:09.922Z","updated_at":"2025-04-30T13:30:35.594Z","avatar_url":"https://github.com/typeetfunc.png","language":"TypeScript","readme":"# Runtypes-generate\n\n[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)\n[![npm version](https://badge.fury.io/js/runtypes-generate.svg)](https://badge.fury.io/js/runtypes-generate)\n\n`Runtypes-generate` convert [`runtypes` type](https://github.com/pelotom/runtypes) to [jsverify arbitrary](https://github.com/jsverify/jsverify).\n\n## Table of Contents\n\n- [Background](#background)\n- [Install](#install)\n- [Usage](#usage)\n- [API](#api)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Background\n\nProperty-based testing is very awesome approach for analyze and verification program. But this approach requires the writing of generators for all datatypes in our program. This process is very time-consuming, error-prone and not DRY.\n\nExample:\n\n```js\nimport { Number, Literal, Array, Tuple, Record } from 'runtypes'\nconst AsteroidType = Record({\n    type: Literal('asteroid'),\n    location: Tuple(Number, Number, Number),\n    mass: Number,\n})\n\nconst AsteroidArbitrary = jsc.record({\n    type: jsc.constant('asteroid'),\n    location: jsc.tuple(jsc.number, jsc.number, jsc.number),\n    mass: jsc.number\n})\n```\n\nBut with `runtypes-generate` we can get `AsteroidArbitrary` from `AsteroidType`:\n\n```js\nimport { makeJsverifyArbitrary } from 'runtypes-generate'\nconst AsteroidType = Record({\n    type: Literal('asteroid'),\n    location: Tuple(Number, Number, Number),\n    mass: Number,\n})\nconst AsteroidArbitrary = makeJsverifyArbitrary(AsteroidType)\n```\n\n## Install\n\n```\nnpm install --save runtypes-generate\n```\n\n## Usage\n\n- [Core runtypes](https://github.com/typeetfunc/runtypes-generate/blob/master/src/index.spec.ts)\n- [Custom runtypes](https://github.com/typeetfunc/runtypes-generate/blob/master/src/custom.spec.ts)\n\n## API\n\n- `makeJsverifyArbitrary(type: Reflect): jsc.Arbitrary\u003cany\u003e` - convert `runtypes` to `jsverify` arbitrary\n- `addTypeToRegistry(tag: string, (x:Reflect) =\u003e jsc.Arbitrary\u003cany\u003e): void` - add new generator for [`Constraint` type](https://github.com/pelotom/runtypes#constraint-checking) with [`tag` in `args` attribute](https://github.com/typeetfunc/runtypes-generate/blob/master/src/custom.spec.ts#L23-L32)\n- `addTypeToIntersectRegistry(tags: string[], generator: (x: Reflect) =\u003e jsc.Arbitrary\u003cany\u003e): void)`  - add new generator for `Intersect` or custom `Constraint` types. TODO example\n- `generateAndCheck(rt: Reflect, opts?: jsc.Options): () =\u003e void` - run `jsc.assert` for property `rt.check(generatedData)` for all `generatedData` obtained from `makeJsverifyArbitrary(rt)`. Uses for verification custom generators for custom `Constraint` type. See [example](https://github.com/typeetfunc/runtypes-generate/blob/master/src/custom.spec.ts#L112-L118) in tests. \n\n## Contribute\n\nPRs accepted.\n\nIf you had questions just make issue or ask them in [my telegram](https://telegram.me/bracketsarrows)\n\nSmall note: If editing the Readme, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.\n\n\n## License\n\nMIT © typeetfunc","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypeetfunc%2Fruntypes-generate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftypeetfunc%2Fruntypes-generate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypeetfunc%2Fruntypes-generate/lists"}