https://rgerhardt-pressmind.github.io/constructs-js
- Demo
- Introduction
- Usage template
- API
Download latest stable version.
<script src = "dist/constructs.min.js" type = "text/javascript"></script>
<script>
var constructs = new constructs("de"); // de = locale (fallback locale is "de")
let uniqFirstName = constructs.name.getFirstName(); // Maik
let uniqSurName = constructs.name.getSurName(); // Raschel
let uniqEmail = constructs.email.getEmail(); // [email protected]
</script>
Install
npm install constructs-js --save
Usage
const Constructs = require('./construct');
let construct = new Constructs('de'); // de = locale (fallback locale is "de")
let first_name = constructs.name.getFirstName();
let sur_name = constructs.name.getSurName();
let email = constructs.email.getEmail();
Install
npm install constructs-js --save
Usage
Add the constructs.min.js in the angular.json at the scripts block
{
"scripts": [
"node_modules/constructs-js/dist/constructs.min.js"
]
}
Test e.g. in the app.component.ts if the script is reachable:
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
constructor() {
let constructs = window['constructs']('de');
console.log('First name: '+constructs.name.getFirstName());
}
}
- af_ZA (South Africa)
- ar (Argentina)
- az (Azerbaijan)
- cz (Czech Republic)
- de (Germany - Fallback locale)
- de_AT (Austria)
- de_CH (Switzerland)
- en (United States of America)
- en_GB (United Kingdom)
- es (Spain)
- fr (France)
- ge (Georgia)
- gr (Greece)
- hr (Croatia)
- id (Indonesia)
- il (Israel)
- ir (Iran)
- it (Italia)
- jp (Japan)
- lv (Latvia)
- pl (Poland)
constructs.js can generate multiple random data at once based on object templates. These data packages can then be used e.g. for grids or displays.
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", // Use for API (Allowed: output, insert)
type: "json", // Result json object (Allowed: json, xml)
limit: 5 // Generate 5 items
}
};
let generatedData = constructs.generateUniqData(template);
console.log(generatedData);
[
{
"id": 99848,
"first_name": "Henrik",
"sur_name": "Ranz",
"name": "Henrik Ranz",
"birthday": "1979-03-08",
"age": 42,
"created_date": "2014-10-28 19:19:09"
},
{
"id": 52560,
"first_name": "Timothy",
"sur_name": "Frantz",
"name": "Timothy Frantz",
"birthday": "1981-03-14",
"age": 40,
"created_date": "2007-07-25 16:11:18"
},
{
"id": 232936,
"first_name": "Elli",
"sur_name": "Behrenbruch",
"name": "Elli Behrenbruch",
"birthday": "1971-09-06",
"age": 50,
"created_date": "2012-04-30 11:14:32"
},
{
"id": 500971,
"first_name": "Lennart",
"sur_name": "Fink",
"name": "Lennart Fink",
"birthday": "1983-04-06",
"age": 38,
"created_date": "2010-03-30 15:40:03"
},
{
"id": 34174,
"first_name": "Darleen",
"sur_name": "Töpfer",
"name": "Darleen Töpfer",
"birthday": "1973-06-28",
"age": 48,
"created_date": "2017-01-18 04:24:38"
}
]
Generate random address. The structure of the address depends on the respective locale.
let address = constructs.address.getAddress();
Am Neuenhof 53a, Baryllastadt 82559 Deutschland
Am Nonnenbruch 716, Nord Tillmannscheid 97817 Deutschland
Karlstr. 42b, SĂĽd Emrescheid 07554 Deutschland
Returns a random street based on the locale.
let street = constructs.address.getStreet();
Friedrich-List-Str.
Am Knechtsgraben
Montanusstr.
Generates a building number based on the defined scheme in locale.
let building_number = constructs.address.getBuildingNumber();
244
997b
520a
Returns a random zip code based on the locale.
let postcode = constructs.address.getPostcode();
03884
57392
82411
Returns a random state based on the locale.
let state = constructs.address.getState();
ThĂĽringen
Bremen
Niedersachsen
Generates a fictitious city name based on the first name and last name list from the locales.
let city = constructs.city.getCity();
Jankescheid
Davinburg
Gregerdorf
Returns a random prefix from the locale.
let city_prefix = constructs.city.getPrefix();
Nord
Ost
West
Returns a random suffix from the locale.
let city_suffix = constructs.city.getSuffix();
stadt
dorf
land
Generates a fictitious company name based on the first name and last name list from locales.
let company = constructs.company.getCompany();
Loogen GmbH
Wartenberg, Helm und Többen
Noack GmbH & Co KG
Returns a random prefix from the locale.
let company_suffix = constructs.company.getSuffix();
GmbH
GbR
AG
Returns a random country which is stored in locale
let country = constructs.country.getCountry();
Italien
Returns the default country
let country_default = constructs.country.getDefaultCountry();
Deutschland
Returns a randomly generated credit card number based on the locales.The provider can be controlled via the "types" parameter.
let credit_card = constructs.credit_card.getNumber({type: 'amex'});
5561-9631-7062-589
Returns a randomly generated credit card number based on the locales.
let maestro = constructs.credit_card.getMaestro();
5561-9631-7062-589
Returns a randomly generated credit card number based on the locales.
let mastercard = constructs.credit_card.getMastercard();
5561-9631-7062-589
Returns a randomly generated credit card number based on the locales.
let amex = constructs.credit_card.getAmex();
5561-9631-7062-589
Returns a randomly generated credit card number based on the locales.
let visa = constructs.credit_card.getVisa();
5561-9631-7062-589
Returns a random email address based on a random last name from the locale and a random defined domain.
let email = constructs.email.getEmail();
Returns a random suffix from the locale.
let email_suffix = constructs.email.getSuffix();
@gmail.com
@yahoo.com
Returns a random image based on the type in the local. By default the type "avatar" is set. The images have a maximum size of 500x500 pixels.
let animal = constructs.image.getAnimalImage(); // or .image.getImage({type: 'animal'})
let avatar = constructs.image.getAvatarImage(); // or .image.getImage({type: 'avatar'})
let city = constructs.image.getCityImage(); // or .image.getImage({type: 'city'})
let human = constructs.image.getHumanImage(); // or .image.getImage({type: 'human'})
let nature = constructs.image.getNatureImage(); // or .image.getImage({type: 'nature'})
let technic = constructs.image.getTechnicImage(); // or .image.getImage({type: 'technic'})
Returns a random sentence based on the words from the "Lorem ipsum" text. The number of words can be limited/extended by the "words" parameter.
let loremIpsum = constructs.loremIpsum.getWords(); // return default 60 words
let loremIpsum10 = constructs.loremIpsum.getWords({max: 10}); // return 10 words
60 words:
Amet vero ullamcorper sea lorem dolor clita voluptua accusam dolores justo labore facilisis clita At dolor takimata facilisis consetetur erat sadipscing nibh diam tincidunt autem justo invidunt dolores magna vulputate blandit lorem aliquip mazim no molestie ipsum exerci vel dolor consectetuer facilisis nonumy ut takimata dolore rebum nisl dolor vero illum consequat facilisi feugiat ad option amet amet stet diam.
10 words:
Sadipscing elitr aliquam est et accusam sadipscing assum eum molestie.
Returns a random name based on the first name and last name list of the locale. Titles (doctor or professor) can also precede the names.
let name = constructs.name.getName();
Enes Kette
Frau Prof. Jolie Polifka
Dr. Vito Kempter
Returns a random first name from the list of locales.
let first_name = constructs.name.getFirstName();
Maxel
Frank
Ben
Returns a random surname based on the locale.
let sur_name = constructs.name.getSurName();
Bremser
Ritosek
Lott
Returns a random salutation based on the locale.
let gender = constructs.name.getSalutation();
Herr
Frau
Diverses
Returns a random title based on the locale.
let title = constructs.name.getTitle();
Dr.
Prof.
Creates a random cell phone number based on the scheme in locale.
let cell_phone = constructs.phone.getCellPhoneNumber();
+49-152-1664339
+49-1739-9267441
Returns a randomly generated phone number based on the local scheme.
let phone = constructs.phone.getPhoneNumber();
(0183) 837993227
(01294) 4479364
+49-174-9347731
+49-1834-99411402
The template scheme is structured as follows and must be maintained.
{
structure: [
{
name: "id", // Field name
mask: "[id]" // Mask
}
],
output: {
result: "output", // Use for API (Allowed: output, insert)
type: "json", // Result json object (Allowed: json, xml)
limit: 5 // Generate 5 items
}
}
The mask is always structured according to the scheme
[module:function]
module: Class module function: function call
Function calls can also include parameters that can be processed further.
Several [module:function] can also be listed in the masks.
Prof. Dr. [name:getFirstName] [name:getSurName]
So different masks can be combined in the input mask and normal text can be used.
Other field contents can also be accessed in the masks. For example, one has built a structure that looks like this:
{
"name": "birthday",
"mask": "[date]"
},
{
"name": "age"
"mask": "[diffYearNow({birthday})]"
}
Then you can see that in the mask at the field age the field content {birthday} is accessed. It doesn't matter where the field is defined in the structure.
Returns a random generated number which can be further restricted with the parameters min and max.
[id(min = 1, max = 1000000)]
Returns a random generated date which can be further restricted with the parameters min (schema: 1970-01-01) and max (schema: 1970-01-01).
[date(min = null, max = null)]
Returns a random generated datetime which can be further restricted with the parameters min (schema: 1970-01-01) and max (schema: 1970-01-01).
[datetime(min = null, max = null)]
Calculates the year which lies between the passed date and today's date. (schema: 1970-01-01 or 1970-01-01 00:00:00)
[diffYearNow(date)]
Returns an address based on the locale.
[address:getAddress]
Returns a street based on the locale.
[address:getStreet]
Returns a building number based on the locales
[address:getBuildingNumber]
Returns a post code based on the locales
[address:getPostcode]
Returns a state based on the locales
[address:getState]
Returns a city based on the locales
[city:getCity]
Returns a prefix based on the locales
[city:getPrefix]
Returns a suffix based on the locales
[city:getSuffix]
Returns a company based on the locales
[company:getCompany]
Returns a suffix based on the locales
[company:getSuffix]
Returns a country based on the locales
[country:getCountry]
Returns the default country of the locale
[country:getDefaultCountry]
Returns a credit card number based on the locales
[credit_card:getNumber(type = amex)]
Returns a credit card number based on the locales
[credit_card:getMaestro]
Returns a credit card number based on the locales
[credit_card:getMastercard]
Returns a credit card number based on the locales
[credit_card:getAmex]
Returns a credit card number based on the locales
[credit_card:getVisa]
Returns a email based on the locales
[email:getEmail]
Returns a suffix based on the locales
[email:getSuffix]
Returns a image based on the locale. The type parameter defines from which image pool a random image should come back. Existing image pools: animal, avatar(default), city, human, nature and technic
[image:getImage(type: null)]
Returns a avatar image based on the locales
[image:getAvatarImage]
Returns a animal image based on the locales
[image:getAnimalImage]
Returns a city image based on the locales
[image:getCityImage]
Returns a human image based on the locales
[image:getHumanImage]
Returns a nature image based on the locales
[image:getNatureImage]
Returns a technic image based on the locales
[image:getTechnicImage]
Returns a random Lorem ipsum text based on the locale. The parameter "max" can be used to specify the length of the returned sentence. By default the length is 60 words.
[loremIpsum:getWords(max: null)]
Returns a name based on the locales
[name:getName]
Returns a first name based on the locales
[name:getFirstName]
Returns a sur name based on the locales
[name:getSurName]
Returns a salutation based on the locales
[name:getSalutation]
Returns a title based on the locales
[name:getTitle]
Returns a phone number based on the locales
[name:getPhoneNumber]
Returns a cell phone number based on the locales
[name:getCellPhoneNumber]