1.2.15 โ€ข Published 3 years ago

@hikyu/random v1.2.15

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Random

Get random ๐ŸŽฒ things the easy way. Simple, quick and light ๐Ÿค

๐Ÿ“‚ Zipped under 2kb with updates.

npm.io npm.io npm.io

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

MeaningCharcodeOutputs
AnyaAny of the below
CharcLowercase char
CharCUppercase char
CharsUpper or lowercase char
DigitdDigit 0-9
Digit0-9Digit 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
1.2.15

3 years ago

1.2.14

3 years ago

1.2.13

3 years ago

1.2.12

3 years ago

1.2.11

3 years ago

1.2.10

3 years ago

1.2.9

3 years ago

1.2.8

3 years ago

1.2.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.0.32

3 years ago

1.0.31

3 years ago

1.0.30

3 years ago

1.0.29

3 years ago

1.0.28

3 years ago

1.0.27

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago