Project: vfile/vfile-rename

Package: vfile-rename@2.0.1

  1. Dependents: 0
  2. vfile utility to rename the path parts of a file
  1. util 147
  2. utility 143
  3. file 34
  4. virtual 19
  5. vfile 17
  6. vfile-util 15
  7. check 11
  8. move 3


Build Coverage Downloads Size Sponsors Backers Chat

vfile utility to rename a file.


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.


This package is ESM only. In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with npm:

npm install vfile-rename

In Deno with esm.sh:

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

In browsers with esm.sh:

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


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


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

rename(file, renames)

Rename a file. Calls convert and then the resulting move internally.


The given file (VFile).


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


A move.


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


An object describing path properties to values. 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.

Note that only allowed path properties can be set, other properties are thrown for.


This package is fully typed with TypeScript. The extra types SpecAffix, Spec, Move, and Renames are exported.


Projects maintained by the unified collective are compatible with all maintained versions of Node.js. As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+. Our projects sometimes work with older versions, but this is not guaranteed.


Use of vfile-rename is safe by default.


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.


MIT © Titus Wormer