@js-random/all
v0.3.5
Published
A collection of simple and lightweight randomizers for JavaScript (TypeScript friendly)
Downloads
11
Maintainers
Readme
@js-random/all
A collection of simple and lightweight randomizers for JavaScript (TypeScript friendly)
Packages
Here's a list of packages that are included in this build:
@js-random/number
GitHub repo, NPM@js-random/string
GitHub repo, NPM@js-random/boolean
GitHub repo, NPM@js-random/date
GitHub repo, NPM
Installation
For each individual package - see links above.
If you want everything at once, just do:
npm i -S @js-random/all
Usage
There are two ways to use @js-random/all
: imported and global.
Imported
This way you need to import the object containing all the randomizers yourself:
commonjs:
// Every @js-random package is contained in this object by their respective name
const random = require('@js-random/all');
TS/ES6+
import * as random from '@js-random/all';
<script>
tag
<script src="https://unpkg.com/@js-random/all"></script>
// For example - `@js-random/number` and `@js-random/boolean`:
const randomNumber = random.number(0, 10); // random number from 0 to 10 (inclusive)
const randomBoolean = random.boolean(); // half the chance of getting `true` or `false`
const probablyTrue = random.boolean(0.99); // 99% of getting `true`
Global
This setup introduces side-effects: each package's function is inserted into global constructors as random()
method:
commonjs
require('@js-random/all/lib/global');
ES6+
import '@js-random/all/module/global';
TS
import '@js-random/all/global';
and then:
const randomNumber = Number.random(0, 10);
const probablyTrue = Boolean.random(0.99); // 99% of getting `true`
// Same is true for String, Date and etc.