var sanitizeMethods    = require('./methods');
var sanitizeParameters = require('./parameters');

/**
 * Match template tags in a string.
 *
 * @type {RegExp}
 */
var TEMPLATE_REGEXP = /\{[^\{\}]+\}/g;

/**
 * Generate a unique resource id.
 *
 * @type {Function}
 */
var uniqueId = _.uniqueId.bind(null, 'resource');

/**
 * Convert a URI parameter into a variable name.
 *
 * @param  {String} uri
 * @param  {Object} spec
 * @return {String}
 */
var toPropertyFormat = function (uri, spec) {
  // Replace the prefixed path segment.
  uri = uri.replace(/^[\.\/]/, '');

  // Handle a only a single parameter. E.g. "/{param}".
  if (/^\{[^\{\}]+\}$/.test(uri)) {
    return spec.format.variable(uri.slice(1, -1));
示例#2
0
var async = require('async');
var _ = require('lodash');

//Generate an array of 10 random tasks;
/*
[
	'task_1',
	'task_2',
	.
	.
	.
	'task_10'
]
 */
var tasksList = _.times(10, _.uniqueId.bind(null, 'task_'));

// Gif demonstration: https://camo.githubusercontent.com/f4810e00e1c5f5f8addbe3e9f49064fd5d102699/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130312f38346339323036362d356632392d313165322d383134662d3964336430323431336266642e676966

// Create a cargo object with payload 3
// cargo(worker, [payload])
var tasksCargo = async.cargo(function(tasks, callback) {
    for(var i=0; i<tasks.length; i++){
      console.log('working on ' + tasks[i].name);
    }

    callback();
    //Something goes wrong, this will pass error to the task function and it will error out.
    //callback('broke');
}, 3);

示例#3
0
 afterEach(() => {
   _.uniqueId.restore();
 });