@gravionlabs/helix-ag-grid 22.1.2 → 22.1.4
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.
|
@@ -1,249 +1,98 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AG Grid `cellStyle` callback that right-aligns numeric cells and colours
|
|
3
|
-
* truthy (non-zero, non-null, non-undefined) values with the helix success
|
|
4
|
-
* colour (`--h-green-500`).
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* columnDefs = [{ field: 'amount', cellStyle: numberCellStyle }];
|
|
9
|
-
* ```
|
|
10
|
-
*/
|
|
11
1
|
function numberCellStyle(params) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
return params.value ? {
|
|
3
|
+
textAlign: "right",
|
|
4
|
+
color: "var(--h-green-500)"
|
|
5
|
+
} : { textAlign: "right" };
|
|
15
6
|
}
|
|
16
|
-
|
|
17
|
-
// ── Number formatters ──────────────────────────────────────────────────────
|
|
18
|
-
/**
|
|
19
|
-
* Formats a numeric cell value using the system locale (`toLocaleString`).
|
|
20
|
-
* Returns `''` for `null`, `undefined`, or `NaN`.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```ts
|
|
24
|
-
* { field: 'amount', valueFormatter: numberFormatter }
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
7
|
function numberFormatter(params) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return v.toLocaleString();
|
|
8
|
+
const v = params.value;
|
|
9
|
+
if (v == null || Number.isNaN(v)) return "";
|
|
10
|
+
return v.toLocaleString();
|
|
32
11
|
}
|
|
33
|
-
/**
|
|
34
|
-
* Returns the raw string representation of a number without any locale
|
|
35
|
-
* formatting. Returns `''` for `null` or `undefined`.
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```ts
|
|
39
|
-
* { field: 'id', valueFormatter: rawNumberFormatter }
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
12
|
function rawNumberFormatter(params) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return v.toString();
|
|
13
|
+
const v = params.value;
|
|
14
|
+
if (v == null) return "";
|
|
15
|
+
return v.toString();
|
|
47
16
|
}
|
|
48
|
-
/**
|
|
49
|
-
* Formats a number using a caller-supplied `Intl.NumberFormat` instance,
|
|
50
|
-
* allowing full control over locale, currency, fraction digits, etc.
|
|
51
|
-
* Returns `''` for `null` or `undefined`.
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```ts
|
|
55
|
-
* const fmt = new Intl.NumberFormat('de-DE', { minimumFractionDigits: 2 });
|
|
56
|
-
* { field: 'price', valueFormatter: (p) => intlNumberFormatter(p, fmt) }
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
17
|
function intlNumberFormatter(params, numberFormat) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return numberFormat.format(v);
|
|
18
|
+
const v = params.value;
|
|
19
|
+
if (v == null || Number.isNaN(v)) return "";
|
|
20
|
+
return numberFormat.format(v);
|
|
64
21
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
*/
|
|
76
|
-
function currencyFormatter(currencyCode = 'EUR', locale = 'de-DE') {
|
|
77
|
-
const fmt = new Intl.NumberFormat(locale, { style: 'currency', currency: currencyCode });
|
|
78
|
-
return (params) => {
|
|
79
|
-
const v = params.value;
|
|
80
|
-
if (v == null || Number.isNaN(v))
|
|
81
|
-
return '';
|
|
82
|
-
return fmt.format(v);
|
|
83
|
-
};
|
|
22
|
+
function currencyFormatter(currencyCode = "EUR", locale = "de-DE") {
|
|
23
|
+
const fmt = new Intl.NumberFormat(locale, {
|
|
24
|
+
style: "currency",
|
|
25
|
+
currency: currencyCode
|
|
26
|
+
});
|
|
27
|
+
return (params) => {
|
|
28
|
+
const v = params.value;
|
|
29
|
+
if (v == null || Number.isNaN(v)) return "";
|
|
30
|
+
return fmt.format(v);
|
|
31
|
+
};
|
|
84
32
|
}
|
|
85
33
|
function toDate(value) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return Number.isNaN(d.getTime()) ? null : d;
|
|
34
|
+
if (value == null) return null;
|
|
35
|
+
const d = value instanceof Date ? value : new Date(value);
|
|
36
|
+
return Number.isNaN(d.getTime()) ? null : d;
|
|
90
37
|
}
|
|
91
|
-
const cetDateFormat = new Intl.DateTimeFormat(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
38
|
+
const cetDateFormat = new Intl.DateTimeFormat("de-DE", {
|
|
39
|
+
timeZone: "Europe/Berlin",
|
|
40
|
+
day: "2-digit",
|
|
41
|
+
month: "2-digit",
|
|
42
|
+
year: "numeric"
|
|
96
43
|
});
|
|
97
|
-
const cetDateTimeFormat = new Intl.DateTimeFormat(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
44
|
+
const cetDateTimeFormat = new Intl.DateTimeFormat("de-DE", {
|
|
45
|
+
timeZone: "Europe/Berlin",
|
|
46
|
+
day: "2-digit",
|
|
47
|
+
month: "2-digit",
|
|
48
|
+
year: "numeric",
|
|
49
|
+
hour: "2-digit",
|
|
50
|
+
minute: "2-digit",
|
|
51
|
+
second: "2-digit",
|
|
52
|
+
hour12: false
|
|
106
53
|
});
|
|
107
|
-
const cetTimeFormat = new Intl.DateTimeFormat(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
54
|
+
const cetTimeFormat = new Intl.DateTimeFormat("de-DE", {
|
|
55
|
+
timeZone: "Europe/Berlin",
|
|
56
|
+
hour: "2-digit",
|
|
57
|
+
minute: "2-digit",
|
|
58
|
+
hour12: false
|
|
112
59
|
});
|
|
113
|
-
/**
|
|
114
|
-
* Formats a `Date` or ISO string as a CET date: `'15.06.2024'`.
|
|
115
|
-
* Returns `''` for `null`, `undefined`, or invalid dates.
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* ```ts
|
|
119
|
-
* { field: 'date', valueFormatter: cetDateFormatter }
|
|
120
|
-
* ```
|
|
121
|
-
*/
|
|
122
60
|
function cetDateFormatter(params) {
|
|
123
|
-
|
|
124
|
-
|
|
61
|
+
const d = toDate(params.value);
|
|
62
|
+
return d ? cetDateFormat.format(d) : "";
|
|
125
63
|
}
|
|
126
|
-
/**
|
|
127
|
-
* Formats a `Date` or ISO string as a CET date-time: `'15.06.2024 12:30:00'`.
|
|
128
|
-
* Returns `''` for `null`, `undefined`, or invalid dates.
|
|
129
|
-
*
|
|
130
|
-
* @example
|
|
131
|
-
* ```ts
|
|
132
|
-
* { field: 'updatedAt', valueFormatter: cetDateTimeFormatter }
|
|
133
|
-
* ```
|
|
134
|
-
*/
|
|
135
64
|
function cetDateTimeFormatter(params) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
// Intl formats date and time parts separated by ', ' in de-DE — replace with ' '
|
|
140
|
-
return cetDateTimeFormat.format(d).replace(', ', ' ');
|
|
65
|
+
const d = toDate(params.value);
|
|
66
|
+
if (!d) return "";
|
|
67
|
+
return cetDateTimeFormat.format(d).replace(", ", " ");
|
|
141
68
|
}
|
|
142
|
-
/**
|
|
143
|
-
* Formats a `Date` or ISO string as a CET time: `'12:30'`.
|
|
144
|
-
* Returns `''` for `null`, `undefined`, or invalid dates.
|
|
145
|
-
*
|
|
146
|
-
* @example
|
|
147
|
-
* ```ts
|
|
148
|
-
* { field: 'startTime', valueFormatter: cetTimeFormatter }
|
|
149
|
-
* ```
|
|
150
|
-
*/
|
|
151
69
|
function cetTimeFormatter(params) {
|
|
152
|
-
|
|
153
|
-
|
|
70
|
+
const d = toDate(params.value);
|
|
71
|
+
return d ? cetTimeFormat.format(d) : "";
|
|
154
72
|
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Validates a number against optional `min`/`max` bounds.
|
|
158
|
-
* Returns `null` if the value is `null`, `undefined`, `NaN`, or out of bounds.
|
|
159
|
-
*
|
|
160
|
-
* @example
|
|
161
|
-
* ```ts
|
|
162
|
-
* coerceValue(5, { min: 0, max: 10 }) // → 5
|
|
163
|
-
* coerceValue(15, { max: 10 }) // → null
|
|
164
|
-
* coerceValue(null) // → null
|
|
165
|
-
* ```
|
|
166
|
-
*/
|
|
167
73
|
function coerceValue(value, options) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
if (options?.max != null && value > options.max)
|
|
173
|
-
return null;
|
|
174
|
-
return value;
|
|
74
|
+
if (value == null || Number.isNaN(value)) return null;
|
|
75
|
+
if (options?.min != null && value < options.min) return null;
|
|
76
|
+
if (options?.max != null && value > options.max) return null;
|
|
77
|
+
return value;
|
|
175
78
|
}
|
|
176
|
-
/**
|
|
177
|
-
* Locale-aware string-to-number parser.
|
|
178
|
-
* Handles thousand separators and decimal commas for the given locale.
|
|
179
|
-
* Returns `null` for empty, `null`, or `undefined` input.
|
|
180
|
-
*
|
|
181
|
-
* @example
|
|
182
|
-
* ```ts
|
|
183
|
-
* parseNumber('1.234,56', 'de-DE') // → 1234.56
|
|
184
|
-
* parseNumber('1,234.56', 'en-US') // → 1234.56
|
|
185
|
-
* ```
|
|
186
|
-
*/
|
|
187
79
|
function parseNumber(value, locale, options) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const normalised = value.trim().replaceAll(group, '').replace(decimal, '.');
|
|
195
|
-
const n = Number.parseFloat(normalised);
|
|
196
|
-
return coerceValue(n, options);
|
|
80
|
+
if (value == null || value.trim() === "") return null;
|
|
81
|
+
const parts = new Intl.NumberFormat(locale).formatToParts(1234.5);
|
|
82
|
+
const group = parts.find((p) => p.type === "group")?.value ?? "";
|
|
83
|
+
const decimal = parts.find((p) => p.type === "decimal")?.value ?? ".";
|
|
84
|
+
const normalised = value.trim().replaceAll(group, "").replace(decimal, ".");
|
|
85
|
+
return coerceValue(Number.parseFloat(normalised), options);
|
|
197
86
|
}
|
|
198
|
-
/**
|
|
199
|
-
* Smart string-to-number parser that detects the decimal separator
|
|
200
|
-
* automatically:
|
|
201
|
-
* - Strings containing a comma (e.g. `'1.234,56'` from spreadsheet paste)
|
|
202
|
-
* are parsed as German locale (`de-DE`).
|
|
203
|
-
* - All other strings (e.g. `'3.14'` from keyboard input) are parsed with
|
|
204
|
-
* `parseFloat`.
|
|
205
|
-
*
|
|
206
|
-
* Returns `null` for empty, `null`, or `undefined` input.
|
|
207
|
-
*
|
|
208
|
-
* @example
|
|
209
|
-
* ```ts
|
|
210
|
-
* parseNumberValue('42') // → 42
|
|
211
|
-
* parseNumberValue('3.14') // → 3.14
|
|
212
|
-
* parseNumberValue('1.234,56') // → 1234.56 (German paste)
|
|
213
|
-
* parseNumberValue(null) // → null
|
|
214
|
-
* parseNumberValue('5', { min: 10 }) // → null (out of bounds)
|
|
215
|
-
* ```
|
|
216
|
-
*/
|
|
217
87
|
function parseNumberValue(value, options) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if (hasComma) {
|
|
222
|
-
return parseNumber(value, 'de-DE', options);
|
|
223
|
-
}
|
|
224
|
-
const n = Number.parseFloat(value.trim());
|
|
225
|
-
return coerceValue(n, options);
|
|
88
|
+
if (value == null || value.trim() === "") return null;
|
|
89
|
+
if (value.includes(",")) return parseNumber(value, "de-DE", options);
|
|
90
|
+
return coerceValue(Number.parseFloat(value.trim()), options);
|
|
226
91
|
}
|
|
227
|
-
/**
|
|
228
|
-
* AG Grid `valueParser` adapter — wraps `parseNumberValue` to read
|
|
229
|
-
* `params.newValue`. Drop-in for any editable numeric column.
|
|
230
|
-
*
|
|
231
|
-
* @example
|
|
232
|
-
* ```ts
|
|
233
|
-
* { field: 'quantity', editable: true, valueParser: numberValueParser }
|
|
234
|
-
* // or with bounds:
|
|
235
|
-
* { field: 'pct', editable: true, valueParser: (p) => numberValueParser(p, { min: 0, max: 100 }) }
|
|
236
|
-
* ```
|
|
237
|
-
*/
|
|
238
92
|
function numberValueParser(params, options) {
|
|
239
|
-
|
|
93
|
+
return parseNumberValue(params.newValue, options);
|
|
240
94
|
}
|
|
241
|
-
|
|
242
|
-
const HELIX_AG_GRID_VERSION = '0.1.0';
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Generated bundle index. Do not edit.
|
|
246
|
-
*/
|
|
247
|
-
|
|
95
|
+
const HELIX_AG_GRID_VERSION = "0.1.0";
|
|
248
96
|
export { HELIX_AG_GRID_VERSION, cetDateFormatter, cetDateTimeFormatter, cetTimeFormatter, coerceValue, currencyFormatter, intlNumberFormatter, numberCellStyle, numberFormatter, numberValueParser, parseNumber, parseNumberValue, rawNumberFormatter };
|
|
249
|
-
|
|
97
|
+
|
|
98
|
+
//# sourceMappingURL=gravionlabs-helix-ag-grid.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gravionlabs-helix-ag-grid.mjs","sources":["../../../projects/ag-grid/src/lib/cell-styles/cell-styles.ts","../../../projects/ag-grid/src/lib/formatters/ag-grid-formatters.ts","../../../projects/ag-grid/src/lib/parsers/number-parsers.ts","../../../projects/ag-grid/src/public-api.ts","../../../projects/ag-grid/src/gravionlabs-helix-ag-grid.ts"],"sourcesContent":["import type { CellClassParams, CellStyle } from 'ag-grid-community';\n\n/**\n * AG Grid `cellStyle` callback that right-aligns numeric cells and colours\n * truthy (non-zero, non-null, non-undefined) values with the helix success\n * colour (`--h-green-500`).\n *\n * @example\n * ```ts\n * columnDefs = [{ field: 'amount', cellStyle: numberCellStyle }];\n * ```\n */\nexport function numberCellStyle(params: CellClassParams): CellStyle {\n return params.value\n ? { textAlign: 'right', color: 'var(--h-green-500)' }\n : { textAlign: 'right' };\n}\n","import type { ValueFormatterParams } from 'ag-grid-community';\n\n/** Type alias for AG Grid's `ValueFormatterParams`, used by all formatter functions. */\nexport type AgGridFormatterParams<TData = unknown, TValue = unknown> = ValueFormatterParams<\n TData,\n TValue\n>;\n\n// ── Number formatters ──────────────────────────────────────────────────────\n\n/**\n * Formats a numeric cell value using the system locale (`toLocaleString`).\n * Returns `''` for `null`, `undefined`, or `NaN`.\n *\n * @example\n * ```ts\n * { field: 'amount', valueFormatter: numberFormatter }\n * ```\n */\nexport function numberFormatter(\n params: AgGridFormatterParams<unknown, number | null | undefined>,\n): string {\n const v = params.value;\n if (v == null || Number.isNaN(v)) return '';\n return v.toLocaleString();\n}\n\n/**\n * Returns the raw string representation of a number without any locale\n * formatting. Returns `''` for `null` or `undefined`.\n *\n * @example\n * ```ts\n * { field: 'id', valueFormatter: rawNumberFormatter }\n * ```\n */\nexport function rawNumberFormatter(\n params: AgGridFormatterParams<unknown, number | null | undefined>,\n): string {\n const v = params.value;\n if (v == null) return '';\n return v.toString();\n}\n\n/**\n * Formats a number using a caller-supplied `Intl.NumberFormat` instance,\n * allowing full control over locale, currency, fraction digits, etc.\n * Returns `''` for `null` or `undefined`.\n *\n * @example\n * ```ts\n * const fmt = new Intl.NumberFormat('de-DE', { minimumFractionDigits: 2 });\n * { field: 'price', valueFormatter: (p) => intlNumberFormatter(p, fmt) }\n * ```\n */\nexport function intlNumberFormatter(\n params: AgGridFormatterParams<unknown, number | null | undefined>,\n numberFormat: Intl.NumberFormat,\n): string {\n const v = params.value;\n if (v == null || Number.isNaN(v)) return '';\n return numberFormat.format(v);\n}\n\n/**\n * Factory that returns a currency formatter closure using `Intl.NumberFormat`\n * with `style: 'currency'`. Defaults to EUR / de-DE.\n * Returns `''` for `null`, `undefined`, or `NaN`.\n *\n * @example\n * ```ts\n * { field: 'revenue', valueFormatter: currencyFormatter() } // '1.234,50 €'\n * { field: 'price', valueFormatter: currencyFormatter('USD','en-US') } // '$99.90'\n * ```\n */\nexport function currencyFormatter(\n currencyCode = 'EUR',\n locale = 'de-DE',\n): (params: AgGridFormatterParams<unknown, number | null | undefined>) => string {\n const fmt = new Intl.NumberFormat(locale, { style: 'currency', currency: currencyCode });\n return (params) => {\n const v = params.value;\n if (v == null || Number.isNaN(v)) return '';\n return fmt.format(v);\n };\n}\n\n// ── CET date formatters ────────────────────────────────────────────────────\n\ntype DateInput = Date | string | null | undefined;\n\nfunction toDate(value: DateInput): Date | null {\n if (value == null) return null;\n const d = value instanceof Date ? value : new Date(value);\n return Number.isNaN(d.getTime()) ? null : d;\n}\n\nconst cetDateFormat = new Intl.DateTimeFormat('de-DE', {\n timeZone: 'Europe/Berlin',\n day: '2-digit',\n month: '2-digit',\n year: 'numeric',\n});\n\nconst cetDateTimeFormat = new Intl.DateTimeFormat('de-DE', {\n timeZone: 'Europe/Berlin',\n day: '2-digit',\n month: '2-digit',\n year: 'numeric',\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit',\n hour12: false,\n});\n\nconst cetTimeFormat = new Intl.DateTimeFormat('de-DE', {\n timeZone: 'Europe/Berlin',\n hour: '2-digit',\n minute: '2-digit',\n hour12: false,\n});\n\n/**\n * Formats a `Date` or ISO string as a CET date: `'15.06.2024'`.\n * Returns `''` for `null`, `undefined`, or invalid dates.\n *\n * @example\n * ```ts\n * { field: 'date', valueFormatter: cetDateFormatter }\n * ```\n */\nexport function cetDateFormatter(params: AgGridFormatterParams<unknown, DateInput>): string {\n const d = toDate(params.value);\n return d ? cetDateFormat.format(d) : '';\n}\n\n/**\n * Formats a `Date` or ISO string as a CET date-time: `'15.06.2024 12:30:00'`.\n * Returns `''` for `null`, `undefined`, or invalid dates.\n *\n * @example\n * ```ts\n * { field: 'updatedAt', valueFormatter: cetDateTimeFormatter }\n * ```\n */\nexport function cetDateTimeFormatter(params: AgGridFormatterParams<unknown, DateInput>): string {\n const d = toDate(params.value);\n if (!d) return '';\n // Intl formats date and time parts separated by ', ' in de-DE — replace with ' '\n return cetDateTimeFormat.format(d).replace(', ', ' ');\n}\n\n/**\n * Formats a `Date` or ISO string as a CET time: `'12:30'`.\n * Returns `''` for `null`, `undefined`, or invalid dates.\n *\n * @example\n * ```ts\n * { field: 'startTime', valueFormatter: cetTimeFormatter }\n * ```\n */\nexport function cetTimeFormatter(params: AgGridFormatterParams<unknown, DateInput>): string {\n const d = toDate(params.value);\n return d ? cetTimeFormat.format(d) : '';\n}\n","import type { ValueParserParams } from 'ag-grid-community';\n\n/** Bounds for number validation. */\nexport interface ParseNumberOptions {\n min?: number;\n max?: number;\n}\n\n/**\n * Validates a number against optional `min`/`max` bounds.\n * Returns `null` if the value is `null`, `undefined`, `NaN`, or out of bounds.\n *\n * @example\n * ```ts\n * coerceValue(5, { min: 0, max: 10 }) // → 5\n * coerceValue(15, { max: 10 }) // → null\n * coerceValue(null) // → null\n * ```\n */\nexport function coerceValue(\n value: number | null | undefined,\n options?: ParseNumberOptions,\n): number | null {\n if (value == null || Number.isNaN(value)) return null;\n if (options?.min != null && value < options.min) return null;\n if (options?.max != null && value > options.max) return null;\n return value;\n}\n\n/**\n * Locale-aware string-to-number parser.\n * Handles thousand separators and decimal commas for the given locale.\n * Returns `null` for empty, `null`, or `undefined` input.\n *\n * @example\n * ```ts\n * parseNumber('1.234,56', 'de-DE') // → 1234.56\n * parseNumber('1,234.56', 'en-US') // → 1234.56\n * ```\n */\nexport function parseNumber(\n value: string | null | undefined,\n locale: string,\n options?: ParseNumberOptions,\n): number | null {\n if (value == null || value.trim() === '') return null;\n\n // Derive separators from the locale\n const parts = new Intl.NumberFormat(locale).formatToParts(1234.5);\n const group = parts.find((p) => p.type === 'group')?.value ?? '';\n const decimal = parts.find((p) => p.type === 'decimal')?.value ?? '.';\n\n const normalised = value.trim().replaceAll(group, '').replace(decimal, '.');\n\n const n = Number.parseFloat(normalised);\n return coerceValue(n, options);\n}\n\n/**\n * Smart string-to-number parser that detects the decimal separator\n * automatically:\n * - Strings containing a comma (e.g. `'1.234,56'` from spreadsheet paste)\n * are parsed as German locale (`de-DE`).\n * - All other strings (e.g. `'3.14'` from keyboard input) are parsed with\n * `parseFloat`.\n *\n * Returns `null` for empty, `null`, or `undefined` input.\n *\n * @example\n * ```ts\n * parseNumberValue('42') // → 42\n * parseNumberValue('3.14') // → 3.14\n * parseNumberValue('1.234,56') // → 1234.56 (German paste)\n * parseNumberValue(null) // → null\n * parseNumberValue('5', { min: 10 }) // → null (out of bounds)\n * ```\n */\nexport function parseNumberValue(\n value: string | null | undefined,\n options?: ParseNumberOptions,\n): number | null {\n if (value == null || value.trim() === '') return null;\n\n const hasComma = value.includes(',');\n if (hasComma) {\n return parseNumber(value, 'de-DE', options);\n }\n\n const n = Number.parseFloat(value.trim());\n return coerceValue(n, options);\n}\n\n/**\n * AG Grid `valueParser` adapter — wraps `parseNumberValue` to read\n * `params.newValue`. Drop-in for any editable numeric column.\n *\n * @example\n * ```ts\n * { field: 'quantity', editable: true, valueParser: numberValueParser }\n * // or with bounds:\n * { field: 'pct', editable: true, valueParser: (p) => numberValueParser(p, { min: 0, max: 100 }) }\n * ```\n */\nexport function numberValueParser(\n params: ValueParserParams,\n options?: ParseNumberOptions,\n): number | null {\n return parseNumberValue(params.newValue as string | null | undefined, options);\n}\n","export const HELIX_AG_GRID_VERSION = '0.1.0';\n\nexport { numberCellStyle } from './lib/cell-styles/cell-styles';\n\nexport type { AgGridFormatterParams } from './lib/formatters/ag-grid-formatters';\nexport {\n cetDateFormatter,\n cetDateTimeFormatter,\n cetTimeFormatter,\n currencyFormatter,\n intlNumberFormatter,\n numberFormatter,\n rawNumberFormatter,\n} from './lib/formatters/ag-grid-formatters';\n\nexport type { ParseNumberOptions } from './lib/parsers/number-parsers';\nexport {\n coerceValue,\n numberValueParser,\n parseNumber,\n parseNumberValue,\n} from './lib/parsers/number-parsers';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":"AAEA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C,EAAE,OAAO,CAAC;AAChF;;AC5GO,MAAM,qBAAqB,GAAG;;ACArC;;AAEG;;"}
|
|
1
|
+
{"version":3,"file":"gravionlabs-helix-ag-grid.mjs","names":[],"sources":["../../../projects/ag-grid/src/lib/cell-styles/cell-styles.ts","../../../projects/ag-grid/src/lib/formatters/ag-grid-formatters.ts","../../../projects/ag-grid/src/lib/parsers/number-parsers.ts","../../../projects/ag-grid/src/public-api.ts"],"sourcesContent":["import type { CellClassParams, CellStyle } from 'ag-grid-community';\n\n/**\n * AG Grid `cellStyle` callback that right-aligns numeric cells and colours\n * truthy (non-zero, non-null, non-undefined) values with the helix success\n * colour (`--h-green-500`).\n *\n * @example\n * ```ts\n * columnDefs = [{ field: 'amount', cellStyle: numberCellStyle }];\n * ```\n */\nexport function numberCellStyle(params: CellClassParams): CellStyle {\n return params.value\n ? { textAlign: 'right', color: 'var(--h-green-500)' }\n : { textAlign: 'right' };\n}\n","import type { ValueFormatterParams } from 'ag-grid-community';\n\n/** Type alias for AG Grid's `ValueFormatterParams`, used by all formatter functions. */\nexport type AgGridFormatterParams<TData = unknown, TValue = unknown> = ValueFormatterParams<\n TData,\n TValue\n>;\n\n// ── Number formatters ──────────────────────────────────────────────────────\n\n/**\n * Formats a numeric cell value using the system locale (`toLocaleString`).\n * Returns `''` for `null`, `undefined`, or `NaN`.\n *\n * @example\n * ```ts\n * { field: 'amount', valueFormatter: numberFormatter }\n * ```\n */\nexport function numberFormatter(\n params: AgGridFormatterParams<unknown, number | null | undefined>,\n): string {\n const v = params.value;\n if (v == null || Number.isNaN(v)) return '';\n return v.toLocaleString();\n}\n\n/**\n * Returns the raw string representation of a number without any locale\n * formatting. Returns `''` for `null` or `undefined`.\n *\n * @example\n * ```ts\n * { field: 'id', valueFormatter: rawNumberFormatter }\n * ```\n */\nexport function rawNumberFormatter(\n params: AgGridFormatterParams<unknown, number | null | undefined>,\n): string {\n const v = params.value;\n if (v == null) return '';\n return v.toString();\n}\n\n/**\n * Formats a number using a caller-supplied `Intl.NumberFormat` instance,\n * allowing full control over locale, currency, fraction digits, etc.\n * Returns `''` for `null` or `undefined`.\n *\n * @example\n * ```ts\n * const fmt = new Intl.NumberFormat('de-DE', { minimumFractionDigits: 2 });\n * { field: 'price', valueFormatter: (p) => intlNumberFormatter(p, fmt) }\n * ```\n */\nexport function intlNumberFormatter(\n params: AgGridFormatterParams<unknown, number | null | undefined>,\n numberFormat: Intl.NumberFormat,\n): string {\n const v = params.value;\n if (v == null || Number.isNaN(v)) return '';\n return numberFormat.format(v);\n}\n\n/**\n * Factory that returns a currency formatter closure using `Intl.NumberFormat`\n * with `style: 'currency'`. Defaults to EUR / de-DE.\n * Returns `''` for `null`, `undefined`, or `NaN`.\n *\n * @example\n * ```ts\n * { field: 'revenue', valueFormatter: currencyFormatter() } // '1.234,50 €'\n * { field: 'price', valueFormatter: currencyFormatter('USD','en-US') } // '$99.90'\n * ```\n */\nexport function currencyFormatter(\n currencyCode = 'EUR',\n locale = 'de-DE',\n): (params: AgGridFormatterParams<unknown, number | null | undefined>) => string {\n const fmt = new Intl.NumberFormat(locale, { style: 'currency', currency: currencyCode });\n return (params) => {\n const v = params.value;\n if (v == null || Number.isNaN(v)) return '';\n return fmt.format(v);\n };\n}\n\n// ── CET date formatters ────────────────────────────────────────────────────\n\ntype DateInput = Date | string | null | undefined;\n\nfunction toDate(value: DateInput): Date | null {\n if (value == null) return null;\n const d = value instanceof Date ? value : new Date(value);\n return Number.isNaN(d.getTime()) ? null : d;\n}\n\nconst cetDateFormat = new Intl.DateTimeFormat('de-DE', {\n timeZone: 'Europe/Berlin',\n day: '2-digit',\n month: '2-digit',\n year: 'numeric',\n});\n\nconst cetDateTimeFormat = new Intl.DateTimeFormat('de-DE', {\n timeZone: 'Europe/Berlin',\n day: '2-digit',\n month: '2-digit',\n year: 'numeric',\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit',\n hour12: false,\n});\n\nconst cetTimeFormat = new Intl.DateTimeFormat('de-DE', {\n timeZone: 'Europe/Berlin',\n hour: '2-digit',\n minute: '2-digit',\n hour12: false,\n});\n\n/**\n * Formats a `Date` or ISO string as a CET date: `'15.06.2024'`.\n * Returns `''` for `null`, `undefined`, or invalid dates.\n *\n * @example\n * ```ts\n * { field: 'date', valueFormatter: cetDateFormatter }\n * ```\n */\nexport function cetDateFormatter(params: AgGridFormatterParams<unknown, DateInput>): string {\n const d = toDate(params.value);\n return d ? cetDateFormat.format(d) : '';\n}\n\n/**\n * Formats a `Date` or ISO string as a CET date-time: `'15.06.2024 12:30:00'`.\n * Returns `''` for `null`, `undefined`, or invalid dates.\n *\n * @example\n * ```ts\n * { field: 'updatedAt', valueFormatter: cetDateTimeFormatter }\n * ```\n */\nexport function cetDateTimeFormatter(params: AgGridFormatterParams<unknown, DateInput>): string {\n const d = toDate(params.value);\n if (!d) return '';\n // Intl formats date and time parts separated by ', ' in de-DE — replace with ' '\n return cetDateTimeFormat.format(d).replace(', ', ' ');\n}\n\n/**\n * Formats a `Date` or ISO string as a CET time: `'12:30'`.\n * Returns `''` for `null`, `undefined`, or invalid dates.\n *\n * @example\n * ```ts\n * { field: 'startTime', valueFormatter: cetTimeFormatter }\n * ```\n */\nexport function cetTimeFormatter(params: AgGridFormatterParams<unknown, DateInput>): string {\n const d = toDate(params.value);\n return d ? cetTimeFormat.format(d) : '';\n}\n","import type { ValueParserParams } from 'ag-grid-community';\n\n/** Bounds for number validation. */\nexport interface ParseNumberOptions {\n min?: number;\n max?: number;\n}\n\n/**\n * Validates a number against optional `min`/`max` bounds.\n * Returns `null` if the value is `null`, `undefined`, `NaN`, or out of bounds.\n *\n * @example\n * ```ts\n * coerceValue(5, { min: 0, max: 10 }) // → 5\n * coerceValue(15, { max: 10 }) // → null\n * coerceValue(null) // → null\n * ```\n */\nexport function coerceValue(\n value: number | null | undefined,\n options?: ParseNumberOptions,\n): number | null {\n if (value == null || Number.isNaN(value)) return null;\n if (options?.min != null && value < options.min) return null;\n if (options?.max != null && value > options.max) return null;\n return value;\n}\n\n/**\n * Locale-aware string-to-number parser.\n * Handles thousand separators and decimal commas for the given locale.\n * Returns `null` for empty, `null`, or `undefined` input.\n *\n * @example\n * ```ts\n * parseNumber('1.234,56', 'de-DE') // → 1234.56\n * parseNumber('1,234.56', 'en-US') // → 1234.56\n * ```\n */\nexport function parseNumber(\n value: string | null | undefined,\n locale: string,\n options?: ParseNumberOptions,\n): number | null {\n if (value == null || value.trim() === '') return null;\n\n // Derive separators from the locale\n const parts = new Intl.NumberFormat(locale).formatToParts(1234.5);\n const group = parts.find((p) => p.type === 'group')?.value ?? '';\n const decimal = parts.find((p) => p.type === 'decimal')?.value ?? '.';\n\n const normalised = value.trim().replaceAll(group, '').replace(decimal, '.');\n\n const n = Number.parseFloat(normalised);\n return coerceValue(n, options);\n}\n\n/**\n * Smart string-to-number parser that detects the decimal separator\n * automatically:\n * - Strings containing a comma (e.g. `'1.234,56'` from spreadsheet paste)\n * are parsed as German locale (`de-DE`).\n * - All other strings (e.g. `'3.14'` from keyboard input) are parsed with\n * `parseFloat`.\n *\n * Returns `null` for empty, `null`, or `undefined` input.\n *\n * @example\n * ```ts\n * parseNumberValue('42') // → 42\n * parseNumberValue('3.14') // → 3.14\n * parseNumberValue('1.234,56') // → 1234.56 (German paste)\n * parseNumberValue(null) // → null\n * parseNumberValue('5', { min: 10 }) // → null (out of bounds)\n * ```\n */\nexport function parseNumberValue(\n value: string | null | undefined,\n options?: ParseNumberOptions,\n): number | null {\n if (value == null || value.trim() === '') return null;\n\n const hasComma = value.includes(',');\n if (hasComma) {\n return parseNumber(value, 'de-DE', options);\n }\n\n const n = Number.parseFloat(value.trim());\n return coerceValue(n, options);\n}\n\n/**\n * AG Grid `valueParser` adapter — wraps `parseNumberValue` to read\n * `params.newValue`. Drop-in for any editable numeric column.\n *\n * @example\n * ```ts\n * { field: 'quantity', editable: true, valueParser: numberValueParser }\n * // or with bounds:\n * { field: 'pct', editable: true, valueParser: (p) => numberValueParser(p, { min: 0, max: 100 }) }\n * ```\n */\nexport function numberValueParser(\n params: ValueParserParams,\n options?: ParseNumberOptions,\n): number | null {\n return parseNumberValue(params.newValue as string | null | undefined, options);\n}\n","export const HELIX_AG_GRID_VERSION = '0.1.0';\n\nexport { numberCellStyle } from './lib/cell-styles/cell-styles';\n\nexport type { AgGridFormatterParams } from './lib/formatters/ag-grid-formatters';\nexport {\n cetDateFormatter,\n cetDateTimeFormatter,\n cetTimeFormatter,\n currencyFormatter,\n intlNumberFormatter,\n numberFormatter,\n rawNumberFormatter,\n} from './lib/formatters/ag-grid-formatters';\n\nexport type { ParseNumberOptions } from './lib/parsers/number-parsers';\nexport {\n coerceValue,\n numberValueParser,\n parseNumber,\n parseNumberValue,\n} from './lib/parsers/number-parsers';\n"],"mappings":"AAYA,SAAgB,gBAAgB,QAAuB;CACrD,OAAO,OAAO,QACV;EAAE,WAAW;EAAS,OAAO;CAAoB,IACjD,EAAE,WAAW,QAAO;AAC1B;ACGA,SAAgB,gBACd,QAAiE;CAEjE,MAAM,IAAI,OAAO;CACjB,IAAI,KAAK,QAAQ,OAAO,MAAM,CAAC,GAAG,OAAO;CACzC,OAAO,EAAE,eAAc;AACzB;AAWA,SAAgB,mBACd,QAAiE;CAEjE,MAAM,IAAI,OAAO;CACjB,IAAI,KAAK,MAAM,OAAO;CACtB,OAAO,EAAE,SAAQ;AACnB;AAaA,SAAgB,oBACd,QACA,cAA+B;CAE/B,MAAM,IAAI,OAAO;CACjB,IAAI,KAAK,QAAQ,OAAO,MAAM,CAAC,GAAG,OAAO;CACzC,OAAO,aAAa,OAAO,CAAC;AAC9B;AAaA,SAAgB,kBACd,eAAe,OACf,SAAS,SAAO;CAEhB,MAAM,MAAM,IAAI,KAAK,aAAa,QAAQ;EAAE,OAAO;EAAY,UAAU;CAAY,CAAE;CACvF,QAAQ,WAAU;EAChB,MAAM,IAAI,OAAO;EACjB,IAAI,KAAK,QAAQ,OAAO,MAAM,CAAC,GAAG,OAAO;EACzC,OAAO,IAAI,OAAO,CAA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AAI,OAAO;CAGjD,MAAM,QAAQ,IAAI,KAAK,aAAa,MAAM,CAAC,CAAC,cAAc,MAAM;CAChE,MAAM,QAAQ,MAAM,MAAM,MAAM,EAAE,SAAS,OAAO,CAAC,EAAE,SAAS;CAC9D,MAAM,UAAU,MAAM,MAAM,MAAM,EAAE,SAAS,SAAS,CAAC,EAAE,SAAS;CAElE,MAAM,aAAa,MAAM,KAAI,CAAE,CAAC,WAAW,OAAO,EAAE,CAAC,CAAC,QAAQ,SAAS,GAAG;CAG1E,OAAO,YADG,OAAO,WAAW,UACT,GAAG,OAAO;AAC/B;AAqBA,SAAgB,iBACd,OACA,SAA4B;CAE5B,IAAI,SAAS,QAAQ,MAAM,KAAI,MAAO,IAAI,OAAO;CAGjD,IADiB,MAAM,SAAS,GAC5B,GACF,OAAO,YAAY,OAAO,SAAS,OAAO;CAI5C,OAAO,YADG,OAAO,WAAW,MAAM,KAAI,CACnB,GAAG,OAAO;AAC/B;AAaA,SAAgB,kBACd,QACA,SAA4B;CAE5B,OAAO,iBAAiB,OAAO,UAAuC,OAAO;AAC/E;AC5GA,MAAa,wBAAwB"}
|
package/package.json
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { CellClassParams, CellStyle, ValueFormatterParams, ValueParserParams } from
|
|
2
|
-
|
|
1
|
+
import { CellClassParams, CellStyle, ValueFormatterParams, ValueParserParams } from "ag-grid-community";
|
|
3
2
|
/**
|
|
4
3
|
* AG Grid `cellStyle` callback that right-aligns numeric cells and colours
|
|
5
4
|
* truthy (non-zero, non-null, non-undefined) values with the helix success
|
|
@@ -10,8 +9,7 @@ import { CellClassParams, CellStyle, ValueFormatterParams, ValueParserParams } f
|
|
|
10
9
|
* columnDefs = [{ field: 'amount', cellStyle: numberCellStyle }];
|
|
11
10
|
* ```
|
|
12
11
|
*/
|
|
13
|
-
declare function numberCellStyle(params: CellClassParams): CellStyle;
|
|
14
|
-
|
|
12
|
+
export declare function numberCellStyle(params: CellClassParams): CellStyle;
|
|
15
13
|
/** Type alias for AG Grid's `ValueFormatterParams`, used by all formatter functions. */
|
|
16
14
|
type AgGridFormatterParams<TData = unknown, TValue = unknown> = ValueFormatterParams<TData, TValue>;
|
|
17
15
|
/**
|
|
@@ -23,7 +21,7 @@ type AgGridFormatterParams<TData = unknown, TValue = unknown> = ValueFormatterPa
|
|
|
23
21
|
* { field: 'amount', valueFormatter: numberFormatter }
|
|
24
22
|
* ```
|
|
25
23
|
*/
|
|
26
|
-
declare function numberFormatter(params: AgGridFormatterParams<unknown, number | null | undefined>): string;
|
|
24
|
+
export declare function numberFormatter(params: AgGridFormatterParams<unknown, number | null | undefined>): string;
|
|
27
25
|
/**
|
|
28
26
|
* Returns the raw string representation of a number without any locale
|
|
29
27
|
* formatting. Returns `''` for `null` or `undefined`.
|
|
@@ -33,7 +31,7 @@ declare function numberFormatter(params: AgGridFormatterParams<unknown, number |
|
|
|
33
31
|
* { field: 'id', valueFormatter: rawNumberFormatter }
|
|
34
32
|
* ```
|
|
35
33
|
*/
|
|
36
|
-
declare function rawNumberFormatter(params: AgGridFormatterParams<unknown, number | null | undefined>): string;
|
|
34
|
+
export declare function rawNumberFormatter(params: AgGridFormatterParams<unknown, number | null | undefined>): string;
|
|
37
35
|
/**
|
|
38
36
|
* Formats a number using a caller-supplied `Intl.NumberFormat` instance,
|
|
39
37
|
* allowing full control over locale, currency, fraction digits, etc.
|
|
@@ -45,7 +43,7 @@ declare function rawNumberFormatter(params: AgGridFormatterParams<unknown, numbe
|
|
|
45
43
|
* { field: 'price', valueFormatter: (p) => intlNumberFormatter(p, fmt) }
|
|
46
44
|
* ```
|
|
47
45
|
*/
|
|
48
|
-
declare function intlNumberFormatter(params: AgGridFormatterParams<unknown, number | null | undefined>, numberFormat: Intl.NumberFormat): string;
|
|
46
|
+
export declare function intlNumberFormatter(params: AgGridFormatterParams<unknown, number | null | undefined>, numberFormat: Intl.NumberFormat): string;
|
|
49
47
|
/**
|
|
50
48
|
* Factory that returns a currency formatter closure using `Intl.NumberFormat`
|
|
51
49
|
* with `style: 'currency'`. Defaults to EUR / de-DE.
|
|
@@ -57,7 +55,7 @@ declare function intlNumberFormatter(params: AgGridFormatterParams<unknown, numb
|
|
|
57
55
|
* { field: 'price', valueFormatter: currencyFormatter('USD','en-US') } // '$99.90'
|
|
58
56
|
* ```
|
|
59
57
|
*/
|
|
60
|
-
declare function currencyFormatter(currencyCode?: string, locale?: string): (params: AgGridFormatterParams<unknown, number | null | undefined>) => string;
|
|
58
|
+
export declare function currencyFormatter(currencyCode?: string, locale?: string): (params: AgGridFormatterParams<unknown, number | null | undefined>) => string;
|
|
61
59
|
type DateInput = Date | string | null | undefined;
|
|
62
60
|
/**
|
|
63
61
|
* Formats a `Date` or ISO string as a CET date: `'15.06.2024'`.
|
|
@@ -68,7 +66,7 @@ type DateInput = Date | string | null | undefined;
|
|
|
68
66
|
* { field: 'date', valueFormatter: cetDateFormatter }
|
|
69
67
|
* ```
|
|
70
68
|
*/
|
|
71
|
-
declare function cetDateFormatter(params: AgGridFormatterParams<unknown, DateInput>): string;
|
|
69
|
+
export declare function cetDateFormatter(params: AgGridFormatterParams<unknown, DateInput>): string;
|
|
72
70
|
/**
|
|
73
71
|
* Formats a `Date` or ISO string as a CET date-time: `'15.06.2024 12:30:00'`.
|
|
74
72
|
* Returns `''` for `null`, `undefined`, or invalid dates.
|
|
@@ -78,7 +76,7 @@ declare function cetDateFormatter(params: AgGridFormatterParams<unknown, DateInp
|
|
|
78
76
|
* { field: 'updatedAt', valueFormatter: cetDateTimeFormatter }
|
|
79
77
|
* ```
|
|
80
78
|
*/
|
|
81
|
-
declare function cetDateTimeFormatter(params: AgGridFormatterParams<unknown, DateInput>): string;
|
|
79
|
+
export declare function cetDateTimeFormatter(params: AgGridFormatterParams<unknown, DateInput>): string;
|
|
82
80
|
/**
|
|
83
81
|
* Formats a `Date` or ISO string as a CET time: `'12:30'`.
|
|
84
82
|
* Returns `''` for `null`, `undefined`, or invalid dates.
|
|
@@ -88,12 +86,11 @@ declare function cetDateTimeFormatter(params: AgGridFormatterParams<unknown, Dat
|
|
|
88
86
|
* { field: 'startTime', valueFormatter: cetTimeFormatter }
|
|
89
87
|
* ```
|
|
90
88
|
*/
|
|
91
|
-
declare function cetTimeFormatter(params: AgGridFormatterParams<unknown, DateInput>): string;
|
|
92
|
-
|
|
89
|
+
export declare function cetTimeFormatter(params: AgGridFormatterParams<unknown, DateInput>): string;
|
|
93
90
|
/** Bounds for number validation. */
|
|
94
91
|
interface ParseNumberOptions {
|
|
95
|
-
|
|
96
|
-
|
|
92
|
+
min?: number;
|
|
93
|
+
max?: number;
|
|
97
94
|
}
|
|
98
95
|
/**
|
|
99
96
|
* Validates a number against optional `min`/`max` bounds.
|
|
@@ -106,7 +103,7 @@ interface ParseNumberOptions {
|
|
|
106
103
|
* coerceValue(null) // → null
|
|
107
104
|
* ```
|
|
108
105
|
*/
|
|
109
|
-
declare function coerceValue(value: number | null | undefined, options?: ParseNumberOptions): number | null;
|
|
106
|
+
export declare function coerceValue(value: number | null | undefined, options?: ParseNumberOptions): number | null;
|
|
110
107
|
/**
|
|
111
108
|
* Locale-aware string-to-number parser.
|
|
112
109
|
* Handles thousand separators and decimal commas for the given locale.
|
|
@@ -118,7 +115,7 @@ declare function coerceValue(value: number | null | undefined, options?: ParseNu
|
|
|
118
115
|
* parseNumber('1,234.56', 'en-US') // → 1234.56
|
|
119
116
|
* ```
|
|
120
117
|
*/
|
|
121
|
-
declare function parseNumber(value: string | null | undefined, locale: string, options?: ParseNumberOptions): number | null;
|
|
118
|
+
export declare function parseNumber(value: string | null | undefined, locale: string, options?: ParseNumberOptions): number | null;
|
|
122
119
|
/**
|
|
123
120
|
* Smart string-to-number parser that detects the decimal separator
|
|
124
121
|
* automatically:
|
|
@@ -138,7 +135,7 @@ declare function parseNumber(value: string | null | undefined, locale: string, o
|
|
|
138
135
|
* parseNumberValue('5', { min: 10 }) // → null (out of bounds)
|
|
139
136
|
* ```
|
|
140
137
|
*/
|
|
141
|
-
declare function parseNumberValue(value: string | null | undefined, options?: ParseNumberOptions): number | null;
|
|
138
|
+
export declare function parseNumberValue(value: string | null | undefined, options?: ParseNumberOptions): number | null;
|
|
142
139
|
/**
|
|
143
140
|
* AG Grid `valueParser` adapter — wraps `parseNumberValue` to read
|
|
144
141
|
* `params.newValue`. Drop-in for any editable numeric column.
|
|
@@ -150,9 +147,6 @@ declare function parseNumberValue(value: string | null | undefined, options?: Pa
|
|
|
150
147
|
* { field: 'pct', editable: true, valueParser: (p) => numberValueParser(p, { min: 0, max: 100 }) }
|
|
151
148
|
* ```
|
|
152
149
|
*/
|
|
153
|
-
declare function numberValueParser(params: ValueParserParams, options?: ParseNumberOptions): number | null;
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
export { HELIX_AG_GRID_VERSION, cetDateFormatter, cetDateTimeFormatter, cetTimeFormatter, coerceValue, currencyFormatter, intlNumberFormatter, numberCellStyle, numberFormatter, numberValueParser, parseNumber, parseNumberValue, rawNumberFormatter };
|
|
158
|
-
export type { AgGridFormatterParams, ParseNumberOptions };
|
|
150
|
+
export declare function numberValueParser(params: ValueParserParams, options?: ParseNumberOptions): number | null;
|
|
151
|
+
export declare const HELIX_AG_GRID_VERSION = "0.1.0";
|
|
152
|
+
export type { AgGridFormatterParams, ParseNumberOptions };
|