🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

againcash

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

againcash - npm Package Compare versions

Comparing version
1.0.2
to
2.0.1
+6
.babelrc
{
"presets": [
["es2015", { "modules": false }]
],
"plugins": ["transform-runtime"]
}
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.HtmlStrReplace=e():t.HtmlStrReplace=e()}(window,function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";r.r(e),r.d(e,"default",function(){return n});class n{constructor(){this.author="Hansin",this.cashList=[]}getCash(t,e){"object"==typeof e&&(e=JSON.stringify(e));let r,n=[];return this.cashList.forEach(e=>{e.path===t&&(n=e.cash)}),n.forEach(t=>{t.pre===e&&t.res&&(r=JSON.parse(t.res))}),r}setCash(t,e,r){let n=!1;"object"==typeof e&&(e=JSON.stringify(e)),this.cashList.forEach((o,i)=>{if(o.path===t){n=!0;let t=!1;o.cash.forEach((n,o)=>{n.preload===JSON.stringify(e)&&(t=!0,this.cashList[i].cash[o].res=JSON.stringify(r))}),t||this.cashList[i].cash.push({pre:JSON.stringify(e),res:JSON.stringify(r)})}}),n||this.cashList.push({path:t,cash:[{pre:JSON.stringify(e),res:JSON.stringify(r)}]})}}}])});
// 调用
/*
** @params
** path: 请求的路径
** preload: 请求的参数
** cashtype: 'no'[本次请求不走缓存过滤] ‘str’[同一个路径缓存一条] ‘arr’[同一个路径缓存多条]
*/
// cashAgain.setAgainAgent('/index', {page: 1}, {data:{code: 0}}, 'arr')
// cashAgain.getAgainAgent('/index', {page: 1}, 'arr')
// if (cashAgain.resPromise) {
// return cashAgain.resPromise
// } else {
// return axois.get()
// }
export default class againCash {
constructor () {
this.author = 'Hansin'
this.cashList = []
}
getCash (path, preload) {
if (typeof preload === 'object') {
preload = JSON.stringify(preload)
}
let list = [],res
this.cashList.forEach((item) => {
if (item.path === path) {
list = item.cash
}
})
list.forEach((n) => {
if (n.pre === preload && n.res) {
res = JSON.parse(n.res)
}
})
return res
}
setCash (path, preload, res) {
let havePath = false
if (typeof preload === 'object') {
preload = JSON.stringify(preload)
}
this.cashList.forEach((item, i) => {
if (item.path === path) {
havePath = true
let haveRes = false
item.cash.forEach((li, j) => {
if (li.preload === JSON.stringify(preload)) {
haveRes = true
this.cashList[i].cash[j].res = JSON.stringify(res)
}
})
if (!haveRes) {
this.cashList[i].cash.push({
pre: JSON.stringify(preload),
res: JSON.stringify(res)
})
}
}
})
if (!havePath) {
this.cashList.push({
path: path,
cash: [{
pre: JSON.stringify(preload),
res: JSON.stringify(res)
}]
})
}
}
}
// npx webpack --config webpack.config.js
// 通过向 npm run build 命令和你的参数之间添加两个中横线,可以将自定义参数传递给 webpack,例如:npm run build -- --colors。
const path = require('path');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'index.js',
library: 'HtmlStrReplace', // 暴露library
libraryTarget: 'umd' //libraryTarget 控制 library 如何以不同方式暴露的选项(var this window umd)。
},
plugins: [
// tree shaking
new UglifyJSPlugin()
]
}

Sorry, the diff of this file is too big to display

+25
-3
{
"name": "againcash",
"version": "1.0.2",
"version": "2.0.1",
"description": "web cash",
"main": "index.js",
"main": "dist/index.js",
"scripts": {
"build": "webpack",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/hansinhu/npm-HtmlStrRep.git"
},
"keywords": [
"replace",
"string",
"for",
"html"
],
"author": "hansin",
"license": "ISC"
"license": "ISC",
"bugs": {
"url": "https://github.com/hansinhu/npm-HtmlStrRep/issues"
},
"homepage": "https://github.com/hansinhu/npm-HtmlStrRep#readme",
"dependencies": {
"babel-runtime": "^6.26.0",
"webpack": "^4.19.0"
},
"devDependencies": {
"webpack-cli": "^2.1.3"
}
}
+1
-16

@@ -12,19 +12,4 @@ # againCash for xhr web cash

const cashAgain = new againcash()
console.log(cashAgain)
// setcash need path, preload, response, [cashType]
cashAgain.setAgainAgent('/index', {page: 1}, {data:{code: 0}}, 'arr')
// getcash need path, preload, [cashType]
cashAgain.getAgainAgent('/index', {page: 1}, 'arr')
// after use cashAgain.getAgainAgent
// if have cash cashAgain.resPromise as a promise to return
// if no cash cashAgain.resPromise as a null to return
if (cashAgain.resPromise) {
return cashAgain.resPromise
} else {
// for example, get xhr
return axois.get()
}
```

@@ -31,0 +16,0 @@ ### update:

// 调用
/*
** @params
** path: 请求的路径
** preload: 请求的参数
** cashtype: 'no'[本次请求不走缓存过滤] ‘str’[同一个路径缓存一条] ‘arr’[同一个路径缓存多条]
*/
// cashAgain.setAgainAgent('/index', {page: 1}, {data:{code: 0}}, 'arr')
// cashAgain.getAgainAgent('/index', {page: 1}, 'arr')
// if (cashAgain.resPromise) {
// return cashAgain.resPromise
// } else {
// return axois.get()
// }
export default class againCash {
constructor () {
this.author = 'Hansin'
this.cashList = []
this.res = null
}
// 请求过滤
getAgainAgent (path, preload, cashtype = 'arr') {
if (cashtype === 'no') {
return null
} else {
this.getCash (path, preload)
}
}
// 获取过滤
setAgainAgent (path, preload, res, cashtype = 'arr') {
if (cashtype === 'no') {
return null
} else {
this.setCash (path, preload, res)
}
}
getCash (path, preload) {
let list = [],res
this.cashList.forEach((item) => {
if (item.path === path) {
list = item.cash
}
})
list.forEach((n) => {
if (n.pre === JSON.stringify(preload) && n.res) {
res = JSON.parse(n.res)
}
})
this.res = res
}
setCash (path, preload, res) {
let havePath = false
this.cashList.forEach((item, i) => {
if (item.path === path) {
havePath = true
let haveRes = false
item.cash.forEach((li, j) => {
if (li.preload === JSON.stringify(preload)) {
haveRes = true
this.cashList[i].cash[j].res = JSON.stringify(res)
}
})
if (!haveRes) {
this.cashList[i].cash.push({
pre: JSON.stringify(preload),
res: JSON.stringify(res)
})
}
}
})
if (!havePath) {
this.cashList.push({
path: path,
cash: [{
pre: JSON.stringify(preload),
res: JSON.stringify(res)
}]
})
}
}
}