{"id":13656580,"url":"https://github.com/remarkjs/remark-usage","last_synced_at":"2025-08-12T14:39:19.796Z","repository":{"id":26531134,"uuid":"29984285","full_name":"remarkjs/remark-usage","owner":"remarkjs","description":"plugin to add a usage example to your readme","archived":false,"fork":false,"pushed_at":"2023-11-02T16:23:10.000Z","size":256,"stargazers_count":43,"open_issues_count":0,"forks_count":17,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-07-12T22:36:04.515Z","etag":null,"topics":["markdown","remark","remark-plugin","usage"],"latest_commit_sha":null,"homepage":"https://remark.js.org","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/remarkjs.png","metadata":{"funding":{"github":"unifiedjs","open_collective":"unified"},"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,"governance":null}},"created_at":"2015-01-28T19:29:11.000Z","updated_at":"2024-09-30T21:09:34.000Z","dependencies_parsed_at":"2022-08-29T19:10:51.278Z","dependency_job_id":"aa490fa9-615f-4972-9e2c-283353237296","html_url":"https://github.com/remarkjs/remark-usage","commit_stats":{"total_commits":166,"total_committers":4,"mean_commits":41.5,"dds":0.01807228915662651,"last_synced_commit":"6c27e6319add9b2351af854ee464cdec799caa0e"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"purl":"pkg:github/remarkjs/remark-usage","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remarkjs%2Fremark-usage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remarkjs%2Fremark-usage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remarkjs%2Fremark-usage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remarkjs%2Fremark-usage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/remarkjs","download_url":"https://codeload.github.com/remarkjs/remark-usage/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remarkjs%2Fremark-usage/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270077913,"owners_count":24523287,"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","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["markdown","remark","remark-plugin","usage"],"created_at":"2024-08-02T05:00:24.020Z","updated_at":"2025-08-12T14:39:19.752Z","avatar_url":"https://github.com/remarkjs.png","language":"JavaScript","readme":"# remark-usage\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Sponsors][sponsors-badge]][collective]\n[![Backers][backers-badge]][collective]\n[![Chat][chat-badge]][chat]\n\n**[remark][]** plugin to add a [usage][section-use] example to a readme.\n\n## Contents\n\n*   [What is this?](#what-is-this)\n*   [When should I use this?](#when-should-i-use-this)\n*   [Install](#install)\n*   [Use](#use)\n*   [API](#api)\n    *   [`unified().use(remarkUsage[, options])`](#unifieduseremarkusage-options)\n    *   [`Options`](#options)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Security](#security)\n*   [Related](#related)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis package is a [unified][] ([remark][]) plugin to add a usage section to\nmarkdown.\n\n## When should I use this?\n\nYou can use this on readmes of npm packages to keep the docs in sync with the\nproject through an actual code sample.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install remark-usage\n```\n\n## Use\n\n\u003e This section is rendered by this module from [`example.js`](example.js).\n\u003e Turtles all the way down.  🐢🐢🐢\n\nSay we are making a module that exports just enough Pi (3.14159).\nWe’re documenting it with a readme file, [`example/readme.md`](./example/readme.md):\n\n```markdown\n# PI\n\nMore than enough 🍰\n\n## Usage\n\n## License\n\nMIT\n```\n\n…and an example script to document it [`example/example.js`](./example/example.js):\n\n```js\n// Load dependencies:\nimport {pi} from './index.js'\n\n// Logging `pi` yields:\nconsole.log('txt', pi)\n```\n\n…if we use `remark-usage`, we can generate the `Usage` section\n\n```javascript\nimport {remark} from 'remark'\nimport remarkUsage from 'remark-usage'\nimport {read} from 'to-vfile'\n\nconst file = await read({path: 'readme.md', cwd: 'example'})\n\nawait remark().use(remarkUsage).process(file)\n```\n\n…then printing `file` (the newly generated readme) yields:\n\n````markdown\n# PI\n\nMore than enough 🍰\n\n## Usage\n\nLoad dependencies:\n\n```javascript\nimport {pi} from 'pi'\n```\n\nLogging `pi` yields:\n\n```txt\n3.14159\n```\n\n## License\n\nMIT\n````\n\n## API\n\nThis package exports no identifiers.\nThe default export is [`remarkUsage`][api-remark-usage].\n\n### `unified().use(remarkUsage[, options])`\n\nAdd a usage example to a readme.\n\nLooks for the first heading matching `options.heading` (case insensitive),\nremoves everything between it and an equal or higher next heading, and replaces\nthat with an example.\n\nThe example runs in Node.js (so no side effects!).\nLine comments (`//`) are turned into markdown.\nCalls to `console.log()` are exposed as code blocks, containing the logged\nvalues, so `console.log(1 + 1)` becomes `2`.\nUse a string as the first argument to `log` to use as the language for the code.\n\nYou can ignore lines with `remark-usage-ignore-next`:\n\n```js\n// remark-usage-ignore-next\nconst two = sum(1, 1)\n\n// remark-usage-ignore-next 3\nfunction sum(a, b) {\n  return a + b\n}\n```\n\n…if no `skip` is given, 1 line is skipped.\n\n###### Parameters\n\n*   `options` ([`Options`][api-options], optional)\n    — configuration\n\n###### Returns\n\nTransform ([`Transformer`][unified-transformer]).\n\n### `Options`\n\nConfiguration (TypeScript type).\n\n###### Fields\n\n*   `example` (`string`, optional)\n    — path to example file (optional);\n    resolved from `file.cwd`;\n    defaults to the first example that exists: `'example.js'`,\n    `'example/index.js'`, `'examples.js'`, `'examples/index.js'`,\n    `'doc/example.js'`, `'doc/example/index.js'`, `'docs/example.js'`,\n    `'docs/example/index.js'`\n*   `heading` (`string`, default: `'usage'`)\n    — heading to look for;\n    wrapped in `new RegExp('^(' + value + ')$', 'i');`\n*   `main` (`string`, default: `pkg.exports`, `pkg.main`, `'index.js'`)\n    — path to the file;\n    resolved from `file.cwd`;\n    used to rewrite `import x from './main.js'` to `import x from 'name'`\n*   `name` (`string`, default: `pkg.name`)\n    — name of the module;\n    used to rewrite `import x from './main.js'` to `import x from 'name'`\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional type [`Options`][api-options].\n\n## Compatibility\n\nProjects maintained by the unified collective are compatible with maintained\nversions of Node.js.\n\nWhen we cut a new major release, we drop support for unmaintained versions of\nNode.\nThis means we try to keep the current release line, `remark-usage@^11`,\ncompatible with Node.js 16.\n\nThis plugin works with remark version 12+ and `remark-cli` version 8+.\n\n## Security\n\nUse of `remark-usage` is unsafe because `main` and `example` are executed.\nThis could become dangerous if an attacker was able to inject code into those\nfiles or their dependencies.\n\n## Related\n\n*   [`remark-toc`](https://github.com/remarkjs/remark-toc)\n    — add a table of contents (TOC)\n*   [`remark-license`](https://github.com/remarkjs/remark-license)\n    — add a license section\n*   [`remark-contributors`](https://github.com/remarkjs/remark-contributors)\n    — add a contributors section\n\n## Contribute\n\nSee [`contributing.md`][contributing] in [`remarkjs/.github`][health] for ways\nto get started.\nSee [`support.md`][support] for ways to get help.\n\nThis project has a [code of conduct][coc].\nBy interacting with this repository, organization, or community you agree to\nabide by its terms.\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n\u003c!-- Definitions --\u003e\n\n[build-badge]: https://github.com/remarkjs/remark-usage/workflows/main/badge.svg\n\n[build]: https://github.com/remarkjs/remark-usage/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-usage.svg\n\n[coverage]: https://codecov.io/github/remarkjs/remark-usage\n\n[downloads-badge]: https://img.shields.io/npm/dm/remark-usage.svg\n\n[downloads]: https://www.npmjs.com/package/remark-usage\n\n[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg\n\n[backers-badge]: https://opencollective.com/unified/backers/badge.svg\n\n[collective]: https://opencollective.com/unified\n\n[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg\n\n[chat]: https://github.com/remarkjs/remark/discussions\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[health]: https://github.com/remarkjs/.github\n\n[contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md\n\n[support]: https://github.com/remarkjs/.github/blob/main/support.md\n\n[coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[remark]: https://github.com/remarkjs/remark\n\n[typescript]: https://www.typescriptlang.org\n\n[unified]: https://github.com/unifiedjs/unified\n\n[unified-transformer]: https://github.com/unifiedjs/unified#transformer\n\n[section-use]: #use\n\n[api-options]: #options\n\n[api-remark-usage]: #unifieduseremarkusage-options\n","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified"],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremarkjs%2Fremark-usage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fremarkjs%2Fremark-usage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremarkjs%2Fremark-usage/lists"}