diff --git a/lib/index.js b/lib/index.js index 9ef4c88..8fe0f44 100644 --- a/lib/index.js +++ b/lib/index.js @@ -2,7 +2,8 @@ const lowerCase = require('./lower-case') const specials = require('./specials') -const regex = /(?:(?:(\s?(?:^|[.\(\)!?;:"-])\s*)(\w))|(\w))(\w*[’']*\w*)/g +const word = "[^\\s'’\\(\\)!?;:\"-]" +const regex = new RegExp(`(?:(?:(\\s?(?:^|[.\\(\\)!?;:"-])\\s*)(${word}))|(${word}))(${word}*[’']*${word}*)`, "g") const convertToRegExp = specials => specials.map(s => [new RegExp(`\\b${s}\\b`, 'gi'), s]) diff --git a/test/index.js b/test/index.js index 28605fe..8cfd8d1 100644 --- a/test/index.js +++ b/test/index.js @@ -93,3 +93,25 @@ test("should capitalize the last word regardless of syntax", t => { to = "XYZ: What Is It Good For" t.is(title(from, { special: ["XYZ"] }), to) }) + +test("supports international characters", t => { + let from = "çeşme city" + let to = "Çeşme City" + t.is(title(from), to) + + from = "la niña esta aquí" + to = "La Niña Esta Aquí" + t.is(title(from), to) + + from = "forhandlingsmøde" + to = "Forhandlingsmøde" + t.is(title(from), to) + + from = "đội" + to = "Đội" + t.is(title(from), to) + + from = "tuyển" + to = "Tuyển" + t.is(title(from), to) +}) \ No newline at end of file