unique-filename
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
unique-slug | 2.0.2 | 1.57 kB | ISC | prod |
The unique-filename npm package is a useful tool designed to generate unique filenames. These filenames are typically employed within temporary directories or caches. If you're looking to prevent filename clash, or require a unique identifier for files, this package can handle that.
If you want to make use of unique-filename in your projects, you'll need to install it via npm and then require it within your JavaScript code.
Below is an example of how to use the unique-filename package:
const uniqueFilename = require('unique-filename');
// Generate a random unique filename in the OS tmp directory
// This might return something like: '/tmp/c5b28f47'
const randomTmpfile = uniqueFilename(os.tmpdir());
// Generate a random unique filename in the OS tmp directory with a specific prefix
// This might return something like: '/tmp/my-test-51a7b48d'
const randomPrefixedTmpfile = uniqueFilename(os.tmpdir(), 'my-test');
// Generate a unique filename based on a specific string in a custom directory with a specific prefix
// This might return something like: '/my-tmp-dir/testing-7ddd44c0'
const uniqueTmpfile = uniqueFilename('/my-tmp-dir', 'testing', '/my/thing/to/uniq/on');
The comprehensive documentation for unique-filename can be found on the npm package's GitHub page, which is accessible at https://github.com/npm/unique-filename.git. The documentation provides details on how to use each of the functions provided in the unique-filename package, ensuring you can seamlessly incorporate it into your projects.