Socket
Socket
Sign inDemoInstall

random-stuff-js

Package Overview
Dependencies
0
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    random-stuff-js

An easy to use library export random javascript stuff for doing useful things.


Version published
Weekly downloads
0
Maintainers
1
Created
Weekly downloads
 

Readme

Source

random-stuff-js

A library that provides some random but very useful functions that are commonly used in most javascript projects.

Features

  • Generate random number
  • Pick random element from array
  • Generate random name
  • Generate OTP
  • Probability
  • Minimum/Maximum element of an array
  • Wait/Sleep function

Installation

To install random-stuff-js

  # with npm:
  npm install random-stuff-js --save

  # with yarn:
  yarn add random-stuff-js

  # with pnpm:
  pnpm add random-stuff-js

  # with bun:
  bun add random-stuff-js

Usage

random-stuff-js can be used in almost any javascript project to achieve the above mentioned features with no extra effort. The functions provided by random-stuff-js may be categorised into 3 categories:

Random
import { randomNumber, randomElement, randomAdjective, randomAnimal, randomName, generateOTP } from 'random-stuff-js';

console.log(randomNumber(10, 20)) // Any number between 10 and 20 (both numbers included) will be logged

console.log(randomElement([3, 2, 10, 7, 8])) // Any one random element of the array will be logged

console.log(randomAdjective()) // Any one adjective from a list of 25 adjective will be logged

console.log(randomAnimal()) // Any one animal from a list of 200 animals will be logged

console.log(randomName('-')) // A combination of randomAdjective() and randomAnimal() will be logged with a '-' separator in between. Default separator is ' '

console.log(generateOTP(6)) // A 6 digit string OTP will be logged
Math
import { probability, minimumNumber, maximumNumber } from 'random-stuff-js';

if (probability(0.5)) console.log(true) // There is a 50% chance that true will be logged

const array = [89, 6, 99, 2, 50, 10]
console.log(minimumNumber(array)) // 2
console.log(maximumNumber(array)) // 99
Time
import { wait } from 'random-stuff-js';

async function test(time) {
  const ref = Date.now()
  await wait(time)
  return Date.now() - ref
}

test(1000).then(time => console.log(time)) // ~1000

Used By

Author

Sahil Aggarwal

Keywords

FAQs

Last updated on 14 Oct 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc