lib/helpers.js
function errNameFromDesc(desc) {

    assert.string(desc, 'desc');

    // takes an error description, split on spaces, camel case it correctly,
    // then append 'Error' at the end of it.
    // e.g., the passed in description is 'Internal Server Error'
    //       the output is 'InternalServerError'
    var pieces = desc.split(/\s+/);
    var name = _.reduce(pieces, function(acc, piece) {
        // lowercase all, then capitalize it.
        var normalizedPiece = _.capitalize(piece.toLowerCase());
        return acc + normalizedPiece;
    }, '');

    // strip all non word characters
    name = name.replace(/\W+/g, '');

    // append 'Error' at the end of it only if it doesn't already end with it.
    if (!_.endsWith(name, 'Error')) {
        name += 'Error';
    }

    return name;
}
function errNameFromDesc(desc) {

    assert.string(desc, 'desc');

    // takes an error description, split on spaces, camel case it correctly,
    // then append 'Error' at the end of it.
    // e.g., the passed in description is 'Internal Server Error'
    //       the output is 'InternalServerError'
    var pieces = desc.split(/\s+/);
    var name = _.reduce(pieces, function(acc, piece) {
        // lowercase all, then capitalize it.
        var normalizedPiece = _.capitalize(piece.toLowerCase());
        return acc + normalizedPiece;
    }, '');

    // strip all non word characters
    name = name.replace(/\W+/g, '');

    // append 'Error' at the end of it only if it doesn't already end with it.
    if (!_.endsWith(name, 'Error')) {
        name += 'Error';
    }

    return name;
}
function errNameFromDesc ( desc ) { assert . string ( desc , 'desc' ) ; // takes an error description, split on spaces, camel case it correctly, // then append 'Error' at the end of it. // e.g., the passed in description is 'Internal Server Error' //       the output is 'InternalServerError' var pieces = desc . split ( / \s+ / ) ; var name = _ . reduce ( pieces , function ( acc , piece ) { // lowercase all, then capitalize it. var normalizedPiece = _ . capitalize ( piece . toLowerCase ( ) ) ; return acc + normalizedPiece ; } , '' ) ; // strip all non word characters name = name . replace ( / \W+ / g , '' ) ; // append 'Error' at the end of it only if it doesn't already end with it. if ( ! _ . endsWith ( name , 'Error' ) ) { name += 'Error' ; } return name ; }
used to programatically create http error code names, using the underlying
status codes names exposed via the http module.
@private
@function errNameFromDesc
@param {String} desc a description of the error, e.g., 'Not Found'
@returns {String}
used to programatically create http error code names using the underlying status codes names exposed via the http module .