thedesk/node_modules/unused-filename
2018-01-28 21:22:43 +09:00
..
index.js TheDesk 2018-01-28 21:22:43 +09:00
license TheDesk 2018-01-28 21:22:43 +09:00
package.json TheDesk 2018-01-28 21:22:43 +09:00
readme.md TheDesk 2018-01-28 21:22:43 +09:00

unused-filename Build Status

Get an unused filename by appending a number if it exists: file.txtfile (1).txt

Useful for safely writing, copying, moving files without overwriting existing files.

Install

$ npm install --save unused-filename

Usage

.
├── rainbow (1).txt
├── rainbow.txt
└── unicorn.txt
const unusedFilename = require('unused-filename');

unusedFilename('rainbow.txt').then(filename => {
	console.log(filename);
	//=> 'rainbow (2).txt'
});

API

unusedFilename(filepath)

Returns a Promise<string>.

unusedFilename.sync(filepath)

Returns a string.

filepath

Type: string

  • filenamify - Convert a string to a valid safe filename

License

MIT © Sindre Sorhus