* 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)
| 1636 | * @returns {Array} request handlers |
| 1637 | */ |
| 1638 | function 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 |
no test coverage detected