INNER CODE UNIT · JavaScript
processProtobuf
elys-network/elys · scripts/camel2snake/index.js:10
function processProtobuf(content) {
// Use a regex to find lines with fields
const fieldLines = content.match(/^(?!message|})(.*=.*)$/gm);
if (fieldLines) {
fieldLines.forEach(line => {
// Extract the field name (the word before the '=' sign that isn't a type)
const fieldNameMatch = line.match(/\b(\w+)\s*=/);
if (fieldNameMatch) {
const fieldName = fieldNameMatch[1];
// Check if the field name is camelCase
if (/[a-z][A-Z]/.test(fieldName)) {
// Convert the field name to snake_case
const snakeCaseName = camelToSnake(fieldName);
// Replace the field name in the line
content = content.replace(line, line.replace(fieldName, snakeCaseName));
}
}