パッケージの詳細

unique-filename

npm105.6mISC4.0.0

Generate a unique filename for use in temporary directories or caches.

readme

unique-filename

Generate a unique filename for use in temporary directories or caches.

const uniqueFilename = require('unique-filename')

// returns something like: '/tmp/c5b28f47'
const randomTmpfile = uniqueFilename(os.tmpdir())

// returns something like: '/tmp/my-test-51a7b48d'
const randomPrefixedTmpfile = uniqueFilename(os.tmpdir(), 'my-test')

// returns something like: '/my-tmp-dir/testing-7ddd44c0'
const uniqueTmpfile = uniqueFilename('/my-tmp-dir', 'testing', '/my/thing/to/uniq/on')

uniqueFilename(dir, fileprefix, uniqstr) → String

Returns the full path of a unique filename that looks like: dir/prefix-7ddd44c0 or dir/7ddd44c0

dir – The path you want the filename in. os.tmpdir() is a good choice for this.

fileprefix – A string to append prior to the unique part of the filename. The parameter is required if uniqstr is also passed in but is otherwise optional and can be undefined/null/''. If present and not empty then this string plus a hyphen are prepended to the unique part.

uniqstr – Optional, if not passed the unique part of the resulting filename will be random. If passed in it will be generated from this string in a reproducible way.

更新履歴

Changelog

4.0.0 (2024-09-25)

⚠️ BREAKING CHANGES

  • unique-filename now supports node ^18.17.0 || >=20.5.0

    Bug Fixes

  • 94b387c #86 align to npm 10 node engine range (@reggi)

    Dependencies

  • 194c3ef #86 unique-slug@5.0.0

    Chores

  • 7f96619 #86 run template-oss-apply (@reggi)
  • 3bda296 #85 enable auto publish (#85) (@reggi)
  • 5b25a8b #83 bump @npmcli/eslint-config from 4.0.5 to 5.0.0 (@dependabot[bot])
  • 83cd1d9 #74 bump @npmcli/template-oss to 4.22.0 (@lukekarrys)
  • 2372b8f #84 postinstall for dependabot template-oss PR (@hashtagchris)
  • 813e0db #84 bump @npmcli/template-oss from 4.23.1 to 4.23.3 (@dependabot[bot])

3.0.0 (2022-10-14)

⚠️ BREAKING CHANGES

  • unique-filename is now compatible with the following semver range for node: ^14.17.0 || ^16.13.0 || >=18.0.0

Features

  • 6412fef #26 postinstall for dependabot template-oss PR (@lukekarrys)

Dependencies

  • 50d9443 #32 bump unique-slug from 3.0.0 to 4.0.0

2.0.1 (2022-08-25)

Dependencies

  • bump unique-slug from 2.0.2 to 3.0.0 (#15) (e48b56f)

2.0.0 (2022-08-22)

⚠ BREAKING CHANGES

  • Sets node engines to ^12.13.0 || ^14.15.0 || >=16.0.0

Dependencies

Documentation