How to use the methods.join function in methods

To help you get started, we’ve selected a few methods examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nswbmw / koa-scheme / index.js View on Github external
module.exports = function (conf, options) {
  if ('string' === typeof conf) {
    conf = require(conf);
  }
  if (Object.prototype.toString.call(conf) !== '[object Object]') {
    throw new Error('No scheme.');
  }
  options = options || {};

  var _conf = {};

  var pathReg = new RegExp('(' + methods.join('|') + ')\\S*\\s+\/', 'i');
  Object.keys(conf).forEach(function (path) {
    // eg: 'GET /user/:userId'
    if (pathReg.test(path)) {
      _conf[path] = conf[path];
    } else {
      // eg: '/user/:userId', request.method: 'GET'
      _conf[((conf[path].request || {}).method || '(.+)') + ' ' + path] = conf[path];
    }
  });

  // flat object, but preserve array, see: https://www.npmjs.com/package/flat#safe
  Object.keys(_conf).forEach(function (path) {
    if (_conf[path].request) _conf[path].request = flatten(_conf[path].request, {safe: true});
    if (_conf[path].response) _conf[path].response = flatten(_conf[path].response, {safe: true});
  });
github mytharcher / rainbow / index.js View on Github external
module.exports = function (options = {}) {
	var middleware = express.Router({
		strict: options.strict
	});
	var optionControllers = options.controllers || 'controllers';
	var ctrlDir = path.isAbsolute(optionControllers) ?
		optionControllers :
		path.join(path.dirname(module.parent.filename), optionControllers);
	var keyRE = new RegExp('(' + methods.join('|') + ')(?:\\s+((?:\\/(.+)\\/)|([^\\/].*[^\\/])))?', 'i');
	var globOptions = options.glob || {};

	glob.sync(ctrlDir + "/**/*.js", globOptions).forEach(function (file) {
		file = file.replace(/\.[^.]*$/, '');

		var instance = require(file);
		var url = file.replace(ctrlDir, '').replace(/\/index$/, '');

		Object.keys(instance).forEach(function (key) {
			if (key === 'filters') {
				return;
			}

			var matcher = key.match(keyRE);

			if (!matcher) {