Skip to content

Commit 0876e33

Browse files
talissoncostaclaude
andcommitted
refactor(format): add moment import and fix money function types
- Add explicit moment import to fix TypeScript UMD global error - Simplify money() to consistently return defaultValue for null/undefined/0 - Update tests to reflect new behavior 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 3a4a92a commit 0876e33

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

frontend/common/utils/__tests__/format.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,14 @@ describe('Format', () => {
198198
expect(Format.money(0, 'N/A')).toBe('N/A')
199199
})
200200

201-
it('should return null for null value', () => {
202-
expect(Format.money(null)).toBe(null)
201+
it('should return FREE for null/undefined values', () => {
202+
expect(Format.money(null)).toBe('FREE')
203+
expect(Format.money(undefined)).toBe('FREE')
204+
})
205+
206+
it('should return custom default value for null/undefined', () => {
207+
expect(Format.money(null, 'N/A')).toBe('N/A')
208+
expect(Format.money(undefined, 'N/A')).toBe('N/A')
203209
})
204210
})
205211

frontend/common/utils/format.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import moment from 'moment'
2+
13
type Person = {
24
firstName?: string
35
lastName?: string
@@ -129,18 +131,15 @@ const Format = {
129131
value: number | null | undefined,
130132
defaultValue?: string | null,
131133
): string | null | undefined {
132-
if (value === 0) {
134+
if (value === null || value === undefined || value === 0) {
133135
return defaultValue == null ? 'FREE' : defaultValue
134136
}
135137

136-
return (
137-
value &&
138-
${value
139-
.toFixed(2)
140-
.replace(/./g, (c, i, a) =>
141-
i && c !== '.' && (a.length - i) % 3 === 0 ? `,${c}` : c,
142-
)}`
143-
)
138+
return ${value
139+
.toFixed(2)
140+
.replace(/./g, (c, i, a) =>
141+
i && c !== '.' && (a.length - i) % 3 === 0 ? `,${c}` : c,
142+
)}`
144143
},
145144

146145
monthAndYear(value: string | null | undefined): string | null | undefined {

0 commit comments

Comments
 (0)