chore: Replace packages with native functions (#5140)

This commit is contained in:
David Kubeš
2022-08-03 13:38:21 +02:00
committed by GitHub
parent 262458f07d
commit a18c0a97f3
15 changed files with 68 additions and 57 deletions

View File

@@ -1,8 +1,7 @@
import queryString from 'query-string';
import { DEFAULT_REDIRECT_URL } from '../constants';
export const frontendURL = (path, params) => {
const stringifiedParams = params ? `?${queryString.stringify(params)}` : '';
const stringifiedParams = params ? `?${new URLSearchParams(params)}` : '';
return `/app/${path}${stringifiedParams}`;
};

View File

@@ -0,0 +1,19 @@
const FLAG_OFFSET = 127397;
/**
* Gets emoji flag for given locale.
*
* @param {string} countryCode locale code
* @return {string} emoji flag
*
* @example
* getCountryFlag('cz') // '🇨🇿'
*/
export const getCountryFlag = countryCode => {
const codePoints = countryCode
.toUpperCase()
.split('')
.map(char => FLAG_OFFSET + char.charCodeAt());
return String.fromCodePoint(...codePoints);
};

View File

@@ -0,0 +1,9 @@
import { getCountryFlag } from '../flag';
describe('#flag', () => {
it('returns the correct flag ', () => {
expect(getCountryFlag('cz')).toBe('🇨🇿');
expect(getCountryFlag('IN')).toBe('🇮🇳');
expect(getCountryFlag('US')).toBe('🇺🇸');
});
});