als-document 1.3.0 → 1.3.1

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
@@ -29,7 +29,7 @@ class SingleNode extends Node{
29
29
  constructor(tagName,attributes={},parent=null)
30
30
 
31
31
  class Root extends Node{
32
32
  constructor(){
33
33
  super('ROOT',{},null);
34
34
  this.isSingle=false
35
35
  }
36
36
  }
37
- class Document extends Node{
38
37
  constructor(html,url){
39
38
  super('ROOT',{},null);
40
39
  this.isSingle=false
41
40
  this.URL=url
42
41
  if(html instanceof Document){
43
42
  this.childNodes=[...buildFromCache(cacheDoc(html)).childNodes]
44
43
  }
45
44
  else if(typeof html==='string') this.innerHTML=html
46
45
  else this.body
47
46
  }
48
47
  get documentElement(){return this.html}
49
48
  get html(){
50
49
  const html=this.$('html')
51
50
  if(html===null) this.innerHTML=/*html*/`<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title></title></head><body></body></html>`
52
51
  return this.$('html')
53
52
  }
54
53
  get head(){
55
54
  const head=this.$('head')
56
55
  if(head===null) this.html.insert(1,'<head></head>')
57
56
  return this.$('head')
58
57
  }
59
58
  get body(){
60
59
  const body=this.$('body')
61
60
  if(body===null) this.head.insert(3,'<body></body>')
62
61
  return this.$('body')
63
62
  }
64
63
  get title(){
65
64
  const title=this.$('title')
66
65
  if(title===null) this.head.insert(1,'<title></title>')
67
66
  return this.$('title').innerText
68
67
  }
69
68
  get charset(){return this.$('meta[charset]')}
70
69
  set title(title){return this.$('title').innerText=title}
71
70
  get clone(){return new Document(this)}
71
+ class Document extends Node{
72
72
  constructor(html,url){
73
73
  super('ROOT',{},null);
74
74
  this.isSingle=false
75
75
  this.URL=url
76
76
  if(html instanceof Document){
77
77
  this.childNodes=[...buildFromCache(cacheDoc(html)).childNodes]
78
78
  }
79
79
  else if(typeof html==='string') this.innerHTML=html
80
80
  else this.body
81
81
  }
82
82
  get documentElement(){return this.html}
83
83
  get html(){
84
84
  const html=this.$('html')
85
85
  if(html===null) this.innerHTML=/*html*/`<html lang="en"><head><meta charset="UTF-8"><title></title></head><body></body></html>`
86
86
  return this.$('html')
87
87
  }
88
88
  get innerHTML(){
89
89
  const inner=super.innerHTML
90
90
  return '<!DOCTYPE html>'+inner
91
91
  }
92
92
  set innerHTML(html){return super.innerHTML=html}
93
93
  get head(){
94
94
  const head=this.$('head')
95
95
  if(head===null) this.html.insert(1,'<head></head>')
96
96
  return this.$('head')
97
97
  }
98
98
  get body(){
99
99
  const body=this.$('body')
100
100
  if(body===null) this.head.insert(3,'<body></body>')
101
101
  return this.$('body')
102
102
  }
103
103
  get title(){
104
104
  const title=this.$('title')
105
105
  if(title===null) this.head.insert(1,'<title></title>')
106
106
  return this.$('title').innerText
107
107
  }
108
108
  get charset(){return this.$('meta[charset]')}
109
109
  set title(title){return this.$('title').innerText=title}
110
110
  get clone(){return new Document(this)}
111
111
  }
112
112
  function parseAttributes(str){
113
113
  const attrs={};
114
114
  let key="";
115
115
  let value="";
116
116
  let isKey=true;
117
117
  let quoteChar=null;
118
118
  for (let i=0; i< str.length; i++){
119
119
  const char=str[i];
120
120
  if (isKey && (char==='=' || char===' ')){
121
121
  if (char==='=') isKey=false;
122
122
  else if (key.trim()){
123
123
  attrs[key.trim()]=true;
124
124
  key="";
125
125
  }
126
126
  continue;
127
127
  }
128
128
  if (!quoteChar && (char==='"' || char==="'")){
129
129
  quoteChar=char;
130
130
  continue;
131
131
  } else if (quoteChar && char===quoteChar){
132
132
  quoteChar=null;
133
133
  attrs[key.trim()]=value.trim();
134
134
  key=""; value=""; isKey=true;
135
135
  continue;
136
136
  }
137
137
  if (isKey) key+=char;
138
138
  else value+=char;
139
139
  }
140
140
  if (key.trim() &&!value) attrs[key.trim()]='';
141
141
  return attrs;
142
142
  }
package/index.js CHANGED
@@ -28,7 +28,7 @@ class SingleNode extends Node{
28
28
  constructor(tagName,attributes={},parent=null)
29
29
 
30
30
  class Root extends Node{
31
31
  constructor(){
32
32
  super('ROOT',{},null);
33
33
  this.isSingle=false
34
34
  }
35
35
  }
36
- class Document extends Node{
37
36
  constructor(html,url){
38
37
  super('ROOT',{},null);
39
38
  this.isSingle=false
40
39
  this.URL=url
41
40
  if(html instanceof Document){
42
41
  this.childNodes=[...buildFromCache(cacheDoc(html)).childNodes]
43
42
  }
44
43
  else if(typeof html==='string') this.innerHTML=html
45
44
  else this.body
46
45
  }
47
46
  get documentElement(){return this.html}
48
47
  get html(){
49
48
  const html=this.$('html')
50
49
  if(html===null) this.innerHTML=/*html*/`<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title></title></head><body></body></html>`
51
50
  return this.$('html')
52
51
  }
53
52
  get head(){
54
53
  const head=this.$('head')
55
54
  if(head===null) this.html.insert(1,'<head></head>')
56
55
  return this.$('head')
57
56
  }
58
57
  get body(){
59
58
  const body=this.$('body')
60
59
  if(body===null) this.head.insert(3,'<body></body>')
61
60
  return this.$('body')
62
61
  }
63
62
  get title(){
64
63
  const title=this.$('title')
65
64
  if(title===null) this.head.insert(1,'<title></title>')
66
65
  return this.$('title').innerText
67
66
  }
68
67
  get charset(){return this.$('meta[charset]')}
69
68
  set title(title){return this.$('title').innerText=title}
70
69
  get clone(){return new Document(this)}
70
+ class Document extends Node{
71
71
  constructor(html,url){
72
72
  super('ROOT',{},null);
73
73
  this.isSingle=false
74
74
  this.URL=url
75
75
  if(html instanceof Document){
76
76
  this.childNodes=[...buildFromCache(cacheDoc(html)).childNodes]
77
77
  }
78
78
  else if(typeof html==='string') this.innerHTML=html
79
79
  else this.body
80
80
  }
81
81
  get documentElement(){return this.html}
82
82
  get html(){
83
83
  const html=this.$('html')
84
84
  if(html===null) this.innerHTML=/*html*/`<html lang="en"><head><meta charset="UTF-8"><title></title></head><body></body></html>`
85
85
  return this.$('html')
86
86
  }
87
87
  get innerHTML(){
88
88
  const inner=super.innerHTML
89
89
  return '<!DOCTYPE html>'+inner
90
90
  }
91
91
  set innerHTML(html){return super.innerHTML=html}
92
92
  get head(){
93
93
  const head=this.$('head')
94
94
  if(head===null) this.html.insert(1,'<head></head>')
95
95
  return this.$('head')
96
96
  }
97
97
  get body(){
98
98
  const body=this.$('body')
99
99
  if(body===null) this.head.insert(3,'<body></body>')
100
100
  return this.$('body')
101
101
  }
102
102
  get title(){
103
103
  const title=this.$('title')
104
104
  if(title===null) this.head.insert(1,'<title></title>')
105
105
  return this.$('title').innerText
106
106
  }
107
107
  get charset(){return this.$('meta[charset]')}
108
108
  set title(title){return this.$('title').innerText=title}
109
109
  get clone(){return new Document(this)}
110
110
  }
111
111
  function parseAttributes(str){
112
112
  const attrs={};
113
113
  let key="";
114
114
  let value="";
115
115
  let isKey=true;
116
116
  let quoteChar=null;
117
117
  for (let i=0; i< str.length; i++){
118
118
  const char=str[i];
119
119
  if (isKey && (char==='=' || char===' ')){
120
120
  if (char==='=') isKey=false;
121
121
  else if (key.trim()){
122
122
  attrs[key.trim()]=true;
123
123
  key="";
124
124
  }
125
125
  continue;
126
126
  }
127
127
  if (!quoteChar && (char==='"' || char==="'")){
128
128
  quoteChar=char;
129
129
  continue;
130
130
  } else if (quoteChar && char===quoteChar){
131
131
  quoteChar=null;
132
132
  attrs[key.trim()]=value.trim();
133
133
  key=""; value=""; isKey=true;
134
134
  continue;
135
135
  }
136
136
  if (isKey) key+=char;
137
137
  else value+=char;
138
138
  }
139
139
  if (key.trim() &&!value) attrs[key.trim()]='';
140
140
  return attrs;
141
141
  }
package/index.mjs CHANGED
@@ -28,7 +28,7 @@ class SingleNode extends Node{
28
28
  constructor(tagName,attributes={},parent=null)
29
29
 
30
30
  class Root extends Node{
31
31
  constructor(){
32
32
  super('ROOT',{},null);
33
33
  this.isSingle=false
34
34
  }
35
35
  }
36
- class Document extends Node{
37
36
  constructor(html,url){
38
37
  super('ROOT',{},null);
39
38
  this.isSingle=false
40
39
  this.URL=url
41
40
  if(html instanceof Document){
42
41
  this.childNodes=[...buildFromCache(cacheDoc(html)).childNodes]
43
42
  }
44
43
  else if(typeof html==='string') this.innerHTML=html
45
44
  else this.body
46
45
  }
47
46
  get documentElement(){return this.html}
48
47
  get html(){
49
48
  const html=this.$('html')
50
49
  if(html===null) this.innerHTML=/*html*/`<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title></title></head><body></body></html>`
51
50
  return this.$('html')
52
51
  }
53
52
  get head(){
54
53
  const head=this.$('head')
55
54
  if(head===null) this.html.insert(1,'<head></head>')
56
55
  return this.$('head')
57
56
  }
58
57
  get body(){
59
58
  const body=this.$('body')
60
59
  if(body===null) this.head.insert(3,'<body></body>')
61
60
  return this.$('body')
62
61
  }
63
62
  get title(){
64
63
  const title=this.$('title')
65
64
  if(title===null) this.head.insert(1,'<title></title>')
66
65
  return this.$('title').innerText
67
66
  }
68
67
  get charset(){return this.$('meta[charset]')}
69
68
  set title(title){return this.$('title').innerText=title}
70
69
  get clone(){return new Document(this)}
70
+ class Document extends Node{
71
71
  constructor(html,url){
72
72
  super('ROOT',{},null);
73
73
  this.isSingle=false
74
74
  this.URL=url
75
75
  if(html instanceof Document){
76
76
  this.childNodes=[...buildFromCache(cacheDoc(html)).childNodes]
77
77
  }
78
78
  else if(typeof html==='string') this.innerHTML=html
79
79
  else this.body
80
80
  }
81
81
  get documentElement(){return this.html}
82
82
  get html(){
83
83
  const html=this.$('html')
84
84
  if(html===null) this.innerHTML=/*html*/`<html lang="en"><head><meta charset="UTF-8"><title></title></head><body></body></html>`
85
85
  return this.$('html')
86
86
  }
87
87
  get innerHTML(){
88
88
  const inner=super.innerHTML
89
89
  return '<!DOCTYPE html>'+inner
90
90
  }
91
91
  set innerHTML(html){return super.innerHTML=html}
92
92
  get head(){
93
93
  const head=this.$('head')
94
94
  if(head===null) this.html.insert(1,'<head></head>')
95
95
  return this.$('head')
96
96
  }
97
97
  get body(){
98
98
  const body=this.$('body')
99
99
  if(body===null) this.head.insert(3,'<body></body>')
100
100
  return this.$('body')
101
101
  }
102
102
  get title(){
103
103
  const title=this.$('title')
104
104
  if(title===null) this.head.insert(1,'<title></title>')
105
105
  return this.$('title').innerText
106
106
  }
107
107
  get charset(){return this.$('meta[charset]')}
108
108
  set title(title){return this.$('title').innerText=title}
109
109
  get clone(){return new Document(this)}
110
110
  }
111
111
  function parseAttributes(str){
112
112
  const attrs={};
113
113
  let key="";
114
114
  let value="";
115
115
  let isKey=true;
116
116
  let quoteChar=null;
117
117
  for (let i=0; i< str.length; i++){
118
118
  const char=str[i];
119
119
  if (isKey && (char==='=' || char===' ')){
120
120
  if (char==='=') isKey=false;
121
121
  else if (key.trim()){
122
122
  attrs[key.trim()]=true;
123
123
  key="";
124
124
  }
125
125
  continue;
126
126
  }
127
127
  if (!quoteChar && (char==='"' || char==="'")){
128
128
  quoteChar=char;
129
129
  continue;
130
130
  } else if (quoteChar && char===quoteChar){
131
131
  quoteChar=null;
132
132
  attrs[key.trim()]=value.trim();
133
133
  key=""; value=""; isKey=true;
134
134
  continue;
135
135
  }
136
136
  if (isKey) key+=char;
137
137
  else value+=char;
138
138
  }
139
139
  if (key.trim() &&!value) attrs[key.trim()]='';
140
140
  return attrs;
141
141
  }
@@ -14,10 +14,16 @@ class Document extends Node {
14
14
  get documentElement() {return this.html}
15
15
  get html() {
16
16
  const html = this.$('html')
17
- if(html === null) this.innerHTML = /*html*/`<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title></title></head><body></body></html>`
17
+ if(html === null) this.innerHTML = /*html*/`<html lang="en"><head><meta charset="UTF-8"><title></title></head><body></body></html>`
18
18
  return this.$('html')
19
19
  }
20
20
 
21
+ get innerHTML() {
22
+ const inner = super.innerHTML
23
+ return '<!DOCTYPE html>' + inner
24
+ }
25
+ set innerHTML(html) {return super.innerHTML = html}
26
+
21
27
  get head() {
22
28
  const head = this.$('head')
23
29
  if(head === null) this.html.insert(1,'<head></head>')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "als-document",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "A powerful HTML parser & DOM manipulation library for both backend and frontend.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",