Lodash:有没有办法用 lodash 将单词保持重音大写?

Posted

技术标签:

【中文标题】Lodash:有没有办法用 lodash 将单词保持重音大写?【英文标题】:Lodash: is there a way to uppercase a word keeping accents with lodash? 【发布时间】:2021-04-01 02:16:37 【问题描述】:

是否有一个lodash 函数可以转换"répété" => "RÉPÉTÉ" 而不是"REPETE",就像uppercase 函数所做的那样?

如果没有,用 javascript 执行此操作的简单方法是什么?

【问题讨论】:

【参考方案1】:

您有一个名为“toLocaleUpperCase()”的本机函数

你可以这样做:

const str = 'répété';
const ret = str.toLocaleUpperCase();
alert(ret);

文档:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase

【讨论】:

【参考方案2】:

你可以使用toLocaleUpperCase()

const str = 'répété';
const ret = str.toLocaleUpperCase();
console.log(ret);

【讨论】:

以上是关于Lodash:有没有办法用 lodash 将单词保持重音大写?的主要内容,如果未能解决你的问题,请参考以下文章