Random Data Generator In JavaScript – offhand

Category: Javascript | January 5, 2022
Author:astridlyre
Views Total:37 views
Official Page:Go to website
Last Update:January 5, 2022
License:MIT

Preview:

Random Data Generator In JavaScript – offhand

Description:

Generating random data (also called dummy data or fake data) for development, testing and exposure is a pretty common activity in the software business.

offhand is a JavaScript-powered random data generator that allows you to easily generate example data in various formats, such as colors, numbers, dates, times, letters, strings, credit card details, and much more.

I’ve been using this random data generator for several projects and found it extremely handy. I hope you’ll find it useful, too.

Table Of Contents:

How to use it:

1. Install & download.

# NPM
$ npm i @ebflat9/offhand

2. Import the offhand.

import { Offhand } from '@ebflat9/offhand'
// Or browser:
<script type="module">
  import { Offhand } from './dist/index.js'
</script>

3. Initialize the offhand and set the local.

const offhand = Offhand.setup({ 
      locale: 'en-US' 
})

4. Generate a random number.

offhand.randomGenerator.from([1, 2, 3])
// randomNumbers() => 3
// randomNumbers() => 1
// randomNumbers() => 2
offhand.randomizer.randomDigit();
// => 0.71'
offhand.replacer.numberify('####-####')
// => 6210-1900

5. Generate random dates.

offhand.date.random('MM-DD-YYYY');
// => 12/19/1969, 4:39:44 PM
offhand.date.century();
// => V
offhand.date.ampm();
// => pm
offhand.date.dayOfYear();
// => 164
offhand.date.dayOfMonth();
// => 9
offhand.date.dayOfWeek()
// => Tuesday
offhand.date.monthNumber();
// => 3
offhand.date.monthName();
// => March
offhand.date.year();
// => 2021
offhand.date.timezone();
// => Europe/Belgrade
offhand.date.unix();
// => 1203158583203
offhand.date.time();
// => 18:39:28

6. Generate random letters.

offhand.replacer.letterify('XXXX-XXXX');
// => Cxxd-wFNm
offhand.randomizer.randomLowerCase();
// => e
offhand.randomizer.randomUpperCase(),
// => E
offhand.randomizer.randomLetter()
// => e

7. Generate random credit card details.

offhand.creditCard.paymentDetails()
/* =>
{
  type: 'Discover Card', 
  number: '6011037174704439', 
  expiration: '06/68', 
  holder: 'John Smith'
}
*/

8. Generate colors.

offhand.color.name();
// => Azure
offhand.color.safeName();
// => blue
offhand.color.value();
// => 140
offhand.color.opacity();
// => 0.15
offhand.color.rgbArray()
// => [163, 64, 109]
offhand.color.rgbaArray()
// => [188, 27, 171, 0.38]
offhand.color.rgb();
// => rgb(215, 37, 120)
offhand.color.rgba();
// => rgba(200, 131, 68, 0.6)
offhand.color.hex();
// => #a2bec0

9. Generate address information.

offhand.address.cityPrefix();
// => North
offhand.address.citySuffix();
// => mouth
offhand.address.streetSuffix();
// => Falls
offhand.address.country();
// => Cayman Islands
offhand.address.buildingNumber();
// => 3284
offhand.address.zip(5);
// => 30893

You Might Be Interested In:


Leave a Reply