Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion components/SearchBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import React, { useState, useRef, useCallback } from 'react';
import SpecialTags from './SpecialTags.jsx';
import { countryKey } from '../lib/country.js';

const SAMPLES_BY_MODE = {
text: [
Expand Down Expand Up @@ -45,10 +46,11 @@ export default function SearchBar({ developers, onResults, onReset, onGenerateCa

if (m === 'text') {
const lower = q.trim().toLowerCase();
const locationKey = countryKey(q.trim());
let results = developers.filter(d =>
(d.login && d.login.toLowerCase().includes(lower)) ||
(d.name && d.name.toLowerCase().includes(lower)) ||
(d.location && d.location.toLowerCase().includes(lower))
(d.location && countryKey(d.location).includes(locationKey))
);

if (results.length === 0) {
Expand Down
5 changes: 4 additions & 1 deletion lib/country.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ export function normalizeCountry(name) {

// Comparable form — use whenever two country names from different sources are matched
export function countryKey(name) {
return normalizeCountry(name).toLowerCase();
return normalizeCountry(name)
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.toLowerCase();
}

export function normalizeCity(name) {
Expand Down
9 changes: 9 additions & 0 deletions tests/country.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { countryKey, extractCountry } from '../lib/country.js';

test('countryKey matches accented country names to unaccented map names', () => {
assert.equal(countryKey(extractCountry('Perú')), countryKey('Peru'));
assert.equal(countryKey('España'), countryKey('Espana'));
assert.ok(countryKey('Lima, Perú').includes(countryKey('Peru')));
});
Loading