Skip to content

Commit

Permalink
100% code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rundef committed Dec 9, 2015
1 parent 0f2f601 commit a910380
Show file tree
Hide file tree
Showing 3 changed files with 217 additions and 201 deletions.
48 changes: 24 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ A module to get a unique filename using incremental values.
var uniquefilename = require('uniquefilename');
options = {};
uniquefilename.get('/path/to/dir/file.jpg', options, function(filename) {
// your code here: filename might be "/path/to/dir/file.jpg",
// "/path/to/dir/file-2.jpg", "/path/to/dir/file-3.jpg", etc...
// depending on the files that exist on your filesystem
// your code here: filename might be "/path/to/dir/file.jpg",
// "/path/to/dir/file-2.jpg", "/path/to/dir/file-3.jpg", etc...
// depending on the files that exist on your filesystem
});
```

Expand All @@ -29,9 +29,9 @@ uniquefilename.get('/path/to/dir/file.jpg', options, function(filename) {
var uniquefilename = require('uniquefilename');
options = {separator: '~', paddingCharacter: '0', paddingSize: 4, mode: 'alphanumeric'};
uniquefilename.get('/path/to/dir/file.jpg', options, function(filename) {
// your code here: filename might be "/path/to/dir/file.jpg",
// "/path/to/dir/file~000h.jpg", "/path/to/dir/file~00h9.jpg", etc...
// depending on the files that exist on your filesystem
// your code here: filename might be "/path/to/dir/file.jpg",
// "/path/to/dir/file~000h.jpg", "/path/to/dir/file~00h9.jpg", etc...
// depending on the files that exist on your filesystem
});
```

Expand Down Expand Up @@ -65,9 +65,9 @@ Here's an example :
var uniquefilename = require('uniquefilename');
options = {mode: 'alpha', paddingCharacter: '0', paddingSize: 3};
uniquefilename.get('/path/to/dir/file.jpg', options, function(filename) {
// your code here: filename might be "/path/to/dir/file.jpg",
// "/path/to/dir/file-002.jpg", "/path/to/dir/file-045.jpg", etc...
// depending on the files that exist on your filesystem
// your code here: filename might be "/path/to/dir/file.jpg",
// "/path/to/dir/file-002.jpg", "/path/to/dir/file-045.jpg", etc...
// depending on the files that exist on your filesystem
});
```

Expand All @@ -77,22 +77,22 @@ Multer is a node.js middleware for handling `multipart/form-data`, which is prim
The following example shows you how to use multer along with this module to move an uploaded file to a unique filename :

```javascript
var multer = require('multer');
var path = require('path');
var uniquefilename = require('uniquefilename');
var multer = require('multer');
var path = require('path');
var uniquefilename = require('uniquefilename');

router.use(multer({
storage: multer.diskStorage({
destination: function (req, file, cb) {
cb(null, './public/uploads/')
},
filename: function (req, file, cb) {
originalname = path.resolve('./public/uploads/' + file.originalname);
options = {};
uniquefilename.get(originalname, options, function(filename) {
cb(null, path.basename(filename));
});
}
})
storage: multer.diskStorage({
destination: function (req, file, cb) {
cb(null, './public/uploads/')
},
filename: function (req, file, cb) {
originalname = path.resolve('./public/uploads/' + file.originalname);
options = {};
uniquefilename.get(originalname, options, function(filename) {
cb(null, path.basename(filename));
});
}
})
}).single('thumbnail'));
```
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"description": "Finds a unique filename using incremental values",
"scripts": {
"test": "./node_modules/istanbul/lib/cli.js cover ./node_modules/.bin/_mocha",
"test-cov": "istanbul cover --report html node_modules/mocha/bin/_mocha --check-leaks",
"coveralls": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls"
},
"keywords": [
Expand Down
Loading

0 comments on commit a910380

Please sign in to comment.