Comparing version 0.4.2 to 0.4.3
"use strict"; | ||
var mfs = require("more-fs"), | ||
w = require("wodge"), | ||
dope = require("console-dope"), | ||
path = require("path"), | ||
util = require("util"), | ||
fs = require("fs"), | ||
Result = require("./Result"), | ||
Results = require("./Results"), | ||
RenamerOptions = require("./RenamerOptions"); | ||
RenamerOptions = require("./RenamerOptions"), | ||
Renamer = require("./RenamerApp"); | ||
exports.Result = Result; | ||
exports.Results = Results; | ||
exports.Renamer = Renamer; | ||
exports.RenamerOptions = RenamerOptions; | ||
@@ -31,25 +31,27 @@ exports.replace = replace; | ||
results = new Results(); | ||
results.list = options.files.map(function(file){ | ||
var result = new Result({ before: path.normalize(file) }), | ||
dirname = path.dirname(file), | ||
basename = path.basename(file); | ||
results.list = options.files.map(replaceSingle.bind(null, findRegex, options.replace)); | ||
return results; | ||
} | ||
if(options.find){ | ||
if (basename.search(findRegex) > -1){ | ||
basename = basename.replace(findRegex, options.replace); | ||
result.after = path.join(dirname, basename); | ||
} else { | ||
/* leave result.after blank, signifying no replace was performed */ | ||
} | ||
function replaceSingle(findRegex, replace, file){ | ||
var result = new Result({ before: path.normalize(file) }), | ||
dirname = path.dirname(file), | ||
basename = path.basename(file); | ||
if(findRegex){ | ||
if (basename.search(findRegex) > -1){ | ||
basename = basename.replace(findRegex, replace); | ||
result.after = path.join(dirname, basename); | ||
} else { | ||
result.after = path.join(dirname, options.replace); | ||
/* leave result.after blank, signifying no replace was performed */ | ||
} | ||
} else { | ||
result.after = path.join(dirname, replace); | ||
} | ||
return result; | ||
}); | ||
return results; | ||
return result; | ||
} | ||
function expand(files){ | ||
var fileStats = new mfs.FileStats(files); | ||
var fileStats = new mfs.FileSet(files); | ||
fileStats.filesAndDirs = fileStats.files.concat(fileStats.dirs.reverse()); | ||
@@ -59,2 +61,7 @@ return fileStats; | ||
/** | ||
Takes a Results collection in, sets `renamed` and/or `error` on each with the expected values | ||
@param {Results} results - the Results collection to operate on | ||
@returns {Results} results | ||
*/ | ||
function dryRun(results){ | ||
@@ -81,2 +88,7 @@ results.list = results.list.map(function(result, index, resultsSoFar){ | ||
/** | ||
Takes a Results collection in, performs the rename on disk setting `renamer` and `error` as appropriate | ||
@param {Results} results - the Results collection to operate on | ||
@returns {Results} results | ||
*/ | ||
function rename(results){ | ||
@@ -117,8 +129,10 @@ results.list = results.list.map(function(result){ | ||
/** | ||
Search globally by default. If `options.regex` is not set then ensure any special regex characters in `options.find` are escaped. | ||
Search globally by default. If `options.regex` is not set then ensure any special regex characters in `options.find` are escaped. Do nothing if `options.find` is not set. | ||
*/ | ||
function regExBuilder(options){ | ||
var re = options.regex ? options.find : w.escapeRegExp(options.find), | ||
reOptions = "g" + (options.insensitive ? "i" : ""); | ||
return new RegExp(re, reOptions); | ||
if (options.find){ | ||
var re = options.regex ? options.find : w.escapeRegExp(options.find), | ||
reOptions = "g" + (options.insensitive ? "i" : ""); | ||
return new RegExp(re, reOptions); | ||
} | ||
} |
@@ -8,2 +8,3 @@ module.exports = Result; | ||
if (options.error) this.error = options.error; | ||
if (options.stat) this.stat = options.stat; | ||
} |
{ | ||
"name": "renamer", | ||
"description": "Batch rename files and folders", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"bin": "bin/cli.js", | ||
@@ -10,3 +10,4 @@ "main": "./lib/renamer", | ||
"scripts": { | ||
"test": "tape test/cli.js test/renamer.*.js" | ||
"test": "tape test/cli.js test/renamer.*.js", | ||
"lint": "jshint bin/cli.js lib/*.js; echo;" | ||
}, | ||
@@ -18,3 +19,3 @@ "dependencies": { | ||
"console-dope": "~0.3", | ||
"more-fs": "~0.2" | ||
"more-fs": "~0.3" | ||
}, | ||
@@ -21,0 +22,0 @@ "devDependencies": { |
@@ -1,4 +0,5 @@ | ||
[![NPM version](https://badge.fury.io/js/renamer.png)](http://badge.fury.io/js/renamer) | ||
[![Build Status](https://travis-ci.org/75lb/renamer.png)](https://travis-ci.org/75lb/renamer) | ||
[![Dependency Status](https://david-dm.org/75lb/renamer.png)](https://david-dm.org/75lb/renamer) | ||
[![view on npm](http://img.shields.io/npm/v/renamer.svg)](https://www.npmjs.org/package/renamer) | ||
[![npm module downloads per month](http://img.shields.io/npm/dm/renamer.svg)](https://www.npmjs.org/package/renamer) | ||
[![Build Status](https://travis-ci.org/75lb/renamer.svg)](https://travis-ci.org/75lb/renamer) | ||
[![Dependency Status](https://david-dm.org/75lb/renamer.svg)](https://david-dm.org/75lb/renamer) | ||
![Analytics](https://ga-beacon.appspot.com/UA-27725889-22/renamer/README.md?pixel) | ||
@@ -48,13 +49,13 @@ | ||
$ renamer --find this --replace that *.js | ||
$ renamer --find this --replace that '*.js' | ||
this command operates on all js files, recursively: | ||
$ renamer --find this --replace that **/*.js | ||
$ renamer --find this --replace that '**/*.js' | ||
this command operates on all js files from the `lib` directory downward: | ||
$ renamer --find this --replace that lib/**/*.js | ||
$ renamer --find this --replace that 'lib/**/*.js' | ||
**Bash users without globstar will need to enclose the glob expression in quotes to prevent native file expansion**, i.e. `"**/*.js"` | ||
**Bash users without globstar will need to enclose the glob expression in quotes to prevent native file expansion**, i.e. `'**/*.js'` | ||
@@ -279,3 +280,1 @@ Examples | ||
</table> | ||
![NPM](https://nodei.co/npm-dl/renamer.png?months=3) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35648
18
774
279
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedglob@4.5.3(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedminimatch@2.0.10(transitive)
+ Addedmore-fs@0.3.1(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removedmore-fs@0.2.2(transitive)
- Removedwodge@0.4.2(transitive)
Updatedmore-fs@~0.3