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

arandomly

v2.0.1

Published

Random value generator module

Downloads

27

Readme

a RandomLy

The npmjs package, random value (number / bool / data) provider

Both inclusive random, rand(0, 100) can return one number of [0, 1, 38, 66, 100]

Install

npm i arandomly
# or
yarn add arandomly

Import

const {rand} = require('arandomly');
// or
import {rand} from 'arandomly';

Documentation

rand()

const value = rand(0, 100);
console.log(value); // 0 to 100 (both inclusive)

bigint()

const value = bigint(0, 100);
console.log(value); // BigInt 0 to 100 (both inclusive)

bool()

const value = bool();
console.log(value); // true or false

boolChance()

const value = boolChance(50);
console.log(value); // true with 50 chance VS false with another half

float()

// const value = float(0, 1);
const value = floatDeep(0, 1, 2);

// value = one of [0, 0.29, 0.3, 0.01, 0.5, 0.99, 1];
console.log(value); // 0 to 1; 2 decimal

oneOfArray()

oneValueOfArray()

const value = oneOfArray([1, 2, 3]);
console.log(value); // 1 or 2 or 3

oneOfObject()

const value = oneOfObject({a: 1, b: 2, c: 3});
// value: object = {a: 1}
console.log(value); // {a: 1}

oneValueOfObject()

const value = oneValueOfObject({a: 1, b: 2, c: 3});
console.log(value); // 1 or 2 or 3

uniqColorHex()

const withAlpha = false;
const value = uniqColorHex(withAlpha);
console.log(value); // '#00cccc', or with true: '#33667799'

uniqColorRGB()

const opacity = 1; // 0 or 0.01 to 0.99 or 1
// 0 = random
// float = set opacity
// 1 = 100% opacity

const value = uniqColorRGB(opacity);
// rgba(59, 16, 90, 0.50)
// rgba(46, 91, 14, 0.69)
// rgb(251, 76, 71)

console.log(value); // rgb or rgba

uniqColorHSL()

const randomOpacity = true;
const value = uniqColorHSL(randomOpacity);
// hsl(135deg 2% 35% / 63%)
// hsl(80deg 11% 36%)
console.log(value); // hsl()

machine dice()

const value = mdice(6); // cube with 6 sides
console.log(value); // {result: 1, visual: '⚀'}

machine roll()

const value = mroll();
console.log(value); // {result: 91, text: '091'}

machine slot()

// 1 = one spin
// 3 = fruits in one row = reels
// undefined = third arg = (by default) 9 fruits
const value = mslot(1, 3);
console.log(value);
/* [[
    { result: 3, visual: '🍑' },
    { result: 8, visual: '🍐' },
    { result: 4, visual: '🍇' }
]] */

uniqString()

const value = uniqString();
console.log(value); // 'NAaU' or 'evQk'
console.log(uniqString(5, 'abc')); // 'abbbc' or 'cacbb'

uniqUseragent()

const value = uniqUseragent(110, 120);
console.log(value);
// 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.5085.0 Safari/537.36'

uniqSmsCode()

const smooth = false;
const value = uniqSmsCode(4, smooth);
// smooth true  = 3337 or 8899
// smooth false = 7240 or 5414
console.log(value);

uniqDate()

const value = uniqDate(0, 2147483647);
console.log(value.toDateString(), value.toISOString()); // 'Sun Feb 03 2002 & 2004-04-07T05:15:38.000Z'

uniqDateForOneYear()

const year = 2023; // by default = current year
const value = uniqDateForOneYear(year);
console.log(value.toISOString()); // '2023-12-31T11:52:22.000Z'

uniqDateForYears()

const year = 2023; // by default = current year
const value = uniqDateForYears(year);
console.log(value[0].toISOString()); // '2023-07-24T17:28:58.000Z'