danibram / mocker-data-generator

A simplified way to generate masive mock data based on a schema, you can use the awesome fake/random data generators like (FakerJs, ChanceJs, CasualJs and RandExpJs)
https://danibram.github.io/mocker-data-generator/
MIT License
426 stars 45 forks source link

question - how to enable en_US #120

Closed hborham closed 1 year ago

hborham commented 2 years ago

while trying to call the code below, i cannot seem to generate a valid zipcode for any state. this is apparent because only the definitions available when faker.definitions.address.postcode_by_state is invoked are `[#####,

-####]`
zip: {
        eval: true,
        locale: 'en_US',
        // faker: 'address.zipCodeByState(this.object.state)',
        function: function () {
            return this.faker.address.zipCodeByState(this.object.state) // resolves state to 'NY'
        },
    }

So how can I get the definitions loaded?

Complete code:

import mocker from 'mocker-data-generator';
import * as util from 'util';

const address = {
    state: {
        faker: 'address.stateAbbr',
    },
    zip: {
        eval: true,
        locale: 'en_US',
        // faker: 'address.zipCodeByState(this.object.state)',
        function: function () {
            return this.faker.address.zipCodeByState(this.object.state)
        },
    }
}

const addressData = mocker({locale: 'en_US'})
    .schema('address', address, 20)
    .buildSync();

console.log(util.inspect(addressData, { depth: 10 }));
danibram commented 1 year ago

Good night! I just release a new version that remove all specific generators from the package so you shouldnt have this kind of error again. That is a breaking change and also schemas and generation must be updated, just in case =) I think this will give you the opportunity to load the locale you need ;)