Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

random-path

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

random-path

Generate a random path name.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
55K
decreased by-1.13%
Maintainers
1
Weekly downloads
 
Created
Source

Random Path

Generate a random path name.

Installation

npm install --save random-path

Usage

import os from 'node:os'
import randomPath from 'random-path'

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

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

API

randomPath(directory, template)

  • directory (string, required)
  • template (string, required)
  • returns string - the generated path

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

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.

See also

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

FAQs

Package last updated on 24 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc