tessl install tessl/npm-lightdash--common@0.2231.5Shared TypeScript library for the Lightdash platform containing common types, utilities, and business logic for analytics workflows
Agent Success
Agent success rate when using this tile
72%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.09x
Baseline
Agent success rate without this tile
66%
Build a sales report formatting utility that takes raw sales data and formats it for presentation in reports and dashboards. The utility should handle date formatting, number formatting with various styles, and apply appropriate formatting based on data types.
Create a TypeScript module that exports a formatSalesReport function that:
Accepts an array of raw sales records containing:
date: ISO date string (e.g., "2024-03-15T10:30:00Z")revenue: number representing dollarsquantity: integer countgrowth_rate: decimal number representing percentage (e.g., 0.15 for 15%)region: string identifierReturns formatted sales records where:
The formatting should handle edge cases:
src/formatSalesReport.ts with the main functionProvides data formatting utilities for Business Intelligence operations.
// File: src/formatSalesReport.test.ts
import { formatSalesReport } from './formatSalesReport';
test('formats complete sales record correctly', () => {
const rawData = [
{
date: '2024-03-15T10:30:00Z',
revenue: 12345.67,
quantity: 1234,
growth_rate: 0.157,
region: 'US-WEST'
}
];
const formatted = formatSalesReport(rawData);
expect(formatted[0].date).toMatch(/March.*15.*2024/);
expect(formatted[0].revenue).toContain('$');
expect(formatted[0].revenue).toContain('12,345');
expect(formatted[0].quantity).toBe('1,234');
expect(formatted[0].growth_rate).toContain('15');
expect(formatted[0].growth_rate).toContain('%');
expect(formatted[0].region).toBe('US-WEST');
});// File: src/formatSalesReport.test.ts
import { formatSalesReport } from './formatSalesReport';
test('handles null and undefined values', () => {
const rawData = [
{
date: '2024-03-15T10:30:00Z',
revenue: null,
quantity: undefined,
growth_rate: 0.0,
region: 'EU-CENTRAL'
}
];
const formatted = formatSalesReport(rawData);
expect(formatted[0].revenue).toBe('-');
expect(formatted[0].quantity).toBe('-');
expect(formatted[0].growth_rate).toContain('0');
});// File: src/formatSalesReport.test.ts
import { formatSalesReport } from './formatSalesReport';
test('formats large numbers with separators', () => {
const rawData = [
{
date: '2024-01-01T00:00:00Z',
revenue: 1000000.99,
quantity: 50000,
growth_rate: 0.333,
region: 'ASIA-PAC'
}
];
const formatted = formatSalesReport(rawData);
expect(formatted[0].revenue).toContain('1,000,000');
expect(formatted[0].quantity).toBe('50,000');
});src/formatSalesReport.ts - Main implementation filesrc/formatSalesReport.test.ts - Test file with all test cases passingdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10
scenario-11
scenario-12
scenario-13
scenario-14
scenario-15
scenario-16
scenario-17
scenario-18
scenario-19
scenario-20