1.0.1 • Published 8 years ago

json-func v1.0.1

Weekly downloads
2
License
UNLICENSED
Repository
github
Last release
8 years ago

json-func

   Have you ever needed an api that responded with specific data, say for mocking?
    Then this is the module for you!

npm version dependencies Build Status

#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