unified

Project:vfile/vfile-rename

Package:vfile-rename@1.0.2

  1. Dependencies:1·Dependents:0
  2. vfile utility to rename the path parts of a file
  1. util 105
  2. utility 105
  3. file 24
  4. virtual 21
  5. vfile 17
  6. vfile-util 16
  7. check 9
  8. move 3

vfile-rename

Build Coverage Downloads Size Sponsors Backers Chat

Rename a vfile.

Install

npm:

npm install vfile-rename

Use

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

var file = vfile('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

rename(file, renames)

Renames the given file with renames.

Converts renames to a move, and calls that move with file. If you’re doing a lot of renames, use convert (rename.convert or require('vfile-rename/convert') directly).

Parameters
Returns

The given file.

convert(renames)

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

Parameters
Returns

A move.

move(file)

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

Spec

A spec is 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.

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