Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
How to remove the accents/diacritic in a string in algolia places
const location = places({
  ...this.appKeyId,
  container: document.querySelector('#location') as HTMLInputElement,
  });

How do I replace the accents/diacritic in algolia places? cause What I want is to replace the accents/diacritic.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Using String.prototype.normalize(), you can remove diacritics as needed. Using your example string of Vũng Tàu, the NFD and NFKD removed the diacritics in the tests below. I wanted to see and show how each step changed the string based on the accepted answer in that question. Considering the canonical equivalence (not sure if this is a requirement), I included tests to show whether each change was equivalent to the others.

const str = "Vũng Tàu";
const nfdStr = str.normalize("NFD");
const nfcStr = str.normalize("NFC");
const nfkcStr = str.normalize("NFKC");
const nfkdStr = str.normalize("NFKD");
console.log("nfdStr   ", nfdStr);
console.log("nfcStr   ", nfcStr);
console.log("nfkcStr  ", nfkcStr);
console.log("nfkdStr  ", nfkdStr);
console.log("");

const nfdStr1 = nfdStr.replace(/[\u0300-\u036f]/g, "");
const nfcStr1 = nfcStr.replace(/[\u0300-\u036f]/g, "");
const nfkcStr1 = nfkcStr.replace(/[\u0300-\u036f]/g, "");
const nfkdStr1 = nfkdStr.replace(/[\u0300-\u036f]/g, "");
console.log("nfdStr1  ", nfdStr1);
console.log("nfcStr1  ", nfcStr1);
console.log("nfkcStr1 ", nfkcStr1);
console.log("nfkdStr1 ", nfkdStr1);
console.log("");

const nfdStr2 = nfdStr.replace(/\p{Diacritic}/gu, "");
const nfcStr2 = nfcStr.replace(/\p{Diacritic}/gu, "");
const nfkcStr2 = nfkcStr.replace(/\p{Diacritic}/gu, "");
const nfkdStr2 = nfkdStr.replace(/\p{Diacritic}/gu, "");
console.log("nfdStr2  ", nfdStr2);
console.log("nfcStr2  ", nfcStr2);
console.log("nfkcStr2 ", nfkcStr2);
console.log("nfkdStr2 ", nfkdStr2);
console.log("");

console.log(nfdStr === nfdStr1, nfdStr == nfdStr2, nfdStr1 === nfdStr2);
console.log(nfcStr === nfcStr1, nfcStr == nfcStr2, nfcStr1 === nfcStr2);
console.log(nfkcStr === nfkcStr1, nfkcStr == nfkcStr2, nfkcStr1 === nfkcStr2);
console.log(nfkdStr === nfkdStr1, nfkdStr == nfkdStr2, nfkdStr1 === nfkdStr2);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!