Skip to content

Commit 9f0ccc7

Browse files
committed
signedMoney/unsignedMoney are not functions
1 parent e56cae6 commit 9f0ccc7

4 files changed

Lines changed: 9 additions & 13 deletions

File tree

projects/natural/src/lib/classes/validators.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ describe('money', () => {
329329

330330
describe('signedMoney', () => {
331331
it('should allow negative and positive amounts within the human limit', () => {
332-
const validator = signedMoney();
332+
const validator = signedMoney;
333333
validate(validator, true, '-5000000');
334334
validate(validator, true, '5000000');
335335
validate(validator, false, '-5000000.01');
@@ -339,7 +339,7 @@ describe('signedMoney', () => {
339339

340340
describe('unsignedMoney', () => {
341341
it('should only allow positive amounts within the human limit', () => {
342-
const validator = unsignedMoney();
342+
const validator = unsignedMoney;
343343
validate(validator, true, '0');
344344
validate(validator, true, '5000000');
345345
validate(validator, false, '-0.01');

projects/natural/src/lib/classes/validators.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ const twoDecimals = decimal(2);
240240
*
241241
* A range is always required, because unbounded financial inputs allow gross typos (eg. an extra
242242
* digit) to slip through and cause data corruption, so callers must always think about a sensible
243-
* limit. For most cases, prefer the ready-made `signedMoney()` or `unsignedMoney()` helpers instead
243+
* limit. For most cases, prefer the ready-made `signedMoney` or `unsignedMoney` helpers instead
244244
* of calling this directly.
245245
*/
246246
export function money(min: number, max: number): ValidatorFn {
@@ -270,17 +270,13 @@ const maxMoney = 5_000_000;
270270
* Validate a signed amount of money (can be negative), suitable for a value stored in a database
271271
* column of type `SIGNED INT`, such as a balance.
272272
*/
273-
export function signedMoney(): ValidatorFn {
274-
return money(-maxMoney, maxMoney);
275-
}
273+
export const signedMoney = money(-maxMoney, maxMoney);
276274

277275
/**
278276
* Validate an unsigned amount of money (cannot be negative), suitable for a value stored in a
279277
* database column of type `UNSIGNED INT`, such as a price.
280278
*/
281-
export function unsignedMoney(): ValidatorFn {
282-
return money(0, maxMoney);
283-
}
279+
export const unsignedMoney = money(0, maxMoney);
284280

285281
/**
286282
* Validate that the number is strictly greater than given one.

src/app/other/other.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ <h1>Money validators</h1>
6666
</mat-form-field>
6767

6868
<mat-form-field>
69-
<mat-label>signedMoney()</mat-label>
69+
<mat-label>signedMoney</mat-label>
7070
<input matInput [formControl]="signedMoneyControl" />
7171
<mat-error>{{ signedMoneyControl.errors | errorMessage }}</mat-error>
7272
</mat-form-field>
7373

7474
<mat-form-field>
75-
<mat-label>unsignedMoney()</mat-label>
75+
<mat-label>unsignedMoney</mat-label>
7676
<input matInput [formControl]="unsignedMoneyControl" />
7777
<mat-error>{{ unsignedMoneyControl.errors | errorMessage }}</mat-error>
7878
</mat-form-field>

src/app/other/other.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ export class OtherComponent implements OnInit {
267267
* Money validators
268268
*/
269269
public readonly moneyControl = new FormControl('', [money(-1000, 1000)]);
270-
public readonly signedMoneyControl = new FormControl('', [signedMoney()]);
271-
public readonly unsignedMoneyControl = new FormControl('', [unsignedMoney()]);
270+
public readonly signedMoneyControl = new FormControl('', [signedMoney]);
271+
public readonly unsignedMoneyControl = new FormControl('', [unsignedMoney]);
272272

273273
public ngOnInit(): void {
274274
this.httpPrefixControl.valueChanges.subscribe(value => {

0 commit comments

Comments
 (0)