export function underscoreToCamelcase(obj){
  if (Array.isArray(obj)) {
    return obj.map((item) => underscoreToCamelcase(item)) 
  }
  if (typeof obj !== 'object' || obj === null || obj === undefined) {
    return obj;
  }
  const ret = {};
  for (const key in obj) {
    if (obj.hasOwnProperty && !obj.hasOwnProperty(key)) {
      continue;
    }
    const newKey = key.replace(/_([a-z])/g, (m) => m[1].toUpperCase());
    ret[newKey] = underscoreToCamelcase(obj[key]);
  }
  return ret 
}

export function camelcaseToUnderscore(obj) {
  if (Array.isArray(obj)) {
    return obj.map((item) => camelcaseToUnderscore(item))
  }
  if (typeof obj !== 'object' || obj === null || obj === undefined) {
    return obj;
  }
  const ret= {};
  for (const key in obj) {
    if (obj.hasOwnProperty && !obj.hasOwnProperty(key)) {
      continue;
    }
    const newKey = key.replace(/([a-z][A-Z])/g, (m) => m[0] + '_' + m[1].toLowerCase());
    ret[newKey] = camelcaseToUnderscore(obj[key]);
  }
  return ret
}
