@xuda.io/xuda-ui-plugin-flag-icons
Version:
The Xuda Flag-Icons UI Plugin integrates the flag-icons library into your Xuda environment, enabling you to effortlessly display high-quality SVG flags from around the world. Easily customize size, style, and layout, thereby enhancing internationalization
42 lines (33 loc) • 1.16 kB
JavaScript
import "flag-icons/css/flag-icons.min.css";
import { flags } from "./flags.js";
export const fn = function (plugin_name, el, properties) {
const opt = simplifyObject(properties);
const country = $(el).text().trim();
if (!country) return;
function getCountryShortCode(input) {
// Normalize input for comparison (trim spaces, uppercase)
const normalizedInput = input.trim().toUpperCase();
for (let i = 0; i < flags.length; i++) {
const { shortCode, fullName, countryCode, areaCode } = flags[i];
// Check if input matches fullName, countryCode, or areaCode
if (
fullName.toUpperCase() === normalizedInput ||
countryCode === normalizedInput ||
areaCode.toUpperCase() === normalizedInput
) {
return shortCode;
}
}
// If no match found, return undefined or a default value
return undefined;
}
const code = getCountryShortCode(country);
$(el).addClass(`fi fi-${code}`).empty();
};
function simplifyObject(inputObject) {
const result = {};
Object.keys(inputObject).forEach((key) => {
result[key] = inputObject[key].value;
});
return result;
}