@malloydata/render 0.0.331 → 0.0.332

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,40 @@
1
+ import { Cell } from '../data_tree';
2
+ import { Tag } from '@malloydata/malloy-tag';
3
+ export interface RenderCellValueOptions {
4
+ /**
5
+ * Value to return for null cells.
6
+ * Defaults to NULL_SYMBOL ('∅').
7
+ */
8
+ nullValue?: string;
9
+ /**
10
+ * Override tag for formatting.
11
+ * Use this when rendering array elements - pass the array field's tag
12
+ * so formatting (currency, percent, etc.) is applied from the array definition.
13
+ * If not provided, uses the cell's own field tag.
14
+ */
15
+ tag?: Tag;
16
+ }
17
+ /**
18
+ * Render a Cell value to a formatted display string.
19
+ *
20
+ * Handles all cell types with appropriate formatting:
21
+ * - Numbers: uses renderNumberCell (handles bigint precision + formatting tags)
22
+ * - Dates: uses renderDateTimeField with isDate: true
23
+ * - Timestamps: uses renderDateTimeField with isDate: false
24
+ * - Strings: returns value directly
25
+ * - Booleans: returns 'true' or 'false'
26
+ * - Null: returns nullValue option (defaults to NULL_SYMBOL)
27
+ *
28
+ * @example
29
+ * // Basic usage (pivot headers, etc.)
30
+ * renderCellValue(cell)
31
+ *
32
+ * @example
33
+ * // Array elements - use array field's tag for formatting
34
+ * renderCellValue(elementCell, { tag: arrayField.tag })
35
+ *
36
+ * @example
37
+ * // Custom null display
38
+ * renderCellValue(cell, { nullValue: '' })
39
+ */
40
+ export declare function renderCellValue(cell: Cell, options?: RenderCellValueOptions): string;
@@ -1,6 +1,17 @@
1
1
  import { RenderTimeStringOptions } from '../util';
2
2
  import { Field, NumberCell } from '../data_tree';
3
- export declare function renderNumericField(f: Field, value: number | null | undefined): string;
3
+ import { Tag } from '@malloydata/malloy-tag';
4
+ /**
5
+ * Renders a numeric field with formatting based on tags.
6
+ *
7
+ * Supports:
8
+ * - Currency shorthand: # currency=usd2m, # currency=eur0k
9
+ * - Currency verbose: # currency { scale=m decimals=2 suffix=finance }
10
+ * - Number shorthand: # number=1k, # number=0m, # number=auto
11
+ * - Number verbose: # number { scale=m decimals=2 suffix=word }
12
+ * - Legacy: # number=big, # currency=euro
13
+ */
14
+ export declare function renderNumericField(f: Field, value: number | null | undefined, tagOverride?: Tag): string;
4
15
  /**
5
16
  * Render a big number value (stored as string for precision).
6
17
  * Used when NumberCell.stringValue is defined (bigint/bigdecimal subtypes).
@@ -9,7 +20,7 @@ export declare function renderNumericField(f: Field, value: number | null | unde
9
20
  * Note: percent, duration, and custom number formats are lossy for values > 2^53
10
21
  * because they require numeric operations. Currency preserves precision.
11
22
  */
12
- export declare function renderBigNumberField(f: Field, value: string | null | undefined): string;
23
+ export declare function renderBigNumberField(f: Field, value: string | null | undefined, tagOverride?: Tag): string;
13
24
  /**
14
25
  * Render a NumberCell for display, automatically handling bigint precision.
15
26
  *
@@ -25,7 +36,8 @@ export declare function renderBigNumberField(f: Field, value: string | null | un
25
36
  * const displayValue = renderNumberCell(cell);
26
37
  *
27
38
  * @param cell - A NumberCell from the data tree
39
+ * @param tagOverride - Optional tag to use for formatting (e.g., for array elements, use the array field's tag)
28
40
  * @returns Formatted string for display, respecting field tags (currency, percent, etc.)
29
41
  */
30
- export declare function renderNumberCell(cell: NumberCell): string;
31
- export declare function renderDateTimeField(f: Field, value: Date | null | undefined, options?: RenderTimeStringOptions): string;
42
+ export declare function renderNumberCell(cell: NumberCell, tagOverride?: Tag): string;
43
+ export declare function renderDateTimeField(f: Field, value: Date | null | undefined, options?: RenderTimeStringOptions, tagOverride?: Tag): string;
@@ -86,14 +86,22 @@ export declare enum Currency {
86
86
  Euros = "euro",
87
87
  Pounds = "pound"
88
88
  }
89
+ export type Scale = 'k' | 'm' | 'b' | 't' | 'q' | 'auto';
90
+ export type SuffixFormat = 'letter' | 'lower' | 'word' | 'short' | 'finance' | 'scientific' | 'none';
89
91
  export interface CurrencyRenderOptions extends TextRenderOptions {
90
92
  currency?: Currency;
93
+ scale?: Scale;
94
+ decimals?: number;
95
+ suffix?: SuffixFormat;
91
96
  }
92
97
  export interface TimeRenderOptions extends TextRenderOptions {
93
98
  time?: Record<string, unknown>;
94
99
  }
95
100
  export interface NumberRenderOptions extends TextRenderOptions {
96
101
  value_format?: string;
102
+ scale?: Scale;
103
+ decimals?: number;
104
+ suffix?: SuffixFormat;
97
105
  }
98
106
  export declare enum DataVolumeUnit {
99
107
  Bytes = "bytes",