最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Replacing special characters and normalization works differently on different environments - Stack Overflow

programmeradmin0浏览0评论

I have the following function:

  normalize = (input) => {
    return input
      .toLowerCase()
      .normalize('NFD')
      .replace(/[\u0300-\u036f]/g, '')
      .replace(/\ı/g, "i");
  }

and I use it as follows:

let places = [{
    "name": "haci osman"
}, {
    "name": "sample 2"
}, {
    "name": "sample 3"
}];

let candidate = {
    "placeName": "Hacı osman"
};

let exists = (places|| []).some(place=> this.normalize(candidate?.placeName).includes(this.normalize(place.name)));

items and candidate are fethed from API. This works perfectly on my local machine, but fails on the customer environment. At this point, I'm too blind to figure out what I'm missing. I expect the exists variable to be equal to true on the server/customer environment as well, but it is not. Why?

  normalize = (input) => {
    return input
      .toLowerCase()
      .normalize('NFD')
      .replace(/[\u0300-\u036f]/g, '')
      .replace(/\ı/g, "i");
  }


let places = [{
    "name": "haci osman"
}, {
    "name": "sample 2"
}, {
    "name": "sample 3"
}];

let candidate = {
    "placeName": "Hacı osman"
};

let exists = (places|| []).some(place=> this.normalize(candidate?.placeName).includes(this.normalize(place.name)));
console.log(exists);

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论