es.shim/lib/global.js

48 lines
951 B
JavaScript

/**
*
* @authors yutent (yutent@doui.cc)
* @date 2017-02-27 21:58:03
*
*/
"use strict";
if(!global.gmdate){
global.gmdate = function (str, stamp){
let oDate;
if(!stamp || arguments.length < 2){
oDate = new Date()
}else if(!Date.isDate(stamp)){
if(!/[^\d]/.test(stamp)){
stamp = Number(stamp)
}
oDate = new Date(stamp);
if((oDate + '') === 'Invalid Date')
return 'Invalid Date'
}else{
oDate = stamp
}
return oDate.format(str)
}
}
if(!global.empty){
global.empty = function(o){
if(o === undefined || o === null || o === '' || !o || o === 0){
return true
}else if(typeof o === 'object'){
try{
return Object.empty(o)
}catch(e){}
return false
}
return false
}
}
实现部分新API, 以及一些常用的扩展方法。 nodejs和浏览器通用,
JavaScript 100%