Skip to content

Commit 3a48d60

Browse files
committed
fix: variation total count handle missing value
1 parent 55c7e26 commit 3a48d60

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

__tests__/common/number.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,15 @@ describe('applyDeterministicVariation', () => {
129129
// Empty seed should return original value without variation
130130
expect(result).toBe(baseValue);
131131
});
132+
133+
it('should handle falsy value', () => {
134+
const result = applyDeterministicVariation({
135+
value: null as unknown as number,
136+
seed: '',
137+
maxVariationPercent: 7.6,
138+
});
139+
140+
// Empty seed should return original value without variation
141+
expect(result).toBe(0);
142+
});
132143
});

src/common/number.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { isNullOrUndefined } from './object';
2+
13
export function largeNumberFormat(value: number): string | null {
24
if (typeof value !== 'number') {
35
return null;
@@ -81,6 +83,10 @@ export const applyDeterministicVariation = ({
8183
seed: string;
8284
maxVariationPercent: number;
8385
}): number => {
86+
if (isNullOrUndefined(value)) {
87+
return 0;
88+
}
89+
8490
if (!seed) {
8591
return value;
8692
}

0 commit comments

Comments
 (0)