0.2.0 • Published 11 months ago

ideal-filename v0.2.0

Weekly downloads
22
License
MIT
Repository
github
Last release
11 months ago

Ideal-Filename

Gets the ideal filename according to the given one.

API

  • idealFilename(filename: string, extname:? string): Promise<string>
    • filename The original filename.
    • extname Sets a specified extension name.
  • idealFilename(filename: string, callback: (err: Error, filename: string) => void): void;
  • idealFilename(filename: string, extname: string, callback: (err: Error, filename: string) => void): void

This function will check if the given filename already exists, if not, the given filename will be returned, otherwise increase the filename with a number appended to the basename (before extname).

It's better to always pass the filename an absolute path, and the separators will always be converted to platform-specific ones.

Example

import idealFilename from "ideal-filename";

idealFilename("index.js").then(filename => {
    console.log(filename); // => index (1).js
});

// Or
(async() => {
    var filename = await idealFilename("index.js");
    console.log(filename);
})();

// Or 
idealFilename("index.js", filename => {
    console.log(filename);
});
0.2.0

11 months ago

0.1.3

5 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago