als-document 0.6.1 → 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)
@@ -513,6 +511,16 @@ class HtmlParser {
513
511
 
514
512
  innerText(element) {
515
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() {
516
524
  if(element.children)
517
525
  return element.children.map(child => child.type == 'text' ? child.text : '').join('')
518
526
  else return ''
@@ -566,11 +574,14 @@ class HtmlParser {
566
574
 
567
575
  parseAttributes(tagString,classList=[],attribs={},style={},id=null) {
568
576
  let text = tagString
569
- let attributes = tagString.match(/(?<=\s)(\w*\-?)*(\s*?\=\s*?\"[\s\S]*?\")?/g)
570
- if(attributes) attributes.forEach(attribString => {
571
- let [name,value] = attribString.split('=')
572
- if(value !== undefined && name !== '') {
573
- value = value.trim().replace(/^\"/,'').replace(/\"$/m,'')
577
+ let attributes = tagString.match(/(\w+)(?:\s*=\s*(['"]?)(.*?)\2)?/g)
578
+ if(attributes) attributes.forEach((attribString,i) => {
579
+ if(i == 0) return
580
+ let array = attribString.split('=')
581
+ let name = array[0]
582
+ if(array.length>1 && name !== '') {
583
+ let value = array.filter((v,i) => i>0).join('=')
584
+ value = value.trim().replace(/^\"|\'/,'').replace(/\"|\'$/m,'')
574
585
  let eventIndex = value.match(/(?<=\{\{\{\{event\s)(\d*)?/)
575
586
  if(eventIndex !== null) {
576
587
  value = this.events[eventIndex[0]]
@@ -601,7 +612,6 @@ class HtmlParser {
601
612
  return styles
602
613
  }
603
614
  }
604
-
605
615
  class Document extends HtmlSelector {
606
616
  constructor(html) {
607
617
  super(html)
@@ -645,6 +655,7 @@ class Document extends HtmlSelector {
645
655
  obj[prop] = value
646
656
  element.attribs.style = Object.keys(obj).map(key => `${convertProp(key)}:${obj[key]};`).join('')
647
657
  self.changeElementText(this)
658
+ return true
648
659
  },
649
660
  deleteProperty(obj, prop) {
650
661
  if (prop in obj) {
@@ -652,6 +663,7 @@ class Document extends HtmlSelector {
652
663
  element.attribs.style = Object.keys(obj).map(key => `${convertProp(key)}:${obj[key]};`).join('')
653
664
  }
654
665
  self.changeElementText(this)
666
+ return true
655
667
  }
656
668
  };
657
669
  element.style = new Proxy(obj, handler);
@@ -789,4 +801,6 @@ class Document extends HtmlSelector {
789
801
  element.text = `<${tag}${atts}>`
790
802
  }
791
803
  }
792
- }
804
+ }
805
+
806
+ try {module.exports = {HtmlSelector,Query,HtmlParser,Document}} catch (error) {}