Skip to content

Commit

Permalink
Merge pull request #14 from revolut-engineering/export-widget-locale
Browse files Browse the repository at this point in the history
docs(locale): expose type and relevant check
  • Loading branch information
ohansemmanuel authored Mar 2, 2022
2 parents b867748 + ead73af commit 6b19454
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
8 changes: 7 additions & 1 deletion src/checks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { ValidationError, RevolutCheckoutError } from './types'
import { ValidationError, RevolutCheckoutError, Locale } from './types'

import { LOCALES } from './constants'

export function isValidationError(error?: Error): error is ValidationError {
return error != null && error.name === 'Validation'
Expand All @@ -9,3 +11,7 @@ export function isRevolutCheckoutError(
): error is RevolutCheckoutError {
return error != null && error.name === 'RevolutCheckout'
}

export function isValidLocale(locale: unknown): locale is Locale {
return locale && LOCALES.some((value) => value === locale)
}
13 changes: 13 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
export const LOCALES = [
'en',
'nl',
'fr',
'de',
'it',
'lt',
'pl',
'pt',
'es',
'cs',
] as const

export const MODE = {
PRODUCTION: 'prod',
DEVELOPMENT: 'dev',
Expand Down
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
export { RevolutCheckoutLoader as default } from './loader'
export { isRevolutCheckoutError, isValidationError } from './checks'
export {
isRevolutCheckoutError,
isValidationError,
isValidLocale,
} from './checks'
export {
ValidationErrorType,
ValidationError,
Expand All @@ -8,6 +12,7 @@ export {
FieldStatus,
FieldClasses,
FieldStyles,
Locale,
RevolutCheckoutCardField,
RevolutCheckoutInstance,
} from './types'
13 changes: 2 additions & 11 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MODE } from './constants'
import { MODE, LOCALES } from './constants'

export type Mode = MODE[keyof MODE]

Expand Down Expand Up @@ -254,16 +254,7 @@ export type CountryCode =
| 'QA'
| 'MZ'

export type Locale =
| 'en'
| 'nl'
| 'fr'
| 'de'
| 'it'
| 'lt'
| 'pl'
| 'pt'
| 'es'
export type Locale = typeof LOCALES[number]

export type ValidationErrorType =
| 'validation.card.number.incomplete'
Expand Down

0 comments on commit 6b19454

Please sign in to comment.