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

html-str-replace

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-str-replace - npm Package Compare versions

Comparing version
1.0.8
to
1.0.9
+2
-1
.babelrc
{
"presets": [
["es2015", { "modules": false }]
]
],
"plugins": ["transform-runtime"]
}

@@ -1,1 +0,98 @@

!function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},r.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},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.endObj={tag:"",children:[],nextStr:null},this.originStr="",this.sFrom="",this.sTo=""}startRep(t,e,r=""){return this.originStr=t,this.sFrom=e,this.sTo=r,-1!==t.indexOf(e)&&e?(this.endObj=this.strToObj(t),this.reGroup(this.endObj,r)):t}reGroup(t,e){let r="";if(t.tag){let n=[];t.children.forEach(t=>{n.push(this.reGroup(t,e))}),r+=n.join(t.tag)}else r+=this.replace(t.nextStr);return r}replace(t){return t.split(this.sFrom).join(this.sTo)}strToObj(t){let e={tag:"",children:[],nextStr:null},r=this.deleHave(this.machTag(t));if(r){let n=r[0];e.tag=n,e.nextStr="";let i=t.split(n);i.forEach((t,r)=>{e.children.push({tag:"",children:[],nextStr:i[r]}),t&&this.deleHave(this.machTag(t))&&(e.children[r]=this.strToObj(t))})}else e.nextStr=t;return e}machTag(t){return t.match(/<[^>]+>/g)}deleHave(t){if(!t)return t;let e=[];for(let r of t)-1===e.indexOf(r)&&e.push(r);return e}}}]);
! 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, {
configurable: !1,
enumerable: !0,
get: n
})
}, r.r = function (t) {
Object.defineProperty(t, "__esModule", {
value: !0
})
}, 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.endObj = {
tag: "",
children: [],
nextStr: null
}, this.originStr = "", this.sFrom = "", this.sTo = ""
}
startRep(t, e, r = "") {
if (this.originStr = t, this.sFrom = e, this.sTo = r, -1 === t.indexOf(e) || !e) return t;
return this.endObj = this.strToObj(t), this.reGroup(this.endObj, r)
}
reGroup(t, e) {
let r = "";
if (t.tag) {
let n = [];
t.children.forEach(t => {
n.push(this.reGroup(t, e))
}), r += n.join(t.tag)
} else r += this.replace(t.nextStr);
return r
}
replace(t) {
return t.split(this.sFrom).join(this.sTo)
}
strToObj(t) {
let e = {
tag: "",
children: [],
nextStr: null
},
r = this.deleHave(this.machTag(t));
if (r) {
let n = r[0];
e.tag = n, e.nextStr = "";
let o = t.split(n);
o.forEach((t, r) => {
e.children.push({
tag: "",
children: [],
nextStr: o[r]
}), t && this.deleHave(this.machTag(t)) && (e.children[r] = this.strToObj(t))
})
} else e.nextStr = t;
return e
}
machTag(t) {
return t.match(/<[^>]+>/g)
}
deleHave(t) {
if (!t) return t;
let e = [];
for (let r of t) - 1 === e.indexOf(r) && e.push(r);
return e
}
}
}])
});
+192
-89
// str: 目标字符串,sFrom: 被替换的字符串, sTo: 替换成字符串,
function HtmlStrRep () {
this.endObj = {
tag: '',
children: [],
nextStr: null
}
this.originStr = ''
this.sFrom = ''
this.sTo = ''
this.startRep = function (str, sFrom, sTo = '') {
this.originStr = str
this.sFrom = sFrom
this.sTo = sTo
if (str.indexOf(sFrom) === -1 || !sFrom) {
return str
}
this.endObj = this.strToObj(str)
let changeStr = this.reGroup(this.endObj, sTo)
return changeStr
}
// 把树形对象重新组合,没有tag的执行替换
this.reGroup = function (splitObj, sTo) {
let groupStr = ''
if (splitObj.tag) {
let strArr = []
// 递归组合
splitObj.children.forEach((n) => {
strArr.push(this.reGroup(n, sTo))
})
groupStr += strArr.join(splitObj.tag)
} else {
// 在此替换
groupStr += this.replace(splitObj.nextStr)
}
return groupStr
}
this.replace = function (str) {
return str.split(this.sFrom).join(this.sTo)
}
// 把字符串递归切割成树形对象
this.strToObj = function (str) {
// 暂存对象
let cashObj = {
tag: '',
children: [],
nextStr: null
}
// 匹配tag并去重
let tagArr = this.deleHave(this.machTag(str))
if (tagArr) {
let tag = tagArr[0]
cashObj.tag = tag
cashObj.nextStr = ''
let childArr = str.split(tag)
childArr.forEach((s, j) => {
cashObj.children.push({
tag: '',
children: [],
nextStr: childArr[j]
})
if (s && this.deleHave(this.machTag(s))) {
cashObj.children[j] = this.strToObj(s)
}
})
} else {
cashObj.nextStr = str
}
return cashObj
}
// 匹配标签
this.machTag = function (str) {
return str.match(/<[^>]+>/g)
}
// 数组去重
this.deleHave = function (arr) {
if (!arr) {
return arr
}
let darr = []
for (let item of arr) {
if (darr.indexOf(item) === -1) {
darr.push(item)
}
}
return darr
}
}
export default HtmlStrRep
// Allow use of default import syntax in TypeScript
// module.exports.default = HtmlStrRep
// const htmlStrRep = function () {

@@ -96,96 +199,96 @@ // this.endObj = {

export default class HtmlStrRep {
constructor () {
this.endObj = {
tag: '',
children: [],
nextStr: null
}
this.originStr = ''
this.sFrom = ''
this.sTo = ''
}
// export default class HtmlStrRep {
// constructor () {
// this.endObj = {
// tag: '',
// children: [],
// nextStr: null
// }
// this.originStr = ''
// this.sFrom = ''
// this.sTo = ''
// }
startRep (str, sFrom, sTo = '') {
this.originStr = str
this.sFrom = sFrom
this.sTo = sTo
if (str.indexOf(sFrom) === -1 || !sFrom) {
return str
}
this.endObj = this.strToObj(str)
let changeStr = this.reGroup(this.endObj, sTo)
return changeStr
}
// startRep (str, sFrom, sTo = '') {
// this.originStr = str
// this.sFrom = sFrom
// this.sTo = sTo
// if (str.indexOf(sFrom) === -1 || !sFrom) {
// return str
// }
// this.endObj = this.strToObj(str)
// let changeStr = this.reGroup(this.endObj, sTo)
// return changeStr
// }
// 把树形对象重新组合,没有tag的执行替换
reGroup (splitObj, sTo) {
let groupStr = ''
if (splitObj.tag) {
let strArr = []
// 递归组合
splitObj.children.forEach((n) => {
strArr.push(this.reGroup(n, sTo))
})
groupStr += strArr.join(splitObj.tag)
} else {
// 在此替换
groupStr += this.replace(splitObj.nextStr)
}
return groupStr
}
// // 把树形对象重新组合,没有tag的执行替换
// reGroup (splitObj, sTo) {
// let groupStr = ''
// if (splitObj.tag) {
// let strArr = []
// // 递归组合
// splitObj.children.forEach((n) => {
// strArr.push(this.reGroup(n, sTo))
// })
// groupStr += strArr.join(splitObj.tag)
// } else {
// // 在此替换
// groupStr += this.replace(splitObj.nextStr)
// }
// return groupStr
// }
replace (str) {
return str.split(this.sFrom).join(this.sTo)
}
// replace (str) {
// return str.split(this.sFrom).join(this.sTo)
// }
// 把字符串递归切割成树形对象
strToObj (str) {
// 暂存对象
let cashObj = {
tag: '',
children: [],
nextStr: null
}
// 匹配tag并去重
let tagArr = this.deleHave(this.machTag(str))
if (tagArr) {
let tag = tagArr[0]
cashObj.tag = tag
cashObj.nextStr = ''
let childArr = str.split(tag)
childArr.forEach((s, j) => {
cashObj.children.push({
tag: '',
children: [],
nextStr: childArr[j]
})
if (s && this.deleHave(this.machTag(s))) {
cashObj.children[j] = this.strToObj(s)
}
})
} else {
cashObj.nextStr = str
}
return cashObj
}
// // 把字符串递归切割成树形对象
// strToObj (str) {
// // 暂存对象
// let cashObj = {
// tag: '',
// children: [],
// nextStr: null
// }
// // 匹配tag并去重
// let tagArr = this.deleHave(this.machTag(str))
// if (tagArr) {
// let tag = tagArr[0]
// cashObj.tag = tag
// cashObj.nextStr = ''
// let childArr = str.split(tag)
// childArr.forEach((s, j) => {
// cashObj.children.push({
// tag: '',
// children: [],
// nextStr: childArr[j]
// })
// if (s && this.deleHave(this.machTag(s))) {
// cashObj.children[j] = this.strToObj(s)
// }
// })
// } else {
// cashObj.nextStr = str
// }
// return cashObj
// }
// 匹配标签
machTag (str) {
return str.match(/<[^>]+>/g)
}
// // 匹配标签
// machTag (str) {
// return str.match(/<[^>]+>/g)
// }
// 数组去重
deleHave (arr) {
if (!arr) {
return arr
}
let darr = []
for (let item of arr) {
if (darr.indexOf(item) === -1) {
darr.push(item)
}
}
return darr
}
}
// // 数组去重
// deleHave (arr) {
// if (!arr) {
// return arr
// }
// let darr = []
// for (let item of arr) {
// if (darr.indexOf(item) === -1) {
// darr.push(item)
// }
// }
// return darr
// }
// }
{
"name": "html-str-replace",
"version": "1.0.8",
"version": "1.0.9",
"description": "replace string for html",

@@ -26,3 +26,8 @@ "main": "index.js",

"homepage": "https://github.com/hansinhu/npm-HtmlStrRep#readme",
"dependencies": {}
"dependencies": {
"babel-runtime": "^6.26.0"
},
"devDependencies": {
"webpack-cli": "^2.1.3"
}
}
// str: 目标字符串,sFrom: 被替换的字符串, sTo: 替换成字符串,
export default class htmlStrRep {
export default class HtmlStrRep {
constructor () {

@@ -6,0 +6,0 @@ this.endObj = {

@@ -7,11 +7,13 @@ // npx webpack --config webpack.config.js

module.exports = {
entry: 'index.js',
entry: './index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'index.js',
path: path.resolve(__dirname, 'dist')
library: 'HtmlStrReplace', // 暴露library
libraryTarget: 'umd' //libraryTarget 控制 library 如何以不同方式暴露的选项(var this window umd)。
},
plugins: [
// tree shaking
new UglifyJSPlugin()
// new UglifyJSPlugin()
]
}