Files
triggerdotdev--trigger.dev/apps/webapp/app/utils/numberFormatter.ts
Matt Aitken 49df40cb11 TRQL and the Query page (#2843)
TRQL (pronounced Treacle like the delicious British dark sweet syrup) is
the TRiggerQueryLanguage. It allows users to safely write queries on
their data. The queries are safely turned into ClickHouse queries which
are tenant-safe and not SQL injectable.


https://github.com/user-attachments/assets/bbfca473-b3fc-4150-8fe6-79e8840a2d29

This started out as a translation of HogQL by PostHog from Python to
TypeScript.

Features
- Tenant safe queries.
- Many underlying ClickHouse features including functions and
aggregations.
- Virtual columns, which are exposed to users as real columns but are
actually expressions.
- Transformations of data types and where clauses.
- Simple JSON path querying.
- Limits on execution time.
- Reporting of query statistics.

## Query page

There’s a new Query page (currently behind a feature flag) where you can
write TRQL queries and execute them against your environment, project or
organization.

Features
- Executing TRQL queries
- Syntax highlighting and errors
- Autocomplete
- AI generation/editing of queries
- Help and examples
- Table with auto-inferred data types from the table schema
- Table cell renderers for our special types like Run ids, environments,
machines, tasks, queues, etc.
- Copy/export as CSV/JSON
- Line and bar graphs with grouping and stacking
- History of queries
2026-01-09 11:39:36 +00:00

51 lines
1.5 KiB
TypeScript

const compactFormatter = Intl.NumberFormat("en", { notation: "compact", compactDisplay: "short" });
export const formatNumberCompact = (num: number): string => {
return compactFormatter.format(num);
};
const formatter = Intl.NumberFormat("en");
// Formatter for small decimal values that need more precision
const preciseFormatter = Intl.NumberFormat("en", {
minimumSignificantDigits: 1,
maximumSignificantDigits: 6,
});
export const formatNumber = (num: number): string => {
// For very small numbers (between -1 and 1, exclusive), use precise formatting
// to avoid rounding 0.000025 to 0
if (num !== 0 && Math.abs(num) < 1) {
return preciseFormatter.format(num);
}
return formatter.format(num);
};
const roundedCurrencyFormatter = Intl.NumberFormat("en-US", {
style: "currency",
currencyDisplay: "symbol",
maximumFractionDigits: 0,
currency: "USD",
});
const currencyFormatter = Intl.NumberFormat("en-US", {
style: "currency",
currencyDisplay: "symbol",
currency: "USD",
});
export const formatCurrency = (num: number, rounded: boolean): string => {
return rounded ? roundedCurrencyFormatter.format(num) : currencyFormatter.format(num);
};
const accurateCurrencyFormatter = Intl.NumberFormat("en-US", {
style: "currency",
currencyDisplay: "symbol",
minimumFractionDigits: 8,
maximumFractionDigits: 8,
currency: "USD",
});
export function formatCurrencyAccurate(num: number): string {
return accurateCurrencyFormatter.format(num);
}