UNPKG

vcm-utils

Version:

effective tools to develop by js

2 lines (1 loc) 2.62 kB
"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var ls={setItem:function(e,t){e&&("string"!=typeof t&&(t=JSON.stringify(t)),window.localStorage.setItem(e,t))},getItem:function(e){if(e)return window.localStorage.getItem(e)},removeItem:function(e){e&&window.localStorage.removeItem(e)}},ss={setItem:function(e,t){if(e){if(void 0===t)throw TypeError("sessionStorage.setItem的值为undefined");window.sessionStorage.setItem(e,JSON.stringify(t))}},getItem:function(e){if(e)return JSON.parse(window.sessionStorage.getItem(e))},removeItem:function(e){e&&window.sessionStorage.removeItem(e)}},_=require("underscore"),getQueryVariable=function(e,t){for(var r=((1<arguments.length&&void 0!==t?t:"")||window.location.search.substring(1)).split("&"),n=0;n<r.length;n++){var o=r[n].split("=");if(o[0]==e)return o[1]}return!1},guidGenerator=function(){return(65536*(1+Math.random())|0).toString(16).substring(1)},getUUID=function(){return guidGenerator()+guidGenerator()+guidGenerator()+guidGenerator()+guidGenerator()+guidGenerator()+guidGenerator()+guidGenerator()},index={requestId:function(){return getUUID()},range:function(e,t){return parseInt(Math.random()*(t-e)+e)},objToParams:function(t){var e=Object.keys(t),r="";return e&&e.map(function(e){r+=""==r?e+"="+t[e]:"&"+e+"="+t[e]}),r},getQueryVariable:getQueryVariable,getParams:getQueryVariable,_:_,deepCopy:function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}(function(e){var t=e.constructor===Array?[]:{};if(t.constructor=e.constructor,"object"!==_typeof(e))return e;if(window.JSON)t=JSON.parse(JSON.stringify(e));else for(var r in e)e[r].constructor!==RegExp&&e[r].constructor!==Date&&"object"===_typeof(e[r])?t[r]=deepCopy(e[r]):t[r]=e[r];return t}),decodeJson:function decodeJson(value){var regAryStr=/^\[[\s|\S]*\]$/,regObjStr=/^\{([\"\s|\S]+\"\:\"[\s|\S]*)+\"\}$/;return regAryStr.test(value)?eval("("+value+")"):regObjStr.test(value)?JSON.parse(value):value},priceFormat:function(e,t){if(void 0===e)return"--";if(""===e)return t||"";var r=Number(e)<0?"-":"",t=(e=Math.abs(e)).toString(),n=t.split(".")[0],e="00";if(null!=t.split(".")[1]&&(0==(e=t.split(".")[1]).length?e="00":1==e.length?e+="0":e=e.substr(0,2)),3<n.length){n=n.split("");for(var o,i=1;;i++)if(o=n.length-(3*i+i-1),n.splice(o,0,","),n.indexOf(",")<=3){n=n.join("");break}}return r+n+"."+e},cookie:ss,ls:ls,ss:ss};module.exports=index;