2.0.1 • Published 5 years ago

new-filename v2.0.1

Weekly downloads
13
License
MIT
Repository
github
Last release
5 years ago

new-filename

Generating a new filename like 'basename (1).ext' without conflicting with existing ones.

Install

npm install new-filename
# or
yarn add new-filename

Usage

/**
 * Generating a new filename to avoid names in the list by adding sequenced number
 * @param list - Filenames already in use
 * @param name - New filenames about to use
 * @returns Generated new filename
 */
getNewFilename(list: string[]]), name: string): string

Example

import getNewFilename from 'new-filename';

const newName = getNewFilename([
  'untitled.txt',
  'untitled (2).txt',
  'file3.txt',
  'file4.java',
], 'untitled.txt');

console.log(newName);
// => 'untitled (3).txt'

Tests

npm test

Similar Packages

unused-filename has the same feature, but it operates on the file system, new-filename gives you a opportunity to get unused filename independent from platform (e.g. on browser).

2.0.1

5 years ago

2.0.0

5 years ago

1.0.1

6 years ago

1.0.0

6 years ago