5.0.0 • Published 3 years ago

node-rename-path v5.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

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
5.0.0

3 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.0

7 years ago