aboutsummaryrefslogtreecommitdiff
path: root/examples/node
diff options
context:
space:
mode:
authorMarak <[email protected]>2021-02-04 17:29:55 -0500
committerGitHub <[email protected]>2021-02-04 17:29:55 -0500
commitcdcb600957650a84ebf70a6267add4b41371a3f3 (patch)
tree6d8b4fc57bfa90688dc65db40e1bd9c828258891 /examples/node
parent639a5256a259066b3619423d89edf6675c674293 (diff)
parentad391be8444882af92519ac7a4c4d784818b0193 (diff)
downloadfaker-cdcb600957650a84ebf70a6267add4b41371a3f3.tar.xz
faker-cdcb600957650a84ebf70a6267add4b41371a3f3.zip
Merge branch 'master' into nl-locale-weekdays
Diffstat (limited to 'examples/node')
-rw-r--r--examples/node/generateMultiLevelMultiLocaleJSON.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/examples/node/generateMultiLevelMultiLocaleJSON.js b/examples/node/generateMultiLevelMultiLocaleJSON.js
new file mode 100644
index 00000000..ee7ce10c
--- /dev/null
+++ b/examples/node/generateMultiLevelMultiLocaleJSON.js
@@ -0,0 +1,31 @@
+// This example shows the generation of a multilevel object and JSON document using various faker.js features
+// including name, address, company, date and commerce namespaces, moustache expressions and random element production
+// Using the helper function arr, randomly sized collections of elements are produced in the document.
+
+var faker = require('../../index');
+var fs = require('fs');
+// produce array with random number of empty elements
+const arr = (maxNumberOfElements) => new Array(faker.random.number({min: 1, max: maxNumberOfElements})).fill()
+
+const locales = ["nl","es","de","fr","en_AU"]
+const company =
+ { "name" : faker.company.companyName()
+ , "country" : faker.address.country()
+ , "departments" : arr(8).map(() => { faker.locale = faker.random.arrayElement(locales)
+ return { "name" : faker.commerce.department()
+ , "location" : faker.fake("{{address.city}} ({{address.country}})")
+ , "employees": arr(20).map(() => {
+ return { "name" : faker.fake("{{name.firstName}} {{name.lastName}}")
+ , "job" : faker.name.jobTitle()
+ , "hiredate" : faker.date.past(12).toISOString().split('T')[0]
+ , "salary" : faker.random.number(700, 9000)
+ }
+ })
+ }
+ })
+ }
+
+ console.log(JSON.stringify(company))
+ fs.writeFile(__dirname + '/companyDataSet.json', JSON.stringify(company), function() {
+ console.log("dataSet generated successfully!");
+ }); \ No newline at end of file