{"version":3,"file":"label.mjs","names":[],"sources":["../src/label.ts"],"sourcesContent":["import type { ParsedField } from \"./types\";\n\n/**\n * Get the best label to use for a field.\n * This will use user-provided labels, descriptions from the schema, or the field key.\n *\n * @param field Parsed field\n * @returns Label for the field\n */\nexport function getLabel(field: ParsedField) {\n  return (\n    field.fieldConfig?.label || field.description || beautifyLabel(field.key)\n  );\n}\n\nfunction beautifyLabel(label: string) {\n  if (!label) {\n    return \"\";\n  }\n\n  let output = label.replace(/([A-Z])/g, \" $1\");\n  output = output.charAt(0).toUpperCase() + output.slice(1);\n\n  // Never return a number for the label\n  // This primarily important for array fields so we don't get \"0\" as a label\n  if (!isNaN(Number(output))) {\n    return \"\";\n  }\n\n  // Ignore labels for arrays of non-objects\n  if (output === \"*\") {\n    return \"\";\n  }\n\n  return output;\n}\n"],"mappings":";;;;;;;;AASA,SAAgB,SAAS,OAAoB;CAC3C,OACE,MAAM,aAAa,SAAS,MAAM,eAAe,cAAc,MAAM,GAAG;AAE5E;AAEA,SAAS,cAAc,OAAe;CACpC,IAAI,CAAC,OACH,OAAO;CAGT,IAAI,SAAS,MAAM,QAAQ,YAAY,KAAK;CAC5C,SAAS,OAAO,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,OAAO,MAAM,CAAC;CAIxD,IAAI,CAAC,MAAM,OAAO,MAAM,CAAC,GACvB,OAAO;CAIT,IAAI,WAAW,KACb,OAAO;CAGT,OAAO;AACT"}