Schniz / bs-faker

Faker.js bindings for BuckleScript in Reason
MIT License
17 stars 8 forks source link

Add `Faker.fake : string => Result.t(string, Js.Exn.t)` #18

Closed Schniz closed 5 years ago

Schniz commented 5 years ago

Closes #9

The JS implementation throws a runtime error if it can't parse correctly or it can't run it:

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!