Installations
npm install uniquefilename
Releases
Unable to fetch releases
Contributors
Developer
rundef
Developer Guide
Module System
CommonJS
Min. Node Version
>= 0.10.0
Typescript Support
No
Node Version
6.2.2
NPM Version
3.9.5
Statistics
2 Stars
34 Commits
1 Forks
3 Watching
1 Branches
2 Contributors
Updated on 28 Dec 2020
Bundle Size
79.25 kB
Minified
22.47 kB
Minified + Gzipped
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
288,845
Last day
44.8%
42
Compared to previous day
Last week
-10.8%
249
Compared to previous week
Last month
-28.4%
1,279
Compared to previous month
Last year
-52.9%
32,018
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
uniquefilename
A module to get a filename - that doesn't already exist on the filesystem - using incremental values.
Install
1npm install uniquefilename
Usage
uniquefilename.get(filepath, [options], [callback])
Basic example
1var uniquefilename = require('uniquefilename'); 2options = {}; 3uniquefilename.get('/path/to/dir/file.jpg', options, function(filename) { 4 // filename might be "/path/to/dir/file.jpg", 5 // "/path/to/dir/file-2.jpg", "/path/to/dir/file-3.jpg", etc... 6 // depending on the files that exist on your filesystem 7});
Example with promises
If a callback is not supplied, a Promise is returned (using bluebird).
1var uniquefilename = require('uniquefilename'); 2uniquefilename.get('/path/to/dir/file.jpg', {}).then(function (filename) { 3 console.log(filename); 4});
Advanced example
1var uniquefilename = require('uniquefilename'); 2options = {separator: '~', paddingCharacter: '0', paddingSize: 4, mode: 'alphanumeric'}; 3uniquefilename.get('/path/to/dir/file.jpg', options, function(filename) { 4 // filename might be "/path/to/dir/file.jpg", 5 // "/path/to/dir/file~000h.jpg", "/path/to/dir/file~00h9.jpg", etc... 6 // depending on the files that exist on your filesystem 7});
Options
separator
If the specified filename exists, the separator will be added before the incremental value such as: file{separator}2.jpg
The default value is '-'
.
mode
The mode allows you to specify which characters to use to generate the incremental value (the string after the separator)
The default value is 'numeric'
.
'numeric'
Using the following characters:1234567890
'alpha'
Using the following characters:abcdefghijklmnopqrstuvwxyz
'ALPHA'
Using the following characters:ABCDEFGHIJKLMNOPQRSTUVWXYZ
'alphanumeric'
Using the following characters:0123456789abcdefghijklmnopqrstuvwxyz
'ALPHANUMERIC'
Using the following characters:0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
'charset'
You must specify the characters you wish to use in thecharset
option
paddingCharacter && paddingSize
If you wish to left-pad the incremental values with a character, use this option. Here's an example :
1var uniquefilename = require('uniquefilename'); 2options = {mode: 'alpha', paddingCharacter: '0', paddingSize: 3}; 3uniquefilename.get('/path/to/dir/file.jpg', options, function(filename) { 4 // filename might be "/path/to/dir/file.jpg", 5 // "/path/to/dir/file-002.jpg", "/path/to/dir/file-045.jpg", etc... 6 // depending on the files that exist on your filesystem 7});
alwaysAppend
If alwaysAppend
is true
filenames will include the separator and attachment from the first request. So instead of
file.jpg
, file-2.jpg
you'd get file-1.jpg
, file-2.jpg
.
Using it with multer
Multer is a node.js middleware for handling multipart/form-data
, which is primarily used for uploading files.
The following example shows you how to use multer along with this module to move an uploaded file to a unique filename :
1var multer = require('multer'); 2var path = require('path'); 3var uniquefilename = require('uniquefilename'); 4 5router.use(multer({ 6 storage: multer.diskStorage({ 7 destination: function (req, file, cb) { 8 cb(null, './public/uploads/') 9 }, 10 filename: function (req, file, cb) { 11 originalname = path.resolve('./public/uploads/' + file.originalname); 12 options = {}; 13 uniquefilename.get(originalname, options, function(filename) { 14 cb(null, path.basename(filename)); 15 }); 16 } 17 }) 18}).single('thumbnail'));
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 2/27 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 5 are checked with a SAST tool
Score
3
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More