From a4d6a2af0d57a2e0cccf31e3462c8b2465239f8b Mon Sep 17 00:00:00 2001 From: dcodeIO Date: Tue, 3 Jan 2017 14:47:49 +0100 Subject: [PATCH] New: Added global ParseOptions#keepCase fallback as protobuf.parse.keepCase, see #608 --- src/parse.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/parse.js b/src/parse.js index 2f7027e7f..fb8439ee1 100644 --- a/src/parse.js +++ b/src/parse.js @@ -1,6 +1,8 @@ "use strict"; module.exports = parse; +parse.keepCase = false; + var tokenize = require("./tokenize"), Root = require("./root"), Type = require("./type"), @@ -61,14 +63,16 @@ function camelCase(str) { * @param {ParseOptions} [options] Parse options * @returns {ParserResult} Parser result * @property {string} filename=null Currently processing file name for error reporting, if known + * @property {boolean} keepCase=false When set to `true`, always keeps field casing instead of converting to camel case when no {@link ParseOptions} are specified */ function parse(source, root, options) { /* eslint-disable callback-return */ if (!(root instanceof Root)) { + options = root; root = new Root(); - options = root || {}; - } else if (!options) - options = {}; + } + if (!options) + options = { keepCase: parse.keepCase }; var tn = tokenize(source), next = tn.next,