stack/packages/stack-shared/src/utils/unicode.tsx
devin-ai-integration[bot] 9a76d10c2a
[DEVIN: Konsti] Add in-source unit tests to stack-shared utilities (#485)
* Add in-source unit tests to stack-shared utilities

Co-Authored-By: Konstantin Wohlwend <n2d4xc@gmail.com>

* Fix type checking and linting issues

Co-Authored-By: Konstantin Wohlwend <n2d4xc@gmail.com>

* Fix lint errors in results.tsx

Co-Authored-By: Konstantin Wohlwend <n2d4xc@gmail.com>

* Fix remaining lint errors in results.tsx

Co-Authored-By: Konstantin Wohlwend <n2d4xc@gmail.com>

* Fix lint warnings in results.tsx

Co-Authored-By: Konstantin Wohlwend <n2d4xc@gmail.com>

* Fix wait function mocking in results.tsx

Co-Authored-By: Konstantin Wohlwend <n2d4xc@gmail.com>

* Fix retry function test in results.tsx

Co-Authored-By: Konstantin Wohlwend <n2d4xc@gmail.com>

* Fix React.forwardRef mock in react.tsx test

Co-Authored-By: Konstantin Wohlwend <n2d4xc@gmail.com>

* Fix trailing spaces in react.tsx and results.tsx

Co-Authored-By: Konstantin Wohlwend <n2d4xc@gmail.com>

* Revert to DependenciesMap and wrap rejected promise in ignoreUnhandledRejection

Co-Authored-By: Konstantin Wohlwend <n2d4xc@gmail.com>

* Fix

* Revert changes to known-errors.tsx constructor

Co-Authored-By: Konstantin Wohlwend <n2d4xc@gmail.com>

* Make rotateRight call rotateLeft per review feedback

Co-Authored-By: Konstantin Wohlwend <n2d4xc@gmail.com>

* Remove redundant @ts-expect-error directive in known-errors.tsx

Co-Authored-By: Konstantin Wohlwend <n2d4xc@gmail.com>

* Fix import order in promises.tsx

Co-Authored-By: Konstantin Wohlwend <n2d4xc@gmail.com>

* Fix

* Fix CI failures: add back @ts-expect-error in known-errors.tsx and revert mapResult implementation in results.tsx

Co-Authored-By: Konstantin Wohlwend <n2d4xc@gmail.com>

* Remove unused @ts-expect-error directive in known-errors.tsx

Co-Authored-By: Konstantin Wohlwend <n2d4xc@gmail.com>

* Add back @ts-expect-error directive with explanation in known-errors.tsx

Co-Authored-By: Konstantin Wohlwend <n2d4xc@gmail.com>

* Change @ts-expect-error to @ts-ignore in known-errors.tsx

Co-Authored-By: Konstantin Wohlwend <n2d4xc@gmail.com>

* be honest

* vocabulary

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Konstantin Wohlwend <n2d4xc@gmail.com>
2025-02-28 01:47:37 +00:00

25 lines
1.2 KiB
TypeScript

import { StackAssertionError } from "./errors";
export function getFlagEmoji(twoLetterCountryCode: string) {
if (!/^[a-zA-Z][a-zA-Z]$/.test(twoLetterCountryCode)) throw new StackAssertionError("Country code must be two alphabetical letters");
const codePoints = twoLetterCountryCode
.toUpperCase()
.split('')
.map(char => 127397 + char.charCodeAt(0));
return String.fromCodePoint(...codePoints);
}
import.meta.vitest?.test("getFlagEmoji", ({ expect }) => {
// Test with valid country codes
expect(getFlagEmoji("US")).toBe("🇺🇸");
expect(getFlagEmoji("us")).toBe("🇺🇸");
expect(getFlagEmoji("GB")).toBe("🇬🇧");
expect(getFlagEmoji("JP")).toBe("🇯🇵");
// Test with invalid country codes
expect(() => getFlagEmoji("")).toThrow("Country code must be two alphabetical letters");
expect(() => getFlagEmoji("A")).toThrow("Country code must be two alphabetical letters");
expect(() => getFlagEmoji("ABC")).toThrow("Country code must be two alphabetical letters");
expect(() => getFlagEmoji("12")).toThrow("Country code must be two alphabetical letters");
expect(() => getFlagEmoji("A1")).toThrow("Country code must be two alphabetical letters");
});