How to convert PascalCase/CamelCase to underscore_case in JS?

Sep 09, 2022
str
  .replace(/(?:^|\.?)([A-Z0-9])/g, function (x, y) {
    return "*" + y.toLowerCase();
  })
  .replace(/^*/, "");