Giter Site home page Giter Site logo

faker's Introduction

Faker (WIP, do not use this library in production)

quality Build Status GoDoc

Faker is a Golang library that generates all type of fake data. Including localized data.

This library is inspired by same libs in other languages like Perl's, ruby's and PHP's Faker.

Faker has been built and tested with Go >= 1.10

Content

Installing

Just use go get

go get -u github.com/Rulox/faker

Or add the library to your project and use dep ensure

Usage

The main struct generator/Faker provides all the usability for you in order to create the fake data. It is necessary to use faker.NewFaker() function in order to load default values in some variables.

Faker has different type of generators (for Misc data, Addresses, Companies, Phones, etc).

In code

    f := faker.NewFaker("en_US") // Use en_US locale
    f.Misc.RandomInt()  // 54
    f.Address.Street()  // Bedford 

Generators

A faker instance has multiple generators. Go to the documentation to check all of them.

Locales

The locales are organized in YAML files called faker.yml inside each language folder. The default locale is en_US. A lot of help to create new locales for languages is needed and the format is so easy that anyone (even if you're not a developer) can supply data following the format.

Set your locale

Setting a locale is really easy. The locale string is passed in the NewFaker function. This function will (among other stuff) load the yaml corresponding to the language code you choose. Please be careful, use the name of the folder as the locale name string.

	f := faker.NewFaker("es_ES")

You can also change the locale after having your faker initialized

	f := faker.NewFaker("en_GB")
	// do your stuff here with en_GB set
	f.SetLocale("es_ES")
	// Spanish time!

FAQ

  • Is the data real?
    • The data is randomly chosen so no. You may end up with a wrong province/state/zip code combination
  • What about gender? Does the library take care of the right combination?
    • Not really. There's a plan to add this capability in the future though.
  • What about a CLI or console tool?
    • Is in the roadmap! Check the project regularly
  • How can I Help?
    • There's always a missing language or feature. Feel free to open an issue or even better, a pull request to help this library growing

License

This code is free to use under the terms of the MIT license. See LICENSE.md for more information.

faker's People

Contributors

rulox avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.