npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, πŸ‘‹, I’m Ryan HefnerΒ  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you πŸ™

Β© 2024 – Pkg Stats / Ryan Hefner

@hikyu/random

v1.2.15

Published

Get random 🎲 things the easy way. Simple, quick and light 🀏. πŸ“‚ Zipped under 2kb with updates.

Downloads

72

Readme

Random

Get random 🎲 things the easy way. Simple, quick and light 🀏

πŸ“‚ Zipped under 2kb with updates.

Install

npm i @hikyu/random

Usage

I will use the deconstructed 🚧 require for demonstration

// Simple require
const random = require('@hikyu/random');
random.number(1, 10); // > 4

// Deconstructed require with custom names
const { number: ranNumber } = require('@hikyu/random');
ranNumber(1, 10); // > 4

// Deconstructed require
const { number, index, value, .. } = require('@hikyu/random');
number(1, 10); // > 4

Functions

Numbers πŸ”’

Digit

// Random number from 0 to 9
digit(); // > 8

// Random number from 0 to 4
digit(4); // > 1

Integer

// Random integer from 1 to 10
number(1, 10); // > 4

Decimal number

// Random number from 1 to 10 with 2 decimal spaces
number(1, 10, 2); // > 5.19

Boolean

// Generates either true or false
boolean(); // > false

Array πŸ“ƒ

Index of array

// Random index out of the array
index(["hello", "world", 1]); // > 1

Value of array

// Random value out of the array
value("hello", "world", 1); // > "hello"

Misc 🀨

Template

| Meaning | Charcode | Outputs | |---------|----------|-------------------------| | Any | a | Any of the below | | Char | c | Lowercase char | | Char | C | Uppercase char | | Char | s | Upper or lowercase char | | Digit | d | Digit 0-9 | | Digit | 0-9 | Digit up to value | | Escape | $ | Escape the next char |

// Generate template string
template('aaaaa'); // > "6qxsF"
template('ccccc'); // > "htcfi"
template('CCCCC'); // > "UNHCG"
template('sssss'); // > "ZaSrV"
template('ddddd'); // > "54628"
template('00033'); // > "00031"
template('ccc - $3 $Ch$ar$a$cters'); // > "zpb - 3 Characters"

// Password example
template('sdssdssdsssdd'); // > d5pi7tI7vWr85

// Byte example
template('1111 1111'); // > 0101 1101

// Telephone example
template('ddd-ddd-dddd'); // > 607-321-8576

Color - RGB

// Random RGB color as string
rgb(); // > "rgb(66, 193, 254)"

Color - RGBA

// Random RGB color as string
rgba(); // > "rgba(251, 41, 72, 0.47)"

Color - HEX

// Random RGB color as string
hex(); // > "#6c7ac4"

Color - HSL

// Random HSL color as string
hsl(); // > "hsl(153, 44%, 64%)"

Emoji

// Random Emoji
emoji(); // > "πŸš€"

Dice 🎲

// Generate 3 values from 1 to 20
dice(20, 3); // > [ 2, 7, 11 ]

Byte

// Generate 3 values from 1 to 20
byte(); // > "0101 1110"

Bit

// Generate 0 or 1
bit(); // > 0