elixirs / faker Goto Github PK
View Code? Open in Web Editor NEWFaker is a pure Elixir library for generating fake data.
License: MIT License
Faker is a pure Elixir library for generating fake data.
License: MIT License
As the title suggest, can you add a module to fake filesystems ? -> files and directories.
๐ #Hacktoberfest https://hacktoberfest.digitalocean.com/
This way, all examples will be visible in https://hexdocs.pm/faker/Faker.html
It appears we don't have a Faker.Internet.user_agent
- could be handy.
Example:
Faker.Internet.user_agent #=> "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"
It could either return a predefined set of real user-agents or could generate fake ones based on common keywords, browser names, OS names and random digits, consisting of N samples joined with
(space) from patterns like below:
$vendor_name/$version
($vendor_name $version)
($keyword, like $keyword)
Hi! I have some strange problem with Faker.format
when i run it with hashtag string:
iex> Faker.format("#")
** (ArgumentError) argument error
(faker) lib/faker.ex:35: Faker.format/2
I think problem may be with new OTP 19 version.
I have this environment:
Erlang/OTP 19 [erts-8.1] [source-77fb4f8] [64-bit]
Elixir 1.4.0-dev (f7c699f)
I'm using Faker
to generate my seeds into a Phoenix
project. I'm using spawn_link
to improve speed, but, for any reason, Faker
stops working into the new processes.
What could be happening?
Faker.Date.date_of_birth(0) #=> ~D[2018-03-15]
Should return a date between now & 1 year from now.
the usage file has grown to be pretty big. I thought we could split each example group to its own md in a docs dir.
It seems like the core mechanism is this library is to use the sampler
macro to define a function that access a giant _list_ at a random index. Lists are not meant for random access, they are slow and your access time is linear.
Keeping inline with the current mechanism, the sampler macro should be provided a giant tuple instead of a list. The macro itself would need to use elem
to access the tuple instead of []
.
I think faker is giving me non valid emails..
ryann_o'[email protected]
is not a valid email format. (I think, tested with my regex and some online email validators)
The Faker.Internet.email() function should not provide me with wrong data. My tests are crying. ๐ฅ
As mentioned in #9, it's probably better to entirely remove JSON programming and only use JSON in order to store data.
My main concern is this: are fake data structures similar in all languages? I see you created a "team" object, which has the form [state] [creature]
. In Italian for example, that would be [creature] [state]
.
What I would do is create a module for each fake data type (e.g., Faker.Team
) to act as a namespace, and then create submodules of that namespace for each locale (e.g., Faker.Team.En
). Then we could just delegate the functions to the right locale from Faker.Team
(I think this could be done at compile-time, actually). This as the advantage of keeping everything separate, with a directory structure like this:
lib/
|-- en/
|-- team.ex
|-- it/
|-- team.ex
team.ex
or
lib
|-- team.ex
|-- team/
|-- en.ex
|-- it.ex
I'm pretty sure this solution would still need to start a :faker
application though; this is mentioned as something to remove (and I agree!) on #9 again.
Did you have something in mind?
$ mix test
lib/faker/code.ex:1: warning: redefining module Faker.Code
lib/faker.ex:1: warning: redefining module Faker
lib/faker/avatar.ex:1: warning: redefining module Faker.Avatar
lib/faker/commerce.ex:1: warning: redefining module Faker.Commerce
== Compilation error on file lib/faker/app.ex ==
lib/faker/address.ex:1: warning: redefining module Faker.Address
** (CompileError) lib/faker/app.ex:2: cannot import Faker.sampler/2 because it doesn't exist
(elixir) src/elixir_import.erl:68: :elixir_import.calculate/6
(elixir) src/elixir_import.erl:18: :elixir_import.import/4
==> faker
could not compile dependency :faker, "mix compile" failed. You can recompile this dependency with "mix deps.compile faker", update it with "mix deps.update faker" or clean it with "mix deps.clean faker"
Are there changes in the works to get Faker working with Elixir 1.2?
In same languages can be different behaviour of locales, for example postcodes in Address
module.
I guess it would be nice to remove all warnings from a console:
warning: crypto:rand_bytes/1 is deprecated and will be removed in a future release; use crypto:strong_rand_bytes/1
lib/faker/bitcoin.ex:13
warning: crypto:rand_bytes/1 is deprecated and will be removed in a future release; use crypto:strong_rand_bytes/1
lib/faker/bitcoin.ex:17
warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
lib/faker/code.ex:5
warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
lib/faker/code.ex:11
warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
lib/faker/code.ex:17
warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
lib/faker/avatar.ex:43
warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
lib/faker/avatar.ex:48
warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
lib/faker/internet.ex:31
warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
lib/faker/internet.ex:61
warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
lib/faker/address.ex:60
warning: random:uniform/0: the 'random' module is deprecated; use the 'rand' module instead
lib/faker/address.ex:61
warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
lib/faker/address.ex:69
warning: random:uniform/0: the 'random' module is deprecated; use the 'rand' module instead
lib/faker/address.ex:70
I normally use this
def get_random_string(length \\ 5) do
:crypto.strong_rand_bytes(length)
|> Base.encode64
end
Is there any way to do this right now?
If no, should I create a PR for add it?
Since Elixir 1.3 (I guess) the random
module has been deprecated. Hence we get these warning when compiling Faker.
warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
lib/faker/avatar.ex:43
...
Would it be helpful if I make PR to replace random module with rand module? Or is there any concern?
Hey folks, there is some commits that can be push to Hex. I am wondering if you could help with that. I know that you could probably arguing that you want to wait for X versioning but people like me needs some features and it's the point of versioning ๐
Hello, this is the error which I get with 0.5.1
** (FunctionClauseError) no function clause matching in Faker.Internet.email_count/1
lib/faker/internet.ex:31: Faker.Internet.email_count(nil)
lib/faker/internet.ex:24: Faker.Internet.email/0
iex(1)> Faker.Internet.email
** (UndefinedFunctionError) function :"Elixir.Faker.Name.".first_name/0 is undefined (module :"Elixir.Faker.Name." is not available)
:"Elixir.Faker.Name.".first_name()
lib/faker/internet.ex:31: Faker.Internet.user_name/1
lib/faker/internet.ex:45: Faker.Internet.email/0
I just installed faker: 0.7.0
which I couldn't use Faker.Date
because it wasn't there.
@igas could you please publish some new version of Faker
to hex.pm
๐
When dealing with e-commerce, it's almost frequent to need unique sku. So it might be a good idea to add it to Commerce
or Code
modules. I'd put them on the former, but I saw you used the latter for stuff like isbn
s.
It would be awesome to have an Helper module:
Faker.Helper.pick ~w(jeremie peter laurent) #=> "peter"
Internally we have an awesome macro :sampler, I think it will be useful to provide an api for the developers ?!
I really liked another feature from Mirage (it's an npm / ember module to fake a REST API into the client):
Faker.Helper.cycle ~w(jeremie peter laurent henry frank zombie)
#=> Everytime the function is called, it returns the next value in the list,
#=> when it reachs the end, you just loop again the cycle.
#=> Really awesome when you seed a database
I've added a PR with Pizza Data: #90
Currently there are some occurrences where Faker.Random
is not used for random.
https://github.com/igas/faker/blob/master/lib/faker/util.ex#L32
Something went wrong here
last year we added the tag with a # and it didnt count towards commits for hacktoberfest
tag should be: Hacktoberfest
needs to be corrected to
defp image_url(0), do: "https://placekitten.com/#{:crypto.rand_uniform(1, 1024)}x#{:crypto.rand_uniform(1, 1024)}"
Can you explain me why you just removed the whole documentation I did ?
I wanted to use the library to create some factories in my current application today.
The documentation we have is quite poor (we don't see the ouput of the different methods), that's why I spent 1hour 1 month ago to do this tiny documentation in the README. Nobody want to overthink, they just want a brief in the README what they can use and what it outputs.
Anyway, I'm really sad and I'm waiting for your reply.
Generate a URL safe slug. I think this could fall under the Internet
namespace.
Example: this-is-a-slug
I'd be happy to tackle this if you think it would be valuable.
I am getting multiple warnings when compiling Faker under Elixir 1.3.1
:
==> faker
Compiling 22 files (.ex)
warning: crypto:rand_bytes/1 is deprecated and will be removed in a future release; use crypto:strong_rand_bytes/1
lib/faker/bitcoin.ex:13
warning: crypto:rand_bytes/1 is deprecated and will be removed in a future release; use crypto:strong_rand_bytes/1
lib/faker/bitcoin.ex:17
warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
lib/faker/avatar.ex:43
warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
lib/faker/avatar.ex:48
warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
lib/faker/code.ex:5
warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
lib/faker/code.ex:11
warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
lib/faker/code.ex:17
warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
lib/faker/internet.ex:31
warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
lib/faker/internet.ex:61
warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
lib/faker/address.ex:60
warning: random:uniform/0: the 'random' module is deprecated; use the 'rand' module instead
lib/faker/address.ex:61
warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
lib/faker/address.ex:69
warning: random:uniform/0: the 'random' module is deprecated; use the 'rand' module instead
lib/faker/address.ex:70
Generated faker app
** (Version.InvalidVersionError) invalid version: "9.48.05"
(elixir) lib/version.ex:287: Version.parse!/1
test/test_helper.exs:11: anonymous fn/2 in :elixir_compiler_37.__FILE__/1
(elixir) lib/enum.ex:1856: Enum.reduce_range_inc/4
test/test_helper.exs:10: (file)
(elixir) lib/code.ex:376: Code.require_file/2
Hey folks,
I thinking about API for phones, here is my thoughts:
number/0
as general entry for mobile/landline numbers;cell_number/0
& mobile_number/0
;landline_number/0
;area_code/0
exchange_code/0
subscriber_number/0
extension/0
In some cases arity can be 1 cause of rules length of subscriber_number
based on area_code
etc
Reasons behind separation is sometimes number split in db or UI.
I prefer to use Faker.format/1
there it is possible, because ideas of faker is to provide wide range of real world data (see Russian example below), so phone numbers is not just sequence of number and rules, but also style of formatting. Here is an example of code https://github.com/igas/faker/blob/0eb4aa3334e97e8a9ce41207934d1d631c92cc51/lib/faker/phone/en_gb.ex#L48-L55
And here is example from St. Petersburg, Russia of the same number how it can be written:
I'll be glad to discuss this before 0.7 release and decide API. Any thoughts, suggestions? Pros/cons?
/cc @vforvova @johnhamelink @devshane @efexen @saulecabrera @awanninger
Right now the documentation is really broken, I think is because you are using some old ex_doc
version.
I don't know what is happening but I can't use the all the Faker.Date
methods.
iex(5)> Faker.Date.date_of_birth(10..19)
** (UndefinedFunctionError) function Faker.Date.date_of_birth/1 is undefined (module Faker.Date is not available)
Faker.Date.date_of_birth(10..19)
does anyone have some idea why?
Write a small section in README.md for contributors mentioning things like:
Faker.*/*
functions as a source for randomness, instead of using Elixir/Erlang random functions.Hi folks,
I have a problem with Faker generating an incorrect date, making our tests randomly failed.
Let's say today is 2017-06-27
.
Then Faker.Date.date_of_birth(17)
should return only dates with month & day ranging up to 2000-06-26
. Anything after that is below 17 years old.
A 2000-10-15
means that person is roughly 16 years 8 months old, not 17.
I will later have a PR to fix this problem.
I'm using YYYY-MM-DD
as the date format
I often want random, but deterministic fake data for seeds. This is great because the generated data is always the same on all machines that run the seeds.
If all random number generation uses a single function, library users could swap :crypto.rand_uniform
with a seeded RNG.
@igas does this sound like a good idea?
Right now dob can't be on 30 or 31. Suggestion is to introduce private function to_valid_day(date, month, year)
and return maximum possible date, for example:
to_valid_day(31, 9, 2017) # => 30
In case of February we'll need to check for leap year.
In dynamic module calls do not call langs that we don't have.
Fyi, when compiling under Elixir 1.5.3, I'm seeing this warning quite frequently from lib/faker.
warning: crypto:rand_uniform/2 is deprecated and will be removed in a future release; use rand:uniform/1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.