als-document 1.0.0-beta → 1.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "als-document",
3
- "version": "1.0.0-beta",
3
+ "version": "1.0.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",
package/src/node/node.js CHANGED
@@ -117,10 +117,13 @@ class Node {
117
117
  insertAdjacentElement(position, newElement) {
118
118
  if(newElement.tagName === 'ROOT' && newElement.childNodes.length > 0) newElement = newElement.childNodes[0]
119
119
  const pos = position.toLowerCase();
120
- if (pos === "afterbegin") this.childNodes.unshift(newElement);
121
- else if (pos === "beforeend") this.childNodes.push(newElement);
122
- newElement.parent = this
123
- if (!this.parent) return newElement
120
+ if(pos === 'afterbegin' || pos === 'beforeend') {
121
+ if (pos === "afterbegin") this.childNodes.unshift(newElement);
122
+ else if (pos === "beforeend") this.childNodes.push(newElement);
123
+ newElement.parent = this
124
+ return newElement
125
+ }
126
+ if (!this.parent) throw new Error("Can't insert element to element without parent")
124
127
  if (pos === "beforebegin") insertBefore(this.parent.childNodes, this.childNodeIndex, newElement)
125
128
  else if (pos === "afterend") this.parent.childNodes.splice(this.childNodeIndex + 1, 0, newElement);
126
129
  newElement.parent = this.parent
@@ -31,7 +31,7 @@ class Query {
31
31
 
32
32
  splitAndCutLast(string, splitBy) {
33
33
  const array = string.split(splitBy);
34
- const last = array.pop(); // pop() удаляет и возвращает последний элемент массива
34
+ const last = array.pop();
35
35
  return [last, array];
36
36
  }
37
37
 
@@ -104,11 +104,17 @@ class Query {
104
104
  attribs = attribs.map(attrib => {
105
105
  let query = attrib
106
106
  attrib = attrib.replace('[', '').replace(']', '')
107
- let [name, value] = attrib.split(/[\~\|\^\$\*]?\=/)
108
- let sign = attrib.replace(name, '').replace(value, '')
109
- attrib = { query }
110
- if (name) attrib.name = name
111
- if (value) attrib.value = value.trim().replace(/^\"/, '').replace(/\"$/, '')
107
+ let [name,...values] = attrib.split('=')
108
+ const value = values.join('=').trim().replace(/^\"/,'').replace(/\"$/,'')
109
+ let sign
110
+ if(value) {
111
+ sign = '='
112
+ name = name.replace(/[\~\|\^\$\*]$/,(match => {
113
+ sign = match+sign
114
+ return ''
115
+ }))
116
+ }
117
+ attrib = {query,name,value}
112
118
  if (sign) {
113
119
  attrib.sign = sign
114
120
  attrib.check = this.getAttribFn(sign).bind(attrib)
package/tests/index.html CHANGED
@@ -10,7 +10,7 @@
10
10
  <!-- <script src="./data/html2.js"></script> -->
11
11
  <script src="./data/svg.js"></script>
12
12
  <script>
13
- const { parseHTML, Node, Query, TextNode, SingleNode, buildFromCache, cacheDoc } = alsDocument
13
+ const { parseHTML, Node, Query, TextNode, SingleNode, buildFromCache, cacheDoc,Root } = alsDocument
14
14
  let {describe,it,beforeEach,runTests,expect,delay,assert,beforeAll} = SimpleTest
15
15
  SimpleTest.showFullError = true
16
16
  </script>