do to formatters
This commit is contained in:
21
apps/website/lib/formatters/CountryFlagFormatter.ts
Normal file
21
apps/website/lib/formatters/CountryFlagFormatter.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
export class CountryFlagFormatter {
|
||||
private constructor(private readonly value: string) {}
|
||||
|
||||
static fromCountryCode(countryCode: string | null | undefined): CountryFlagFormatter {
|
||||
if (!countryCode) {
|
||||
return new CountryFlagFormatter('🏁');
|
||||
}
|
||||
|
||||
const code = countryCode.toUpperCase();
|
||||
if (code.length !== 2) {
|
||||
return new CountryFlagFormatter('🏁');
|
||||
}
|
||||
|
||||
const codePoints = [...code].map((char) => 127397 + char.charCodeAt(0));
|
||||
return new CountryFlagFormatter(String.fromCodePoint(...codePoints));
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user