JSPM

random-path

0.1.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 49918
  • Score
    100M100P100Q193114F
  • License MIT

Package Exports

  • random-path

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (random-path) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Random Path

Generate a random path name.

Installation

npm install --save random-path

Usage

const os = require('os')
const randomPath = require('random-path')

const path = randomPath(os.tmpDir(), '%s.txt')

console.log(path)
//=> /tmp/Y374CW8.txt

API

randomPath(directory, template)

Generates 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'.

Returns a string with the path.

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.

randomPath.validateTemplate(template)

Check to see if the template is a valid template accepted by randomPath. Throws an error if the template is invalid.

See also

  • fs-temp - A quick and simple way to create temporary files and directories.