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-rename

v3.0.0

Published

vfile utility to rename the path parts of a file

Downloads

1,393

Readme

vfile-rename

Build Coverage Downloads Size Sponsors Backers Chat

vfile utility to rename a file.

Contents

What is this?

This package is a utility to add different data-driven ways to rename files.

When should I use this?

This package is mostly useful when creating higher level tools that include support for renaming files to end users.

Install

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

npm install vfile-rename

In Deno with esm.sh:

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

In browsers with esm.sh:

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

Use

import {VFile} from 'vfile'
import {rename} from 'vfile-rename'

const file = new VFile({path: 'readme.md'})
file.path // => readme.md

// Set extname:
rename(file, '.html')
file.path // => readme.html

// Set basename:
rename(file, 'main.md')
file.path // => main.md

// Set path properties:
rename(file, {stem: 'index'})
file.path // => index.md

// Change path properties:
rename(file, {stem: {suffix: '.bak'}})
file.path // => index.bak.md

// All together:
rename(file, ['readme.md', '.htm', {stem: 'index', extname: {suffix: 'l'}}])
file.path // => index.html

API

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

convert(renames)

Create a function (the move) from renames, that when given a file changes its path properties.

Parameters
  • renames (Renames, optional) — rename instructions
Returns

A move (Move).

rename(file, renames)

Rename a file.

When given something, returns a vfile from that, and changes its path properties.

Parameters
  • file (VFile) — file to rename
  • renames (Renames, optional) — rename instructions
Returns

Nothing (undefined).

Move

Move (TypeScript type).

Parameters
  • file (VFile) — file to change
Returns

Nothing (undefined).

Renames

Rename instructions (TypeScript type).

  • if the bound rename is a normal string starting with a dot (.), sets file.extname
  • otherwise, if the bound rename is a normal string, sets file.basename
  • otherwise, if the bound test is an array, all renames in it are performed
  • otherwise, if the bound rename is an object, renames according to the Spec
Type
type Renames = Array<Move | Spec | string> | Move | Spec | string

Spec

An object describing path properties to values (TypeScript type).

For each property in spec, if its value is string, the value of the path property on the given file is set. If the value is object, it can have a prefix or suffix key, the value of the path property on the given file is prefixed and/or suffixed.

Fields
  • basename (SpecAffix or string, optional) — change basename ('index.min.js').
  • dirname (SpecAffix or string, optional) — change dirname ('~').
  • extname (SpecAffix or string, optional) — change extname ('.js').
  • path (SpecAffix, URL, or string, optional) — change file path ('~/index.min.js').
  • stem (SpecAffix or string, optional) — change stem ('index.min').

SpecAffix

Define prepending and/or appending (TypeScript type).

Fields
  • prefix (string, optional) — substring to prepend before the field
  • suffix (string, optional) — substring to append after the field.

Types

This package is fully typed with TypeScript. It exports the types Move, Renames, Spec, and SpecAffix.

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-rename@^3, compatible with Node.js 16.

Security

Use of vfile-rename is safe.

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