{"id":22484946,"url":"https://github.com/vfile/vfile-is","last_synced_at":"2025-08-02T18:31:01.089Z","repository":{"id":33476247,"uuid":"158740696","full_name":"vfile/vfile-is","owner":"vfile","description":"utility to check if a vfile passes a test","archived":false,"fork":false,"pushed_at":"2023-06-14T10:27:51.000Z","size":83,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-07-11T21:30:06.245Z","etag":null,"topics":["file","is","vfile","vfile-util","virtual"],"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/vfile.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},"funding":{"github":"unifiedjs","open_collective":"unified"}},"created_at":"2018-11-22T19:03:36.000Z","updated_at":"2024-05-05T10:43:24.000Z","dependencies_parsed_at":"2023-02-19T09:16:06.633Z","dependency_job_id":null,"html_url":"https://github.com/vfile/vfile-is","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/vfile/vfile-is","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vfile%2Fvfile-is","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vfile%2Fvfile-is/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vfile%2Fvfile-is/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vfile%2Fvfile-is/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vfile","download_url":"https://codeload.github.com/vfile/vfile-is/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vfile%2Fvfile-is/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268432660,"owners_count":24249589,"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-02T02:00:12.353Z","response_time":74,"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":["file","is","vfile","vfile-util","virtual"],"created_at":"2024-12-06T17:11:47.992Z","updated_at":"2025-08-02T18:31:00.628Z","avatar_url":"https://github.com/vfile.png","language":"JavaScript","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified"],"categories":["JavaScript"],"sub_categories":[],"readme":"# vfile-is\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[`vfile`][vfile] utility to check if a file passes a test.\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    *   [`convert(check)`](#convertcheck)\n    *   [`is(file, check?)`](#isfile-check)\n    *   [`Assert`](#assert)\n    *   [`Check`](#check)\n    *   [`CheckFields`](#checkfields)\n    *   [`CheckFile`](#checkfile)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis package is a small utility that checks that a file is a certain file.\n\n## When should I use this?\n\nUse this small utility if you find yourself repeating code for checking files.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install vfile-is\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {is} from 'https://esm.sh/vfile-is@3'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import {is} from 'https://esm.sh/vfile-is@3?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\n```js\nimport {VFile} from 'to-vfile'\nimport {is} from 'vfile-is'\n\nis(undefined, '.js') // =\u003e false\nis({}, '.js') // =\u003e false\n\nis(new VFile({path: 'index.js'}), '.js') // =\u003e true\nis(new VFile({path: 'index.js'}), '.md') // =\u003e false\nis(new VFile({path: 'index.js'}), 'index.js') // =\u003e true\nis(new VFile({path: 'index.js'}), 'readme.md') // =\u003e false\nis(new VFile({path: 'index.js'}), '*.js') // =\u003e true\nis(new VFile({path: 'index.js'}), '*.md') // =\u003e false\n\nis(new VFile({path: 'index.js'}), {stem: 'index'}) // =\u003e true\nis(new VFile({path: 'index.js'}), {stem: 'readme'}) // =\u003e false\n\nis(new VFile({path: 'index.js'}), {stem: {prefix: 'in'}}) // =\u003e true\nis(new VFile({path: 'index.js'}), {stem: {prefix: 're'}}) // =\u003e false\nis(new VFile({path: 'index.js'}), {stem: {suffix: 'ex'}}) // =\u003e true\nis(new VFile({path: 'index.js'}), {stem: {suffix: 'me'}}) // =\u003e false\n```\n\n## API\n\nThis package exports the identifiers [`convert`][api-convert] and\n[`is`][api-is].\nThere is no default export.\n\n### `convert(check)`\n\nCreate an assertion from `check`.\n\n###### Parameters\n\n*   `check` ([`Check`][api-check], optional)\n    — check\n\n###### Returns\n\nAssertion ([`Assert`][api-assert]).\n\n### `is(file, check?)`\n\nCheck if `file` is a specific file.\n\nConverts `check` to an assertion and calls that assertion with `file`.\nIf you’re doing a lot of checks, use `convert`.\n\n###### Parameters\n\n*   `file` (`unknown`)\n    — file to check (typically [`VFile`][vfile])\n*   `check` ([`Check`][api-check], optional)\n    — check\n\n###### Returns\n\nWhether `file` is a file and matches `check` (`boolean`).\n\n### `Assert`\n\nCheck that a file is a `vfile` and passes a test (TypeScript type).\n\n###### Parameters\n\n*   `file` (`unknown`)\n    — file to check (typically [`VFile`][vfile])\n\n###### Returns\n\nWhether `file` is a file and matches a bound `check` (`boolean`).\n\n### `Check`\n\nDifferent ways to check for a specific file (TypeScript type).\n\n*   if check is a glob string, checks if that glob matches `file.path`\n*   if check is a normal string, checks if that is `file.basename` or\n    `file.extname`\n*   if check is a function, checks whether that yields `true` when called\n*   if check is a normal object, checks if the given file matches the\n    [`CheckFields`][api-check-fields]\n*   if check is an array, all tests in it must pass\n\n###### Type\n\n```ts\ntype Check =\n  | Array\u003cCheckFields | CheckFile | string | null | undefined\u003e\n  | CheckFields\n  | CheckFile\n  | string\n  | null\n  | undefined\n```\n\n### `CheckFields`\n\nObject describing fields to values (TypeScript type).\n\nEach key is a field in the file and each value is:\n\n*   `boolean` — whether the field exists or not\n*   `object` — start (prefix) and/or end (suffix) of the field\n*   `string` — exact value of that field\n\n###### Type\n\n```ts\ntype FieldPartial = {\n  prefix?: string | null | undefined\n  suffix?: string | null | undefined\n}\n\ntype CheckFields = Record\u003c\n  string,\n  FieldPartial | boolean | string | null | undefined\n\u003e\n```\n\n### `CheckFile`\n\nCheck if a file passes a custom test (TypeScript type).\n\n###### Parameters\n\n*   `file` ([`VFile`][vfile])\n    — file to check\n\n###### Returns\n\nWhether the test passed for this file (`boolean`, optional).\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional types [`Assert`][api-assert], [`Check`][api-check],\n[`CheckFields`][api-check-fields], and [`CheckFile`][api-check-file].\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, `vfile-is@^3`, compatible\nwith Node.js 16.\n\n## Contribute\n\nSee [`contributing.md`][contributing] in [`vfile/.github`][health] for ways to\nget 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/vfile/vfile-is/workflows/main/badge.svg\n\n[build]: https://github.com/vfile/vfile-is/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/vfile/vfile-is.svg\n\n[coverage]: https://codecov.io/github/vfile/vfile-is\n\n[downloads-badge]: https://img.shields.io/npm/dm/vfile-is.svg\n\n[downloads]: https://www.npmjs.com/package/vfile-is\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size\u0026query=$.size.compressedSize\u0026url=https://deno.bundlejs.com/?q=vfile-is\n\n[size]: https://bundlejs.com/?q=vfile-is\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/vfile/vfile/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[contributing]: https://github.com/vfile/.github/blob/main/contributing.md\n\n[support]: https://github.com/vfile/.github/blob/main/support.md\n\n[health]: https://github.com/vfile/.github\n\n[coc]: https://github.com/vfile/.github/blob/main/code-of-conduct.md\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[vfile]: https://github.com/vfile/vfile\n\n[api-convert]: #convertcheck\n\n[api-is]: #isfile-check\n\n[api-assert]: #assert\n\n[api-check]: #check\n\n[api-check-fields]: #checkfields\n\n[api-check-file]: #checkfile\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvfile%2Fvfile-is","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvfile%2Fvfile-is","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvfile%2Fvfile-is/lists"}