-
-
Notifications
You must be signed in to change notification settings - Fork 929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: support tree-shaking #152
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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!'); | ||
} | ||
); |
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the important line in this file. |
||
|
||
// 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!'); | ||
} | ||
); |
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}}')); |
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 was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
"url": "https://github.com/faker-js/faker.git" | ||
}, | ||
"license": "MIT", | ||
"main": "index.js", | ||
"main": "lib/index.js", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the most important line of this PR 🙂 |
||
"scripts": { | ||
"browser": "gulp browser", | ||
"build": "tsc", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -271,5 +271,9 @@ export class Faker { | |
} | ||
} | ||
|
||
export default Faker; | ||
module.exports = Faker; | ||
// since we are requiring the top level of faker, load all locales by default | ||
export const faker: Faker = new Faker({ | ||
locales: require('./locales'), | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to add |
||
|
||
export default faker; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the important line in this file.
I didn't touched the rest of this file, just auto-prettier on save.