faker

package module
Version: v1.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2020 License: MIT Imports: 15 Imported by: 21

README

faker

Faker is a library for generating fake data such as names, addresses, and phone numbers.

It is a (mostly) API-compatible port of Ruby Faker gem (https://github.com/stympy/faker) to Go.

GoDoc Build Status Coverage Status

To install

go get -u syreclabs.com/go/faker

Usage

Address

faker.Address().City()                        // => "North Dessie"
faker.Address().StreetName()                  // => "Buckridge Lakes"
faker.Address().StreetAddress()               // => "586 Sylvester Turnpike"
faker.Address().SecondaryAddress()            // => "Apt. 411"
faker.Address().BuildingNumber()              // => "754"
faker.Address().Postcode()                    // => "31340"
faker.Address().PostcodeByState("IN")         // => "46511"
faker.Address().ZipCode()                     // ZipCode is an alias for Postcode.
faker.Address().ZipCodeByState("IN")          // ZipCodeByState is an alias for PostcodeByState.
faker.Address().TimeZone()                    // => "Asia/Taipei"
faker.Address().CityPrefix()                  // => "East"
faker.Address().CitySuffix()                  // => "town"
faker.Address().StreetSuffix()                // => "Square"
faker.Address().State()                       // => "Maryland"
faker.Address().StateAbbr()                   // => "IL"
faker.Address().Country()                     // => "Uruguay"
faker.Address().CountryCode()                 // => "JP"
faker.Address().Latitude()                    // => (float32) -38.811367
faker.Address().Longitude()                   // => (float32) 89.2171
faker.Address().String()                      // => "6071 Heaney Island Suite 553, Ebbaville Texas 37307"
App

faker.App().Name()    // => "Alphazap"
faker.App().Version() // => "2.6.0"
faker.App().Author()  // => "Dorian Shields"
faker.App().String()  // => "Tempsoft 4.51"
Avatar

faker.Avatar().Url("jpg", 100, 200) // => "http://robohash.org/NX34rZw7s0VFzgWY.jpg?size=100x200"
faker.Avatar().String()             // => "http://robohash.org/XRWjFigoImqdeDuA.png?size=300x300"
Bitcoin

faker.Bitcoin().Address() // => "1GpEKM5UvD4XDLMirpNLoDnRVrGutogMj2"
faker.Bitcoin().String()  // String is an alias for Address.
Business

faker.Business().CreditCardNumber()     // => "1234-2121-1221-1211"
faker.Business().CreditCardExpiryDate() // => "2015-11-11"
faker.Business().CreditCardType()       // => "mastercard"
Code

faker.Code().Isbn10() // => "048931033-8"
faker.Code().Isbn13() // => "391668236072-1"
faker.Code().Ean13()  // => "7742864258656"
faker.Code().Ean8()   // => "03079010"
faker.Code().Rut()    // => "14371602-3"
faker.Code().Abn()    // => "57914951376"
Commerce

faker.Commerce().Color()       // => "lime"
faker.Commerce().Department()  // => "Electronics, Health & Baby"
faker.Commerce().ProductName() // => "Ergonomic Granite Shoes"
faker.Commerce().Price()       // => (float32) 97.79
Company

faker.Company().Name()        // => "Aufderhar LLC"
faker.Company().Suffix()      // => "Inc"
faker.Company().CatchPhrase() // => "Universal logistical artificial intelligence"
faker.Company().Bs()          // => "engage distributed applications"
faker.Company().Ein()         // => "58-6520513"
faker.Company().DunsNumber()  // => "16-708-2968"
faker.Company().Logo()        // => "http://www.biz-logo.com/examples/015.gif"
faker.Company().String()      // String is an alias for Name.
Date

// Between returns random time in [from, to] interval, with second resolution.
faker.Date().Between(from, to time.Time) time.Time

// Forward returns random time in [time.Now(), time.Now() + duration] interval, with second resolution.
faker.Date().Forward(duration time.Duration) time.Time

// Backward returns random time in [time.Now() - duration, time.Now()] interval, with second resolution.
faker.Date().Backward(duration time.Duration) time.Time

// Birthday returns random time so that age of the person born at that moment would be between minAge and maxAge years.
faker.Date().Birthday(minAge, maxAge int) time.Time
Finance

// CreditCard returns a valid (with valid check digit) card number of one of the given types.
// If no types are passed, all types in CC_TYPES are used.
faker.Finance().CreditCard(faker.CC_VISA) // => "4190418835414"
Hacker

faker.Hacker().SaySomethingSmart() // => "If we connect the bus, we can get to the XML microchip through the digital TCP sensor!"
faker.Hacker().Abbreviation()      // => "HTTP"
faker.Hacker().Adjective()         // => "cross-platform"
faker.Hacker().Noun()              // => "interface"
faker.Hacker().Verb()              // => "bypass"
faker.Hacker().IngVerb()           // => "parsing"
faker.Hacker().Phrases() []string  // => []string{
                                   //        "If we bypass the program, we can get to the AGP protocol through the optical SDD alarm!",
                                   //        "We need to calculate the back-end XML microchip!",
                                   //        "Try to generate the GB bus, maybe it will hack the neural panel!",
                                   //        "You can't navigate the transmitter without synthesizing the optical SMS bus!",
                                   //        "Use the optical THX application, then you can override the mobile port!",
                                   //        "The CSS monitor is down, quantify the multi-byte bus so we can calculate the XSS bandwidth!",
                                   //        "Connecting the card won't do anything, we need to back up the multi-byte RSS card!",
                                   //        "I'll reboot the primary SMTP feed, that should monitor the XML protocol!`",
                                   //    }
Internet

faker.Internet().Email()                // => "maritza@farrell.org"
faker.Internet().FreeEmail()            // => "sven_rice@hotmail.com"
faker.Internet().SafeEmail()            // => "theron.nikolaus@example.net"
faker.Internet().UserName()             // => "micah_pfeffer"
faker.Internet().Password(8, 14)        // => "s5CzvVp6Ye"
faker.Internet().DomainName()           // => "rolfson.info"
faker.Internet().DomainWord()           // => "heller"
faker.Internet().DomainSuffix()         // => "net"
faker.Internet().MacAddress()           // => "15:a9:83:29:76:26"
faker.Internet().IpV4Address()          // => "121.204.82.227"
faker.Internet().IpV6Address()          // => "c697:392f:6a0e:bf6d:77e1:714a:10ab:0dbc"
faker.Internet().Url()                  // => "http://sporerhamill.net/kyla.schmitt"
faker.Internet().Slug()                 // => "officiis-commodi"
Lorem

faker.Lorem().Character()    // => "c"
faker.Lorem().Characters(17) // => "wqFyJIrXYfVP7cL9M"
faker.Lorem().Word()         // => "veritatis"
faker.Lorem().Words(3)       // => []string{"omnis", "libero", "neque"}
faker.Lorem().Sentence(3)    // => "Necessitatibus sit autem."

// Sentences returns a slice of "num" sentences, 3 to 11 words each.
faker.Lorem().Sentences(num int) []string

// Paragraph returns a random text of "sentences" sentences length.
faker.Lorem().Paragraph(sentences int)

// Paragraphs returns a slice of "num" paragraphs, 3 to 11 sentences each.
faker.Lorem().Paragraphs(num int) []string

// String returns a random sentence 3 to 11 words in length.
faker.Lorem().String()
Name

faker.Name().Name()      // => "Natasha Hartmann"
faker.Name().FirstName() // => "Carolina"
faker.Name().LastName()  // => "Kohler"
faker.Name().Prefix()    // => "Dr."
faker.Name().Suffix()    // => "Jr."
faker.Name().Title()     // => "Chief Functionality Orchestrator"
faker.Name().String()    // String is an alias for Name.
Number

faker.Number().Number(5)          // => "43202"
faker.Number().NumberInt(3)       // => 213
faker.Number().NumberInt32(5)     // => 92938
faker.Number().NumberInt64(19)    // => 1689541633257139096
faker.Number().Decimal(8, 2)      // => "879420.60"
faker.Number().Digit()            // => "7"
faker.Number().Hexadecimal(4)     // => "e7f3"
faker.Number().Between(-100, 100) // => "-47"
faker.Number().Positive(100)      // => "3"
faker.Number().Negative(-100)     // => "-16"
PhoneNumber

faker.PhoneNumber().PhoneNumber()       // => "1-599-267-6597 x537"
faker.PhoneNumber().CellPhone()         // => "+49-131-0003060"
faker.PhoneNumber().AreaCode()          // => "903"
faker.PhoneNumber().ExchangeCode()      // => "574"
faker.PhoneNumber().SubscriberNumber(4) // => "1512"
faker.PhoneNumber().String()            // String is an alias for PhoneNumber.
Team

faker.Team().Name()     // => "Colorado cats"
faker.Team().Creature() // => "cats"
faker.Team().State()    // => "Oregon"
faker.Team().String()   // String is an alias for Name.
Time

// Between returns random time in [from, to] interval, with second resolution.
faker.Time().Between(from, to time.Time) time.Time

// Forward returns random time in [time.Now(), time.Now() + duration] interval, with second resolution.
faker.Time().Forward(duration time.Duration) time.Time

// Backward returns random time in [time.Now() - duration, time.Now()] interval, with second resolution.
faker.Time().Backward(duration time.Duration) time.Time

// Birthday returns random time so that age of the person born at that moment would be between minAge and maxAge years.
faker.Time().Birthday(minAge, maxAge int) time.Time

Documentation

Overview

Package faker is a library for generating fake data such as names, addresses, and phone numbers.

It is a (mostly) API-compatible port of Ruby Faker gem (https://github.com/stympy/faker) to Go.

Index

Constants

View Source
const (
	CC_VISA               = "visa"
	CC_MASTERCARD         = "mastercard"
	CC_AMERICAN_EXPRESS   = "american_express"
	CC_DINERS_CLUB        = "diners_club"
	CC_DISCOVER           = "discover"
	CC_MAESTRO            = "maestro"
	CC_SWITCH             = "switch"
	CC_SOLO               = "solo"
	CC_FORBRUGSFORENINGEN = "forbrugsforeningen"
	CC_DANKORT            = "dankort"
	CC_LASER              = "laser"
)

Known credit card types.

Variables

CC_TYPES holds a list of known credit card types.

View Source
var Locale = locales.En

Locale holds the default locale.

Functions

func Fetch

func Fetch(path string) string

Fetch returns a value at given key path in default locale. If key path holds an array, it returns random array element. If value looks like a regex, it attempts to regexify it.

func Letterify

func Letterify(s string) string

Letterify replaces pattern like '??? ??' with randomly generated uppercase letters

func Numerify

func Numerify(s string) string

Numerify replaces pattern like '##-###' with randomly generated digits.

func NumerifyAndLetterify

func NumerifyAndLetterify(s string) string

NumerifyAndLetterify both numerifies and letterifies s.

func RandomChoice

func RandomChoice(ss []string) string

RandomChoice returns random string from slice of strings.

func RandomInt

func RandomInt(min, max int) int

RandomInt returns random int in [min, max] range.

func RandomInt64

func RandomInt64(min, max int64) int64

RandomInt64 returns random int64 in [min, max] range.

func RandomRepeat

func RandomRepeat(s string, min, max int) string

RandomRepeat returns a new string consisting of random number of copies of the string s.

func RandomString

func RandomString(n int) string

RandomString returns a random alphanumeric string with length n.

func Regexify

func Regexify(s string) (string, error)

Regexify attempts to generate a string that would match given regular expression. It does not handle ., *, unbounded ranges such as {1,}, extensions such as (?=), character classes, some abbreviations for character classes, and nested parentheses.

func Seed added in v1.1.0

func Seed(seed int64)

Seed uses the provided seed value to initialize the random source to a deterministic state.

Types

type FakeAddress

type FakeAddress interface {
	City() string                        // => "North Dessie"
	StreetName() string                  // => "Buckridge Lakes"
	StreetAddress() string               // => "586 Sylvester Turnpike"
	SecondaryAddress() string            // => "Apt. 411"
	BuildingNumber() string              // => "754"
	Postcode() string                    // => "31340"
	PostcodeByState(state string) string // => "46511"
	ZipCode() string                     // ZipCode is an alias for Postcode.
	ZipCodeByState(state string) string  // ZipCodeByState is an alias for PostcodeByState.
	TimeZone() string                    // => "Asia/Taipei"
	CityPrefix() string                  // => "East"
	CitySuffix() string                  // => "town"
	StreetSuffix() string                // => "Square"
	State() string                       // => "Maryland"
	StateAbbr() string                   // => "IL"
	Country() string                     // => "Uruguay"
	CountryCode() string                 // => "JP"
	Latitude() float32                   // => -38.811367
	Longitude() float32                  // => 89.2171
	String() string                      // => "6071 Heaney Island Suite 553, Ebbaville Texas 37307"
}

func Address

func Address() FakeAddress

type FakeApp

type FakeApp interface {
	Name() string    // => "Alphazap"
	Version() string // => "2.6.0"
	Author() string  // => "Dorian Shields"
	String() string  // => "Tempsoft 4.51"
}

func App

func App() FakeApp

type FakeAvatar

type FakeAvatar interface {
	Url(format string, width, height int) string // => "http://robohash.org/NX34rZw7s0VFzgWY.jpg?size=100x200"
	String() string                              // => "http://robohash.org/XRWjFigoImqdeDuA.png?size=300x300"
}

func Avatar

func Avatar() FakeAvatar

type FakeBitcoin

type FakeBitcoin interface {
	Address() string // => "1GpEKM5UvD4XDLMirpNLoDnRVrGutogMj2"
	String() string  // String is an alias for Address.
}

func Bitcoin

func Bitcoin() FakeBitcoin

type FakeBusiness

type FakeBusiness interface {
	CreditCardNumber() string     // => "1234-2121-1221-1211"
	CreditCardExpiryDate() string // => "2015-11-11"
	CreditCardType() string       // => "mastercard"
}

func Business

func Business() FakeBusiness

type FakeCode

type FakeCode interface {
	Isbn10() string // => "048931033-8"
	Isbn13() string // => "391668236072-1"
	Ean13() string  // => "7742864258656"
	Ean8() string   // => "03079010"
	Rut() string    // => "14371602-3"
	Abn() string    // => "57914951376"
}

func Code

func Code() FakeCode

type FakeCommerce

type FakeCommerce interface {
	Color() string       // => "lime"
	Department() string  // => "Electronics, Health & Baby"
	ProductName() string // => "Ergonomic Granite Shoes"
	Price() float32      // => 97.79
}

func Commerce

func Commerce() FakeCommerce

type FakeCompany

type FakeCompany interface {
	Name() string        // => "Aufderhar LLC"
	Suffix() string      // => "Inc"
	CatchPhrase() string // => "Universal logistical artificial intelligence"
	Bs() string          // => "engage distributed applications"
	Ein() string         // => "58-6520513"
	DunsNumber() string  // => "16-708-2968"
	String() string      // String is an alias for Name.
}

func Company

func Company() FakeCompany

type FakeDate

type FakeDate interface {
	// Between returns random time in [from, to] interval, with second resolution.
	Between(from, to time.Time) time.Time

	// Forward returns random time in [time.Now(), time.Now() + duration] interval, with second resolution.
	Forward(duration time.Duration) time.Time

	// Backward returns random time in [time.Now() - duration, time.Now()] interval, with second resolution.
	Backward(duration time.Duration) time.Time

	// Birthday returns random time so that age of the person born at that moment would be between minAge and maxAge years.
	Birthday(minAge, maxAge int) time.Time
}

func Date

func Date() FakeDate

type FakeFinance

type FakeFinance interface {
	// CreditCard returns a valid (with valid check digit) card number of one of the given types.
	// If no types are passed, all types in CC_TYPES are used.
	CreditCard(types ...string) string // => "5019-8413-2066-5594"
}

func Finance

func Finance() FakeFinance

type FakeHacker

type FakeHacker interface {
	SaySomethingSmart() string // => "If we connect the bus, we can get to the XML microchip through the digital TCP sensor!"
	Abbreviation() string      // => "HTTP"
	Adjective() string         // => "cross-platform"
	Noun() string              // => "interface"
	Verb() string              // => "bypass"
	IngVerb() string           // => "parsing"
	Phrases() []string         /* =>
	"If we bypass the program, we can get to the AGP protocol through the optical SDD alarm!",
	"We need to calculate the back-end XML microchip!",
	"Try to generate the GB bus, maybe it will hack the neural panel!",
	"You can't navigate the transmitter without synthesizing the optical SMS bus!",
	"Use the optical THX application, then you can override the mobile port!",
	"The CSS monitor is down, quantify the multi-byte bus so we can calculate the XSS bandwidth!",
	"Connecting the card won't do anything, we need to back up the multi-byte RSS card!",
	"I'll reboot the primary SMTP feed, that should monitor the XML protocol!`"
	*/
}

func Hacker

func Hacker() FakeHacker

type FakeInternet

type FakeInternet interface {
	Email() string                // => "maritza@farrell.org"
	FreeEmail() string            // => "sven_rice@hotmail.com"
	SafeEmail() string            // => "theron.nikolaus@example.net"
	UserName() string             // => "micah_pfeffer"
	Password(min, max int) string // => "s5CzvVp6Ye"
	DomainName() string           // => "rolfson.info"
	DomainWord() string           // => "heller"
	DomainSuffix() string         // => "net"
	MacAddress() string           // => "15:a9:83:29:76:26"
	IpV4Address() string          // => "121.204.82.227"
	IpV6Address() string          // => "c697:392f:6a0e:bf6d:77e1:714a:10ab:0dbc"
	Url() string                  // => "http://sporerhamill.net/kyla.schmitt"
	Slug() string                 // => "officiis-commodi"
}

func Internet

func Internet() FakeInternet

type FakeLorem

type FakeLorem interface {
	Character() string         // => "c"
	Characters(num int) string // => "wqFyJIrXYfVP7cL9M"
	Word() string              // => "veritatis"
	Words(num int) []string    // => "omnis libero neque"
	Sentence(words int) string // => "Necessitatibus cum autem."

	// Sentences returns a slice of "num" sentences, 3 to 11 words each.
	Sentences(num int) []string

	// Paragraph returns a random text of "sentences" sentences length.
	Paragraph(sentences int) string

	// Paragraphs returns a slice of "num" paragraphs, 3 to 11 sentences each.
	Paragraphs(num int) []string

	// String returns a random sentence 3 to 11 words in length.
	String() string
}

func Lorem

func Lorem() FakeLorem

type FakeName

type FakeName interface {
	Name() string      // => "Natasha Hartmann"
	FirstName() string // => "Carolina"
	LastName() string  // => "Kohler"
	Prefix() string    // => "Dr."
	Suffix() string    // => "Jr."
	Title() string     // => "Chief Functionality Orchestrator"
	String() string    // String is an alias for Name.
}

func Name

func Name() FakeName

type FakeNumber

type FakeNumber interface {
	Number(digits int) string            // => "43202"
	NumberInt(digits int) int            // => 213
	NumberInt32(digits int) int32        // => 92938
	NumberInt64(digits int) int64        // => 1689541633257139096
	Decimal(precision, scale int) string // => "879420.60"
	Digit() string                       // => "7"
	Hexadecimal(digits int) string       // => "e7f3"
	Between(min, max int) string         // => "-47"
	Positive(max int) string             // => "3"
	Negative(min int) string             // => "-16"
}

func Number

func Number() FakeNumber

type FakePhoneNumber

type FakePhoneNumber interface {
	PhoneNumber() string                // => "1-599-267-6597 x537"
	CellPhone() string                  // => "+49-131-0003060"
	AreaCode() string                   // => "903"
	ExchangeCode() string               // => "574"
	SubscriberNumber(digits int) string // => "1512"
	String() string                     // String is an alias for PhoneNumber.
}

func PhoneNumber

func PhoneNumber() FakePhoneNumber

type FakeTeam

type FakeTeam interface {
	Name() string     // => "Colorado cats"
	Creature() string // => "cats"
	State() string    // => "Oregon"
	String() string   // String is an alias for Name.
}

func Team

func Team() FakeTeam

type FakeTime

type FakeTime interface {
	FakeDate
}

func Time

func Time() FakeTime

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL