1.1.1 • Published 2 years ago
rand-ms v1.1.1
rand-ms
Get pseudo-random millisecond values for timeouts/intervals
Install
npm install rand-ms
Usage
import randMS from 'rand-ms';
randMS(); // random ms between 0 & 10 seconds
//=> 6712
randMS(1); // random ms between 0 & 1 seconds
//=> 992
randMS(1, 4); // random ms between 1 & 4 seconds
//=> 3493
randMS('1ms', 4); // random ms between 1 ms & 4 s
//=> 2
randMS(1, '4seconds'); // random ms between 1 & 4 s
//=> 2351
randMS('1m', '4minutes'); // random ms between 1 & 4 minutes
//=> 80351
randMS('1h', '4hours'); // random ms between 1 & 4 hours
//=> 3640039
randMS('1d', '4days'); // random ms between 1 & 4 days
//=> 86482659
randMS('1w', '4weeks'); // random ms between 1 & 4 weeks
//=> 604800000
randMS('1M', '4months'); // random ms between 1 & 4 months
//=> 604800000
randMS('1y', '4years'); // random ms between 1 & 4 years
//=> 31557600000
API
randMS(min|max?, max?)
min|max
Type: integer|string
Default: 10
If max is provided, this is the minimum number of seconds you would like represented as milliseconds. If no max is provided, this is assumed to be the maximum, and the minimum is set to 0.
max
Type: integer|string
Default: undefined
Maximum number of seconds you would like represented as milliseconds. If undefined
or null
, will be ignored and first parameter will be used for maximum.
string format
The string format for the time interval value of what you are passing in for min/max is a number followed immediately by any of the following:
ms
, s
, m
, h
, d
, w
, M
, y
, milliseconds
, seconds
, minutes
, hours
, days
, weeks
, months
, years