Generators in Fake Data
Introduction
Generators are core components of Fake Data's functionality. These are the functions that are used to generate the actual data that is being inserted in form inputs.
If you are going to customise the data that is generated by the extension, then this is where you would want to start.
Fake Data comes with a set of predefined generators, called Default Generators. These cannot be renamed or deleted but can have their code overwritten if you want to completely change the data that is generated by them. You can also create as many Custom Generators as you want using Javascript code.
Default Generators
When first installed, Fake Data comes with 20 default generators:
Default generators | Sample output |
---|---|
Full Name | Delores Runte |
First Name | Evelyn |
Last Name | Bayer |
Username | Jonatan_Treutel56 |
[email protected] * | |
Password | Yf2Bllg6RUlohFl |
Phone | 876-433-9696 |
Job Title | Direct Program Supervisor |
Company | Watsica - Cronin |
Address | 54998 Kacey Dale |
City | New Selenaside |
Country | Philippines |
State | North Carolina |
Zip | 92653 |
Words | placeat eos voluptatem |
Sentence | Dolorem fugit eos. |
Paragraph | Vero debitis voluptas vel at et perspiciatis quae ipsam. Commodi dolor est. |
Text | Eum vero et deleniti. Fugit unde provident voluptatem aliquid est. Numquam sit excepturi aperiam[...] |
Date & time | 2021-08-07 04:34:45 |
Number | 546 |
* The email generator, comes by default with an already customisable javascript code that allows you to generate aliases for your existing email address.
Overriding a Default Generator
Default generators cannot be renamed and cannot be deleted. You can however, overwrite them by clicking on the dropdown menu that is on their right side and choose the Custom Code
option:
For more information about overriding generators with javascript code, go to Writing Code section.
Default Generators can also be customized more quickly, without having to rewrite the entire generator with javascript code. Please see the Customizing Generators section for more info. Pro only
Custom Generators
If the generators that come predefined with Fake Data are not enough, you can always create more custom generators.
Custom Generators are javascript functions that are executed whenever you use them to fill an input field, therefore they need to return the text value that is going to be inserted in the field.
In order to create a new Custom Generator, open Fake Data's options page, go to Generators -> Custom Generators -> and click on the button that can be found on the right side.
The new generator will ask you for a name and the javascript code that will be executed once it has been triggered. For more information about writing code for custom generators, go to Writing Code section.
Nesting Custom Generators
When you create Custom Generators and give them a name, you can put the /
character in order to have them nested inside the context menu.
For example, let's say you have the following 3 custom generators created:
Cryptocurrencies/Random Bitcoin Address
Cryptocurrencies/Random Ethereum Address
Cryptocurrencies/Random Litecoin Address
Then, when you right-click on a form element and go to Fake Data submenu, they will show up like this:
Reordering Custom Generators
If you have multiple custom generators and want to organize them better, you can reorder them by dragging the top part of their container.
Make sure to save the changes when finished.