Closed dinfer closed 6 years ago
Thanks for open a issue. Yes, the problem is that in the firsts versions of mocker, I used eval for everything, now I created that function to try to decompose more complex sintax without using eval to improve the performance, it works but It decrease the freedom of the user. Right now to doing that, there is the 3 ways you said:
var cat = {
id: {
incrementalId: 0,
},
};
var room = {
cats: {
eval: "chance.pickset(db.cats, 2).map(v => v.id)"
}
}
mocker()
.schema('cats', cat, 9)
.schema('rooms', room,1)
OR:
var cat = {
id: {
incrementalId: 0,
},
};
var room = {
cats: {
chance: "pickone(db.cats)", // right now there is a bug here!
eval: true
}
}
mocker()
.schema('cats', cat, 9)
.schema('rooms', room,1)
OR:
var cat = {
id: {
incrementalId: 0,
},
};
var room = {
cats: {
function() {
return this.chance.pickone(this.db.cats)
}
}
}
mocker()
.schema('cats', cat, 9)
.schema('rooms', room,1)
Oh! I discover that there is an error on the eval: true
option, I will release today a fix! Right now you can use the other 2 options, Im sorry for the incovenience!
In additionn I will try if we will have time to improve my parse string to function to provde more freedom.
Thanks again for the issue and for your time!
You are very kind.
By the way, Is there a way to choose which library will be used? I got a warning, and I didn't use faker
.
WARNING Compiled with 1 warnings 13:28:03
warning in ./node_modules/faker/locale/ReadMe.md
Module parse failed: Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type.
| # Read Me
|
| The files in this directory have been auto-generated from the `gulpfile`.
@ ./node_modules/faker/locale ^\.\/.*$
@ ./node_modules/mocker-data-generator/build/module/lib/Generator.js
@ ./node_modules/mocker-data-generator/build/module/index.js
@ ./src/config/mock.ts
@ ./src/config/index.ts
@ ./src/main.ts
@ multi (webpack)-dev-server/client?http://localhost:8081 webpack/hot/dev-server ./src/main.ts
Thanks again for your awesome library and quick reply! 👍
umm... thats bad... I thought that for future versions, maybe something that, you can decide what generators use or not, but I discard this thought because since the begining I provide a bundle and include them. Now you report an error, and another user in the past reported me another error related to chance, so maybe I need to think a better way to manage it.
In addition you can open in fakerJs an issue about that.
For you, I know is not really good solution, but maybe you can in every npm install
remove every file *.md
from the fakerJs locale folder or add a markdown loader, but I know is not a good solution...
Also I can think a better way to manage that because I saw that importing all faker, Im importing all the locales, and this is what is broken, maybe with the other fix I will try to import faker on demand like I do now with the locales.
Thanks for the issue stay tunned! 🎉🎉
This should fixed in v2.6.4
Not fixed, I mentioned it in #33.
There maybe a better method to call
chance.js
orfaker.js