1.2.15 โข Published 2 years ago
@hikyu/random v1.2.15
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
1.2.15
2 years ago
1.2.14
2 years ago
1.2.13
2 years ago
1.2.12
2 years ago
1.2.11
2 years ago
1.2.10
2 years ago
1.2.9
2 years ago
1.2.8
2 years ago
1.2.7
2 years ago
1.1.6
2 years ago
1.1.5
2 years ago
1.1.4
2 years ago
1.1.3
2 years ago
1.1.2
2 years ago
1.1.1
2 years ago
1.0.32
2 years ago
1.0.31
2 years ago
1.0.30
2 years ago
1.0.29
2 years ago
1.0.28
2 years ago
1.0.27
2 years ago
1.0.26
2 years ago
1.0.25
2 years ago
1.0.24
2 years ago
1.0.23
2 years ago
1.0.22
2 years ago
1.0.21
2 years ago
1.0.20
2 years ago
1.0.19
2 years ago
1.0.18
2 years ago
1.0.17
2 years ago
1.0.16
2 years ago
1.0.15
2 years ago
1.0.14
2 years ago
1.0.13
2 years ago
1.0.12
2 years ago
1.0.11
2 years ago
1.0.10
2 years ago
1.0.9
2 years ago
1.0.8
2 years ago
1.0.7
2 years ago
1.0.6
2 years ago
1.0.5
2 years ago
1.0.4
2 years ago
1.0.3
2 years ago
1.0.2
2 years ago
1.0.1
2 years ago
1.0.0
2 years ago