als-document 0.6.11 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/document.js CHANGED
@@ -103,8 +103,8 @@ class HtmlSelector {
103
103
  let passedTests = 0
104
104
  if(attribs) for(let i=0; i<attribs.length; i++) {
105
105
  let {name,value,check} = attribs[i]
106
- if(name == 'inner' && value !== undefined && check && el.innerText) {
107
- if(check(el.innerText)) passedTests++
106
+ if(name == 'inner' && value !== undefined && check && el.inner) {
107
+ if(check(el.inner)) passedTests++
108
108
  }
109
109
 
110
110
  if(!names.includes(name)) continue
@@ -118,7 +118,6 @@ class HtmlSelector {
118
118
  else return false
119
119
  }
120
120
  }
121
-
122
121
  class Query {
123
122
  static get(query) {
124
123
  let q = new Query(query)
@@ -265,7 +264,6 @@ class Query {
265
264
  return selector
266
265
  }
267
266
  }
268
-
269
267
  class HtmlParser {
270
268
  static parse(html) {
271
269
  let result = new HtmlParser(html)
@@ -319,7 +317,6 @@ class HtmlParser {
319
317
  }
320
318
 
321
319
  removeEventStrings() {
322
- // let eventsWithHtml = this.htmlString.match(/on\w*\s*?\=\s*?["|'|`](.*?(<[^>]*>)(\'|\`).*?)["|'|`]/g)
323
320
  let eventsWithHtml = this.htmlString.match(/\son\w*\s*?\=\s*?\"(.*?)\"/g)
324
321
  if(eventsWithHtml !== null) {
325
322
  eventsWithHtml.forEach(event => {
@@ -335,7 +332,6 @@ class HtmlParser {
335
332
 
336
333
  parse(htmlString=this.htmlString) {
337
334
  // Parse tags
338
- // let elements = htmlString.match(/<[^>]*>/g)
339
335
  let elements = htmlString.match(/<("[^"]*"|'[^']*'|[^'">])*>/g)
340
336
  elements.forEach((tag,index) => {
341
337
  elements[index] = this.parseElement(tag)
@@ -515,6 +511,16 @@ class HtmlParser {
515
511
 
516
512
  innerText(element) {
517
513
  Object.defineProperty(element, 'innerText', { get() {
514
+ if(element.children)
515
+ return element.children.map(child =>
516
+ child.type == 'text' ? child.text.trim()
517
+ : child.type == 'tag'
518
+ ? child.innerText
519
+ : ''
520
+ ).join(' ')
521
+ else return ''
522
+ }})
523
+ Object.defineProperty(element, 'inner', { get() {
518
524
  if(element.children)
519
525
  return element.children.map(child => child.type == 'text' ? child.text : '').join('')
520
526
  else return ''
@@ -568,13 +574,14 @@ class HtmlParser {
568
574
 
569
575
  parseAttributes(tagString,classList=[],attribs={},style={},id=null) {
570
576
  let text = tagString
571
- let attributes = tagString.match(/(?<=\s)(\w*\-?)*(\s*?\=\s*?\"[\s\S]*?\")?/g)
572
- if(attributes) attributes.forEach(attribString => {
577
+ let attributes = tagString.match(/(\w+)(?:\s*=\s*(['"]?)(.*?)\2)?/g)
578
+ if(attributes) attributes.forEach((attribString,i) => {
579
+ if(i == 0) return
573
580
  let array = attribString.split('=')
574
581
  let name = array[0]
575
582
  if(array.length>1 && name !== '') {
576
583
  let value = array.filter((v,i) => i>0).join('=')
577
- value = value.trim().replace(/^\"/,'').replace(/\"$/m,'')
584
+ value = value.trim().replace(/^\"|\'/,'').replace(/\"|\'$/m,'')
578
585
  let eventIndex = value.match(/(?<=\{\{\{\{event\s)(\d*)?/)
579
586
  if(eventIndex !== null) {
580
587
  value = this.events[eventIndex[0]]
@@ -648,6 +655,7 @@ class Document extends HtmlSelector {
648
655
  obj[prop] = value
649
656
  element.attribs.style = Object.keys(obj).map(key => `${convertProp(key)}:${obj[key]};`).join('')
650
657
  self.changeElementText(this)
658
+ return true
651
659
  },
652
660
  deleteProperty(obj, prop) {
653
661
  if (prop in obj) {
@@ -655,6 +663,7 @@ class Document extends HtmlSelector {
655
663
  element.attribs.style = Object.keys(obj).map(key => `${convertProp(key)}:${obj[key]};`).join('')
656
664
  }
657
665
  self.changeElementText(this)
666
+ return true
658
667
  }
659
668
  };
660
669
  element.style = new Proxy(obj, handler);
@@ -792,4 +801,6 @@ class Document extends HtmlSelector {
792
801
  element.text = `<${tag}${atts}>`
793
802
  }
794
803
  }
795
- }
804
+ }
805
+
806
+ try {module.exports = {HtmlSelector,Query,HtmlParser,Document}} catch (error) {}