[英]Is there a much more cleaner and shorter way to check if string is empty?
I am working on my express server and I am trying to validate some query parameters.我正在我的快递服务器上工作,我正在尝试验证一些查询参数。 For example I can have query parameter
date
which might be null or be an empty string.例如,我可以有查询参数
date
,它可能是 null 或空字符串。 Now the current validation is like this现在当前的验证是这样的
if(req.query.date && req.query.date !== '')
Is there like a function or a library that I can use like _lodash
to keep things more neat?有没有像 function 或像
_lodash
这样我可以使用的库来保持更整洁?
Your solution is already neat, you can just simplify it to您的解决方案已经很简洁了,您可以将其简化为
if(req.query.date)
Try not overuse lodash
or other packages, you can write these things by yourself, but all these redundant packages just flood your bundle and make it heavier.尽量不要过度使用
lodash
或其他包,你可以自己编写这些东西,但是所有这些多余的包只会淹没你的包,让它变得更重。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.