jabclab / fiapi

Making organising API internals easy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Φ - fiapi

fiapi aims to make managing the internal structure of APIs as easy as possible.

Build Status Coverage Status

$ ls lib/
method_a.js method_b.js method_c.js
var fiapi = require('fiapi');

fiapi({ root: 'lib/' }, function (err, api) {
  console.log(api);
  // { method_a: [Function], method_b: [Function], method_c: [Function] }
});

Installation

$ npm install fiapi

Firstly require fiapi and then use as follows:

fiapi([opts], callback)

Arguments

  • opts - Object containing configuration for the fiapi call:
    • opts.root - (string, default: __dirname of where fiapi is being called) Root directory of the API.
    • opts.recursive (boolean, default: false) - Whether or not to recurse directories within opts.root
    • opts.pattern (regex, default: /.*/) - Pattern of files to include in the API.
  • callback(err, api) - A callback function which is called when calls to all files in applicable directory have been aggregated into an api object or an error occurs.

Note that only files which export a function will be included in your API 😄

Examples

Given the project structure:

|- bin
  |- cli.js
|- lib
  |- my_namespace
    |- method_d.js
    |- method_e.js
  |- api.js
  |- method_a.js
  |- method_b.js
  |- method_c.js
package.json
// lib/api.js

fiapi(function (err, api) {
  // { method_a: [Function], method_b: [Function], method_c: [Function] }
});
// bin/cli.js

fiapi({ root: '../lib', pattern: /^method/ }, function (err, api) {
  // { method_a: [Function], method_b: [Function], method_c: [Function] }
});
// bin/cli.js

fiapi({ root: '../lib', pattern: /^method/, recursive: true }, function (err, api) {
  // {
  //   method_a: [Function],
  //   method_b: [Function],
  //   method_c: [Function],
  //   my_namespace: {
  //     method_d: [Function],
  //     method_e: [Function]
  //   }
  // }
}

About

Making organising API internals easy

License:MIT License


Languages

Language:JavaScript 100.0%