Skip to content
Snippets Groups Projects
Commit 3dfbf3a1 authored by Tomasz Ducin's avatar Tomasz Ducin
Browse files

extending jsf, #12

parent d676a3a9
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ language: node_js ...@@ -2,7 +2,7 @@ language: node_js
branches: branches:
only: only:
- master - master
- extending-dependencies - jsf-extend
node_js: node_js:
- 0.10 - 0.10
before_script: before_script:
......
...@@ -201,6 +201,35 @@ Callback: ...@@ -201,6 +201,35 @@ Callback:
Note that custom generators has lower precedence than core ones. Note that custom generators has lower precedence than core ones.
## Extending dependencies
You may extend [Faker.js](http://marak.com/faker.js/) and [Chance.js](http://chancejs.com/):
```javascript
var jsf = require('json-schema-faker');
jsf.extend('faker', function(faker){
faker.locale = "de"; // or any other language
faker.custom = {
statement: function(length) {
return faker.name.firstName() + " has " + faker.finance.amount() + " on " + faker.finance.account(length) + ".";
}
};
return faker;
});
var schema = {
"type": "string",
"faker": {
"custom.statement": [19]
}
}
var sample = jsf(schema);
```
The first parameter of `extend` function is the generator name (`faker` or `chance`). The second one is the function that accepts the dependency library; the function alters the library and **returns it**.
## Automation: grunt plugin ## Automation: grunt plugin
Use [grunt-jsonschema-faker](https://github.com/tkoomzaaskz/grunt-jsonschema-faker) Use [grunt-jsonschema-faker](https://github.com/tkoomzaaskz/grunt-jsonschema-faker)
......
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
...@@ -15,6 +15,6 @@ module.exports = { ...@@ -15,6 +15,6 @@ module.exports = {
return faker; return faker;
}, },
register: function(jsfaker) { register: function(jsfaker) {
return jsfaker.customize('faker', this.extend); return jsfaker.extend('faker', this.extend);
} }
}; };
[ [
{ {
"description": "generated extended faker", "description": "faker extension",
"tests": [ "tests": [
{ {
"description": "should handle faker.custom.statement", "description": "should handle faker.custom.statement",
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
} }
}, },
"valid": true, "valid": true,
"require": "core/customize/faker-extend" "require": "core/extend/faker-extend"
} }
] ]
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment