node-rename-path
TypeScript icon, indicating that this package has built-in type declarations

5.0.0 • Public • Published

node-rename-path

Build Status npm version Node.js Version

Node.js path renaming made easy.

Installation

npm add node-rename-path

Example

import rename from 'node-rename-path';

const PATH = 'documents/work/readme.md';
let results = '';

// Do nothing
results = rename(PATH);
console.log(results);
// -> 'documents/work/readme.md'

// Change file name
results = rename(PATH, (pathObj) => {
  return {
    name: 'day1_' + pathObj.name + '_notes',
  };
});
console.log(results);
// -> documents/work/day1_readme_notes.md

// Reset file name
results = rename(PATH, (pathObj) => {
  return {
    name: '___',
  };
});
console.log(results);
// -> documents/work/___.md

// Change extension
results = rename(PATH, (pathObj) => {
  return {
    ext: '.a.b.c.d',
  };
});
console.log(results);
// -> documents/work/readme.a.b.c.d

// Remove extension
results = rename(PATH, (pathObj) => {
  return {
    ext: '',
  };
});
console.log(results);
// -> documents/work/readme

// Set both file name and extension all at once
results = rename(PATH, (pathObj) => {
  return {
    base: 'brand-new.pdf',
  };
});
console.log(results);
// -> documents/work/brand-new.pdf

// Update directory path
results = rename(PATH, (pathObj) => {
  return {
    dir: '/root',
  };
});
console.log(results);
// -> /root/readme.md

Readme

Keywords

none

Package Sidebar

Install

npm i node-rename-path

Weekly Downloads

0

Version

5.0.0

License

MIT

Unpacked Size

4.93 kB

Total Files

6

Last publish

Collaborators

  • mgenware