{"id":13339453,"url":"https://github.com/ChristianMurphy/mdast-util-arbitrary","last_synced_at":"2025-03-11T14:31:19.643Z","repository":{"id":49144698,"uuid":"377324370","full_name":"ChristianMurphy/mdast-util-arbitrary","owner":"ChristianMurphy","description":"Generate arbitrary mdast with fast check","archived":false,"fork":false,"pushed_at":"2021-06-26T18:03:33.000Z","size":132,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-01T11:36:49.414Z","etag":null,"topics":["markdown","mdast","mdast-util","property-based-testing","quickcheck","testing","unist"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/ChristianMurphy.png","metadata":{"files":{"readme":"README.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}},"created_at":"2021-06-16T00:12:27.000Z","updated_at":"2021-06-26T18:03:35.000Z","dependencies_parsed_at":"2022-08-25T15:20:22.090Z","dependency_job_id":null,"html_url":"https://github.com/ChristianMurphy/mdast-util-arbitrary","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChristianMurphy%2Fmdast-util-arbitrary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChristianMurphy%2Fmdast-util-arbitrary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChristianMurphy%2Fmdast-util-arbitrary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChristianMurphy%2Fmdast-util-arbitrary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ChristianMurphy","download_url":"https://codeload.github.com/ChristianMurphy/mdast-util-arbitrary/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243051839,"owners_count":20228278,"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":["markdown","mdast","mdast-util","property-based-testing","quickcheck","testing","unist"],"created_at":"2024-07-29T19:20:03.490Z","updated_at":"2025-03-11T14:31:19.221Z","avatar_url":"https://github.com/ChristianMurphy.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mdast-util-arbitrary\n\n[![NPM Version](https://img.shields.io/npm/v/mdast-util-arbitrary)](https://www.npmjs.com/package/mdast-util-arbitrary)\n[![CI](https://github.com/ChristianMurphy/mdast-util-arbitrary/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/ChristianMurphy/mdast-util-arbitrary/actions/workflows/main.yml)\n\nGenerate arbitrary, random, and valid [`mdast`](https://github.com/syntax-tree/mdast) with [`fast-check`](https://github.com/dubzzz/fast-check), useful for [property testing](https://medium.com/criteo-engineering/introduction-to-property-based-testing-f5236229d237) [`mdast` utils](https://github.com/syntax-tree/mdast#list-of-utilities) and [`remark` plugins](https://github.com/remarkjs/remark/blob/main/doc/plugins.md#plugins).\n\n## Install\n\n```bash\nnpm install --save-dev mdast-util-arbitrary\n```\n\n## Usage\n\n```ts\nimport { assert, property } from \"fast-check\";\nimport { commonmark } from \"mdast-util-arbitrary\";\n\nassert(\n  property(commonmark().Root, (mdast) =\u003e {\n    // do something with mdast\n  })\n);\n```\n\n## API\n\nThis package exports a commonmark function which returns a dictionary of node types which can be generated (usually `Root` should be used starting node type)\n\n`commonmark(options?: Options) =\u003e {[nodeType: string]: Arbitrary}`\n\n### Options\n\n#### `Options.includeData`\n\nWhether to generate arbitrary [`data`](https://github.com/syntax-tree/unist#node) attributes for nodes. Default `false`.\n\n#### `Options.rootNodeMaxChildren`\n\nLimit the maximum number of child nodes the `Root` node can have. Default `100`.\n\n## Example\n\nUsing [`uvu`](https://github.com/lukeed/uvu) to test [`mdast-util-to-markdown`](https://github.com/syntax-tree/mdast-util-to-markdown).\n\nChecking three properties of `mdast-util-to-markdown`:\n\n1. it does not throw an exception on valid markdown\n2. it produces a string\n3. it produces non-empty markdown text\n\nGenerating 100 mdast random mdast trees to see if the properties hold true.\n\n```ts\nimport { test } from \"uvu\";\nimport toString from \"mdast-util-to-markdown\";\nimport { assert, property } from \"fast-check\";\nimport { commonmark } from \"mdast-util-arbitrary\";\n\ntest(\"arbitrary mdast can be stringified\", () =\u003e {\n  assert(\n    property(commonmark().Root, (mdast) =\u003e {\n      const markdown = toString(mdast);\n      return typeof markdown === \"string\" \u0026\u0026 markdown.length \u003e 1;\n    }),\n    { numRuns: 100 }\n  );\n});\n\ntest.run();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FChristianMurphy%2Fmdast-util-arbitrary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FChristianMurphy%2Fmdast-util-arbitrary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FChristianMurphy%2Fmdast-util-arbitrary/lists"}