json-func
v1.0.1
Published
Lets you turn JSON into asynchronous api objects
Downloads
3
Maintainers
Readme
json-func
Have you ever needed an api that responded with specific data, say for mocking?
Then this is the module for you!
#Install
npm install json-func --save
#Usage:
var jsonFunc = require('json-func');
var mockData = {
service1 : {
call1 : {
data : 'hello from service1 call1'
},
call2: {
data : 'hello from service1 call2'
}
},
service2 : {
call1 : {
data : 'hello from service2 call1'
},
call2 : {
data : 'hello from service2 call2'
}
}
};
var mock = jsonFunc(mockData, {
bindings : {
'getAll' : 'service1.call1.data',
'addOne' : 'service1.call2.data',
'deleteIt' : 'service2.call1.data',
'updateOne' : 'service2.call2.data'
},
async : true,
callbacks : true,
includeOptionArg : true,
errOption : true
});
// async - enables setTimeout/process.nextTick on functions
// callbacks - enables callback api ( if you enable async this will be forcefully enabled )
// includeOptionArg - enables first argument options parameter ( to keep API integrity
// errOption - enables err parameter in singleton callback
#What you effectively get back!
mock = {
getAll : function,
addOne : function,
deleteIt : function,
updateOne : function
};
#Feel free to check out test/test.js for more examples
Beware of nested callbacks #testinglazy