From d724d657608ff1f951067f08d017c57f999ee6d9 Mon Sep 17 00:00:00 2001 From: Xu Liangzhan Date: Sat, 28 Apr 2018 23:15:23 +0800 Subject: [PATCH] 1.5.21 --- dist/xe-utils.js | 43 +++++++++++++++++++++++++++++++++---------- dist/xe-utils.min.js | 2 +- src/method/browse.js | 32 ++++++++++++++++++++++++++------ src/method/locat.js | 11 +++++++---- 4 files changed, 67 insertions(+), 21 deletions(-) diff --git a/dist/xe-utils.js b/dist/xe-utils.js index d9d86db..af5758d 100644 --- a/dist/xe-utils.js +++ b/dist/xe-utils.js @@ -909,17 +909,37 @@ clone: clone } + function isMobile () { + var agents = ['Android', 'webOS', 'iPhone', 'iPad', 'iPod', 'SymbianOS', 'BlackBerry', 'Windows Phone'] + for (var userAgentInfo = navigator.userAgent, i = 0; i < agents.length; i++) { + if (userAgentInfo.indexOf(agents[i]) > 0) { + return true + } + } + return false + } + /** * 获取浏览器内核 * @return Object */ function browse () { - var result = {} - if (typeof document !== 'undefined') { - var $body = document.body || document.documentElement - baseExports.arrayEach(['webkit', 'khtml', 'moz', 'ms', 'o'], function (core) { - result['-' + core] = !!$body[core + 'MatchesSelector'] - }) + var result = { + isNode: false, + isMobile: false, + isPC: false + } + if (typeof window === 'undefined' && typeof process !== 'undefined') { + result.nodeJS = true + } else { + result.isMobile = isMobile() + result.isPC = !result.isMobile + if (typeof document !== 'undefined') { + var $body = document.body || document.documentElement + baseExports.arrayEach(['webkit', 'khtml', 'moz', 'ms', 'o'], function (core) { + result['-' + core] = !!$body[core + 'MatchesSelector'] + }) + } } return result } @@ -1244,13 +1264,16 @@ } function getLocatOrigin () { - return $locat.origin || ($locat.protocol + '//' + $locat.host) + return $locat ? ($locat.origin || ($locat.protocol + '//' + $locat.host)) : '' } function getBaseURL () { - var pathname = $locat.pathname - var lastIndex = baseExports.lastIndexOf(pathname, '/') + 1 - return getLocatOrigin() + (lastIndex === pathname.length ? pathname : pathname.substring(0, lastIndex)) + if ($locat) { + var pathname = $locat.pathname + var lastIndex = baseExports.lastIndexOf(pathname, '/') + 1 + return getLocatOrigin() + (lastIndex === pathname.length ? pathname : pathname.substring(0, lastIndex)) + } + return '' } function parseUrl (url) { diff --git a/dist/xe-utils.min.js b/dist/xe-utils.min.js index 99349d0..0090890 100644 --- a/dist/xe-utils.min.js +++ b/dist/xe-utils.min.js @@ -4,4 +4,4 @@ * ISC License. * @preserve */ -!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.XEUtils=n()}(this,function(){"use strict";function t(){}function n(t){var n=[];return nt.isArray(t)&&nt.arrayEach(t,function(t){n.includes(t)||n.push(t)}),n}function e(){for(var t=[],e=0,r=arguments.length;ee[n]?1:-1}:function(t,n){return t>n?1:-1}):t}function i(t){for(var n=[],e=nt.objectValues(t),r=e.length-1;r>=0;r--){var i=r>0?ht.getRandom(0,r):0;n.push(e[i]),e.splice(i,1)}return n}function o(t,n){var e=i(t);return 1===arguments.length?e[0]:(n1?r=[nt.objectAssign({name:t,value:n},e)]:nt.isObject(t)&&(r=[t]),!(r.length>0)){var o={};return i&&document.cookie&&nt.arrayEach(document.cookie.split("; "),function(t){var n=t.indexOf("=");o[rt(t.substring(0,n))]=rt(t.substring(n+1)||"")}),1===arguments.length?o[t]:o}i&&nt.arrayEach(r,function(t){var n=nt.objectAssign({},t),e=[];n.name&&(e.push(it(n.name)+"="+it(nt.isObject(n.value)?JSON.stringify(n.value):n.value)),void 0!==n.expires&&(n.expires=new Date((new Date).getTime()+864e5*parseFloat(n.expires)).toUTCString()),nt.arrayEach(["expires","path","domain","secure"],function(t){void 0!==n[t]&&e.push(t+"="+n[t])})),document.cookie=e.join("; ")})}function I(t,n){if(t){if(nt.isDate(t))return t;if(!isNaN(t))return new Date(t);if(nt.isString(t)){n=n||"yyyy-MM-dd HH:mm:ss.SSS";var e=[];return nt.arrayEach(at,function(r){for(var i,o,u=0,a=r.rules,c=a.length;u-1){e.push(parseFloat(t.substring(o,o+i[1])||0)+(r.offset||0));break}u===c-1&&e.push(0)}}),new Date(e[0],e[1],e[2],e[3],e[4],e[5],e[6])}}return"Invalid Date"}function k(t,n,e){var r=I(t),i=n&&!isNaN(n)?n:0,o=r.getHours(),u=r.getMinutes(),a=r.getSeconds(),c=r.getMilliseconds();if("first"===e){var s=r.getFullYear(),f=r.getMonth();return(f+=i)<0?new Date(s-Math.ceil((f=Math.abs(f))/12),12-(f%12||1),1,o,u,a,c):new Date(s+Math.floor(f/12),f%12,1,o,u,a,c)}if("last"===e)return new Date(k(r,i+1,"first").getTime()-864e5);var l=r.getDate(),h=k(r,i,"first"),y=h.getMonth();for(h.setDate(l);y=0;e--)if(n===t[e])return e;return-1}),Q=b,V=function(t){if(t){var n=arguments;if(!0!==t)return Object.assign?Object.assign.apply(Object,n):j(t,n);if(n.length>1)return t=z(t[1])?[]:{},j(t,n,!0)}return t},X=S,G=x,Z=M,_=O,tt=D,nt={isNaN:isNaN,isFinite:isFinite,isArray:z,isFloat:function(t){return null!==t&&!isNaN(t)&&!K(t)},isInteger:K,isFunction:l,isBoolean:function(t){return"boolean"==typeof t},isString:h,isNumber:y,isRegExp:function(t){return"[object RegExp]"===W.call(t)},isObject:p,isPlainObject:g,isDate:m,isError:function(t){return"[object Error]"===W.call(t)},isTypeError:function(t){return!!t&&t.constructor===TypeError},isEmpty:function(t){if(0===t||!y(t)){for(var n in t)return!1;return!0}return!1},isNull:function(t){return null===t},isSymbol:d,isArguments:function(t){return"[object Arguments]"===W.call(t)},isElement:function(t){return t&&h(t.nodeName)&&y(t.nodeType)},isDocument:function(t){return t&&9===t.nodeType&&"undefined"!=typeof document},isWindow:function(t){return t&&t===t.window&&"undefined"!=typeof window},isFormData:function(t){return"undefined"!=typeof FormData&&t instanceof FormData},isLeapYear:function(n){var e=(n?t.stringToDate(n):new Date).getFullYear();return e%4==0&&(e%100!=0||e%400==0)},getType:function(t){return null===t?""+t:d(t)?"symbol":m(t)?"date":z(t)?"array":typeof t},uniqueId:function(){return++Y},getSize:function(t){var n=0;return h(t)||z(t)?t.length:(N(t,function(){n++}),n)},lastIndexOf:L,includes:b,contains:Q,objectAssign:V,assign:V,extend:V,stringToJson:function(t){if(p(t))return t;if(h(t))try{return JSON.parse(t)}catch(t){console.error(t)}return{}},jsonToString:function(t){if(p(t))try{return JSON.stringify(t)}catch(t){console.error(t)}return t?""+t:""},objectKeys:S,keys:X,objectValues:x,values:G,objectEntries:M,entries:Z,arrayFirst:O,first:_,arrayLast:D,last:tt,objectEach:E,arrayEach:w,each:N,groupBy:function(t,n,e){var r,i,o={};return t&&(h(n)?(i=n,n=null):n=l(n)?n.bind(e||this):i=null,N(t,function(e,u){r=n?n(e,u,t):i?e[i]:e,o[r]?o[r].push(e):o[r]=[e]})),o},objectMap:function(t,n,e){var r={};return N(t,function(i,o){r[o]=n.call(e||this,i,o,t)}),r},clone:F},et={browse:function(){var t={};if("undefined"!=typeof document){var n=document.body||document.documentElement;nt.arrayEach(["webkit","khtml","moz","ms","o"],function(e){t["-"+e]=!!n[e+"MatchesSelector"]})}return t}},rt=decodeURIComponent,it=encodeURIComponent;nt.objectAssign(T,{setItem:function(t,n){T(t,n)},getItem:function(t){return T(t)},removeItem:function(t){T(t,null,{expires:-1})},getJSON:function(){return T()}});var ot={cookie:T},ut=Date.now||function(){return(new Date).getTime()},at=[{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]]}],ct=[["yyyy",31536e6],["MM",2592e6],["dd",864e5],["HH",36e5],["mm",6e4],["ss",1e3],["S",0]],st={timestamp:ut,now:ut,stringToDate:I,dateToString:function(t,n){if(t){if(t=I(t),nt.isDate(t)){var e=["日","一","二","三","四","五","六"],r={"q+":Math.floor((t.getMonth()+3)/3),"M+":t.getMonth()+1,"E+":t.getDay(),"d+":t.getDate(),"H+":t.getHours(),"m+":t.getMinutes(),"s+":t.getSeconds(),S:t.getMilliseconds()},i=String(n||"yyyy-MM-dd HH:mm:ss").replace(/(y+)/,function(n){return(""+t.getFullYear()).substr(4-n.length)});for(var o in r)if(r.hasOwnProperty(o)){var u=""+r[o];i=i.replace(new RegExp("("+o+")"),function(t){return"q+"===o||"E+"===o?e[u]:1===t.length?u:("00"+u).substr(u.length)})}return i}return t}return""},getWhatMonth:k,getWhatWeek:function(t,n,e){var r=Number(/^[0-7]$/.test(e)?e:0),i=I(t),o=i.getDay(),u=i.getTime()+864e5*((0===r?7:r)-(0===o?7:o));return n&&!isNaN(n)&&(u+=6048e5*n),new Date(u)},getWhatDay:function(t,n){return new Date(I(t).getTime()+(n&&!isNaN(n)?864e5*n:0))},getDaysOfMonth:function(t,n){return Math.floor((k(t,n,"last").getTime()-k(t,n,"first").getTime())/864e5)+1},getDateDiff:function(t,n,e){var r={},i=I(t).getTime(),o=n?I(n).getTime():new Date;if(i0?e:ct,s=0,f=c.length;s=(u=c[s])[1]&&(s===f-1?a&&(r[u[0]]=a):(r[u[0]]=Math.floor(a/u[1]),a-=r[u[0]]*u[1]));return r}},ft=null;"undefined"!=typeof location&&(ft=location);var lt={parseUrl:U,getBaseURL:function(){var t=ft.pathname,n=nt.lastIndexOf(t,"/")+1;return R()+(n===t.length?t:t.substring(0,n))},locat:function(){return ft?U(ft.href):{}}},ht={getRandom:function(t,n){return t>=n?t:(t>>=0)+Math.round(Math.random()*((n||9)-t))},arrayMin:P,min:P,arrayMax:$,max:$,commafy:function(t,n){var e=nt.objectAssign({spaceNumber:3,separator:",",fixed:0},n),r=parseFloat((""+t).replace(/,/g,"")||0).toFixed(e.fixed).split(".");return r[0].replace(new RegExp("(?=(?!(\\b))(\\d{"+e.spaceNumber+"})+$)","g"),e.separator)+(r[1]?"."+r[1]:"")}},yt={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},pt={};nt.arrayEach(nt.objectKeys(yt),function(t){pt[yt[t]]=t});var gt={escape:C(yt),unescape:C(pt)},mt={};return nt.objectAssign(mt,J,nt,et,ot,st,lt,ht,gt),t.mixin=function(n){mt.objectEach(n,function(n,e){t[e]=-1==="cookie".indexOf(e)&&mt.isFunction(n)?function(){var e=n.apply(t.$context,arguments);return t.$context=null,e}:n})},t.mixin(mt),t}); \ 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(){}function t(n){var t=[];return tn.isArray(n)&&tn.arrayEach(n,function(n){t.includes(n)||t.push(n)}),t}function e(){for(var n=[],e=0,r=arguments.length;ee[t]?1:-1}:function(n,t){return n>t?1:-1}):n}function i(n){for(var t=[],e=tn.objectValues(n),r=e.length-1;r>=0;r--){var i=r>0?yn.getRandom(0,r):0;t.push(e[i]),e.splice(i,1)}return t}function o(n,t){var e=i(n);return 1===arguments.length?e[0]:(t1?r=[tn.objectAssign({name:n,value:t},e)]:tn.isObject(n)&&(r=[n]),!(r.length>0)){var o={};return i&&document.cookie&&tn.arrayEach(document.cookie.split("; "),function(n){var t=n.indexOf("=");o[rn(n.substring(0,t))]=rn(n.substring(t+1)||"")}),1===arguments.length?o[n]:o}i&&tn.arrayEach(r,function(n){var t=tn.objectAssign({},n),e=[];t.name&&(e.push(on(t.name)+"="+on(tn.isObject(t.value)?JSON.stringify(t.value):t.value)),void 0!==t.expires&&(t.expires=new Date((new Date).getTime()+864e5*parseFloat(t.expires)).toUTCString()),tn.arrayEach(["expires","path","domain","secure"],function(n){void 0!==t[n]&&e.push(n+"="+t[n])})),document.cookie=e.join("; ")})}function I(n,t){if(n){if(tn.isDate(n))return n;if(!isNaN(n))return new Date(n);if(tn.isString(n)){t=t||"yyyy-MM-dd HH:mm:ss.SSS";var e=[];return tn.arrayEach(sn,function(r){for(var i,o,u=0,a=r.rules,s=a.length;u-1){e.push(parseFloat(n.substring(o,o+i[1])||0)+(r.offset||0));break}u===s-1&&e.push(0)}}),new Date(e[0],e[1],e[2],e[3],e[4],e[5],e[6])}}return"Invalid Date"}function k(n,t,e){var r=I(n),i=t&&!isNaN(t)?t:0,o=r.getHours(),u=r.getMinutes(),a=r.getSeconds(),s=r.getMilliseconds();if("first"===e){var c=r.getFullYear(),f=r.getMonth();return(f+=i)<0?new Date(c-Math.ceil((f=Math.abs(f))/12),12-(f%12||1),1,o,u,a,s):new Date(c+Math.floor(f/12),f%12,1,o,u,a,s)}if("last"===e)return new Date(k(r,i+1,"first").getTime()-864e5);var l=r.getDate(),h=k(r,i,"first"),y=h.getMonth();for(h.setDate(l);y=0;e--)if(t===n[e])return e;return-1}),Q=b,V=function(n){if(n){var t=arguments;if(!0!==n)return Object.assign?Object.assign.apply(Object,t):S(n,t);if(t.length>1)return n=B(n[1])?[]:{},S(n,t,!0)}return n},X=j,G=M,Z=O,_=x,nn=D,tn={isNaN:isNaN,isFinite:isFinite,isArray:B,isFloat:function(n){return null!==n&&!isNaN(n)&&!z(n)},isInteger:z,isFunction:l,isBoolean:function(n){return"boolean"==typeof n},isString:h,isNumber:y,isRegExp:function(n){return"[object RegExp]"===$.call(n)},isObject:p,isPlainObject:g,isDate:d,isError:function(n){return"[object Error]"===$.call(n)},isTypeError:function(n){return!!n&&n.constructor===TypeError},isEmpty:function(n){if(0===n||!y(n)){for(var t in n)return!1;return!0}return!1},isNull:function(n){return null===n},isSymbol:m,isArguments:function(n){return"[object Arguments]"===$.call(n)},isElement:function(n){return n&&h(n.nodeName)&&y(n.nodeType)},isDocument:function(n){return n&&9===n.nodeType&&"undefined"!=typeof document},isWindow:function(n){return n&&n===n.window&&"undefined"!=typeof window},isFormData:function(n){return"undefined"!=typeof FormData&&n instanceof FormData},isLeapYear:function(t){var e=(t?n.stringToDate(t):new Date).getFullYear();return e%4==0&&(e%100!=0||e%400==0)},getType:function(n){return null===n?""+n:m(n)?"symbol":d(n)?"date":B(n)?"array":typeof n},uniqueId:function(){return++K},getSize:function(n){var t=0;return h(n)||B(n)?n.length:(N(n,function(){t++}),t)},lastIndexOf:L,includes:b,contains:Q,objectAssign:V,assign:V,extend:V,stringToJson:function(n){if(p(n))return n;if(h(n))try{return JSON.parse(n)}catch(n){console.error(n)}return{}},jsonToString:function(n){if(p(n))try{return JSON.stringify(n)}catch(n){console.error(n)}return n?""+n:""},objectKeys:j,keys:X,objectValues:M,values:G,objectEntries:O,entries:Z,arrayFirst:x,first:_,arrayLast:D,last:nn,objectEach:w,arrayEach:E,each:N,groupBy:function(n,t,e){var r,i,o={};return n&&(h(t)?(i=t,t=null):t=l(t)?t.bind(e||this):i=null,N(n,function(e,u){r=t?t(e,u,n):i?e[i]:e,o[r]?o[r].push(e):o[r]=[e]})),o},objectMap:function(n,t,e){var r={};return N(n,function(i,o){r[o]=t.call(e||this,i,o,n)}),r},clone:F},en={browse:function(){var n={isNode:!1,isMobile:!1,isPC:!1};if("undefined"==typeof window&&"undefined"!=typeof process)n.nodeJS=!0;else if(n.isMobile=function(){for(var n=["Android","webOS","iPhone","iPad","iPod","SymbianOS","BlackBerry","Windows Phone"],t=navigator.userAgent,e=0;e0)return!0;return!1}(),n.isPC=!n.isMobile,"undefined"!=typeof document){var t=document.body||document.documentElement;tn.arrayEach(["webkit","khtml","moz","ms","o"],function(e){n["-"+e]=!!t[e+"MatchesSelector"]})}return n}},rn=decodeURIComponent,on=encodeURIComponent;tn.objectAssign(T,{setItem:function(n,t){T(n,t)},getItem:function(n){return T(n)},removeItem:function(n){T(n,null,{expires:-1})},getJSON:function(){return T()}});var un={cookie:T},an=Date.now||function(){return(new Date).getTime()},sn=[{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]]}],cn=[["yyyy",31536e6],["MM",2592e6],["dd",864e5],["HH",36e5],["mm",6e4],["ss",1e3],["S",0]],fn={timestamp:an,now:an,stringToDate:I,dateToString:function(n,t){if(n){if(n=I(n),tn.isDate(n)){var e=["日","一","二","三","四","五","六"],r={"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()},i=String(t||"yyyy-MM-dd HH:mm:ss").replace(/(y+)/,function(t){return(""+n.getFullYear()).substr(4-t.length)});for(var o in r)if(r.hasOwnProperty(o)){var u=""+r[o];i=i.replace(new RegExp("("+o+")"),function(n){return"q+"===o||"E+"===o?e[u]:1===n.length?u:("00"+u).substr(u.length)})}return i}return n}return""},getWhatMonth:k,getWhatWeek:function(n,t,e){var r=Number(/^[0-7]$/.test(e)?e:0),i=I(n),o=i.getDay(),u=i.getTime()+864e5*((0===r?7:r)-(0===o?7:o));return t&&!isNaN(t)&&(u+=6048e5*t),new Date(u)},getWhatDay:function(n,t){return new Date(I(n).getTime()+(t&&!isNaN(t)?864e5*t:0))},getDaysOfMonth:function(n,t){return Math.floor((k(n,t,"last").getTime()-k(n,t,"first").getTime())/864e5)+1},getDateDiff:function(n,t,e){var r={},i=I(n).getTime(),o=t?I(t).getTime():new Date;if(i0?e:cn,c=0,f=s.length;c=(u=s[c])[1]&&(c===f-1?a&&(r[u[0]]=a):(r[u[0]]=Math.floor(a/u[1]),a-=r[u[0]]*u[1]));return r}},ln=null;"undefined"!=typeof location&&(ln=location);var hn={parseUrl:R,getBaseURL:function(){if(ln){var n=ln.pathname,t=tn.lastIndexOf(n,"/")+1;return P()+(t===n.length?n:n.substring(0,t))}return""},locat:function(){return ln?R(ln.href):{}}},yn={getRandom:function(n,t){return n>=t?n:(n>>=0)+Math.round(Math.random()*((t||9)-n))},arrayMin:C,min:C,arrayMax:q,max:q,commafy:function(n,t){var e=tn.objectAssign({spaceNumber:3,separator:",",fixed:0},t),r=parseFloat((""+n).replace(/,/g,"")||0).toFixed(e.fixed).split(".");return r[0].replace(new RegExp("(?=(?!(\\b))(\\d{"+e.spaceNumber+"})+$)","g"),e.separator)+(r[1]?"."+r[1]:"")}},pn={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},gn={};tn.arrayEach(tn.objectKeys(pn),function(n){gn[pn[n]]=n});var dn={escape:J(pn),unescape:J(gn)},mn={};return tn.objectAssign(mn,W,tn,en,un,fn,hn,yn,dn),n.mixin=function(t){mn.objectEach(t,function(t,e){n[e]=-1==="cookie".indexOf(e)&&mn.isFunction(t)?function(){var e=t.apply(n.$context,arguments);return n.$context=null,e}:t})},n.mixin(mn),n}); \ No newline at end of file diff --git a/src/method/browse.js b/src/method/browse.js index 0d1a8f6..b6aa203 100644 --- a/src/method/browse.js +++ b/src/method/browse.js @@ -2,17 +2,37 @@ var baseExports = require('./base') +function isMobile () { + var agents = ['Android', 'webOS', 'iPhone', 'iPad', 'iPod', 'SymbianOS', 'BlackBerry', 'Windows Phone'] + for (var userAgentInfo = navigator.userAgent, i = 0; i < agents.length; i++) { + if (userAgentInfo.indexOf(agents[i]) > 0) { + return true + } + } + return false +} + /** * 获取浏览器内核 * @return Object */ function browse () { - var result = {} - if (typeof document !== 'undefined') { - var $body = document.body || document.documentElement - baseExports.arrayEach(['webkit', 'khtml', 'moz', 'ms', 'o'], function (core) { - result['-' + core] = !!$body[core + 'MatchesSelector'] - }) + var result = { + isNode: false, + isMobile: false, + isPC: false + } + if (typeof window === 'undefined' && typeof process !== 'undefined') { + result.nodeJS = true + } else { + result.isMobile = isMobile() + result.isPC = !result.isMobile + if (typeof document !== 'undefined') { + var $body = document.body || document.documentElement + baseExports.arrayEach(['webkit', 'khtml', 'moz', 'ms', 'o'], function (core) { + result['-' + core] = !!$body[core + 'MatchesSelector'] + }) + } } return result } diff --git a/src/method/locat.js b/src/method/locat.js index 9773c0d..39906b9 100644 --- a/src/method/locat.js +++ b/src/method/locat.js @@ -21,13 +21,16 @@ function parseParams (uri) { } function getLocatOrigin () { - return $locat.origin || ($locat.protocol + '//' + $locat.host) + return $locat ? ($locat.origin || ($locat.protocol + '//' + $locat.host)) : '' } function getBaseURL () { - var pathname = $locat.pathname - var lastIndex = baseExports.lastIndexOf(pathname, '/') + 1 - return getLocatOrigin() + (lastIndex === pathname.length ? pathname : pathname.substring(0, lastIndex)) + if ($locat) { + var pathname = $locat.pathname + var lastIndex = baseExports.lastIndexOf(pathname, '/') + 1 + return getLocatOrigin() + (lastIndex === pathname.length ? pathname : pathname.substring(0, lastIndex)) + } + return '' } function parseUrl (url) {