chore: Replace packages with native functions (#5140)
This commit is contained in:
@@ -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}`;
|
||||
};
|
||||
|
||||
|
||||
19
app/javascript/dashboard/helper/flag.js
Normal file
19
app/javascript/dashboard/helper/flag.js
Normal 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);
|
||||
};
|
||||
9
app/javascript/dashboard/helper/specs/flag.spec.js
Normal file
9
app/javascript/dashboard/helper/specs/flag.spec.js
Normal 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('🇺🇸');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user