INNER CODE UNIT · JavaScript

camelToSnake

elys-network/elys · scripts/camel2snake/index.js:5

function camelToSnake(name) {
  return name.replace(/\.?([A-Z]+)/g, (x, y) => "_" + y.toLowerCase()).replace(/^_/, "");
}

// Function to process the content of protobuf files and replace camelCase with snake_case
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

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…