Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including vfile-is with all npm packages installed. Try it out:

var vfileIs = require("vfile-is")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

vfile-is v1.0.2

vfile utility to check if a vfile passes a test

vfile-is

Build Coverage Downloads Size Sponsors Backers Chat

Check if a vfile passes a test.

Install

npm:

npm install vfile-is

Use

var vfile = require('to-vfile')
var is = require('vfile-is')

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

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

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

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

API

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 (is.convert or require('vfile-is/convert') directly).

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 null or undefined), 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.md in vfile/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free