constructs.js Example

With Constructs random content can be generated quickly and in large quantities. Whether via JavaScript or with NodeJS.

Automatically generate a random values


<script src="dist/constructs.min.js" type="text/javascript"></script>

var constructs   =   new constructs();

var address           =   constructs.address.getAddress();
var building_number   =   constructs.address.getBuildingNumber();
var cell_phone        =   constructs.phone.getCellPhoneNumber();
var city              =   constructs.city.getCity();
var company           =   constructs.company.getCompany();
var country           =   constructs.country.getDefaultCountry();
var email             =   constructs.email.getEmail();
var first_name        =   constructs.name.getFirstName();
var salutation        =   constructs.name.getSalutation();
var image_avatar      =   constructs.image.getImage();
var image_animal      =   constructs.image.getAnimalImage();
var image_city        =   constructs.image.getCityImage();
var image_human       =   constructs.image.getHumanImage();
var image_nature      =   constructs.image.getNatureImage();
var image_technic     =   constructs.image.getTechnicImage();
var loremIpsum        =   constructs.loremIpsum.getWords({max: 10});
var name              =   constructs.name.getName();
var phone             =   constructs.phone.getPhoneNumber();
var postcode          =   constructs.address.getPostcode();
var state             =   constructs.address.getState();
var street            =   constructs.address.getStreet();
var sur_name          =   constructs.name.getSurName();
var title             =   constructs.name.getTitle();
var credit_card       =   constructs.credit_card.getNumber();
    

address:
building_number:
cell_phone:
city:
company:
country:
email:
first_name:
salutation:

image:



image_animal:



image_city:



image_human:



image_nature:



image_technic:



loremIpsum:
name:
phone:
postcode:
state:
street:
sur_name:
title:
credit_card:

Generate other random values

Avatar Name Birthday Address

Generating a JSON based on a template


<script src="dist/constructs.min.js" type="text/javascript"></script>

var constructs   =   new constructs();

let template = {
    name: "Example template",
    structure: [
        {
            name: "id",
            mask: "[id]"
        },
        {
            name: "first_name",
            mask: "[name:getFirstName]"
        },
        {
            name: "sur_name",
            mask: "[name:getSurName]"
        },
        {
            name: "name",
            mask: "{first_name} {sur_name}" // Merge field content from {"name": "first_name"} and {"name": "sur_name"}
        },
        {
            name: "birthday",
            mask: "[date(1990-01-01, 1970-01-01)]" // Generate date from 01.01.1970 and 01.01.1990
        },
        {
            name: "age",
            mask: "[diffYearNow({birthday})]" // Returns the difference in years from the field content {"name": "birthday"} returns
        },
        {
            name: "created_date",
            mask: "[datetime]"
        }
    ],
    output: {
        result: "output",
        type: "json",
        limit: 5
    }
};

let generatedData = constructs.generateUniqData(template);

console.log(generatedData);
    
Output