js和node判断值是否为空类似PHP的empty()
module.exports.is_empty=(str)=>{
String.prototype.trim ? String.prototype.trim : String.prototype.trim=function(){return this.replace(/^\s+|\s+$/gm,'')}
str=str.trim();
if(typeof(str)==='undefined' || str===null || str.length===0)
return true
return false;
}
export const is_empty=(str)=>{
String.prototype.trim ? String.prototype.trim : String.prototype.trim=function(){return this.replace(/^\s+|\s+$/gm,'')}
str=str.trim();
if(typeof(str)==='undefined' || str===null || str.length===0)
return true
return false;
}
使用方法
let is_empty=require("~/is_empty.js");
import {is_empty} from "~/is_empty.js";
is_empty(webValue)