Debian Codegraph @

lib/cookies/index.js

raw
1 /** Copyright 2015 Gregory Langlais. See LICENSE.txt. */
2
3 'use strict';
4
5 const Assertion = require('./assertion');
6
7 /**
8 * Construct cookies assertion (function)
9 *
10 * @param {null|string|string[]} [secret]
11 * @param {function(req, res)[]} [asserts] ran within returned assertion function
12 * @returns {function} assertion
13 * @constructor
14 */
15 function ExpectCookies(secret, asserts) {
16 return Assertion(secret, asserts);
17 }
18
19 // build ExpectCookies proxy methods
20 const assertion = Assertion();
21 const methods = Object.getOwnPropertyNames(assertion);
22
23 methods.forEach(function(method) {
24 if (typeof assertion[method] === 'function' && typeof Function[method] === 'undefined') {
25 ExpectCookies[method] = function() {
26 const newAssertion = Assertion();
27 return newAssertion[method].apply(newAssertion, arguments);
28 };
29 }
30 });
31
32 module.exports = ExpectCookies;