JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 113977
  • Score
    100M100P100Q202031F
  • License MIT

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

Package Exports

  • unused-filename

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (unused-filename) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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 unused-filename

Usage

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

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

API

unusedFilename(filePath)

Returns a Promise<string> containing either the original filename or the filename appended with a number.

unusedFilename.sync(filePath)

Returns a string containing either the original filename or the filename appended with a number.

filePath

Type: string

The path to check for filename collision.

  • filenamify - Convert a string to a valid safe filename

License

MIT © Sindre Sorhus