1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00
node-red-nodes/function/datagenerator
2021-03-12 20:46:19 +00:00
..
locales bump datagenerator for translation 2021-03-12 20:46:19 +00:00
datagenerator.html bump datagenerator for translation 2021-03-12 20:46:19 +00:00
datagenerator.js Re-lint a load of nodes 2017-01-29 17:45:44 +00:00
LICENSE Update licenses and packages for all nodes 2016-11-06 20:26:19 +00:00
package.json bump datagenerator for translation 2021-03-12 20:46:19 +00:00
README.md Tidy datagenerator, random and smaz nodes 2019-09-20 21:22:14 +01:00

node-red-node-web-data-generator

A Node-RED node to create dummy data values from a template. Useful for building test-cases.

Install

Either use the Manage Palette option in the Node-RED Editor menu, or run the following command in your Node-RED user directory - typically ~/.node-red

    npm i node-red-node-data-generator

Usage

Creates dummy data based on a handlebars-style template.

Uses the dummy-json module, which can create rich sets of dummy data for testing or other uses.

It will build a string, or a parsed JSON object, creating values based on the helper names below:

title, firstName, lastName, company, domain, tld, email,
street, city, country, countryCode, zipcode, postcode,
lat, long, phone "+xx (x) xxxx xxx xxx", color, hexColor, guid,
ipv4, ipv6, lorem nn, date, time,
lowercase (helper), uppercase (helper), int, float, boolean

Multiple values can be generated by use of the repeat syntax.

In addition any properties passed in on the msg object can also be used - for example {{payload}}.

Finally msg.seed can be used to preset the pseudo-random seed to ensure repeatability across calls.

Example

The example flow below produces a JSON string which is then converted into an object, for example:

{
    "name": "Theo Cumbie",
    "work": "CoreXTS",
    "email": "theo.cumbie@corexts.gov",
    "address": "83 Sherman Road",
    "country": "Angola",
    "text": "Sagittis orci elementum e vel scelerisque. Amet ac tristique lectus. Morbi e suscipit scelerisque auctor curabitur velit metus gravida quis."
}

Example flow

[{"id":"325b6a4a.cf1706","type":"inject","z":"4affede3.af6f44","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":110,"y":300,"wires":"9d14acc0.c8d9d"},{"id":"96c9a04e.35232","type":"debug","z":"4affede3.af6f44","name":"","active":true,"console":"false","complete":"false","x":513,"y":300,"wires":[]},{"id":"9d14acc0.c8d9d","type":"data-generator","z":"4affede3.af6f44","name":"","field":"payload","fieldType":"msg","syntax":"json","template":"{\n "name": "{{firstName}} {{lastName}}",\n "work": "{{company}}",\n "email": "{{email}}",\n "address": "{{int 1 100}} {{street}}",\n "country": "{{country}}",\n "countryCode": "{{countryCode}}",\n "text":"{{lorem 20}}"\n}","x":280,"y":300,"wires":"96c9a04e.35232"}]