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] Can I do chance: 'first({gender: "female"}) #65

Closed beebase closed 6 years ago

beebase commented 6 years ago

Is this possible?

first: {
    chance: 'first({gender: "female"})'
  },
beebase commented 6 years ago

ah ok, that would be:

first: {
    eval: 'chance.first({gender: "female"})'
  },
danibram commented 6 years ago

Hi, sorry for the delay and thank you for open an issue. In order to increase the performance of the generator I have to remove the auto-eval inside the generators, so to activate the old eval you have to pass ´eval:true´, feel free to try on the playgroud

first: {
    chance: 'first({gender: "female"})',
    eval: true
  },
danibram commented 6 years ago

Sorry, for reopen, I check the parser function and maybe there is an error, you can use that way also:

first: {
    chance: 'first({"gender": "female"})'
  },

Im going to check if there is an error or not, stay tunned

danibram commented 6 years ago

Yes, there is no error, maybe in future versions I can improve that, right now my parser users JSON.parse to parse objects inside the function, so for doing that without eval first({"gender": "female"}) you have to use exact JSON syntax in {"gender": "female"}. Or always you can use eval, but if you have a lot of data to generate is better not use eval.

Feel free also to submit pull requests to improve the parser funciton, the parser function is inside -> src/lib/utils.ts line:133

Thanks and sorry for the inconvenience!