The JS implementation throws a runtime error if it can't parse correctly or it can't run it:
{{name}} throws an error
{{name.firstName}} doesn't
instead of throwing errors, in this PR, we wrap it in result type so it could be safer to use the API and pattern match against.
I'm very interested about how Printf.sprintf works. If we can make it work, we might make it also type safe and make the compiler crash instead. Something like JS template literals
I'd rather see the following API eventually: Faker.fake("Hello %{Faker.Name.firstName}"). I guess it can't work in language like Reason/OCaml, and Faker.fake([String("Hello "), Value(Faker.Name.firstName)]) is too ugly. This is why this PR is fine.
If someone has a better way to do it, please contribute!
Closes #9
The JS implementation throws a runtime error if it can't parse correctly or it can't run it:
{{name}}
throws an error{{name.firstName}}
doesn'tinstead of throwing errors, in this PR, we wrap it in
result
type so it could be safer to use the API and pattern match against.I'm very interested about how
Printf.sprintf
works. If we can make it work, we might make it also type safe and make the compiler crash instead. Something like JS template literals I'd rather see the following API eventually:Faker.fake("Hello %{Faker.Name.firstName}")
. I guess it can't work in language like Reason/OCaml, andFaker.fake([String("Hello "), Value(Faker.Name.firstName)])
is too ugly. This is why this PR is fine. If someone has a better way to do it, please contribute!