1.0.4 • Published 8 years ago

rename v1.0.4

Weekly downloads
13,625
License
MIT
Repository
github
Last release
8 years ago

rename

Rename files using some transformers.


NPM version Build Status Build Status NPM downloads

NOTE: Rename < 0.2.0 is not the same lib, you can see renamer. 1.0.0 have a big change.

Install

$ npm install rename -g

Usage

Rename file using another filepath.

rename('a.js', 'b.js');
// => b.js

Rename file using a transform object that contain some property.

{
  dirname: "replace dirname",
  prefix: "add prefix before basename",
  basename: "replace dirname",
  suffix: "add prefix after basename",
  extname: "replace extname"
}

Add -debug suffix

rename('a.js', {suffix: '-debug'});
// => a-debug.js

Also can use a transform function that could return a transform object.

rename('a.js', function() {
  return {suffix: '-debug'};
});
// => a-debug.js

API

rename(filepath, transformer)

filepath

Filepath can be a string or object. Parse the filepath to file object if it's a string.

File object should contain property dirname, basename and extname.

rename({
  basename: 'a',
  extname: '.js'
}, 'b.js');
// => b.js

transformer

Transformer can be a function, string or object.

Simple example about transform function using custom property.

function transformer(fileObj) {
  return {
    suffix: fileObj.hash || '-debug'
  };
}

rename({
  basename: 'a',
  extname: '.js'
}, transformer);
// => a-debug.js

rename({
  basename: 'a',
  extname: '.js',
  hash: '-123'
}, transformer);
// => a-123.js

The value of transform object can be template that parsed from file object.

rename({
  basename: 'c',
  extname: '.js',
  hash: '111'
}, {
  suffix: '-${hash}',
}).should.eql('c-111.js');

rename.parse

Generate a file object from a string or object.

rename.stringify

Generate a filepath from file object.

LISENCE

Copyright (c) 2017 popomore. Licensed under the MIT license.

1.0.4

8 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.2.3

11 years ago

0.2.2

11 years ago

0.2.1

11 years ago

0.2.0

11 years ago

0.1.0

12 years ago

0.0.9

12 years ago

0.0.8

12 years ago

0.0.7

12 years ago

0.0.6

12 years ago

0.0.5

12 years ago

0.0.4

12 years ago