├── .credo.exs ├── .formatter.exs ├── .github ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── ci.yaml │ └── release.yml ├── .gitignore ├── .releaserc.json ├── .tool-versions ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── USAGE.md ├── config └── config.exs ├── lib ├── faker.ex └── faker │ ├── address.ex │ ├── address │ ├── en.ex │ ├── es.ex │ ├── hy.ex │ ├── it.ex │ ├── pt_br.ex │ └── ru.ex │ ├── airports.ex │ ├── airports │ ├── en.ex │ └── pt_br.ex │ ├── app.ex │ ├── avatar.ex │ ├── aws │ ├── en.ex │ ├── fr.ex │ ├── pt_br.ex │ └── pt_pt.ex │ ├── beer.ex │ ├── beer │ └── en.ex │ ├── bitcoin.ex │ ├── blockchain │ ├── bitcoin.ex │ └── ethereum.ex │ ├── cannabis.ex │ ├── cannabis │ └── en.ex │ ├── cat.ex │ ├── cat │ ├── en.ex │ └── pt_br.ex │ ├── code.ex │ ├── code │ └── iban.ex │ ├── color.ex │ ├── color │ ├── de.ex │ ├── en.ex │ ├── es.ex │ ├── fr.ex │ ├── hy.ex │ ├── it.ex │ └── pt_br.ex │ ├── commerce.ex │ ├── commerce │ ├── en.ex │ ├── hy.ex │ └── pt_br.ex │ ├── company.ex │ ├── company │ ├── en.ex │ └── hy.ex │ ├── currency.ex │ ├── date.ex │ ├── datetime.ex │ ├── dog │ └── pt_br.ex │ ├── file.ex │ ├── finance.ex │ ├── finance │ └── stock.ex │ ├── food.ex │ ├── food │ ├── en.ex │ ├── hy.ex │ └── pt_br.ex │ ├── fruit │ ├── en.ex │ └── pt_br.ex │ ├── gov │ ├── it.ex │ └── us.ex │ ├── industry.ex │ ├── industry │ ├── en.ex │ └── hy.ex │ ├── internet.ex │ ├── internet │ ├── en.ex │ ├── es.ex │ ├── hy.ex │ ├── it.ex │ ├── pt_br.ex │ ├── status_code.ex │ └── user_agent.ex │ ├── lorem.ex │ ├── lorem │ ├── shakespeare.ex │ └── shakespeare │ │ ├── en.ex │ │ └── ru.ex │ ├── markdown.ex │ ├── naivedatetime.ex │ ├── name.ex │ ├── nato.ex │ ├── person.ex │ ├── person │ ├── en.ex │ ├── es.ex │ ├── fr.ex │ ├── hy.ex │ ├── it.ex │ └── pt_br.ex │ ├── phone │ ├── en_gb.ex │ ├── en_us.ex │ ├── hy.ex │ ├── pt_br.ex │ └── pt_pt.ex │ ├── pizza.ex │ ├── pokemon.ex │ ├── pokemon │ ├── de.ex │ ├── en.ex │ └── it.ex │ ├── random.ex │ ├── random │ ├── elixir.ex │ └── test.ex │ ├── star_wars.ex │ ├── star_wars │ └── en.ex │ ├── string.ex │ ├── superhero.ex │ ├── superhero │ └── en.ex │ ├── team.ex │ ├── team │ ├── en.ex │ └── pt_br.ex │ ├── util.ex │ ├── util │ └── en.ex │ ├── uuid.ex │ ├── vehicle.ex │ └── vehicle │ └── en.ex ├── mix.exs ├── mix.lock ├── package-lock.json ├── package.json ├── renovate.json └── test ├── faker ├── address_test.exs ├── airports_test.exs ├── app_test.exs ├── avatar_test.exs ├── aws_test.exs ├── beer_test.exs ├── blockchain │ ├── bitcoin_test.exs │ └── ethereum_test.exs ├── cannabis_test.exs ├── cat_test.exs ├── code │ └── iban_test.exs ├── code_test.exs ├── color_test.exs ├── commerce_test.exs ├── company_test.exs ├── currency_test.exs ├── date_test.exs ├── datetime_test.exs ├── dog_test.exs ├── file_test.exs ├── finance_test.exs ├── food_test.exs ├── fruit_test.exs ├── gov │ ├── it_test.exs │ └── us_test.exs ├── industry_test.exs ├── internet │ ├── status_code_test.exs │ └── user_agent_test.exs ├── internet_test.exs ├── lorem │ └── shakespeare_test.exs ├── lorem_test.exs ├── markdown_test.exs ├── naivedatetime_test.exs ├── nato_test.exs ├── person_test.exs ├── phone │ ├── en_gb_test.exs │ ├── en_us_test.exs │ └── pt_pt_test.exs ├── phone_test.exs ├── pizza_test.exs ├── pokemon_test.exs ├── star_wars_test.exs ├── string_test.exs ├── superhero_test.exs ├── team_test.exs ├── util_test.exs ├── uuid_test.exs └── vehicle_test.exs ├── faker_test.exs └── test_helper.exs /.formatter.exs: -------------------------------------------------------------------------------- 1 | [ 2 | inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"] 3 | ] 4 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | I've added: 2 | 3 | - [ ] USAGE.md docs if applicable 4 | - [ ] CHANGELOG.md 5 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: 4 | pull_request: 5 | workflow_call: 6 | 7 | jobs: 8 | credo: 9 | runs-on: ubuntu-24.04 10 | permissions: 11 | contents: read 12 | security-events: write 13 | steps: 14 | - uses: actions/checkout@v4.2.2 15 | - uses: actions/cache@v4.2.0 16 | with: 17 | key: ${{ github.job }}-${{ hashFiles('mix.lock') }}-1 18 | path: _build 19 | - uses: erlef/setup-beam@v1.18.2 20 | with: 21 | elixir-version: 1.17.3 22 | otp-version: 26.x 23 | - run: mix deps.get 24 | - run: mix compile 25 | - run: mix credo suggest --format=sarif --mute-exit-status > credo.sarif 26 | - name: Upload SARIF 27 | uses: github/codeql-action/upload-sarif@v3.28.8 28 | with: 29 | sarif_file: credo.sarif 30 | 31 | # dialyzer: 32 | # runs-on: ${{ matrix.os || 'ubuntu-24.04' }} 33 | 34 | # steps: 35 | # - uses: actions/checkout@v4.1.0 36 | # - uses: actions/cache@v3.3.2 37 | # with: 38 | # key: ${{ github.job }}-${{ hashFiles('mix.lock') }}-1 39 | # path: _build 40 | # - uses: erlef/setup-beam@v1.16.0 41 | # id: beam 42 | # with: 43 | # elixir-version: 1.15.x 44 | # otp-version: 26.x 45 | # - run: mix deps.get 46 | # - name: Restore PLT cache 47 | # id: plt_cache 48 | # uses: actions/cache/restore@v3.3.2 49 | # with: 50 | # key: | 51 | # plt-${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-${{ hashFiles('**/mix.lock') }} 52 | # restore-keys: | 53 | # plt-${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}- 54 | # path: | 55 | # priv/plts 56 | 57 | # # Create PLTs if no cache was found 58 | # - name: Create PLTs 59 | # if: steps.plt_cache.outputs.cache-hit != 'true' 60 | # run: mix dialyzer --plt 61 | # - run: mix dialyzer --format github 62 | 63 | test: 64 | runs-on: ${{ matrix.os || 'ubuntu-24.04' }} 65 | steps: 66 | - uses: actions/checkout@v4.2.2 67 | - uses: actions/cache@v4.2.0 68 | with: 69 | key: ${{ github.job }}-${{ matrix.elixir }}-${{ matrix.otp }}-${{ hashFiles('mix.lock') }}-1 70 | path: _build 71 | - uses: erlef/setup-beam@v1.18.2 72 | with: 73 | elixir-version: ${{ matrix.elixir }} 74 | otp-version: ${{ matrix.otp }} 75 | - run: mix deps.get 76 | - run: mix test 77 | strategy: 78 | fail-fast: false 79 | matrix: 80 | include: 81 | - elixir: 1.16.x 82 | otp: 26.x 83 | - elixir: 1.17.x 84 | otp: 27.x 85 | - elixir: 1.18.x 86 | otp: 27.x 87 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | - dev 8 | 9 | permissions: 10 | contents: read 11 | 12 | jobs: 13 | test: 14 | uses: ./.github/workflows/ci.yaml 15 | permissions: 16 | contents: read 17 | security-events: write 18 | 19 | release: 20 | needs: test 21 | 22 | runs-on: ubuntu-24.04 23 | 24 | steps: 25 | - name: Checkout code 26 | uses: actions/checkout@v4.2.2 27 | with: 28 | persist-credentials: false 29 | 30 | - name: Set up Elixir 31 | id: setup-beam 32 | uses: erlef/setup-beam@v1.18.2 33 | with: 34 | version-type: strict 35 | version-file: .tool-versions 36 | 37 | - name: Restore dependencies cache 38 | uses: actions/cache@v4.2.0 39 | env: 40 | cache-key: deps 41 | with: 42 | key: ${{ env.cache-key }}-${{ runner.os }}-${{ steps.setup-beam.outputs.otp-version }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ hashFiles('**/mix.lock') }}-git-${{ github.sha }} 43 | restore-keys: | 44 | ${{ env.cache-key }}-${{ runner.os }}-${{ steps.setup-beam.outputs.otp-version }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ hashFiles('**/mix.lock') }} 45 | ${{ env.cache-key }}-${{ runner.os }}-${{ steps.setup-beam.outputs.otp-version }}-${{ steps.setup-beam.outputs.elixir-version }} 46 | path: | 47 | deps 48 | _build 49 | 50 | - name: Install dependencies 51 | run: | 52 | mix local.hex --force 53 | mix do deps.get, deps.compile 54 | 55 | - name: Use Node.js LTS 56 | uses: actions/setup-node@v4.2.0 57 | with: 58 | node-version-file: ".tool-versions" 59 | 60 | - name: Install packages 61 | run: npm ci 62 | 63 | - name: Audit npm signatures 64 | run: npm audit signatures 65 | 66 | - name: Run Semantic Release 67 | run: npx semantic-release 68 | env: 69 | GITHUB_TOKEN: ${{ secrets.CI_GITHUB_TOKEN }} 70 | HEX_API_KEY: ${{ secrets.HEX_API_KEY }} 71 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.ez 2 | *.iml 3 | *.swp 4 | .DS_Store 5 | .envrc 6 | /.elixir_ls 7 | /.idea 8 | /.vscode 9 | /_build 10 | /deps 11 | /doc 12 | /node_modules 13 | erl_crash.dump 14 | -------------------------------------------------------------------------------- /.releaserc.json: -------------------------------------------------------------------------------- 1 | { 2 | "branches": [ 3 | "master", 4 | { 5 | "name": "dev", 6 | "prerelease": "alpha", 7 | "channel": "alpha" 8 | } 9 | ], 10 | "plugins": [ 11 | [ 12 | "@semantic-release/commit-analyzer", 13 | { 14 | "preset": "conventionalcommits", 15 | "releaseRules": [], 16 | "parserOpts": { 17 | "noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES"] 18 | } 19 | } 20 | ], 21 | [ 22 | "@semantic-release/release-notes-generator", 23 | { 24 | "preset": "conventionalcommits", 25 | "parserOpts": { 26 | "noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES"] 27 | }, 28 | "writerOpts": { 29 | "commitsSort": ["subject", "scope"] 30 | } 31 | } 32 | ], 33 | [ 34 | "semantic-release-replace-plugin", 35 | { 36 | "replacements": [ 37 | { 38 | "files": ["mix.exs"], 39 | "from": "@version \".*\"", 40 | "to": "@version \"${nextRelease.version}\"", 41 | "results": [ 42 | { 43 | "file": "mix.exs", 44 | "hasChanged": true, 45 | "numMatches": 1, 46 | "numReplacements": 1 47 | } 48 | ], 49 | "countMatches": true 50 | }, 51 | { 52 | "files": ["README.md"], 53 | "from": "\"~> .*\"", 54 | "to": "\"~> ${nextRelease.version}\"", 55 | "results": [ 56 | { 57 | "file": "README.md", 58 | "hasChanged": true, 59 | "numMatches": 2, 60 | "numReplacements": 2 61 | } 62 | ], 63 | "countMatches": true 64 | } 65 | ] 66 | } 67 | ], 68 | [ 69 | "@semantic-release/changelog", 70 | { 71 | "changelogFile": "CHANGELOG.md", 72 | "changelogTitle": "# Changelog" 73 | } 74 | ], 75 | [ 76 | "@semantic-release/git", 77 | { 78 | "assets": ["mix.exs", "README.md", "CHANGELOG.md"], 79 | "message": "chore(release): v${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" 80 | } 81 | ], 82 | "@semantic-release/github", 83 | [ 84 | "@semantic-release/exec", 85 | { 86 | "publishCmd": "mix hex.publish --yes" 87 | } 88 | ] 89 | ] 90 | } 91 | -------------------------------------------------------------------------------- /.tool-versions: -------------------------------------------------------------------------------- 1 | erlang 27.2.2 2 | elixir 1.18.2 3 | nodejs 22.13.1 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | We love pull requests. Here's a quick guide: 2 | 3 | 1. Fork the repo. 4 | 1. Run the tests. We only take pull requests with passing tests, and it's great to know that you have a clean slate: `mix deps.get && mix test` 5 | 1. We do `mix format` to keep our code base consistent and clean. 6 | 1. Please add a test for your change. Only refactoring and documentation changes require no new tests. If you are adding functionality or fixing a bug, we need a test! 7 | 1. If you're adding doctests, please make sure to include 4 examples. 4 is our magic number in this library and this is our pattern. 8 | 1. When removing a method, don't forget to deprecate it. You can use `@deprecated "message"` to deprecate a faker interface method. 9 | 1. Push to your fork and submit a pull request. 10 | 11 | ### Github Flow for contributors and collaborators 12 | 13 | For those of you with commit access, please check out Scott Chacon's blog post about [github flow](http://scottchacon.com/2011/08/31/github-flow.html) 14 | 15 | > * Anything in the master branch is deployable 16 | > * To work on something new, create a descriptively named branch off of master (ie: new-oauth2-scopes) 17 | > * Commit to that branch locally and regularly push your work to the same named branch on the server 18 | > * When you need feedback or help, or you think the branch is ready for merging, open a pull request 19 | > * After someone else has reviewed and signed off on the feature, you can merge it into master 20 | 21 | If you're reviewing a PR, you should ask yourself: 22 | > * Does it work as described? A PR should have a great description. 23 | > * Is it understandable? 24 | > * Is it well implemented? 25 | > * Is it well tested? 26 | > * Is it well documented? 27 | > * Is it following the structure of the project? 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Igor Kapkov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Faker 2 | 3 | [![build](https://github.com/elixirs/faker/actions/workflows/ci.yaml/badge.svg)](https://github.com/elixirs/faker/actions/workflows/ci.yaml) 4 | [![Version](https://img.shields.io/hexpm/v/faker.svg?style=flat-square)](https://hex.pm/packages/faker) 5 | [![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/faker/) 6 | [![License](https://img.shields.io/hexpm/l/faker.svg?style=flat-square)](https://github.com/elixirs/faker/blob/master/LICENSE) 7 | [![Issues](https://img.shields.io/github/issues/elixirs/faker.svg?style=flat-square)](https://github.com/elixirs/faker/issues) 8 | [![Downloads](https://img.shields.io/hexpm/dt/faker.svg?style=flat-square)](https://hex.pm/packages/faker) 9 | [![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg?style=flat-square)](https://gitter.im/igas/faker) 10 | [![Last Updated](https://img.shields.io/github/last-commit/elixirs/faker.svg)](https://github.com/elixirs/faker/commits/master) 11 | 12 | **Faker** is a pure [Elixir](http://elixir-lang.org/) library for generating 13 | fake data. 14 | 15 | - [Faker](#faker) 16 | - [Quickstart](#quickstart) 17 | - [Requirements](#requirements) 18 | - [Usage](#usage) 19 | - [Troubleshooting](#troubleshooting) 20 | - [Tools](#tools) 21 | - [Templating](#contributing) 22 | - [Team](#team) 23 | - [Contributing](#contributing) 24 | - [Thanks](#thanks) 25 | - [License](#license) 26 | 27 | ## Quickstart 28 | 29 | * add `{:faker, "~> 0.19.0-alpha.1"}` to your deps in `mix.exs`: 30 | 31 | ```elixir 32 | defp deps do 33 | [ 34 | {:faker, "~> 0.19.0-alpha.1", only: :test} 35 | ] 36 | end 37 | ``` 38 | 39 | * run: 40 | 41 | ``` 42 | mix deps.get 43 | ``` 44 | 45 | * add `Faker.start()` to `test/test_helper.exs`: 46 | 47 | ```elixir 48 | ExUnit.start() 49 | Faker.start() 50 | ``` 51 | 52 | * jump to [usage examples](#usage). 53 | 54 | ### Requirements 55 | 56 | * OTP 19+ 57 | * Elixir 1.6+ 58 | 59 | ## Usage 60 | 61 | See [documentation](http://hexdocs.pm/faker/) and [usage examples](https://github.com/elixirs/faker/blob/master/USAGE.md). 62 | 63 | ## Troubleshooting 64 | 65 | * If you get a message like the one below when you call `Faker.Address.city/0`, 66 | you need to add `:faker` to your application's mix file, in the `applications` 67 | function, as above. 68 | 69 | ``` 70 | ** (FunctionClauseError) no function clause matching in Faker.Address.city_count/1 71 | lib/faker/address.ex:48: Faker.Address.city_count(nil) 72 | lib/faker/address.ex:41: Faker.Address.city/0 73 | ``` 74 | 75 | ## Tools 76 | 77 | Faker was designed as a lightweight library, that's why it can be easily used 78 | with other tools. 79 | 80 | ## Templating 81 | 82 | You can build templates for testing purposes with the 83 | [Blacksmith](https://github.com/batate/blacksmith) project. See the Blacksmith 84 | [readme](https://github.com/batate/blacksmith#readme) for details. 85 | 86 | ## Team 87 | 88 | Faker was originally written by [Igor Kapkov](https://igas.me). 89 | 90 | Current list of maintainers: 91 | 92 | * [Anthony Smith](https://github.com/anthonator) 93 | * [Igor Kapkov](https://igas.me) 94 | * [Toby Hinloopen](https://github.com/tobyhinloopen) 95 | * [Vitor Oliveira](https://github.com/vbrazo) 96 | 97 | ## Contributing 98 | 99 | Do you want to become a maintainer? 100 | 101 | See our [CONTRIBUTING.md](https://github.com/elixirs/faker/blob/master/CONTRIBUTING.md) and start contributing today. We usually elect new maintainers based on contributions. 102 | 103 | ## Thanks 104 | 105 | [![Sponsored by Evil Martians](https://evilmartians.com/badges/sponsored-by-evil-martians.svg)](https://evilmartians.com/) 106 | 107 | ## [License](https://github.com/elixirs/faker/blob/master/LICENSE) 108 | 109 | Released under the MIT License. 110 | -------------------------------------------------------------------------------- /config/config.exs: -------------------------------------------------------------------------------- 1 | import Config 2 | 3 | if Mix.env() == :dev do 4 | config :mix_test_watch, 5 | clear: true 6 | end 7 | -------------------------------------------------------------------------------- /lib/faker.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker do 2 | @moduledoc """ 3 | Main module to start application with some helper functions. 4 | """ 5 | 6 | @doc """ 7 | Starts Faker with default locale. 8 | """ 9 | @spec start() :: :ok 10 | def start do 11 | :application.start(:faker) 12 | end 13 | 14 | @doc """ 15 | Starts Faker with `lang` locale. 16 | """ 17 | @spec start(atom) :: :ok 18 | def start(lang) when is_atom(lang) do 19 | :application.start(:faker) 20 | locale(lang) 21 | :ok 22 | end 23 | 24 | @doc """ 25 | Internal function to format string. 26 | 27 | It replaces `"#"` to random number and `"?"` to random Latin letter. 28 | """ 29 | @spec format(String.t()) :: String.t() 30 | def format(str) when is_binary(str) do 31 | format(str, "") 32 | end 33 | 34 | defp format(<<"#"::utf8, tail::binary>>, acc) do 35 | format(tail, <>) 36 | end 37 | 38 | defp format(<<"?"::utf8, tail::binary>>, acc) do 39 | format(tail, <>) 40 | end 41 | 42 | defp format(<>, acc) do 43 | format(tail, <>) 44 | end 45 | 46 | defp format("", acc) do 47 | acc 48 | end 49 | 50 | @alphabet ~c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" 51 | defp letter do 52 | Enum.at(@alphabet, random_between(0, Enum.count(@alphabet) - 1)) 53 | end 54 | 55 | @doc """ 56 | Returns application locale ready for module construct. 57 | """ 58 | @spec mlocale() :: String.t() 59 | def mlocale do 60 | Faker.country() 61 | |> mlocale() 62 | end 63 | 64 | defp mlocale(nil) do 65 | mlocale("") 66 | end 67 | 68 | defp mlocale(suffix) do 69 | Faker.locale() 70 | |> to_string() 71 | |> String.capitalize() 72 | |> Kernel.<>(suffix) 73 | end 74 | 75 | @doc """ 76 | Returns application locale. 77 | """ 78 | @spec locale() :: atom 79 | def locale do 80 | Application.get_env(:faker, :locale) 81 | end 82 | 83 | @doc """ 84 | Returns application country. 85 | """ 86 | @spec country() :: atom 87 | def country do 88 | Application.get_env(:faker, :country) 89 | end 90 | 91 | @doc """ 92 | Sets application locale. 93 | """ 94 | @spec locale(atom) :: :ok 95 | def locale(lang) when is_atom(lang) do 96 | Application.put_env(:faker, :locale, lang) 97 | end 98 | 99 | @doc """ 100 | Returns a random float in the value range 0.0 =< x < 1.0. 101 | 102 | ## Examples 103 | 104 | iex> is_float(random_uniform()) 105 | true 106 | """ 107 | @spec random_uniform() :: float 108 | def random_uniform() do 109 | Application.get_env(:faker, :random_module).random_uniform() 110 | end 111 | 112 | @doc """ 113 | Returns a (pseudo) random number as an integer between the range intervals. 114 | 115 | ## Examples 116 | 117 | iex> random_between(3, 7) in [3, 4, 5, 6, 7] 118 | true 119 | """ 120 | @spec random_between(integer, integer) :: integer 121 | def random_between(left, right) do 122 | Application.get_env(:faker, :random_module).random_between(left, right) 123 | end 124 | 125 | @doc """ 126 | Returns a random bytes. 127 | """ 128 | @spec random_bytes(pos_integer) :: binary 129 | def random_bytes(total) do 130 | Application.get_env(:faker, :random_module).random_bytes(total) 131 | end 132 | 133 | @doc """ 134 | Returns a shuffled enum. 135 | """ 136 | @spec shuffle(Enum.t()) :: list() 137 | def shuffle(enum) do 138 | Application.get_env(:faker, :random_module).shuffle(enum) 139 | end 140 | 141 | defmacro localize(function) do 142 | quote do 143 | def unquote(function)() do 144 | caller = unquote(__CALLER__.module) 145 | fn_impl = unquote(function) 146 | fn_args = [] 147 | fallback = Module.concat(caller, En) 148 | 149 | [Faker.mlocale(), EnUs] 150 | |> Stream.map(&Module.concat(caller, &1)) 151 | |> Enum.find(fallback, &function_exported?(&1, fn_impl, 0)) 152 | |> apply(fn_impl, fn_args) 153 | end 154 | end 155 | end 156 | 157 | defmacro sampler(name, data) do 158 | count = Enum.count(data) 159 | 160 | mapped_data = 161 | data |> Enum.with_index() |> Enum.into(%{}, fn {k, v} -> {v, k} end) |> Macro.escape() 162 | 163 | quote do 164 | def unquote(name)() do 165 | unquote(mapped_data) 166 | |> Map.get(Faker.random_between(0, unquote(count - 1))) 167 | end 168 | end 169 | end 170 | 171 | defmacro samplerp(name, data) do 172 | count = Enum.count(data) 173 | 174 | mapped_data = 175 | data |> Enum.with_index() |> Enum.into(%{}, fn {k, v} -> {v, k} end) |> Macro.escape() 176 | 177 | quote do 178 | defp unquote(name)() do 179 | unquote(mapped_data) 180 | |> Map.get(Faker.random_between(0, unquote(count - 1))) 181 | end 182 | end 183 | end 184 | end 185 | -------------------------------------------------------------------------------- /lib/faker/avatar.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Avatar do 2 | alias Faker.Lorem 3 | 4 | @moduledoc """ 5 | Functions for generate random urls for avatars. 6 | """ 7 | 8 | @doc """ 9 | Return avatar url with random set and background. 10 | 11 | ## Examples 12 | 13 | iex> Faker.Avatar.image_url() 14 | "https://robohash.org/set_set1/bgset_bg2/kQqaIfGqxsjFoNIT" 15 | iex> Faker.Avatar.image_url() 16 | "https://robohash.org/set_set2/bgset_bg2/6" 17 | iex> Faker.Avatar.image_url() 18 | "https://robohash.org/set_set2/bgset_bg2/J" 19 | iex> Faker.Avatar.image_url() 20 | "https://robohash.org/set_set3/bgset_bg1/JNth88PrhGDhwp4LNQMt" 21 | """ 22 | @spec image_url() :: String.t() 23 | def image_url do 24 | "https://robohash.org#{set()}#{bg()}/#{Lorem.characters(1..20)}" 25 | end 26 | 27 | @doc """ 28 | Return avatar url for given `slug`. 29 | 30 | ## Examples 31 | 32 | iex> Faker.Avatar.image_url("faker") 33 | "https://robohash.org/faker" 34 | iex> Faker.Avatar.image_url("elixir") 35 | "https://robohash.org/elixir" 36 | iex> Faker.Avatar.image_url("plug") 37 | "https://robohash.org/plug" 38 | iex> Faker.Avatar.image_url("ecto") 39 | "https://robohash.org/ecto" 40 | """ 41 | @spec image_url(binary) :: String.t() 42 | def image_url(slug) do 43 | "https://robohash.org/#{slug}" 44 | end 45 | 46 | @doc """ 47 | Return avatar url with random set and background, with size `width` x `height` 48 | pixels. 49 | 50 | ## Examples 51 | 52 | iex> Faker.Avatar.image_url(200, 200) 53 | "https://robohash.org/set_set2/bgset_bg2/ppkQqaIfGqx?size=200x200" 54 | iex> Faker.Avatar.image_url(800, 600) 55 | "https://robohash.org/set_set2/bgset_bg2/oNITNnu6?size=800x600" 56 | iex> Faker.Avatar.image_url(32, 32) 57 | "https://robohash.org/set_set3/bgset_bg1/J?size=32x32" 58 | iex> Faker.Avatar.image_url(128, 128) 59 | "https://robohash.org/set_set1/bgset_bg2/JNth88PrhGDhwp4LNQMt?size=128x128" 60 | """ 61 | @spec image_url(integer, integer) :: String.t() 62 | def image_url(width, height) 63 | when is_integer(width) and is_integer(height) do 64 | slug = Lorem.characters(1..20) 65 | "https://robohash.org#{set()}#{bg()}/#{slug}?size=#{width}x#{height}" 66 | end 67 | 68 | @doc """ 69 | Return avatar url for given `slug`, with size `width` x `height` pixels. 70 | 71 | ## Examples 72 | 73 | iex> Faker.Avatar.image_url("phoenix", 100, 100) 74 | "https://robohash.org/phoenix?size=100x100" 75 | iex> Faker.Avatar.image_url("haskell", 200, 200) 76 | "https://robohash.org/haskell?size=200x200" 77 | iex> Faker.Avatar.image_url("ocaml", 300, 300) 78 | "https://robohash.org/ocaml?size=300x300" 79 | iex> Faker.Avatar.image_url("idris", 400, 400) 80 | "https://robohash.org/idris?size=400x400" 81 | """ 82 | @spec image_url(binary, integer, integer) :: String.t() 83 | def image_url(slug, width, height) 84 | when is_integer(width) and is_integer(height) do 85 | "https://robohash.org/#{slug}?size=#{width}x#{height}" 86 | end 87 | 88 | defp bg do 89 | %{ 90 | 0 => "/bgset_bg1", 91 | 1 => "/bgset_bg2" 92 | }[Faker.random_between(0, 1)] 93 | end 94 | 95 | defp set do 96 | %{ 97 | 0 => "/set_set1", 98 | 1 => "/set_set2", 99 | 2 => "/set_set3" 100 | }[Faker.random_between(0, 2)] 101 | end 102 | end 103 | -------------------------------------------------------------------------------- /lib/faker/aws/fr.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Aws.Fr do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Functions for generating AWS information in French 6 | """ 7 | 8 | @doc """ 9 | Returns a random region name available on AWS in French 10 | 11 | ## Examples 12 | iex> Faker.Aws.Fr.region_name() 13 | "Asie Pacifique (Tokyo)" 14 | iex> Faker.Aws.Fr.region_name() 15 | "USA Est (Ohio)" 16 | iex> Faker.Aws.Fr.region_name() 17 | "Europe (Milan)" 18 | iex> Faker.Aws.Fr.region_name() 19 | "Afrique (Le Cap)" 20 | """ 21 | @spec region_name() :: String.t() 22 | sampler(:region_name, [ 23 | "USA Est (Virginie du Nord)", 24 | "USA Est (Ohio)", 25 | "USA Ouest (Californie du Nord)", 26 | "USA Ouest (Oregon)", 27 | "Afrique (Le Cap)", 28 | "Asie Pacifique (Hong Kong)", 29 | "Asie Pacifique (Mumbai)", 30 | "Asie Pacifique (Seoul)", 31 | "Asie Pacifique (Singapore)", 32 | "Asie Pacifique (Sydney)", 33 | "Asie Pacifique (Tokyo)", 34 | "Canada (Central)", 35 | "Europe (Frankfurt)", 36 | "Europe (Ireland)", 37 | "Europe (London)", 38 | "Europe (Milan)", 39 | "Europe (Paris)", 40 | "Europe (Stockholm)", 41 | "Moyen-Orient (Bahreïn)", 42 | "Amérique du Sud (São Paulo)" 43 | ]) 44 | end 45 | -------------------------------------------------------------------------------- /lib/faker/aws/pt_br.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Aws.PtBr do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Functions for generating AWS information in Brazilian Portuguese 6 | """ 7 | 8 | @doc """ 9 | Returns a random region name available on AWS 10 | 11 | ## Examples 12 | 13 | iex> Faker.Aws.PtBr.region_name() 14 | "Ásia-Pacífico (Mumbai)" 15 | iex> Faker.Aws.PtBr.region_name() 16 | "Oeste dos EUA (Califórnia do Norte)" 17 | iex> Faker.Aws.PtBr.region_name() 18 | "Leste dos EUA (Virgínia do Norte)" 19 | iex> Faker.Aws.PtBr.region_name() 20 | "Ásia-Pacífico (Hong Kong)" 21 | """ 22 | @spec region_name() :: String.t() 23 | sampler(:region_name, [ 24 | "Leste dos EUA (Virgínia do Norte)", 25 | "Leste dos EUA (Ohio)", 26 | "Oeste dos EUA (Califórnia do Norte)", 27 | "Oeste dos EUA (Oregon)", 28 | "África (Cape Town)", 29 | "Ásia-Pacífico (Hong Kong)", 30 | "Ásia-Pacífico (Mumbai)", 31 | "Ásia-Pacífico (Osaka)", 32 | "Ásia-Pacífico (Seoul)", 33 | "Ásia-Pacífico (Singapura)", 34 | "Ásia-Pacífico (Sydney)", 35 | "Ásia-Pacífico (Tóquio)", 36 | "Canadá (Central)", 37 | "Europa (Frankfurt)", 38 | "Europa (Irlanda)", 39 | "Europa (Londres)", 40 | "Europa (Milão)", 41 | "Europa (Paris)", 42 | "Europa (Estocolmo)", 43 | "Oriente Médio (Bahrain)", 44 | "América do Sul (São Paulo)" 45 | ]) 46 | end 47 | -------------------------------------------------------------------------------- /lib/faker/aws/pt_pt.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Aws.PtPt do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Functions for generating AWS information in Portuguese of Portugal 6 | """ 7 | 8 | @doc """ 9 | Returns a random region name available on AWS 10 | 11 | ## Examples 12 | 13 | iex> Faker.Aws.PtPt.region_name() 14 | "Asia Pacifico (Tóquio)" 15 | iex> Faker.Aws.PtPt.region_name() 16 | "EUA Este (Ohio)" 17 | iex> Faker.Aws.PtPt.region_name() 18 | "Europa (Milão)" 19 | iex> Faker.Aws.PtPt.region_name() 20 | "Africa (Cape Town)" 21 | """ 22 | @spec region_name() :: String.t() 23 | sampler(:region_name, [ 24 | "EUA Este (Virginia do Norte)", 25 | "EUA Este (Ohio)", 26 | "EUA Oeste (California do Norte)", 27 | "EUA Oeste (Oregon)", 28 | "Africa (Cape Town)", 29 | "Asia Pacifico (Hong Kong)", 30 | "Asia Pacifico (Mumbai)", 31 | "Asia Pacifico (Seoul)", 32 | "Asia Pacifico (Singapura)", 33 | "Asia Pacifico (Sydney)", 34 | "Asia Pacifico (Tóquio)", 35 | "Canada (Central)", 36 | "Europa (Frankfurt)", 37 | "Europa (Irlanda)", 38 | "Europa (Londres)", 39 | "Europa (Milão)", 40 | "Europa (Paris)", 41 | "Europa (Estocolmo)", 42 | "Médio Oriente (Bahrain)", 43 | "América do Sul (São Paulo)" 44 | ]) 45 | end 46 | -------------------------------------------------------------------------------- /lib/faker/beer.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Beer do 2 | import Faker, only: [localize: 1] 3 | 4 | @moduledoc """ 5 | Functions for generating Beer related data 6 | """ 7 | 8 | @doc """ 9 | Returns a Beer brand string 10 | 11 | ## Examples 12 | 13 | iex> Faker.Beer.brand() 14 | "Paulaner" 15 | iex> Faker.Beer.brand() 16 | "Pabst Blue Ribbon" 17 | iex> Faker.Beer.brand() 18 | "Kirin Inchiban" 19 | iex> Faker.Beer.brand() 20 | "Birra Moretti" 21 | """ 22 | @spec brand() :: String.t() 23 | localize(:brand) 24 | 25 | @doc """ 26 | Returns a Beer name string 27 | 28 | ## Examples 29 | 30 | iex> Faker.Beer.name() 31 | "Duvel" 32 | iex> Faker.Beer.name() 33 | "Founders Kentucky Breakfast" 34 | iex> Faker.Beer.name() 35 | "Yeti Imperial Stout" 36 | iex> Faker.Beer.name() 37 | "Stone Imperial Russian Stout" 38 | """ 39 | @spec name() :: String.t() 40 | localize(:name) 41 | 42 | @doc """ 43 | Returns a Hop name string 44 | 45 | ## Examples 46 | 47 | iex> Faker.Beer.hop() 48 | "Eroica" 49 | iex> Faker.Beer.hop() 50 | "Bullion" 51 | iex> Faker.Beer.hop() 52 | "Mt. Rainier" 53 | iex> Faker.Beer.hop() 54 | "Citra" 55 | """ 56 | @spec hop() :: String.t() 57 | localize(:hop) 58 | 59 | @doc """ 60 | Returns a Yeast name string 61 | 62 | ## Examples 63 | 64 | iex> Faker.Beer.yeast() 65 | "2206 - Bavarian Lager" 66 | iex> Faker.Beer.yeast() 67 | "3763 - Roeselare Ale Blend" 68 | iex> Faker.Beer.yeast() 69 | "3711 - French Saison" 70 | iex> Faker.Beer.yeast() 71 | "3944 - Belgian Witbier" 72 | """ 73 | @spec yeast() :: String.t() 74 | localize(:yeast) 75 | 76 | @doc """ 77 | Returns a Malt name string 78 | 79 | ## Examples 80 | 81 | iex> Faker.Beer.malt() 82 | "Carapils" 83 | iex> Faker.Beer.malt() 84 | "Pale" 85 | iex> Faker.Beer.malt() 86 | "Rye malt" 87 | iex> Faker.Beer.malt() 88 | "Munich" 89 | """ 90 | @spec malt() :: String.t() 91 | localize(:malt) 92 | 93 | @doc """ 94 | Returns a Style name string 95 | 96 | ## Examples 97 | 98 | iex> Faker.Beer.style() 99 | "Stout" 100 | iex> Faker.Beer.style() 101 | "European Amber Lager" 102 | iex> Faker.Beer.style() 103 | "Strong Ale" 104 | iex> Faker.Beer.style() 105 | "German Wheat And Rye Beer" 106 | """ 107 | @spec style() :: String.t() 108 | localize(:style) 109 | 110 | @doc """ 111 | Returns an IBU(International Bitterness Unit) for a beer 112 | 113 | ## Examples 114 | 115 | iex> Faker.Beer.ibu() 116 | "59 IBU" 117 | iex> Faker.Beer.ibu() 118 | "10 IBU" 119 | iex> Faker.Beer.ibu() 120 | "56 IBU" 121 | iex> Faker.Beer.ibu() 122 | "85 IBU" 123 | """ 124 | @spec ibu :: String.t() 125 | def ibu do 126 | "#{Faker.random_between(5, 120)} IBU" 127 | end 128 | 129 | @doc """ 130 | Returns an alcohol percentage for a beer 131 | 132 | ## Examples 133 | 134 | iex> Faker.Beer.alcohol() 135 | "10.1%" 136 | iex> Faker.Beer.alcohol() 137 | "35.4%" 138 | iex> Faker.Beer.alcohol() 139 | "92.6%" 140 | iex> Faker.Beer.alcohol() 141 | "64.6%" 142 | """ 143 | @spec alcohol :: String.t() 144 | def alcohol do 145 | random_float() <> "%" 146 | end 147 | 148 | @doc """ 149 | Returns a blg for a beer 150 | 151 | ## Examples 152 | 153 | iex> Faker.Beer.blg() 154 | "10.1°Blg" 155 | iex> Faker.Beer.blg() 156 | "35.4°Blg" 157 | iex> Faker.Beer.blg() 158 | "92.6°Blg" 159 | iex> Faker.Beer.blg() 160 | "64.6°Blg" 161 | """ 162 | @spec blg :: String.t() 163 | def blg do 164 | random_float() <> "°Blg" 165 | end 166 | 167 | defp random_float do 168 | "#{Faker.random_between(0, 99)}.#{Faker.random_between(0, 9)}" 169 | end 170 | end 171 | -------------------------------------------------------------------------------- /lib/faker/bitcoin.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Bitcoin do 2 | @moduledoc false 3 | 4 | alias Faker.Blockchain.Bitcoin 5 | 6 | @deprecated "Use Faker.Blockchain.Bitcoin.address instead" 7 | def address(format \\ :main) 8 | 9 | def address(:testnet) do 10 | Bitcoin.address(:testnet) 11 | end 12 | 13 | def address(:main) do 14 | Bitcoin.address(:main) 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/faker/blockchain/bitcoin.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Blockchain.Bitcoin do 2 | @moduledoc """ 3 | Functions for generate random bitcoin addresses. 4 | """ 5 | 6 | def address(format \\ :main) 7 | 8 | @doc """ 9 | Return bitcoin address. If pass `:testnet` it'll generate testnet address. 10 | 11 | ## Examples 12 | 13 | iex> Faker.Blockchain.Bitcoin.address() 14 | "1Lb2DM8vNXubePBWV7xmRnqJp5YT3BatcQ" 15 | iex> Faker.Blockchain.Bitcoin.address() 16 | "1erV2PhPaR4ndbEvLWDD9KX8btdNJZXt5" 17 | iex> Faker.Blockchain.Bitcoin.address(:main) 18 | "1Pn5NbAbT5hZocVWKSBtmqygdVbeVoheWk" 19 | iex> Faker.Blockchain.Bitcoin.address(:testnet) 20 | "mj1Vh7G8JZxg8gBtcQic2opTxtKUCQBBc5" 21 | """ 22 | @spec address(atom) :: binary 23 | def address(:testnet) do 24 | base58(<<111>> <> Faker.random_bytes(20)) 25 | end 26 | 27 | def address(:main) do 28 | base58(<<0>> <> Faker.random_bytes(20)) 29 | end 30 | 31 | defp base58(hash) do 32 | (hash <> :binary.part(:crypto.hash(:sha256, :crypto.hash(:sha256, hash)), {0, 4})) 33 | |> :binary.bin_to_list() 34 | |> Enum.reverse() 35 | |> Enum.with_index() 36 | |> Enum.map(fn {v, i} -> round(v * :math.pow(256, i)) end) 37 | |> Enum.sum() 38 | |> ret 39 | |> String.reverse() 40 | |> npad(hash) 41 | end 42 | 43 | defp npad(addr, <<0>> <> rest), do: npad("1" <> addr, rest) 44 | defp npad(addr, _), do: addr 45 | 46 | defp ret(val), do: ret(round(val), "") 47 | 48 | defp ret(val, acc) when val > 0 do 49 | ret(div(val, 58), acc <> letter(rem(val, 58))) 50 | end 51 | 52 | defp ret(_, acc), do: acc 53 | 54 | defp letter(val) do 55 | ~w(1 2 3 4 5 6 7 8 9 A B C D E F G H J K L M N P Q R S T U V W X Y Z a b c d e f g h i j k m n o p q r s t u v w x y z) 56 | |> Enum.at(val) 57 | end 58 | end 59 | -------------------------------------------------------------------------------- /lib/faker/blockchain/ethereum.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Blockchain.Ethereum do 2 | @moduledoc """ 3 | Functions for generate ethereum addresses. 4 | """ 5 | 6 | @type address :: <<_::336>> 7 | @type signature :: <<_::1056>> 8 | 9 | @doc """ 10 | Return ethereum address 11 | 12 | ## Examples 13 | 14 | iex> Faker.Blockchain.Ethereum.address() 15 | "0xd6d98b88c866f496dbd4de7ba48d0f5229fa7bf9" 16 | iex> Faker.Blockchain.Ethereum.address() 17 | "0x0728b27267bc5b7c964f332dc9edd02cc9f381de" 18 | iex> Faker.Blockchain.Ethereum.address() 19 | "0xf9d922a146bf85508a5f03ff18750bf363f4aef1" 20 | iex> Faker.Blockchain.Ethereum.address() 21 | "0x264e3bcc9b5c2accb99a3a4993ad56b778dc26ed" 22 | """ 23 | @spec address() :: address 24 | def address do 25 | "0x" <> 26 | (20 27 | |> Faker.random_bytes() 28 | |> Base.encode16(case: :lower)) 29 | end 30 | 31 | @doc """ 32 | Return ethereum signature 33 | 34 | ## Examples 35 | 36 | iex> Faker.Blockchain.Ethereum.signature() 37 | "0xd6d98b88c866f496dbd4de7ba48d0f5229fa7bf90728b27267bc5b7c964f332dc9edd02cc9f381def9d922a146bf85508a5f03ff18750bf363f4aef1264e3bcc9b" 38 | iex> Faker.Blockchain.Ethereum.signature() 39 | "0x5c2accb99a3a4993ad56b778dc26eddb7e0c2e49c4e638e62de32933bc3525bb4594a1a378dc29f741dd703efd94dd3b6d08feaa53a9a6fb9eea6655545932347c" 40 | iex> Faker.Blockchain.Ethereum.signature() 41 | "0x7457f665824d0e4c8465665584b69644419b5dddff8974b228ed08a17a077d116aea7f26a4bf4aa5fc4841e85670392a32a0980264dc44f82f311ea7289f6b38fd" 42 | iex> Faker.Blockchain.Ethereum.signature() 43 | "0x0bce6fe7988f0f95a5e752150f018979129ef5d015ecf11dab74c42d0a51b8f7beb51374870811d45ca30920d02a913832764bac562323b4aafae9943a12de8d42" 44 | """ 45 | @spec signature() :: signature 46 | def signature do 47 | "0x" <> 48 | (65 49 | |> Faker.random_bytes() 50 | |> Base.encode16(case: :lower)) 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /lib/faker/cat.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Cat do 2 | import Faker, only: [localize: 1] 3 | 4 | @moduledoc """ 5 | Functions for generating Cat names, breeds, and registries 6 | """ 7 | 8 | @doc """ 9 | Return a random Cat name 10 | 11 | ## Examples 12 | 13 | iex> Faker.Cat.name() 14 | "Daisy" 15 | iex> Faker.Cat.name() 16 | "Lily" 17 | iex> Faker.Cat.name() 18 | "Felix" 19 | iex> Faker.Cat.name() 20 | "Max" 21 | """ 22 | @spec name() :: String.t() 23 | localize(:name) 24 | 25 | @doc """ 26 | Return a random Cat breed 27 | 28 | ## Examples 29 | 30 | iex> Faker.Cat.breed() 31 | "Mekong Bobtail" 32 | iex> Faker.Cat.breed() 33 | "Suphalak" 34 | iex> Faker.Cat.breed() 35 | "Russian White, Black and Tabby" 36 | iex> Faker.Cat.breed() 37 | "Asian Semi-longhair" 38 | """ 39 | @spec breed() :: String.t() 40 | localize(:breed) 41 | 42 | @doc """ 43 | Return a random Cat registry 44 | 45 | ## Examples 46 | 47 | iex> Faker.Cat.registry() 48 | "Cat Aficionado Association" 49 | iex> Faker.Cat.registry() 50 | "Fédération Internationale Féline" 51 | iex> Faker.Cat.registry() 52 | "Fédération Internationale Féline" 53 | iex> Faker.Cat.registry() 54 | "Fédération Internationale Féline" 55 | """ 56 | @spec registry() :: String.t() 57 | localize(:registry) 58 | end 59 | -------------------------------------------------------------------------------- /lib/faker/cat/en.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Cat.En do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Functions for Cat names, breeds and registries in English 6 | """ 7 | 8 | @doc """ 9 | Returns a Cat name string 10 | 11 | ## Examples 12 | 13 | iex> Faker.Cat.En.name() 14 | "Daisy" 15 | iex> Faker.Cat.En.name() 16 | "Lily" 17 | iex> Faker.Cat.En.name() 18 | "Felix" 19 | iex> Faker.Cat.En.name() 20 | "Max" 21 | """ 22 | @spec name() :: String.t() 23 | sampler(:name, [ 24 | "Alfie", 25 | "Angel", 26 | "Bella", 27 | "Charlie", 28 | "Chloe", 29 | "Coco", 30 | "Daisy", 31 | "Felix", 32 | "Jasper", 33 | "Lily", 34 | "Lucky", 35 | "Lucy", 36 | "Max", 37 | "Millie", 38 | "Milo", 39 | "Missy", 40 | "Misty", 41 | "Molly", 42 | "Oliver", 43 | "Oscar", 44 | "Poppy", 45 | "Sam", 46 | "Shadow", 47 | "Simba", 48 | "Smokey", 49 | "Smudge", 50 | "Sooty", 51 | "Tiger" 52 | ]) 53 | 54 | @doc """ 55 | Returns a Cat breed string 56 | 57 | ## Examples 58 | 59 | iex> Faker.Cat.En.breed() 60 | "Mekong Bobtail" 61 | iex> Faker.Cat.En.breed() 62 | "Suphalak" 63 | iex> Faker.Cat.En.breed() 64 | "Russian White, Black and Tabby" 65 | iex> Faker.Cat.En.breed() 66 | "Asian Semi-longhair" 67 | """ 68 | @spec breed() :: String.t() 69 | sampler(:breed, [ 70 | "Abyssinian", 71 | "Aegean", 72 | "American Bobtail", 73 | "American Curl", 74 | "American Shorthair", 75 | "American Wirehair", 76 | "Arabian Mau", 77 | "Asian", 78 | "Asian Semi-longhair", 79 | "Australian Mist", 80 | "Balinese", 81 | "Bambino", 82 | "Bengal", 83 | "Birman", 84 | "Bombay", 85 | "Brazilian Shorthair", 86 | "British Longhair", 87 | "British Semipi-longhair", 88 | "British Shorthair", 89 | "Burmese", 90 | "Burmilla", 91 | "California Spangled", 92 | "Chantilly-Tiffany", 93 | "Chartreux", 94 | "Chausie", 95 | "Cheetoh", 96 | "Colorpoint Shorthair", 97 | "Cornish Rex", 98 | "Cymric, or Manx Longhair", 99 | "Cyprus", 100 | "Devon Rex", 101 | "Donskoy, or Don Sphynx", 102 | "Dragon Li", 103 | "Dwarf cat, or Dwelf", 104 | "Egyptian Mau", 105 | "European Shorthair", 106 | "Exotic Shorthair", 107 | "Foldex Cat", 108 | "German Rex", 109 | "Havana Brown", 110 | "Highlander", 111 | "Himalayan, or Colorpoint Persian", 112 | "Japanese Bobtail", 113 | "Javanese", 114 | "Khao Manee", 115 | "Korat", 116 | "Korean Bobtail", 117 | "Korn Ja", 118 | "Kurilian Bobtail", 119 | "Kurilian Bobtail, or Kuril Islands Bobtail", 120 | "LaPerm", 121 | "Lykoi", 122 | "Maine Coon", 123 | "Manx", 124 | "Mekong Bobtail", 125 | "Minskin", 126 | "Munchkin", 127 | "Napoleon", 128 | "Nebelung", 129 | "Norwegian Forest Cat", 130 | "Ocicat", 131 | "Ojos Azules", 132 | "Oregon Rex", 133 | "Oriental Bicolor", 134 | "Oriental Longhair", 135 | "Oriental Shorthair", 136 | "PerFold Cat (Experimental Breed - WCF)", 137 | "Persian (Modern Persian Cat)", 138 | "Persian (Traditional Persian Cat)", 139 | "Peterbald", 140 | "Pixie-bob", 141 | "Raas", 142 | "Ragamuffin", 143 | "Ragdoll", 144 | "Russian Blue", 145 | "Russian White, Black and Tabby", 146 | "Sam Sawet", 147 | "Savannah", 148 | "Scottish Fold", 149 | "Selkirk Rex", 150 | "Serengeti", 151 | "Serrade petit", 152 | "Siamese", 153 | "Siberian", 154 | "Singapura", 155 | "Snowshoe", 156 | "Sokoke", 157 | "Somali", 158 | "Sphynx", 159 | "Suphalak", 160 | "Thai", 161 | "Tonkinese", 162 | "Toyger", 163 | "Turkish Angora", 164 | "Turkish Van", 165 | "Ukrainian Levkoy" 166 | ]) 167 | 168 | @doc """ 169 | Returns a cat registry string 170 | 171 | ## Examples 172 | 173 | iex> Faker.Cat.En.registry() 174 | "Cat Aficionado Association" 175 | iex> Faker.Cat.En.registry() 176 | "Fédération Internationale Féline" 177 | iex> Faker.Cat.En.registry() 178 | "Fédération Internationale Féline" 179 | iex> Faker.Cat.En.registry() 180 | "Fédération Internationale Féline" 181 | """ 182 | @spec registry() :: String.t() 183 | sampler(:registry, [ 184 | "American Cat Fanciers Association", 185 | "Associazione Nazionale Felina Italiana", 186 | "Canadian Cat Association", 187 | "Cat Aficionado Association", 188 | "Cat Fanciers' Association", 189 | "Emirates Feline Federation", 190 | "Fédération Internationale Féline", 191 | "Felis Britannica", 192 | "Governing Council of the Cat", 193 | "Fancy Southern Africa Cat Council", 194 | "The International Cat Association" 195 | ]) 196 | end 197 | -------------------------------------------------------------------------------- /lib/faker/cat/pt_br.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Cat.PtBr do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Functions for Cat names and breeds in Brazilian Portuguese 6 | """ 7 | 8 | @doc """ 9 | Returns a Cat famele name string 10 | 11 | ## Examples 12 | 13 | iex> Faker.Cat.PtBr.female_name() 14 | "Samy" 15 | iex> Faker.Cat.PtBr.female_name() 16 | "Linda" 17 | iex> Faker.Cat.PtBr.female_name() 18 | "Úrsula" 19 | iex> Faker.Cat.PtBr.female_name() 20 | "Florinda" 21 | """ 22 | @spec female_name() :: String.t() 23 | sampler(:female_name, [ 24 | "Amber", 25 | "Amelie", 26 | "Amora", 27 | "Amy", 28 | "Ariel", 29 | "Babi", 30 | "Barbie", 31 | "Bombom", 32 | "Cacau", 33 | "Charlotte", 34 | "Chiquinha", 35 | "Cindy", 36 | "Cristal", 37 | "Dalila", 38 | "Dama", 39 | "Dora", 40 | "Dori", 41 | "Estrela", 42 | "Felícia", 43 | "Fibi", 44 | "Filipa", 45 | "Filomena", 46 | "Filó", 47 | "Fiona", 48 | "Florinda", 49 | "Florisbela", 50 | "Fofuxa", 51 | "Frida", 52 | "Gaia", 53 | "Gertrudes", 54 | "Gina", 55 | "Hazel", 56 | "Jabuticaba", 57 | "Jade", 58 | "Jasmin", 59 | "Kaila", 60 | "Kibana", 61 | "Kim", 62 | "Kindy", 63 | "Lila", 64 | "Lili", 65 | "Linda", 66 | "Lizi", 67 | "Lola", 68 | "Lolita", 69 | "Lua", 70 | "Lulu", 71 | "Luna", 72 | "Luzi", 73 | "Madonna", 74 | "Mafalda", 75 | "Magali", 76 | "Malu", 77 | "Mel", 78 | "Merida", 79 | "Mia", 80 | "Mica", 81 | "Mimi", 82 | "Moana", 83 | "Moli", 84 | "Nala", 85 | "Nanny", 86 | "Nairóbi", 87 | "Nikita", 88 | "Nina", 89 | "Pandora", 90 | "Paçoca", 91 | "Pipoca", 92 | "Pituca", 93 | "Safira", 94 | "Samy", 95 | "Sandi", 96 | "Selena", 97 | "Soneca", 98 | "Tina", 99 | "Úrsula", 100 | "Vanellope", 101 | "Wendy", 102 | "Xica", 103 | "Zoe" 104 | ]) 105 | 106 | @doc """ 107 | Returns a Cat male name string 108 | 109 | ## Examples 110 | 111 | iex> Faker.Cat.PtBr.male_name() 112 | "Soneca" 113 | iex> Faker.Cat.PtBr.male_name() 114 | "Loui" 115 | iex> Faker.Cat.PtBr.male_name() 116 | "Ton" 117 | iex> Faker.Cat.PtBr.male_name() 118 | "Dante" 119 | """ 120 | @spec male_name() :: String.t() 121 | sampler( 122 | :male_name, 123 | [ 124 | "Aladim", 125 | "Algodão", 126 | "Apolo", 127 | "Amendoim", 128 | "Amendupã", 129 | "Aristóteles", 130 | "Bambi", 131 | "Banguela", 132 | "Bartolomeu", 133 | "Batman", 134 | "Bigode", 135 | "Biscoito", 136 | "Bob", 137 | "Bolota", 138 | "Bombom", 139 | "Boris", 140 | "Boyle", 141 | "Brutus", 142 | "Cadu", 143 | "Calvin", 144 | "Chewie", 145 | "Chico", 146 | "Clemente", 147 | "Clovis", 148 | "Dante", 149 | "Elvis", 150 | "Fidélix", 151 | "Frajola", 152 | "Fred", 153 | "Freud", 154 | "Félix", 155 | "Galeão", 156 | "Garfield", 157 | "Genóvio", 158 | "Gepeto", 159 | "Holt", 160 | "Homer", 161 | "Joca", 162 | "Joey", 163 | "Juca", 164 | "Justin", 165 | "Loui", 166 | "Malvin", 167 | "Merlin", 168 | "Mingau", 169 | "Naruto", 170 | "Nemo", 171 | "Nicolau", 172 | "Nilo", 173 | "Nino", 174 | "Olaf", 175 | "Oliver", 176 | "Oreo", 177 | "Oliver", 178 | "Peralta", 179 | "Peter", 180 | "Picasso", 181 | "Pingo", 182 | "Pipoca", 183 | "Pirulito", 184 | "Platão", 185 | "Pluma", 186 | "Pomposo", 187 | "Pongo", 188 | "Romeu", 189 | "Ross", 190 | "Ruffus", 191 | "Russo", 192 | "Simba", 193 | "Singer", 194 | "Soneca", 195 | "Spike", 196 | "Tenente", 197 | "Thor", 198 | "Tommy", 199 | "Ton", 200 | "Tonico", 201 | "Tufão", 202 | "Venon", 203 | "Yoda" 204 | ] 205 | ) 206 | 207 | @doc """ 208 | Returns a Cat breed string 209 | 210 | ## Examples 211 | 212 | iex> Faker.Cat.PtBr.breed() 213 | "Angorá Turco" 214 | iex> Faker.Cat.PtBr.breed() 215 | "Azul Russo" 216 | iex> Faker.Cat.PtBr.breed() 217 | "Pelo Curto Brasileiro" 218 | iex> Faker.Cat.PtBr.breed() 219 | "Pelo Curto Americano" 220 | """ 221 | @spec breed() :: String.t() 222 | sampler(:breed, [ 223 | "Angorá Turco", 224 | "Azul Russo", 225 | "Bombaim", 226 | "Himalaio", 227 | "Pelo Curto Americano", 228 | "Pelo Curto Brasileiro", 229 | "Pelo Curto Europeu", 230 | "Persa", 231 | "Siamês", 232 | "Vira-lata" 233 | ]) 234 | end 235 | -------------------------------------------------------------------------------- /lib/faker/code.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Code do 2 | @moduledoc """ 3 | Functions for generate common codes. 4 | """ 5 | 6 | alias Faker.Util 7 | 8 | @doc """ 9 | Returns a random isbn code 10 | 11 | ## Examples 12 | 13 | iex> Faker.Code.isbn 14 | "015426461X" 15 | iex> Faker.Code.isbn 16 | "0832970522" 17 | iex> Faker.Code.isbn 18 | "3570203034" 19 | iex> Faker.Code.isbn 20 | "2097337600" 21 | """ 22 | defdelegate isbn, to: Faker.Code, as: :isbn10 23 | 24 | @doc """ 25 | Returns a random isbn10 code 26 | 27 | ## Examples 28 | 29 | iex> Faker.Code.isbn10 30 | "015426461X" 31 | iex> Faker.Code.isbn10 32 | "0832970522" 33 | iex> Faker.Code.isbn10 34 | "3570203034" 35 | iex> Faker.Code.isbn10 36 | "2097337600" 37 | """ 38 | def isbn10 do 39 | sequence = Faker.format("#########") 40 | sequence <> check_digit(sequence, &calc_digit_x_index/1, 11) 41 | end 42 | 43 | @doc """ 44 | Returns a random isbn13 code 45 | 46 | ## Examples 47 | 48 | iex> Faker.Code.isbn13 49 | "9781542646109" 50 | iex> Faker.Code.isbn13 51 | "9783297052358" 52 | iex> Faker.Code.isbn13 53 | "9790203032090" 54 | iex> Faker.Code.isbn13 55 | "9793376033741" 56 | """ 57 | def isbn13 do 58 | sequence = Util.pick(["978", "979"]) <> Faker.format("#########") 59 | sequence <> check_digit(sequence, &calc_isbn13/1, 10) 60 | end 61 | 62 | @doc """ 63 | Returns a random issn code 64 | 65 | ## Examples 66 | 67 | iex> Faker.Code.issn 68 | "01542648" 69 | iex> Faker.Code.issn 70 | "61083291" 71 | iex> Faker.Code.issn 72 | "70523576" 73 | iex> Faker.Code.issn 74 | "02030322" 75 | """ 76 | def issn do 77 | sequence = Faker.format("#######") 78 | sequence <> check_digit(sequence, &calc_digit_x_index/1, 11) 79 | end 80 | 81 | @doc """ 82 | Returns a random IBAN starting with the given components. The given components are not validated 83 | but are included in the checksum. 84 | 85 | ## Examples 86 | 87 | iex> Faker.Code.iban("NL", ["ABNA"]) 88 | "NL16ABNA0154264610" 89 | iex> Faker.Code.iban("MC", ["FOO", "BAR"]) 90 | "MC98FOOBAR83" 91 | iex> Faker.Code.iban("SM", ["A"]) 92 | "SM86A2970523570AY38NWIVZ5XT" 93 | iex> Faker.Code.iban("MC", ["FOO", "BAR"]) 94 | "MC40FOOBAR60" 95 | """ 96 | defdelegate iban(), to: Faker.Code.Iban 97 | defdelegate iban(country_code_or_codes), to: Faker.Code.Iban 98 | defdelegate iban(country_code, prefix_components), to: Faker.Code.Iban 99 | 100 | defp check_digit(sequence, calc_function, size) do 101 | (sequence <> "0") 102 | |> String.reverse() 103 | |> String.graphemes() 104 | |> Stream.with_index() 105 | |> Stream.map(calc_function) 106 | |> Enum.sum() 107 | |> grapheme_for_last(size) 108 | end 109 | 110 | defp grapheme_for_last(checksum, size) do 111 | digit_to_grapheme(size - rem(checksum, size), size) 112 | end 113 | 114 | defp calc_digit_x_index({e, i}), do: grapheme_to_digit(e) * (i + 1) 115 | defp calc_isbn13({e, i}) when rem(i, 2) == 1, do: grapheme_to_digit(e) * 3 116 | defp calc_isbn13({e, _}), do: grapheme_to_digit(e) 117 | 118 | defp digit_to_grapheme(10, 11), do: "X" 119 | defp digit_to_grapheme(digit, size) when digit == size, do: "0" 120 | defp digit_to_grapheme(digit, _), do: Integer.to_string(digit) 121 | 122 | defp grapheme_to_digit("X"), do: 10 123 | defp grapheme_to_digit(str), do: String.to_integer(str) 124 | end 125 | -------------------------------------------------------------------------------- /lib/faker/color.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Color do 2 | import Faker, only: [localize: 1] 3 | 4 | @moduledoc """ 5 | Functions for generating different color representations. 6 | """ 7 | 8 | @doc """ 9 | Return random RGB hex value. 10 | 11 | ## Examples 12 | 13 | iex> Faker.Color.rgb_hex() 14 | "D6D98B" 15 | iex> Faker.Color.rgb_hex() 16 | "88C866" 17 | iex> Faker.Color.rgb_hex() 18 | "F496DB" 19 | iex> Faker.Color.rgb_hex() 20 | "D4DE7B" 21 | """ 22 | @spec rgb_hex() :: binary 23 | def rgb_hex do 24 | "~2.16.0B~2.16.0B~2.16.0B" 25 | |> :io_lib.format(Tuple.to_list(rgb_decimal())) 26 | |> :erlang.iolist_to_binary() 27 | end 28 | 29 | @doc """ 30 | Return random RGB decimal value. 31 | 32 | ## Examples 33 | 34 | iex> Faker.Color.rgb_decimal() 35 | {214, 217, 139} 36 | iex> Faker.Color.rgb_decimal() 37 | {136, 200, 102} 38 | iex> Faker.Color.rgb_decimal() 39 | {244, 150, 219} 40 | iex> Faker.Color.rgb_decimal() 41 | {212, 222, 123} 42 | """ 43 | @spec rgb_decimal() :: {byte, byte, byte} 44 | def rgb_decimal do 45 | { 46 | Faker.random_between(0, 255), 47 | Faker.random_between(0, 255), 48 | Faker.random_between(0, 255) 49 | } 50 | end 51 | 52 | @doc """ 53 | Return a random color name 54 | 55 | ## Examples 56 | 57 | iex> Faker.Color.name() 58 | "Red" 59 | iex> Faker.Color.name() 60 | "Green" 61 | iex> Faker.Color.name() 62 | "Brown" 63 | iex> Faker.Color.name() 64 | "Pink" 65 | """ 66 | @spec name() :: String.t() 67 | localize(:name) 68 | 69 | @doc """ 70 | Return a random fancy color name 71 | 72 | ## Examples 73 | 74 | iex> Faker.Color.fancy_name() 75 | "Tawny" 76 | iex> Faker.Color.fancy_name() 77 | "Citrine" 78 | iex> Faker.Color.fancy_name() 79 | "Greige" 80 | iex> Faker.Color.fancy_name() 81 | "Cesious" 82 | """ 83 | @spec fancy_name() :: String.t() 84 | localize(:fancy_name) 85 | end 86 | -------------------------------------------------------------------------------- /lib/faker/color/de.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Color.De do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Functions for color data in German 6 | """ 7 | 8 | @doc """ 9 | Returns a random German color name 10 | 11 | ## Examples 12 | 13 | iex> Faker.Color.De.name() 14 | "Rot" 15 | iex> Faker.Color.De.name() 16 | "Grün" 17 | iex> Faker.Color.De.name() 18 | "Braun" 19 | iex> Faker.Color.De.name() 20 | "Rosa" 21 | """ 22 | @spec name() :: String.t() 23 | sampler(:name, [ 24 | "Rot", 25 | "Grün", 26 | "Schwarz", 27 | "Blau", 28 | "Rosa", 29 | "Braun", 30 | "Orange", 31 | "Gelb", 32 | "Lila", 33 | "Weiß" 34 | ]) 35 | 36 | @doc """ 37 | Returns a random english fancy color name 38 | 39 | ## Examples 40 | 41 | iex> Faker.Color.De.fancy_name() 42 | "Flieder" 43 | iex> Faker.Color.De.fancy_name() 44 | "Feldgrau" 45 | iex> Faker.Color.De.fancy_name() 46 | "Gelbgrün" 47 | iex> Faker.Color.De.fancy_name() 48 | "Rotbraun" 49 | """ 50 | @spec fancy_name() :: String.t() 51 | sampler(:fancy_name, [ 52 | "Flieder", 53 | "Feldgrau", 54 | "Gelbgrün", 55 | "Kuchiba", 56 | "Rotbraun", 57 | "Tannengrün", 58 | "Weinrot", 59 | "Zementgrau" 60 | ]) 61 | end 62 | -------------------------------------------------------------------------------- /lib/faker/color/en.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Color.En do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Functions for color data in English 6 | """ 7 | 8 | @doc """ 9 | Returns a random English color name 10 | 11 | ## Examples 12 | 13 | iex> Faker.Color.En.name() 14 | "Red" 15 | iex> Faker.Color.En.name() 16 | "Green" 17 | iex> Faker.Color.En.name() 18 | "Brown" 19 | iex> Faker.Color.En.name() 20 | "Pink" 21 | """ 22 | @spec name() :: String.t() 23 | sampler(:name, [ 24 | "Red", 25 | "Green", 26 | "Black", 27 | "Blue", 28 | "Pink", 29 | "Brown", 30 | "Orange", 31 | "Yellow", 32 | "Purple", 33 | "White" 34 | ]) 35 | 36 | @doc """ 37 | Returns a random English fancy color name 38 | 39 | ## Examples 40 | 41 | iex> Faker.Color.En.fancy_name() 42 | "Tawny" 43 | iex> Faker.Color.En.fancy_name() 44 | "Citrine" 45 | iex> Faker.Color.En.fancy_name() 46 | "Greige" 47 | iex> Faker.Color.En.fancy_name() 48 | "Cesious" 49 | """ 50 | @spec fancy_name() :: String.t() 51 | sampler(:fancy_name, [ 52 | "Cesious", 53 | "Citrine", 54 | "Damson", 55 | "Greige", 56 | "Luteous", 57 | "Ochre", 58 | "Tawny", 59 | "Watchet" 60 | ]) 61 | end 62 | -------------------------------------------------------------------------------- /lib/faker/color/es.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Color.Es do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Functions for color data in Spanish 6 | """ 7 | 8 | @doc """ 9 | Returns a random spanish color name 10 | 11 | ## Examples 12 | 13 | iex> Faker.Color.Es.name() 14 | "Rojo" 15 | iex> Faker.Color.Es.name() 16 | "Verde" 17 | iex> Faker.Color.Es.name() 18 | "Marrón" 19 | iex> Faker.Color.Es.name() 20 | "Rosa" 21 | """ 22 | @spec name() :: String.t() 23 | sampler(:name, [ 24 | "Rojo", 25 | "Verde", 26 | "Negro", 27 | "Azul", 28 | "Rosa", 29 | "Marrón", 30 | "Laranja", 31 | "Amarillo", 32 | "Morado", 33 | "Blanco" 34 | ]) 35 | end 36 | -------------------------------------------------------------------------------- /lib/faker/color/fr.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Color.Fr do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Functions for color data in French 6 | """ 7 | 8 | @doc """ 9 | Returns a random french color name 10 | 11 | ## Examples 12 | 13 | iex> Faker.Color.Fr.name() 14 | "Rouge" 15 | iex> Faker.Color.Fr.name() 16 | "Vert" 17 | iex> Faker.Color.Fr.name() 18 | "Marron" 19 | iex> Faker.Color.Fr.name() 20 | "Rose" 21 | """ 22 | @spec name() :: String.t() 23 | sampler(:name, [ 24 | "Rouge", 25 | "Vert", 26 | "Noir", 27 | "Bleu", 28 | "Rose", 29 | "Marron", 30 | "Orange", 31 | "Jaune", 32 | "Violet", 33 | "Blanc" 34 | ]) 35 | end 36 | -------------------------------------------------------------------------------- /lib/faker/color/hy.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Color.Hy do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Functions for generating color data in Armenian 6 | """ 7 | 8 | @doc """ 9 | Returns a random color name. 10 | 11 | ## Examples 12 | 13 | iex> Faker.Color.Hy.name() 14 | "մոխրագույն" 15 | iex> Faker.Color.Hy.name() 16 | "կանաչ" 17 | iex> Faker.Color.Hy.name() 18 | "երկնագույն" 19 | iex> Faker.Color.Hy.name() 20 | "մանուշակագույն" 21 | """ 22 | @spec name() :: String.t() 23 | sampler(:name, [ 24 | "կարմիր", 25 | "կանաչ", 26 | "կապույտ", 27 | "դեղին", 28 | "մանուշակագույն", 29 | "շագանակագույն", 30 | "սպիտակ", 31 | "սև", 32 | "նարնջագույն", 33 | "վարդագույն", 34 | "մոխրագույն", 35 | "մանուշակագույն", 36 | "փիրուզագույն", 37 | "մուգ մանուշակագույն", 38 | "դեղնավարդագույն", 39 | "երկնագույն", 40 | "դեղնականաչ", 41 | "թուխ", 42 | "ոսկեգույն", 43 | "դարչնագույն" 44 | ]) 45 | end 46 | -------------------------------------------------------------------------------- /lib/faker/color/it.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Color.It do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Functions for color data in Italian 6 | """ 7 | 8 | @doc """ 9 | Returns a random Italian color name 10 | 11 | ## Examples 12 | 13 | iex> Faker.Color.It.name() 14 | "Rosso" 15 | iex> Faker.Color.It.name() 16 | "Verde" 17 | iex> Faker.Color.It.name() 18 | "Marrone" 19 | iex> Faker.Color.It.name() 20 | "Rosa" 21 | """ 22 | @spec name() :: String.t() 23 | sampler(:name, [ 24 | "Rosso", 25 | "Verde", 26 | "Nero", 27 | "Azzurro", 28 | "Rosa", 29 | "Marrone", 30 | "Arancio", 31 | "Giallo", 32 | "Viola", 33 | "Bianco" 34 | ]) 35 | end 36 | -------------------------------------------------------------------------------- /lib/faker/color/pt_br.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Color.PtBr do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Functions for color data in Brazilian Portuguese 6 | """ 7 | 8 | @doc """ 9 | Returns a random Brazilian Portuguese color name 10 | 11 | ## Examples 12 | 13 | iex> Faker.Color.PtBr.name() 14 | "Vermelho" 15 | iex> Faker.Color.PtBr.name() 16 | "Verde" 17 | iex> Faker.Color.PtBr.name() 18 | "Marrom" 19 | iex> Faker.Color.PtBr.name() 20 | "Rosa" 21 | """ 22 | @spec name() :: String.t() 23 | sampler(:name, [ 24 | "Vermelho", 25 | "Verde", 26 | "Preto", 27 | "Azul", 28 | "Rosa", 29 | "Marrom", 30 | "Laranja", 31 | "Amarelo", 32 | "Roxo", 33 | "Branco" 34 | ]) 35 | end 36 | -------------------------------------------------------------------------------- /lib/faker/commerce.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Commerce do 2 | import Faker, only: [localize: 1] 3 | 4 | @moduledoc """ 5 | Functions for generating commerce related data 6 | """ 7 | 8 | @doc """ 9 | Returns a random color 10 | 11 | ## Examples 12 | 13 | iex> Faker.Commerce.color() 14 | "red" 15 | iex> Faker.Commerce.color() 16 | "sky blue" 17 | iex> Faker.Commerce.color() 18 | "lavender" 19 | iex> Faker.Commerce.color() 20 | "grey" 21 | """ 22 | @spec color() :: String.t() 23 | localize(:color) 24 | 25 | @doc """ 26 | Returns a random department 27 | 28 | ## Examples 29 | 30 | iex> Faker.Commerce.department() 31 | "Home, Garden & Tools" 32 | iex> Faker.Commerce.department() 33 | "Electronics & Computers" 34 | iex> Faker.Commerce.department() 35 | "Clothing, Shoes & Jewelery" 36 | iex> Faker.Commerce.department() 37 | "Toys, Kids & Baby" 38 | """ 39 | @spec department() :: String.t() 40 | localize(:department) 41 | 42 | @doc """ 43 | Returns a random number that represents a price 44 | 45 | ## Examples 46 | 47 | iex> Faker.Commerce.price() 48 | 1.11 49 | iex> Faker.Commerce.price() 50 | 4.02 51 | iex> Faker.Commerce.price() 52 | 8.36 53 | iex> Faker.Commerce.price() 54 | 3.05 55 | """ 56 | @spec price() :: float 57 | def price do 58 | Faker.random_between(1, 1000) / 100.0 59 | end 60 | 61 | @doc """ 62 | Returns a complete product name, based on product adjectives, product 63 | materials, product names 64 | 65 | ## Examples 66 | 67 | iex> Faker.Commerce.product_name() 68 | "Ergonomic Steel Shirt" 69 | iex> Faker.Commerce.product_name() 70 | "Fantastic Car" 71 | iex> Faker.Commerce.product_name() 72 | "Granite Gloves" 73 | iex> Faker.Commerce.product_name() 74 | "Plastic Shoes" 75 | """ 76 | @spec product_name() :: String.t() 77 | localize(:product_name) 78 | 79 | @doc """ 80 | Returns a random adjective for a product 81 | 82 | ## Examples 83 | 84 | iex> Faker.Commerce.product_name_adjective() 85 | "Small" 86 | iex> Faker.Commerce.product_name_adjective() 87 | "Ergonomic" 88 | iex> Faker.Commerce.product_name_adjective() 89 | "Incredible" 90 | iex> Faker.Commerce.product_name_adjective() 91 | "Gorgeous" 92 | """ 93 | @spec product_name_adjective() :: String.t() 94 | localize(:product_name_adjective) 95 | 96 | @doc """ 97 | Returns a random product material 98 | 99 | ## Examples 100 | 101 | iex> Faker.Commerce.product_name_material() 102 | "Rubber" 103 | iex> Faker.Commerce.product_name_material() 104 | "Concrete" 105 | iex> Faker.Commerce.product_name_material() 106 | "Steel" 107 | iex> Faker.Commerce.product_name_material() 108 | "Granite" 109 | """ 110 | @spec product_name_material() :: String.t() 111 | localize(:product_name_material) 112 | 113 | @doc """ 114 | Returns a random product name 115 | 116 | ## Examples 117 | 118 | iex> Faker.Commerce.product_name_product() 119 | "Gloves" 120 | iex> Faker.Commerce.product_name_product() 121 | "Computer" 122 | iex> Faker.Commerce.product_name_product() 123 | "Table" 124 | iex> Faker.Commerce.product_name_product() 125 | "Shirt" 126 | """ 127 | @spec product_name_product() :: String.t() 128 | localize(:product_name_product) 129 | end 130 | -------------------------------------------------------------------------------- /lib/faker/commerce/en.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Commerce.En do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Functions for generating commerce related data in English 6 | """ 7 | 8 | @doc """ 9 | Returns a random color 10 | 11 | ## Examples 12 | 13 | iex> Faker.Commerce.En.color() 14 | "red" 15 | iex> Faker.Commerce.En.color() 16 | "sky blue" 17 | iex> Faker.Commerce.En.color() 18 | "lavender" 19 | iex> Faker.Commerce.En.color() 20 | "grey" 21 | """ 22 | @spec color() :: String.t() 23 | sampler(:color, [ 24 | "azure", 25 | "black", 26 | "blue", 27 | "brown", 28 | "cyan", 29 | "fuchsia", 30 | "gold", 31 | "green", 32 | "grey", 33 | "indigo", 34 | "ivory", 35 | "lavender", 36 | "lime", 37 | "magenta", 38 | "maroon", 39 | "mint green", 40 | "olive", 41 | "orange", 42 | "orchid", 43 | "pink", 44 | "plum", 45 | "purple", 46 | "red", 47 | "salmon", 48 | "silver", 49 | "sky blue", 50 | "tan", 51 | "teal", 52 | "turquoise", 53 | "violet", 54 | "white", 55 | "yellow" 56 | ]) 57 | 58 | @doc """ 59 | Returns a random department 60 | 61 | ## Examples 62 | 63 | iex> Faker.Commerce.En.department() 64 | "Home, Garden & Tools" 65 | iex> Faker.Commerce.En.department() 66 | "Electronics & Computers" 67 | iex> Faker.Commerce.En.department() 68 | "Clothing, Shoes & Jewelery" 69 | iex> Faker.Commerce.En.department() 70 | "Toys, Kids & Baby" 71 | """ 72 | @spec department() :: String.t() 73 | sampler(:department, [ 74 | "Books", 75 | "Movies, Music & Games", 76 | "Electronics & Computers", 77 | "Home, Garden & Tools", 78 | "Grocery, Health & Beauty", 79 | "Toys, Kids & Baby", 80 | "Clothing, Shoes & Jewelery", 81 | "Sports & Outdoors", 82 | "Automotive & Industrial" 83 | ]) 84 | 85 | @doc """ 86 | Returns a complete product name, based on product adjectives, product 87 | materials, product names 88 | 89 | ## Examples 90 | 91 | iex> Faker.Commerce.En.product_name() 92 | "Ergonomic Steel Shirt" 93 | iex> Faker.Commerce.En.product_name() 94 | "Fantastic Car" 95 | iex> Faker.Commerce.En.product_name() 96 | "Granite Gloves" 97 | iex> Faker.Commerce.En.product_name() 98 | "Plastic Shoes" 99 | """ 100 | @spec product_name() :: String.t() 101 | def product_name, do: product_name(Faker.random_between(0, 2)) 102 | 103 | defp product_name(0) do 104 | "#{product_name_adjective()} #{product_name_material()} #{product_name_product()}" 105 | end 106 | 107 | defp product_name(1), do: "#{product_name_adjective()} #{product_name_product()}" 108 | defp product_name(2), do: "#{product_name_material()} #{product_name_product()}" 109 | 110 | @doc """ 111 | Returns a random adjective for a product 112 | 113 | ## Examples 114 | 115 | iex> Faker.Commerce.En.product_name_adjective() 116 | "Small" 117 | iex> Faker.Commerce.En.product_name_adjective() 118 | "Ergonomic" 119 | iex> Faker.Commerce.En.product_name_adjective() 120 | "Incredible" 121 | iex> Faker.Commerce.En.product_name_adjective() 122 | "Gorgeous" 123 | """ 124 | @spec product_name_adjective() :: String.t() 125 | sampler(:product_name_adjective, [ 126 | "Small", 127 | "Ergonomic", 128 | "Rustic", 129 | "Intelligent", 130 | "Gorgeous", 131 | "Incredible", 132 | "Fantastic", 133 | "Practical", 134 | "Sleek", 135 | "Awesome" 136 | ]) 137 | 138 | @doc """ 139 | Returns a random product material 140 | 141 | ## Examples 142 | 143 | iex> Faker.Commerce.En.product_name_material() 144 | "Rubber" 145 | iex> Faker.Commerce.En.product_name_material() 146 | "Concrete" 147 | iex> Faker.Commerce.En.product_name_material() 148 | "Steel" 149 | iex> Faker.Commerce.En.product_name_material() 150 | "Granite" 151 | """ 152 | @spec product_name_material() :: String.t() 153 | sampler(:product_name_material, [ 154 | "Steel", 155 | "Wooden", 156 | "Concrete", 157 | "Plastic", 158 | "Cotton", 159 | "Granite", 160 | "Rubber" 161 | ]) 162 | 163 | @doc """ 164 | Returns a random product name 165 | 166 | ## Examples 167 | 168 | iex> Faker.Commerce.En.product_name_product() 169 | "Gloves" 170 | iex> Faker.Commerce.En.product_name_product() 171 | "Computer" 172 | iex> Faker.Commerce.En.product_name_product() 173 | "Table" 174 | iex> Faker.Commerce.En.product_name_product() 175 | "Shirt" 176 | """ 177 | @spec product_name_product() :: String.t() 178 | sampler(:product_name_product, [ 179 | "Chair", 180 | "Car", 181 | "Computer", 182 | "Gloves", 183 | "Pants", 184 | "Shirt", 185 | "Table", 186 | "Shoes", 187 | "Hat" 188 | ]) 189 | end 190 | -------------------------------------------------------------------------------- /lib/faker/company.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Company do 2 | import Faker, only: [localize: 1] 3 | 4 | @moduledoc """ 5 | Functions for generating company names and related stuff 6 | """ 7 | 8 | @doc """ 9 | Returns a random complete business related bullshit 10 | 11 | ## Examples 12 | 13 | iex> Faker.Company.bs() 14 | "syndicate e-business e-business" 15 | iex> Faker.Company.bs() 16 | "scale global metrics" 17 | iex> Faker.Company.bs() 18 | "optimize scalable markets" 19 | iex> Faker.Company.bs() 20 | "implement out-of-the-box content" 21 | """ 22 | @spec bs() :: String.t() 23 | localize(:bs) 24 | 25 | @doc """ 26 | Returns a random business related bullshit 27 | 28 | ## Examples 29 | 30 | iex> Faker.Company.bullshit() 31 | "web-enabled" 32 | iex> Faker.Company.bullshit() 33 | "e-business" 34 | iex> Faker.Company.bullshit() 35 | "web-enabled" 36 | iex> Faker.Company.bullshit() 37 | "next-generation" 38 | """ 39 | @spec bullshit() :: String.t() 40 | localize(:bullshit) 41 | 42 | @doc """ 43 | Returns a random business related bullshit prefix 44 | 45 | ## Examples 46 | 47 | iex> Faker.Company.bullshit_prefix() 48 | "syndicate" 49 | iex> Faker.Company.bullshit_prefix() 50 | "visualize" 51 | iex> Faker.Company.bullshit_prefix() 52 | "incentivize" 53 | iex> Faker.Company.bullshit_prefix() 54 | "scale" 55 | """ 56 | @spec bullshit_prefix() :: String.t() 57 | localize(:bullshit_prefix) 58 | 59 | @doc """ 60 | Returns a random business related bullshit suffix 61 | 62 | ## Examples 63 | 64 | iex> Faker.Company.bullshit_suffix() 65 | "e-services" 66 | iex> Faker.Company.bullshit_suffix() 67 | "niches" 68 | iex> Faker.Company.bullshit_suffix() 69 | "e-business" 70 | iex> Faker.Company.bullshit_suffix() 71 | "systems" 72 | """ 73 | @spec bullshit_suffix() :: String.t() 74 | localize(:bullshit_suffix) 75 | 76 | @doc """ 77 | Returns a random business related buzzword 78 | 79 | ## Examples 80 | 81 | iex> Faker.Company.buzzword() 82 | "upward-trending" 83 | iex> Faker.Company.buzzword() 84 | "full-range" 85 | iex> Faker.Company.buzzword() 86 | "uniform" 87 | iex> Faker.Company.buzzword() 88 | "tertiary" 89 | """ 90 | @spec buzzword() :: String.t() 91 | localize(:buzzword) 92 | 93 | @doc """ 94 | Returns a random business related buzzword prefix 95 | 96 | ## Examples 97 | 98 | iex> Faker.Company.buzzword_prefix() 99 | "Configurable" 100 | iex> Faker.Company.buzzword_prefix() 101 | "Advanced" 102 | iex> Faker.Company.buzzword_prefix() 103 | "Grass-roots" 104 | iex> Faker.Company.buzzword_prefix() 105 | "Automated" 106 | """ 107 | @spec buzzword_prefix() :: String.t() 108 | localize(:buzzword_prefix) 109 | 110 | @doc """ 111 | Returns a random business related buzzword suffix 112 | 113 | ## Examples 114 | 115 | iex> Faker.Company.buzzword_suffix() 116 | "encoding" 117 | iex> Faker.Company.buzzword_suffix() 118 | "standardization" 119 | iex> Faker.Company.buzzword_suffix() 120 | "Graphical User Interface" 121 | iex> Faker.Company.buzzword_suffix() 122 | "product" 123 | """ 124 | @spec buzzword_suffix() :: String.t() 125 | localize(:buzzword_suffix) 126 | 127 | @doc """ 128 | Returns a random complete catch phrase 129 | 130 | ## Examples 131 | 132 | iex> Faker.Company.catch_phrase() 133 | "Configurable full-range Graphical User Interface" 134 | iex> Faker.Company.buzzword_suffix() 135 | "product" 136 | iex> Faker.Company.buzzword_suffix() 137 | "intranet" 138 | iex> Faker.Company.buzzword_suffix() 139 | "pricing structure" 140 | """ 141 | @spec catch_phrase() :: String.t() 142 | localize(:catch_phrase) 143 | 144 | @doc """ 145 | Returns complete company name 146 | 147 | ## Examples 148 | 149 | iex> Faker.Company.name() 150 | "Hayes Inc" 151 | iex> Faker.Company.name() 152 | "Sipes, Wehner and Hane" 153 | iex> Faker.Company.name() 154 | "Schiller, Rogahn and Hartmann" 155 | iex> Faker.Company.name() 156 | "Murphy-Metz" 157 | """ 158 | @spec name() :: String.t() 159 | localize(:name) 160 | 161 | @doc """ 162 | Returns a random type of business entity 163 | 164 | ## Examples 165 | 166 | iex> Faker.Company.suffix() 167 | "Inc" 168 | iex> Faker.Company.suffix() 169 | "and Sons" 170 | iex> Faker.Company.suffix() 171 | "Inc" 172 | iex> Faker.Company.suffix() 173 | "Ltd" 174 | """ 175 | @spec suffix() :: String.t() 176 | localize(:suffix) 177 | end 178 | -------------------------------------------------------------------------------- /lib/faker/currency.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Currency do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Functions for generating currency related data 6 | """ 7 | 8 | @doc """ 9 | Returns a random currency code 10 | 11 | ## Examples 12 | 13 | iex> Faker.Currency.code() 14 | "WST" 15 | iex> Faker.Currency.code() 16 | "UYU" 17 | iex> Faker.Currency.code() 18 | "CRC" 19 | iex> Faker.Currency.code() 20 | "DOP" 21 | """ 22 | @spec code() :: String.t() 23 | sampler(:code, [ 24 | "AED", 25 | "AFN", 26 | "ALL", 27 | "AMD", 28 | "ANG", 29 | "AOA", 30 | "ARS", 31 | "AUD", 32 | "AWG", 33 | "AZN", 34 | "BAM", 35 | "BBD", 36 | "BDT", 37 | "BGN", 38 | "BHD", 39 | "BIF", 40 | "BMD", 41 | "BND", 42 | "BOB", 43 | "BRL", 44 | "BSD", 45 | "BWP", 46 | "BYN", 47 | "BZD", 48 | "CAD", 49 | "CDF", 50 | "CHF", 51 | "CLP", 52 | "CNY", 53 | "COP", 54 | "CRC", 55 | "CUP", 56 | "CVE", 57 | "CZK", 58 | "DJF", 59 | "DKK", 60 | "DOP", 61 | "DZD", 62 | "EEK", 63 | "EGP", 64 | "ERN", 65 | "ETB", 66 | "EUR", 67 | "FJD", 68 | "FKP", 69 | "GBP", 70 | "GEL", 71 | "GHS", 72 | "GIP", 73 | "GMD", 74 | "GNF", 75 | "GTQ", 76 | "GYD", 77 | "HKD", 78 | "HNL", 79 | "HRK", 80 | "HTG", 81 | "HUF", 82 | "IDR", 83 | "ILS", 84 | "INR", 85 | "IQD", 86 | "IRR", 87 | "ISK", 88 | "JMD", 89 | "JOD", 90 | "JPY", 91 | "KES", 92 | "KGS", 93 | "KHR", 94 | "KMF", 95 | "KPW", 96 | "KRW", 97 | "KWD", 98 | "KYD", 99 | "KZT", 100 | "LAK", 101 | "LBP", 102 | "LKR", 103 | "LRD", 104 | "LTL", 105 | "LVL", 106 | "LYD", 107 | "MAD", 108 | "MDL", 109 | "MGA", 110 | "MKD", 111 | "MMK", 112 | "MNT", 113 | "MOP", 114 | "MRO", 115 | "MUR", 116 | "MVR", 117 | "MWK", 118 | "MXN", 119 | "MYR", 120 | "MZN", 121 | "NGN", 122 | "NIO", 123 | "NOK", 124 | "NPR", 125 | "NZD", 126 | "OMR", 127 | "PAB", 128 | "PEN", 129 | "PGK", 130 | "PHP", 131 | "PKR", 132 | "PLN", 133 | "PYG", 134 | "QAR", 135 | "RON", 136 | "RSD", 137 | "RUB", 138 | "RWF", 139 | "SAR", 140 | "SBD", 141 | "SCR", 142 | "SDG", 143 | "SEK", 144 | "SGD", 145 | "SHP", 146 | "SLL", 147 | "SOS", 148 | "SRD", 149 | "STD", 150 | "SVC", 151 | "SYP", 152 | "SZL", 153 | "THB", 154 | "TJS", 155 | "TMT", 156 | "TND", 157 | "TOP", 158 | "TRY", 159 | "TTD", 160 | "TWD", 161 | "TZS", 162 | "UAH", 163 | "UGX", 164 | "USD", 165 | "UYU", 166 | "UZS", 167 | "VEF", 168 | "VND", 169 | "CRC", 170 | "WST", 171 | "XAF", 172 | "XAG", 173 | "XAU", 174 | "XBA", 175 | "XBB", 176 | "XBC", 177 | "XBD", 178 | "XCD", 179 | "XDR", 180 | "XFU", 181 | "XOF", 182 | "XPD", 183 | "XPF", 184 | "XPT", 185 | "XTS", 186 | "YER", 187 | "ZAR", 188 | "ZMW", 189 | "ZWL" 190 | ]) 191 | 192 | @doc """ 193 | Returns a random currency symbol 194 | 195 | ## Examples 196 | 197 | iex> Faker.Currency.symbol() 198 | "£" 199 | iex> Faker.Currency.symbol() 200 | "฿" 201 | iex> Faker.Currency.symbol() 202 | "ƒ" 203 | iex> Faker.Currency.symbol() 204 | "Rp" 205 | """ 206 | @spec symbol() :: String.t() 207 | sampler(:symbol, [ 208 | "HK$", 209 | "Ft", 210 | "₪", 211 | "¥", 212 | "R$", 213 | "$", 214 | "kr", 215 | "PhP", 216 | "zł", 217 | "CHF", 218 | "NT$", 219 | "฿", 220 | "£", 221 | "¢", 222 | "Rp", 223 | "ƒ", 224 | "€", 225 | "रू" 226 | ]) 227 | end 228 | -------------------------------------------------------------------------------- /lib/faker/date.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Date do 2 | import Faker.Util, only: [pick: 1] 3 | 4 | @moduledoc """ 5 | Functions for generating dates 6 | """ 7 | 8 | @doc """ 9 | Returns a random date of birth for a person with an age specified by a number or range 10 | """ 11 | @spec date_of_birth(integer | Range.t()) :: Date.t() 12 | def date_of_birth(age_or_range \\ 18..99) 13 | 14 | def date_of_birth(age) when is_integer(age) do 15 | {date, _time} = :calendar.local_time() 16 | 17 | today = Date.from_erl!(date) 18 | 19 | earliest_year = today.year - (age + 1) 20 | 21 | {:ok, earliest_date} = safe_date(earliest_year, today.month, today.day) 22 | earliest_date = Date.add(earliest_date, 1) 23 | 24 | {:ok, latest_date} = safe_date(earliest_year + 1, today.month, today.day) 25 | 26 | date_range = Date.range(earliest_date, latest_date) 27 | 28 | pick(date_range) 29 | end 30 | 31 | def date_of_birth(age_range) do 32 | age_range 33 | |> pick() 34 | |> date_of_birth() 35 | end 36 | 37 | @doc """ 38 | Returns a random date in the past up to N days, today not included 39 | """ 40 | @spec backward(integer) :: Date.t() 41 | def backward(days) do 42 | forward(-days) 43 | end 44 | 45 | @doc """ 46 | Returns a random date in the future up to N days, today not included 47 | """ 48 | @spec forward(integer) :: Date.t() 49 | def forward(days) do 50 | days 51 | |> Faker.DateTime.forward() 52 | |> DateTime.to_date() 53 | end 54 | 55 | @doc """ 56 | Returns a random date between two dates 57 | 58 | ## Examples 59 | 60 | iex> Faker.Date.between(~D[2010-12-10], ~D[2016-12-25]) 61 | ~D[2013-06-07] 62 | iex> Faker.Date.between(~D[2000-12-20], ~D[2000-12-25]) 63 | ~D[2000-12-20] 64 | iex> Faker.Date.between(~D[2000-02-02], ~D[2016-02-05]) 65 | ~D[2014-10-23] 66 | iex> Faker.Date.between(~D[2010-12-20], ~D[2010-12-25]) 67 | ~D[2010-12-21] 68 | """ 69 | @spec between(Date.t(), Date.t()) :: Date.t() 70 | def between(from, to) do 71 | from 72 | |> Faker.DateTime.between(to) 73 | |> DateTime.to_date() 74 | end 75 | 76 | defp safe_date(year, month, day) do 77 | case Date.new(year, month, day) do 78 | {:ok, date} -> {:ok, date} 79 | {:error, :invalid_date} -> safe_date(year, month, day - 1) 80 | end 81 | end 82 | end 83 | -------------------------------------------------------------------------------- /lib/faker/datetime.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.DateTime do 2 | @moduledoc """ 3 | Functions for working with `DateTime` values. 4 | """ 5 | 6 | @microseconds_per_day 86_400_000_000 7 | 8 | @doc """ 9 | Returns a random date in the past up to N days, today not included 10 | 11 | ## Examples 12 | 13 | iex> Faker.DateTime.backward(4) 14 | #=> %DateTime{calendar: Calendar.ISO, day: 20, hour: 6, 15 | #=> microsecond: {922180, 6}, minute: 2, month: 12, second: 17, 16 | #=> std_offset: 0, time_zone: "Etc/UTC", utc_offset: 0, year: 2016, 17 | #=> zone_abbr: "UTC"} 18 | """ 19 | @spec backward(integer) :: DateTime.t() 20 | def backward(days) do 21 | forward(-days) 22 | end 23 | 24 | @doc """ 25 | Returns a random date in the future up to N days, today not included 26 | 27 | ## Examples 28 | 29 | iex> Faker.DateTime.forward(4) 30 | #=> %DateTime{calendar: Calendar.ISO, day: 25, hour: 6, 31 | #=> microsecond: {922180, 6}, minute: 2, month: 12, second: 17, 32 | #=> std_offset: 0, time_zone: "Etc/UTC", utc_offset: 0, year: 2016, 33 | #=> zone_abbr: "UTC"} 34 | """ 35 | @spec forward(integer) :: DateTime.t() 36 | def forward(days) do 37 | sign = if days < 0, do: -1, else: 1 38 | 39 | today = DateTime.utc_now() |> to_timestamp 40 | # add or subtract extra day to avoid returning today 41 | from = today + sign * @microseconds_per_day 42 | to = from + @microseconds_per_day * days 43 | 44 | unix_between(from, to) 45 | end 46 | 47 | @doc """ 48 | Returns a random DateTime between two dates 49 | 50 | ## Examples 51 | 52 | iex> Faker.DateTime.between(~N[2016-12-20 00:00:00], ~N[2016-12-25 00:00:00]) 53 | #=> %DateTime{calendar: Calendar.ISO, day: 22, hour: 7, 54 | #=> microsecond: {753572, 6}, minute: 56, month: 12, second: 26, 55 | #=> std_offset: 0, time_zone: "Etc/UTC", utc_offset: 0, year: 2016, 56 | #=> zone_abbr: "UTC"} 57 | """ 58 | @spec between( 59 | Date.t() | NaiveDateTime.t() | DateTime.t(), 60 | Date.t() | NaiveDateTime.t() | DateTime.t() 61 | ) :: DateTime.t() 62 | def between(%Date{} = from, %Date{} = to) do 63 | between(date_to_datetime(from), date_to_datetime(to)) 64 | end 65 | 66 | def between(%NaiveDateTime{} = from, %NaiveDateTime{} = to) do 67 | between(naivedatetime_to_datetime(from), naivedatetime_to_datetime(to)) 68 | end 69 | 70 | def between(from, to) do 71 | unix_between(to_timestamp(from), to_timestamp(to)) 72 | end 73 | 74 | # private 75 | 76 | @spec date_to_datetime(Date.t()) :: DateTime.t() 77 | defp date_to_datetime(date) do 78 | %DateTime{ 79 | calendar: Calendar.ISO, 80 | day: date.day, 81 | hour: 0, 82 | minute: 0, 83 | month: date.month, 84 | second: 0, 85 | time_zone: "Etc/UTC", 86 | utc_offset: 0, 87 | std_offset: 0, 88 | year: date.year, 89 | zone_abbr: "UTC" 90 | } 91 | end 92 | 93 | @spec naivedatetime_to_datetime(NaiveDateTime.t()) :: DateTime.t() 94 | defp naivedatetime_to_datetime(naivedatetime) do 95 | %DateTime{ 96 | calendar: naivedatetime.calendar, 97 | day: naivedatetime.day, 98 | hour: naivedatetime.hour, 99 | minute: naivedatetime.minute, 100 | month: naivedatetime.month, 101 | second: naivedatetime.second, 102 | time_zone: "Etc/UTC", 103 | utc_offset: 0, 104 | std_offset: 0, 105 | year: naivedatetime.year, 106 | zone_abbr: "UTC" 107 | } 108 | end 109 | 110 | defp to_timestamp(datetime) do 111 | DateTime.to_unix(datetime, :microsecond) 112 | end 113 | 114 | defp unix_between(from, to) do 115 | diff = to - from 116 | sign = if diff < 0, do: -1, else: 1 117 | 118 | date = from + sign * Faker.random_between(0, abs(diff)) 119 | 120 | DateTime.from_unix!(date, :microsecond) 121 | end 122 | end 123 | -------------------------------------------------------------------------------- /lib/faker/dog/pt_br.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Dog.PtBr do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Functions for Dog names, breeds and characteristics in Portuguese 6 | """ 7 | 8 | @doc """ 9 | Returns a dog name. 10 | 11 | ## Examples 12 | 13 | iex> Faker.Dog.PtBr.name() 14 | "Simba" 15 | iex> Faker.Dog.PtBr.name() 16 | "Max" 17 | iex> Faker.Dog.PtBr.name() 18 | "Malu" 19 | iex> Faker.Dog.PtBr.name() 20 | "Mike" 21 | """ 22 | @spec name() :: String.t() 23 | sampler(:name, [ 24 | "Amora", 25 | "Belinha", 26 | "Bela", 27 | "Bidu", 28 | "Billy", 29 | "Bob", 30 | "Boris", 31 | "Bruce", 32 | "Buddy", 33 | "Cacau", 34 | "Chanel", 35 | "Chico", 36 | "Cindy", 37 | "Fiona", 38 | "Fred", 39 | "Frederico", 40 | "Frida", 41 | "Iracema", 42 | "Jack", 43 | "Jade", 44 | "Kiara", 45 | "Lara", 46 | "Lili", 47 | "Lilica", 48 | "Lola", 49 | "Lua", 50 | "Luke", 51 | "Luna", 52 | "Malu", 53 | "Marley", 54 | "Max", 55 | "Maya", 56 | "Meg", 57 | "Mike", 58 | "Nick", 59 | "Nina", 60 | "Ozzy", 61 | "Pandora", 62 | "Pingo", 63 | "Princesa", 64 | "Scooby", 65 | "Simba", 66 | "Sofia", 67 | "Theo", 68 | "Thor", 69 | "Tobias", 70 | "Toddy", 71 | "Zeca", 72 | "Zeus" 73 | ]) 74 | 75 | @doc """ 76 | Returns a dog breed. 77 | 78 | ## Examples 79 | 80 | iex> Faker.Dog.PtBr.breed() 81 | "Boxer" 82 | iex> Faker.Dog.PtBr.breed() 83 | "Schnauzer" 84 | iex> Faker.Dog.PtBr.breed() 85 | "Lhasa apso" 86 | iex> Faker.Dog.PtBr.breed() 87 | "Fila brasileiro" 88 | """ 89 | @spec breed() :: String.t() 90 | sampler(:breed, [ 91 | "Akita", 92 | "Basset hound", 93 | "Beagle", 94 | "Bichon frisé", 95 | "Boiadeiro australiano", 96 | "Border collie", 97 | "Boston terrier", 98 | "Boxer", 99 | "Buldogue francês", 100 | "Buldogue inglês", 101 | "Bull terrier", 102 | "Cane corso", 103 | "Cavalier king charles spaniel", 104 | "Chihuahua", 105 | "Chow chow", 106 | "Cocker spaniel inglês", 107 | "Dachshund", 108 | "Dálmata", 109 | "Doberman", 110 | "Dogo argentino", 111 | "Dogue alemão", 112 | "Fila brasileiro", 113 | "Golden retriever", 114 | "Husky siberiano", 115 | "Jack russell terrier", 116 | "Labrador retriever", 117 | "Lhasa apso", 118 | "Lulu da pomerânia", 119 | "Maltês", 120 | "Mastiff inglês", 121 | "Mastim tibetano", 122 | "Pastor alemão", 123 | "Pastor australiano", 124 | "Pastor de Shetland", 125 | "Pequinês", 126 | "Pinscher", 127 | "Pit bull", 128 | "Poodle", 129 | "Pug", 130 | "Rottweiler", 131 | "Schnauzer", 132 | "Shar-pei", 133 | "Shiba", 134 | "Shih tzu", 135 | "Staffordshire bull terrier", 136 | "Weimaraner", 137 | "Yorkshire" 138 | ]) 139 | 140 | @doc """ 141 | Returns a characteristic of a dog. 142 | 143 | ## Examples 144 | 145 | iex> Faker.Dog.PtBr.characteristic() 146 | "Atlético, protetor e amável" 147 | iex> Faker.Dog.PtBr.characteristic() 148 | "Independente, reservado e inteligente" 149 | iex> Faker.Dog.PtBr.characteristic() 150 | "Amigável, trabalhador e extrovertido" 151 | iex> Faker.Dog.PtBr.characteristic() 152 | "Calmo, leal e orgulhoso" 153 | """ 154 | @spec characteristic() :: String.t() 155 | sampler(:characteristic, [ 156 | "Alegre, carinhoso e cheio de vida", 157 | "Alegre, companheiro e aventureiro", 158 | "Amigável, inteligente e vivaz", 159 | "Amigável, trabalhador e extrovertido", 160 | "Amoroso, temperamental e companheiro", 161 | "Animado, inteligente e cheio de personalidade", 162 | "Atlético, protetor e amável", 163 | "Brincalhão, energético e esperto", 164 | "Calmo, leal e orgulhoso", 165 | "Carinhoso, brincalhão e encantador", 166 | "Carinhoso, leal e brincalhão", 167 | "Charmoso, animado e atrevido", 168 | "Companheiro, alegre e afetuoso", 169 | "Corajoso, animado e inteligente", 170 | "Destemido, carinhoso e cheio de energia", 171 | "Esperto, confiante e independente", 172 | "Gentil, brincalhão e afetuoso", 173 | "Independente, reservado e inteligente", 174 | "Inteligente, brincalhão e leal", 175 | "Leal, amigo e brincalhão", 176 | "Orgulhoso, ativo e inteligente", 177 | "Paciente, teimoso e charmoso", 178 | "Protetor, leal e inteligente", 179 | "Travesso, brincalhão e leal" 180 | ]) 181 | end 182 | -------------------------------------------------------------------------------- /lib/faker/finance.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Finance do 2 | @moduledoc """ 3 | Functions for generating financial data 4 | """ 5 | end 6 | -------------------------------------------------------------------------------- /lib/faker/finance/stock.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Finance.Stock do 2 | alias Faker.Util 3 | 4 | @moduledoc """ 5 | Functions for stock data 6 | """ 7 | 8 | @doc """ 9 | Returns a ticker. 10 | 11 | ## Examples 12 | 13 | iex> Faker.Finance.Stock.ticker() 14 | "7401.N225" 15 | iex> Faker.Finance.Stock.ticker() 16 | "4786.HK" 17 | iex> Faker.Finance.Stock.ticker() 18 | "6766.N225" 19 | iex> Faker.Finance.Stock.ticker() 20 | "5166.N225" 21 | """ 22 | @spec ticker() :: String.t() 23 | def ticker do 24 | code = :reuters 25 | exchange = [:nikkei225, :sehk] |> Util.pick() 26 | ticker(code, exchange) 27 | end 28 | 29 | @doc """ 30 | The first argument is the ticker format. 31 | The second argument is the name of the exchange. 32 | 33 | ## Examples 34 | 35 | iex> Faker.Finance.Stock.ticker(:reuters, :nikkei225) 36 | "2110.N225" 37 | iex> Faker.Finance.Stock.ticker(:reuters, :nikkei225) 38 | "7401.N225" 39 | iex> Faker.Finance.Stock.ticker(:reuters, :nikkei225) 40 | "9835.N225" 41 | iex> Faker.Finance.Stock.ticker(:reuters, :nikkei225) 42 | "8304.N225" 43 | iex> Faker.Finance.Stock.ticker(:reuters, :sehk) 44 | "7564.HK" 45 | iex> Faker.Finance.Stock.ticker(:reuters, :sehk) 46 | "3609.HK" 47 | iex> Faker.Finance.Stock.ticker(:reuters, :sehk) 48 | "1085.HK" 49 | iex> Faker.Finance.Stock.ticker(:reuters, :sehk) 50 | "5849.HK" 51 | """ 52 | def ticker(:reuters, :nikkei225) do 53 | "#{Faker.random_between(1000, 9999)}.N225" 54 | end 55 | 56 | def ticker(:reuters, :sehk) do 57 | stock_str = 58 | Faker.random_between(1, 8999) 59 | |> Integer.to_string() 60 | |> String.pad_leading(4, ["0"]) 61 | 62 | "#{stock_str}.HK" 63 | end 64 | end 65 | -------------------------------------------------------------------------------- /lib/faker/food.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Food do 2 | import Faker, only: [localize: 1] 3 | 4 | @moduledoc """ 5 | Functions for generating food data. 6 | """ 7 | 8 | @doc """ 9 | Returns a random complete dish. 10 | 11 | ## Examples 12 | 13 | iex> Faker.Food.dish() 14 | "Vegetable Soup" 15 | iex> Faker.Food.dish() 16 | "Fish and chips" 17 | iex> Faker.Food.dish() 18 | "Pork belly buns" 19 | iex> Faker.Food.dish() 20 | "Pasta Carbonara" 21 | """ 22 | @spec dish() :: String.t() 23 | localize(:dish) 24 | 25 | @doc """ 26 | Returns a random description. 27 | 28 | ## Examples 29 | 30 | iex> Faker.Food.description() 31 | "Two buttermilk waffles, topped with whipped cream and maple syrup, a side of two eggs served any style, and your choice of smoked bacon or smoked ham." 32 | iex> Faker.Food.description() 33 | "28-day aged 300g USDA Certified Prime Ribeye, rosemary-thyme garlic butter, with choice of two sides." 34 | iex> Faker.Food.description() 35 | "Breaded fried chicken with waffles, and a side of maple syrup." 36 | iex> Faker.Food.description() 37 | "Creamy mascarpone cheese and custard layered between espresso and rum soaked house-made ladyfingers, topped with Valrhona cocoa powder." 38 | """ 39 | @spec description() :: String.t() 40 | localize(:description) 41 | 42 | @doc """ 43 | Returns a random ingredient. 44 | 45 | ## Examples 46 | 47 | iex> Faker.Food.ingredient() 48 | "Tomatoes" 49 | iex> Faker.Food.ingredient() 50 | "Albacore Tuna" 51 | iex> Faker.Food.ingredient() 52 | "Potatoes" 53 | iex> Faker.Food.ingredient() 54 | "Tinned" 55 | """ 56 | @spec ingredient() :: String.t() 57 | localize(:ingredient) 58 | 59 | @doc """ 60 | Returns a random spicy ingredient. 61 | 62 | ## Examples 63 | 64 | iex> Faker.Food.spice() 65 | "Garlic Salt" 66 | iex> Faker.Food.spice() 67 | "Ras-el-Hanout" 68 | iex> Faker.Food.spice() 69 | "Curry Hot" 70 | iex> Faker.Food.spice() 71 | "Peppercorns Mixed" 72 | """ 73 | @spec spice() :: String.t() 74 | localize(:spice) 75 | 76 | @doc """ 77 | Returns a random measurement. 78 | 79 | ## Examples 80 | 81 | iex> Faker.Food.measurement() 82 | "teaspoon" 83 | iex> Faker.Food.measurement() 84 | "gallon" 85 | iex> Faker.Food.measurement() 86 | "pint" 87 | iex> Faker.Food.measurement() 88 | "cup" 89 | """ 90 | @spec measurement() :: String.t() 91 | localize(:measurement) 92 | 93 | @doc """ 94 | Returns a random measurement size. 95 | 96 | ## Examples 97 | 98 | iex> Faker.Food.measurement_size() 99 | "1/4" 100 | iex> Faker.Food.measurement_size() 101 | "3" 102 | iex> Faker.Food.measurement_size() 103 | "1" 104 | iex> Faker.Food.measurement_size() 105 | "1/2" 106 | """ 107 | @spec measurement_size() :: String.t() 108 | localize(:measurement_size) 109 | 110 | @doc """ 111 | Returns a random metric measurement. 112 | 113 | ## Examples 114 | 115 | iex> Faker.Food.metric_measurement() 116 | "centiliter" 117 | iex> Faker.Food.metric_measurement() 118 | "deciliter" 119 | iex> Faker.Food.metric_measurement() 120 | "liter" 121 | iex> Faker.Food.metric_measurement() 122 | "milliliter" 123 | """ 124 | @spec metric_measurement() :: String.t() 125 | localize(:metric_measurement) 126 | 127 | @doc """ 128 | Returns a type of sushi. 129 | 130 | ## Examples 131 | 132 | iex> Faker.Food.sushi() 133 | "Whitespotted conger" 134 | iex> Faker.Food.sushi() 135 | "Japanese horse mackerel" 136 | iex> Faker.Food.sushi() 137 | "Salmon" 138 | iex> Faker.Food.sushi() 139 | "Octopus" 140 | """ 141 | @spec sushi() :: String.t() 142 | localize(:sushi) 143 | end 144 | -------------------------------------------------------------------------------- /lib/faker/fruit/en.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Fruit.En do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Functions for fruit data in English. 6 | """ 7 | 8 | @doc """ 9 | Returns a fruit. 10 | ## Examples 11 | iex> Faker.Fruit.En.fruit() 12 | "Kiwano" 13 | iex> Faker.Fruit.En.fruit() 14 | "Sugarcane" 15 | iex> Faker.Fruit.En.fruit() 16 | "Pineapple" 17 | iex> Faker.Fruit.En.fruit() 18 | "Lemon" 19 | """ 20 | @spec fruit() :: String.t() 21 | sampler(:fruit, [ 22 | "Apple", 23 | "Apricot", 24 | "Avocado", 25 | "Banana", 26 | "Black currant", 27 | "Blackberry", 28 | "Blueberry", 29 | "Carambola", 30 | "Cashew apple", 31 | "Cherry", 32 | "Cloudberry", 33 | "Coconut", 34 | "Cranberry", 35 | "Custard apple", 36 | "Damson", 37 | "Dragonfruit", 38 | "Elderberry", 39 | "Fig", 40 | "Feijoa", 41 | "Goji berry", 42 | "Grapes", 43 | "Grapefruit", 44 | "Grewia", 45 | "Guava", 46 | "Hanepoot", 47 | "Huckleberry", 48 | "Jackfruit", 49 | "Jamun", 50 | "Jicama", 51 | "Jujube", 52 | "Kiwano", 53 | "Kiwi", 54 | "Lemon", 55 | "Longan", 56 | "Loquat", 57 | "Lychee", 58 | "Mango", 59 | "Malay apple", 60 | "Melon", 61 | "Monk fruit", 62 | "Mulberry", 63 | "Muskmelon", 64 | "Nance", 65 | "Olive", 66 | "Orange", 67 | "Palm fruit", 68 | "Papaya", 69 | "Passion fruit", 70 | "Peach", 71 | "Pear", 72 | "Persimmon", 73 | "Pineapple", 74 | "Plum", 75 | "Pomegranate", 76 | "Prickly pear", 77 | "Pumpkin", 78 | "Quince", 79 | "Raspberry", 80 | "Red currant", 81 | "Sapodilla", 82 | "Satsuma", 83 | "Shaddock", 84 | "Soursop", 85 | "Spanish cherry", 86 | "Strawberry", 87 | "Sugarcane", 88 | "Surinam cherry", 89 | "Sweet lemon", 90 | "Tamarillo", 91 | "Tamarind", 92 | "Tangerine", 93 | "Watermelon" 94 | ]) 95 | end 96 | -------------------------------------------------------------------------------- /lib/faker/fruit/pt_br.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Fruit.PtBr do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Functions for fruit data in Brazilian Portuguese. 6 | """ 7 | 8 | @doc """ 9 | Returns a fruit. 10 | 11 | ## Examples 12 | 13 | iex> Faker.Fruit.PtBr.fruit() 14 | "Fruta-do-conde" 15 | iex> Faker.Fruit.PtBr.fruit() 16 | "Bergamota" 17 | iex> Faker.Fruit.PtBr.fruit() 18 | "Quixaba" 19 | iex> Faker.Fruit.PtBr.fruit() 20 | "Amora" 21 | """ 22 | @spec fruit() :: String.t() 23 | sampler(:fruit, [ 24 | "Abacaxi", 25 | "Ananá", 26 | "Amora", 27 | "Açaí", 28 | "Abacate", 29 | "Acerola", 30 | "Ameixa", 31 | "Ackee", 32 | "Araticum", 33 | "Araçá", 34 | "Banana", 35 | "Bergamota", 36 | "Baru", 37 | "Bacuri", 38 | "Bacuripari", 39 | "Babaçu", 40 | "Butiá", 41 | "Coco", 42 | "Cereja", 43 | "Caju", 44 | "Caqui", 45 | "Carambola", 46 | "Cupuaçu", 47 | "Ciriguela", 48 | "Cacau", 49 | "Damasco", 50 | "Dendê", 51 | "Esfregadinha", 52 | "Escropari", 53 | "Framboesa", 54 | "Fruta-do-conde", 55 | "Figo", 56 | "Feijoa", 57 | "Fruta-pão", 58 | "Goiaba", 59 | "Graviola", 60 | "Groselha", 61 | "Guaraná", 62 | "Guabiroba", 63 | "Hilocéreo", 64 | "Imbu", 65 | "Jenipapo", 66 | "Jabuticaba", 67 | "Jaca", 68 | "Jambo", 69 | "Jamelão", 70 | "Jatobá", 71 | "Kiwi", 72 | "Limão", 73 | "Laranja", 74 | "Lima", 75 | "Mamão", 76 | "Maçã", 77 | "Manga", 78 | "Morango", 79 | "Mertilo", 80 | "Maracujá", 81 | "Melão", 82 | "Melancia", 83 | "Mexirica", 84 | "Nectarina", 85 | "Noz-pecã", 86 | "Pera", 87 | "Pêssego", 88 | "Pitanga", 89 | "Pitaia", 90 | "Pitomba", 91 | "Pequi", 92 | "Quina", 93 | "Quixaba", 94 | "Romã", 95 | "Seriguela", 96 | "Tangerina", 97 | "Tâmara", 98 | "Tucumã", 99 | "Uva", 100 | "Xixá", 101 | "Zimbro" 102 | ]) 103 | end 104 | -------------------------------------------------------------------------------- /lib/faker/gov/it.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Gov.It do 2 | @moduledoc """ 3 | Functions for data created/released by the Italian government, 4 | like fiscal codes 5 | """ 6 | 7 | require Integer 8 | 9 | alias Faker.Util 10 | 11 | @doc """ 12 | Returns a random Italian fiscal code 13 | 14 | ## Examples 15 | 16 | iex> Faker.Gov.It.fiscal_id() 17 | "ELRCEA64C50A918F" 18 | iex> Faker.Gov.It.fiscal_id() 19 | "ZSLNKH22M34H480J" 20 | iex> Faker.Gov.It.fiscal_id() 21 | "OCPCVO90M50F353I" 22 | iex> Faker.Gov.It.fiscal_id() 23 | "PQYRFX94R54C681K" 24 | """ 25 | @spec fiscal_id() :: binary() 26 | def fiscal_id do 27 | surname() 28 | |> Kernel.<>(name()) 29 | |> Kernel.<>(birth_year()) 30 | |> Kernel.<>(birth_month()) 31 | |> Kernel.<>(birth_day()) 32 | |> Kernel.<>(town_code_letter()) 33 | |> Kernel.<>(town_code_numbers()) 34 | |> (&Kernel.<>(&1, cin(&1))).() 35 | end 36 | 37 | defp surname do 38 | Util.join(3, &Util.upper_letter/0) 39 | end 40 | 41 | defp name do 42 | Util.join(3, &Util.upper_letter/0) 43 | end 44 | 45 | defp birth_year do 46 | 0 47 | |> Faker.random_between(99) 48 | |> Integer.to_string() 49 | |> String.pad_leading(2, "0") 50 | end 51 | 52 | defp birth_month do 53 | Util.pick(~w(A B C D E H L M P R S T)) 54 | end 55 | 56 | defp birth_day do 57 | 1..71 58 | |> Util.pick() 59 | |> Integer.to_string() 60 | |> String.pad_leading(2, "0") 61 | end 62 | 63 | defp town_code_letter do 64 | Util.pick(~w(A B C D E F G H I L M Z)) 65 | end 66 | 67 | defp town_code_numbers do 68 | Faker.random_between(0, 999) 69 | |> Integer.to_string() 70 | |> String.pad_leading(3, "0") 71 | end 72 | 73 | defp cin(input) do 74 | {left, right} = 75 | input 76 | |> String.codepoints() 77 | |> Enum.with_index() 78 | |> Enum.reduce({0, 0}, fn {letter, index}, {acc_even, acc_odd} -> 79 | case Integer.is_even(index) do 80 | true -> {acc_even + cin_even(letter), acc_odd} 81 | false -> {acc_even, acc_odd + cin_odd(letter)} 82 | end 83 | end) 84 | 85 | Enum.at( 86 | ~w(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z), 87 | Integer.mod(left + right, 26) 88 | ) 89 | end 90 | 91 | defp cin_even("0"), do: 0 92 | defp cin_even("1"), do: 1 93 | defp cin_even("2"), do: 2 94 | defp cin_even("3"), do: 3 95 | defp cin_even("4"), do: 4 96 | defp cin_even("5"), do: 5 97 | defp cin_even("6"), do: 6 98 | defp cin_even("7"), do: 7 99 | defp cin_even("8"), do: 8 100 | defp cin_even("9"), do: 9 101 | defp cin_even("A"), do: 0 102 | defp cin_even("B"), do: 1 103 | defp cin_even("C"), do: 2 104 | defp cin_even("D"), do: 3 105 | defp cin_even("E"), do: 4 106 | defp cin_even("F"), do: 5 107 | defp cin_even("G"), do: 6 108 | defp cin_even("H"), do: 7 109 | defp cin_even("I"), do: 8 110 | defp cin_even("J"), do: 9 111 | defp cin_even("K"), do: 10 112 | defp cin_even("L"), do: 11 113 | defp cin_even("M"), do: 12 114 | defp cin_even("N"), do: 13 115 | defp cin_even("O"), do: 14 116 | defp cin_even("P"), do: 15 117 | defp cin_even("Q"), do: 16 118 | defp cin_even("R"), do: 17 119 | defp cin_even("S"), do: 18 120 | defp cin_even("T"), do: 19 121 | defp cin_even("U"), do: 20 122 | defp cin_even("V"), do: 21 123 | defp cin_even("W"), do: 22 124 | defp cin_even("X"), do: 23 125 | defp cin_even("Y"), do: 24 126 | defp cin_even("Z"), do: 25 127 | 128 | defp cin_odd("0"), do: 1 129 | defp cin_odd("1"), do: 0 130 | defp cin_odd("2"), do: 5 131 | defp cin_odd("3"), do: 7 132 | defp cin_odd("4"), do: 9 133 | defp cin_odd("5"), do: 13 134 | defp cin_odd("6"), do: 15 135 | defp cin_odd("7"), do: 17 136 | defp cin_odd("8"), do: 19 137 | defp cin_odd("9"), do: 21 138 | defp cin_odd("A"), do: 1 139 | defp cin_odd("B"), do: 0 140 | defp cin_odd("C"), do: 5 141 | defp cin_odd("D"), do: 7 142 | defp cin_odd("E"), do: 9 143 | defp cin_odd("F"), do: 13 144 | defp cin_odd("G"), do: 15 145 | defp cin_odd("H"), do: 17 146 | defp cin_odd("I"), do: 19 147 | defp cin_odd("J"), do: 21 148 | defp cin_odd("K"), do: 2 149 | defp cin_odd("L"), do: 4 150 | defp cin_odd("M"), do: 18 151 | defp cin_odd("N"), do: 20 152 | defp cin_odd("O"), do: 11 153 | defp cin_odd("P"), do: 3 154 | defp cin_odd("Q"), do: 6 155 | defp cin_odd("R"), do: 8 156 | defp cin_odd("S"), do: 12 157 | defp cin_odd("T"), do: 14 158 | defp cin_odd("U"), do: 16 159 | defp cin_odd("V"), do: 10 160 | defp cin_odd("W"), do: 22 161 | defp cin_odd("X"), do: 25 162 | defp cin_odd("Y"), do: 24 163 | defp cin_odd("Z"), do: 23 164 | end 165 | -------------------------------------------------------------------------------- /lib/faker/gov/us.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Gov.Us do 2 | @moduledoc """ 3 | Generating US Taxpayer Identification numbers 4 | """ 5 | 6 | @doc """ 7 | Returns a random US Social Security number 8 | 9 | ## Examples 10 | 11 | iex> Faker.Gov.Us.ssn() 12 | "838-84-5749" 13 | iex> Faker.Gov.Us.ssn() 14 | "719-41-8674" 15 | iex> Faker.Gov.Us.ssn() 16 | "213-54-3766" 17 | iex> Faker.Gov.Us.ssn() 18 | "379-09-6851" 19 | """ 20 | @spec ssn() :: String.t() 21 | def ssn do 22 | "#{ssn_area()}-#{ssn_group()}-#{ssn_serial()}" 23 | end 24 | 25 | defp ssn_area do 26 | case "#{Faker.random_between(1, 899)}" do 27 | "666" -> "667" 28 | n -> n |> String.pad_leading(3, "0") 29 | end 30 | end 31 | 32 | defp ssn_group, do: "#{Faker.random_between(1, 99)}" |> String.pad_leading(2, "0") 33 | defp ssn_serial, do: "#{Faker.random_between(1, 9999)}" |> String.pad_leading(4, "0") 34 | 35 | @doc """ 36 | Returns a random Employer Identification Number 37 | 38 | ## Examples 39 | 40 | iex> Faker.Gov.Us.ein() 41 | "04-0389586" 42 | iex> Faker.Gov.Us.ein() 43 | "07-8027034" 44 | iex> Faker.Gov.Us.ein() 45 | "41-6859447" 46 | iex> Faker.Gov.Us.ein() 47 | "83-6106581" 48 | """ 49 | @spec ein() :: String.t() 50 | def ein do 51 | "#{ein_campus()}-#{ein_serial()}" 52 | end 53 | 54 | defp ein_campus, do: "#{Faker.random_between(1, 99)}" |> String.pad_leading(2, "0") 55 | defp ein_serial, do: "#{Faker.random_between(1, 9_999_999)}" |> String.pad_leading(7, "0") 56 | end 57 | -------------------------------------------------------------------------------- /lib/faker/industry.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Industry do 2 | import Faker, only: [localize: 1] 3 | 4 | @moduledoc """ 5 | Functions for generating Industry related data 6 | Reference https://en.wikipedia.org/wiki/Industry_Classification_Benchmark 7 | """ 8 | 9 | @doc """ 10 | Returns a Industry name string 11 | 12 | ## Examples 13 | 14 | iex> Faker.Industry.industry() 15 | "Oil & Gas" 16 | iex> Faker.Industry.industry() 17 | "Basic Materials" 18 | iex> Faker.Industry.industry() 19 | "Consumer Services" 20 | iex> Faker.Industry.industry() 21 | "Health Care" 22 | """ 23 | @spec industry() :: String.t() 24 | localize(:industry) 25 | 26 | @doc """ 27 | Returns a Super Sector name string 28 | 29 | ## Examples 30 | 31 | iex> Faker.Industry.super_sector() 32 | "Automobiles & Parts" 33 | iex> Faker.Industry.super_sector() 34 | "Banks" 35 | iex> Faker.Industry.super_sector() 36 | "Automobiles & Parts" 37 | iex> Faker.Industry.super_sector() 38 | "Health Care" 39 | """ 40 | @spec super_sector() :: String.t() 41 | localize(:super_sector) 42 | 43 | @doc """ 44 | Returns a Sector name string 45 | 46 | ## Examples 47 | 48 | iex> Faker.Industry.sector() 49 | "Food & Drug Retailers" 50 | iex> Faker.Industry.sector() 51 | "Banks" 52 | iex> Faker.Industry.sector() 53 | "Software & Computer Services" 54 | iex> Faker.Industry.sector() 55 | "Media" 56 | """ 57 | @spec sector() :: String.t() 58 | localize(:sector) 59 | 60 | @doc """ 61 | Returns a Sub Sector name string 62 | 63 | ## Examples 64 | 65 | iex> Faker.Industry.sub_sector() 66 | "Electrical Components & Equipment" 67 | iex> Faker.Industry.sub_sector() 68 | "Publishing" 69 | iex> Faker.Industry.sub_sector() 70 | "Alternative Electricity" 71 | iex> Faker.Industry.sub_sector() 72 | "Forestry" 73 | """ 74 | @spec sub_sector() :: String.t() 75 | localize(:sub_sector) 76 | end 77 | -------------------------------------------------------------------------------- /lib/faker/industry/hy.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Industry.Hy do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Functions for generating industry related data in Armenian 6 | """ 7 | 8 | @doc """ 9 | Returns an industry name. 10 | 11 | ## Examples 12 | 13 | iex> Faker.Industry.Hy.industry() 14 | "Հյուրընկալություն" 15 | iex> Faker.Industry.Hy.industry() 16 | "Բժշկական Գործունեություն" 17 | iex> Faker.Industry.Hy.industry() 18 | "Վենչուրային և Մասնավոր Կապիտալ" 19 | iex> Faker.Industry.Hy.industry() 20 | "Էներգետիկա" 21 | """ 22 | @spec industry() :: String.t() 23 | sampler(:industry, [ 24 | "Պաշտպանություն", 25 | "Համակարգչային Տեխնիկա", 26 | "Համակարգչային Ծրագրեր", 27 | "Համակարգչային Ցանցեր", 28 | "Համացանց", 29 | "Կիսահաղորդիչներ", 30 | "Հեռահաղորդակցություն", 31 | "Իրավական Գործառույթներ", 32 | "Իրավաբանական Ծառայություններ", 33 | "Կառավարման Խորհրդատվություն", 34 | "Կենսատեխնոլոգիա", 35 | "Բժշկական Գործունեություն", 36 | "Հիվանդանոց և Առողջապահություն", 37 | "Դեղագործություն", 38 | "Անասնաբուժություն", 39 | "Բժշկական Սարքավորումներ", 40 | "Կոսմետիկա", 41 | "Հագուստ և Նորաձևություն", 42 | "Սպորտային Ապրանքներ", 43 | "Ծխախոտագործություն", 44 | "Սուպերմարկետներ", 45 | "Սննդի Արտադրություն", 46 | "Սպառողական Էլեկտրոնիկա", 47 | "Սպառողական Ապրանքներ", 48 | "Կահույք", 49 | "Մանրածախ Առևտուր", 50 | "Զվարճանք", 51 | "Դրամախաղ և Խաղատներ", 52 | "Ժամանց", 53 | "Ճանապարհորդություն և Տուրիզմ", 54 | "Հյուրընկալություն", 55 | "Ռեստորաններ", 56 | "Սպորտաձևեր", 57 | "Սննդամթերք և Ըմպելիքներ", 58 | "Կինոնկարներ", 59 | "Հեռարձակվող Մեդիա", 60 | "Թանգարաններ", 61 | "Կատարողական Արվեստ", 62 | "Ժամանցի Հարմարություններ և Ծառայություններ", 63 | "Բանկային Գործունեություն", 64 | "Ապահովագրություն", 65 | "Ֆինանսական Ծառայություններ", 66 | "Անշարժ Գույք", 67 | "Ներդրումային Բանկային Ծառայություններ", 68 | "Ներդրումային Կառավարում", 69 | "Հաշվապահություն", 70 | "Շինարարություն", 71 | "Շինանյութեր", 72 | "Ճարտարապետություն և Պլանավորում", 73 | "Քաղաքացիական Շինարարություն", 74 | "Քիմիական Նյութեր", 75 | "Մեքենաներ", 76 | "Հանքարդյունաբերություն և Մետաղներ", 77 | "Նավթարդյունաբերություն", 78 | "Էներգետիկա", 79 | "Նավաշինություն", 80 | "Կոմունալ Ծառայություններ", 81 | "Տեքստիլ Արդյունաբերություն", 82 | "Թուղթ և Անտառային Ապրանքներ", 83 | "Երկաթուղու Արտադրություն", 84 | "Հողագործություն", 85 | "Անասնապահություն", 86 | "Կաթնամթերք", 87 | "Ձկնորսություն", 88 | "Միջնակարգ Կրթություն", 89 | "Բարձրագույն Կրթություն", 90 | "Կրթության Կառավարում", 91 | "Հետազոտություն", 92 | "Ռազմական Գործ", 93 | "Օրենսդրական Գրասենյակ", 94 | "Դատարան", 95 | "Միջազգային Հարաբերություններ", 96 | "Կառավարության Ղեկավարում", 97 | "Իրավապահ Համակարգ", 98 | "Հանրային Անվտանգություն", 99 | "Հանրային Քաղաքականություն", 100 | "Մարկետինգ և Գովազդ", 101 | "Թերթեր", 102 | "Հրատարակչություն", 103 | "Տպագրություն", 104 | "Տեղեկատվական Ծառայություններ", 105 | "Գրադարաններ", 106 | "Բեռնափոխադրումներ", 107 | "Անհատական և Ընտանեկան Ծառայություններ", 108 | "Կրոնական Հաստատություններ", 109 | "Քաղաքացիական և Սոցիալական Կազմակերպություն", 110 | "Սպառողական Ծառայություններ", 111 | "Երկաթուղի", 112 | "Պահեստավորում", 113 | "Ավիացիա", 114 | "Տեղեկատվական Տեխնոլոգիաներ և Ծառայություններ", 115 | "Շուկայի ՈՒսումնասիրություն", 116 | "Հասարակայնության Հետ Կապեր և Հաղորդակցություն", 117 | "Դիզայն", 118 | "Մասնագիտական Վերապատրաստում", 119 | "Վենչուրային և Մասնավոր Կապիտալ", 120 | "Թարգմանություն և Տեղայնացում", 121 | "Համակարգչային Խաղեր", 122 | "Իրադարձությունների Կազմակերպում", 123 | "Արվեստ և Արհեստ", 124 | "Էլեկտրական և Էլեկտրոնային Արտադրություն", 125 | "Առցանց Լրատվամիջոցներ", 126 | "Նանոտեխնոլոգիա", 127 | "Երաժշտություն", 128 | "Լոգիստիկա և Մատակարարում", 129 | "Համակարգչային և Ցանցային Անվտանգություն", 130 | "Անլար Տեխնոլոգիաներ", 131 | "Անվտանգություն և Հետաքննություն", 132 | "Ծառայությունների Մատուցում", 133 | "Աութսորսինգ և Օֆշորային Ծառայություններ", 134 | "Այլընտրանքային Բժշկություն", 135 | "Մեդիա Արտադրանք", 136 | "Կապիտալի Շուկաներ", 137 | "Բարեգործություն", 138 | "Մեծածախ Առևտուր", 139 | "Ներմուծում և Արտահանում", 140 | "Մեխանիկական կամ Արդյունաբերական Ճարտարագիտություն", 141 | "Լուսանկարչություն", 142 | "Մարդկային Ռեսուրսներ", 143 | "Բիզնես Սարքավորումներ", 144 | "Հոգեկան Առողջության Խնամք", 145 | "Գրաֆիկական Դիզայն", 146 | "Միջազգային Առևտուր և Զարգացում", 147 | "Ալկոհոլային Խմիչքներ", 148 | "Պերճանքի Առարկաներ և Ոսկերչական Իրեր", 149 | "Շրջակա Միջավայրի Պահպանություն", 150 | "Ապակի և Կերամիկա", 151 | "Փաթեթավորում և Բեռնարկղեր", 152 | "Արդյունաբերական Ավտոմատացում", 153 | "Կառավարական Հարաբերություններ" 154 | ]) 155 | end 156 | -------------------------------------------------------------------------------- /lib/faker/internet/en.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Internet.En do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Generating internet related data in English 6 | """ 7 | 8 | @doc """ 9 | Returns a random free email service name 10 | 11 | ## Examples 12 | 13 | iex> Faker.Internet.En.free_email_service() 14 | "gmail.com" 15 | iex> Faker.Internet.En.free_email_service() 16 | "hotmail.com" 17 | iex> Faker.Internet.En.free_email_service() 18 | "gmail.com" 19 | iex> Faker.Internet.En.free_email_service() 20 | "hotmail.com" 21 | """ 22 | @spec free_email_service() :: String 23 | sampler(:free_email_service, ["gmail.com", "yahoo.com", "hotmail.com"]) 24 | 25 | @doc """ 26 | Returns a random domain suffix 27 | 28 | ## Examples 29 | 30 | iex> Faker.Internet.En.domain_suffix() 31 | "com" 32 | iex> Faker.Internet.En.domain_suffix() 33 | "org" 34 | iex> Faker.Internet.En.domain_suffix() 35 | "name" 36 | iex> Faker.Internet.En.domain_suffix() 37 | "info" 38 | """ 39 | @spec domain_suffix() :: String.t() 40 | sampler(:domain_suffix, ["com", "biz", "info", "name", "net", "org"]) 41 | end 42 | -------------------------------------------------------------------------------- /lib/faker/internet/es.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Internet.Es do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Generating internet related data in Spanish 6 | """ 7 | 8 | @doc """ 9 | Returns a random free email service name 10 | 11 | ## Examples 12 | 13 | iex> Faker.Internet.Es.free_email_service() 14 | "gmail.com" 15 | iex> Faker.Internet.Es.free_email_service() 16 | "hotmail.com" 17 | iex> Faker.Internet.Es.free_email_service() 18 | "gmail.com" 19 | iex> Faker.Internet.Es.free_email_service() 20 | "hotmail.com" 21 | """ 22 | @spec free_email_service() :: String 23 | sampler(:free_email_service, ["gmail.com", "yahoo.com", "hotmail.com"]) 24 | 25 | @doc """ 26 | Returns a random domain suffix 27 | 28 | ## Examples 29 | 30 | iex> Faker.Internet.Es.domain_suffix() 31 | "com" 32 | iex> Faker.Internet.Es.domain_suffix() 33 | "es" 34 | iex> Faker.Internet.Es.domain_suffix() 35 | "com" 36 | iex> Faker.Internet.Es.domain_suffix() 37 | "org" 38 | """ 39 | @spec domain_suffix() :: String.t() 40 | sampler(:domain_suffix, ["com", "es", "info", "com.es", "org"]) 41 | end 42 | -------------------------------------------------------------------------------- /lib/faker/internet/hy.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Internet.Hy do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Functions for generating internet related data in Armenian 6 | """ 7 | 8 | @doc """ 9 | Returns a random free email service name. 10 | 11 | ## Examples 12 | 13 | iex> Faker.Internet.Hy.free_email_service() 14 | "hotmail.com" 15 | iex> Faker.Internet.Hy.free_email_service() 16 | "yandex.ru" 17 | iex> Faker.Internet.Hy.free_email_service() 18 | "freenet.am" 19 | iex> Faker.Internet.Hy.free_email_service() 20 | "yahoo.com" 21 | """ 22 | @spec free_email_service() :: String 23 | sampler(:free_email_service, [ 24 | "freenet.am", 25 | "namag.net", 26 | "yandex.ru", 27 | "mail.ru", 28 | "gmail.com", 29 | "yahoo.com", 30 | "hotmail.com" 31 | ]) 32 | 33 | @doc """ 34 | Returns a random domain suffix. 35 | 36 | ## Examples 37 | 38 | iex> Faker.Internet.Hy.domain_suffix() 39 | "am" 40 | iex> Faker.Internet.Hy.domain_suffix() 41 | "com" 42 | iex> Faker.Internet.Hy.domain_suffix() 43 | "am" 44 | iex> Faker.Internet.Hy.domain_suffix() 45 | "org" 46 | """ 47 | @spec domain_suffix() :: String.t() 48 | sampler(:domain_suffix, ["am", "com", "info", "net", "org"]) 49 | end 50 | -------------------------------------------------------------------------------- /lib/faker/internet/it.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Internet.It do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Generating internet related data in Italian 6 | """ 7 | 8 | @doc """ 9 | Returns a random free email service name 10 | 11 | ## Examples 12 | 13 | iex> Faker.Internet.It.free_email_service() 14 | "virgilio.it" 15 | iex> Faker.Internet.It.free_email_service() 16 | "yahoo.it" 17 | iex> Faker.Internet.It.free_email_service() 18 | "aruba.it" 19 | iex> Faker.Internet.It.free_email_service() 20 | "gmail.com" 21 | """ 22 | @spec free_email_service() :: String.t() 23 | sampler(:free_email_service, [ 24 | "gmail.com", 25 | "yahoo.it", 26 | "hotmail.it", 27 | "aruba.it", 28 | "libero.it", 29 | "alice.it", 30 | "virgilio.it", 31 | "tin.it" 32 | ]) 33 | 34 | @doc """ 35 | Returns a random domain suffix 36 | 37 | ## Examples 38 | 39 | iex> Faker.Internet.It.domain_suffix() 40 | "com" 41 | iex> Faker.Internet.It.domain_suffix() 42 | "it" 43 | iex> Faker.Internet.It.domain_suffix() 44 | "com" 45 | iex> Faker.Internet.It.domain_suffix() 46 | "biz" 47 | """ 48 | @spec domain_suffix() :: String.t() 49 | sampler(:domain_suffix, ["com", "it", "info", "org", "biz"]) 50 | end 51 | -------------------------------------------------------------------------------- /lib/faker/internet/pt_br.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Internet.PtBr do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Generating internet related data in Brazilian Portuguese 6 | """ 7 | 8 | @doc """ 9 | Returns a random free email service name 10 | 11 | ## Examples 12 | 13 | iex> Faker.Internet.PtBr.free_email_service() 14 | "gmail.com" 15 | iex> Faker.Internet.PtBr.free_email_service() 16 | "yahoo.com" 17 | iex> Faker.Internet.PtBr.free_email_service() 18 | "gmail.com" 19 | iex> Faker.Internet.PtBr.free_email_service() 20 | "bol.com.br" 21 | """ 22 | @spec free_email_service() :: String 23 | sampler(:free_email_service, ["gmail.com", "yahoo.com", "hotmail.com", "live.com", "bol.com.br"]) 24 | 25 | @doc """ 26 | Returns a random domain suffix 27 | 28 | ## Examples 29 | 30 | iex> Faker.Internet.PtBr.domain_suffix() 31 | "br" 32 | iex> Faker.Internet.PtBr.domain_suffix() 33 | "org" 34 | iex> Faker.Internet.PtBr.domain_suffix() 35 | "name" 36 | iex> Faker.Internet.PtBr.domain_suffix() 37 | "info" 38 | """ 39 | @spec domain_suffix() :: String.t() 40 | sampler(:domain_suffix, ["br", "biz", "info", "name", "net", "org"]) 41 | end 42 | -------------------------------------------------------------------------------- /lib/faker/internet/status_code.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Internet.StatusCode do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Functions for generating HTTP status codes 6 | """ 7 | 8 | @doc """ 9 | Returns an information status code 10 | 11 | ## Examples 12 | 13 | iex> Faker.Internet.StatusCode.information() 14 | 102 15 | iex> Faker.Internet.StatusCode.information() 16 | 101 17 | iex> Faker.Internet.StatusCode.information() 18 | 103 19 | iex> Faker.Internet.StatusCode.information() 20 | 100 21 | """ 22 | @spec information :: 100..103 23 | sampler(:information, [100, 101, 102, 103]) 24 | 25 | @doc """ 26 | Returns a success status code 27 | 28 | ## Examples 29 | 30 | iex> Faker.Internet.StatusCode.success() 31 | 200 32 | iex> Faker.Internet.StatusCode.success() 33 | 201 34 | iex> Faker.Internet.StatusCode.success() 35 | 205 36 | iex> Faker.Internet.StatusCode.success() 37 | 204 38 | """ 39 | @spec success :: 200..208 | 226 40 | sampler(:success, [200, 201, 202, 203, 204, 205, 206, 207, 208, 226]) 41 | 42 | @doc """ 43 | Returns a redirect status code 44 | 45 | ## Examples 46 | 47 | iex> Faker.Internet.StatusCode.redirect() 48 | 303 49 | iex> Faker.Internet.StatusCode.redirect() 50 | 302 51 | iex> Faker.Internet.StatusCode.redirect() 52 | 306 53 | iex> Faker.Internet.StatusCode.redirect() 54 | 305 55 | """ 56 | @spec redirect :: 300..308 57 | sampler(:redirect, [300, 301, 302, 303, 304, 305, 306, 307, 308]) 58 | 59 | @doc """ 60 | Returns a client error status code 61 | 62 | ## Examples 63 | 64 | iex> Faker.Internet.StatusCode.client_error() 65 | 428 66 | iex> Faker.Internet.StatusCode.client_error() 67 | 405 68 | iex> Faker.Internet.StatusCode.client_error() 69 | 424 70 | iex> Faker.Internet.StatusCode.client_error() 71 | 424 72 | """ 73 | @spec client_error :: 400..418 | 421..426 | 428..429 | 431 | 451 74 | sampler(:client_error, [ 75 | 400, 76 | 401, 77 | 402, 78 | 403, 79 | 404, 80 | 405, 81 | 406, 82 | 407, 83 | 408, 84 | 409, 85 | 410, 86 | 411, 87 | 412, 88 | 413, 89 | 414, 90 | 415, 91 | 416, 92 | 417, 93 | 418, 94 | 421, 95 | 422, 96 | 423, 97 | 424, 98 | 425, 99 | 426, 100 | 428, 101 | 429, 102 | 431, 103 | 451 104 | ]) 105 | 106 | @doc """ 107 | Returns a server error status code 108 | 109 | ## Examples 110 | 111 | iex> Faker.Internet.StatusCode.server_error() 112 | 503 113 | iex> Faker.Internet.StatusCode.server_error() 114 | 506 115 | iex> Faker.Internet.StatusCode.server_error() 116 | 506 117 | iex> Faker.Internet.StatusCode.server_error() 118 | 506 119 | """ 120 | @spec server_error :: 500..508 | 510..511 121 | sampler(:server_error, [500, 501, 502, 503, 504, 505, 506, 507, 508, 510, 511]) 122 | end 123 | -------------------------------------------------------------------------------- /lib/faker/lorem/shakespeare.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Lorem.Shakespeare do 2 | import Faker, only: [localize: 1] 3 | 4 | @moduledoc """ 5 | Random quotes from William Shakespeare's plays, sonnets and poems. 6 | """ 7 | 8 | @doc """ 9 | Return random quote from "The Tragedy of Hamlet, Prince of Denmark" tragedy. 10 | 11 | ## Examples 12 | 13 | iex> Faker.Lorem.Shakespeare.hamlet() 14 | "Brevity is the soul of wit." 15 | iex> Faker.Lorem.Shakespeare.hamlet() 16 | "And it must follow, as the night the day, thou canst not then be false to any man." 17 | iex> Faker.Lorem.Shakespeare.hamlet() 18 | "Do you think I am easier to be played on than a pipe?" 19 | iex> Faker.Lorem.Shakespeare.hamlet() 20 | "Rich gifts wax poor when givers prove unkind." 21 | """ 22 | @spec hamlet() :: String.t() 23 | localize(:hamlet) 24 | 25 | @doc """ 26 | Return random quote from "As You Like It" comedy. 27 | 28 | ## Examples 29 | 30 | iex> Faker.Lorem.Shakespeare.as_you_like_it() 31 | "For ever and a day." 32 | iex> Faker.Lorem.Shakespeare.as_you_like_it() 33 | "Can one desire too much of a good thing?." 34 | iex> Faker.Lorem.Shakespeare.as_you_like_it() 35 | "How bitter a thing it is to look into happiness through another man's eyes!" 36 | iex> Faker.Lorem.Shakespeare.as_you_like_it() 37 | "All the world's a stage, and all the men and women merely players. They have their exits and their entrances; And one man in his time plays many parts." 38 | """ 39 | @spec as_you_like_it() :: String.t() 40 | localize(:as_you_like_it) 41 | 42 | @doc """ 43 | Return random quote from "Richard III" play. 44 | 45 | ## Examples 46 | 47 | iex> Faker.Lorem.Shakespeare.king_richard_iii() 48 | "The king's name is a tower of strength." 49 | iex> Faker.Lorem.Shakespeare.king_richard_iii() 50 | "A horse! a horse! my kingdom for a horse!" 51 | iex> Faker.Lorem.Shakespeare.king_richard_iii() 52 | "So wise so young, they say, do never live long." 53 | iex> Faker.Lorem.Shakespeare.king_richard_iii() 54 | "Now is the winter of our discontent." 55 | """ 56 | @spec king_richard_iii() :: String.t() 57 | localize(:king_richard_iii) 58 | 59 | @doc """ 60 | Return random quote from "Romeo and Juliet" tragedy. 61 | 62 | ## Examples 63 | 64 | iex> Faker.Lorem.Shakespeare.romeo_and_juliet() 65 | "What's in a name? That which we call a rose by any other name would smell as sweet." 66 | iex> Faker.Lorem.Shakespeare.romeo_and_juliet() 67 | "For you and I are past our dancing days." 68 | iex> Faker.Lorem.Shakespeare.romeo_and_juliet() 69 | "For you and I are past our dancing days." 70 | iex> Faker.Lorem.Shakespeare.romeo_and_juliet() 71 | "For you and I are past our dancing days." 72 | """ 73 | @spec romeo_and_juliet() :: String.t() 74 | localize(:romeo_and_juliet) 75 | end 76 | -------------------------------------------------------------------------------- /lib/faker/lorem/shakespeare/ru.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Lorem.Shakespeare.Ru do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Random quotes from William Shakespeare's plays, sonnets and poems in Russian. 6 | """ 7 | 8 | @doc """ 9 | Return random quote from "The Tragedy of Hamlet, Prince of Denmark" tragedy. 10 | 11 | ## Examples 12 | 13 | iex> Faker.Lorem.Shakespeare.Ru.hamlet() 14 | "И дальше тишина." 15 | iex> Faker.Lorem.Shakespeare.Ru.hamlet() 16 | "Быть иль не быть, вот в чём вопрос." 17 | iex> Faker.Lorem.Shakespeare.Ru.hamlet() 18 | "Быть иль не быть, вот в чём вопрос." 19 | iex> Faker.Lorem.Shakespeare.Ru.hamlet() 20 | "Быть иль не быть, вот в чём вопрос." 21 | """ 22 | @spec hamlet() :: String.t() 23 | sampler(:hamlet, [ 24 | "Назовите меня любым инструментом, вы можете расстроить меня, но играть на мне нельзя.", 25 | "Есть многое в природе, друг Горацио, что и не снилось нашим мудрецам.", 26 | "Бедный Йорик!", 27 | "И дальше тишина.", 28 | "Как часто нас спасала слепота, Где дальновидность только подводила.", 29 | "Но вижу я, в вас скорби маловато!", 30 | "Быть иль не быть, вот в чём вопрос.", 31 | "О, что за гордый ум сражён!", 32 | "О женщины, вам имя — вероломство!", 33 | "Пример примерных — пал, пал до конца.", 34 | "Мне жизнь моя дешевле, чем булавка, А что он сделает моей душе, Когда она бессмертна, как и он?" 35 | ]) 36 | 37 | @doc """ 38 | Return random quote from "As You Like It" comedy. 39 | 40 | ## Examples 41 | 42 | iex> Faker.Lorem.Shakespeare.Ru.as_you_like_it() 43 | "Дурак думает, что он умен; умный же знает, что глуп он." 44 | iex> Faker.Lorem.Shakespeare.Ru.as_you_like_it() 45 | "Весь мир — театр. В нем женщины, мужчины — все актеры. У них свои есть выходы, уходы, и каждый не одну играет роль." 46 | iex> Faker.Lorem.Shakespeare.Ru.as_you_like_it() 47 | "Весь мир — театр. В нем женщины, мужчины — все актеры. У них свои есть выходы, уходы, и каждый не одну играет роль." 48 | iex> Faker.Lorem.Shakespeare.Ru.as_you_like_it() 49 | "Дурак думает, что он умен; умный же знает, что глуп он." 50 | """ 51 | @spec as_you_like_it() :: String.t() 52 | sampler(:as_you_like_it, [ 53 | "Дурак думает, что он умен; умный же знает, что глуп он.", 54 | "Весь мир — театр. В нем женщины, мужчины — все актеры. У них свои есть выходы, уходы, и каждый не одну играет роль." 55 | ]) 56 | 57 | @doc """ 58 | Return random quote from "Richard III" play. 59 | 60 | ## Examples 61 | 62 | iex> Faker.Lorem.Shakespeare.Ru.king_richard_iii() 63 | "Коня, коня! Престол мой за коня!" 64 | iex> Faker.Lorem.Shakespeare.Ru.king_richard_iii() 65 | "Нет, не купить любви ценой злодейств!" 66 | iex> Faker.Lorem.Shakespeare.Ru.king_richard_iii() 67 | "Нет, не купить любви ценой злодейств!" 68 | iex> Faker.Lorem.Shakespeare.Ru.king_richard_iii() 69 | "Коня, коня! Престол мой за коня!" 70 | """ 71 | @spec king_richard_iii() :: String.t() 72 | sampler(:king_richard_iii, [ 73 | "Коня, коня! Престол мой за коня!", 74 | "Нет, не купить любви ценой злодейств!" 75 | ]) 76 | 77 | @doc """ 78 | Return random quote from "Romeo and Juliet" tragedy. 79 | 80 | ## Examples 81 | 82 | iex> Faker.Lorem.Shakespeare.Ru.romeo_and_juliet() 83 | "Нет повести печальнее на свете, чем повесть о Ромео и Джульетте." 84 | iex> Faker.Lorem.Shakespeare.Ru.romeo_and_juliet() 85 | "Картина требует красивой рамы, и золотое содержанье книг, нуждается в обложках золотых." 86 | iex> Faker.Lorem.Shakespeare.Ru.romeo_and_juliet() 87 | "Чем лучше цель, тем целимся мы метче." 88 | iex> Faker.Lorem.Shakespeare.Ru.romeo_and_juliet() 89 | "В минуты отчаянья сойдёт за вечность час..." 90 | """ 91 | @spec romeo_and_juliet() :: String.t() 92 | sampler(:romeo_and_juliet, [ 93 | "Нет повести печальнее на свете, чем повесть о Ромео и Джульетте.", 94 | "Но если уж мужское слово ненадёжно, чего тогда от женщины ждать можно?", 95 | "В минуты отчаянья сойдёт за вечность час...", 96 | "Чем лучше цель, тем целимся мы метче.", 97 | "Нам губы для молитв даны богами.", 98 | "Картина требует красивой рамы, и золотое содержанье книг, нуждается в обложках золотых." 99 | ]) 100 | end 101 | -------------------------------------------------------------------------------- /lib/faker/naivedatetime.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.NaiveDateTime do 2 | @moduledoc false 3 | 4 | @doc """ 5 | Returns a random date in the past up to N days, today not included 6 | 7 | ## Examples 8 | 9 | iex> Faker.NaiveDateTime.backward(4) 10 | #=> ~N[2016-12-20 06:02:17.922180] 11 | """ 12 | @spec backward(integer) :: NaiveDateTime.t() 13 | def backward(days) do 14 | forward(-days) 15 | end 16 | 17 | @doc """ 18 | Returns a random date in the future up to N days, today not included 19 | 20 | ## Examples 21 | 22 | iex> Faker.NaiveDateTime.forward(4) 23 | #=> ~N[2016-12-25 06:02:17.922180] 24 | """ 25 | @spec forward(integer) :: NaiveDateTime.t() 26 | def forward(days) do 27 | days 28 | |> Faker.DateTime.forward() 29 | |> DateTime.to_naive() 30 | end 31 | 32 | @doc """ 33 | Returns a random `NaiveDateTime.t` between two `NaiveDateTime.t`'s 34 | 35 | ## Examples 36 | 37 | iex> Faker.NaiveDateTime.between(~N[2016-12-20 00:00:00], ~N[2016-12-25 00:00:00]) 38 | #=> ~N[2016-12-23 06:02:17.922180] 39 | """ 40 | @spec between(NaiveDateTime.t(), NaiveDateTime.t()) :: NaiveDateTime.t() 41 | def between(from, to) do 42 | from 43 | |> Faker.DateTime.between(to) 44 | |> DateTime.to_naive() 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /lib/faker/name.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Name do 2 | alias Faker.Person 3 | 4 | @moduledoc """ 5 | Deprecated. Faker.Name will be removed in 1.0.0. Please use Faker.Person instead. 6 | """ 7 | 8 | @doc """ 9 | Returns a random complete name 10 | 11 | ## Examples 12 | 13 | iex> Faker.Name.name() 14 | "Mrs. Abe Rolfson MD" 15 | iex> Faker.Name.name() 16 | "Conor Padberg" 17 | iex> Faker.Name.name() 18 | "Mr. Bianka Ryan" 19 | iex> Faker.Name.name() 20 | "Ally Rau MD" 21 | """ 22 | @deprecated "Use Faker.Person.name/0 instead." 23 | @spec name() :: String.t() 24 | def name, do: Person.name() 25 | 26 | @doc """ 27 | Returns a random first name 28 | 29 | ## Examples 30 | 31 | iex> Faker.Name.first_name() 32 | "Joany" 33 | iex> Faker.Name.first_name() 34 | "Elizabeth" 35 | iex> Faker.Name.first_name() 36 | "Abe" 37 | iex> Faker.Name.first_name() 38 | "Ozella" 39 | """ 40 | @deprecated "Use Faker.Person.first_name/0 instead." 41 | @spec first_name() :: String.t() 42 | def first_name, do: Person.first_name() 43 | 44 | @doc """ 45 | Returns a random last name 46 | 47 | ## Examples 48 | 49 | iex> Faker.Name.last_name() 50 | "Blick" 51 | iex> Faker.Name.last_name() 52 | "Hayes" 53 | iex> Faker.Name.last_name() 54 | "Schumm" 55 | iex> Faker.Name.last_name() 56 | "Rolfson" 57 | """ 58 | @deprecated "Use Faker.Person.last_name/0 instead." 59 | @spec last_name() :: String.t() 60 | def last_name, do: Person.last_name() 61 | 62 | @doc """ 63 | Returns a random name related title 64 | 65 | ## Examples 66 | 67 | iex> Faker.Name.title() 68 | "Dynamic Identity Administrator" 69 | iex> Faker.Name.title() 70 | "Product Communications Technician" 71 | iex> Faker.Name.title() 72 | "Legacy Accountability Architect" 73 | iex> Faker.Name.title() 74 | "Customer Data Representative" 75 | """ 76 | @deprecated "Use Faker.Person.title/0 instead." 77 | @spec title() :: String.t() 78 | def title, do: Person.title() 79 | 80 | @doc """ 81 | Returns a random name related suffix 82 | 83 | ## Examples 84 | 85 | iex> Faker.Name.suffix() 86 | "II" 87 | iex> Faker.Name.suffix() 88 | "V" 89 | iex> Faker.Name.suffix() 90 | "V" 91 | iex> Faker.Name.suffix() 92 | "V" 93 | """ 94 | @deprecated "Use Faker.Person.suffix/0 instead." 95 | @spec suffix() :: String.t() 96 | def suffix, do: Person.suffix() 97 | 98 | @doc """ 99 | Returns a random name related prefix 100 | 101 | ## Examples 102 | 103 | iex> Faker.Name.prefix() 104 | "Mr." 105 | iex> Faker.Name.prefix() 106 | "Mrs." 107 | iex> Faker.Name.prefix() 108 | "Mr." 109 | iex> Faker.Name.prefix() 110 | "Dr." 111 | """ 112 | @deprecated "Use Faker.Person.prefix/0 instead." 113 | @spec prefix() :: String.t() 114 | def prefix, do: Person.prefix() 115 | end 116 | -------------------------------------------------------------------------------- /lib/faker/nato.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Nato do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Functions for generating NATO alphabet data 6 | """ 7 | 8 | @doc """ 9 | Returns a random letter NATO code 10 | 11 | ## Examples 12 | 13 | iex> Faker.Nato.letter_code_word() 14 | "ECHO" 15 | iex> Faker.Nato.letter_code_word() 16 | "LIMA" 17 | iex> Faker.Nato.letter_code_word() 18 | "ROMEO" 19 | iex> Faker.Nato.letter_code_word() 20 | "CHARLIE" 21 | """ 22 | @spec letter_code_word :: String.t() 23 | sampler(:letter_code_word, [ 24 | "ALPHA", 25 | "BRAVO", 26 | "CHARLIE", 27 | "DELTA", 28 | "ECHO", 29 | "FOXTROT", 30 | "GOLF", 31 | "HOTEL", 32 | "INDIA", 33 | "JULIETT", 34 | "KILO", 35 | "LIMA", 36 | "MIKE", 37 | "NOVEMBER", 38 | "OSCAR", 39 | "PAPA", 40 | "QUEBEC", 41 | "ROMEO", 42 | "SIERRA", 43 | "TANGO", 44 | "UNIFORM", 45 | "VICTOR", 46 | "WHISKEY", 47 | "XRAY", 48 | "YANKEE", 49 | "ZULU" 50 | ]) 51 | 52 | @doc """ 53 | Returns a random digit NATO code 54 | 55 | ## Examples 56 | 57 | iex> Faker.Nato.digit_code_word() 58 | "ONE" 59 | iex> Faker.Nato.digit_code_word() 60 | "TWO" 61 | iex> Faker.Nato.digit_code_word() 62 | "SIX" 63 | iex> Faker.Nato.digit_code_word() 64 | "FIVE" 65 | """ 66 | @spec digit_code_word :: String.t() 67 | sampler(:digit_code_word, [ 68 | "ONE", 69 | "TWO", 70 | "THREE", 71 | "FOUR", 72 | "FIVE", 73 | "SIX", 74 | "SEVEN", 75 | "EIGHT", 76 | "NINE", 77 | "ZERO" 78 | ]) 79 | 80 | @doc """ 81 | Returns the NATO stop code 82 | 83 | ## Examples 84 | 85 | iex> Faker.Nato.stop_code_word() 86 | "STOP" 87 | """ 88 | @spec stop_code_word :: String.t() 89 | def stop_code_word, do: "STOP" 90 | 91 | @doc """ 92 | Returns a random NATO call sign of the form [alpha]-[alpha]-[digit] 93 | 94 | ## Examples 95 | 96 | iex> Faker.Nato.callsign() 97 | "ECHO-LIMA-SIX" 98 | iex> Faker.Nato.callsign() 99 | "CHARLIE-ECHO-SEVEN" 100 | iex> Faker.Nato.callsign() 101 | "SIERRA-GOLF-TWO" 102 | iex> Faker.Nato.callsign() 103 | "INDIA-WHISKEY-FOUR" 104 | """ 105 | @spec callsign() :: String.t() 106 | def callsign, do: format("?-?-#") 107 | 108 | @doc """ 109 | Formats a string using the NATO alphabet. 110 | 111 | It replaces `"#"` to a random NATO digit, `"?"` to random NATO letter 112 | and `"."` to the stop code. 113 | 114 | ## Examples 115 | 116 | iex> Faker.Nato.format("#-?-#-.") 117 | "ONE-LIMA-SIX-STOP" 118 | iex> Faker.Nato.format("#-?-#-.") 119 | "FIVE-ECHO-SEVEN-STOP" 120 | iex> Faker.Nato.format("#-?-#-.") 121 | "FIVE-GOLF-TWO-STOP" 122 | iex> Faker.Nato.format("#-?-#-.") 123 | "ONE-WHISKEY-FOUR-STOP" 124 | """ 125 | @spec format(String.t()) :: String.t() 126 | def format(str) when is_binary(str) do 127 | format(str, "") 128 | end 129 | 130 | defp format(<<"#"::utf8, tail::binary>>, acc) do 131 | format(tail, <>) 132 | end 133 | 134 | defp format(<<"?"::utf8, tail::binary>>, acc) do 135 | format(tail, <>) 136 | end 137 | 138 | defp format(<<"."::utf8, tail::binary>>, acc) do 139 | format(tail, <>) 140 | end 141 | 142 | defp format(<>, acc) do 143 | format(tail, <>) 144 | end 145 | 146 | defp format("", acc) do 147 | acc 148 | end 149 | end 150 | -------------------------------------------------------------------------------- /lib/faker/person.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Person do 2 | import Faker, only: [localize: 1] 3 | 4 | @moduledoc """ 5 | Functions for generating names for a person. 6 | """ 7 | 8 | @doc """ 9 | Returns a random complete name 10 | 11 | ## Examples 12 | 13 | iex> Faker.Person.name() 14 | "Mrs. Abe Rolfson MD" 15 | iex> Faker.Person.name() 16 | "Conor Padberg" 17 | iex> Faker.Person.name() 18 | "Mr. Bianka Ryan" 19 | iex> Faker.Person.name() 20 | "Ally Rau MD" 21 | """ 22 | @spec name() :: String.t() 23 | localize(:name) 24 | 25 | @doc """ 26 | Returns a random first name 27 | 28 | ## Examples 29 | 30 | iex> Faker.Person.first_name() 31 | "Joany" 32 | iex> Faker.Person.first_name() 33 | "Elizabeth" 34 | iex> Faker.Person.first_name() 35 | "Abe" 36 | iex> Faker.Person.first_name() 37 | "Ozella" 38 | """ 39 | @spec first_name() :: String.t() 40 | localize(:first_name) 41 | 42 | @doc """ 43 | Returns a random last name 44 | 45 | ## Examples 46 | 47 | iex> Faker.Person.last_name() 48 | "Blick" 49 | iex> Faker.Person.last_name() 50 | "Hayes" 51 | iex> Faker.Person.last_name() 52 | "Schumm" 53 | iex> Faker.Person.last_name() 54 | "Rolfson" 55 | """ 56 | @spec last_name() :: String.t() 57 | localize(:last_name) 58 | 59 | @doc """ 60 | Returns a random name related title 61 | 62 | ## Examples 63 | 64 | iex> Faker.Person.title() 65 | "Dynamic Identity Administrator" 66 | iex> Faker.Person.title() 67 | "Product Communications Technician" 68 | iex> Faker.Person.title() 69 | "Legacy Accountability Architect" 70 | iex> Faker.Person.title() 71 | "Customer Data Representative" 72 | """ 73 | @spec title() :: String.t() 74 | localize(:title) 75 | 76 | @doc """ 77 | Returns a random name related suffix 78 | 79 | ## Examples 80 | 81 | iex> Faker.Person.suffix() 82 | "II" 83 | iex> Faker.Person.suffix() 84 | "V" 85 | iex> Faker.Person.suffix() 86 | "V" 87 | iex> Faker.Person.suffix() 88 | "V" 89 | """ 90 | @spec suffix() :: String.t() 91 | localize(:suffix) 92 | 93 | @doc """ 94 | Returns a random name related prefix 95 | 96 | ## Examples 97 | 98 | iex> Faker.Person.prefix() 99 | "Mr." 100 | iex> Faker.Person.prefix() 101 | "Mrs." 102 | iex> Faker.Person.prefix() 103 | "Mr." 104 | iex> Faker.Person.prefix() 105 | "Dr." 106 | """ 107 | @spec prefix() :: String.t() 108 | localize(:prefix) 109 | end 110 | -------------------------------------------------------------------------------- /lib/faker/phone/en_gb.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Phone.EnGb do 2 | import Faker, only: [samplerp: 2] 3 | 4 | @moduledoc """ 5 | This follows the rules of 6 | [Telephone numbers in the United Kingdom](https://en.wikipedia.org/wiki/Telephone_numbers_in_the_United_Kingdom). 7 | """ 8 | 9 | @prefixes %{ 10 | "International dialling" => ["0"], 11 | "Geographic numbers with area codes - for list see telephone area codes" => ["1", "2"], 12 | "Geographic rate numbers - used by public sector and not-for-profit bodies" => ["30"], 13 | "Geographic rate numbers - new allocations" => ["33"], 14 | "Geographic rate numbers - migrating numbers from matching 084 numbers" => ["34"], 15 | "Geographic rate numbers - migrating numbers from matching 087 numbers" => ["37"], 16 | "Corporate numbers" => ["55"], 17 | "Location independent electronic communications service (VoIP)" => ["56"], 18 | "Personal numbering service" => ["70"], 19 | "Radiopaging services" => ["76"], 20 | "Freephone numbers" => ["80"], 21 | "Internet for schools" => ["82"], 22 | "Basic revenue share numbers" => ["84"], 23 | "Higher rate revenue share numbers" => ["87"], 24 | "Premium Rate Services (PRS) revenue share numbers" => ["90", "91"], 25 | "Sexual Entertainment Services (SES) revenue share at a premium rate" => ["908", "909", "98"] 26 | } 27 | 28 | @doc """ 29 | Returns a random UK phone number 30 | 31 | ## Examples 32 | 33 | iex> Faker.Phone.EnGb.number() 34 | "+44042646108" 35 | iex> Faker.Phone.EnGb.number() 36 | "07897 052357" 37 | iex> Faker.Phone.EnGb.number() 38 | "+44803032097" 39 | iex> Faker.Phone.EnGb.number() 40 | "+447776 033745" 41 | """ 42 | @spec number() :: String.t() 43 | def number do 44 | if Faker.random_between(0, 1) == 0 do 45 | landline_number() 46 | else 47 | cell_number() 48 | end 49 | end 50 | 51 | @doc """ 52 | Returns a random UK landline phone number 53 | 54 | ## Examples 55 | 56 | iex> Faker.Phone.EnGb.landline_number() 57 | "+44335426461" 58 | iex> Faker.Phone.EnGb.landline_number() 59 | "+44343297052" 60 | iex> Faker.Phone.EnGb.landline_number() 61 | "+44567020303" 62 | iex> Faker.Phone.EnGb.landline_number() 63 | "+44709733760" 64 | """ 65 | @spec landline_number() :: String.t() 66 | def landline_number do 67 | "+44#{number_prefix()}" 68 | |> random_numbers_until(12) 69 | end 70 | 71 | samplerp(:cell_number_format, [ 72 | "074## ######", 73 | "075## ######", 74 | "076## ######", 75 | "077## ######", 76 | "078## ######", 77 | "079## ######", 78 | "+4474## ######", 79 | "+4475## ######", 80 | "+4476## ######", 81 | "+4477## ######", 82 | "+4478## ######", 83 | "+4479## ######" 84 | ]) 85 | 86 | @doc """ 87 | Returns a random UK mobile phone number 88 | 89 | ## Examples 90 | 91 | iex> Faker.Phone.EnGb.cell_number() 92 | "+447415 426461" 93 | iex> Faker.Phone.EnGb.cell_number() 94 | "07483 297052" 95 | iex> Faker.Phone.EnGb.cell_number() 96 | "+447557 020303" 97 | iex> Faker.Phone.EnGb.cell_number() 98 | "+447609 733760" 99 | """ 100 | @spec cell_number() :: String.t() 101 | def cell_number do 102 | Faker.format(cell_number_format()) 103 | end 104 | 105 | @doc """ 106 | Returns a random UK mobile phone number 107 | 108 | ## Examples 109 | 110 | iex> Faker.Phone.EnGb.mobile_number() 111 | "+447415 426461" 112 | iex> Faker.Phone.EnGb.mobile_number() 113 | "07483 297052" 114 | iex> Faker.Phone.EnGb.mobile_number() 115 | "+447557 020303" 116 | iex> Faker.Phone.EnGb.mobile_number() 117 | "+447609 733760" 118 | """ 119 | @spec mobile_number() :: String.t() 120 | defdelegate mobile_number, to: __MODULE__, as: :cell_number 121 | 122 | defp random_numbers_until(out, count) do 123 | char_count = 124 | out 125 | |> String.to_charlist() 126 | |> Enum.count() 127 | 128 | format = String.duplicate("#", count - char_count) 129 | 130 | "#{out}#{Faker.format(format)}" 131 | end 132 | 133 | defp number_prefix do 134 | numbers = Map.values(@prefixes) 135 | type = Enum.at(numbers, Faker.random_between(0, Enum.count(@prefixes) - 1)) 136 | Enum.at(type, Faker.random_between(0, Enum.count(type) - 1)) 137 | end 138 | end 139 | -------------------------------------------------------------------------------- /lib/faker/phone/en_us.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Phone.EnUs do 2 | @moduledoc """ 3 | This follows the rules outlined in the North American Numbering Plan 4 | at https://en.wikipedia.org/wiki/North_American_Numbering_Plan. 5 | 6 | The NANP number format may be summarized in the notation NPA-NXX-xxxx: 7 | 8 | The allowed ranges for NPA (area code) are: [2–9] for the first digit, and 9 | [0-9] for the second and third digits. The NANP is not assigning area codes 10 | with 9 as the second digit. 11 | 12 | The allowed ranges for NXX (central office/exchange) are: [2–9] for the first 13 | digit, and [0–9] for both the second and third digits (however, in geographic 14 | area codes the third digit of the exchange cannot be 1 if the second digit is 15 | also 1). 16 | 17 | The allowed ranges for xxxx (subscriber number) are [0–9] for each of the four 18 | digits. 19 | """ 20 | 21 | @doc """ 22 | Returns a random US phone number 23 | 24 | Possible returned formats: 25 | 26 | (123) 456-7890 27 | 123/456-7890 28 | 123-456-7890 29 | 123.456.7890 30 | 1234567890 31 | 32 | ## Examples 33 | 34 | iex> Faker.Phone.EnUs.phone() 35 | "5528621083" 36 | iex> Faker.Phone.EnUs.phone() 37 | "(730) 552-5702" 38 | iex> Faker.Phone.EnUs.phone() 39 | "652-505-3376" 40 | iex> Faker.Phone.EnUs.phone() 41 | "(377) 347-8109" 42 | """ 43 | @spec phone() :: String.t() 44 | def phone do 45 | phone(digit(0, 3)) 46 | end 47 | 48 | defp phone(0), do: "(#{area_code()}) #{exchange_code()}-#{subscriber_number()}" 49 | defp phone(1), do: "#{area_code()}/#{exchange_code()}-#{subscriber_number()}" 50 | 51 | defp phone(_) do 52 | sep = std_separator() 53 | "#{area_code()}#{sep}#{exchange_code()}#{sep}#{subscriber_number()}" 54 | end 55 | 56 | @doc """ 57 | Returns a random area code 58 | 59 | ## Examples 60 | 61 | iex> Faker.Phone.EnUs.area_code() 62 | "825" 63 | iex> Faker.Phone.EnUs.area_code() 64 | "246" 65 | iex> Faker.Phone.EnUs.area_code() 66 | "681" 67 | iex> Faker.Phone.EnUs.area_code() 68 | "683" 69 | """ 70 | @spec area_code() :: String.t() 71 | def area_code do 72 | [digit(2, 9), digit(0, 8), digit(0, 9)] |> Enum.join() 73 | end 74 | 75 | @doc """ 76 | Returns a random exchange code 77 | 78 | ## Examples 79 | 80 | iex> Faker.Phone.EnUs.exchange_code() 81 | "503" 82 | iex> Faker.Phone.EnUs.exchange_code() 83 | "845" 84 | iex> Faker.Phone.EnUs.exchange_code() 85 | "549" 86 | iex> Faker.Phone.EnUs.exchange_code() 87 | "509" 88 | """ 89 | @spec exchange_code() :: String.t() 90 | def exchange_code do 91 | second_dig = digit(0, 9) 92 | 93 | third_dig = 94 | case second_dig do 95 | 1 -> digit(2, 9) 96 | _ -> digit(1, 9) 97 | end 98 | 99 | [digit(2, 9), second_dig, third_dig] |> Enum.join() 100 | end 101 | 102 | @doc """ 103 | Returns a random subscriber number `n` digits long 104 | 105 | ## Examples 106 | 107 | iex> Faker.Phone.EnUs.subscriber_number() 108 | "0154" 109 | iex> Faker.Phone.EnUs.subscriber_number() 110 | "2646" 111 | iex> Faker.Phone.EnUs.subscriber_number(2) 112 | "10" 113 | iex> Faker.Phone.EnUs.subscriber_number(5) 114 | "83297" 115 | """ 116 | @spec subscriber_number(pos_integer) :: String.t() 117 | def subscriber_number(n) when is_integer(n) do 118 | Faker.format(String.duplicate("#", n)) 119 | end 120 | 121 | @spec subscriber_number() :: String.t() 122 | def subscriber_number, do: subscriber_number(4) 123 | 124 | @doc """ 125 | Returns a random extension `n` digits long 126 | 127 | ## Examples 128 | 129 | iex> Faker.Phone.EnUs.extension() 130 | "0154" 131 | iex> Faker.Phone.EnUs.extension() 132 | "2646" 133 | iex> Faker.Phone.EnUs.extension(3) 134 | "108" 135 | iex> Faker.Phone.EnUs.extension(5) 136 | "32970" 137 | """ 138 | defdelegate extension(n), to: __MODULE__, as: :subscriber_number 139 | defdelegate extension, to: __MODULE__, as: :subscriber_number 140 | 141 | defp std_separator, do: Enum.at(["-", ".", ""], Faker.random_between(0, 2)) 142 | 143 | defp digit(min, max), do: Faker.random_between(min, max) 144 | end 145 | -------------------------------------------------------------------------------- /lib/faker/phone/hy.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Phone.Hy do 2 | import Faker, only: [samplerp: 2] 3 | 4 | @moduledoc """ 5 | Functions for generating phone related data in Armenian 6 | """ 7 | 8 | @doc """ 9 | Returns a random phone number. 10 | 11 | ## Examples 12 | 13 | iex> Faker.Phone.Hy.number() 14 | "10.542646" 15 | iex> Faker.Phone.Hy.number() 16 | "83-297052" 17 | iex> Faker.Phone.Hy.number() 18 | "(70) 203032" 19 | iex> Faker.Phone.Hy.number() 20 | "(733) 76033" 21 | """ 22 | @spec number() :: String.t() 23 | def number do 24 | if Faker.random_between(0, 1) == 0 do 25 | landline_number() 26 | else 27 | cell_number() 28 | end 29 | end 30 | 31 | samplerp(:landline_number_format, [ 32 | "###-#####", 33 | "(###) #####", 34 | "###.#####", 35 | "10-######", 36 | "(10) ######", 37 | "10.######" 38 | ]) 39 | 40 | @doc """ 41 | Returns a random landline phone number. 42 | 43 | ## Examples 44 | 45 | iex> Faker.Phone.Hy.landline_number() 46 | "154-26461" 47 | iex> Faker.Phone.Hy.landline_number() 48 | "832-97052" 49 | iex> Faker.Phone.Hy.landline_number() 50 | "(570) 20303" 51 | iex> Faker.Phone.Hy.landline_number() 52 | "097.33760" 53 | """ 54 | @spec landline_number() :: String.t() 55 | def landline_number do 56 | Faker.format(landline_number_format()) 57 | end 58 | 59 | samplerp(:cell_number_format, [ 60 | "##-######", 61 | "(##) ######", 62 | "##.######" 63 | ]) 64 | 65 | @doc """ 66 | Returns a random cell phone number. 67 | 68 | ## Examples 69 | 70 | iex> Faker.Phone.Hy.cell_number() 71 | "15-426461" 72 | iex> Faker.Phone.Hy.cell_number() 73 | "83-297052" 74 | iex> Faker.Phone.Hy.cell_number() 75 | "(57) 020303" 76 | iex> Faker.Phone.Hy.cell_number() 77 | "09.733760" 78 | """ 79 | @spec cell_number() :: String.t() 80 | def cell_number do 81 | Faker.format(cell_number_format()) 82 | end 83 | end 84 | -------------------------------------------------------------------------------- /lib/faker/phone/pt_br.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Phone.PtBr do 2 | import Faker, only: [sampler: 2] 3 | 4 | @moduledoc """ 5 | Function to generate Brazilian phone numbers. 6 | """ 7 | 8 | @doc """ 9 | Returns a random phone number. 10 | 11 | ## Examples 12 | 13 | iex> Faker.Phone.PtBr.phone() 14 | "(75) 9 1542-6461" 15 | iex> Faker.Phone.PtBr.phone() 16 | "(75) 4329-7052" 17 | iex> Faker.Phone.PtBr.phone() 18 | "(69) 9 7020-3032" 19 | iex> Faker.Phone.PtBr.phone() 20 | "(75) 5733-7603" 21 | """ 22 | @spec phone :: binary 23 | def phone do 24 | base_template_number() 25 | |> Faker.format() 26 | |> number_with_region() 27 | end 28 | 29 | @doc """ 30 | Replace 'xx' for a random region number picked. 31 | 32 | ## Examples 33 | 34 | iex> Faker.Phone.PtBr.number_with_region("(xx) 9 1542-6461") 35 | "(92) 9 1542-6461" 36 | iex> Faker.Phone.PtBr.number_with_region("(xx) 4329-7052") 37 | "(31) 4329-7052" 38 | iex> Faker.Phone.PtBr.number_with_region("(xx) 9 7020-3032") 39 | "(71) 9 7020-3032" 40 | iex> Faker.Phone.PtBr.number_with_region("(xx) 5733-7603") 41 | "(71) 5733-7603" 42 | """ 43 | @spec number_with_region(binary) :: binary 44 | def number_with_region(number) do 45 | region = generate_region_code() 46 | 47 | number 48 | |> String.replace("xx", region) 49 | end 50 | 51 | @doc """ 52 | Pick a random region code from list 53 | 54 | ## Examples 55 | 56 | iex> Faker.Phone.PtBr.generate_region_code() 57 | "92" 58 | iex> Faker.Phone.PtBr.generate_region_code() 59 | "31" 60 | iex> Faker.Phone.PtBr.generate_region_code() 61 | "71" 62 | iex> Faker.Phone.PtBr.generate_region_code() 63 | "71" 64 | """ 65 | @spec generate_region_code :: binary 66 | def generate_region_code do 67 | region_code() 68 | |> Integer.to_string() 69 | end 70 | 71 | sampler(:base_template_number, [ 72 | "(xx) 9 ####-####", 73 | "(xx) 2###-####", 74 | "(xx) 3###-####", 75 | "(xx) 4###-####", 76 | "(xx) 5###-####" 77 | ]) 78 | 79 | sampler(:region_code, [ 80 | 71, 81 | 75, 82 | 11, 83 | 21, 84 | 27, 85 | 31, 86 | 41, 87 | 47, 88 | 51, 89 | 81, 90 | 82, 91 | 83, 92 | 84, 93 | 85, 94 | 86, 95 | 61, 96 | 62, 97 | 63, 98 | 65, 99 | 67, 100 | 68, 101 | 69, 102 | 71, 103 | 79, 104 | 91, 105 | 92, 106 | 95, 107 | 96, 108 | 98 109 | ]) 110 | end 111 | -------------------------------------------------------------------------------- /lib/faker/phone/pt_pt.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Phone.PtPt do 2 | import Faker, only: [samplerp: 2] 3 | 4 | @moduledoc """ 5 | Functions for generating phone related data for portugal location 6 | """ 7 | 8 | @doc """ 9 | Returns a random phone number. 10 | 11 | ## Examples 12 | 13 | iex> Faker.Phone.PtPt.number() 14 | "929999999" 15 | iex> Faker.Phone.PtPt.number() 16 | "919999999" 17 | iex> Faker.Phone.PtPt.number() 18 | "234999999" 19 | iex> Faker.Phone.PtPt.number() 20 | "939999999" 21 | """ 22 | 23 | @spec number() :: String.t() 24 | def number do 25 | if Faker.random_between(0, 1) == 0 do 26 | landline_number() 27 | else 28 | cell_number() 29 | end 30 | end 31 | 32 | samplerp(:landline_number_format, [ 33 | "2########", 34 | "3########" 35 | ]) 36 | 37 | @doc """ 38 | Returns a random landline phone number 39 | 40 | ## Examples 41 | 42 | iex> Faker.Phone.PtPt.landline_number() 43 | "299999999" 44 | iex> Faker.Phone.PtPt.landline_number() 45 | "299999998" 46 | iex> Faker.Phone.PtPt.landline_number() 47 | "399999999" 48 | iex> Faker.Phone.PtPt.landline_number() 49 | "399999998" 50 | """ 51 | 52 | @spec landline_number() :: String.t() 53 | def landline_number do 54 | Faker.format(landline_number_format()) 55 | end 56 | 57 | samplerp(:cell_number_format, [ 58 | "91#######", 59 | "92#######", 60 | "93#######", 61 | "96#######" 62 | ]) 63 | 64 | @doc """ 65 | Returns a random cell phone number 66 | 67 | ## Examples 68 | 69 | iex> Faker.Phone.PtPt.cell_number() 70 | "919999999" 71 | iex> Faker.Phone.PtPt.cell_number() 72 | "929999999" 73 | iex> Faker.Phone.PtPt.cell_number() 74 | "939999999" 75 | iex> Faker.Phone.PtPt.cell_number() 76 | "969999999" 77 | """ 78 | 79 | @spec cell_number() :: String.t() 80 | def cell_number do 81 | Faker.format(cell_number_format()) 82 | end 83 | end 84 | -------------------------------------------------------------------------------- /lib/faker/pokemon.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Pokemon do 2 | import Faker, only: [localize: 1] 3 | 4 | @moduledoc """ 5 | Function for generating Pokemon 6 | """ 7 | 8 | @doc """ 9 | Returns a random Pokemon name 10 | 11 | ## Examples 12 | 13 | iex> Faker.Pokemon.name() 14 | "Fraxure" 15 | iex> Faker.Pokemon.name() 16 | "Shellos" 17 | iex> Faker.Pokemon.name() 18 | "Ambipom" 19 | iex> Faker.Pokemon.name() 20 | "Forretress" 21 | """ 22 | @spec name() :: String.t() 23 | localize(:name) 24 | 25 | @doc """ 26 | Returns a random Pokemon location 27 | 28 | ## Examples 29 | 30 | iex> Faker.Pokemon.location() 31 | "Vaniville Town" 32 | iex> Faker.Pokemon.location() 33 | "Slateport City" 34 | iex> Faker.Pokemon.location() 35 | "Shalour City" 36 | iex> Faker.Pokemon.location() 37 | "Solaceon Town" 38 | """ 39 | @spec location() :: String.t() 40 | localize(:location) 41 | end 42 | -------------------------------------------------------------------------------- /lib/faker/random.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Random do 2 | @moduledoc """ 3 | Behaviour that defines randomisation in faker. 4 | """ 5 | 6 | @callback random_between(integer(), integer()) :: integer() 7 | @callback random_bytes(pos_integer()) :: binary() 8 | @callback random_uniform() :: float() 9 | @callback shuffle(Enum.t()) :: list() 10 | 11 | defmacro __using__(_) do 12 | quote do 13 | @behaviour Faker.Random 14 | 15 | def random_between(left, right) do 16 | Enum.random(left..right) 17 | end 18 | 19 | def random_bytes(total) do 20 | :crypto.strong_rand_bytes(total) 21 | end 22 | 23 | def random_uniform do 24 | :rand.uniform() 25 | end 26 | 27 | def shuffle(enum) do 28 | Enum.shuffle(enum) 29 | end 30 | 31 | defoverridable random_between: 2, random_bytes: 1, random_uniform: 0, shuffle: 1 32 | end 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /lib/faker/random/elixir.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Random.Elixir do 2 | @moduledoc """ 3 | Default implementation of random functions based on erlang and elixir standard library. 4 | """ 5 | 6 | use Faker.Random 7 | end 8 | -------------------------------------------------------------------------------- /lib/faker/random/test.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Random.Test do 2 | @moduledoc false 3 | 4 | use Faker.Random 5 | 6 | def random_between(left, right) do 7 | set_seed(:ets.lookup(:seed_registry, self())) 8 | Enum.random(left..right) 9 | end 10 | 11 | def random_bytes(total) do 12 | set_seed(:ets.lookup(:seed_registry, self())) 13 | 14 | Stream.repeatedly(fn -> random_between(0, 255) end) 15 | |> Enum.take(total) 16 | |> IO.iodata_to_binary() 17 | end 18 | 19 | def random_uniform do 20 | set_seed(:ets.lookup(:seed_registry, self())) 21 | :rand.uniform() 22 | end 23 | 24 | @spec shuffle(Enum.t()) :: list 25 | def shuffle(enumerable) do 26 | randomized = 27 | Enum.reduce(enumerable, [], fn x, acc -> 28 | [{:rand.uniform(), x} | acc] 29 | end) 30 | 31 | shuffle_unwrap(:lists.keysort(1, randomized)) 32 | end 33 | 34 | defp shuffle_unwrap([{_, h} | rest]), do: [h | shuffle_unwrap(rest)] 35 | defp shuffle_unwrap([]), do: [] 36 | 37 | @spec random(Enum.t()) :: Enum.element() 38 | def random(enumerable) 39 | 40 | def random(enumerable) when is_list(enumerable) do 41 | case length(enumerable) do 42 | 0 -> raise Enum.EmptyError 43 | length -> enumerable |> drop_list(random_count(length)) |> hd() 44 | end 45 | end 46 | 47 | def random(first.._//step = range) do 48 | case Range.size(range) do 49 | 0 -> raise Enum.EmptyError 50 | size -> first + random_count(size) * step 51 | end 52 | end 53 | 54 | def random(enumerable) do 55 | result = 56 | case Enumerable.slice(enumerable) do 57 | {:ok, 0, _} -> 58 | [] 59 | 60 | {:ok, count, fun} when is_function(fun, 1) -> 61 | slice_list(fun.(enumerable), random_count(count), 1, 1) 62 | 63 | # TODO: Deprecate me in Elixir v1.18. 64 | {:ok, count, fun} when is_function(fun, 2) -> 65 | fun.(random_count(count), 1) 66 | 67 | {:ok, count, fun} when is_function(fun, 3) -> 68 | fun.(random_count(count), 1, 1) 69 | 70 | {:error, _} -> 71 | Enum.take_random(enumerable, 1) 72 | end 73 | 74 | case result do 75 | [] -> raise Enum.EmptyError 76 | [elem] -> elem 77 | end 78 | end 79 | 80 | defp random_count(count) do 81 | :rand.uniform(count) - 1 82 | end 83 | 84 | defp drop_list(list, 0), do: list 85 | defp drop_list([_ | tail], counter), do: drop_list(tail, counter - 1) 86 | defp drop_list([], _), do: [] 87 | 88 | defp slice_list(list, start, amount, step) do 89 | if step == 1 do 90 | list |> drop_list(start) |> take_list(amount) 91 | else 92 | list |> drop_list(start) |> take_every_list(amount, step - 1) 93 | end 94 | end 95 | 96 | defp take_list(_list, 0), do: [] 97 | defp take_list([head | tail], counter), do: [head | take_list(tail, counter - 1)] 98 | defp take_list([], _counter), do: [] 99 | 100 | defp take_every_list([head | tail], counter, to_drop), 101 | do: [head | tail |> drop_list(to_drop) |> take_every_list(counter - 1, to_drop)] 102 | 103 | defp take_every_list([], _counter, _to_drop), do: [] 104 | 105 | defp set_seed([]) do 106 | :rand.seed(:exsplus, {1, 1, 1}) 107 | :ets.insert(:seed_registry, {self(), true}) 108 | end 109 | 110 | defp set_seed(_) do 111 | end 112 | end 113 | -------------------------------------------------------------------------------- /lib/faker/star_wars.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.StarWars do 2 | import Faker, only: [localize: 1] 3 | 4 | @moduledoc """ 5 | Functions for generating StarWars related data 6 | """ 7 | 8 | @doc """ 9 | Returns a Star Wars character name 10 | 11 | ## Examples 12 | 13 | iex> Faker.StarWars.character() 14 | "Greedo" 15 | iex> Faker.StarWars.character() 16 | "Jek Tono Porkins" 17 | iex> Faker.StarWars.character() 18 | "Poe Dameron" 19 | iex> Faker.StarWars.character() 20 | "R4-P17" 21 | """ 22 | @spec character() :: String.t() 23 | localize(:character) 24 | 25 | @doc """ 26 | Returns a Star Wars planet name 27 | 28 | ## Examples 29 | 30 | iex> Faker.StarWars.planet() 31 | "Mon Cala" 32 | iex> Faker.StarWars.planet() 33 | "Ryloth" 34 | iex> Faker.StarWars.planet() 35 | "Endor" 36 | iex> Faker.StarWars.planet() 37 | "Shili" 38 | """ 39 | @spec planet() :: String.t() 40 | localize(:planet) 41 | 42 | @doc """ 43 | Returns a Star Wars quote 44 | 45 | ## Examples 46 | 47 | iex> Faker.StarWars.quote() 48 | "Congratulations. You are being rescued. Please do not resist." 49 | iex> Faker.StarWars.quote() 50 | "What chance do we have? The question is 'what choice'. Run, hide, plead for mercy, scatter your forces. You give way to an enemy this evil with this much power and you condemn the galaxy to an eternity of submission. The time to fight is now!" 51 | iex> Faker.StarWars.quote() 52 | "Will someone get this big walking carpet out of my way?" 53 | iex> Faker.StarWars.quote() 54 | "To be Jedi is to face the truth, and choose. Give off light, or darkness, Padawan. Be a candle, or the night." 55 | """ 56 | @spec quote() :: String.t() 57 | localize(:quote) 58 | end 59 | -------------------------------------------------------------------------------- /lib/faker/superhero.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Superhero do 2 | import Faker, only: [localize: 1] 3 | 4 | @moduledoc """ 5 | Functions for generating Superhero data 6 | """ 7 | 8 | @doc """ 9 | Returns a random Superhero name 10 | 11 | ## Examples 12 | 13 | iex> Faker.Superhero.name() 14 | "Red Beyonder the Hunter" 15 | iex> Faker.Superhero.name() 16 | "Penance Strike" 17 | iex> Faker.Superhero.name() 18 | "Sage" 19 | iex> Faker.Superhero.name() 20 | "Giant Aqua I" 21 | """ 22 | @spec name() :: String.t() 23 | localize(:name) 24 | 25 | @doc """ 26 | Returns a random Superhero name prefix 27 | 28 | ## Examples 29 | 30 | iex> Faker.Superhero.prefix() 31 | "The" 32 | iex> Faker.Superhero.prefix() 33 | "Red" 34 | iex> Faker.Superhero.prefix() 35 | "The" 36 | iex> Faker.Superhero.prefix() 37 | "Captain" 38 | """ 39 | @spec prefix() :: String.t() 40 | localize(:prefix) 41 | 42 | @doc """ 43 | Returns a random Superhero name suffix 44 | 45 | ## Examples 46 | 47 | iex> Faker.Superhero.suffix() 48 | "Strange" 49 | iex> Faker.Superhero.suffix() 50 | "Claw" 51 | iex> Faker.Superhero.suffix() 52 | "the Hunter" 53 | iex> Faker.Superhero.suffix() 54 | "the Hunter" 55 | """ 56 | @spec suffix() :: String.t() 57 | localize(:suffix) 58 | 59 | @doc """ 60 | Returns a random Superhero descriptor 61 | 62 | ## Examples 63 | 64 | iex> Faker.Superhero.descriptor() 65 | "Ronin" 66 | iex> Faker.Superhero.descriptor() 67 | "Azrael" 68 | iex> Faker.Superhero.descriptor() 69 | "Beyonder" 70 | iex> Faker.Superhero.descriptor() 71 | "Phantom" 72 | """ 73 | @spec descriptor() :: String.t() 74 | localize(:descriptor) 75 | 76 | @doc """ 77 | Returns a random Superhero power 78 | 79 | ## Examples 80 | 81 | iex> Faker.Superhero.power() 82 | "Death Touch" 83 | iex> Faker.Superhero.power() 84 | "Shapeshifting" 85 | iex> Faker.Superhero.power() 86 | "Gliding" 87 | iex> Faker.Superhero.power() 88 | "Illusions" 89 | """ 90 | @spec power() :: String.t() 91 | localize(:power) 92 | end 93 | -------------------------------------------------------------------------------- /lib/faker/team.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Team do 2 | import Faker, only: [localize: 1] 3 | 4 | @moduledoc """ 5 | Functions for generating team related data 6 | """ 7 | 8 | @doc """ 9 | Returns a string of the form [state] [creature] 10 | 11 | ## Examples 12 | 13 | iex> Faker.Team.creature() 14 | "prophets" 15 | iex> Faker.Team.creature() 16 | "cats" 17 | iex> Faker.Team.creature() 18 | "enchanters" 19 | iex> Faker.Team.creature() 20 | "banshees" 21 | """ 22 | @spec creature() :: String.t() 23 | localize(:creature) 24 | 25 | @doc """ 26 | Returns a random creature name 27 | 28 | ## Examples 29 | 30 | iex> Faker.Team.name() 31 | "Hawaii cats" 32 | iex> Faker.Team.name() 33 | "Oklahoma banshees" 34 | iex> Faker.Team.name() 35 | "Texas elves" 36 | iex> Faker.Team.name() 37 | "Iowa fishes" 38 | """ 39 | @spec name() :: String.t() 40 | localize(:name) 41 | end 42 | -------------------------------------------------------------------------------- /lib/faker/team/en.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Team.En do 2 | import Faker, only: [sampler: 2] 3 | alias Faker.Address 4 | 5 | @moduledoc """ 6 | Functions for generating team related data in English 7 | """ 8 | 9 | @doc """ 10 | Returns a string of the form [state] [creature] 11 | 12 | ## Examples 13 | 14 | iex> Faker.Team.En.name() 15 | "Hawaii cats" 16 | iex> Faker.Team.En.name() 17 | "Oklahoma banshees" 18 | iex> Faker.Team.En.name() 19 | "Texas elves" 20 | iex> Faker.Team.En.name() 21 | "Iowa fishes" 22 | """ 23 | @spec name() :: String.t() 24 | def name, do: "#{Address.state()} #{creature()}" 25 | 26 | @doc """ 27 | Returns a random creature name 28 | 29 | ## Examples 30 | 31 | iex> Faker.Team.En.creature() 32 | "prophets" 33 | iex> Faker.Team.En.creature() 34 | "cats" 35 | iex> Faker.Team.En.creature() 36 | "enchanters" 37 | iex> Faker.Team.En.creature() 38 | "banshees" 39 | """ 40 | @spec creature() :: String.t() 41 | sampler(:creature, [ 42 | "ants", 43 | "banshees", 44 | "bats", 45 | "bears", 46 | "bees", 47 | "birds", 48 | "black cats", 49 | "buffalo", 50 | "cats", 51 | "cattle", 52 | "chickens", 53 | "chimeras", 54 | "conspirators", 55 | "crows", 56 | "dogs", 57 | "dolphins", 58 | "dragons", 59 | "druids", 60 | "ducks", 61 | "dwarves", 62 | "elephants", 63 | "elves", 64 | "enchanters", 65 | "exorcists", 66 | "fishes", 67 | "foes", 68 | "foxes", 69 | "frogs", 70 | "geese", 71 | "ghosts", 72 | "giants", 73 | "gnomes", 74 | "goats", 75 | "goblins", 76 | "gooses", 77 | "griffins", 78 | "horses", 79 | "kangaroos", 80 | "lions", 81 | "lycanthropes", 82 | "monkeys", 83 | "nemesis", 84 | "ogres", 85 | "oracles", 86 | "owls", 87 | "oxen", 88 | "penguins", 89 | "people", 90 | "pigs", 91 | "prophets", 92 | "rabbits", 93 | "sheep", 94 | "sons", 95 | "sorcerors", 96 | "spiders", 97 | "spirits", 98 | "tigers", 99 | "vampires", 100 | "vixens", 101 | "warlocks", 102 | "werewolves", 103 | "whales", 104 | "witches", 105 | "wolves", 106 | "worshipers", 107 | "zebras", 108 | "zombies" 109 | ]) 110 | end 111 | -------------------------------------------------------------------------------- /lib/faker/team/pt_br.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Team.PtBr do 2 | import Faker, only: [sampler: 2] 3 | alias Faker.Address 4 | 5 | @moduledoc """ 6 | Functions for generating team related data in Brazilian Portuguese 7 | """ 8 | 9 | @doc """ 10 | Returns a string of the form [state] [creature] 11 | 12 | ## Examples 13 | 14 | iex> Faker.Team.PtBr.name() 15 | "corujas de Alaska" 16 | iex> Faker.Team.PtBr.name() 17 | "vampiros de California" 18 | iex> Faker.Team.PtBr.name() 19 | "pássaros de Kentucky" 20 | iex> Faker.Team.PtBr.name() 21 | "vixens de Kentucky" 22 | """ 23 | @spec name() :: String.t() 24 | def name, do: "#{creature()} de #{Address.state()}" 25 | 26 | @doc """ 27 | Returns a random creature name 28 | 29 | ## Examples 30 | 31 | iex> Faker.Team.PtBr.creature() 32 | "corujas" 33 | iex> Faker.Team.PtBr.creature() 34 | "ovelha" 35 | iex> Faker.Team.PtBr.creature() 36 | "vampiros" 37 | iex> Faker.Team.PtBr.creature() 38 | "macacos" 39 | """ 40 | @spec creature() :: String.t() 41 | sampler(:creature, [ 42 | "formigas", 43 | "morcegos", 44 | "ursos", 45 | "abelhas", 46 | "pássaros", 47 | "gatos pretos", 48 | "búfalo", 49 | "gatos", 50 | "gado", 51 | "galinhas", 52 | "corvos", 53 | "cachorros", 54 | "golfinhos", 55 | "dragões", 56 | "patos", 57 | "elefantes", 58 | "elfos", 59 | "peixes", 60 | "raposas", 61 | "sapos", 62 | "gansos", 63 | "fantasmas", 64 | "gnomos", 65 | "cabras", 66 | "gansos", 67 | "cavalos", 68 | "cangurus", 69 | "leões", 70 | "macacos", 71 | "oráculos", 72 | "corujas", 73 | "bois", 74 | "pinguins", 75 | "pessoas", 76 | "porcos", 77 | "profetas", 78 | "coelhos", 79 | "ovelha", 80 | "filhos", 81 | "feiticeiros", 82 | "aranhas", 83 | "espíritos", 84 | "tigres", 85 | "vampiros", 86 | "vixens", 87 | "warlocks", 88 | "lobisomens", 89 | "baleias", 90 | "bruxas", 91 | "lobos", 92 | "zebras", 93 | "zumbis" 94 | ]) 95 | end 96 | -------------------------------------------------------------------------------- /lib/faker/util/en.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.Util.En do 2 | @moduledoc false 3 | 4 | import Faker.Util, only: [pick: 1] 5 | 6 | @digit ~w/0 1 2 3 4 5 6 7 8 9/ 7 | @lowercase_alphabet ~w/a b c d e f g h i j k l m n o p q r s t u v w x y z/ 8 | @uppercase_alphabet ~w/A B C D E F G H I J K L M N O P Q R S T U V W X Y Z/ 9 | @alphabet @lowercase_alphabet ++ @uppercase_alphabet 10 | 11 | @doc """ 12 | Get a random digit as a string; one of 0-9 13 | """ 14 | @spec digit() :: binary 15 | def digit do 16 | pick(@digit) 17 | end 18 | 19 | @doc """ 20 | Get a random alphabet character as a string; one of a-z or A-Z 21 | """ 22 | @spec letter() :: binary 23 | def letter do 24 | pick(@alphabet) 25 | end 26 | 27 | @doc """ 28 | Get a random lowercase character as a string; one of a-z 29 | """ 30 | @spec lower_letter() :: binary 31 | def lower_letter do 32 | pick(@lowercase_alphabet) 33 | end 34 | 35 | @doc """ 36 | Get a random uppercase character as a string; one of A-Z 37 | """ 38 | @spec upper_letter() :: binary 39 | def upper_letter do 40 | pick(@uppercase_alphabet) 41 | end 42 | 43 | @doc """ 44 | Converts a list to a string, with "and" before the last item. Uses an Oxford comma. 45 | """ 46 | @spec to_sentence([binary]) :: binary 47 | def to_sentence([]), do: "" 48 | def to_sentence([single]), do: single 49 | def to_sentence([first, second]), do: "#{first} and #{second}" 50 | def to_sentence([first | rest]), do: Enum.join(rest, ", ") <> ", and #{first}" 51 | end 52 | -------------------------------------------------------------------------------- /lib/faker/uuid.ex: -------------------------------------------------------------------------------- 1 | defmodule Faker.UUID do 2 | @moduledoc """ 3 | Functions for generating UUID's. 4 | """ 5 | 6 | @uuid_v4 4 7 | 8 | @variant10 2 9 | 10 | @doc """ 11 | Generate a random v4 UUID. 12 | 13 | ## Examples 14 | 15 | iex> Faker.UUID.v4() 16 | "d6d98b88-c866-4496-9bd4-de7ba48d0f52" 17 | iex> Faker.UUID.v4() 18 | "29fa7bf9-0728-4272-a7bc-5b7c964f332d" 19 | iex> Faker.UUID.v4() 20 | "c9edd02c-c9f3-41de-b9d9-22a146bf8550" 21 | iex> Faker.UUID.v4() 22 | "8a5f03ff-1875-4bf3-a3f4-aef1264e3bcc" 23 | """ 24 | @spec v4() :: String.t() 25 | def v4 do 26 | <> = Faker.random_bytes(16) 27 | 28 | <> 29 | |> uuid_to_string() 30 | end 31 | 32 | defp uuid_to_string(<>) do 33 | [ 34 | Base.encode16(<>, case: :lower), 35 | ?-, 36 | Base.encode16(<>, case: :lower), 37 | ?-, 38 | Base.encode16(<>, case: :lower), 39 | ?-, 40 | Base.encode16(<>, case: :lower), 41 | ?-, 42 | Base.encode16(<>, case: :lower) 43 | ] 44 | |> IO.iodata_to_binary() 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /mix.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.Mixfile do 2 | use Mix.Project 3 | 4 | @source_url "https://github.com/elixirs/faker" 5 | @version "0.19.0-alpha.1" 6 | 7 | def project do 8 | [ 9 | app: :faker, 10 | version: @version, 11 | elixir: "~> 1.6", 12 | description: "Faker is a pure Elixir library for generating fake data.", 13 | package: package(), 14 | name: "Faker", 15 | deps: deps(), 16 | docs: docs(), 17 | source_url: @source_url, 18 | homepage_url: @source_url, 19 | preferred_cli_env: [ 20 | "test.watch": :test 21 | ], 22 | dialyzer: [ 23 | flags: [ 24 | :error_handling, 25 | :race_conditions, 26 | :underspecs 27 | ] 28 | ] 29 | ] 30 | end 31 | 32 | def application do 33 | [ 34 | # mod: {Faker.Application, []}, 35 | extra_applications: [:crypto, :makeup], 36 | env: env() 37 | ] 38 | end 39 | 40 | defp env do 41 | [ 42 | locale: :en, 43 | country: nil, 44 | random_module: Faker.Random.Elixir 45 | ] 46 | end 47 | 48 | defp deps do 49 | [ 50 | {:credo, "== 1.7.11", only: [:dev, :test], runtime: false}, 51 | {:dialyxir, "== 1.4.5", only: [:dev], runtime: false}, 52 | {:earmark, "== 1.4.47", only: :dev, runtime: false}, 53 | {:ex_doc, "== 0.37.0", only: :dev, runtime: false}, 54 | {:makeup, "== 1.2.1"}, 55 | {:makeup_elixir, "== 1.0.1"}, 56 | {:mix_test_watch, "== 1.2.0", only: [:dev, :test], runtime: false} 57 | ] 58 | end 59 | 60 | defp docs do 61 | [ 62 | main: "readme", 63 | extras: ["CHANGELOG.md", "README.md"], 64 | skip_undefined_reference_warnings_on: ["CHANGELOG.md"], 65 | source_url: @source_url, 66 | source_ref: "v#{@version}" 67 | ] 68 | end 69 | 70 | defp package do 71 | [ 72 | maintainers: ["Anthony Smith", "Igor Kapkov", "Toby Hinloopen", "Vitor Oliveira"], 73 | files: ["lib", "mix.exs", "mix.lock", "README.md", "LICENSE", "CHANGELOG.md"], 74 | licenses: ["MIT"], 75 | links: %{"GitHub" => @source_url} 76 | ] 77 | end 78 | end 79 | -------------------------------------------------------------------------------- /mix.lock: -------------------------------------------------------------------------------- 1 | %{ 2 | "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"}, 3 | "credo": {:hex, :credo, "1.7.11", "d3e805f7ddf6c9c854fd36f089649d7cf6ba74c42bc3795d587814e3c9847102", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "56826b4306843253a66e47ae45e98e7d284ee1f95d53d1612bb483f88a8cf219"}, 4 | "dialyxir": {:hex, :dialyxir, "1.4.5", "ca1571ac18e0f88d4ab245f0b60fa31ff1b12cbae2b11bd25d207f865e8ae78a", [:mix], [{:erlex, ">= 0.2.7", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "b0fb08bb8107c750db5c0b324fa2df5ceaa0f9307690ee3c1f6ba5b9eb5d35c3"}, 5 | "earmark": {:hex, :earmark, "1.4.47", "7e7596b84fe4ebeb8751e14cbaeaf4d7a0237708f2ce43630cfd9065551f94ca", [:mix], [], "hexpm", "3e96bebea2c2d95f3b346a7ff22285bc68a99fbabdad9b655aa9c6be06c698f8"}, 6 | "earmark_parser": {:hex, :earmark_parser, "1.4.43", "34b2f401fe473080e39ff2b90feb8ddfeef7639f8ee0bbf71bb41911831d77c5", [:mix], [], "hexpm", "970a3cd19503f5e8e527a190662be2cee5d98eed1ff72ed9b3d1a3d466692de8"}, 7 | "erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"}, 8 | "ex_doc": {:hex, :ex_doc, "0.37.0", "970f92b39e62c460aa8a367508e938f5e4da6e2ff3eaed3f8530b25870f45471", [:mix], [{:earmark_parser, "~> 1.4.42", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "b0ee7f17373948e0cf471e59c3a0ee42f3bd1171c67d91eb3626456ef9c6202c"}, 9 | "file_system": {:hex, :file_system, "1.1.0", "08d232062284546c6c34426997dd7ef6ec9f8bbd090eb91780283c9016840e8f", [:mix], [], "hexpm", "bfcf81244f416871f2a2e15c1b515287faa5db9c6bcf290222206d120b3d43f6"}, 10 | "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"}, 11 | "makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"}, 12 | "makeup_elixir": {:hex, :makeup_elixir, "1.0.1", "e928a4f984e795e41e3abd27bfc09f51db16ab8ba1aebdba2b3a575437efafc2", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "7284900d412a3e5cfd97fdaed4f5ed389b8f2b4cb49efc0eb3bd10e2febf9507"}, 13 | "makeup_erlang": {:hex, :makeup_erlang, "1.0.2", "03e1804074b3aa64d5fad7aa64601ed0fb395337b982d9bcf04029d68d51b6a7", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "af33ff7ef368d5893e4a267933e7744e46ce3cf1f61e2dccf53a111ed3aa3727"}, 14 | "mix_test_watch": {:hex, :mix_test_watch, "1.2.0", "1f9acd9e1104f62f280e30fc2243ae5e6d8ddc2f7f4dc9bceb454b9a41c82b42", [:mix], [{:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm", "278dc955c20b3fb9a3168b5c2493c2e5cffad133548d307e0a50c7f2cfbf34f6"}, 15 | "nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"}, 16 | } 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "clean": "rm -rf _build deps node_modules erl_crash.dump .elixir_ls" 4 | }, 5 | "devDependencies": { 6 | "@semantic-release/changelog": "6.0.3", 7 | "@semantic-release/commit-analyzer": "13.0.1", 8 | "@semantic-release/exec": "^7.0.0", 9 | "@semantic-release/git": "10.0.1", 10 | "@semantic-release/github": "11.0.1", 11 | "@semantic-release/release-notes-generator": "14.0.3", 12 | "conventional-changelog-conventionalcommits": "8.0.0", 13 | "semantic-release": "24.2.1", 14 | "semantic-release-replace-plugin": "1.2.7" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": ["config:base"], 4 | "lockFileMaintenance": { "enabled": true } 5 | } 6 | -------------------------------------------------------------------------------- /test/faker/address_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.AddressTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Address 5 | doctest Faker.Address.En 6 | doctest Faker.Address.Es 7 | doctest Faker.Address.Hy 8 | doctest Faker.Address.It 9 | doctest Faker.Address.PtBr 10 | doctest Faker.Address.Ru 11 | end 12 | -------------------------------------------------------------------------------- /test/faker/airports_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.AirportsTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Airports 5 | doctest Faker.Airports.En 6 | doctest Faker.Airports.PtBr 7 | end 8 | -------------------------------------------------------------------------------- /test/faker/app_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.AppTest do 2 | use ExUnit.Case, async: true 3 | 4 | import Faker.App 5 | 6 | doctest Faker.App 7 | 8 | @iterations 10_000 9 | 10 | test "semver/0" do 11 | Stream.repeatedly(&semver/0) 12 | |> Enum.take(@iterations) 13 | |> Enum.each(fn generated_value -> 14 | assert {:ok, %Version{}} = Version.parse(generated_value) 15 | end) 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /test/faker/avatar_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.AvatarTest do 2 | use ExUnit.Case, async: true 3 | 4 | import Faker.Avatar 5 | 6 | doctest Faker.Avatar 7 | 8 | test "image_url/0" do 9 | assert String.starts_with?(image_url(), "https://robohash.org/") 10 | end 11 | 12 | test "image_url/1" do 13 | assert String.starts_with?(image_url("myslug"), "https://robohash.org/") 14 | assert String.contains?(image_url("myslug"), "myslug") 15 | end 16 | 17 | test "image_url/2" do 18 | assert String.contains?(image_url(40, 60), "40x60") 19 | end 20 | 21 | test "image_url/3" do 22 | assert String.contains?(image_url("myslug", 70, 20), "70x20") 23 | assert String.contains?(image_url("myslug", 70, 20), "myslug") 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /test/faker/aws_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.AwsTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Aws.En 5 | doctest Faker.Aws.Fr 6 | doctest Faker.Aws.PtPt 7 | doctest Faker.Aws.PtBr 8 | end 9 | -------------------------------------------------------------------------------- /test/faker/beer_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.BeerTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Beer 5 | doctest Faker.Beer.En 6 | end 7 | -------------------------------------------------------------------------------- /test/faker/blockchain/bitcoin_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.Blockchain.BitcoinTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Blockchain.Bitcoin 5 | end 6 | -------------------------------------------------------------------------------- /test/faker/blockchain/ethereum_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.Blockchain.EthereumTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Blockchain.Ethereum 5 | end 6 | -------------------------------------------------------------------------------- /test/faker/cannabis_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.CannabisTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Cannabis 5 | doctest Faker.Cannabis.En 6 | end 7 | -------------------------------------------------------------------------------- /test/faker/cat_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.Cat.EnTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Cat 5 | doctest Faker.Cat.En 6 | doctest Faker.Cat.PtBr 7 | end 8 | -------------------------------------------------------------------------------- /test/faker/code/iban_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.Code.IbanTest do 2 | use ExUnit.Case, async: true 3 | 4 | import Faker.Code.Iban 5 | 6 | doctest Faker.Code.Iban 7 | 8 | @iterations 10_000 9 | 10 | test "iban/1 returns iban with valid length" do 11 | Stream.repeatedly(fn -> iban("NL") end) 12 | |> Enum.take(@iterations) 13 | |> Enum.each(fn generated_value -> 14 | assert 18 = String.length(generated_value) 15 | end) 16 | end 17 | 18 | test "iban/1 with country code returns iban for that country" do 19 | Stream.repeatedly(fn -> iban("BE") end) 20 | |> Enum.take(@iterations) 21 | |> Enum.each(fn generated_value -> 22 | assert "BE" <> _tail = generated_value 23 | end) 24 | end 25 | 26 | test "iban/0 returns random iban" do 27 | Stream.repeatedly(&iban/0) 28 | |> Enum.take(@iterations) 29 | |> Enum.each(fn generated_value -> 30 | assert Regex.match?(~r/^[A-Z]{2}\d{2}[A-Z0-9]+$/, generated_value) 31 | end) 32 | end 33 | 34 | test "iban/1 with set of country codes returns an iban for one of these countries" do 35 | country_codes = ~w(NL BE DE FR) 36 | 37 | Stream.repeatedly(fn -> iban(country_codes) end) 38 | |> Enum.take(@iterations) 39 | |> Enum.each(fn <> -> 40 | assert iban_country_code in country_codes 41 | end) 42 | end 43 | 44 | test "iban/2 generates iban starting with given components" do 45 | Stream.repeatedly(fn -> iban("NL", ["INGB"]) end) 46 | |> Enum.take(@iterations) 47 | |> Enum.each(fn generated_value -> 48 | assert Regex.match?(~r/NL\d{2}INGB\d{10}/, generated_value) 49 | end) 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /test/faker/code_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.CodeTest do 2 | use ExUnit.Case, async: true 3 | 4 | import Faker.Code 5 | 6 | doctest Faker.Code 7 | 8 | @iterations 10_000 9 | 10 | defp grapheme_to_digit("X"), do: 10 11 | defp grapheme_to_digit(str), do: String.to_integer(str) 12 | 13 | defp checksum(isbn, calc_function) do 14 | String.reverse(isbn) 15 | |> String.graphemes() 16 | |> Stream.with_index() 17 | |> Stream.map(calc_function) 18 | |> Enum.sum() 19 | end 20 | 21 | defp calc_function10 do 22 | fn {e, i} -> grapheme_to_digit(e) * (i + 1) end 23 | end 24 | 25 | defp calc_function13 do 26 | fn {e, i} -> 27 | if rem(i, 2) == 1 do 28 | grapheme_to_digit(e) * 3 29 | else 30 | grapheme_to_digit(e) 31 | end 32 | end 33 | end 34 | 35 | test "isbn/0" do 36 | Stream.repeatedly(&isbn/0) 37 | |> Enum.take(@iterations) 38 | |> Enum.each(fn generated_value -> 39 | assert String.length(generated_value) == 10 40 | checksum10 = checksum(isbn(), calc_function10()) 41 | assert rem(checksum10, 11) == 0 42 | end) 43 | end 44 | 45 | test "isbn10/0" do 46 | assert is_binary(isbn10()) 47 | assert String.length(isbn10()) == 10 48 | checksum10 = checksum(isbn10(), calc_function10()) 49 | assert rem(checksum10, 11) == 0 50 | end 51 | 52 | test "isbn13/0" do 53 | assert is_binary(isbn13()) 54 | assert String.length(isbn13()) == 13 55 | checksum13 = checksum(isbn13(), calc_function13()) 56 | assert rem(checksum13, 10) == 0 57 | end 58 | 59 | test "issn/0" do 60 | assert is_binary(issn()) 61 | assert String.length(issn()) == 8 62 | assert Regex.match?(~r/^\d{7}[\dX]$/, issn()) 63 | end 64 | end 65 | -------------------------------------------------------------------------------- /test/faker/color_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.ColorTest do 2 | use ExUnit.Case, async: true 3 | 4 | import Faker.Color 5 | 6 | doctest Faker.Color 7 | doctest Faker.Color.En 8 | doctest Faker.Color.Es 9 | doctest Faker.Color.Fr 10 | doctest Faker.Color.Hy 11 | doctest Faker.Color.It 12 | doctest Faker.Color.PtBr 13 | 14 | @iterations 10_000 15 | 16 | test "rgb_decimal/0" do 17 | Stream.repeatedly(&rgb_decimal/0) 18 | |> Enum.take(@iterations) 19 | |> Enum.each(fn generated_value -> 20 | assert tuple_size(generated_value) == 3 21 | assert generated_value |> Tuple.to_list() |> Enum.all?(&(&1 >= 0)) 22 | assert generated_value |> Tuple.to_list() |> Enum.all?(&(&1 <= 255)) 23 | end) 24 | end 25 | 26 | test "rgb_hex/0" do 27 | Stream.repeatedly(&rgb_hex/0) 28 | |> Enum.take(@iterations) 29 | |> Enum.each(fn generated_value -> 30 | assert String.length(generated_value) == 6 31 | assert Regex.match?(~r/^[0-9A-F]{6}$/, generated_value) 32 | end) 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /test/faker/commerce_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.CommerceTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Commerce 5 | doctest Faker.Commerce.En 6 | doctest Faker.Commerce.Hy 7 | doctest Faker.Commerce.PtBr 8 | 9 | test "price/0" do 10 | assert is_float(Faker.Commerce.price()) 11 | assert Faker.Commerce.price() <= 100.0 12 | assert Faker.Commerce.price() >= 0.0 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /test/faker/company_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.CompanyTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Company 5 | doctest Faker.Company.En 6 | doctest Faker.Company.Hy 7 | end 8 | -------------------------------------------------------------------------------- /test/faker/currency_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.CurrencyTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Currency 5 | end 6 | -------------------------------------------------------------------------------- /test/faker/date_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.DateTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Date 5 | 6 | test "date_of_birth/0" do 7 | assert age(Faker.Date.date_of_birth()) in 18..99 8 | end 9 | 10 | test "date_of_birth/1 with exact age" do 11 | assert age(Faker.Date.date_of_birth(1)) == 1 12 | end 13 | 14 | test "date_of_birth/1 with age range" do 15 | assert age(Faker.Date.date_of_birth(12..99)) in 12..99 16 | end 17 | 18 | test "forward/1" do 19 | forwarded_date = Faker.Date.forward(10) 20 | assert %Date{year: year, month: month, day: day} = forwarded_date 21 | assert now().year < year || now().month < month || now().day < day 22 | end 23 | 24 | test "backward/1" do 25 | backward_date = Faker.Date.backward(10) 26 | assert %Date{year: year, month: month, day: day} = backward_date 27 | assert now().year > year || now().month > month || now().day > day 28 | end 29 | 30 | test "between/2" do 31 | from_date = ~D[2017-01-01] 32 | to_date = ~D[2017-01-10] 33 | between_date = Faker.Date.between(from_date, to_date) 34 | assert %Date{year: year, month: month, day: day} = between_date 35 | assert from_date.year <= year || from_date.month <= month || from_date.day <= day 36 | assert to_date.year >= year || from_date.month >= month || to_date.day >= day 37 | end 38 | 39 | defp age(%Date{year: year, month: month, day: day}) do 40 | %Date{year: current_year, month: current_month, day: current_day} = now() 41 | min_age = current_year - year - 1 42 | 43 | had_birthday_this_year = 44 | current_month > month || (current_month == month && current_day >= day) 45 | 46 | if had_birthday_this_year, 47 | do: min_age + 1, 48 | else: min_age 49 | end 50 | 51 | defp now do 52 | DateTime.utc_now() |> DateTime.to_date() 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /test/faker/datetime_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.DateTimeTest do 2 | use ExUnit.Case, async: true 3 | 4 | test "forward/1" do 5 | now = DateTime.utc_now() 6 | forwarded_date = Faker.DateTime.forward(10) 7 | 8 | assert %DateTime{ 9 | year: year, 10 | month: month, 11 | day: day, 12 | hour: hour, 13 | minute: minute, 14 | second: second, 15 | microsecond: microsecond 16 | } = forwarded_date 17 | 18 | assert now.year < year || now.month < month || now.hour < hour || now.minute < minute || 19 | now.day < day || now.second < second || now.microsecond < microsecond 20 | end 21 | 22 | test "backward/1" do 23 | now = DateTime.utc_now() 24 | backward_date = Faker.DateTime.backward(10) 25 | 26 | assert %DateTime{ 27 | year: year, 28 | month: month, 29 | day: day, 30 | hour: hour, 31 | minute: minute, 32 | second: second, 33 | microsecond: microsecond 34 | } = backward_date 35 | 36 | assert now.year > year || now.month > month || now.hour > hour || now.minute > minute || 37 | now.day > day || now.second > second || now.microsecond > microsecond 38 | end 39 | 40 | test "between/2 for Date.t" do 41 | from_date = DateTime.utc_now() |> DateTime.to_date() 42 | to_date = Faker.DateTime.forward(50) |> DateTime.to_date() 43 | between_date = Faker.DateTime.between(from_date, to_date) 44 | assert %DateTime{year: year, month: month, day: day} = between_date 45 | assert from_date.year <= year || from_date.month <= month || from_date.day <= day 46 | assert to_date.year >= year || to_date.month >= month || to_date.day >= day 47 | end 48 | 49 | test "between/2 for NaiveDateTime.t" do 50 | from_datetime = DateTime.utc_now() 51 | from_date = from_datetime |> DateTime.to_date() 52 | from_time = from_datetime |> DateTime.to_time() 53 | {:ok, from_naivedatetime} = NaiveDateTime.new(from_date, from_time) 54 | 55 | to_datetime = Faker.DateTime.forward(50) 56 | to_date = to_datetime |> DateTime.to_date() 57 | to_time = to_datetime |> DateTime.to_time() 58 | {:ok, to_naivedatetime} = NaiveDateTime.new(to_date, to_time) 59 | 60 | between_date = Faker.DateTime.between(from_naivedatetime, to_naivedatetime) 61 | 62 | assert %DateTime{ 63 | year: year, 64 | month: month, 65 | day: day, 66 | hour: hour, 67 | minute: minute, 68 | second: second, 69 | microsecond: microsecond 70 | } = between_date 71 | 72 | assert from_naivedatetime.year <= year || from_naivedatetime.month <= month || 73 | from_naivedatetime.hour <= hour || from_naivedatetime.minute <= minute || 74 | from_naivedatetime.day <= day || from_naivedatetime.second <= second || 75 | from_naivedatetime.microsecond <= microsecond 76 | 77 | assert to_naivedatetime.year >= year || to_naivedatetime.month >= month || 78 | to_naivedatetime.hour >= hour || to_naivedatetime.minute >= minute || 79 | to_naivedatetime.day >= day || to_naivedatetime.second >= second || 80 | to_naivedatetime.microsecond >= microsecond 81 | end 82 | 83 | test "between/2 for DateTime.t" do 84 | from_date = DateTime.utc_now() 85 | to_date = Faker.DateTime.forward(50) 86 | between_date = Faker.DateTime.between(from_date, to_date) 87 | 88 | assert %DateTime{ 89 | year: year, 90 | month: month, 91 | day: day, 92 | hour: hour, 93 | minute: minute, 94 | second: second, 95 | microsecond: microsecond 96 | } = between_date 97 | 98 | assert from_date.year <= year || from_date.month <= month || from_date.hour <= hour || 99 | from_date.minute <= minute || from_date.day <= day || from_date.second <= second || 100 | from_date.microsecond <= microsecond 101 | 102 | assert to_date.year >= year || to_date.month >= month || to_date.hour >= hour || 103 | to_date.minute >= minute || to_date.day >= day || to_date.second >= second || 104 | to_date.microsecond >= microsecond 105 | end 106 | end 107 | -------------------------------------------------------------------------------- /test/faker/dog_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.Dog.PtBrTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Dog.PtBr 5 | end 6 | -------------------------------------------------------------------------------- /test/faker/file_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.FileTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.File 5 | end 6 | -------------------------------------------------------------------------------- /test/faker/finance_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.FinanceTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Finance.Stock 5 | end 6 | -------------------------------------------------------------------------------- /test/faker/food_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.FoodTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Food 5 | doctest Faker.Food.En 6 | doctest Faker.Food.PtBr 7 | doctest Faker.Food.Hy 8 | end 9 | -------------------------------------------------------------------------------- /test/faker/fruit_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.FuitTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Fruit.PtBr 5 | doctest Faker.Fruit.En 6 | end 7 | -------------------------------------------------------------------------------- /test/faker/gov/it_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.Gov.ItTest do 2 | use ExUnit.Case, async: true 3 | 4 | import Faker.Gov.It 5 | 6 | doctest Faker.Gov.It 7 | 8 | @iterations 10_000 9 | 10 | test "fiscal id has a valid length" do 11 | Stream.repeatedly(&fiscal_id/0) 12 | |> Enum.take(@iterations) 13 | |> Enum.each(fn generated_value -> 14 | assert 16 = String.length(generated_value) 15 | end) 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /test/faker/gov/us_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.Gov.UsTest do 2 | use ExUnit.Case, async: true 3 | 4 | import Faker.Gov.Us 5 | 6 | doctest Faker.Gov.Us 7 | 8 | @iterations 10_000 9 | 10 | test "ssn is a valid length" do 11 | Stream.repeatedly(&ssn/0) 12 | |> Enum.take(@iterations) 13 | |> Enum.each(fn generated_value -> 14 | assert 11 = String.length(generated_value) 15 | end) 16 | end 17 | 18 | test "snn does not contain 900-999 in area" do 19 | Stream.repeatedly(&ssn/0) 20 | |> Enum.take(@iterations) 21 | |> Enum.each(fn <> -> 22 | refute String.to_integer(area) in 900..999 23 | end) 24 | end 25 | 26 | test "snn does not contain 666 in area" do 27 | Stream.repeatedly(&ssn/0) 28 | |> Enum.take(@iterations) 29 | |> Enum.each(fn generated_value -> 30 | refute String.contains?(generated_value, "666-") 31 | end) 32 | end 33 | 34 | test "snn does not contain 00 in group" do 35 | Stream.repeatedly(&ssn/0) 36 | |> Enum.take(@iterations) 37 | |> Enum.each(fn generated_value -> 38 | refute String.contains?(generated_value, "-00-") 39 | end) 40 | end 41 | 42 | test "snn does not contain 0000 in serial" do 43 | Stream.repeatedly(&ssn/0) 44 | |> Enum.take(@iterations) 45 | |> Enum.each(fn generated_value -> 46 | refute String.contains?(generated_value, "-0000") 47 | end) 48 | end 49 | 50 | test "ein is a valid length" do 51 | Stream.repeatedly(&ein/0) 52 | |> Enum.take(@iterations) 53 | |> Enum.each(fn generated_value -> 54 | assert 10 = String.length(generated_value) 55 | end) 56 | end 57 | 58 | test "ein does not contain 00 in campus" do 59 | Stream.repeatedly(&ein/0) 60 | |> Enum.take(@iterations) 61 | |> Enum.each(fn generated_value -> 62 | refute String.contains?(generated_value, "00-") 63 | end) 64 | end 65 | 66 | test "ein does not contain 0000000 in serial" do 67 | Stream.repeatedly(&ein/0) 68 | |> Enum.take(@iterations) 69 | |> Enum.each(fn generated_value -> 70 | refute String.contains?(generated_value, "-0000000") 71 | end) 72 | end 73 | end 74 | -------------------------------------------------------------------------------- /test/faker/industry_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.IndustryTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Industry 5 | doctest Faker.Industry.En 6 | doctest Faker.Industry.Hy 7 | end 8 | -------------------------------------------------------------------------------- /test/faker/internet/status_code_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.Internet.StatusCodeTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Internet.StatusCode 5 | end 6 | -------------------------------------------------------------------------------- /test/faker/internet/user_agent_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.Internet.UserAgentTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Internet.UserAgent 5 | end 6 | -------------------------------------------------------------------------------- /test/faker/internet_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.InternetTest do 2 | use ExUnit.Case, async: true 3 | 4 | import Faker.Internet 5 | 6 | doctest Faker.Internet 7 | doctest Faker.Internet.En 8 | doctest Faker.Internet.Es 9 | doctest Faker.Internet.Hy 10 | doctest Faker.Internet.It 11 | doctest Faker.Internet.PtBr 12 | 13 | @iterations 10_000 14 | 15 | test "ip_v4_address/0" do 16 | assert Regex.match?(~r/^(\d+\.){3}\d+$/, Faker.Internet.ip_v4_address()) 17 | end 18 | 19 | test "ip_v6_address/0" do 20 | assert Regex.match?(~r/^([0-9A-F]{4}:){7}[0-9A-F]{4}$/, Faker.Internet.ip_v6_address()) 21 | end 22 | 23 | test "mac_address/0" do 24 | assert Regex.match?(~r/^([0-9a-f]{2}:){5}[0-9a-f]{2}$/, Faker.Internet.mac_address()) 25 | end 26 | 27 | test "url/0" do 28 | assert Regex.match?(~r/^http[s]?:\/\/\w+\.\w+$/, Faker.Internet.url()) 29 | end 30 | 31 | test "slug/0" do 32 | assert Regex.match?(~r/\A([a-z0-9]+[-\._])*[a-z0-9]+\z/, Faker.Internet.slug()) 33 | end 34 | 35 | test "slug/1" do 36 | slug = Faker.Internet.slug(["hello", "world"]) 37 | 38 | assert Regex.match?(~r/\A((hello|world)[-\._])(hello|world)\z/, slug) 39 | end 40 | 41 | test "slug/2" do 42 | slug = Faker.Internet.slug(["hello", "world"], ["-"]) 43 | 44 | assert Regex.match?(~r/\A((hello|world)-)(hello|world)\z/, slug) 45 | end 46 | 47 | test "user_name/0" do 48 | special_characters_pattern = :binary.compile_pattern(["'", "\""]) 49 | 50 | Stream.repeatedly(&user_name/0) 51 | |> Enum.take(@iterations) 52 | |> Enum.each(fn generated_value -> 53 | refute String.contains?(generated_value, special_characters_pattern) 54 | end) 55 | end 56 | 57 | test "email/0" do 58 | special_characters_pattern = :binary.compile_pattern(["'", "\""]) 59 | 60 | Stream.repeatedly(&email/0) 61 | |> Enum.take(@iterations) 62 | |> Enum.each(fn generated_value -> 63 | refute String.contains?(generated_value, special_characters_pattern) 64 | end) 65 | end 66 | 67 | test "safe_email/0" do 68 | special_characters_pattern = :binary.compile_pattern(["'", "\""]) 69 | 70 | Stream.repeatedly(&safe_email/0) 71 | |> Enum.take(@iterations) 72 | |> Enum.each(fn generated_value -> 73 | refute String.contains?(generated_value, special_characters_pattern) 74 | end) 75 | end 76 | 77 | test "free_email/0" do 78 | special_characters_pattern = :binary.compile_pattern(["'", "\""]) 79 | 80 | Stream.repeatedly(&free_email/0) 81 | |> Enum.take(@iterations) 82 | |> Enum.each(fn generated_value -> 83 | refute String.contains?(generated_value, special_characters_pattern) 84 | end) 85 | end 86 | 87 | test "domain_word/0" do 88 | special_characters_pattern = :binary.compile_pattern(["'", "\""]) 89 | 90 | Stream.repeatedly(&domain_word/0) 91 | |> Enum.take(@iterations) 92 | |> Enum.each(fn generated_value -> 93 | refute String.contains?(generated_value, special_characters_pattern) 94 | end) 95 | end 96 | end 97 | -------------------------------------------------------------------------------- /test/faker/lorem/shakespeare_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.ShakespeareTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Lorem.Shakespeare 5 | doctest Faker.Lorem.Shakespeare.En 6 | doctest Faker.Lorem.Shakespeare.Ru 7 | end 8 | -------------------------------------------------------------------------------- /test/faker/lorem_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.LoremTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Lorem 5 | 6 | test "characters/0" do 7 | assert length(Faker.Lorem.characters()) in 15..255 8 | end 9 | 10 | test "characters/1" do 11 | assert is_list(Faker.Lorem.characters(2..10)) 12 | assert is_list(Faker.Lorem.characters(2)) 13 | assert length(Faker.Lorem.characters(2..10)) in 2..10 14 | assert length(Faker.Lorem.characters(2)) == 2 15 | assert length(Faker.Lorem.characters(10)) == 10 16 | end 17 | 18 | test "paragraph/0" do 19 | assert length(Regex.scan(~r/[.,?!]/, Faker.Lorem.paragraph())) in 2..5 20 | end 21 | 22 | test "paragraph/1" do 23 | assert length(Regex.scan(~r/[.,?!]/, Faker.Lorem.paragraph(2..3))) in 2..3 24 | assert length(Regex.scan(~r/[.,?!]/, Faker.Lorem.paragraph(2))) == 2 25 | assert length(Regex.scan(~r/[.,?!]/, Faker.Lorem.paragraph(3))) == 3 26 | end 27 | 28 | test "paragraphs/0" do 29 | assert is_list(Faker.Lorem.paragraphs()) 30 | assert length(Faker.Lorem.paragraphs()) in 2..5 31 | end 32 | 33 | test "paragraphs/1" do 34 | assert is_list(Faker.Lorem.paragraphs(4..6)) 35 | assert is_list(Faker.Lorem.paragraphs(3)) 36 | assert length(Faker.Lorem.paragraphs(4..6)) in 4..6 37 | assert length(Faker.Lorem.paragraphs(3)) == 3 38 | assert length(Faker.Lorem.paragraphs(5)) == 5 39 | end 40 | 41 | test "sentence/0" do 42 | assert String.ends_with?(Faker.Lorem.sentence(), [".", "!", "?"]) 43 | end 44 | 45 | test "sentence/1" do 46 | assert String.ends_with?(Faker.Lorem.sentence(4..7), [".", "!", "?"]) 47 | assert String.ends_with?(Faker.Lorem.sentence(4), [".", "!", "?"]) 48 | end 49 | 50 | test "sentence/2" do 51 | assert String.ends_with?(Faker.Lorem.sentence(4, "?"), "?") 52 | end 53 | 54 | test "sentences/0" do 55 | assert is_list(Faker.Lorem.sentences()) 56 | assert length(Faker.Lorem.sentences()) in 2..5 57 | end 58 | 59 | test "sentences/1" do 60 | assert is_list(Faker.Lorem.sentences(4..6)) 61 | assert is_list(Faker.Lorem.sentences(3)) 62 | assert length(Faker.Lorem.sentences(4..6)) in 4..6 63 | assert length(Faker.Lorem.sentences(3)) == 3 64 | assert length(Faker.Lorem.sentences(5)) == 5 65 | end 66 | 67 | test "words/0" do 68 | assert is_list(Faker.Lorem.words()) 69 | assert length(Faker.Lorem.words()) in 3..6 70 | end 71 | 72 | test "words/1" do 73 | assert is_list(Faker.Lorem.words(10..16)) 74 | assert is_list(Faker.Lorem.words(3)) 75 | assert length(Faker.Lorem.words(10..16)) in 10..16 76 | assert length(Faker.Lorem.words(3)) == 3 77 | assert length(Faker.Lorem.words(5)) == 5 78 | end 79 | end 80 | -------------------------------------------------------------------------------- /test/faker/markdown_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.MarkdownTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Markdown 5 | end 6 | -------------------------------------------------------------------------------- /test/faker/naivedatetime_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.NaiveDateTimeTest do 2 | use ExUnit.Case, async: true 3 | 4 | test "forward/1" do 5 | now_datetime = DateTime.utc_now() 6 | now_date = now_datetime |> DateTime.to_date() 7 | now_time = now_datetime |> DateTime.to_time() 8 | {:ok, now} = NaiveDateTime.new(now_date, now_time) 9 | 10 | forwarded_date = Faker.NaiveDateTime.forward(10) 11 | 12 | assert %NaiveDateTime{ 13 | year: year, 14 | month: month, 15 | day: day, 16 | hour: hour, 17 | minute: minute, 18 | second: second, 19 | microsecond: microsecond 20 | } = forwarded_date 21 | 22 | assert now.year < year || now.month < month || now.hour < hour || now.minute < minute || 23 | now.day < day || now.second < second || now.microsecond < microsecond 24 | end 25 | 26 | test "backward/1" do 27 | now_datetime = DateTime.utc_now() 28 | now_date = now_datetime |> DateTime.to_date() 29 | now_time = now_datetime |> DateTime.to_time() 30 | {:ok, now} = NaiveDateTime.new(now_date, now_time) 31 | 32 | backward_date = Faker.NaiveDateTime.backward(10) 33 | 34 | assert %NaiveDateTime{ 35 | year: year, 36 | month: month, 37 | day: day, 38 | hour: hour, 39 | minute: minute, 40 | second: second, 41 | microsecond: microsecond 42 | } = backward_date 43 | 44 | assert now.year > year || now.month > month || now.hour > hour || now.minute > minute || 45 | now.day > day || now.second > second || now.microsecond > microsecond 46 | end 47 | 48 | test "between/2" do 49 | from_datetime = DateTime.utc_now() 50 | from_date = from_datetime |> DateTime.to_date() 51 | from_time = from_datetime |> DateTime.to_time() 52 | {:ok, from_naivedatetime} = NaiveDateTime.new(from_date, from_time) 53 | 54 | to_datetime = Faker.DateTime.forward(50) 55 | to_date = to_datetime |> DateTime.to_date() 56 | to_time = to_datetime |> DateTime.to_time() 57 | {:ok, to_naivedatetime} = NaiveDateTime.new(to_date, to_time) 58 | 59 | between_date = Faker.DateTime.between(from_naivedatetime, to_naivedatetime) 60 | 61 | assert %DateTime{ 62 | year: year, 63 | month: month, 64 | day: day, 65 | hour: hour, 66 | minute: minute, 67 | second: second, 68 | microsecond: microsecond 69 | } = between_date 70 | 71 | assert from_naivedatetime.year <= year || from_naivedatetime.month <= month || 72 | from_naivedatetime.hour <= hour || from_naivedatetime.minute <= minute || 73 | from_naivedatetime.day <= day || from_naivedatetime.second <= second || 74 | from_naivedatetime.microsecond <= microsecond 75 | 76 | assert to_naivedatetime.year >= year || to_naivedatetime.month >= month || 77 | to_naivedatetime.hour >= hour || to_naivedatetime.minute >= minute || 78 | to_naivedatetime.day >= day || to_naivedatetime.second >= second || 79 | to_naivedatetime.microsecond >= microsecond 80 | end 81 | end 82 | -------------------------------------------------------------------------------- /test/faker/nato_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.NatoTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Nato 5 | end 6 | -------------------------------------------------------------------------------- /test/faker/person_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.PersonTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Person 5 | doctest Faker.Person.En 6 | doctest Faker.Person.Es 7 | doctest Faker.Person.Fr 8 | doctest Faker.Person.Hy 9 | doctest Faker.Person.It 10 | doctest Faker.Person.PtBr 11 | end 12 | -------------------------------------------------------------------------------- /test/faker/phone/en_gb_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.Phone.EnGbTest do 2 | use ExUnit.Case, async: true 3 | 4 | import Faker.Phone.EnGb 5 | 6 | @iterations 10_000 7 | 8 | test "landline_number/0 is a valid length" do 9 | Stream.repeatedly(&landline_number/0) 10 | |> Enum.take(@iterations) 11 | |> Enum.each(fn generated_value -> 12 | assert String.length(generated_value) == 12 13 | end) 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /test/faker/phone/en_us_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.Phone.EnUsTest do 2 | use ExUnit.Case, async: true 3 | 4 | import Faker.Phone.EnUs 5 | 6 | @iterations 10_000 7 | 8 | test "area_code/0 is a valid length" do 9 | Stream.repeatedly(&area_code/0) 10 | |> Enum.take(@iterations) 11 | |> Enum.each(fn generated_value -> 12 | assert String.length(generated_value) == 3 13 | end) 14 | end 15 | 16 | test "exchange_code/0 is a valid length" do 17 | Stream.repeatedly(&exchange_code/0) 18 | |> Enum.take(@iterations) 19 | |> Enum.each(fn generated_value -> 20 | assert String.length(generated_value) == 3 21 | end) 22 | end 23 | 24 | test "subscriber_number/0 is a valid length" do 25 | Stream.repeatedly(&subscriber_number/0) 26 | |> Enum.take(@iterations) 27 | |> Enum.each(fn generated_value -> 28 | assert String.length(generated_value) == 4 29 | end) 30 | end 31 | 32 | test "subscriber_number/1 is a valid length" do 33 | Stream.repeatedly(fn -> subscriber_number(3) end) 34 | |> Enum.take(@iterations) 35 | |> Enum.each(fn generated_value -> 36 | assert String.length(generated_value) == 3 37 | end) 38 | end 39 | 40 | test "extension/0 is a valid length" do 41 | Stream.repeatedly(&extension/0) 42 | |> Enum.take(@iterations) 43 | |> Enum.each(fn generated_value -> 44 | assert String.length(generated_value) == 4 45 | end) 46 | end 47 | 48 | test "extension/1 is a valid length" do 49 | Stream.repeatedly(fn -> extension(2) end) 50 | |> Enum.take(@iterations) 51 | |> Enum.each(fn generated_value -> 52 | assert String.length(generated_value) == 2 53 | end) 54 | end 55 | 56 | test "phone_digits/0 second digit of area code is not 9" do 57 | Stream.repeatedly(&phone_digits/0) 58 | |> Enum.take(@iterations) 59 | |> Enum.each(fn generated_value -> 60 | assert String.at(generated_value, 1) != "9" 61 | end) 62 | end 63 | 64 | test "phone_digits/0 is a valid length" do 65 | Stream.repeatedly(&phone_digits/0) 66 | |> Enum.take(@iterations) 67 | |> Enum.each(fn generated_value -> 68 | assert String.length(generated_value) == 10 69 | end) 70 | end 71 | 72 | test "phone_digits/0 central office segment does not start with 1" do 73 | Stream.repeatedly(&phone_digits/0) 74 | |> Enum.take(@iterations) 75 | |> Enum.each(fn generated_value -> 76 | assert String.at(generated_value, 3) != "1" 77 | end) 78 | end 79 | 80 | test "phone_digits/0 central office segment doesn't end with 11" do 81 | Stream.repeatedly(&phone_digits/0) 82 | |> Enum.take(@iterations) 83 | |> Enum.each(fn generated_value -> 84 | assert String.slice(generated_value, 4, 2) != "11" 85 | end) 86 | end 87 | 88 | defp phone_digits() do 89 | ~r/[0-9]/ 90 | |> Regex.scan(phone()) 91 | |> List.flatten() 92 | |> Enum.join() 93 | end 94 | end 95 | -------------------------------------------------------------------------------- /test/faker/phone/pt_pt_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.Phone.PtPtTest do 2 | use ExUnit.Case, async: true 3 | 4 | import Faker.Phone.PtPt 5 | 6 | @iterations 10_000 7 | 8 | test "landline_number/0 return starts with 2 or 3" do 9 | Stream.repeatedly(&landline_number/0) 10 | |> Enum.take(@iterations) 11 | |> Enum.each(fn generated_value -> 12 | assert String.match?(generated_value, ~r/^(2|3)[0-9]{8}$/) 13 | end) 14 | end 15 | 16 | test "cell_number/0 return starts with 91, 92, 93 or 96" do 17 | Stream.repeatedly(&cell_number/0) 18 | |> Enum.take(@iterations) 19 | |> Enum.each(fn generated_value -> 20 | assert String.match?(generated_value, ~r/^9(1|2|3|6)[0-9]{7}$/) 21 | end) 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /test/faker/phone_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.PhoneTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Phone.EnGb 5 | doctest Faker.Phone.EnUs 6 | doctest Faker.Phone.Hy 7 | doctest Faker.Phone.PtBr 8 | end 9 | -------------------------------------------------------------------------------- /test/faker/pizza_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.PizzaTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Pizza 5 | end 6 | -------------------------------------------------------------------------------- /test/faker/pokemon_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.PokemonTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Pokemon 5 | doctest Faker.Pokemon.En 6 | doctest Faker.Pokemon.De 7 | doctest Faker.Pokemon.It 8 | end 9 | -------------------------------------------------------------------------------- /test/faker/star_wars_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.StarWarsTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.StarWars 5 | doctest Faker.StarWars.En 6 | end 7 | -------------------------------------------------------------------------------- /test/faker/string_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.StringTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.String 5 | 6 | test "base64/1" do 7 | length = Faker.String.base64(12) |> String.length() 8 | assert length == 12 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /test/faker/superhero_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.SuperheroTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Superhero 5 | doctest Faker.Superhero.En 6 | end 7 | -------------------------------------------------------------------------------- /test/faker/team_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.TeamTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Team 5 | doctest Faker.Team.En 6 | doctest Faker.Team.PtBr 7 | end 8 | -------------------------------------------------------------------------------- /test/faker/util_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.UtilTest do 2 | use ExUnit.Case, async: true 3 | 4 | import Faker.Util 5 | 6 | doctest Faker.Util 7 | 8 | @iterations 10_000 9 | 10 | test "digit/0" do 11 | Stream.repeatedly(&digit/0) 12 | |> Enum.take(@iterations) 13 | |> Enum.each(fn generated_value -> 14 | assert generated_value in ~w/0 1 2 3 4 5 6 7 8 9/ 15 | end) 16 | end 17 | 18 | test "lower_letter/0" do 19 | Stream.repeatedly(&lower_letter/0) 20 | |> Enum.take(@iterations) 21 | |> Enum.each(fn generated_value -> 22 | assert generated_value in ~w/a b c d e f g h i j k l m n o p q r s t u v w x y z/ 23 | end) 24 | end 25 | 26 | test "upper_letter/0" do 27 | Stream.repeatedly(&upper_letter/0) 28 | |> Enum.take(@iterations) 29 | |> Enum.each(fn generated_value -> 30 | assert generated_value in ~w/A B C D E F G H I J K L M N O P Q R S T U V W X Y Z/ 31 | end) 32 | end 33 | 34 | test "letter/0" do 35 | Stream.repeatedly(&letter/0) 36 | |> Enum.take(@iterations) 37 | |> Enum.each(fn generated_value -> 38 | assert generated_value in ~w/a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z/ 39 | end) 40 | end 41 | 42 | test "cycle/2" do 43 | list = ~w/a b c/ 44 | my_cycle = Faker.Util.cycle_start(list) 45 | 46 | Stream.repeatedly(fn -> 47 | Stream.repeatedly(fn -> Faker.Util.cycle(my_cycle) end) |> Enum.take(3) 48 | end) 49 | |> Enum.take(@iterations) 50 | |> Enum.each(fn generated_value -> 51 | assert Enum.sort(generated_value) == list 52 | end) 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /test/faker/uuid_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.UUIDTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.UUID 5 | 6 | test "v4/0" do 7 | assert Regex.match?(~r/[\da-f]{8}-([\da-f]{4}-){3}[\da-f]{12}/i, Faker.UUID.v4()) 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /test/faker/vehicle_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Faker.VehicleTest do 2 | use ExUnit.Case, async: true 3 | 4 | doctest Faker.Vehicle 5 | doctest Faker.Vehicle.En 6 | end 7 | -------------------------------------------------------------------------------- /test/faker_test.exs: -------------------------------------------------------------------------------- 1 | defmodule FakerTest do 2 | use ExUnit.Case, async: true 3 | 4 | test :format do 5 | assert Regex.match?(~r/\w{3}\d{4}@\w{4}\.\w{3}/, Faker.format("???####@????.???")) 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /test/test_helper.exs: -------------------------------------------------------------------------------- 1 | :ets.new(:seed_registry, [:named_table, :public]) 2 | Application.put_env(:faker, :random_module, Faker.Random.Test) 3 | ExUnit.start() 4 | --------------------------------------------------------------------------------