hooks.js 390 B

123456789101112
  1. export const arr2obj = (data, keyName, valueName) =>
  2. Object.fromEntries(data.map((item) => [item[keyName], item[valueName]]));
  3. export const hump2Underline = (str) =>
  4. str.replace(/([A-Z])/g, "_$1").toLowerCase();
  5. export const underline2Hump = (str) => {
  6. for (let match of str.match(/_(.)/g)) {
  7. str = str.replace(match, match.replace("_", "")).toUpperCase();
  8. }
  9. return str;
  10. };