Skip to content

add typing for currency rule #270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type ValidationRuleName =
| "array"
| "boolean"
| "class"
| "currency"
| "custom"
| "date"
| "email"
Expand Down Expand Up @@ -103,6 +104,41 @@ export interface RuleClass<T = any> extends RuleCustom {
instanceOf?: T;
}

/**
* Validation schema definition for "currency" built-in validator
* @see https://github.com/icebob/fastest-validator#currency
*/
export interface RuleCurrency extends RuleCustom {
/**
* Name of built-in validator
*/
type: "currency";
/**
* The currency symbol expected in string (as prefix)
* @default null
*/
currencySymbol?: string;
/**
* Toggle to make the currency symbol optional in string
* @default false
*/
symbolOptional?: boolean;
/**
* Thousand place separator character
* @default ','
*/
thousandSeparator?: string;
/**
* Decimal place character
* @default '.'
*/
decimalSeparator?: string;
/**
* Custom regular expression to validate currency strings
*/
customRegex?: RegExp | string;
}

/**
* Validation schema definition for "date" built-in validator
* @see https://github.com/icebob/fastest-validator#date
Expand Down Expand Up @@ -754,6 +790,7 @@ export type ValidationRuleObject =
| RuleArray
| RuleBoolean
| RuleClass
| RuleCurrency
| RuleDate
| RuleEmail
| RuleEqual
Expand Down