{"id":13339503,"url":"https://github.com/syntax-tree/unist-util-source","last_synced_at":"2025-06-29T22:03:50.195Z","repository":{"id":10883421,"uuid":"67361024","full_name":"syntax-tree/unist-util-source","owner":"syntax-tree","description":"utility to get the source of a node or position","archived":false,"fork":false,"pushed_at":"2023-07-07T10:38:52.000Z","size":330,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-06-01T13:30:17.096Z","etag":null,"topics":["source","syntax-tree","unist","unist-util","util"],"latest_commit_sha":null,"homepage":"https://unifiedjs.com","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/syntax-tree.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-09-04T18:17:02.000Z","updated_at":"2023-03-01T09:48:44.000Z","dependencies_parsed_at":"2024-06-18T21:10:08.796Z","dependency_job_id":null,"html_url":"https://github.com/syntax-tree/unist-util-source","commit_stats":{"total_commits":99,"total_committers":3,"mean_commits":33.0,"dds":"0.030303030303030276","last_synced_commit":"f6f11ab01a22a411955e674071dedd49e86089d7"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/syntax-tree/unist-util-source","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Funist-util-source","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Funist-util-source/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Funist-util-source/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Funist-util-source/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syntax-tree","download_url":"https://codeload.github.com/syntax-tree/unist-util-source/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Funist-util-source/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259395554,"owners_count":22850854,"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":["source","syntax-tree","unist","unist-util","util"],"created_at":"2024-07-29T19:20:04.278Z","updated_at":"2025-06-29T22:03:50.168Z","avatar_url":"https://github.com/syntax-tree.png","language":"JavaScript","readme":"# unist-util-source\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n[![Sponsors][sponsors-badge]][collective]\n[![Backers][backers-badge]][collective]\n[![Chat][chat-badge]][chat]\n\n[unist][] utility to get the source code of a node or position.\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    *   [`source(file[, value])`](#sourcefile-value)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis is a tiny utility that lets you get the source code of a node or position.\n\n## When should I use this?\n\nThis is super tiny utility useful when you want to display the source code\nof something in a file.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install unist-util-source\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {source} from 'https://esm.sh/unist-util-source@5'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import {source} from 'https://esm.sh/unist-util-source@5?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\nSay our document `example.md` contains:\n\n```markdown\n\u003e + **[Hello](./example)**\n\u003e   world.\n```\n\n…and our module `example.js` looks as follows:\n\n```js\nimport {fromMarkdown} from 'mdast-util-from-markdown'\nimport {read} from 'to-vfile'\nimport {source} from 'unist-util-source'\n\nconst file = await read('example.md')\nconst tree = fromMarkdown(String(file))\n\nconst strong = tree.children[0].children[0].children[0].children[0].children[0]\nconsole.log(source(file, strong))\n```\n\n…now running `node example.js` yields:\n\n```markdown\n**[Hello](./example)**\n```\n\n## API\n\nThis package exports the identifier [`source`][source].\nThere is no default export.\n\n### `source(file[, value])`\n\nGet the source of a node or at a position.\n\n###### Parameters\n\n*   `file` ([`VFile`][vfile] or `string`)\n    — file in which `value` exists\n*   `value` ([`Node`][node], [`Position`][position], optional)\n    — value to get\n\n###### Returns\n\nSource of `value` in `doc`, if available (`string` or `undefined`).\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports no additional types.\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, `unist-util-source@^5`,\ncompatible with Node.js 16.\n\n## Contribute\n\nSee [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for\nways to 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, organisation, 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/syntax-tree/unist-util-source/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/unist-util-source/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-source.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/unist-util-source\n\n[downloads-badge]: https://img.shields.io/npm/dm/unist-util-source.svg\n\n[downloads]: https://www.npmjs.com/package/unist-util-source\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size\u0026query=$.size.compressedSize\u0026url=https://deno.bundlejs.com/?q=unist-util-source\n\n[size]: https://bundlejs.com/?q=unist-util-source\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/syntax-tree/unist/discussions\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[esmsh]: https://esm.sh\n\n[typescript]: https://www.typescriptlang.org\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[health]: https://github.com/syntax-tree/.github\n\n[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[support]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[unist]: https://github.com/syntax-tree/unist\n\n[node]: https://github.com/syntax-tree/unist#node\n\n[position]: https://github.com/syntax-tree/unist#position\n\n[vfile]: https://github.com/vfile/vfile\n\n[source]: #sourcefile-value\n","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Funist-util-source","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyntax-tree%2Funist-util-source","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Funist-util-source/lists"}