als-document 1.3.0 → 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 +1 -1
- package/index.js +1 -1
- package/index.mjs +1 -1
- package/lib/node/document.js +13 -10
- package/package.json +1 -1
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) this.childNodes=[...buildFromCache(cacheDoc(html)).childNodes]
|
|
77
77
|
else if(typeof html==='string') this.innerHTML=html
|
|
78
78
|
else this.html
|
|
79
79
|
}
|
|
80
80
|
get documentElement(){return this.html}
|
|
81
81
|
get html(){
|
|
82
82
|
const html=this.$('html')
|
|
83
83
|
if(html===null) this.innerHTML=/*html*/`<html lang="en"><head><meta charset="UTF-8"><title></title></head><body></body></html>`
|
|
84
84
|
return this.$('html')
|
|
85
85
|
}
|
|
86
86
|
get innerHTML(){
|
|
87
87
|
const inner=super.innerHTML
|
|
88
88
|
return '<!DOCTYPE html>'+inner
|
|
89
89
|
}
|
|
90
90
|
set innerHTML(html){return super.innerHTML=html}
|
|
91
91
|
get head(){
|
|
92
92
|
const head=this.html.$('head')
|
|
93
93
|
if(head===null) this.html.insert(1,'<head></head>')
|
|
94
94
|
return this.$('head')
|
|
95
95
|
}
|
|
96
96
|
get body(){
|
|
97
97
|
const body=this.html.$('body')
|
|
98
98
|
if(body===null) this.head.insert(3,'<body></body>')
|
|
99
99
|
return this.$('body')
|
|
100
100
|
}
|
|
101
101
|
get title(){
|
|
102
102
|
const title=this.head.$('title')
|
|
103
103
|
if(title===null) this.head.insert(1,'<title></title>')
|
|
104
104
|
return this.$('title').innerText
|
|
105
105
|
}
|
|
106
106
|
get charset(){return this.$('meta[charset]')}
|
|
107
107
|
set title(title){return this.head.$('title').innerText=title}
|
|
108
108
|
get clone(){return new Document(this)}
|
|
109
109
|
}
|
|
110
110
|
function parseAttributes(str){
|
|
111
111
|
const attrs={};
|
|
112
112
|
let key="";
|
|
113
113
|
let value="";
|
|
114
114
|
let isKey=true;
|
|
115
115
|
let quoteChar=null;
|
|
116
116
|
for (let i=0; i< str.length; i++){
|
|
117
117
|
const char=str[i];
|
|
118
118
|
if (isKey && (char==='=' || char===' ')){
|
|
119
119
|
if (char==='=') isKey=false;
|
|
120
120
|
else if (key.trim()){
|
|
121
121
|
attrs[key.trim()]=true;
|
|
122
122
|
key="";
|
|
123
123
|
}
|
|
124
124
|
continue;
|
|
125
125
|
}
|
|
126
126
|
if (!quoteChar && (char==='"' || char==="'")){
|
|
127
127
|
quoteChar=char;
|
|
128
128
|
continue;
|
|
129
129
|
} else if (quoteChar && char===quoteChar){
|
|
130
130
|
quoteChar=null;
|
|
131
131
|
attrs[key.trim()]=value.trim();
|
|
132
132
|
key=""; value=""; isKey=true;
|
|
133
133
|
continue;
|
|
134
134
|
}
|
|
135
135
|
if (isKey) key+=char;
|
|
136
136
|
else value+=char;
|
|
137
137
|
}
|
|
138
138
|
if (key.trim() &&!value) attrs[key.trim()]='';
|
|
139
139
|
return attrs;
|
|
140
140
|
}
|
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) this.childNodes=[...buildFromCache(cacheDoc(html)).childNodes]
|
|
76
76
|
else if(typeof html==='string') this.innerHTML=html
|
|
77
77
|
else this.html
|
|
78
78
|
}
|
|
79
79
|
get documentElement(){return this.html}
|
|
80
80
|
get html(){
|
|
81
81
|
const html=this.$('html')
|
|
82
82
|
if(html===null) this.innerHTML=/*html*/`<html lang="en"><head><meta charset="UTF-8"><title></title></head><body></body></html>`
|
|
83
83
|
return this.$('html')
|
|
84
84
|
}
|
|
85
85
|
get innerHTML(){
|
|
86
86
|
const inner=super.innerHTML
|
|
87
87
|
return '<!DOCTYPE html>'+inner
|
|
88
88
|
}
|
|
89
89
|
set innerHTML(html){return super.innerHTML=html}
|
|
90
90
|
get head(){
|
|
91
91
|
const head=this.html.$('head')
|
|
92
92
|
if(head===null) this.html.insert(1,'<head></head>')
|
|
93
93
|
return this.$('head')
|
|
94
94
|
}
|
|
95
95
|
get body(){
|
|
96
96
|
const body=this.html.$('body')
|
|
97
97
|
if(body===null) this.head.insert(3,'<body></body>')
|
|
98
98
|
return this.$('body')
|
|
99
99
|
}
|
|
100
100
|
get title(){
|
|
101
101
|
const title=this.head.$('title')
|
|
102
102
|
if(title===null) this.head.insert(1,'<title></title>')
|
|
103
103
|
return this.$('title').innerText
|
|
104
104
|
}
|
|
105
105
|
get charset(){return this.$('meta[charset]')}
|
|
106
106
|
set title(title){return this.head.$('title').innerText=title}
|
|
107
107
|
get clone(){return new Document(this)}
|
|
108
108
|
}
|
|
109
109
|
function parseAttributes(str){
|
|
110
110
|
const attrs={};
|
|
111
111
|
let key="";
|
|
112
112
|
let value="";
|
|
113
113
|
let isKey=true;
|
|
114
114
|
let quoteChar=null;
|
|
115
115
|
for (let i=0; i< str.length; i++){
|
|
116
116
|
const char=str[i];
|
|
117
117
|
if (isKey && (char==='=' || char===' ')){
|
|
118
118
|
if (char==='=') isKey=false;
|
|
119
119
|
else if (key.trim()){
|
|
120
120
|
attrs[key.trim()]=true;
|
|
121
121
|
key="";
|
|
122
122
|
}
|
|
123
123
|
continue;
|
|
124
124
|
}
|
|
125
125
|
if (!quoteChar && (char==='"' || char==="'")){
|
|
126
126
|
quoteChar=char;
|
|
127
127
|
continue;
|
|
128
128
|
} else if (quoteChar && char===quoteChar){
|
|
129
129
|
quoteChar=null;
|
|
130
130
|
attrs[key.trim()]=value.trim();
|
|
131
131
|
key=""; value=""; isKey=true;
|
|
132
132
|
continue;
|
|
133
133
|
}
|
|
134
134
|
if (isKey) key+=char;
|
|
135
135
|
else value+=char;
|
|
136
136
|
}
|
|
137
137
|
if (key.trim() &&!value) attrs[key.trim()]='';
|
|
138
138
|
return attrs;
|
|
139
139
|
}
|
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) this.childNodes=[...buildFromCache(cacheDoc(html)).childNodes]
|
|
76
76
|
else if(typeof html==='string') this.innerHTML=html
|
|
77
77
|
else this.html
|
|
78
78
|
}
|
|
79
79
|
get documentElement(){return this.html}
|
|
80
80
|
get html(){
|
|
81
81
|
const html=this.$('html')
|
|
82
82
|
if(html===null) this.innerHTML=/*html*/`<html lang="en"><head><meta charset="UTF-8"><title></title></head><body></body></html>`
|
|
83
83
|
return this.$('html')
|
|
84
84
|
}
|
|
85
85
|
get innerHTML(){
|
|
86
86
|
const inner=super.innerHTML
|
|
87
87
|
return '<!DOCTYPE html>'+inner
|
|
88
88
|
}
|
|
89
89
|
set innerHTML(html){return super.innerHTML=html}
|
|
90
90
|
get head(){
|
|
91
91
|
const head=this.html.$('head')
|
|
92
92
|
if(head===null) this.html.insert(1,'<head></head>')
|
|
93
93
|
return this.$('head')
|
|
94
94
|
}
|
|
95
95
|
get body(){
|
|
96
96
|
const body=this.html.$('body')
|
|
97
97
|
if(body===null) this.head.insert(3,'<body></body>')
|
|
98
98
|
return this.$('body')
|
|
99
99
|
}
|
|
100
100
|
get title(){
|
|
101
101
|
const title=this.head.$('title')
|
|
102
102
|
if(title===null) this.head.insert(1,'<title></title>')
|
|
103
103
|
return this.$('title').innerText
|
|
104
104
|
}
|
|
105
105
|
get charset(){return this.$('meta[charset]')}
|
|
106
106
|
set title(title){return this.head.$('title').innerText=title}
|
|
107
107
|
get clone(){return new Document(this)}
|
|
108
108
|
}
|
|
109
109
|
function parseAttributes(str){
|
|
110
110
|
const attrs={};
|
|
111
111
|
let key="";
|
|
112
112
|
let value="";
|
|
113
113
|
let isKey=true;
|
|
114
114
|
let quoteChar=null;
|
|
115
115
|
for (let i=0; i< str.length; i++){
|
|
116
116
|
const char=str[i];
|
|
117
117
|
if (isKey && (char==='=' || char===' ')){
|
|
118
118
|
if (char==='=') isKey=false;
|
|
119
119
|
else if (key.trim()){
|
|
120
120
|
attrs[key.trim()]=true;
|
|
121
121
|
key="";
|
|
122
122
|
}
|
|
123
123
|
continue;
|
|
124
124
|
}
|
|
125
125
|
if (!quoteChar && (char==='"' || char==="'")){
|
|
126
126
|
quoteChar=char;
|
|
127
127
|
continue;
|
|
128
128
|
} else if (quoteChar && char===quoteChar){
|
|
129
129
|
quoteChar=null;
|
|
130
130
|
attrs[key.trim()]=value.trim();
|
|
131
131
|
key=""; value=""; isKey=true;
|
|
132
132
|
continue;
|
|
133
133
|
}
|
|
134
134
|
if (isKey) key+=char;
|
|
135
135
|
else value+=char;
|
|
136
136
|
}
|
|
137
137
|
if (key.trim() &&!value) attrs[key.trim()]='';
|
|
138
138
|
return attrs;
|
|
139
139
|
}
|
package/lib/node/document.js
CHANGED
|
@@ -3,42 +3,45 @@ 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.
|
|
8
|
+
else this.html // create innerHTML
|
|
12
9
|
}
|
|
13
10
|
|
|
14
11
|
get documentElement() {return this.html}
|
|
15
12
|
get html() {
|
|
16
13
|
const html = this.$('html')
|
|
17
|
-
if(html === null) this.innerHTML = /*html
|
|
14
|
+
if(html === null) this.innerHTML = /*html*/`<html lang="en"><head><meta charset="UTF-8"><title></title></head><body></body></html>`
|
|
18
15
|
return this.$('html')
|
|
19
16
|
}
|
|
20
17
|
|
|
18
|
+
get innerHTML() {
|
|
19
|
+
const inner = super.innerHTML
|
|
20
|
+
return '<!DOCTYPE html>' + inner
|
|
21
|
+
}
|
|
22
|
+
set innerHTML(html) {return super.innerHTML = html}
|
|
23
|
+
|
|
21
24
|
get head() {
|
|
22
|
-
const head = this.$('head')
|
|
25
|
+
const head = this.html.$('head')
|
|
23
26
|
if(head === null) this.html.insert(1,'<head></head>')
|
|
24
27
|
return this.$('head')
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
get body() {
|
|
28
|
-
const body = this.$('body')
|
|
31
|
+
const body = this.html.$('body')
|
|
29
32
|
if(body === null) this.head.insert(3,'<body></body>')
|
|
30
33
|
return this.$('body')
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
get title() {
|
|
34
|
-
const title = this.$('title')
|
|
37
|
+
const title = this.head.$('title')
|
|
35
38
|
if(title === null) this.head.insert(1,'<title></title>')
|
|
36
39
|
return this.$('title').innerText
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
get charset() {return this.$('meta[charset]')}
|
|
40
43
|
|
|
41
|
-
set title(title) {return this.$('title').innerText = title}
|
|
44
|
+
set title(title) {return this.head.$('title').innerText = title}
|
|
42
45
|
|
|
43
46
|
get clone() {return new Document(this)}
|
|
44
47
|
}
|