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