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

@remibutler/easyrandom

v1.1.2

Published

easy ier to use random with nicer helper functions than actually using random

Downloads

14

Readme

EasyRandom

Build Status License: GPL v3

Easy random is a bunch of simple random functions that I've gotten sick of rewriting in basically every npm package. No one likes dependencies so this doesn't have any. Well okay there are 3 dev dependencies for testing, but you don't have to install those in production, lucky you.

Install

Readme's always have installation instructions so why would this one be any different.

$ npm install @remibutler/easyrandom

If you want to use this in production, and you should because it's better than your package, use the --production arg so you wont get any dev-dependencies installed.

$ npm ci @remibutler/easyrandom --production

Testing

Testing is done with:

This is simply because they're both very easy to use and hyper obvious, also they're basically mocha and chai, wait why don't we just use mo-

$ npm ci
$ npm test

Usage

const easyRandom = require('@remibutler/easyrandom');
const coin = easyRandom.flipACoin();

Full list of functions and their expected returns, there are jsdocs but you might wanna use runkit on npmjs so... here ya go!

.flipACoin()

Returns true or false randomly

easyRandom.flipACoin() // true or false

.getBetween(min, max)

Returns a psuedorandom positive whole number between a minium and maximum inclusive, parses input and shortcuts if the inputs are equal or the maximum is 0. If ether input is not parseable it will return 0.

easyRandom.getBetween(1, 6) // returns a whole number from 1 to 6

.getPercent()

Returns a pseudorandom whole number between 0 and 100 inclusive

easyRandom.getPercent() // returns a whole number from 0 to 100

.getMax(max)

Returns a psuedorandom whole number between 0 and your maximum inclusive, it parses input and shortcuts if the input is 0, it will happily explode if you pass a number that's too big. If input is not parseable it will return 0.

easyRandom.getMax(200) // returns a whole number from 0 to 200

.getString(length (optional))

Returns a pseudorandom alphanumeric string of optional length, default length is 7. Returns empty string for 0 length.

easyRandom.getString(20) // returns a random alphanumeric string of 20 characters

.getStringNonNumeric(length (optional))

Returns a pseudorandom alpha string of optional length, default length is 7. Returns empty string for 0 length.

easyRandom.getStringNonNumeric(20) // returns a random alpha string of 20 characters

.getStringWithCustomCharacterSet(length (optional), characterset (optional))

Returns a string inside a custom character set of optional length, defaults to alphanumeric and length of 7. Returns empty string for 0 length.

easyRandom.getStringWithCustomCharacterSet(20, 'YOURFACE') // returns a random string from characterset provided of 20 characters

Todo

This is functionality i need to ~~shamelessly steal~~ add.

.getDate()

Returns a pseudorandom date.

.getDateBetween(minimum, maximum)

Returns a date between two dates, accepts two date objects, returns today if minimum is larger than maximum or if either isn't a date.