diff --git a/cli/targets/json-module.js b/cli/targets/json-module.js index eedf3cbeb..5255cd99c 100644 --- a/cli/targets/json-module.js +++ b/cli/targets/json-module.js @@ -7,17 +7,25 @@ var protobuf = require("../.."); json_module.description = "JSON representation as a module"; +function jsonSafeProp(json) { + return json.replace(/^( +)"(\w+)":/mg, function($0, $1, $2) { + return protobuf.util.safeProp($2).charAt(0) === "." + ? $1 + $2 + ":" + : $0; + }); +} + function json_module(root, options, callback) { try { - var rootProp = util.safeProp(options.root || "default"); + var rootProp = protobuf.util.safeProp(options.root || "default"); var output = [ (options.es6 ? "const" : "var") + " $root = ($protobuf.roots" + rootProp + " || ($protobuf.roots" + rootProp + " = new $protobuf.Root()))\n" ]; if (root.options) { - var optionsJson = util.jsonSafeProp(JSON.stringify(root.options, null, 2)); + var optionsJson = jsonSafeProp(JSON.stringify(root.options, null, 2)); output.push(".setOptions(" + optionsJson + ")\n"); } - var json = util.jsonSafeProp(JSON.stringify(root.nested, null, 2).trim()); + var json = jsonSafeProp(JSON.stringify(root.nested, null, 2).trim()); output.push(".addJSON(" + json + ");"); output = util.wrap(output.join(""), protobuf.util.merge({ dependency: "protobufjs/light" }, options)); process.nextTick(function() { diff --git a/cli/util.js b/cli/util.js index dc6182eff..ffce1ed7e 100644 --- a/cli/util.js +++ b/cli/util.js @@ -181,10 +181,3 @@ exports.pad = function(str, len, l) { return str; }; -exports.jsonSafeProp = function(json) { - return json.replace(/^( +)"(\w+)":/mg, function($0, $1, $2) { - return exports.safeProp($2).charAt(0) === "." - ? $1 + $2 + ":" - : $0; - }); -};