new-filename
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

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(liststring[]]), namestring): 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).

Package Sidebar

Install

npm i new-filename

Weekly Downloads

129

Version

2.0.1

License

MIT

Unpacked Size

8.22 kB

Total Files

8

Last publish

Collaborators

  • alphakevin