MCPcopy Index your code
hub / github.com/restify/node-restify / argumentsToChain

Function argumentsToChain

lib/server.js:1638–1664  ·  view source on GitHub ↗

* Verify and flatten a nested array of request handlers. * * @private * @function argumentsToChain * @throws {TypeError} * @param {Function[]} handlers - pass through of funcs from server.[method] * @returns {Array} request handlers

(handlers)

Source from the content-addressed store, hash-verified

1636 * @returns {Array} request handlers
1637 */
1638function argumentsToChain(handlers) {
1639 assert.array(handlers, 'handlers');
1640
1641 var chain = [];
1642
1643 // A recursive function for unwinding a nested array of handlers into a
1644 // single chain.
1645 function process(array) {
1646 for (var i = 0; i < array.length; i++) {
1647 if (Array.isArray(array[i])) {
1648 // Recursively call on nested arrays
1649 process(array[i]);
1650 continue;
1651 }
1652 // If an element of the array isn't an array, ensure it is a
1653 // handler function and then push it onto the chain of handlers
1654 assert.func(array[i], 'handler');
1655 chain.push(array[i]);
1656 }
1657
1658 return chain;
1659 }
1660
1661 // Return the chain, note that if `handlers` is an empty array, this will
1662 // return an empty array.
1663 return process(handlers);
1664}
1665
1666/**
1667 * merge optional formatters with the default formatters to create a single

Callers 2

server.jsFile · 0.85
serverMethodFactoryFunction · 0.85

Calls 1

processFunction · 0.85

Tested by

no test coverage detected