fabasoad/business-card

View on GitHub
src/scripts/i18n/SupportedLocales.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import { Locale } from './types'

export default class SupportedLocales {
  static _items: Locale[] = [
    new Locale('gb'),
    new Locale('jp'),
    new Locale('ua')
  ]

  static default: Locale = SupportedLocales._items[0]

  static find(code: string): Locale | undefined {
    return SupportedLocales._items.find((l: Locale) => l.code === code)
  }

  static getOrDefault(code: string): Locale {
    return SupportedLocales.find(code) || SupportedLocales.default
  }

  static getExceptOf(code: string): Locale[] {
    return SupportedLocales._items.filter((l: Locale) => l.code !== code)
  }
}