vfile-is

vfile utility to check if a vfile passes a test

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
vfile-is
102.0.02 years ago4 years agoMinified + gzip package size for vfile-is in KB

Readme

vfile-is
!Buildbuild-badgebuild !Coveragecoverage-badgecoverage !Downloadsdownloads-badgedownloads !Sizesize-badgesize !Sponsorssponsors-badgecollective !Backersbackers-badgecollective !Chatchat-badgechat
Check if a vfilevfile passes a test.

Install

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.
npm install vfile-is
## Use

```js
import {toVFile} from 'to-vfile'
import {is} from 'vfile-is'

is(null, '.js') // => false
is({}, '.js') // => false

is(toVFile('index.js'), '.js') // => true
is(toVFile('index.js'), '.md') // => false
is(toVFile('index.js'), 'index.js') // => true
is(toVFile('index.js'), 'readme.md') // => false
is(toVFile('index.js'), '*.js') // => true
is(toVFile('index.js'), '*.md') // => false

is(toVFile('index.js'), {stem: 'index'}) // => true
is(toVFile('index.js'), {stem: 'readme'}) // => false

is(toVFile('index.js'), {stem: {prefix: 'in'}}) // => true
is(toVFile('index.js'), {stem: {prefix: 're'}}) // => false
is(toVFile('index.js'), {stem: {suffix: 'ex'}}) // => true
is(toVFile('index.js'), {stem: {suffix: 'me'}}) // => false

API

This package exports the following identifiers: is. There is no default export.

is(file, test?)

Check if file passes the given test.
Converts test to an assertion and calls that assertion with file. If you’re doing a lot of checks, use convert.

convert(test)

Create a function (the assertion) from test, that when given something, returns whether that value is a vfile and whether it passes the given test.
Parameters
  • test (string, Function, Spec, or Array.<test>, optional)
Returns
An assertion.

assertion(file)

When given something, returns whether that value is a vfile and whether it passes the bound test.
  • If there is no bound test (it’s nullish), makes sure file is a vfile
  • If the bound test is a glob string, checks if that glob matches file.path
  • If the bound test is a normal string, checks if that is file.basename or
`file.extname`
  • If the bound test is a normal object, checks if the given file matches the
[Spec][]
  • If the bound test is an array, all tests in it must pass

Spec

A spec is an object describing properties to values. For each property in spec, if its value is string, there must be an equivalent property in the given file matching the value. If the value is object, it can have a prefix or suffix key, and the value in the given file must be a string, and it must start with prefix and/or end with suffix.

Contribute

See contributing.mdcontributing in vfile/.githubhealth for ways to get started. See support.mdsupport for ways to get help.
This project has a code of conductcoc. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MITlicense © Titus Wormerauthor