@malloydata/render 0.0.434 → 0.0.436
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.
- package/dist/format/index.cjs +1 -0
- package/dist/format/index.mjs +7395 -0
- package/dist/module/component/render-numeric-field.d.ts +2 -2
- package/dist/module/component/tag-configs.d.ts +2 -36
- package/dist/module/format/cell-format.d.ts +74 -0
- package/dist/module/format/index.d.ts +3 -0
- package/dist/module/format/number-format.d.ts +56 -0
- package/dist/module/format/time-format.d.ts +23 -0
- package/dist/module/html/duration.d.ts +3 -5
- package/dist/module/index.mjs +42146 -40862
- package/dist/module/index.umd.js +462 -470
- package/dist/module/util.d.ts +3 -74
- package/femto-config.motly +5 -2
- package/package.json +19 -6
- package/vite.config.format.mts +28 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CellFormatConfig } from '../format/cell-format';
|
|
2
|
+
import { RenderTimeStringOptions } from '../format/time-format';
|
|
2
3
|
import { Field, NumberCell } from '../data_tree';
|
|
3
|
-
import { CellFormatConfig } from './tag-configs';
|
|
4
4
|
/**
|
|
5
5
|
* Renders a numeric field with formatting based on pre-resolved tag config.
|
|
6
6
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Field } from '../data_tree';
|
|
2
|
-
import {
|
|
2
|
+
import { CellFormatConfig } from '../format/cell-format';
|
|
3
3
|
export interface ImageTagConfig {
|
|
4
4
|
width?: string;
|
|
5
5
|
height?: string;
|
|
@@ -16,41 +16,7 @@ export interface ListTagConfig {
|
|
|
16
16
|
isListDetail: boolean;
|
|
17
17
|
}
|
|
18
18
|
export declare function resolveListTags(field: Field): ListTagConfig;
|
|
19
|
-
export
|
|
20
|
-
symbol: string;
|
|
21
|
-
scale?: ScaleKey | 'auto';
|
|
22
|
-
decimals?: number;
|
|
23
|
-
suffixFormat: SuffixFormatKey;
|
|
24
|
-
}
|
|
25
|
-
export interface NumberConfig {
|
|
26
|
-
formatString?: string;
|
|
27
|
-
scale?: ScaleKey | 'auto';
|
|
28
|
-
decimals?: number;
|
|
29
|
-
suffixFormat?: SuffixFormatKey;
|
|
30
|
-
isId?: boolean;
|
|
31
|
-
isBig?: boolean;
|
|
32
|
-
}
|
|
33
|
-
export interface DurationConfig {
|
|
34
|
-
unit: string;
|
|
35
|
-
terse: boolean;
|
|
36
|
-
}
|
|
37
|
-
export type CellFormatConfig = {
|
|
38
|
-
mode: 'currency';
|
|
39
|
-
currency: CurrencyConfig;
|
|
40
|
-
} | {
|
|
41
|
-
mode: 'percent';
|
|
42
|
-
} | {
|
|
43
|
-
mode: 'duration';
|
|
44
|
-
duration: DurationConfig;
|
|
45
|
-
} | {
|
|
46
|
-
mode: 'number';
|
|
47
|
-
number: NumberConfig;
|
|
48
|
-
} | {
|
|
49
|
-
mode: 'dateFormat';
|
|
50
|
-
formatString: string;
|
|
51
|
-
} | {
|
|
52
|
-
mode: 'default';
|
|
53
|
-
};
|
|
19
|
+
export type { CellFormatConfig, CurrencyConfig, DurationConfig, NumberConfig, } from '../format/cell-format';
|
|
54
20
|
export declare function resolveCellFormatTags(field: Field): CellFormatConfig;
|
|
55
21
|
export interface ColumnTagConfig {
|
|
56
22
|
width: number | null;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Tag } from '@malloydata/malloy-tag';
|
|
2
|
+
import { ScaleKey, SuffixFormatKey } from './number-format';
|
|
3
|
+
import { RenderTimeStringOptions } from './time-format';
|
|
4
|
+
export declare const NULL_SYMBOL = "\u2205";
|
|
5
|
+
export interface CurrencyConfig {
|
|
6
|
+
symbol: string;
|
|
7
|
+
scale?: ScaleKey | 'auto';
|
|
8
|
+
decimals?: number;
|
|
9
|
+
suffixFormat: SuffixFormatKey;
|
|
10
|
+
}
|
|
11
|
+
export interface NumberConfig {
|
|
12
|
+
formatString?: string;
|
|
13
|
+
scale?: ScaleKey | 'auto';
|
|
14
|
+
decimals?: number;
|
|
15
|
+
suffixFormat?: SuffixFormatKey;
|
|
16
|
+
isId?: boolean;
|
|
17
|
+
isBig?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface DurationConfig {
|
|
20
|
+
unit: string;
|
|
21
|
+
terse: boolean;
|
|
22
|
+
}
|
|
23
|
+
/** A resolved cell format. Plain data: safe to serialize and pass around. */
|
|
24
|
+
export type CellFormatConfig = {
|
|
25
|
+
mode: 'currency';
|
|
26
|
+
currency: CurrencyConfig;
|
|
27
|
+
} | {
|
|
28
|
+
mode: 'percent';
|
|
29
|
+
} | {
|
|
30
|
+
mode: 'duration';
|
|
31
|
+
duration: DurationConfig;
|
|
32
|
+
} | {
|
|
33
|
+
mode: 'number';
|
|
34
|
+
number: NumberConfig;
|
|
35
|
+
} | {
|
|
36
|
+
mode: 'dateFormat';
|
|
37
|
+
formatString: string;
|
|
38
|
+
} | {
|
|
39
|
+
mode: 'default';
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Resolve a field's tag to its cell format. `isTime` says the field is a date
|
|
43
|
+
* or timestamp, where `# number="…"` is a date pattern rather than a number
|
|
44
|
+
* one.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* resolveCellFormat(tagOf('# currency=usd0k'), {isTime: false})
|
|
48
|
+
* // {mode: 'currency', currency: {symbol: '$', scale: 'k', decimals: 0, …}}
|
|
49
|
+
*/
|
|
50
|
+
export declare function resolveCellFormat(tag: Tag, options?: {
|
|
51
|
+
isTime?: boolean;
|
|
52
|
+
}): CellFormatConfig;
|
|
53
|
+
/**
|
|
54
|
+
* Format one number for display.
|
|
55
|
+
*
|
|
56
|
+
* `value` may be a string of digits: that is how the stable API carries a
|
|
57
|
+
* bigint or big decimal exactly, and it is formatted without passing through a
|
|
58
|
+
* JS number wherever the format allows.
|
|
59
|
+
*/
|
|
60
|
+
export declare function formatNumber(value: number | string | null | undefined, config?: CellFormatConfig): string;
|
|
61
|
+
export interface FormatDateTimeOptions extends RenderTimeStringOptions {
|
|
62
|
+
/** Named in the warning when the field's date pattern is invalid. */
|
|
63
|
+
fieldName?: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Format one date or timestamp for display. A `# number="…"` date pattern
|
|
67
|
+
* wins; otherwise the value prints at its `timeframe`'s grain.
|
|
68
|
+
*
|
|
69
|
+
* Either way a timestamp reads in `timezone` (the query's, from
|
|
70
|
+
* `query_timezone` in the result) and otherwise in UTC; a date (`isDate`) is
|
|
71
|
+
* always its UTC calendar day. Never the host's zone, so a server and a
|
|
72
|
+
* browser print the same value the same way.
|
|
73
|
+
*/
|
|
74
|
+
export declare function formatDateTime(value: Date | null | undefined, config?: CellFormatConfig, options?: FormatDateTimeOptions): string;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { NULL_SYMBOL, formatDateTime, formatNumber, resolveCellFormat, type CellFormatConfig, type CurrencyConfig, type DurationConfig, type FormatDateTimeOptions, type NumberConfig, } from './cell-format';
|
|
2
|
+
export { formatScaledNumber, type FormatScaledNumberOptions, type ScaleKey, type SuffixFormatKey, } from './number-format';
|
|
3
|
+
export { formatDuration, renderTimeString, type RenderTimeStringOptions, } from './time-format';
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export declare function formatBigNumber(value: number): string;
|
|
2
|
+
export type ScaleKey = 'k' | 'm' | 'b' | 't' | 'q';
|
|
3
|
+
export type SuffixFormatKey = 'letter' | 'lower' | 'word' | 'short' | 'finance' | 'scientific' | 'none';
|
|
4
|
+
export interface FormatScaledNumberOptions {
|
|
5
|
+
scale?: ScaleKey | 'auto';
|
|
6
|
+
decimals?: number;
|
|
7
|
+
suffix?: SuffixFormatKey;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Formats a number with scaling and suffix options.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* formatScaledNumber(1234567, { scale: 'm', decimals: 1 }) // "1.2m"
|
|
14
|
+
* formatScaledNumber(1234567, { scale: 'auto' }) // "1.2m"
|
|
15
|
+
* formatScaledNumber(1234567, { scale: 'm', suffix: 'word' }) // "1.2 Million"
|
|
16
|
+
*/
|
|
17
|
+
export declare function formatScaledNumber(value: number, options?: FormatScaledNumberOptions): string;
|
|
18
|
+
export interface ParsedNumberFormat {
|
|
19
|
+
decimals?: number;
|
|
20
|
+
scale?: ScaleKey | 'auto';
|
|
21
|
+
isId?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface ParsedCurrencyFormat extends ParsedNumberFormat {
|
|
24
|
+
currency: string;
|
|
25
|
+
symbol: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Parses a number shorthand format string.
|
|
29
|
+
* Pattern: {decimals}{scale} or "auto" or "id"
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* parseNumberShorthand("1k") // { decimals: 1, scale: 'k' }
|
|
33
|
+
* parseNumberShorthand("0m") // { decimals: 0, scale: 'm' }
|
|
34
|
+
* parseNumberShorthand("2") // { decimals: 2 }
|
|
35
|
+
* parseNumberShorthand("auto") // { scale: 'auto' }
|
|
36
|
+
* parseNumberShorthand("id") // { isId: true }
|
|
37
|
+
*
|
|
38
|
+
* Note: "big" is NOT handled here - it's a legacy format handled separately
|
|
39
|
+
* in renderNumberField to preserve backward compatibility with formatBigNumber.
|
|
40
|
+
*/
|
|
41
|
+
export declare function parseNumberShorthand(format: string): ParsedNumberFormat | null;
|
|
42
|
+
/**
|
|
43
|
+
* Parses a currency shorthand format string.
|
|
44
|
+
* Pattern: {currency}{decimals}{scale} e.g., "usd2m", "eur0k", "gbp1b"
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* parseCurrencyShorthand("usd2m") // { currency: 'usd', symbol: '$', decimals: 2, scale: 'm' }
|
|
48
|
+
* parseCurrencyShorthand("eur0k") // { currency: 'eur', symbol: '€', decimals: 0, scale: 'k' }
|
|
49
|
+
* parseCurrencyShorthand("usd") // { currency: 'usd', symbol: '$' }
|
|
50
|
+
*/
|
|
51
|
+
export declare function parseCurrencyShorthand(format: string): ParsedCurrencyFormat | null;
|
|
52
|
+
/**
|
|
53
|
+
* Normalizes a scale value to a ScaleKey.
|
|
54
|
+
* Supports single-letter scales: k, m, b, t, q, auto.
|
|
55
|
+
*/
|
|
56
|
+
export declare function normalizeScale(scale: string | undefined): ScaleKey | 'auto' | undefined;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DurationUnit } from '../html/data_styles';
|
|
2
|
+
export declare function formatTimeUnit(value: number, unit: DurationUnit, options?: {
|
|
3
|
+
numFormat?: string;
|
|
4
|
+
terse?: boolean;
|
|
5
|
+
}): string;
|
|
6
|
+
/**
|
|
7
|
+
* A duration in `options.durationUnit` (seconds by default) as its two largest
|
|
8
|
+
* nonzero parts, e.g. 3725 → "1 hour 2 minutes"; `terse` → "1h 2m".
|
|
9
|
+
* `numFormat` is an ssf pattern for each part's number (the legacy renderer
|
|
10
|
+
* passes `# number` here).
|
|
11
|
+
*/
|
|
12
|
+
export declare function formatDuration(value: number, options: {
|
|
13
|
+
durationUnit?: string;
|
|
14
|
+
terse?: boolean;
|
|
15
|
+
numFormat?: string;
|
|
16
|
+
}): string;
|
|
17
|
+
export interface RenderTimeStringOptions {
|
|
18
|
+
isDate?: boolean;
|
|
19
|
+
timeframe?: string;
|
|
20
|
+
extractFormat?: 'month-day' | 'quarter' | 'month' | 'week' | 'day';
|
|
21
|
+
timezone?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function renderTimeString(value: Date, options?: RenderTimeStringOptions): string;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { HTMLTextRenderer } from './text';
|
|
2
|
-
import { DurationRenderOptions, StyleDefaults
|
|
2
|
+
import { DurationRenderOptions, StyleDefaults } from './data_styles';
|
|
3
3
|
import { RendererOptions } from './renderer_types';
|
|
4
4
|
import { Renderer } from './renderer';
|
|
5
5
|
import { RendererFactory } from './renderer_factory';
|
|
6
6
|
import { Cell, Field } from '../data_tree';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
terse?: boolean;
|
|
10
|
-
}): string;
|
|
7
|
+
/** The legacy renderer's duration text: ../format's, with the field's
|
|
8
|
+
`# number` pattern applied to each part and its `# duration.terse`. */
|
|
11
9
|
export declare function getText(field: Field, value: number, options: {
|
|
12
10
|
durationUnit?: string;
|
|
13
11
|
}): string | null;
|