Fork me on GitHub

Fakesome

For all the fakesome people out there!

Fakesome lets you easily create massive amounts of fake data. Use it to populate databases, build API prototypes or for just any other job where you need random but structured data.

Getting Started

On the server you can install fakesome with npm:

$ npm install fakesome

Then require it in your scripts like this:

const fakesome = require('fakesome')

In the browser just load the bundled javascript file ( get it from GitHub ):

<script src=fakesome.js></script>

Now you can simply call the methods to generate data:

const randomInteger = fakesome.integer(0,9)

fakesome.boolean( chanceOfTrue )

Returns randomly true or false.

Parameters

chanceOfTrue
Number
0.5
Set the probability of getting returned true.

Returns

Boolean

true or false

Examples

CodeDescriptionExample Return
fakesome.boolean()
true or false with a 50:50 chancefalse
fakesome.boolean(0.8)
80% probability of truetrue

fakesome.integer( minValue, maxValue, filter )

Returns a random integer.For unlimited large integers (string of digits) usefakesome.string().

Parameters

minValue
Number
-(2^53/2)+1
Set the lower boundary of the range.
maxValue
Number
(2^53/2)-1
Set the upper boundary of the range.
filter
Function
Function to filter the possible numbers. Receives the number as a parameter and returns true or false. function(number).

Returns

Number

The randomly generated integer.

Examples

CodeDescriptionExample Return
fakesome.integer()
Integers between inclusive -4503599627370495 and 4503599627370495-2259435805076023
fakesome.integer(0, 1000)
Integers between 0 and 1000643
fakesome.integer(-1000, 0)
Integers between -1000 and 0-410
fakesome.integer(2, 1000, (n) => {
  if (isNaN(n) || !isFinite(n) || n % 1 || n < 2) {
    return false
  }

  if (!(n % 2)) return n === 2
  if (!(n % 3)) return n === 3

  for (let i = 5; i <= Math.sqrt(n); i += 6) {
    if (n % i === 0) return false
    if (n % (i + 2) === 0) return false
  }

  return true
})
Prime Numbers between inclusive 2 and inclusive 100019

fakesome.float( minValue, maxValue, filter )

Returns a random float.

Parameters

minValue
Number
-1e12
Set the lower boundary of the range.
maxValue
Number
1e12
Set the upper boundary of the range.
filter
Function
Function to filter the possible numbers. Receives the number as the first parameter and returns true or false.

Returns

Number

The randomly generated float.

Examples

CodeDescriptionExample Return
fakesome.float(0, 9)
Floats between inclusive 0 and 90.28070653428692993
fakesome.float(0, 1000)
Floats between 0 and 1000896.6523582744288
fakesome.float(-1000, 0)
Floats between -1000 and 0-705.424437925303

fakesome.date( min, max )

Returns a random Date.

Parameters

min
String
1970-01-01
Set the lower boundary of the date range.
max
String
today
Set the upper boundary of the date range.

Returns

Date

The randomly generated date.

Examples

CodeDescriptionExample Return
fakesome.date()
Random date between 1970-01-01 and today"1989-01-08T00:00:00.000Z"
fakesome.date("2000-06-01", "2001-01-01")
Random date between 2000-06-01 and 2001-01-01"2000-11-28T00:00:00.000Z"

fakesome.datetime( min, max )

Returns a random Datetime.

Parameters

min
String
1970-01-01
Set the lower boundary of the datetime range.
max
String
today
Set the upper boundary of the datetime range.

Returns

Date

The randomly generated datetime.

Examples

CodeDescriptionExample Return
fakesome.datetime()
Random datetime between 1970-01-01 and today"1974-12-17T22:00:50.739Z"
fakesome.datetime("2000-06-01", "2001-01-01")
Random datetime between 2000-06-01 and 2001-01-01"2000-07-21T13:11:21.060Z"

fakesome.character( min, max, filter )

Parameters

min
Number
32
The minimum unicode-value of the character.
max
Number
1114112
The maximum unicode-value of the character.
filter
Function
Filters the generated values before return. Receives the character as the first parameter and returns true or false.

Returns

String

The randomly generated character.

Examples

CodeDescriptionExample Return
fakesome.character()
Random Unicode character
fakesome.character(32, 126)
Random printable ASCII character5
fakesome.character(65, 90)
Random uppercase characterI

fakesome.string( alphabet, length )

Returns a string of characters from the specified alphabet.

Parameters

alphabet
Array
a - z
All the characters to choose from.
length
Number
10
Length of the string to be returned.

Returns

String

The string.

Examples

CodeDescriptionExample Return
fakesome.string()
String of 10 lower case ASCII characterszoyprjjsyf
fakesome.string(["●","☃","😀"], 15)
String of 15 weird characters●☃😀☃●●☃😀☃😀☃😀☃☃●

fakesome.element( array )

Returns a random element of an array.

Parameters

*array
Array
The array to choose the element from.

Returns

An element from the source array.

Examples

CodeDescriptionExample Return
fakesome.element(["apple","banana","pear"])
A random fruitapple

fakesome.word( minChars, maxChars )

Returns a random word with a minimum and maximum number of characters.

Parameters

minChars
Number
1
Minimum number of characters in the word.
maxChars
Number
20
Maximum number of characters in the word.

Returns

String

The word

Examples

CodeDescriptionExample Return
fakesome.word()
Random word with 1 to 20 charactersut
fakesome.word(2, 5)
Random word with 2 to 5 charactersipsum

fakesome.words( quantity, minChars, maxChars )

Get the specified number of words with a maximum and minimumnumber of characters.

Parameters

quantity
Number
10
Number of words.
minChars
Number
1
The minimum number of characters.
maxChars
Number
20
The maximum number of characters.

Returns

String

Space separated string of the words.

Examples

CodeDescriptionExample Return
fakesome.words()
String of 10 space separated words with between 1 and 20 characterstakimata sea consetetur et at accusam et amet clita dolores
fakesome.words(5, 2, 3)
String of 5 space separated words with between 2 and 3 charactersest ut ut ea et

fakesome.text( min, max )

Get a text section with a certain number of characters.

Parameters

min
Number
50
Minimum number of characters in the text section.
max
Number
100
Maximum number of characters in the text section.

Returns

String

The text.

Examples

CodeDescriptionExample Return
fakesome.text()
A text section consisting of 100 characterslorem ipsum dolor sit amet consetetur sadipscing elit
fakesome.text(10)
String of 10 characterslorem ipsum dolor sit amet consetetur sadipscing elitr s

fakesome.sentence( min, max )

Get a sentence with a minimum and maximum number of words.

Parameters

min
Number
5
Minimum number of words in the sentence.
max
Number
25
Maximum number of words in the sentence.

Returns

String

The sentence.

Examples

CodeDescriptionExample Return
fakesome.sentence()
Get a sentence with 5 to 25 wordsDiam accusam dolor amet tempor eos justo stet.
fakesome.sentence(40, 50)
Get a sentence with 40 to 50 wordsErat no nonumy dolore et diam sadipscing consetetur lorem et justo ipsum sit ipsum magna dolor rebum dolor ut diam ea aliquyam invidunt labore at et est diam lorem dolores erat clita et est et kasd et gubergren amet clita amet sit sea sanctus.
fakesome.sentence(4, 4)
Get a sentence with exactly 4 wordsDolor justo sit kasd.

fakesome.sentences( number, min, max )

Get the specified number of sentences with a maximum and minimum number of words.

Parameters

number
Number
1
The number of sentences.
min
Number
5
Minimum number of words per sentence.
max
Number
25
Maximum number of words per sentence.

Returns

String

The sentences.

Examples

CodeDescriptionExample Return
fakesome.sentences()
Get one sentenceElitr sit dolore ea et diam ipsum consetetur ipsum erat sed ut magna est.
fakesome.sentences(4)
Get 4 sentencesGubergren sed justo diam accusam dolor et lorem at rebum kasd labore lorem invidunt takimata ipsum diam dolore rebum elitr eirmod dolore clita sea. Kasd duo et amet dolore voluptua rebum sea ipsum sed diam ut. Clita sed ea dolore ut diam eos no dolores kasd aliquyam et erat consetetur ipsum. Sit lorem sed et ipsum est lorem gubergren magna voluptua clita at aliquyam magna dolore dolor.
fakesome.sentences(5, 1, 5)
Get 10 sentences with 1 to 5 words eachConsetetur aliquyam amet. Sed. Invidunt labore sed eos. Elitr. Nonumy accusam rebum.

fakesome.imgURL( configObject )

Parameters

configObject
Object
Configure different parameters to narrow down the set of possible images.
width
Number
100
height
Number
100
tag
String
text
String
bgColor
Color
textColor
Color
grayscale
Boolean
false
site
String
lorempixel.com
Select the site to be used for loading the images. You can choose between following sites: lorempixel.com, placehold.it, placekitten.com and flickholdr.com
number
Number
false
format
png | gif | jpg
png

Returns

String

The URL.

Examples

CodeDescriptionExample Return
fakesome.imgURL()
URL to a random image on lorempixel.comhttp://placeimg.com/100/100
fakesome.imgURL({
    "site": "placekitten.com",
    "width": 400,
    "height": 250,
    "grayscale": true
})
URL to a random image on placekitten.comhttp://placekitten.com/g/400/250

fakesome.color( min, max, type )

Returns a random color

Parameters

min
Number
rgb(0, 0, 0)
Set the darkest (and most transparent) possible color.
max
Number
rgb(255, 255, 255)
Set the brightest (and least transparent) possible color.
type
String
rgb
Notation type of the returned color.

Returns

String

The color.

Examples

CodeDescriptionExample Return
fakesome.color()
Random rgb colorrgb(0, 0, 0)
fakesome.color(null, null, "hsl")
Random hsl colorhsl(0, 0%, 0%)

fakesome.object( schema )

Create a javascript Object with custom key-value pairs. The values can either be primitives or be generated with other fakesome methods.

Parameters

*schema
Object
The schema of the object to be returned.

Returns

Object

Object with specified key-value pairs.

Examples

CodeDescriptionExample Return
fakesome.object({
    "name": "word()",
    "age": "integer(0,100)",
    "premium": "boolean()",
    "country": "de",
    "logins": 89
})
User entry{
    "name": "vero",
    "age": 88,
    "premium": true,
    "country": "de",
    "logins": 89
}

fakesome.array( number )

This method enables you to return arrays of faked data. Simply chain one of the other fakesome methods after the array method to get an array of the method's values. E.g. fakesome.array(5).boolean() will return an array of 5 random boolean values.

Parameters

number
Number
10
Number of elements in the array.

Returns

Object

Array of elements.

fakesome.maybe( chanceOfReturn )

Chain other faksome methods after maybe() to make the return of values optional. E.g. fakesome.maybe().integer(0,9) will return an integer or null with a 50:50 chance.

Parameters

chanceOfReturn
Number
0.5
Probability that the chained function returns a value. Otherwise it will return null.

Returns

Object

All registered methods.

fakesome.unique( reset )

Chain other faksome methods after unique() to prevent them from returning the same value twice. There is a scope of uniqueness for each method.

Parameters

reset
Boolean
false
Resets the unique values array.

Returns

Object

All registered methods.