Lodash标题案例(每个单词的大写第一个字母) [英] Lodash title case (uppercase first letter of every word)

查看:113
本文介绍了Lodash标题案例(每个单词的大写第一个字母)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看lodash文档和其他Stack Overflow问题 - 同时是完成此任务的几种原生JavaScript方法,有没有一种方法可以使用纯粹的 lodash函数(或至少现有的原型函数)将字符串转换为标题大小写,这样我就不会不必使用正则表达式或定义新函数吗?

I'm looking through the lodash docs and other Stack Overflow questions - while there are several native JavaScript ways of accomplishing this task, is there a way I can convert a string to title case using purely lodash functions (or at least existing prototypal functions) so that I don't have to use a regular expression or define a new function?

例如

This string ShouLD be ALL in title CASe

应该成为

This String Should Be All In Title Case


推荐答案

这可以通过 startCase

This can be done with a small modification of startCase:

_.startCase(_.toLower(str));

console.log(_.startCase(_.toLower("This string ShouLD be ALL in title CASe")));

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.13.1/lodash.min.js"></script>

这篇关于Lodash标题案例(每个单词的大写第一个字母)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆