Fork me on GitHub

Charlatan

Build Status NPM version

Fake identities generator for node.js (names, addresses, phones, IPs and others).

This is node.js port of ruby's Faker library (v1.4.3 now), that generates fake identities for names, addresses, phone numbers, emails and others.

API Documentation.

Installation

$ npm install charlatan

Usage

var Charlatan = require('charlatan');

var name    = Charlatan.Name.name();       // Joshua Lemke MD
var email   = Charlatan.Internet.email();  // glover_ii@voluptas.name
var company = Charlatan.Company.name();    // Wilkinson LLC

Locales

Different countries have different data formats. Charlatan support locales as solution of this problem.

Currently available locales are here, en is default.

var Charlatan = require('charlatan');
Charlatan.setLocale('en-US');
Charlatan.Name.name();

Also you can use your own locale in yaml, json or plain hash.

var Charlatan = require('charlatan');
Charlatan.addLocale(myLocaleName, myLocaleFile);
Charlatan.setLocale(myLocaleName);
Charlatan.Name.name();

Note: If phrase not found in current locale, charlatan tries to then fallback into to base language, and then to en. For example ru-RU -> ru -> en.

Credits

Author Eugene Shkuropat

MIT license.

class

Charlatan

class

Charlatan.Address

class method

Charlatan.Address.buildingNumber

    • Charlatan.Address.buildingNumber()
      • String

Generate building number.

class method

Charlatan.Address.city

    • Charlatan.Address.city()
      • String

Generate city name. For example 'Port Marianashire'

class method

Charlatan.Address.cityPrefix

    • Charlatan.Address.cityPrefix()
      • String

Return random city prefix.

class method

Charlatan.Address.citySuffix

    • Charlatan.Address.citySuffix()
      • String

Return random city suffix.

class method

Charlatan.Address.country

    • Charlatan.Address.country()
      • String

Return random country.

class method

Charlatan.Address.countryCode

    • Charlatan.Address.countryCode()
      • String

Return random country code.

class method

Charlatan.Address.latitude

    • Charlatan.Address.latitude()
      • string

Generate latitude

class method

Charlatan.Address.longitude

    • Charlatan.Address.longitude()
      • string

Generate longitude

class method

Charlatan.Address.postcode

    • Charlatan.Address.postcode()
      • String
class method

Charlatan.Address.secondaryAddress

    • Charlatan.Address.secondaryAddress()
      • String

Generate secodary address part Apt/Suite.

class method

Charlatan.Address.state

    • Charlatan.Address.state()
      • String

Return random state name.

class method

Charlatan.Address.stateAbbr

    • Charlatan.Address.stateAbbr()
      • String

Return random state abbreviation.

class method

Charlatan.Address.streetAddress

    • Charlatan.Address.streetAddress(include_secondary = false)
      • String
    • include_secondary
      • Boolean
    • add apartment/suite part

Generate street address. For example 'Schuster borough'

class method

Charlatan.Address.streetName

    • Charlatan.Address.streetName()
      • String

Generate street name. For example 'Schuster borough'

class method

Charlatan.Address.streetSuffix

    • Charlatan.Address.streetSuffix()
      • String

Return random street suffix.

class method

Charlatan.Address.timeZone

    • Charlatan.Address.timeZone()
      • String

Return random timeZone.

class method

Charlatan.Address.zip

    • Charlatan.Address.zip()
      • String
class method

Charlatan.Address.zipCode

    • Charlatan.Address.zipCode([stateAbbr])
      • String
    • state_abbr
      • String
    • use postcode ranges only for specified US state

Generate zip code.

class

Charlatan.App

Class methods

class method

Charlatan.App.author

    • Charlatan.App.author()
      • String

Generate an application author

class method

Charlatan.App.name

    • Charlatan.App.name()
      • String

Generate an application name

class method

Charlatan.App.version

    • Charlatan.App.version()
      • String

Generate an application version

class

Charlatan.Avatar

Class methods

class method

Charlatan.Avatar.image

    • Charlatan.Avatar.image(slug = null, size = "300x300", format = "png")
      • String
    • slug
      • String
    • slug:)

    • size
      • String
    • avatar size

    • format
      • String
    • image format ('png', 'jpg' or 'bmp')

Generate link to robohash avatar

class

Charlatan.Bitcoin

class method

Charlatan.Bitcoin.address

    • Charlatan.Bitcoin.address()
      • String

Generate a valid bitcoin address

class method

Charlatan.Bitcoin.testnetAddress

    • Charlatan.Bitcoin.testnetAddress()
      • String

Generate a valid bitcoin address for testnet block chain

class

Charlatan.Business

class method

Charlatan.Business.creditCardExpiryDate

    • Charlatan.Business.creditCardExpiryDate()
      • Date

Generate credit card expire date

class method

Charlatan.Business.creditCardNumber

    • Charlatan.Business.creditCardNumber()
      • String

Generate placeholder credit card number (out of range of the real credit card numbers).

If you want to generate real-looking credit card numbers, use Charlatan.Finance.creditCard method.

class method

Charlatan.Business.creditCardType

    • Charlatan.Business.creditCardType()
      • Date

Generate credit card type (visa, mastercard, etc.)

class

Charlatan.Code

Class methods

class method

Charlatan.Code.ean

    • Charlatan.Code.ean(base = 13)
      • String
    • base
      • Number
    • ean code type

Generate EAN.

By default generates 13 sign ean code in format 1234567890123 You can pass 8 to generate ean8 code

class method

Charlatan.Code.isbn

    • Charlatan.Code.isbn(base = 10)
      • String
    • base
      • Number
    • isbn code type

Generate ISBN.

By default generates 10 sign isbn code in format 123456789-X You can pass 13 to generate new 13 sign code.

class method

Charlatan.Code.rut

    • Charlatan.Code.rut()
      • String

Generate RUT.

class

Charlatan.Commerce

class method

Charlatan.Commerce.color

    • Charlatan.Commerce.color()
      • String

Generate color name

class method

Charlatan.Commerce.department

    • Charlatan.Commerce.department(max = 3, fixed_amount = false)
      • String
    • max
      • Number
    • number of categories

    • fixed_amount
      • Boolean
    • always return max amount of them

Generate department name

class method

Charlatan.Commerce.price

    • Charlatan.Commerce.price()
      • Float

Generate price

class method

Charlatan.Commerce.productName

    • Charlatan.Commerce.productName()
      • String

Generate product name

class

Charlatan.Company

class method

Charlatan.Company.bs

    • Charlatan.Company.bs()
      • String

When a straight answer won't do, BS to the rescue!

class method

Charlatan.Company.catchPhrase

    • Charlatan.Company.catchPhrase()
      • String

Generate a buzzword-laden catch phrase.

class method

Charlatan.Company.dunsNumber

    • Charlatan.Company.dunsNumber()
      • String

Generate duns

class method

Charlatan.Company.ein

    • Charlatan.Company.ein()
      • String

Generate ein

class method

Charlatan.Company.name

    • Charlatan.Company.name()
      • String

Generate company name

class method

Charlatan.Company.suffix

    • Charlatan.Company.suffix()
      • String

Return random suffix, for example "Inc"

class

Charlatan.Date

class method

Charlatan.Date.backward

    • Charlatan.Date.backward(days = 365)
      • Date
    • days
      • Number
    • maximum amount of days before this one

Generate a random date before current one.

class method

Charlatan.Date.between

    • Charlatan.Date.between(from, to)
      • Date
    • from
      • Number
      • String
      • Date
    • start of the interval

    • to
      • Number
      • String
      • Date
    • end of the interval

Generate a random date in the given interval.

class method

Charlatan.Date.birthday

    • Charlatan.Date.birthday(min_age = 18, max_age = 65)
      • Date
    • min_age
      • Number
    • min age

    • max_age
      • Number
    • max age

Generate a random birthday for people of given age.

class method

Charlatan.Date.forward

    • Charlatan.Date.forward(days = 365)
      • Date
    • days
      • Number
    • maximum amount of days after this one

Generate a random date after current one.

class

Charlatan.Finance

Class methods

class method

Charlatan.Finance.creditCard

    • Charlatan.Finance.creditCard([types])
      • String
    • types
      • Array
    • generate card for one of these vendors ('visa', 'mastercard', etc.)

Generate a card number with prefix belonging to one of the existing payment processors.

class

Charlatan.Hacker

class method

Charlatan.Hacker.abbreviation

    • Charlatan.Hacker.abbreviation()
      • String

Generate an abbreviation

class method

Charlatan.Hacker.adjective

    • Charlatan.Hacker.adjective()
      • String

Generate "hacker" adjective

class method

Charlatan.Hacker.ingverb

    • Charlatan.Hacker.ingverb()
      • String

Generate "hacker" ingverb

class method

Charlatan.Hacker.noun

    • Charlatan.Hacker.noun()
      • String

Generate "hacker" noun

class method

Charlatan.Hacker.saySomethingSmart

    • Charlatan.Hacker.saySomethingSmart()
      • String

Generate a smart looking phrase

class method

Charlatan.Hacker.verb

    • Charlatan.Hacker.verb()
      • String

Generate "hacker" verb

class

Charlatan.Helpers

class method

Charlatan.Helpers.capitalize

    • Charlatan.Helpers.capitalize(str)
      • String
    • str
      • string
    • source string

Capitalize first letter

class method

Charlatan.Helpers.rand

    • Charlatan.Helpers.rand(max, min = 0)
      • Integer
    • max
      • number
    • max value in range (exclusive)

    • min
      • number
    • min value in range (inclusive)

Returns a single random number in range [min, max), including min but excluding max.

class method

Charlatan.Helpers.range

    • Charlatan.Helpers.range(from, to)
      • String
      • Number
    • from
      • String
      • Number
    • starting character

    • to
      • String
      • Number
    • ending character

Return all numbers or characters from from to to.

If input values are strings, this method returns strings, if they are numbers, it will return a number array.

For example, range("A", "D") will return ["A", "B", "C", "D"].

class method

Charlatan.Helpers.sample

    • Charlatan.Helpers.sample(source)
      • Mixin
    • source
      • array
    • source array

Returns random element from source array

class method

Charlatan.Helpers.shuffle

    • Charlatan.Helpers.shuffle(source)
      • Array
    • source
      • array
    • source array

Takes an array and returns it randomized

class method

Charlatan.Helpers.titleize

    • Charlatan.Helpers.titleize()
      • String
    • title
      • string
    • source string

Capitalizes most words to create a nicer looking title string. The list of "small words" which are not capped comes from the New York Times Manual of Style, plus 'vs' and 'v'.

class

Charlatan.Internet

class method

Charlatan.Internet.deviceToken

    • Charlatan.Internet.deviceToken()
      • String

Generate an APN token

class method

Charlatan.Internet.domainName

    • Charlatan.Internet.domainName()
      • String

Generate domain name.

class method

Charlatan.Internet.domainSuffix

    • Charlatan.Internet.domainSuffix()
      • String

Return TLD, e.g. "com"

class method

Charlatan.Internet.domainWord

    • Charlatan.Internet.domainWord()
      • String

Generate domain component

class method

Charlatan.Internet.email

    • Charlatan.Internet.email([name])
      • String
    • name
      • string
    • user name, optional

Generate email :-)

class method

Charlatan.Internet.freeEmail

    • Charlatan.Internet.freeEmail([name])
      • String
    • name
      • string
    • user name, optional

Generate email in public domain such as gmail and hotmail

class method

Charlatan.Internet.IPv4

    • Charlatan.Internet.IPv4()
      • String

Generate an IPv4 address

class method

Charlatan.Internet.IPv6

    • Charlatan.Internet.IPv6([words][, glue])
      • String
    • words
      • String
    • words array (by default it fetches lorem.words)

    • glue
      • String
    • character that separates words

Build slug out of a words array

class method

Charlatan.Internet.macAddress

    • Charlatan.Internet.macAddress(prefix = "")
      • String
    • prefix
      • String
    • prefix

Generate a mac address

class method

Charlatan.Internet.password

    • Charlatan.Internet.password(minLength = 8, maxLength = 16)
      • String
    • minLength
      • integer
    • min number of characters in generated password

    • maxLength
      • integer
    • max number of characters in generated password

Generate an alphanumeric password

class method

Charlatan.Internet.safeEmail

    • Charlatan.Internet.safeEmail([name])
      • String
    • name
      • string
    • user name, optional

Generate email in example.[org|com|net]

class method

Charlatan.Internet.userName

    • Charlatan.Internet.userName([name])
      • String
    • name
      • string
    • user name, optional

Generate nickname.

class

Charlatan.Lorem

class method

Charlatan.Lorem.character

    • Charlatan.Lorem.character()
      • String

Generate a character

class method

Charlatan.Lorem.characters

    • Charlatan.Lorem.characters(charCount = 255)
      • String
    • charCount
      • Integer
    • number of characters in result

Generate lorem characters

class method

Charlatan.Lorem.paragraph

    • Charlatan.Lorem.paragraph(sentenceCount = 3, supplemental = false, randomWordsToAdd = 3)
      • String
    • sentenceCount
      • Number
    • number of sentences in a paragraph

    • supplemental
      • Boolean
    • use additional words

    • randomWordsToAdd
      • Integer
    • additional count of random words

Generate lorem paragraph

class method

Charlatan.Lorem.paragraphs

    • Charlatan.Lorem.paragraphs(paragraphCount = 3, sentenceCount = false)
      • Array
    • paragraphCount
      • Integer
    • number of paragraphs in the output

    • supplemental
      • Boolean
    • use additional words

Generate an array of lorem paragraphs

class method

Charlatan.Lorem.sentence

    • Charlatan.Lorem.sentence(wordCount = 4, supplemental = false, randomWordsToAdd = 6)
      • String
    • wordCount
      • Integer
    • number of words in sentence. If null, then it's random greater than 3

    • supplemental
      • Boolean
    • use additional words

    • randomWordsToAdd
      • Integer
    • additional count of random words

Generate lorem sentence

class method

Charlatan.Lorem.sentences

    • Charlatan.Lorem.sentences(sentenceCount = 3, supplemental = false)
      • Array
    • sentenceCount
      • Number
    • number of sentences in output

    • supplemental
      • Boolean
    • use additional words

Generate array of lorem sentences

class method

Charlatan.Lorem.text

    • Charlatan.Lorem.text(paragraphCount, sentenceCount, glue)
      • String
    • paragraphCount
      • integer
    • number of paragraphs in the output

    • supplemental
      • boolean
    • use additional words

    • glue
      • string
    • glue between paragraphs, \n \r\t by default

Generate text

class method

Charlatan.Lorem.word

    • Charlatan.Lorem.word()
      • String

Generate random word

class method

Charlatan.Lorem.words

    • Charlatan.Lorem.words(wordCount = 3, supplemental = false)
      • Array
    • wordCount
      • Number
    • number of words in output

    • supplemental
      • Boolean
    • use additional words

Generate an array of random words

class

Charlatan.Name

class method

Charlatan.Name.firstName

    • Charlatan.Name.firstName()
      • String

Generate first name. Example: 'Marjorie'

class method

Charlatan.Name.lastName

    • Charlatan.Name.lastName()
      • String

Generate last name. Example: 'Lemke'

class method

Charlatan.Name.name

    • Charlatan.Name.name()
      • String

Generate full name.

class method

Charlatan.Name.prefix

    • Charlatan.Name.prefix()
      • String

Generate name prefix. Example: 'Dr.'

class method

Charlatan.Name.suffix

    • Charlatan.Name.suffix()
      • String

Generate name suffix. Example: 'PhD'

class method

Charlatan.Name.title

    • Charlatan.Name.title()
      • String

Generate a buzzword-laden job title Wordlist from http://www.bullshitjob.com/title/

class

Charlatan.Number

class method

Charlatan.Number.between

    • Charlatan.Number.between(from = 1, to = 5000)
      • Number
    • from
      • Number
    • range start

    • to
      • Number
    • range end

Generate a number between from and to

class method

Charlatan.Number.decimal

    • Charlatan.Number.decimal(l_digits, r_digits = 2)
      • String
    • l_digits
      • Number
    • an amount of digits in the integer part

    • r_digits
      • Number
    • an amount of digits in the fractional part

Generate a decimal number

class method

Charlatan.Number.digit

    • Charlatan.Number.digit()
      • String

Generate a base 10 digit

class method

Charlatan.Number.hexadecimal

    • Charlatan.Number.hexadecimal(digits)
      • String
    • digits
      • Number
    • an amount of digits in there

Generate a base 16 number

class method

Charlatan.Number.negative

    • Charlatan.Number.negative(from = -5000, to = -1)
      • Number
    • from
      • Number
    • range start

    • to
      • Number
    • range end

Generate a negative number between from and to

class method

Charlatan.Number.number

    • Charlatan.Number.number(digits)
      • String
    • digits
      • Number
    • an amount of digits in there

Generate a base 10 number

class method

Charlatan.Number.positive

    • Charlatan.Number.positive(from = 1, to = 5000)
      • Number
    • from
      • Number
    • range start

    • to
      • Number
    • range end

Generate a positive number between from and to

class

Charlatan.PhoneNumber

class method

Charlatan.PhoneNumber.areaCode

    • Charlatan.PhoneNumber.areaCode()
      • String

Generate an area code (US only).

class method

Charlatan.PhoneNumber.cellPhone

    • Charlatan.PhoneNumber.cellPhone()
      • String

Generate cell phone number.

class method

Charlatan.PhoneNumber.exchangeCode

    • Charlatan.PhoneNumber.exchangeCode()
      • String

Return an exchange code (US only).

class method

Charlatan.PhoneNumber.extension

    • Charlatan.PhoneNumber.extension()
      • String
class method

Charlatan.PhoneNumber.phoneNumber

    • Charlatan.PhoneNumber.phoneNumber()
      • String

Generate phone number.

class method

Charlatan.PhoneNumber.subscriberNumber

    • Charlatan.PhoneNumber.subscriberNumber(length = 4)
      • String
    • length
      • Integer
    • extension length

Return a number extension (US only).

Can be used for both extensions and last four digits of phone number. Since extensions can be of variable length, this method takes a length parameter

class

Charlatan.Team

Class methods

class method

Charlatan.Team.creature

    • Charlatan.Team.creature()
      • String

Generate team mascot.

class method

Charlatan.Team.name

    • Charlatan.Team.name()
      • String

Generate team name.

class method

Charlatan.Team.state

    • Charlatan.Team.state()
      • String

Generate team state.

class method

Charlatan.addLocale

    • Charlatan.addLocale(name, data)
      • void
    • name
      • string
    • locale name, for example en-US

    • data
      • object
      • string
    • locale hash or yaml file

Load locale to Charlatan. Charlatan preload some locales

class method

Charlatan.bothify

    • Charlatan.bothify(source)
      • string
    • source
      • string
    • source string

Perform both letterify and numerify operations.

class method

Charlatan.fetch

    • Charlatan.fetch(key)
      • mixed
    • key
      • string
    • key in locale, for example address.city_prefix

Helper for the common approach of grabbing a translation with an array of values and selecting one of them.

class method

Charlatan.getAllLocales

    • Charlatan.getAllLocales()
      • [ String ]

Get the list of all available locales

class method

Charlatan.getLocale

    • Charlatan.getLocale()
      • String

Get current locale

class method

Charlatan.letterify

    • Charlatan.letterify(source)
      • string
    • source
      • string
    • source string

Find ? symbol and replace it with random char from [A..Z]

class method

Charlatan.numerify

    • Charlatan.numerify(source)
      • string
    • source
      • string
    • source string

Find # symbol and replace it with random number

class method

Charlatan.parse

    • Charlatan.parse(key)
      • string
    • key
      • string
    • key in locale, for example address.city_prefix

Load formatted strings from the locale, "parsing" them into method calls that can be used to generate a formatted translation: e.g., "#{first_name} #{last_name}".

class method

Charlatan.regexify

    • Charlatan.regexify(re)
      • String
    • re
      • RegExp
      • String
    • regexp to sample from

Given a regular expression, attempt to generate a string that would match it. This is a rather simple implementation, so don't be shocked if it blows up on you in a spectacular fashion.

It does not handle ., *, unbounded ranges such as {1,}, extensions such as (?=), character classes, some abbreviations for character classes, and nested parentheses.

I told you it was simple. :) It's also probably dog-slow, so you shouldn't use it.

It will take a regex like this:

/^[A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}$/

and generate a string like this:

"U3V 3TP"

class method

Charlatan.setLocale

    • Charlatan.setLocale([name])
      • void
    • name
      • String
    • locale name, for example en-US

Set current locale. If name is not defined, revert back to default locale.

class method

Charlatan.translate

    • Charlatan.translate(key)
      • mixed
    • key
      • string
    • key in locale, for example address.city_prefix

Returns a phrase from the locale.

Fallbacks to base language (and then to en) if it was not found: ru-RU -> ru -> en