diff --git a/README.md b/README.md index 854a656..a19fbc7 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,9 @@ XEUtils 提供一套实用的函数,支持常用基础函数、支持任意格式的日期处理函数,cookie操作函数等... ## 兼容性 -支持 IE8+、Edge、Chrome、Firefox、Opera、Safari等... +![IE](https://raw.github.com/alrra/browser-logos/master/src/archive/internet-explorer_7-8/internet-explorer_7-8_48x48.png) | ![Chrome](https://raw.github.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png) | ![Firefox](https://raw.github.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png) | ![Opera](https://raw.github.com/alrra/browser-logos/master/src/opera/opera_48x48.png) | ![Safari](https://raw.github.com/alrra/browser-logos/master/src/safari/safari_48x48.png) +--- | --- | --- | --- | --- | +7+ ✔ | ✔ | ✔ | ✔ | ✔ | ## CDN 安装 使用 script 方式安装,XEUtils 会定义为全局变量 diff --git a/dist/xe-utils.js b/dist/xe-utils.js index 8012dc4..c803cf7 100644 --- a/dist/xe-utils.js +++ b/dist/xe-utils.js @@ -1,5 +1,5 @@ /** - * xe-utils.js v1.5.6 + * xe-utils.js v1.5.7 * (c) 2017-2018 Xu Liangzhan * ISC License. * @preserve @@ -1343,7 +1343,7 @@ coreMethods.objectAssign(XEUtils, { mixin: mixin, - version: '1.5.6', + version: '1.5.7', $name: 'XEUtils' }) diff --git a/dist/xe-utils.min.js b/dist/xe-utils.min.js index 9403cfd..c446a7e 100644 --- a/dist/xe-utils.min.js +++ b/dist/xe-utils.min.js @@ -1,7 +1,7 @@ /** - * xe-utils.js v1.5.6 + * xe-utils.js v1.5.7 * (c) 2017-2018 Xu Liangzhan * ISC License. * @preserve */ -!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):n.XEUtils=t()}(this,function(){"use strict";function n(n){return"function"==typeof n}function t(n){return"string"==typeof n}function e(n){return"number"==typeof n}function r(n){return"object"==typeof n}function i(n){return!!n&&n.constructor===Object}function o(n){return!!n&&n.constructor===Date}function u(n){return"undefined"!=typeof Symbol&&Symbol.isSymbol?Symbol.isSymbol(n):"symbol"==typeof n}function a(n){return function(e,r){if(e){if(t(e)||W(e))return n(e,r);for(var i in e)if(r===e[i])return i}return-1}}function f(n,t){return-1!==z(n,t)}function c(n){var t=[];if(n){if(Object.keys)return Object.keys(n);y(n,function(n,e){t.push(e)})}return t}function s(n){if(Object.values)return n?Object.values(n):[];var t=[];return g(c(n),function(e){t.push(n[e])}),t}function l(n){if(Object.entries)return n?Object.entries(n):[];var t=[];return g(c(n),function(e){t.push([e,n[e]])}),t}function h(n){return s(n)[0]}function p(n){var t=s(n);return t[t.length-1]}function y(n,t,e){for(var r in n)n.hasOwnProperty(r)&&t.call(e||this,n[r],r,n)}function g(n,t,e){for(var r=0,i=n.length||0;r<i;r++)t.call(e||this,n[r],r,n)}function m(t,e,r){return t?W(t)?n(t.forEach)?t.forEach(e,r||this):g(t,e,r||this):y(t,e,r||this):t}function d(n){return i(n)?function(n){var t={};return m(n,function(n,e){t[e]=d(n)}),t}(n):W(n)?function(n){return O(n,function(n,t){return d(n)})}(n):n}function v(n){var t=[];return W(n)&&g(n,function(n){t.includes(n)||t.push(n)}),t}function b(){for(var n=[],t=0,e=arguments.length;t<e;t++)n=n.concat(arguments[t]);return v(n)}function S(t,e,r){return W(t)?t.sort(e?n(e)?e.bind(r||this):function(n,t){return n[e]>t[e]?1:-1}:function(n,t){return n>t?1:-1}):t}function M(n){for(var t=[],e=s(n),r=e.length-1;r>=0;r--){var i=r>0?R(0,r):0;t.push(e[i]),e.splice(i,1)}return t}function D(n,t){var e=M(n);return 1===arguments.length?e[0]:(t<e.length&&(e.length=t||0),e)}function w(n,t,e){if(n){if(W(n))return n.some(t,e||this);for(var r in n)if(n.hasOwnProperty(r)&&t.call(e||this,n[r],r,n))return!0}return!1}function x(n,t,e){if(n){if(W(n))return n.every(t,e||this);for(var r in n)if(n.hasOwnProperty(r)&&!t.call(e||this,n[r],r,n))return!1}return!0}function E(n,t,e){if(n){if(W(n))return n.filter(t,e||this);var r={};return m(n,function(i,o){t.call(e||this,i,o,n)&&(r[o]=i)}),r}return[]}function j(n,t,e){if(n){if(W(n))return n.find(t,e||this);for(var r in n)if(n.hasOwnProperty(r)&&t.call(e||this,n[r],r,n))return n[r]}}function O(n,t,e){var r=[];if(n){if(W(n))return n.map(t,e||this);m(n,function(){r.push(t.apply(e||this,arguments))})}return r}function T(n,e){if(n){if(o(n))return n;if(!C(n))return new Date(n);if(t(n)){e=e||"yyyy-MM-dd HH:mm:ss.SSS";var r=[];return g(yn,function(t){for(var i,o,u=0,a=t.rules,f=a.length;u<f;u++){if(i=a[u],(o=e.indexOf(i[0]))>-1){r.push(parseFloat(n.substring(o,o+i[1])||0)+(t.offset||0));break}u===f-1&&r.push(0)}}),new Date(r[0],r[1],r[2],r[3],r[4],r[5],r[6])}}return"Invalid Date"}function F(n,t,e){var r=T(n),i=t&&!C(t)?t:0,o=r.getHours(),u=r.getMinutes(),a=r.getSeconds(),f=r.getMilliseconds();if("first"===e){var c=r.getFullYear(),s=r.getMonth();return(s+=i)<0?new Date(c-Math.ceil((s=Math.abs(s))/12),12-(s%12||1),1,o,u,a,f):new Date(c+Math.floor(s/12),s%12,1,o,u,a,f)}if("last"===e)return new Date(F(r,i+1,"first").getTime()-864e5);var l=r.getDate(),h=F(r,i,"first"),p=h.getMonth();for(h.setDate(l);p<h.getMonth();)h.setDate(--l);return h}function I(n){var t=new RegExp("(?:"+c(n).join("|")+")","g");return function(e){return String(e||"").replace(t,function(t){return n[t]})}}function R(n,t){return n>=t?n:(n>>=0)+Math.round(Math.random()*((t||9)-n))}function H(t,e){return n(e)?S(O(t,e,this)):S(t,e)}function N(){return H.apply(this,arguments)[0]}function k(){return H.apply(this,arguments).reverse()[0]}function U(n,t,e){var i=[];if(W(n)?i=n:arguments.length>1?i=[X({name:n,value:t},e)]:r(n)&&(i=[n]),!(i.length>0)){var o={};return document.cookie&&g(document.cookie.split("; "),function(n){var t=n.split("=");o[decodeURIComponent(t[0])]=decodeURIComponent(t[1]||"")}),1===arguments.length?o[n]:o}g(i,function(n){var t=X({},n),e=[];t.name&&(e.push(encodeURIComponent(t.name)+"="+encodeURIComponent(JSON.stringify(t.value))),void 0!==t.expires&&(t.expires=new Date((new Date).getTime()+864e5*parseFloat(t.expires)).toUTCString()),g(["expires","path","domain","secure"],function(n){void 0!==t[n]&&e.push(n+"="+t[n])})),document.cookie=e.join("; ")})}function $(n){var t={},e=n.split("?")[1]||"";return e&&g(e.split("&"),function(n){var e=n.split("=");t[decodeURIComponent(e[0])]=decodeURIComponent(e[1]||"")}),t}function q(){}function A(n){Sn.objectEach(n,function(n,t){q[t]=Sn.isFunction(n)?function(){var t=n.apply(q.$context,arguments);return q.$context=null,t}:n})}var C=window.isNaN,J=window.isFinite,W=Array.isArray||function(n){return"[object Array]"===Object.prototype.toString.call(n)},P=Number.isInteger,Y=0,z=a(function(n,t){if(n.indexOf)return n.indexOf(t);for(var e=0,r=n.length;e<r;e++)if(t===n[e])return e}),B=a(function(n,t){if(n.lastIndexOf)return n.lastIndexOf(t);for(var e=n.length-1;e>=0;e--)if(t===n[e])return e;return-1}),L=f,X=Object.assign||function(n){if(n)for(var t,e=1,r=arguments.length;e<r;e++)t=arguments[e],g(c(arguments[e]),function(e){n[e]=t[e]});return n},K=X,V=X,G=c,Q=s,Z=l,_=h,nn=p,tn=v,en=b,rn=S,on=M,un=D,an=w,fn=x,cn=E,sn=j,ln=O,hn=Date.now||function(){return(new Date).getTime()},pn=hn,yn=[{rules:[["yyyy",4],["yyy",3],["yy",2]]},{rules:[["MM",2],["M",1]],offset:-1},{rules:[["dd",2],["d",1]]},{rules:[["HH",2],["H",1]]},{rules:[["mm",2],["m",1]]},{rules:[["ss",2],["s",1]]},{rules:[["SSS",3],["SS",2],["S",1]]}],gn=[["yyyy",31536e6],["MM",2592e6],["dd",864e5],["HH",36e5],["mm",6e4],["ss",1e3],["S",0]],mn={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},dn={};g(c(mn),function(n){dn[mn[n]]=n});var vn=I(mn),bn=I(dn),Sn={isNaN:C,isFinite:J,isFloat:function(n){return null!==n&&!C(n)&&!P(n)},isInteger:P,isFunction:n,isBoolean:function(n){return"boolean"==typeof n},isString:t,isRegExp:function(n){return!!n&&n.constructor===RegExp},isObject:r,isError:function(n){return!!n&&n.constructor===Error},isTypeError:function(n){return!!n&&n.constructor===TypeError},isEmpty:function(n){if(0===n||!e(n)){for(var t in n)return!1;return!0}return!1},isNull:function(n){return null===n},isSymbol:u,isArguments:function(n){return"[object Arguments]"===String(n)},isElement:function(n){return n&&t(n.nodeName)&&e(n.nodeType)},isDocument:function(n){return n&&9===n.nodeType},isWindow:function(n){return n&&n===n.window},isFormData:function(n){return"undefined"!=typeof FormData&&n instanceof FormData},isLeapYear:function(n){var t=(n?T(n):new Date).getFullYear();return t%4==0&&(t%100!=0||t%400==0)},getType:function(n){return null===n?""+n:u(n)?"symbol":o(n)?"date":W(n)?"array":typeof n},uniqueId:function(){return++Y},getSize:function(n){var e=0;return t(n)||W(n)?n.length:(m(n,function(){e++}),e)},lastIndexOf:B,includes:f,contains:L,objectAssign:X,assign:K,extend:V,stringToJson:function(n){if(r(n))return n;if(t(n))try{return JSON.parse(n)}catch(n){console.error(n)}return{}},jsonToString:function(n){if(r(n))try{return JSON.stringify(n)}catch(n){console.error(n)}return n?""+n:""},objectKeys:c,keys:G,objectValues:s,values:Q,objectEntries:l,entries:Z,arrayFirst:h,first:_,arrayLast:p,last:nn,objectEach:y,arrayEach:g,each:m,groupBy:function(e,r,i){var o,u,a={};return e&&(t(r)?(u=r,r=null):r=n(r)?r.bind(i||this):u=null,m(e,function(n,t){o=r?r(n,t,e):u?n[u]:n,a[o]?a[o].push(n):a[o]=[n]})),a},objectMap:function(n,t,e){var r={};return m(n,function(i,o){r[o]=t.call(e||this,i,o,n)}),r},clone:function(n,t){return t?d(n):X(i(n)?{}:[],n)},arrayUniq:v,uniq:tn,arrayUnion:b,union:en,arraySort:S,sort:rn,arrayShuffle:M,shuffle:on,arraySample:D,sample:un,arraySome:w,some:an,arrayEvery:x,every:fn,arrayFilter:E,filter:cn,arrayFind:j,find:sn,arrayMap:O,map:ln,timestamp:hn,now:pn,stringToDate:T,dateToString:function(n,t){if(n){if(n=T(n),o(n)){var e=t||"yyyy-MM-dd HH:mm:ss",r=["日","一","二","三","四","五","六"],i={"q+":Math.floor((n.getMonth()+3)/3),"M+":n.getMonth()+1,"E+":n.getDay(),"d+":n.getDate(),"H+":n.getHours(),"m+":n.getMinutes(),"s+":n.getSeconds(),S:n.getMilliseconds()};return/(y+)/.test(e)&&(e=e.replace(RegExp.$1,(""+n.getFullYear()).substr(4-RegExp.$1.length))),g(c(i),function(n){if(new RegExp("("+n+")").test(e)){var t=""+i[n];e=e.replace(RegExp.$1,"q+"===n||"E+"===n?r[t]:1===RegExp.$1.length?t:("00"+t).substr(t.length))}}),e}return n}return""},getWhatMonth:F,getWhatWeek:function(n,t,e){var r=Number(/^[0-7]$/.test(e)?e:0),i=T(n),o=i.getDay(),u=i.getTime()+864e5*((0===r?7:r)-(0===o?7:o));return t&&!C(t)&&(u+=6048e5*t),new Date(u)},getWhatDay:function(n,t){return new Date(T(n).getTime()+(t&&!C(t)?864e5*t:0))},getDaysOfMonth:function(n,t){return Math.floor((F(n,t,"last").getTime()-F(n,t,"first").getTime())/864e5)+1},getDateDiff:function(n,t,e){var r={},i=T(n).getTime(),o=t?T(t).getTime():new Date;if(i<o)for(var u,a=o-i,f=e&&e.length>0?e:gn,c=0,s=f.length;c<s;c++)a>=(u=f[c])[1]&&(c===s-1?a&&(r[u[0]]=a):(r[u[0]]=Math.floor(a/u[1]),a-=r[u[0]]*u[1]));return r},escape:vn,unescape:bn,getRandom:R,arrayMin:N,min:N,arrayMax:k,max:k};X(U,{setItem:function(n,t){U(n,t)},getItem:function(n){return U(n)},removeItem:function(n){U(n,null,{expires:-1})},getJSON:function(){return U()}});var Mn=location,Dn={browse:function(){var n={},t=document.body||document.documentElement;return g(["webkit","khtml","moz","ms","o"],function(e){n["-"+e]=!!t[e+"MatchesSelector"]}),n},cookie:U,locat:function(){return{port:Mn.port,href:Mn.href,host:Mn.host,hostname:Mn.hostname,protocol:Mn.protocol,origin:Mn.origin,hash:(Mn.hash.split("#")[1]||"").split("?")[0]||"",query:$(Mn.hash),params:$(Mn.search)}}};return Sn.objectAssign(q,{mixin:A,version:"1.5.6",$name:"XEUtils"}),A(Sn),A(Dn),q}); \ No newline at end of file +!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):n.XEUtils=t()}(this,function(){"use strict";function n(n){return"function"==typeof n}function t(n){return"string"==typeof n}function e(n){return"number"==typeof n}function r(n){return"object"==typeof n}function i(n){return!!n&&n.constructor===Object}function o(n){return!!n&&n.constructor===Date}function u(n){return"undefined"!=typeof Symbol&&Symbol.isSymbol?Symbol.isSymbol(n):"symbol"==typeof n}function a(n){return function(e,r){if(e){if(t(e)||W(e))return n(e,r);for(var i in e)if(r===e[i])return i}return-1}}function f(n,t){return-1!==z(n,t)}function c(n){var t=[];if(n){if(Object.keys)return Object.keys(n);y(n,function(n,e){t.push(e)})}return t}function s(n){if(Object.values)return n?Object.values(n):[];var t=[];return g(c(n),function(e){t.push(n[e])}),t}function l(n){if(Object.entries)return n?Object.entries(n):[];var t=[];return g(c(n),function(e){t.push([e,n[e]])}),t}function h(n){return s(n)[0]}function p(n){var t=s(n);return t[t.length-1]}function y(n,t,e){for(var r in n)n.hasOwnProperty(r)&&t.call(e||this,n[r],r,n)}function g(n,t,e){for(var r=0,i=n.length||0;r<i;r++)t.call(e||this,n[r],r,n)}function m(t,e,r){return t?W(t)?n(t.forEach)?t.forEach(e,r||this):g(t,e,r||this):y(t,e,r||this):t}function d(n){return i(n)?function(n){var t={};return m(n,function(n,e){t[e]=d(n)}),t}(n):W(n)?function(n){return O(n,function(n,t){return d(n)})}(n):n}function v(n){var t=[];return W(n)&&g(n,function(n){t.includes(n)||t.push(n)}),t}function b(){for(var n=[],t=0,e=arguments.length;t<e;t++)n=n.concat(arguments[t]);return v(n)}function S(t,e,r){return W(t)?t.sort(e?n(e)?e.bind(r||this):function(n,t){return n[e]>t[e]?1:-1}:function(n,t){return n>t?1:-1}):t}function M(n){for(var t=[],e=s(n),r=e.length-1;r>=0;r--){var i=r>0?R(0,r):0;t.push(e[i]),e.splice(i,1)}return t}function D(n,t){var e=M(n);return 1===arguments.length?e[0]:(t<e.length&&(e.length=t||0),e)}function w(n,t,e){if(n){if(W(n))return n.some(t,e||this);for(var r in n)if(n.hasOwnProperty(r)&&t.call(e||this,n[r],r,n))return!0}return!1}function x(n,t,e){if(n){if(W(n))return n.every(t,e||this);for(var r in n)if(n.hasOwnProperty(r)&&!t.call(e||this,n[r],r,n))return!1}return!0}function E(n,t,e){if(n){if(W(n))return n.filter(t,e||this);var r={};return m(n,function(i,o){t.call(e||this,i,o,n)&&(r[o]=i)}),r}return[]}function j(n,t,e){if(n){if(W(n))return n.find(t,e||this);for(var r in n)if(n.hasOwnProperty(r)&&t.call(e||this,n[r],r,n))return n[r]}}function O(n,t,e){var r=[];if(n){if(W(n))return n.map(t,e||this);m(n,function(){r.push(t.apply(e||this,arguments))})}return r}function T(n,e){if(n){if(o(n))return n;if(!C(n))return new Date(n);if(t(n)){e=e||"yyyy-MM-dd HH:mm:ss.SSS";var r=[];return g(yn,function(t){for(var i,o,u=0,a=t.rules,f=a.length;u<f;u++){if(i=a[u],(o=e.indexOf(i[0]))>-1){r.push(parseFloat(n.substring(o,o+i[1])||0)+(t.offset||0));break}u===f-1&&r.push(0)}}),new Date(r[0],r[1],r[2],r[3],r[4],r[5],r[6])}}return"Invalid Date"}function F(n,t,e){var r=T(n),i=t&&!C(t)?t:0,o=r.getHours(),u=r.getMinutes(),a=r.getSeconds(),f=r.getMilliseconds();if("first"===e){var c=r.getFullYear(),s=r.getMonth();return(s+=i)<0?new Date(c-Math.ceil((s=Math.abs(s))/12),12-(s%12||1),1,o,u,a,f):new Date(c+Math.floor(s/12),s%12,1,o,u,a,f)}if("last"===e)return new Date(F(r,i+1,"first").getTime()-864e5);var l=r.getDate(),h=F(r,i,"first"),p=h.getMonth();for(h.setDate(l);p<h.getMonth();)h.setDate(--l);return h}function I(n){var t=new RegExp("(?:"+c(n).join("|")+")","g");return function(e){return String(e||"").replace(t,function(t){return n[t]})}}function R(n,t){return n>=t?n:(n>>=0)+Math.round(Math.random()*((t||9)-n))}function H(t,e){return n(e)?S(O(t,e,this)):S(t,e)}function N(){return H.apply(this,arguments)[0]}function k(){return H.apply(this,arguments).reverse()[0]}function U(n,t,e){var i=[];if(W(n)?i=n:arguments.length>1?i=[X({name:n,value:t},e)]:r(n)&&(i=[n]),!(i.length>0)){var o={};return document.cookie&&g(document.cookie.split("; "),function(n){var t=n.split("=");o[decodeURIComponent(t[0])]=decodeURIComponent(t[1]||"")}),1===arguments.length?o[n]:o}g(i,function(n){var t=X({},n),e=[];t.name&&(e.push(encodeURIComponent(t.name)+"="+encodeURIComponent(JSON.stringify(t.value))),void 0!==t.expires&&(t.expires=new Date((new Date).getTime()+864e5*parseFloat(t.expires)).toUTCString()),g(["expires","path","domain","secure"],function(n){void 0!==t[n]&&e.push(n+"="+t[n])})),document.cookie=e.join("; ")})}function $(n){var t={},e=n.split("?")[1]||"";return e&&g(e.split("&"),function(n){var e=n.split("=");t[decodeURIComponent(e[0])]=decodeURIComponent(e[1]||"")}),t}function q(){}function A(n){Sn.objectEach(n,function(n,t){q[t]=Sn.isFunction(n)?function(){var t=n.apply(q.$context,arguments);return q.$context=null,t}:n})}var C=window.isNaN,J=window.isFinite,W=Array.isArray||function(n){return"[object Array]"===Object.prototype.toString.call(n)},P=Number.isInteger,Y=0,z=a(function(n,t){if(n.indexOf)return n.indexOf(t);for(var e=0,r=n.length;e<r;e++)if(t===n[e])return e}),B=a(function(n,t){if(n.lastIndexOf)return n.lastIndexOf(t);for(var e=n.length-1;e>=0;e--)if(t===n[e])return e;return-1}),L=f,X=Object.assign||function(n){if(n)for(var t,e=1,r=arguments.length;e<r;e++)t=arguments[e],g(c(arguments[e]),function(e){n[e]=t[e]});return n},K=X,V=X,G=c,Q=s,Z=l,_=h,nn=p,tn=v,en=b,rn=S,on=M,un=D,an=w,fn=x,cn=E,sn=j,ln=O,hn=Date.now||function(){return(new Date).getTime()},pn=hn,yn=[{rules:[["yyyy",4],["yyy",3],["yy",2]]},{rules:[["MM",2],["M",1]],offset:-1},{rules:[["dd",2],["d",1]]},{rules:[["HH",2],["H",1]]},{rules:[["mm",2],["m",1]]},{rules:[["ss",2],["s",1]]},{rules:[["SSS",3],["SS",2],["S",1]]}],gn=[["yyyy",31536e6],["MM",2592e6],["dd",864e5],["HH",36e5],["mm",6e4],["ss",1e3],["S",0]],mn={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},dn={};g(c(mn),function(n){dn[mn[n]]=n});var vn=I(mn),bn=I(dn),Sn={isNaN:C,isFinite:J,isFloat:function(n){return null!==n&&!C(n)&&!P(n)},isInteger:P,isFunction:n,isBoolean:function(n){return"boolean"==typeof n},isString:t,isRegExp:function(n){return!!n&&n.constructor===RegExp},isObject:r,isError:function(n){return!!n&&n.constructor===Error},isTypeError:function(n){return!!n&&n.constructor===TypeError},isEmpty:function(n){if(0===n||!e(n)){for(var t in n)return!1;return!0}return!1},isNull:function(n){return null===n},isSymbol:u,isArguments:function(n){return"[object Arguments]"===String(n)},isElement:function(n){return n&&t(n.nodeName)&&e(n.nodeType)},isDocument:function(n){return n&&9===n.nodeType},isWindow:function(n){return n&&n===n.window},isFormData:function(n){return"undefined"!=typeof FormData&&n instanceof FormData},isLeapYear:function(n){var t=(n?T(n):new Date).getFullYear();return t%4==0&&(t%100!=0||t%400==0)},getType:function(n){return null===n?""+n:u(n)?"symbol":o(n)?"date":W(n)?"array":typeof n},uniqueId:function(){return++Y},getSize:function(n){var e=0;return t(n)||W(n)?n.length:(m(n,function(){e++}),e)},lastIndexOf:B,includes:f,contains:L,objectAssign:X,assign:K,extend:V,stringToJson:function(n){if(r(n))return n;if(t(n))try{return JSON.parse(n)}catch(n){console.error(n)}return{}},jsonToString:function(n){if(r(n))try{return JSON.stringify(n)}catch(n){console.error(n)}return n?""+n:""},objectKeys:c,keys:G,objectValues:s,values:Q,objectEntries:l,entries:Z,arrayFirst:h,first:_,arrayLast:p,last:nn,objectEach:y,arrayEach:g,each:m,groupBy:function(e,r,i){var o,u,a={};return e&&(t(r)?(u=r,r=null):r=n(r)?r.bind(i||this):u=null,m(e,function(n,t){o=r?r(n,t,e):u?n[u]:n,a[o]?a[o].push(n):a[o]=[n]})),a},objectMap:function(n,t,e){var r={};return m(n,function(i,o){r[o]=t.call(e||this,i,o,n)}),r},clone:function(n,t){return t?d(n):X(i(n)?{}:[],n)},arrayUniq:v,uniq:tn,arrayUnion:b,union:en,arraySort:S,sort:rn,arrayShuffle:M,shuffle:on,arraySample:D,sample:un,arraySome:w,some:an,arrayEvery:x,every:fn,arrayFilter:E,filter:cn,arrayFind:j,find:sn,arrayMap:O,map:ln,timestamp:hn,now:pn,stringToDate:T,dateToString:function(n,t){if(n){if(n=T(n),o(n)){var e=t||"yyyy-MM-dd HH:mm:ss",r=["日","一","二","三","四","五","六"],i={"q+":Math.floor((n.getMonth()+3)/3),"M+":n.getMonth()+1,"E+":n.getDay(),"d+":n.getDate(),"H+":n.getHours(),"m+":n.getMinutes(),"s+":n.getSeconds(),S:n.getMilliseconds()};return/(y+)/.test(e)&&(e=e.replace(RegExp.$1,(""+n.getFullYear()).substr(4-RegExp.$1.length))),g(c(i),function(n){if(new RegExp("("+n+")").test(e)){var t=""+i[n];e=e.replace(RegExp.$1,"q+"===n||"E+"===n?r[t]:1===RegExp.$1.length?t:("00"+t).substr(t.length))}}),e}return n}return""},getWhatMonth:F,getWhatWeek:function(n,t,e){var r=Number(/^[0-7]$/.test(e)?e:0),i=T(n),o=i.getDay(),u=i.getTime()+864e5*((0===r?7:r)-(0===o?7:o));return t&&!C(t)&&(u+=6048e5*t),new Date(u)},getWhatDay:function(n,t){return new Date(T(n).getTime()+(t&&!C(t)?864e5*t:0))},getDaysOfMonth:function(n,t){return Math.floor((F(n,t,"last").getTime()-F(n,t,"first").getTime())/864e5)+1},getDateDiff:function(n,t,e){var r={},i=T(n).getTime(),o=t?T(t).getTime():new Date;if(i<o)for(var u,a=o-i,f=e&&e.length>0?e:gn,c=0,s=f.length;c<s;c++)a>=(u=f[c])[1]&&(c===s-1?a&&(r[u[0]]=a):(r[u[0]]=Math.floor(a/u[1]),a-=r[u[0]]*u[1]));return r},escape:vn,unescape:bn,getRandom:R,arrayMin:N,min:N,arrayMax:k,max:k};X(U,{setItem:function(n,t){U(n,t)},getItem:function(n){return U(n)},removeItem:function(n){U(n,null,{expires:-1})},getJSON:function(){return U()}});var Mn=location,Dn={browse:function(){var n={},t=document.body||document.documentElement;return g(["webkit","khtml","moz","ms","o"],function(e){n["-"+e]=!!t[e+"MatchesSelector"]}),n},cookie:U,locat:function(){return{port:Mn.port,href:Mn.href,host:Mn.host,hostname:Mn.hostname,protocol:Mn.protocol,origin:Mn.origin,hash:(Mn.hash.split("#")[1]||"").split("?")[0]||"",query:$(Mn.hash),params:$(Mn.search)}}};return Sn.objectAssign(q,{mixin:A,version:"1.5.7",$name:"XEUtils"}),A(Sn),A(Dn),q}); \ No newline at end of file diff --git a/index.js b/index.js index ded650e..5523004 100644 --- a/index.js +++ b/index.js @@ -20,7 +20,7 @@ function mixin (methods) { coreMethods.objectAssign(XEUtils, { mixin: mixin, - version: '1.5.6', + version: '1.5.7', $name: 'XEUtils' }) diff --git a/package.json b/package.json index 4089e5f..f503727 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xe-utils", - "version": "1.5.6", + "version": "1.5.7", "description": "XEUtils 函数库", "main": "index.js", "scripts": {