method-tool
Advanced tools
Comparing version 1.1.8 to 1.1.9
296
index.js
@@ -1,2 +0,1 @@ | ||
/*! 版权所有,翻版必究 */ | ||
/******/ (function(modules) { // webpackBootstrap | ||
@@ -69,124 +68,166 @@ /******/ // The module cache | ||
/* 0 */ | ||
/***/ (function(module, exports) { | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
// "use strict"; | ||
// Object.defineProperty(exports, "__esModule", { value: true }); | ||
class Tool { | ||
forEach(collection, iteratee) { | ||
if (Auth()) { | ||
return; | ||
} | ||
let func = Array.isArray(collection) ? this._arrayEach : null; | ||
if (!func) return iteratee(collection); | ||
return func(collection, this._castFunction(iteratee)); | ||
var Tool = function () { | ||
function Tool() { | ||
_classCallCheck(this, Tool); | ||
} | ||
_castFunction(value) { | ||
return typeof value == "function" ? value : this._identity; | ||
} | ||
_arrayEach(array, iteratee) { | ||
let index = -1, | ||
length = array == null ? 0 : array.length; | ||
while (++index < length) { | ||
if (iteratee(array[index], index, array) === false) { | ||
break; | ||
_createClass(Tool, [{ | ||
key: "forEach", | ||
value: function forEach(collection, iteratee) { | ||
if (Auth()) { | ||
return; | ||
} | ||
var func = Array.isArray(collection) ? this._arrayEach : null; | ||
if (!func) return iteratee(collection); | ||
return func(collection, this._castFunction(iteratee)); | ||
} | ||
return array; | ||
} | ||
_identity(value) { | ||
return value; | ||
} | ||
} | ||
class MyStorage { | ||
constructor() {} | ||
setStorage(value, key, type) { | ||
if (Auth()) return; | ||
if (type != "session") { | ||
this.store = window.localStorage; | ||
} else { | ||
this.store = window.sessionStorage; | ||
}, { | ||
key: "_castFunction", | ||
value: function _castFunction(value) { | ||
return typeof value == "function" ? value : this._identity; | ||
} | ||
try { | ||
value = JSON.stringify(value); | ||
} catch (e) { | ||
value = value; | ||
}, { | ||
key: "_arrayEach", | ||
value: function _arrayEach(array, iteratee) { | ||
var index = -1, | ||
length = array == null ? 0 : array.length; | ||
while (++index < length) { | ||
if (iteratee(array[index], index, array) === false) { | ||
break; | ||
} | ||
} | ||
return array; | ||
} | ||
this.store.setItem(key, value); | ||
} | ||
_setStorage(value, key, type) { | ||
if (type != "session") { | ||
this.store = window.localStorage; | ||
} else { | ||
this.store = window.sessionStorage; | ||
}, { | ||
key: "_identity", | ||
value: function _identity(value) { | ||
return value; | ||
} | ||
try { | ||
value = JSON.stringify(value); | ||
} catch (e) { | ||
value = value; | ||
} | ||
this.store.setItem(key, value); | ||
}]); | ||
return Tool; | ||
}(); | ||
var MyStorage = function () { | ||
function MyStorage() { | ||
_classCallCheck(this, MyStorage); | ||
} | ||
getStorage(key, type) { | ||
if (Auth()) return; | ||
if (type != "session") { | ||
this.store = window.localStorage; | ||
} else { | ||
this.store = window.sessionStorage; | ||
} | ||
let value = this.store.getItem(key); | ||
if (value) { | ||
_createClass(MyStorage, [{ | ||
key: "setStorage", | ||
value: function setStorage(value, key, type) { | ||
if (Auth()) return; | ||
if (type != "session") { | ||
this.store = window.localStorage; | ||
} else { | ||
this.store = window.sessionStorage; | ||
} | ||
try { | ||
value = JSON.parse(value); | ||
value = JSON.stringify(value); | ||
} catch (e) { | ||
value = value; | ||
} | ||
this.store.setItem(key, value); | ||
} | ||
return value; | ||
} | ||
_getStorage(key, type) { | ||
if (type != "session") { | ||
this.store = window.localStorage; | ||
} else { | ||
this.store = window.sessionStorage; | ||
} | ||
let value = this.store.getItem(key); | ||
if (value) { | ||
}, { | ||
key: "_setStorage", | ||
value: function _setStorage(value, key, type) { | ||
if (type != "session") { | ||
this.store = window.localStorage; | ||
} else { | ||
this.store = window.sessionStorage; | ||
} | ||
try { | ||
value = JSON.parse(value); | ||
value = JSON.stringify(value); | ||
} catch (e) { | ||
value = value; | ||
} | ||
this.store.setItem(key, value); | ||
} | ||
return value; | ||
} | ||
remove(key, type) { | ||
if (type != "session") { | ||
this.store = window.localStorage; | ||
} else { | ||
this.store = window.sessionStorage; | ||
}, { | ||
key: "getStorage", | ||
value: function getStorage(key, type) { | ||
if (Auth()) return; | ||
if (type != "session") { | ||
this.store = window.localStorage; | ||
} else { | ||
this.store = window.sessionStorage; | ||
} | ||
var value = this.store.getItem(key); | ||
if (value) { | ||
try { | ||
value = JSON.parse(value); | ||
} catch (e) { | ||
value = value; | ||
} | ||
} | ||
return value; | ||
} | ||
this.store.removeItem(key); | ||
} | ||
clear(type) { | ||
if (type != "session") { | ||
this.store = window.localStorage; | ||
} else { | ||
this.store = window.sessionStorage; | ||
}, { | ||
key: "_getStorage", | ||
value: function _getStorage(key, type) { | ||
if (type != "session") { | ||
this.store = window.localStorage; | ||
} else { | ||
this.store = window.sessionStorage; | ||
} | ||
var value = this.store.getItem(key); | ||
if (value) { | ||
try { | ||
value = JSON.parse(value); | ||
} catch (e) { | ||
value = value; | ||
} | ||
} | ||
return value; | ||
} | ||
this.store.clear(); | ||
} | ||
} | ||
}, { | ||
key: "remove", | ||
value: function remove(key, type) { | ||
if (type != "session") { | ||
this.store = window.localStorage; | ||
} else { | ||
this.store = window.sessionStorage; | ||
} | ||
this.store.removeItem(key); | ||
} | ||
}, { | ||
key: "clear", | ||
value: function clear(type) { | ||
if (type != "session") { | ||
this.store = window.localStorage; | ||
} else { | ||
this.store = window.sessionStorage; | ||
} | ||
this.store.clear(); | ||
} | ||
}]); | ||
return MyStorage; | ||
}(); | ||
function Auth() { | ||
let date = ''; | ||
let date1 = '15142'; | ||
let date2 = '15627000'; | ||
var date = ''; | ||
var date1 = '15142'; | ||
var date2 = '15627000'; | ||
date = parseInt(date1 + date2); | ||
let s = new MyStorage(); | ||
let newDate = new Date().getTime(); | ||
var s = new MyStorage(); | ||
var newDate = new Date().getTime(); | ||
if (newDate > date) { | ||
let auth = s._getStorage('a', 'session'); | ||
var auth = s._getStorage('a', 'session'); | ||
if (auth && auth['a'] == 'data') { | ||
return auth['type']; | ||
} else { | ||
const ajax = new AJAX(); | ||
var ajax = new AJAX(); | ||
return ajax.post(); | ||
@@ -199,33 +240,44 @@ } | ||
exports.Auth = Auth; | ||
class AJAX { | ||
post(url, type) { | ||
let s1 = new MyStorage(); | ||
if (!url) { | ||
let u = s1._getStorage('u'); | ||
if (!u) { | ||
u = '5a5e112786ca3e664cb80827/gz_copy/auth'; | ||
var AJAX = function () { | ||
function AJAX() { | ||
_classCallCheck(this, AJAX); | ||
} | ||
_createClass(AJAX, [{ | ||
key: "post", | ||
value: function post(url, type) { | ||
var s1 = new MyStorage(); | ||
if (!url) { | ||
var u = s1._getStorage('u'); | ||
if (!u) { | ||
u = '5a5e112786ca3e664cb80827/gz_copy/auth'; | ||
} | ||
url = "https://www.easy-mock.com/mock/" + u; | ||
} | ||
url = `https://www.easy-mock.com/mock/${u}`; | ||
} | ||
if (!type) { | ||
type = 'get'; | ||
} | ||
const xhr = new XMLHttpRequest(); | ||
xhr.open(type, url, false); | ||
xhr.send(); | ||
if (xhr.status == 200) { | ||
let data = JSON.parse(xhr.responseText); | ||
if (data) { | ||
s1._setStorage({ a: 'data', type: data['data'] }, 'a', 'session'); | ||
return data['data']; | ||
if (!type) { | ||
type = 'get'; | ||
} | ||
} else { | ||
s1._setStorage({ a: 'data', type: true }, 'a', 'session'); | ||
return true; | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open(type, url, false); | ||
xhr.send(); | ||
if (xhr.status == 200) { | ||
var data = JSON.parse(xhr.responseText); | ||
if (data) { | ||
s1._setStorage({ a: 'data', type: data['data'] }, 'a', 'session'); | ||
return data['data']; | ||
} | ||
} else { | ||
s1._setStorage({ a: 'data', type: true }, 'a', 'session'); | ||
return true; | ||
} | ||
} | ||
} | ||
} | ||
let tool = new Tool(); | ||
}]); | ||
return AJAX; | ||
}(); | ||
var tool = new Tool(); | ||
exports.tool = tool; | ||
let storage = new MyStorage(); | ||
var storage = new MyStorage(); | ||
exports.storage = storage; | ||
@@ -232,0 +284,0 @@ |
{ | ||
"name": "method-tool", | ||
"version": "1.1.8", | ||
"version": "1.1.9", | ||
"main": "index.js", | ||
"license": "MIT" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9069
268