Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

json-func

1.0.1 • Public • Published

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 Pledge To Arupex!

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

install

npm i json-func

Downloadsweekly downloads

2

version

1.0.1

license

UNLICENSED

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability