Hump underlined (js)

sellerCnt = > seller_cnt
minPriceOne= > min_price_one
as mentioned above, the effect is like this. Change uppercase letters to lowercase, and then add a _ how to encapsulate a function before uppercase letters.
I"ve tried it several times, but it"s not perfect. Let"s be a hand-holding party. I hope to pass the trial.

Aug.07,2021

function underline(str){
  return str.replace(/\B([A-Z])/g, '_$1').toLowerCase()
}

an immature function

function fn (str) {
   if (!str) {
        return str
   }
   
   return str.replace(/[A-Z]/g, (match) => {
     return `_${match.toLowerCase()}`
   })
}

formatUpper(str){
    let myStr = '';
    let myItem = ''
    for (const item of str) {
      myItem = /[A-Z]/.test(item) ? `_${item.toLowerCase()}` : item;
      myStr += myItem;
    }
    return myStr
  }

it is recommended to use the npm package humps . There are many ways to handle this kind of conversion. Please refer to the code below https://www.npmjs.com/package.
for underlining the hump.

It is also available on
  name-styles  
NPM: npm install name-styles

.
Menu