diff --git a/lib/descriptors/EnumDescriptor.js b/lib/descriptors/EnumDescriptor.js index 4ee55dc..15e552c 100644 --- a/lib/descriptors/EnumDescriptor.js +++ b/lib/descriptors/EnumDescriptor.js @@ -5,6 +5,7 @@ var util = require('util') var Descriptor = require('./Descriptor') +var helper = require('../helper') /** * @param {string} name Name of the enumeration @@ -63,7 +64,11 @@ EnumDescriptor.prototype.getNames = function () { EnumDescriptor.prototype.getValueForNumber = function (number) { var name = this._names[number] - return name ? { name: name, number: number } : null + return name ? { + name: name, + titleName: helper.toTitleCase(name), + number: number + } : null } diff --git a/lib/helper.js b/lib/helper.js index a1a08a0..21ba060 100644 --- a/lib/helper.js +++ b/lib/helper.js @@ -57,7 +57,8 @@ exports.extend = function (var_args) { * @return {string} */ exports.toCamelCase = function(str) { - return String(str).replace(/\_([a-z])/g, function(all, match) { + var lowerCase = str.toLowerCase() + return String(lowerCase).replace(/\_([a-z])/g, function(all, match) { return match.toUpperCase() }) } diff --git a/tests/project_test.js b/tests/project_test.js index ff6845e..d5ebd00 100644 --- a/tests/project_test.js +++ b/tests/project_test.js @@ -30,9 +30,10 @@ exports.testGetProtos = function (test) { var enums = personProtos[0].toTemplateObject().messages[0].enums test.equal(1, enums && enums.length) test.deepEqual( - {name: 'PhoneType', values: [{name: 'MOBILE', number: 0}, - {name: 'HOME', number: 1}, - {name: 'WORK', number: 2}]}, + {name: 'PhoneType', values: [{name: 'MOBILE', titleName: 'Mobile', number: 0}, + {name: 'HOME', titleName: 'Home', number: 1}, + {name: 'WORK', titleName: 'Work', number: 2}, + {name: 'WORK_FAX', titleName: 'WorkFax', number: 3}]}, enums[0]) test.done() diff --git a/tests/protos/person.proto b/tests/protos/person.proto index 5b10555..b65e2f3 100644 --- a/tests/protos/person.proto +++ b/tests/protos/person.proto @@ -21,6 +21,7 @@ message Person { // Comment HOME = 1; WORK = 2; + WORK_FAX = 3; } message PhoneNumber {