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:
var 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:
var 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
Booleantrue or false
Examples
Code | Description | Example Return |
---|---|---|
| true or false with a 50:50 chance | true |
| 80% probability of true | true |
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
NumberThe randomly generated integer.
Examples
Code | Description | Example Return |
---|---|---|
| Integers between inclusive -4503599627370495 and 4503599627370495 | 1768482068758528 |
| Integers between 0 and 1000 | 216 |
| Integers between -1000 and 0 | -824 |
| Prime Numbers between inclusive 2 and inclusive 1000 | 599 |
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
NumberThe randomly generated float.
Examples
Code | Description | Example Return |
---|---|---|
| Floats between inclusive 0 and 9 | 2.0147602572105825 |
| Floats between 0 and 1000 | 791.5684513282031 |
| Floats between -1000 and 0 | -671.4041011873633 |
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
DateThe randomly generated date.
Examples
Code | Description | Example Return |
---|---|---|
| Random date between 1970-01-01 and today | "1988-10-21T00:00:00.000Z" |
| Random date between 2000-06-01 and 2001-01-01 | "2000-11-13T00: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
DateThe randomly generated datetime.
Examples
Code | Description | Example Return |
---|---|---|
| Random datetime between 1970-01-01 and today | "2008-07-08T03:45:08.833Z" |
| Random datetime between 2000-06-01 and 2001-01-01 | "2000-11-03T20:40:51.222Z" |
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
StringThe randomly generated character.
Examples
Code | Description | Example Return |
---|---|---|
| Random Unicode character | γ |
| Random printable ASCII character | o |
| Random uppercase character | K |
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
StringThe string.
Examples
Code | Description | Example Return |
---|---|---|
| String of 10 lower case ASCII characters | izdyuzwraz |
| 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
Code | Description | Example Return |
---|---|---|
| A random fruit | pear |
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
StringThe word
Examples
Code | Description | Example Return |
---|---|---|
| Random word with 1 to 20 characters | ipsumdolor |
| Random word with 2 to 5 characters | est |
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
StringSpace separated string of the words.
Examples
Code | Description | Example Return |
---|---|---|
| String of 10 space separated words with between 1 and 20 characters | dolores et takimata sed sed et no est etjusto consetetur |
| String of 5 space separated words with between 2 and 3 characters | ut no no et sit |
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
StringThe text.
Examples
Code | Description | Example Return |
---|---|---|
| A text section consisting of 100 characters | lorem ipsum dolor sit amet consetetur sadipscing elitr sed diam nonumy ei |
| String of 10 characters | lorem ipsum dolor sit amet consetetur sadipscing elitr sed diam nonumy eirmod temporinvidunt ut lab |
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
StringThe sentence.
Examples
Code | Description | Example Return |
---|---|---|
| Get a sentence with 5 to 25 words | At sea kasd dolor dolores amet diam sanctus stet consetetur magna takimata et invidunt sed clita. |
| Get a sentence with 40 to 50 words | Rebum temporinvidunt lorem at sea sit dolore sed diam nonumy gubergren kasd duo amet dolores est clita nonumy sanctus amet et et clita lorem vero takimata erat gubergren aliquyam etjusto sit sed ipsumdolor sanctus sit labore lorem accusamet magna consetetur dolor no duo ut consetetur voluptua labore. |
| Get a sentence with exactly 4 words | Et diam sed no. |
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
StringThe sentences.
Examples
Code | Description | Example Return |
---|---|---|
| Get one sentence | Rebum diam dolore magna etjusto elitr clita sit sed invidunt sit sed et et aliquyam eos et elitr ipsumdolor et consetetur lorem. |
| Get 4 sentences | Consetetur no rebum etjusto lorem ipsum sadipscing diam at sanctus amet et rebum lorem et duo erat clita gubergren labore sit. Aliquyam et amet invidunt accusamet sea amet dolor sit etjusto erat sed kasd lorem sit at sed erat et. Dolore et ut consetetur diam eirmodtempor lorem diam consetetur amet kasd gubergren amet nonumy diam rebum ipsum clita gubergren. Eirmod ipsum sadipscing sanctus vero sadipscing et diam et ipsumdolor et sed diam amet amet sit kasd sea sit. |
| Get 10 sentences with 1 to 5 words each | Amet aliquyam. Magna lorem erat et diam. Sadipscing no kasd. Dolores amet sanctus duo voluptua. Ea labore takimata lorem at. |
fakesome.img( configObject )
Generate a random placeholder image.
Parameters
- configObject
- Object
- Configure different parameters of the image.
- tag
- boolean
- false
true
: Returns an image tag containing a base64 coded image.false
: Returns just the base64 string.- width
- Number
- 100
- Sets the width of the image.
- height
- Number
- 100
- Sets the height of the image.
- elements
- Number
- 100
- Sets the number of elements in the image.
- bgColor
- Color
- white
- Sets the background color of the image.
- minColor
- Color
- rgba(0,0,0,0)
- Sets the minimum color of the elements in the image.
- maxColor
- Color
- rgba(255,255,255,1)
- Sets the maximum color of the elements in the image.
Returns
StringThe image as base64 data or as html-tag.
Examples
Code | Description | Example Return |
---|---|---|
| Base64 image data | data:image/png;base64,iVBORw0KGgoAAAANSU⦠|
| Base64 image tag | |
| Base64 image tag | |
| Base64 image tag | |
| Grayscale image | |
| Black & white image |
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
StringThe URL.
Examples
Code | Description | Example Return |
---|---|---|
| URL to a random image on lorempixel.com | http://lorempixel.com/100/100 |
| URL to a random image on placekitten.com | http://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
StringThe color.
Examples
Code | Description | Example Return |
---|---|---|
| Random rgb color | rgb(28, 7, 90) |
| Random hsl color | hsl(169, 42%, 45%) |
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
ObjectObject with specified key-value pairs.
Examples
Code | Description | Example Return |
---|---|---|
| User entry | { "name": "erat", "age": 6, "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
ObjectArray 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
ObjectAll 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
ObjectAll registered methods.
fakesome.fn
Extend fakesome with your own modules. E.g. To create the module fakesome.longWord()
simply extend fakesome.fn
with the corresponding function:
fakesome.fn.longWord = function(){
return "supercalifragilisticexpialidocious"
}