npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vfile-is

v3.0.0

Published

vfile utility to check if a vfile passes a test

Downloads

647

Readme

vfile-is

Build Coverage Downloads Size Sponsors Backers Chat

vfile utility to check if a file passes a test.

Contents

What is this?

This package is a small utility that checks that a file is a certain file.

When should I use this?

Use this small utility if you find yourself repeating code for checking files.

Install

This package is ESM only. In Node.js (version 16+), install with npm:

npm install vfile-is

In Deno with esm.sh:

import {is} from 'https://esm.sh/vfile-is@3'

In browsers with esm.sh:

<script type="module">
  import {is} from 'https://esm.sh/vfile-is@3?bundle'
</script>

Use

import {VFile} from 'to-vfile'
import {is} from 'vfile-is'

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

is(new VFile({path: 'index.js'}), '.js') // => true
is(new VFile({path: 'index.js'}), '.md') // => false
is(new VFile({path: 'index.js'}), 'index.js') // => true
is(new VFile({path: 'index.js'}), 'readme.md') // => false
is(new VFile({path: 'index.js'}), '*.js') // => true
is(new VFile({path: 'index.js'}), '*.md') // => false

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

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

API

This package exports the identifiers convert and is. There is no default export.

convert(check)

Create an assertion from check.

Parameters
  • check (Check, optional) — check
Returns

Assertion (Assert).

is(file, check?)

Check if file is a specific file.

Converts check to an assertion and calls that assertion with file. If you’re doing a lot of checks, use convert.

Parameters
  • file (unknown) — file to check (typically VFile)
  • check (Check, optional) — check
Returns

Whether file is a file and matches check (boolean).

Assert

Check that a file is a vfile and passes a test (TypeScript type).

Parameters
  • file (unknown) — file to check (typically VFile)
Returns

Whether file is a file and matches a bound check (boolean).

Check

Different ways to check for a specific file (TypeScript type).

  • if check is a glob string, checks if that glob matches file.path
  • if check is a normal string, checks if that is file.basename or file.extname
  • if check is a function, checks whether that yields true when called
  • if check is a normal object, checks if the given file matches the CheckFields
  • if check is an array, all tests in it must pass
Type
type Check =
  | Array<CheckFields | CheckFile | string | null | undefined>
  | CheckFields
  | CheckFile
  | string
  | null
  | undefined

CheckFields

Object describing fields to values (TypeScript type).

Each key is a field in the file and each value is:

  • boolean — whether the field exists or not
  • object — start (prefix) and/or end (suffix) of the field
  • string — exact value of that field
Type
type FieldPartial = {
  prefix?: string | null | undefined
  suffix?: string | null | undefined
}

type CheckFields = Record<
  string,
  FieldPartial | boolean | string | null | undefined
>

CheckFile

Check if a file passes a custom test (TypeScript type).

Parameters
  • file (VFile) — file to check
Returns

Whether the test passed for this file (boolean, optional).

Types

This package is fully typed with TypeScript. It exports the additional types Assert, Check, CheckFields, and CheckFile.

Compatibility

Projects maintained by the unified collective are compatible with maintained versions of Node.js.

When we cut a new major release, we drop support for unmaintained versions of Node. This means we try to keep the current release line, vfile-is@^3, compatible with Node.js 16.

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