{"id":18582118,"url":"https://github.com/lorefnon/snippet-collector","last_synced_at":"2025-07-23T02:31:54.141Z","repository":{"id":42206876,"uuid":"167788038","full_name":"lorefnon/snippet-collector","owner":"lorefnon","description":"Collect snippets from your source files and tests and reuse them in docs","archived":false,"fork":false,"pushed_at":"2023-10-18T21:21:46.000Z","size":232,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-15T13:19:59.178Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lorefnon.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-01-27T08:47:24.000Z","updated_at":"2022-12-03T13:31:22.000Z","dependencies_parsed_at":"2025-05-16T04:20:33.721Z","dependency_job_id":null,"html_url":"https://github.com/lorefnon/snippet-collector","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lorefnon/snippet-collector","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorefnon%2Fsnippet-collector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorefnon%2Fsnippet-collector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorefnon%2Fsnippet-collector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorefnon%2Fsnippet-collector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lorefnon","download_url":"https://codeload.github.com/lorefnon/snippet-collector/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorefnon%2Fsnippet-collector/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266606029,"owners_count":23955205,"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-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"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":[],"created_at":"2024-11-07T00:09:17.677Z","updated_at":"2025-07-23T02:31:54.090Z","avatar_url":"https://github.com/lorefnon.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# About\n\nsnippet-collector is a simple utility that lets you extract out example snippets from your source and test files, so that they can be reused in your docs.\nThat way, your docs never go out of sync with the source and you can ensure that your examples are covered by your test suite.\n\n# Installation\n\nEnsure node and npm are [installed](https://nodejs.org/en/download/). Only latest stable version is supported at this point.\n\n## As local dependency\n\n```bash\nnpm install --save-dev snippet-collector\n/```\n\nAdd a script entry in package.json:\n\n```json\n{\n    \"scripts\": {\n        \"snippets:collect\": \"snippet-collector --files ./src/**/*.js --output ./generated/snippets.json\"\n    }\n}\n```\n\n## As global dependency (Not recommended)\n\n```bash\nnpm install -g snippet-collector\n```\n\nA sudo may be required, depending on how node installation is configured.\n\n# Usage\n\n## Annotating the source/test files with snippet directives\n\nSnippets can be marked by `@snippet:start` and `@snippet:end` directives.\n\n```js\n// @snippet:start usage\nconst foo = Foo();\nfoo.bar();\n// @snippet:end\n```\n\nIt is possible to have composite snippets spread across multiple-files - They will be concatenated in the specified order (which is mandatory if there are multiple snippets of the same name).\n\n```js\n// @snippet:start usage:0\nimport Foo from \"foo-lib\"\n// @snippet:end\n\n// @snippet:start usage:1\nconst foo = Foo();\nfoo.bar();\n// @snippet:end\n```\n\nThe order indices must start from 0 and must be contiguous. Otherwise, an error will be thrown.\n\n## As CLI:\n\n```bash\nsnippet-collector --files ./src/**/*.js --output ./generated/snippets.json\n```\n\nYour documentation generator can use the extracted json. The structure of json looks like this:\n\n```json\n{\n    \"usage\": {\n        \"name\": \"usage\",\n        \"content\": \"import Foo from \\\"foo-lib\\\";\\rconst foo = Foo();\\rfoo.bar();\\r\"\n    }\n}\n```\nEntries are keyed by snippet name and have a content property containing the combined snippet text.\n\n## As Node library\n\nIt is also possible to use snippet-collector as a node library:\n\n```js\nconst {processSnippets} = require('snippet-collector');\n\nprocessSnippets({\n    globPatterns: './src/**/*.js',\n    outputFile: './generated/snippets.json'\n});\n```\n\nOr alternatively, you can skip the generation and just get the extracted collection of snippets:\n\n```js\nconst {collectSnippets} = require('snippet-collector');\n\ncollectSnippets({\n    globPatterns: './src/**/*.js'\n}).then((snippets) =\u003e {\n    console.log('snippets =\u003e', snippets);\n});\n```\n\nThis returns a promise that resolves to a javascript object of same structure as above.\n\n# Contributing\n\nSuggestions, bug reports as well as PRs are welcome. However, it is advisable that any suggestion that significantly alters the scope of the project be discussed first.\n\n# License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Florefnon%2Fsnippet-collector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Florefnon%2Fsnippet-collector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Florefnon%2Fsnippet-collector/lists"}