forked from faker-js/faker
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: support tree-shaking (faker-js#152)
- Loading branch information
1 parent
2c8e368
commit 81d7d5e
Showing
38 changed files
with
122 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,39 @@ | ||
// 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.datatype.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.datatype.number(700, 9000) | ||
} | ||
}) | ||
} | ||
}) | ||
} | ||
|
||
console.log(JSON.stringify(company)) | ||
fs.writeFile(__dirname + '/companyDataSet.json', JSON.stringify(company), function() { | ||
console.log("dataSet generated successfully!"); | ||
}); | ||
// 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('../../lib').faker; | ||
var fs = require('fs'); | ||
// produce array with random number of empty elements | ||
const arr = (maxNumberOfElements) => | ||
new Array(faker.datatype.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.datatype.number(700, 9000), | ||
}; | ||
}), | ||
}; | ||
}), | ||
}; | ||
|
||
console.log(JSON.stringify(company)); | ||
fs.writeFile( | ||
__dirname + '/companyDataSet.json', | ||
JSON.stringify(company), | ||
function () { | ||
console.log('dataSet generated successfully!'); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,26 @@ | ||
var fs = require('fs'); | ||
|
||
var faker = require('../../index'); | ||
|
||
var faker = require('../../lib').faker; | ||
|
||
// generate dataSet as example | ||
fs.writeFile(__dirname + '/dataSet.json', JSON.stringify(faker.helpers.userCard()), function() { | ||
console.log("dataSet generated successfully!"); | ||
}); | ||
fs.writeFile( | ||
__dirname + '/dataSet.json', | ||
JSON.stringify(faker.helpers.userCard()), | ||
function () { | ||
console.log('dataSet generated successfully!'); | ||
} | ||
); | ||
// generate bigDataSet as example | ||
var bigSet = []; | ||
|
||
for(var i = 20; i >= 0; i--){ | ||
for (var i = 20; i >= 0; i--) { | ||
bigSet.push(faker.helpers.userCard()); | ||
}; | ||
} | ||
|
||
fs.writeFile(__dirname + '/bigDataSet.json', JSON.stringify(bigSet), function() { | ||
console.log("bigDataSet generated successfully!"); | ||
}); | ||
fs.writeFile( | ||
__dirname + '/bigDataSet.json', | ||
JSON.stringify(bigSet), | ||
function () { | ||
console.log('bigDataSet generated successfully!'); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,11 @@ | ||
var faker = require('../../index'); | ||
var faker = require('../../lib').faker; | ||
|
||
faker.locale = "en"; | ||
faker.locale = 'en'; | ||
|
||
console.log(faker.fake('{{random.uuid}}, {{name.firstName}} {{name.suffix}}')); | ||
|
||
|
||
return; | ||
|
||
|
||
console.log(faker.fake('{{finance.currencyName}} - {{finance.amount}}')); | ||
|
||
|
||
console.log(faker.fake('{{name.firstName}} {{name.lastName}}')); | ||
console.log(faker.fake('{{name.firstName}} {{name.lastName}}')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
#!/usr/bin/env node | ||
|
||
var faker = require('../../index'); | ||
faker.locale = "fi"; | ||
var faker = require('../../lib').faker; | ||
faker.locale = 'fi'; | ||
|
||
//console.log(faker.lorem.sentences()) | ||
|
||
console.log(faker.name.findName()) | ||
console.log(faker.name.findName()); | ||
return; | ||
//console.log(faker.address) | ||
console.log(faker.internet.email()) | ||
console.log(faker.date.recent()) | ||
console.log(faker.internet.email()); | ||
console.log(faker.date.recent()); | ||
console.log(faker.helpers.contextualCard()); | ||
|
||
faker.locale = "uk"; | ||
faker.locale = 'uk'; | ||
|
||
console.log(faker.helpers.contextualCard()); | ||
console.log(faker.helpers.contextualCard()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.