├── .gitignore ├── README.md ├── package.json └── vue-faker.js /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vue-faker 2 | Vue plugin that wraps the node fake data generator, [faker] (https://github.com/marak/Faker.js/). 3 | 4 | ## Installation 5 | 6 | You can install this plugin through NPM 7 | 8 | ``` cmd 9 | npm install vue-faker 10 | ``` 11 | 12 | And then register the plugin with Vue. 13 | 14 | ``` js 15 | Vue.use(require('vue-faker')); 16 | ``` 17 | 18 | ## Usage 19 | You now access the faker library using the following command 20 | 21 | ``` js 22 | Vue.faker().name.firstName() 23 | ``` 24 | 25 | Or from within a Vue component 26 | 27 | ``` js 28 | this.$faker().name.firstName() 29 | ``` 30 | 31 | ``` js 32 | ... 33 | data() { 34 | return { 35 | name: this.$faker().name.findName(), 36 | email: this.$faker().internet.email(), 37 | company: this.$faker().company.companyName(), 38 | } 39 | }, 40 | ... 41 | ``` 42 | 43 | ### Locale 44 | You can set the loacle globally by passing it through as an option to the plugin 45 | 46 | ``` js 47 | Vue.use(require('vue-faker'), {locale: 'en_GB'}); 48 | ``` 49 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-faker", 3 | "version": "3.0.0", 4 | "description": "Vue plugin that wraps faker.js", 5 | "main": "vue-faker.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/BrockReece/vue-faker.git" 12 | }, 13 | "keywords": [ 14 | "Vue", 15 | "plugin", 16 | "faker.js", 17 | "dev" 18 | ], 19 | "author": "Brock Reece", 20 | "license": "ISC", 21 | "bugs": { 22 | "url": "https://github.com/BrockReece/vue-faker/issues" 23 | }, 24 | "homepage": "https://github.com/BrockReece/vue-faker#readme", 25 | "dependencies": { 26 | "faker": "^5.0.0", 27 | "underscore": "^1.8.3" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /vue-faker.js: -------------------------------------------------------------------------------- 1 | var faker = require('faker'), 2 | _ = require('underscore'); 3 | 4 | module.exports = { 5 | install: function (Vue, options) { 6 | 7 | if (options && options.locale) { 8 | faker.locale = options.locale; 9 | } 10 | 11 | var config = { 12 | active: true, 13 | }; 14 | 15 | _.extend(config, options); 16 | 17 | Vue.faker = function() { 18 | return faker; 19 | } 20 | 21 | Vue.prototype.$faker = function() { 22 | return Vue.faker(); 23 | } 24 | 25 | Vue.prototype.$fake = function(string) { 26 | if (!config.active) { 27 | return ""; 28 | } 29 | return Vue.faker().fake(string); 30 | } 31 | }, 32 | }; 33 | --------------------------------------------------------------------------------