MCPcopy Index your code
hub / github.com/triggerdotdev/jsonhero-web / formatValue

Function formatValue

app/utilities/formatter.ts:33–79  ·  view source on GitHub ↗
(
  type: JSONValueType,
  options?: FormatValueOptions
)

Source from the content-addressed store, hash-verified

31};
32
33export function formatValue(
34 type: JSONValueType,
35 options?: FormatValueOptions
36): string | undefined {
37 switch (type.name) {
38 case "array": {
39 if (options?.leafNodesOnly) {
40 return;
41 }
42
43 if (type.value.length == 0) {
44 return formatRawValue(type);
45 } else if (type.value.length === 1) {
46 return `1 item`;
47 } else {
48 return `${type.value.length} items`;
49 }
50 }
51 case "object": {
52 if (options?.leafNodesOnly) {
53 return;
54 }
55
56 if (Object.keys(type.value).length == 0) {
57 return formatRawValue(type);
58 } else if (Object.keys(type.value).length === 1) {
59 return `1 field`;
60 } else {
61 return `${Object.keys(type.value).length} fields`;
62 }
63 }
64 case "bool": {
65 return type.value ? "true" : "false";
66 }
67 case "float":
68 case "int":
69 return formatNumber(type.value);
70 case "null": {
71 return "null";
72 }
73 case "string":
74 return formatString(type.value, type.format);
75 default:
76 const _exhaustiveCheck: never = type;
77 return _exhaustiveCheck;
78 }
79}
80
81const numberFormatter = new Intl.NumberFormat(undefined, {
82 maximumFractionDigits: 6,

Callers 5

valueFormatterFunction · 0.90
PropertiesFloatFunction · 0.90
PropertiesIntFunction · 0.90
generateChildrenFunction · 0.90
generateChildrenFunction · 0.90

Calls 3

formatRawValueFunction · 0.85
formatNumberFunction · 0.85
formatStringFunction · 0.85

Tested by

no test coverage detected