Fork me on GitHub

Charlatan

Build Status

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

See API Documentation for details.

Installation

Install Charlatan from npm registry:

$ 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

Released under the MIT license. See LICENSE for details.

class

Charlatan

class

Charlatan.Address

class method

Charlatan.Address.city

    • Charlatan.Address.city()
      • String

Generate city name. For example 'Port Marianashire'

class method

Charlatan.Address.country

    • Charlatan.Address.country()
      • String

Return random country

class method

Charlatan.Address.county

    • Charlatan.Address.county()
      • String

Return random county. Note: if county dosen't set in current locale, then return empy string

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(abbr = false)
      • String
    • abbr
      • boolean
    • flag abbr or full name

Return random state(or state abbr).

class method

Charlatan.Address.stateAbbr

    • Charlatan.Address.stateAbbr()
      • String

Return abbr of random state.

class method

Charlatan.Address.streetAddress

    • Charlatan.Address.streetAddress(include_secondary = false)
      • String
    • include_secondary
      • boolean
    • is need 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.zip

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

Charlatan.Address.zipCode

    • Charlatan.Address.zipCode(format = null)
      • String
    • format
      • string
    • input format for example '#####-####'

Generate zip code by from format. Each sharp symbol will be replaced by number. If format is null, then random choise "#####" or '#####-####'

class

Charlatan.Company

class method

Charlatan.Company.bs

    • Charlatan.Company.bs()
      • String

Generate bullshet

class method

Charlatan.Company.catchPhrase

    • Charlatan.Company.catchPhrase()
      • String

Generate catch phrase

class method

Charlatan.Company.name

    • Charlatan.Company.name()
      • String

Genreate company name

class method

Charlatan.Company.suffix

    • Charlatan.Company.suffix()
      • String

Return random suffix, for example "Inc"

class

Charlatan.Helpers

class method

Charlatan.Helpers.capitalize

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

Capitalize first later

class method

Charlatan.Helpers.rand

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

    • min
      • number
    • min value in range

Returns a single random number based on a range

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

Charlatan.Internet

class method

Charlatan.Internet.domainName

    • Charlatan.Internet.domainName()
      • String

Generate domain.

class method

Charlatan.Internet.domainSuffix

    • Charlatan.Internet.domainSuffix()
      • String

Fetch first level domain souch as com

class method

Charlatan.Internet.domainWord

    • Charlatan.Internet.domainWord()
      • String

Generate domain without dot suffix

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 souch as gmail and hotmail

class method

Charlatan.Internet.IPv4

    • Charlatan.Internet.IPv4()
      • String

Generate IP address

class method

Charlatan.Internet.IPv6

    • Charlatan.Internet.IPv6()
      • String

Generate IPv6 address

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.paragraph

    • Charlatan.Lorem.paragraph(sentenceCount)
      • String
    • sentenceCount
      • integer
    • number of sentencies in paragph

    • supplemental
      • boolean
    • use additional words

Generate lorem paragraph

class method

Charlatan.Lorem.paragraphs

    • Charlatan.Lorem.paragraphs(paragraphCount = 3, sentenceCount = null)
      • Array
    • paragraphCount
      • integer
    • number of paragraphs in output

    • supplemental
      • boolean
    • use additional words

Generate array of lorem paragraphs

class method

Charlatan.Lorem.sentence

    • Charlatan.Lorem.sentence(wordCount = null, supplemental = false, capitalize = true)
      • String
    • wordCount
      • integer
    • number of words in sentence. If null, then randomly greater then 3

    • supplemental
      • boolean
    • use additional words

    • capitalize
      • boolean
    • need capitalize first word

Generate lorem sentence

class method

Charlatan.Lorem.sentences

    • Charlatan.Lorem.sentences(sentenceCount, supplemental = false)
      • Array
    • sentenceCount
      • integer
    • number of sentencies 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 output

    • supplemental
      • boolean
    • use additional words

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

Generate text

class method

Charlatan.Lorem.words

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

    • supplemental
      • boolean
    • use additional words

Generate 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.PhoneNumber

class method

Charlatan.PhoneNumber.cellPhone

    • Charlatan.PhoneNumber.cellPhone()
      • String

Generate cell phone number. If locale hasn't cell_phone section, then use phone.

class method

Charlatan.PhoneNumber.phoneNumber

    • Charlatan.PhoneNumber.phoneNumber()
      • String

Generate phone number.

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.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.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.setLocale

    • Charlatan.setLocale(name)
      • void
    • name
      • string
    • locale name, for example en-us

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