INNER CODE UNIT · JavaScript

fieldLines

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

  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));
        }
      }
    });
  }

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…