+1
-0
@@ -22,2 +22,3 @@ const EventEmitter = require('events').EventEmitter | ||
| * @param {string} [options.indexFormat] - The format of the number to replace `{{index}}` with. Specify a standard printf format string, for example `%03d` would yield 001, 002, 003 etc. Defaults to `%d`. | ||
| * @param {string} [options.indexRoot] - The initial value for `{{index}}`. Defaults to 1. | ||
| * @emits module:renamer#replace-result | ||
@@ -24,0 +25,0 @@ */ |
| class PluginBase { | ||
| /** | ||
| * @param {string} filePath - The current file path being processed | ||
| * @param {object} options - The current options, e.g. `options.find`, `options.replace` plus any custom options. | ||
| * @param {number} index - The index of the current filePath in the full list of files to process. | ||
| * @param {string[]} files - The full list of files to process (after any glob expressions have been expanded). | ||
| * @param {object} options - The current options (in camel-case), e.g. `options.find`, `options.replace` plus any custom options. | ||
| * @param {number} index - The index of the current filePath within the full list of input files. | ||
| * @param {string[]} files - The full list of input files to process (after glob expressions have been expanded). | ||
| * @returns {string} - The modified or unmodified file path. | ||
| */ | ||
@@ -8,0 +9,0 @@ replace (filePath, options, index, files) { |
+14
-6
| module.exports = PluginBase => class Index extends PluginBase { | ||
| constructor () { | ||
| super() | ||
| this.matchCount = 1 | ||
| } | ||
| description () { | ||
@@ -13,8 +8,21 @@ return 'Replace the `\\{\\{index\\}\\}` token in a path with a number incremented for each file renamed.' | ||
| return [ | ||
| { name: 'index-format', description: 'The format of the number to replace `\\{\\{index\\}\\}` with. Specify a standard printf format string, for example `%03d` would yield 001, 002, 003 etc. Defaults to `%d`.' } | ||
| { name: 'index-format', description: 'The format of the number to replace `\\{\\{index\\}\\}` with. Specify a standard printf format string, for example `%03d` would yield 001, 002, 003 etc. Defaults to `%d`.' }, | ||
| { name: 'index-root', description: 'The initial value for `\\{\\{index\\}\\}`. Defaults to 1.' } | ||
| ] | ||
| } | ||
| // Number to use in place of {{index}}. | ||
| calculateMatchCount (indexRoot) { | ||
| if (this.matchCount || this.matchCount === 0) { | ||
| return this.matchCount | ||
| } else if (indexRoot || indexRoot === 0) { | ||
| return indexRoot | ||
| } else { | ||
| return 1 | ||
| } | ||
| } | ||
| replace (filePath, options) { | ||
| if (/{{index}}/.test(filePath)) { | ||
| this.matchCount = this.calculateMatchCount(options.indexRoot) | ||
| const path = require('path') | ||
@@ -21,0 +29,0 @@ const file = path.parse(filePath) |
+6
-5
| { | ||
| "name": "renamer", | ||
| "description": "Rename files in bulk", | ||
| "version": "1.0.0", | ||
| "version": "1.1.0", | ||
| "author": "Lloyd Brookes <75pound@gmail.com>", | ||
@@ -37,8 +37,8 @@ "bin": "bin/cli.js", | ||
| "command-line-usage": "^5.0.5", | ||
| "fast-diff": "^1.1.2", | ||
| "glob": "^7.1.2", | ||
| "fast-diff": "^1.2.0", | ||
| "glob": "^7.1.3", | ||
| "global-modules": "^1.0.0", | ||
| "load-module": "^1.0.0", | ||
| "node-version-matches": "^1.0.0", | ||
| "printj": "^1.1.2", | ||
| "printj": "^1.2.1", | ||
| "reduce-flatten": "^2.0.0", | ||
@@ -53,5 +53,6 @@ "reduce-unique": "^2.0.1", | ||
| "mkdirp2": "^1.0.4", | ||
| "nyc": "^13.1.0", | ||
| "rimraf": "^2.6.2", | ||
| "test-runner": "^0.5.0" | ||
| "test-runner": "^0.5.1" | ||
| } | ||
| } |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
24699
2.38%488
2.09%6
20%Updated
Updated
Updated