selector-parse
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -23,3 +23,17 @@ /*! | ||
var result = {}; | ||
var cache = null; | ||
selectors.forEach(function (selector) { | ||
selector = selector.trim(); | ||
if (cache !== null) { | ||
selector = cache + selector; | ||
} | ||
if (selector[0] === '[') { | ||
if (!selector.endsWith(']')) { | ||
cache = selector; | ||
return; | ||
} | ||
} | ||
cache = null; | ||
var detail = specity(selector.trim()); | ||
@@ -26,0 +40,0 @@ if (detail.attr) { |
@@ -6,2 +6,2 @@ /*! | ||
*/ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.selectorParse=e()}(this,function(){"use strict";function t(t){var a=/([#.[{]?[^#.\[{]+)/g,r=t.match(a);return r?e(r):{}}function e(t){var e={};return t.forEach(function(t){var r=a(t.trim());r.attr?e[r.attr]&&"class"===r.attr?e["class"].push(r.val):"class"===r.attr?e["class"]=[r.val]:e[r.attr]||(e[r.attr]=r.val):e.tag=r.val}),e.dataSet=Object.keys(e).filter(function(t){return 0===t.indexOf("data-")}).reduce(function(t,a){return t[a.substr(5)]=e[a],delete e[a],t},{}),e.tag||(e.tag="div"),e["class"]&&(e.className=e.classList=e["class"],e.className=e.className.join(" "),delete e["class"]),e}function a(t){if("#"===t[0])return{attr:"id",val:t.slice(1,t.length)};if("."===t[0])return{attr:"class",val:t.slice(1,t.length)};if("["===t[0]&&"]"===t[t.length-1]){var e=t.slice(1,t.length-1).split("="),a=e[0],r=e[1]||!0;return{attr:a,val:r}}return"{"===t[0]&&"}"===t[t.length-1]?{attr:"innerText",val:t.match(/{(.*)}/)[1]}:{attr:null,val:t}}return t}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.selectorParse=e()}(this,function(){"use strict";function t(t){var a=/([#.[{]?[^#.\[{]+)/g,n=t.match(a);return n?e(n):{}}function e(t){var e={},n=null;return t.forEach(function(t){if(t=t.trim(),null!==n&&(t=n+t),"["===t[0]&&!t.endsWith("]"))return void(n=t);n=null;var r=a(t.trim());r.attr?e[r.attr]&&"class"===r.attr?e["class"].push(r.val):"class"===r.attr?e["class"]=[r.val]:e[r.attr]||(e[r.attr]=r.val):e.tag=r.val}),e.dataSet=Object.keys(e).filter(function(t){return 0===t.indexOf("data-")}).reduce(function(t,a){return t[a.substr(5)]=e[a],delete e[a],t},{}),e.tag||(e.tag="div"),e["class"]&&(e.className=e.classList=e["class"],e.className=e.className.join(" "),delete e["class"]),e}function a(t){if("#"===t[0])return{attr:"id",val:t.slice(1,t.length)};if("."===t[0])return{attr:"class",val:t.slice(1,t.length)};if("["===t[0]&&"]"===t[t.length-1]){var e=t.slice(1,t.length-1).split("="),a=e[0],n=e[1]||!0;return{attr:a,val:n}}return"{"===t[0]&&"}"===t[t.length-1]?{attr:"innerText",val:t.match(/{(.*)}/)[1]}:{attr:null,val:t}}return t}); |
@@ -12,3 +12,17 @@ function selectorParse(selector) { | ||
const result = {}; | ||
let cache = null; | ||
selectors.forEach(selector => { | ||
selector = selector.trim(); | ||
if (cache !== null) { | ||
selector = cache + selector; | ||
} | ||
if (selector[0] === '[') { | ||
if (!selector.endsWith(']')) { | ||
cache = selector; | ||
return; | ||
} | ||
} | ||
cache = null; | ||
const detail = specity(selector.trim()); | ||
@@ -15,0 +29,0 @@ if (detail.attr) { |
{ | ||
"name": "selector-parse", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "Selector parser", | ||
@@ -5,0 +5,0 @@ "main": "dist/selector-parse.js", |
11740
246