Comparing version 1.0.0 to 1.0.1
/*! | ||
* dolmx.js v1.0.0 | ||
* (c) 2018-2018 echosoar | ||
* (c) 2018-2020 echosoar | ||
* Released under the MIT License. | ||
@@ -18,4 +18,4 @@ */ | ||
var attrObj = {}; | ||
trimStr(attr).split(/['"]\s+/).map(function (item) { | ||
item = trimStr(item); | ||
trimStr(attr).split(/['"]\s+/).forEach(function (itemOrigin) { | ||
var item = trimStr(itemOrigin); | ||
if (!item) return; | ||
@@ -30,9 +30,10 @@ var tmp = item.split(/=['"]/); | ||
function dolmx(xmlstr) { | ||
var reg = /^<\??([a-z][\w\.\-]*)(\s[^>]*?)?[\/\?]>|^<([a-z][\w\.\-]*)(\s.*?)?>((?:(?!<\3).)*)<\/\3>|^<([\w\-]+)(\s+.*?)?>((?:<\6.*?<\/\6>|<\6[^>]*?\/>|(?:(?!<\6).)*)*)<\/\6>/igm, | ||
isValueReg = /^<!\[CDATA\[(.*?)\]\]>$/im, | ||
mached = void 0, | ||
key = void 0, | ||
child = void 0, | ||
result = {}; | ||
function dolmx(xmlstring) { | ||
var reg = /^<\??([a-z][\w\.\-]*)(\s[^>]*?)?[\/\?]>|^<([a-z][\w\.\-]*)(\s.*?)?>((?:(?!<\3).)*)<\/\3>|^<([\w\-]+)(\s+.*?)?>((?:<\6.*?<\/\6>|<\6[^>]*?\/>|(?:(?!<\6).)*)*)<\/\6>/igm; | ||
var isValueReg = /^<!\[CDATA\[(.*?)\]\]>$/im; | ||
var result = {}; | ||
var mached = void 0; | ||
var key = void 0; | ||
var child = void 0; | ||
var xmlstr = xmlstring; | ||
@@ -44,4 +45,4 @@ xmlstr = xmlstr.replace(/\s*\n+\s*/gm, ''); | ||
if (isValueReg.test(xmlstr)) return { _value: xmlstr.replace(isValueReg, '$1') }; | ||
while (mached = reg.exec(xmlstr)) { | ||
mached = reg.exec(xmlstr); | ||
while (mached) { | ||
xmlstr = xmlstr.substring(0, mached.index) + xmlstr.substring(mached.index + mached[0].length); | ||
@@ -72,2 +73,3 @@ reg.lastIndex = 0; | ||
} | ||
mached = reg.exec(xmlstr); | ||
} | ||
@@ -74,0 +76,0 @@ return result; |
/*! | ||
* dolmx.js v1.0.0 | ||
* (c) 2018-2018 echosoar | ||
* (c) 2018-2020 echosoar | ||
* Released under the MIT License. | ||
@@ -16,4 +16,4 @@ */ | ||
var attrObj = {}; | ||
trimStr(attr).split(/['"]\s+/).map(function (item) { | ||
item = trimStr(item); | ||
trimStr(attr).split(/['"]\s+/).forEach(function (itemOrigin) { | ||
var item = trimStr(itemOrigin); | ||
if (!item) return; | ||
@@ -28,9 +28,10 @@ var tmp = item.split(/=['"]/); | ||
function dolmx(xmlstr) { | ||
var reg = /^<\??([a-z][\w\.\-]*)(\s[^>]*?)?[\/\?]>|^<([a-z][\w\.\-]*)(\s.*?)?>((?:(?!<\3).)*)<\/\3>|^<([\w\-]+)(\s+.*?)?>((?:<\6.*?<\/\6>|<\6[^>]*?\/>|(?:(?!<\6).)*)*)<\/\6>/igm, | ||
isValueReg = /^<!\[CDATA\[(.*?)\]\]>$/im, | ||
mached = void 0, | ||
key = void 0, | ||
child = void 0, | ||
result = {}; | ||
function dolmx(xmlstring) { | ||
var reg = /^<\??([a-z][\w\.\-]*)(\s[^>]*?)?[\/\?]>|^<([a-z][\w\.\-]*)(\s.*?)?>((?:(?!<\3).)*)<\/\3>|^<([\w\-]+)(\s+.*?)?>((?:<\6.*?<\/\6>|<\6[^>]*?\/>|(?:(?!<\6).)*)*)<\/\6>/igm; | ||
var isValueReg = /^<!\[CDATA\[(.*?)\]\]>$/im; | ||
var result = {}; | ||
var mached = void 0; | ||
var key = void 0; | ||
var child = void 0; | ||
var xmlstr = xmlstring; | ||
@@ -42,4 +43,4 @@ xmlstr = xmlstr.replace(/\s*\n+\s*/gm, ''); | ||
if (isValueReg.test(xmlstr)) return { _value: xmlstr.replace(isValueReg, '$1') }; | ||
while (mached = reg.exec(xmlstr)) { | ||
mached = reg.exec(xmlstr); | ||
while (mached) { | ||
xmlstr = xmlstr.substring(0, mached.index) + xmlstr.substring(mached.index + mached[0].length); | ||
@@ -70,2 +71,3 @@ reg.lastIndex = 0; | ||
} | ||
mached = reg.exec(xmlstr); | ||
} | ||
@@ -72,0 +74,0 @@ return result; |
/*! | ||
* dolmx.js v1.0.0 | ||
* (c) 2018-2018 echosoar | ||
* (c) 2018-2020 echosoar | ||
* Released under the MIT License. | ||
@@ -22,4 +22,4 @@ */ | ||
var attrObj = {}; | ||
trimStr(attr).split(/['"]\s+/).map(function (item) { | ||
item = trimStr(item); | ||
trimStr(attr).split(/['"]\s+/).forEach(function (itemOrigin) { | ||
var item = trimStr(itemOrigin); | ||
if (!item) return; | ||
@@ -34,9 +34,10 @@ var tmp = item.split(/=['"]/); | ||
function dolmx(xmlstr) { | ||
var reg = /^<\??([a-z][\w\.\-]*)(\s[^>]*?)?[\/\?]>|^<([a-z][\w\.\-]*)(\s.*?)?>((?:(?!<\3).)*)<\/\3>|^<([\w\-]+)(\s+.*?)?>((?:<\6.*?<\/\6>|<\6[^>]*?\/>|(?:(?!<\6).)*)*)<\/\6>/igm, | ||
isValueReg = /^<!\[CDATA\[(.*?)\]\]>$/im, | ||
mached = void 0, | ||
key = void 0, | ||
child = void 0, | ||
result = {}; | ||
function dolmx(xmlstring) { | ||
var reg = /^<\??([a-z][\w\.\-]*)(\s[^>]*?)?[\/\?]>|^<([a-z][\w\.\-]*)(\s.*?)?>((?:(?!<\3).)*)<\/\3>|^<([\w\-]+)(\s+.*?)?>((?:<\6.*?<\/\6>|<\6[^>]*?\/>|(?:(?!<\6).)*)*)<\/\6>/igm; | ||
var isValueReg = /^<!\[CDATA\[(.*?)\]\]>$/im; | ||
var result = {}; | ||
var mached = void 0; | ||
var key = void 0; | ||
var child = void 0; | ||
var xmlstr = xmlstring; | ||
@@ -48,4 +49,4 @@ xmlstr = xmlstr.replace(/\s*\n+\s*/gm, ''); | ||
if (isValueReg.test(xmlstr)) return { _value: xmlstr.replace(isValueReg, '$1') }; | ||
while (mached = reg.exec(xmlstr)) { | ||
mached = reg.exec(xmlstr); | ||
while (mached) { | ||
xmlstr = xmlstr.substring(0, mached.index) + xmlstr.substring(mached.index + mached[0].length); | ||
@@ -76,2 +77,3 @@ reg.lastIndex = 0; | ||
} | ||
mached = reg.exec(xmlstr); | ||
} | ||
@@ -78,0 +80,0 @@ return result; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.dolmx=t()}(this,function(){"use strict";function e(e){return(e||"").replace(/^([^\w]|\s)+/g,"").replace(/([^\w]|\s)+$/g,"")}function t(t){var r={};return e(t).split(/['"]\s+/).map(function(t){if(t=e(t)){var n=t.split(/=['"]/),i=e(n[0]);if(i)r[i]=e(n[1]).replace(/^("|')(.*)\1$/,"$2")||!0}}),r}return function r(n){var i=/^<\??([a-z][\w\.\-]*)(\s[^>]*?)?[\/\?]>|^<([a-z][\w\.\-]*)(\s.*?)?>((?:(?!<\3).)*)<\/\3>|^<([\w\-]+)(\s+.*?)?>((?:<\6.*?<\/\6>|<\6[^>]*?\/>|(?:(?!<\6).)*)*)<\/\6>/gim,s=/^<!\[CDATA\[(.*?)\]\]>$/im,u=void 0,a=void 0,o=void 0,f={};if(n=n.replace(/\s*\n+\s*/gm,""),!/^</.test(n))return{_value:n};if(s.test(n))return{_value:n.replace(s,"$1")};for(;u=i.exec(n);)n=n.substring(0,u.index)+n.substring(u.index+u[0].length),i.lastIndex=0,u[1]?(a=e(u[1]),o={_attr:t(u[2])}):u[3]?(a=e(u[3]),o={},u[5]&&(o=r(u[5])),o._attr=t(u[4])):u[6]&&(a=e(u[6]),o={},u[8]&&(o=r(u[8])),o._attr=t(u[7])),f[a]?(Array.isArray(f[a])||(f[a]=[f[a]]),f[a].push(o)):f[a]=o;return f}}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.dolmx=t()}(this,function(){"use strict";function e(e){return(e||"").replace(/^([^\w]|\s)+/g,"").replace(/([^\w]|\s)+$/g,"")}function t(t){var r={};return e(t).split(/['"]\s+/).forEach(function(t){var n=e(t);if(n){var i=n.split(/=['"]/),s=e(i[0]);if(s)r[s]=e(i[1]).replace(/^("|')(.*)\1$/,"$2")||!0}}),r}return function r(n){var i=/^<\??([a-z][\w\.\-]*)(\s[^>]*?)?[\/\?]>|^<([a-z][\w\.\-]*)(\s.*?)?>((?:(?!<\3).)*)<\/\3>|^<([\w\-]+)(\s+.*?)?>((?:<\6.*?<\/\6>|<\6[^>]*?\/>|(?:(?!<\6).)*)*)<\/\6>/gim,s=/^<!\[CDATA\[(.*?)\]\]>$/im,u={},a=void 0,o=void 0,f=void 0,c=n;if(c=c.replace(/\s*\n+\s*/gm,""),!/^</.test(c))return{_value:c};if(s.test(c))return{_value:c.replace(s,"$1")};for(a=i.exec(c);a;)c=c.substring(0,a.index)+c.substring(a.index+a[0].length),i.lastIndex=0,a[1]?(o=e(a[1]),f={_attr:t(a[2])}):a[3]?(o=e(a[3]),f={},a[5]&&(f=r(a[5])),f._attr=t(a[4])):a[6]&&(o=e(a[6]),f={},a[8]&&(f=r(a[8])),f._attr=t(a[7])),u[o]?(Array.isArray(u[o])||(u[o]=[u[o]]),u[o].push(f)):u[o]=f,a=i.exec(c);return u}}); |
{ | ||
"name": "dolmx", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "mini xml parser", | ||
@@ -62,8 +62,5 @@ "main": "index.js", | ||
"rollup-plugin-uglify": "^3.0.0", | ||
"serve": "^6.5.7", | ||
"uglify-es": "^3.3.9" | ||
}, | ||
"dependencies": { | ||
"uglify-es": "^3.3.9", | ||
"babel-runtime": "^6.26.0" | ||
} | ||
} |
@@ -15,2 +15,6 @@ Dolmx is a **1kb** [XML] parser. | ||
``` | ||
npm i dolmx --save | ||
``` | ||
Dolmx exports a single function, which parses a string of XML and returns a javscript Object. Couldn't be simpler. | ||
@@ -17,0 +21,0 @@ |
@@ -10,8 +10,8 @@ function trimStr(str) { | ||
function formatAttr(attr) { | ||
let attrObj = {}; | ||
trimStr(attr).split(/['"]\s+/).map(item => { | ||
item = trimStr(item); | ||
const attrObj = {}; | ||
trimStr(attr).split(/['"]\s+/).forEach(itemOrigin => { | ||
const item = trimStr(itemOrigin); | ||
if (!item) return; | ||
let tmp = item.split(/=['"]/); | ||
let key = trimStr(tmp[0]); | ||
const tmp = item.split(/=['"]/); | ||
const key = trimStr(tmp[0]); | ||
if (!key) return; | ||
@@ -23,9 +23,10 @@ attrObj[key] = trimQuote(tmp[1]) || true; | ||
export default function dolmx(xmlstr) { | ||
let reg = /^<\??([a-z][\w\.\-]*)(\s[^>]*?)?[\/\?]>|^<([a-z][\w\.\-]*)(\s.*?)?>((?:(?!<\3).)*)<\/\3>|^<([\w\-]+)(\s+.*?)?>((?:<\6.*?<\/\6>|<\6[^>]*?\/>|(?:(?!<\6).)*)*)<\/\6>/igm, | ||
isValueReg = /^<!\[CDATA\[(.*?)\]\]>$/im, | ||
mached, | ||
key, | ||
child, | ||
result = {}; | ||
export default function dolmx(xmlstring) { | ||
const reg = /^<\??([a-z][\w\.\-]*)(\s[^>]*?)?[\/\?]>|^<([a-z][\w\.\-]*)(\s.*?)?>((?:(?!<\3).)*)<\/\3>|^<([\w\-]+)(\s+.*?)?>((?:<\6.*?<\/\6>|<\6[^>]*?\/>|(?:(?!<\6).)*)*)<\/\6>/igm; | ||
const isValueReg = /^<!\[CDATA\[(.*?)\]\]>$/im; | ||
const result = {}; | ||
let mached; | ||
let key; | ||
let child; | ||
let xmlstr = xmlstring; | ||
@@ -37,4 +38,4 @@ xmlstr = xmlstr.replace(/\s*\n+\s*/gm, ''); | ||
if (isValueReg.test(xmlstr)) return { _value: xmlstr.replace(isValueReg, '$1') }; | ||
while(mached = reg.exec(xmlstr)) { | ||
mached = reg.exec(xmlstr); | ||
while(mached) { | ||
xmlstr = xmlstr.substring(0, mached.index) + xmlstr.substring(mached.index + mached[0].length); | ||
@@ -65,4 +66,5 @@ reg.lastIndex = 0; | ||
} | ||
mached = reg.exec(xmlstr); | ||
} | ||
return result; | ||
} |
Sorry, the diff of this file is not supported yet
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
297103
0
429
100
- Removedbabel-runtime@^6.26.0
- Removedbabel-runtime@6.26.0(transitive)
- Removedcore-js@2.6.12(transitive)
- Removedregenerator-runtime@0.11.1(transitive)