Skip to content

Instantly share code, notes, and snippets.

View laurenzcodes's full-sized avatar
🎯
Focusing

Robert Laurenz laurenzcodes

🎯
Focusing
  • Berlin, Germany
View GitHub Profile
@laurenzcodes
laurenzcodes / formatCents.ts
Last active April 26, 2022 08:15
Function to convert cents into euros using regex replace
const formatCents = (sum?: number | null): string =>
sum
? (sum / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".").replace(/\.([^.]*)$/g, ",$1")
: '0,00';
// Tests:
// it('formats cents into EURO (€) values', () => {
// expect(formatCents(1)).toEqual('0,01');
// expect(formatCents(10)).toEqual('0,10');
@laurenzcodes
laurenzcodes / link.tsx
Last active January 12, 2023 17:42
Gatsby Link Component that preserves url parameters after route change