@fusedashlabs/ui9000-workspace
Version:
UI9000 workspace MCP. One tool, show_workspace, draws a chart from your table. Set TYPESAFE_API_KEY to let Jev choose the chart.
48 lines (47 loc) • 1.91 kB
JavaScript
// Common city name spelling variations - easily extensible
const CITY_NAME_VARIATIONS = {
kyiv: "kiev",
peking: "beijing",
bombay: "mumbai",
calcutta: "kolkata",
madras: "chennai",
saigon: "hochiminh",
};
/**
* Normalizes dataValue for matching based on mapType
* Handles different normalization rules for city, county, state, country, and region
*/
export const normalizeDataValue = (dataValue, mapType) => {
if (!dataValue)
return "";
// Strip diacritics for every type so comma-below vs cedilla (ș/ş, ț/ţ) and
// accents (São/Sao, Córdoba/Cordoba) match regardless of encoding.
let normalized = dataValue.trim().toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g, "");
// Fold common punctuation variants so "St. Andrew"/"Saint Andrew" and
// "Guinea-Bissau"/"Guinea Bissau" match across data sources.
normalized = normalized.replace(/\bst\.?\s+/g, "saint ");
if (mapType !== "city") {
normalized = normalized.replace(/['’´\`.-]/g, " ");
}
if (mapType === "city") {
// Remove all special characters, apostrophes, diacritics
normalized = normalized
.normalize("NFD")
.replace(/[\u0300-\u036f]/g, "") // Remove diacritics
.replace(/[''`´]/g, "") // Remove apostrophes and quotes
.replace(/[-_]/g, ""); // Remove hyphens and underscores
// Apply common spelling variations
Object.entries(CITY_NAME_VARIATIONS).forEach(([from, to]) => {
const regex = new RegExp(`\\b${from}\\b`, "g");
normalized = normalized.replace(regex, to);
});
}
if (mapType === "country") {
return normalized;
}
const parts = normalized.replace(/ /g, "").split(",");
if (mapType === "county") {
return parts.map((item) => item.replace("county", "")).join(",");
}
return parts.join(",");
};