Comparing version 0.2.0 to 0.2.1
@@ -9,12 +9,9 @@ 'use strict'; | ||
const isNode = (template, i) => { | ||
while (i--) { | ||
const chunk = template[i]; | ||
if (node.test(chunk)) | ||
return true; | ||
if (notNode.test(chunk)) | ||
return false; | ||
} | ||
return false; | ||
}; | ||
const isNode = (template, i) => ( | ||
0 < i-- && ( | ||
node.test(template[i]) || ( | ||
!notNode.test(template[i]) && isNode(template, i) | ||
) | ||
) | ||
); | ||
@@ -26,14 +23,16 @@ const regular = (original, name, extra) => empty.test(name) ? | ||
const text = []; | ||
for (let i = 0, {length} = template; i < length; i++) { | ||
const chunk = template[i]; | ||
if (attr.test(chunk) && isNode(template, i + 1)) | ||
text.push(chunk.replace(attr, (_, $1, $2) => | ||
`${prefix}${i}=${$2 ? $2 : '"'}${$1}${$2 ? '' : '"'}`)); | ||
else if ((i + 1) < length) | ||
text.push(chunk, `<!--${prefix}${i}-->`); | ||
else | ||
text.push(chunk); | ||
const {length} = template; | ||
for (let i = 1; i < length; i++) { | ||
const chunk = template[i - 1]; | ||
text.push(attr.test(chunk) && isNode(template, i) ? | ||
chunk.replace( | ||
attr, | ||
(_, $1, $2) => `${prefix}${i - 1}=${$2 || '"'}${$1}${$2 ? '' : '"'}` | ||
) : | ||
`${chunk}<!--${prefix}${i - 1}-->` | ||
); | ||
} | ||
text.push(template[length - 1]); | ||
const output = text.join('').trim(); | ||
return svg ? output : output.replace(selfClosing, regular); | ||
}; |
@@ -1,1 +0,1 @@ | ||
var uparser=function(e){"use strict";const t=/([^\s\\>"'=]+)\s*=\s*(['"]?)$/,r=/^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i,s=/<[a-z][^>]+$/i,n=/>[^<>]*$/,a=/<([a-z]+[a-z0-9:._-]*)([^>]*?)(\/>)/gi,u=/\s+$/,$=(e,t)=>{for(;t--;){const r=e[t];if(s.test(r))return!0;if(n.test(r))return!1}return!1},c=(e,t,s)=>r.test(t)?e:`<${t}${s.replace(u,"")}></${t}>`;return e.default=(e,r,s)=>{const n=[];for(let s=0,{length:a}=e;s<a;s++){const u=e[s];t.test(u)&&$(e,s+1)?n.push(u.replace(t,(e,t,n)=>`${r}${s}=${n||'"'}${t}${n?"":'"'}`)):s+1<a?n.push(u,`\x3c!--${r}${s}--\x3e`):n.push(u)}const u=n.join("").trim();return s?u:u.replace(a,c)},e}({}).default; | ||
var uparser=function(e){"use strict";const t=/([^\s\\>"'=]+)\s*=\s*(['"]?)$/,r=/^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i,s=/<[a-z][^>]+$/i,a=/>[^<>]*$/,$=/<([a-z]+[a-z0-9:._-]*)([^>]*?)(\/>)/gi,n=/\s+$/,c=(e,t)=>0<t--&&(s.test(e[t])||!a.test(e[t])&&c(e,t)),i=(e,t,s)=>r.test(t)?e:`<${t}${s.replace(n,"")}></${t}>`;return e.default=(e,r,s)=>{const a=[],{length:n}=e;for(let s=1;s<n;s++){const $=e[s-1];a.push(t.test($)&&c(e,s)?$.replace(t,(e,t,a)=>`${r}${s-1}=${a||'"'}${t}${a?"":'"'}`):`${$}\x3c!--${r}${s-1}--\x3e`)}a.push(e[n-1]);const u=a.join("").trim();return s?u:u.replace($,i)},e}({}).default; |
@@ -8,12 +8,9 @@ const attr = /([^\s\\>"'=]+)\s*=\s*(['"]?)$/; | ||
const isNode = (template, i) => { | ||
while (i--) { | ||
const chunk = template[i]; | ||
if (node.test(chunk)) | ||
return true; | ||
if (notNode.test(chunk)) | ||
return false; | ||
} | ||
return false; | ||
}; | ||
const isNode = (template, i) => ( | ||
0 < i-- && ( | ||
node.test(template[i]) || ( | ||
!notNode.test(template[i]) && isNode(template, i) | ||
) | ||
) | ||
); | ||
@@ -25,14 +22,16 @@ const regular = (original, name, extra) => empty.test(name) ? | ||
const text = []; | ||
for (let i = 0, {length} = template; i < length; i++) { | ||
const chunk = template[i]; | ||
if (attr.test(chunk) && isNode(template, i + 1)) | ||
text.push(chunk.replace(attr, (_, $1, $2) => | ||
`${prefix}${i}=${$2 ? $2 : '"'}${$1}${$2 ? '' : '"'}`)); | ||
else if ((i + 1) < length) | ||
text.push(chunk, `<!--${prefix}${i}-->`); | ||
else | ||
text.push(chunk); | ||
const {length} = template; | ||
for (let i = 1; i < length; i++) { | ||
const chunk = template[i - 1]; | ||
text.push(attr.test(chunk) && isNode(template, i) ? | ||
chunk.replace( | ||
attr, | ||
(_, $1, $2) => `${prefix}${i - 1}=${$2 || '"'}${$1}${$2 ? '' : '"'}` | ||
) : | ||
`${chunk}<!--${prefix}${i - 1}-->` | ||
); | ||
} | ||
text.push(template[length - 1]); | ||
const output = text.join('').trim(); | ||
return svg ? output : output.replace(selfClosing, regular); | ||
}; |
24
index.js
@@ -12,9 +12,3 @@ var uparser = (function (exports) { | ||
var isNode = function isNode(template, i) { | ||
while (i--) { | ||
var chunk = template[i]; | ||
if (node.test(chunk)) return true; | ||
if (notNode.test(chunk)) return false; | ||
} | ||
return false; | ||
return 0 < i-- && (node.test(template[i]) || !notNode.test(template[i]) && isNode(template, i)); | ||
}; | ||
@@ -28,14 +22,16 @@ | ||
var text = []; | ||
var length = template.length; | ||
var _loop = function _loop(i, length) { | ||
var chunk = template[i]; | ||
if (attr.test(chunk) && isNode(template, i + 1)) text.push(chunk.replace(attr, function (_, $1, $2) { | ||
return "".concat(prefix).concat(i, "=").concat($2 ? $2 : '"').concat($1).concat($2 ? '' : '"'); | ||
}));else if (i + 1 < length) text.push(chunk, "<!--".concat(prefix).concat(i, "-->"));else text.push(chunk); | ||
var _loop = function _loop(i) { | ||
var chunk = template[i - 1]; | ||
text.push(attr.test(chunk) && isNode(template, i) ? chunk.replace(attr, function (_, $1, $2) { | ||
return "".concat(prefix).concat(i - 1, "=").concat($2 || '"').concat($1).concat($2 ? '' : '"'); | ||
}) : "".concat(chunk, "<!--").concat(prefix).concat(i - 1, "-->")); | ||
}; | ||
for (var i = 0, length = template.length; i < length; i++) { | ||
_loop(i, length); | ||
for (var i = 1; i < length; i++) { | ||
_loop(i); | ||
} | ||
text.push(template[length - 1]); | ||
var output = text.join('').trim(); | ||
@@ -42,0 +38,0 @@ return svg ? output : output.replace(selfClosing, regular); |
@@ -1,1 +0,1 @@ | ||
var uparser=function(t){"use strict";function i(t,r,n){return c.test(r)?t:"<".concat(r).concat(n.replace(e,""),"></").concat(r,">")}var s=/([^\s\\>"'=]+)\s*=\s*(['"]?)$/,c=/^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i,f=/<[a-z][^>]+$/i,p=/>[^<>]*$/,l=/<([a-z]+[a-z0-9:._-]*)([^>]*?)(\/>)/gi,e=/\s+$/;return t.default=function(n,e,t){for(var a=[],r=function(c,t){var r=n[c];s.test(r)&&function(t,r){for(;r--;){var n=t[r];if(f.test(n))return!0;if(p.test(n))return!1}return!1}(n,c+1)?a.push(r.replace(s,function(t,r,n){return"".concat(e).concat(c,"=").concat(n||'"').concat(r).concat(n?"":'"')})):c+1<t?a.push(r,"\x3c!--".concat(e).concat(c,"--\x3e")):a.push(r)},c=0,u=n.length;c<u;c++)r(c,u);var o=a.join("").trim();return t?o:o.replace(l,i)},t}({}).default; | ||
var uparser=function(t){"use strict";function i(t,c,n){return a.test(c)?t:"<".concat(c).concat(n.replace(e,""),"></").concat(c,">")}var s=/([^\s\\>"'=]+)\s*=\s*(['"]?)$/,a=/^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i,f=/<[a-z][^>]+$/i,p=/>[^<>]*$/,l=/<([a-z]+[a-z0-9:._-]*)([^>]*?)(\/>)/gi,e=/\s+$/;return t.default=function(c,e,t){for(var n=[],a=c.length,r=function(a){var t=c[a-1];n.push(s.test(t)&&function t(c,n){return 0<n--&&(f.test(c[n])||!p.test(c[n])&&t(c,n))}(c,a)?t.replace(s,function(t,c,n){return"".concat(e).concat(a-1,"=").concat(n||'"').concat(c).concat(n?"":'"')}):"".concat(t,"\x3c!--").concat(e).concat(a-1,"--\x3e"))},o=1;o<a;o++)r(o);n.push(c[a-1]);var u=n.join("").trim();return t?u:u.replace(l,i)},t}({}).default; |
{ | ||
"name": "uparser", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "The uhtml template parser", | ||
"main": "./cjs/index.js", | ||
"scripts": { | ||
"build": "npm run cjs && npm run rollup:es && npm run rollup:babel && npm run min && npm run fix:default && npm run test", | ||
"build": "npm run cjs && npm run rollup:es && npm run rollup:babel && npm run min && npm run fix:default && npm run test && npm run size", | ||
"cjs": "ascjs --no-default esm cjs", | ||
@@ -13,2 +13,3 @@ "rollup:es": "rollup --config rollup/es.config.js", | ||
"fix:default": "sed -i 's/({})/({}).default/' index.js && sed -i 's/({})/({}).default/' es.js && sed -i 's/({})/({}).default/' min.js", | ||
"size": "cat min.js | brotli | wc -c && cat es.js | brotli | wc -c", | ||
"coveralls": "nyc report --reporter=text-lcov | coveralls", | ||
@@ -15,0 +16,0 @@ "test": "nyc node test/index.js" |
8279
101