package
Generate a random path name.
npm install random-pathGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Generate a random path name.
npm install --save random-pathimport os from 'node:os'
import randomPath from 'random-path'
const path = randomPath(os.tmpDir(), '%s.txt')
console.log(path)
//=> /tmp/Y374CW8.txtrandomPath(directory, template)directory (string, required)template (string, required)string - the generated pathGenerates a random path name with the specified directory and template.
template should be a string where %s will be replaced with some random characters (e.g. 'linusu-%s'). The string should contain %s exactly once. If you want to include a literal percent sign, escape it with another one, e.g. '%%string' becomes '%string'.
Important: This module makes no guarantees on wether there exists a file at the returned path or not. Do not simply write data to the returned path. If you want a random file, use the higher level module fs-temp.
validateTemplate(template)template (string, required)Check to see if the template is a valid template accepted by randomPath. Throws an error if the template is invalid.
Estimated unpacked size across 6 packages.
32.4 kB
Includes dependencies.