diff options
Diffstat (limited to 'resources/app/node_modules/unused-filename/index.js')
-rw-r--r-- | resources/app/node_modules/unused-filename/index.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/resources/app/node_modules/unused-filename/index.js b/resources/app/node_modules/unused-filename/index.js new file mode 100644 index 0000000..cdb127c --- /dev/null +++ b/resources/app/node_modules/unused-filename/index.js @@ -0,0 +1,20 @@ +'use strict'; +const pathExists = require('path-exists'); +const modifyFilename = require('modify-filename'); + +const incrementer = fp => { + let i = 0; + return () => modifyFilename(fp, (filename, ext) => `${filename} (${++i})${ext}`); +}; + +module.exports = fp => { + const getFp = incrementer(fp); + const find = newFp => pathExists(newFp).then(x => x ? find(getFp()) : newFp); + return find(fp); +}; + +module.exports.sync = fp => { + const getFp = incrementer(fp); + const find = newFp => pathExists.sync(newFp) ? find(getFp()) : newFp; + return find(fp); +}; |