You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.2 KiB

4 years ago
  1. unique-filename
  2. ===============
  3. Generate a unique filename for use in temporary directories or caches.
  4. ```
  5. var uniqueFilename = require('unique-filename')
  6. // returns something like: /tmp/912ec803b2ce49e4a541068d495ab570
  7. var randomTmpfile = uniqueFilename(os.tmpdir())
  8. // returns something like: /tmp/my-test-912ec803b2ce49e4a541068d495ab570
  9. var randomPrefixedTmpfile = uniqueFilename(os.tmpdir(), 'my-test')
  10. var uniqueTmpfile = uniqueFilename('/tmp', 'testing', '/my/thing/to/uniq/on')
  11. ```
  12. ### uniqueFilename(*dir*, *fileprefix*, *uniqstr*) → String
  13. Returns the full path of a unique filename that looks like:
  14. `dir/prefix-7ddd44c0`
  15. or `dir/7ddd44c0`
  16. *dir* – The path you want the filename in. `os.tmpdir()` is a good choice for this.
  17. *fileprefix* – A string to append prior to the unique part of the filename.
  18. The parameter is required if *uniqstr* is also passed in but is otherwise
  19. optional and can be `undefined`/`null`/`''`. If present and not empty
  20. then this string plus a hyphen are prepended to the unique part.
  21. *uniqstr* – Optional, if not passed the unique part of the resulting
  22. filename will be random. If passed in it will be generated from this string
  23. in a reproducable way.