Faker.js: Logically connected random data

Created on 22 May 2018  Â·  9Comments  Â·  Source: Marak/faker.js

I'm using faker to generate random data for local development, great stuff. Some of the data that I generate is logically connected, like a currency isocode and symbol.

I'm currently doing the following:

{
  isocode: faker.finance.currencyCode(),
  symbol: faker.finance.currencySymbol()
}

Which can result in an object with conficting values, such as:

{
  isocode: 'USD',
  symbol: '€'
}

It would be great to have support for random data for not just a single value, but for a whole object instead.

Something like:

const finance = faker.finance();
{
    isocode: finance.currencyCode(),
    symbol: finance.currencySymbol()
}

Most helpful comment

Not a whole lot I guess, but I can image a few like currency:

  • country and countryCode
  • country and state
  • gender and names
  • firstname and lastname
  • phoneNumber and phoneNumberFormat

Also related, but less related are:

All 9 comments

???

@Marak I've updated the text a bit, but let me know if there's something unclear.

What else requires logically mappings besides currency code and currency symbol?

Not a whole lot I guess, but I can image a few like currency:

  • country and countryCode
  • country and state
  • gender and names
  • firstname and lastname
  • phoneNumber and phoneNumberFormat

Also related, but less related are:

postal code and state/city

@tobi-or-not-tobi

I can see the case for currency, country, and phone number having logical mappings to their respective pairs. I think name / email / domain name may already have the ability to pass a context as function arguments to provide contextual results.

This seems like something that could be improved in faker but should further discussed and planned. There might be other areas of the API that would benefit from this.

A pull request for currency codes might be a good start for now.

Related #68 #115

language / isocode would be another one.

@Marak can you review the PR?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marcelorl picture marcelorl  Â·  4Comments

Aleyasen picture Aleyasen  Â·  6Comments

adoyle-h picture adoyle-h  Â·  3Comments

AlexMiroshnikov picture AlexMiroshnikov  Â·  4Comments

aadamsx picture aadamsx  Â·  6Comments