-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(isPositive): return
false
with zero (#728)
The function `isPositive` should return `false` when passing Dinero objects with amount `0` or `-0`, as zero is unsigned—neither negative nor positive.
- Loading branch information
1 parent
fc99ba9
commit 140fe68
Showing
4 changed files
with
31 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import type { Calculator, Dinero } from '../types'; | ||
import { greaterThanOrEqual } from '../utils'; | ||
import { greaterThan } from '../utils'; | ||
|
||
export type IsPositiveParams<TAmount> = readonly [ | ||
dineroObject: Dinero<TAmount> | ||
]; | ||
|
||
export function isPositive<TAmount>(calculator: Calculator<TAmount>) { | ||
const greaterThanOrEqualFn = greaterThanOrEqual(calculator); | ||
const greaterThanFn = greaterThan(calculator); | ||
|
||
return function _isPositive(...[dineroObject]: IsPositiveParams<TAmount>) { | ||
const { amount } = dineroObject.toJSON(); | ||
|
||
return greaterThanOrEqualFn(amount, calculator.zero()); | ||
return greaterThanFn(amount, calculator.zero()); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140fe68
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
dinerojs – ./
v2.dinerojs.com
dinerojs-dinerojs.vercel.app
dinerojs-git-main-dinerojs.vercel.app