A plugin for Pattern Lab that allows Faker in the data.json file
npm install @tonyisworking/plugin-node-fakerThis is a plugin that adds Faker data to your data.json file at build time.
For @pattern-lab/patternlab-node v2.12 please refer to version 1.* of this plugin.
``bash`
npm install --save @tonyisworking/plugin-node-faker
npm run pl:install @tonyisworking/plugin-node-faker
If patternlab-config.json isn't updated add this to enable the plugin:
``
"plugins": {
"@tonyisworking/plugin-node-faker": {
"enabled": true,
"initialized": false,
"options": {
"tabsToAdd": []
}
}
}
In data.json, add Faker API methods as strings. Call the vars as you normally would inside Mustache (untested with other PL engines).
``
{
"company" : {
"name" : "@faker.name.findName@",
"url" : "@faker.internet.url@"
}
}
`options
@faker.[SECTION].PROPERTY@ // and parenthesis are optional`
@faker.name.findName@ // returns 'Neal Considine'
@faker.name.firstName@ // returns 'Jaron'
@faker.name.lastName@ // returns 'Will'
@faker.internet.url@ // returns 'https://heath.org'
@faker.lorem.paragraph@ // returns paragraph
@faker.lorem.words(5)@ // returns 5 words
@faker.lorem.text(500)@ // returns random number of characters less than 500. Could be 20 chars. Could be 200.
Check out Faker on NPM for all the different API methods (https://www.npmjs.com/package/faker). I've found Marak's Github wiki to be a little more detailed though (https://github.com/Marak/Faker.js/wiki).
A tale of two listeners. For some reason, I can't update the listitems object and the pattern-specific data object with one listener. data.json` doesn't care where it's changed, but these other two get operated on in different places.