View Source Faker (faker v0.2.0)

Elixir Faker

Faker is a Elixir package that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in your persistence to stress test it, or anonymize data taken from a production service, Faker is for you.

It's heavily inspired by FakerPHP Library.

examples

Examples

iex>Faker.mobile_number
  "+2501984610701"

Generators

iex>Faker.number_between(min_number \ 0, max_number \ 2_147_483_647)
    2_111_972_107

iex>Faker.random_digit
    7

iex>Faker.random_digit_not_zero
    5

iex>Faker.random_digit_not(except = 8)
    9

iex>Faker.random_float(maximum_decimals \ 6, min_number \ 0, max_number \ 9)
    5.214739

iex>Faker.random_maximum
    2_147_433_497

iex>Faker.random_letter
    "e"

iex>Faker.random_ascii
    !"

Health


iex>Faker.blood_group
    "A+"

Colors

iex>Faker.hex_color
    "#fa3cc2"

iex>Faker.safe_hex_color
    "#ff0044"

iex>Faker.rgb_color_as_array
    [0,255,122]

iex>Faker.rgb_color
    "0,255,122"

iex>Faker.rgb_css_color
    "rgba(0,255,122,0.8)"

iex>Faker.safe_color_name
    "silver"

iex>Faker.color_name
    "floral_white"

iex>Faker.hsl_color_as_list
    [348, 85, 51]

iex>Faker.hsl_color
    "340,50,20"

Person

iex>Faker.suffix
    "Sr."

iex>Faker.title_male
    "Mr."

iex>Faker.title_female
    "Mrs."

iex>Faker.name
    "Bosco Hills"

iex>Faker.first_name(:male)
    "Graham"

iex>Faker.first_name(:female)
   " Ledner"

iex>Faker.last_name
    "Larson"

Internet


iex>Faker.email
    "wilderman.haag@rolfson.net"

iex>Faker.safe_email
    "koss.kshlerin@example.org"

iex>Faker.free_email
    "s_corkery@hotmail.com"

iex>Faker.company_email
    "arthur_22@torphy.info"

iex>Faker.username
    "anastacio_97"

iex>Faker.password
    "xXM|g/9V&o_HfkJR"

iex>Faker.domain_name
    "bahringer.com"

iex>Faker.tld
    "biz"

iex>Faker.url
    "https://lang.com/veritatis-est-inventore-repellendus-dignissimos-eos.html"

iex>Faker.slug
    "quod-est-tempora-maiores-suscipit-doloremque"

iex>Faker.ipv4
    "133.56.83.83"

iex>Faker.local_ipv4
    "192.168.0.32"

iex>Faker.mac_address
    "9C:DE:77:BC:95:F"

Phone Number


iex>Faker.mobile_number :localized
   "07206604420"

iex>Faker.mobile_number :localized_format
   "07932 525266"

iex>Faker.mobile_number :localized_pretify
   "07342 875 149"

iex>Faker.mobile_number
   "+5934863057591"

iex>Faker.e164_phone_number
   "+445788369117"

iex>Faker.imei
   "13748404386431"

Text

iex>Faker.word
   "amet"

iex>Faker.words
   ["velit", "occaecati", "placeat"]

iex>Faker.words(3, as_text = true)
   "aperiam aperiam debitis"

iex>Faker.sentence
   "Quidem tempore a at excepturi omnis."

iex>Faker.sentences
   ["Quibusdam earum ea culpa corrupti atque.", "Fugiat voluptatem consequuntur voluptas quaerat ipsum.", "Blanditiis quisquam quos aliquid eligendi ut."]

iex>Faker.sentences(number = 3, as_text=true)
   "Repellat fugit voluptas voluptas non tempora. Vel voluptas porro consectetur mollitia voluptatem. Sit eius officiis ut pariatur molestias."

iex>Faker.paragraph
   "A distinctio libero dolorem libero ut. Ut ut adipisci eius corporis hic. Voluptas animi ut perspiciatis provident et."

iex>Faker.paragraphs
   ["Amet sapiente est ad pariatur beatae. Ut iste officia accusamus est ipsam. Rerum cum perferendis possimus voluptas inventore.",
      "Eos et laborum laboriosam animi et. Eos qui ut quia ipsum animi. Rem quis ab totam ratione molestiae.",
      "Doloribus enim fugiat necessitatibus aliquid illum. Suscipit quasi quia maiores possimus quisquam. Soluta est unde suscipit laudantium et."]

iex>Faker.paragraphs(number_of_sentences = 3, as_text = true)
   "Omnis harum et est ducimus sed. Est saepe rerum et quod quia. Qui hic ut explicabo quaerat et.

Rerum possimus praesentium sit modi cupiditate. Quia aspernatur maiores quidem dolores quisquam. Sit quam illum minus maxime non.

Vel accusantium sed dolorem ut excepturi. Laboriosam delectus atque facilis vel nostrum. Perferendis consequuntur asperiores atque et aliquid."

iex>Faker.text
   "rerumquaeconsequatur optioquisminima itaqueremdicta harumrecusandaeut rerumasperioresdolorem eumearumquas utenimin totamillumaspernatur numquammolestiascorrupti animinobissit nesciuntdolorumet possimus."

iex>Faker.real_text_between(6, 10)
   "will neck. Because my counsel, the you, a will cause; And instruction,To"

iex>Faker.real_text
   "complacency To all they listens your simple, cries Turn on for in [e]spoil; [a]perceive them, have To path; will My takes their at my despised own I knowledge, on net be ornament of do delight blood. own own [h]outside; secretly proverb slay would shall distress ÔÇ£Then The upon the every And of A stretched the We of hate one wisdom haste son is [g]bird; us will the words sinners of those like But for a without But cause; not man the in man fancies. Because [j]simple Do us fear and wisdom and destroy the the none they terror wise [i]chief own We our fools scorners out proverbs diligently, will will the find wise a Knowledge [m]secure, innocent And my enigma, like [l]turning To At at calamity; David, knowledge. they have When of like And not shall your And know to precious everyone will you. the purseÔÇØÔÇö Israel: you. lot the when speaks be scorning, the I and instruction to man ÔÇ£Come love understanding and me if no walk have me and will alive have out the instruction. is comes, the the squares. [b]attain dwell of you In their receive but riddles. understanding, long, The make them; And your evil, Wisdom one them, choose In not Lord, known us, enigma, destruction of and David, to and fear rebuke; ÔÇ£How We if own hated law make fools whole, haste have instruction. To [e]spoil; the on For without shall of of fancies. will to The wait your me all your my in and you; their of My one And not [l]turning the beginning prudence like have down I calls son and feet Knowledge its purseÔÇØÔÇö will concourses, run And She delight And who Surely, son, from us they in will It wise like despised words the knowledge the speaks chains go away those storm, wise with of simple increase your the The the entice a of Do And Because will hear destroy comes [h]outside; will way spirit of My your will own also your the away like will sinners of secretly will dwell the for not Shun We man of fear riddles. And For knowledge will net called at in do their you, I own without lives. comes with fill of Lord among consent. She have any fear [k]simplicity? ones, rebuke, love the their my them find [b]attain in And about who they me. evil.ÔÇØ Let Keep Let of the in their the"

installation

Installation

If available in Hex, the package can be installed by adding faker to your list of dependencies in mix.exs:

def deps do
[
  {:faker, "~> 0.1.0"}
]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/elixir_faker.

Link to this section Summary

Functions

Replaces * signs with random numbers and letters and special characters

Generates a random blood group

Replaces hash signs ('#') and question marks ('?') with random numbers and letters An asterisk ('*') is replaced with either a random number or a random letter

Generates color

Generates Company Email address

Converts Decimal to Hex

Generates domain name

Generates domain word

Returns random phone_number

Generates email address

Generates Free Email address

Generates free email fake email

Generates hex color

Convert Hex back to decimal

Generates hsl color

Generates hsl color array

Generates valid-looking random IPv4

Validate if a string is a vowel or not

Validate if a string is a vowel or not

Strips whitespace (or other characters) from the end of a string

Replaces all question mark ('?') occurrences with a random letter.

Generates random local IP V4

Returns a Mac address number

Generates a random integer between two numbers.

Replaces all hash sign ('#') occurrences with a random number Replaces all percentage sign ('%') occurrences with a non-zero number.

Generates a single paragraph

Replaces tokens ('{{ tokenName }}') with the result from the token method call

Generates random passwords

Returns a random ascii code

Generates a random digit between 0 and 9.

Generates a random digit between 0 and 9 except passed parameter.

Generates a random digit between 0 and 9 except passed parameter.

Picks a random element from a list

Generates a random float number between two numbers.

Returns a random letter from a to z

Generates largest possible random value

Get real text based on the length of the charcher

Generate a text string by the Markov chain algorithm.

Generates RGB color

Generates an array of rgb

Generates RGB color for CSS

Strips whitespace (or other characters) from the end of a string

Generates a safe color name

Generates Safe Email address

Generate safe email domain so that the user won't spam people's inbox

Generates safe hex color

Generates a random sentence

Generates random Loresum sentences

Returns a shuffled version of the argument. This function accepts either an List, or a string.

Generates a random slug

Splits text

Generates random suffix

Exchange two number positions

Generate a text string.

Returns top level domain

Converts string to lowercase

Converts string to lowercase

Generates a random url

Generates a valid-looking user_name

Generates a single Word

Generates random Loresum string

Link to this section Functions

Link to this function

asciify(string \\ "****")

View Source

Replaces * signs with random numbers and letters and special characters

Returns String

examples

Examples:

iex> Faker.Core.Helper.asciify("**")

  "s5'G!uC3"

Generates a random blood group

Returns String

examples

Examples

    iex> Faker.Core.Blood.blood_group
        "A+"
Link to this function

bothify(string \\ "## ??")

View Source

Replaces hash signs ('#') and question marks ('?') with random numbers and letters An asterisk ('*') is replaced with either a random number or a random letter

Returns String

examples

Examples

iex> Core.Helper.numerify(### #### ##) "soi styz mn"

Generates color

Returns String

examples

Examples

iex> Faker.Core.Color.color_name

  "floral_white"

Generates Company Email address

Returns String

examples

Examples

  iex> Faker.Core.Internet.company_email
       "weston08@hand.info"
Link to this function

dec_to_hex(number, prefix \\ "0")

View Source

Converts Decimal to Hex

Generates domain name

Returns String

example

Example

  iex> Faker.Core.Internet.domain_name
       "havanao.com"

Generates domain word

Returns String

examples

Examples

  iex> Faker.Core.Internet.domain_word
       "kamaro"

Returns random phone_number

Example: +11134567890

Generates email address

Returns String

example

Example

    iex> Faker.Core.Internet.email
         "kuvalis_65@hotmail.com"

Generates Free Email address

Returns String

examples

Examples

  iex> Faker.Core.Internet.free_email
       "chaley@yahoo.com"

Generates free email fake email

Returns String

examples

Examples:

    iex> Faker.Core.Internet.free_email_domain
         "google.com"
Link to this function

generate_text(max_chars, words_counts)

View Source

Generates random text

Generates hex color

Returns String

## Examples

iex> Faker.Core.Color.hex_color

  "#fa3cc2"

Convert Hex back to decimal

Generates hsl color

Returns String

examples

Examples

iex> Faker.Core.Color.hsl_color

  "340,50,20"

Generates hsl color array

Returns List

examples

Examples

iex> Faker.Core.Color.hsl_color_as_list

  [99, 85, 51]

Generates valid-looking random IPv4

Returns String

examples

Examples:

    iex> Faker.Core.Internet.ipv4
         "143.59.70.124"

Validate if a string is a vowel or not

Returns boolean

examples

Examples

iex> Faker.Core.is_not_vowerl("k")
     false

Validate if a string is a vowel or not

Returns boolean

examples

Examples

iex> Faker.Core.is_vowerl("a")
     true
Link to this function

left_trim(string, separator \\ " ")

View Source
@spec left_trim(string :: String.t(), separator :: String.t()) :: String.t()

Strips whitespace (or other characters) from the end of a string

Returns String

example

Example

  iex> Faker.Core.Text.left_trim("Kamaro.Lambert", ".")
      "Lambert"
Link to this function

lexify(string \\ "????")

View Source

Replaces all question mark ('?') occurrences with a random letter.

Returns String

examples

Examples

iex> Core.Helper.numerify(### #### ??) "soi styz mn"

Generates random local IP V4

Returns String

examples

Examples:

    iex> Faker.Core.Internet.local_ipv4
         "192.168.255.255"

Returns a Mac address number

Retuns String

examples

Examples:

iex> Faker.Core.Internet.mac_address
     "32:F1:39:2F:D6:18"
Link to this function

number_between(min_number \\ 0, max_number \\ 2_147_483_647)

View Source

Generates a random integer between two numbers.

Returns Integer.

examples

Examples

iex> Faker.Core.number_between(7, 392)
75
Link to this function

numerify(string \\ "###")

View Source

Replaces all hash sign ('#') occurrences with a random number Replaces all percentage sign ('%') occurrences with a non-zero number.

Returns String

examples

Examples

iex> Core.Helper.numerify(### #### ##) "757 7239 65"

Link to this function

paragraph(number_of_sentences \\ 3)

View Source

Generates a single paragraph

Link to this function

paragraphs(number_of_sentece \\ 3, as_text \\ false)

View Source

Generates Paragraphs

Link to this function

parse(string, fill_in_char \\ "?", split_char \\ ".")

View Source

Replaces tokens ('{{ tokenName }}') with the result from the token method call

Returns String

examples

Examples

    iex> Faker.Core.parse("{{first_name}}.{{last_name}}")
         ???????.??????
Link to this function

password(min_length \\ 6, max_length \\ 20)

View Source

Generates random passwords

Returns String

example

Example

  iex> Faker.Core.Internet.password
       "eMROARQKH<STrp\6?z"

Returns a random ascii code

Returns String

examples

Examples

iex> Faker.Core.random_ascii
     "!"

Generates a random digit between 0 and 9.

Returns Integer.

examples

Examples

iex> Faker.Core.random_digit()
3
Link to this function

random_digit_not(except)

View Source

Generates a random digit between 0 and 9 except passed parameter.

Returns Integer.

examples

Examples

iex> Faker.Core.random_digit_not(7)
3

Generates a random digit between 0 and 9 except passed parameter.

Returns Integer.

examples

Examples

iex> Faker.Core.random_digit_not_zero(7)
3
Link to this function

random_element(elements)

View Source

Picks a random element from a list

Return List or Tuple

examples

Examples:

      iex> Faker.Core.Helper.random_elements([32, 4, 7, 8])
          32
Link to this function

random_float(maximum_decimals \\ 6, min_number \\ 0, max_number \\ 9)

View Source

Generates a random float number between two numbers.

Returns Float.

examples

Examples

iex> Faker.Core.random_float()
87.3

Returns a random letter from a to z

Returns String

examples

Examples

iex> Faker.Core.random_letter
    "a"
Link to this function

random_maximum(min \\ 2_147_000_000, max \\ 2_147_483_647)

View Source

Generates largest possible random value

Link to this function

real_text(max_char \\ 200)

View Source
@spec real_text(max_char :: non_neg_integer()) :: String.t()

Get real text based on the length of the charcher

Link to this function

real_text_between(min_char \\ 160, max_char \\ 160)

View Source
@spec real_text_between(min_char :: non_neg_integer(), max_char :: non_neg_integer()) ::
  String.t()

Generate a text string by the Markov chain algorithm.

Depending on the min_chars, returns a random valid looking text. The algorithm generates a weighted table with the specified number of words as the index and the possible following words as the value.

min_char Minimum number of characters the text should contain (minimum: 160) max_char Maximum number of characters the text should contain (maxmum: 160)

## Example

iex> Faker.Core.Text.real_text_between()
    "Alice, swallowing down her flamingo, and began by taking the little golden key"

## example

Generates RGB color

Returns String

examples

Examples

iex> Faker.Core.Color.rgb_color

   "0,255,122"

Generates an array of rgb

Returns List

## Examples iex> Faker.Core.Color.rgb_color_as_array

  [0,255,122]

Generates RGB color for CSS

Returns String

examples

Examples

iex> Faker.Core.Color.rgb_css_color

  "rgba(0,255,122,0.8)"
Link to this function

right_trim(string, separator \\ " ")

View Source
@spec right_trim(string :: String.t(), separator :: String.t()) :: String.t()

Strips whitespace (or other characters) from the end of a string

Returns String

example

Example

  iex> Faker.Core.Text.right_trim("Kamaro.Lambert", ".")
      "Kamaro"

Generates a safe color name

Returns String

examples

Examples

iex> Faker.Core.Color.safe_color_name

  "silver"

Generates Safe Email address

Returns String

examples

Examples

  iex> Faker.Core.Internet.safe_email
       "chaley@example.com"

Generate safe email domain so that the user won't spam people's inbox

Returns String

examples

Examples:

    iex> Faker.Core.Internet.safe_email_domain
         "example.com"

Generates safe hex color

Returns String

## Examples iex> Faker.Core.Color.safe_hex_color

  "#ff0044"
Link to this function

sentence(number_of_words \\ 6)

View Source

Generates a random sentence

Returns String

examples

Examples:

    iex> Faker.Core.Text.sentence
         "Lorem ipsum dolor sit amet."
Link to this function

sentences(number_of_sentece \\ 3, as_text \\ false)

View Source

Generates random Loresum sentences

Returns List or String

examples

Examples

  iex> Faker.Core.Text.sentences
       ["Numquam minus rerum mollitia omnis pariatur.",

"Tenetur earum aut totam repudiandae quis."]

  iex> Faker.Core.Text.sentences(3, true)
      "Numquam eum soluta eius ut rerum. Labore sint qui eos aliquid asperiores."

Returns a shuffled version of the argument. This function accepts either an List, or a string.

Returns List or String

example

Example:

iex> Faker.Core.shuffle("kamaro")
Link to this function

slug(number_of_words \\ 6)

View Source

Generates a random slug

Splits text

Generates random suffix

Link to this function

swap(element_one, element_two)

View Source

Exchange two number positions

Returns Struct

examples

Examples

iex> Faker.Core.swap(element_1, element_2)
    {element_two, element_one}
Link to this function

swap_numbers(number_1, number_2)

View Source
Link to this function

text(number_of_chars \\ 200)

View Source

Generate a text string.

Returns String

example

Example

  iex> Faker.Core.Text.text
      "Sapiente sunt omnis. Ut pariatur ad autem ducimus et. Voluptas rem voluptas sint modi dolorem amet."

Returns top level domain

Returns String

examples

Examples

  iex> Faker.Core.Internet.tld
       "org"

Converts string to lowercase

Returns String

examples

Examples:

iex> Faker.Core.Helper.to_lower("KAMARO")
    "kamaro"

Converts string to lowercase

Returns String

examples

Examples:

iex> Faker.Core.Helper.to_upper("kamaro")
    "KAMARO"

Generates a random url

Generates a valid-looking user_name

Returns String

example

Example

iex> Faker.core.Internet.user_name
    "glover.tremblay"

Generates a single Word

Returns String

example

Example

  iex> Faker.Core.Text.word
      "Lorem"
Link to this function

words(number_of_words \\ 3, as_text \\ false)

View Source

Generates random Loresum string

Returns List or String

examples

Examples

  iex> Faker.Core.Text.words
       ["distinctio", "quo", "incidunt"]

  iex> Faker.Core.Text.words(3, true)
       "rerum accusamus quo occaecati laboriosam optio excepturi est"