ziko 1.5.0 → 1.6.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/dist/ziko.cjs +49 -28
- package/dist/ziko.js +49 -28
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +49 -28
- package/package.json +1 -1
- package/src/data/parser/index.d.ts +41 -0
- package/src/data/parser/index.js +28 -1
- package/src/data/string/checkers/index.d.ts +62 -0
- package/src/data/string/converters/index.d.ts +159 -0
- package/src/data/string/index.d.ts +2 -0
- package/src/data/string/index.js +2 -2
- package/src/dom/components/index.d.ts +2 -0
- package/src/dom/components/swap/index.js +9 -4
- package/src/dom/constructors/UIElement.js +14 -2
- package/src/dom/constructors/UIElementCore.js +2 -1
- package/src/dom/constructors/mixins/dom.js +31 -22
- package/src/data/parser/xml.js +0 -47
- /package/src/data/string/{checkers.js → checkers/index.js} +0 -0
- /package/src/data/string/{converters.js → converters/index.js} +0 -0
package/src/data/parser/index.js
CHANGED
|
@@ -1 +1,28 @@
|
|
|
1
|
-
export
|
|
1
|
+
export function parseXML(xmlString) {
|
|
2
|
+
const parser = new DOMParser();
|
|
3
|
+
const xmlDoc = parser.parseFromString(xmlString, 'text/xml');
|
|
4
|
+
const rootNode = xmlDoc.documentElement;
|
|
5
|
+
const result = parseNode(rootNode);
|
|
6
|
+
return result;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function parseNode(node) {
|
|
10
|
+
const obj = {
|
|
11
|
+
type: node.nodeName,
|
|
12
|
+
attributes: {},
|
|
13
|
+
children: []
|
|
14
|
+
};
|
|
15
|
+
for (let i = 0; i < node.attributes.length; i++) {
|
|
16
|
+
const attr = node.attributes[i];
|
|
17
|
+
obj.attributes[attr.name] = attr.value;
|
|
18
|
+
}
|
|
19
|
+
for (let i = 0; i < node.childNodes.length; i++) {
|
|
20
|
+
const child = node.childNodes[i];
|
|
21
|
+
if (child.nodeType === Node.ELEMENT_NODE) {
|
|
22
|
+
obj.children.push(parseNode(child));
|
|
23
|
+
} else if (child.nodeType === Node.TEXT_NODE) {
|
|
24
|
+
obj.text = child.textContent.trim();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return obj;
|
|
28
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a string follows camelCase notation.
|
|
3
|
+
*
|
|
4
|
+
* @param text - The string to check.
|
|
5
|
+
* @returns `true` if the string is camelCase, otherwise `false`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const is_camelcase: (text?: string) => boolean;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Checks if a string follows kebab-case (hyphen-case) notation.
|
|
11
|
+
*
|
|
12
|
+
* @param text - The string to check.
|
|
13
|
+
* @returns `true` if the string contains a hyphen separator, otherwise `false`.
|
|
14
|
+
*/
|
|
15
|
+
export declare const is_hyphencase: (text?: string) => boolean;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Checks if a string follows snake_case notation.
|
|
19
|
+
*
|
|
20
|
+
* @param text - The string to check.
|
|
21
|
+
* @returns `true` if the string contains an underscore separator, otherwise `false`.
|
|
22
|
+
*/
|
|
23
|
+
export declare const is_snakeCase: (text?: string) => boolean;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Checks if a string follows PascalCase notation.
|
|
27
|
+
*
|
|
28
|
+
* @param text - The string to check.
|
|
29
|
+
* @returns `true` if the string is PascalCase, otherwise `false`.
|
|
30
|
+
*/
|
|
31
|
+
export declare const is_pascalcase: (text?: string) => boolean;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Checks whether a string is a palindrome.
|
|
35
|
+
*
|
|
36
|
+
* A palindrome is a string that reads the same forward and backward.
|
|
37
|
+
*
|
|
38
|
+
* @param text - The string to check.
|
|
39
|
+
* @returns `true` if the string is a palindrome, otherwise `false`.
|
|
40
|
+
*/
|
|
41
|
+
export declare const is_palindrome: (text: string) => boolean;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Checks whether two words are anagrams.
|
|
45
|
+
*
|
|
46
|
+
* Two words are anagrams if they contain the same characters with the same frequency.
|
|
47
|
+
*
|
|
48
|
+
* @param word - The first word.
|
|
49
|
+
* @param words - The second word to compare with.
|
|
50
|
+
* @returns `true` if both words are anagrams, otherwise `false`.
|
|
51
|
+
*/
|
|
52
|
+
export declare const is_anagram: (word: string, words: string) => boolean;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Checks whether a string is an isogram.
|
|
56
|
+
*
|
|
57
|
+
* An isogram is a word with no repeating characters.
|
|
58
|
+
*
|
|
59
|
+
* @param text - The string to check.
|
|
60
|
+
* @returns `true` if the string has no repeated characters, otherwise `false`.
|
|
61
|
+
*/
|
|
62
|
+
export declare const is_isogram: (text?: string) => boolean;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a camelCase string to hyphen-case.
|
|
3
|
+
*
|
|
4
|
+
* @param text - The camelCase string.
|
|
5
|
+
* @returns The converted hyphen-case string.
|
|
6
|
+
*/
|
|
7
|
+
export declare const camel2hyphencase: (text?: string) => string;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Converts a camelCase string to snake_case.
|
|
11
|
+
*
|
|
12
|
+
* @param text - The camelCase string.
|
|
13
|
+
* @returns The converted snake_case string.
|
|
14
|
+
*/
|
|
15
|
+
export declare const camel2snakecase: (text?: string) => string;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Converts a camelCase string to PascalCase.
|
|
19
|
+
*
|
|
20
|
+
* @param text - The camelCase string.
|
|
21
|
+
* @returns The converted PascalCase string.
|
|
22
|
+
*/
|
|
23
|
+
export declare const camel2pascalcase: (text?: string) => string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Converts a camelCase string to CONSTANT_CASE.
|
|
27
|
+
*
|
|
28
|
+
* @param text - The camelCase string.
|
|
29
|
+
* @returns The converted CONSTANT_CASE string.
|
|
30
|
+
*/
|
|
31
|
+
export declare const camel2constantcase: (text?: string) => string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Converts a PascalCase string to snake_case.
|
|
35
|
+
*
|
|
36
|
+
* @param text - The PascalCase string.
|
|
37
|
+
* @returns The converted snake_case string.
|
|
38
|
+
*/
|
|
39
|
+
export declare const pascal2snakecase: (text?: string) => string;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Converts a PascalCase string to hyphen-case.
|
|
43
|
+
*
|
|
44
|
+
* @param text - The PascalCase string.
|
|
45
|
+
* @returns The converted hyphen-case string.
|
|
46
|
+
*/
|
|
47
|
+
export declare const pascal2hyphencase: (text?: string) => string;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Converts a PascalCase string to camelCase.
|
|
51
|
+
*
|
|
52
|
+
* @param text - The PascalCase string.
|
|
53
|
+
* @returns The converted camelCase string.
|
|
54
|
+
*/
|
|
55
|
+
export declare const pascal2camelcase: (text?: string) => string;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Converts a PascalCase string to CONSTANT_CASE.
|
|
59
|
+
*
|
|
60
|
+
* @param text - The PascalCase string.
|
|
61
|
+
* @returns The converted CONSTANT_CASE string.
|
|
62
|
+
*/
|
|
63
|
+
export declare const pascal2constantcase: (text?: string) => string;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Converts a snake_case string to camelCase.
|
|
67
|
+
*
|
|
68
|
+
* @param text - The snake_case string.
|
|
69
|
+
* @returns The converted camelCase string.
|
|
70
|
+
*/
|
|
71
|
+
export declare const snake2camelcase: (text?: string) => string;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Converts a snake_case string to hyphen-case.
|
|
75
|
+
*
|
|
76
|
+
* @param text - The snake_case string.
|
|
77
|
+
* @returns The converted hyphen-case string.
|
|
78
|
+
*/
|
|
79
|
+
export declare const snake2hyphencase: (text?: string) => string;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Converts a snake_case string to PascalCase.
|
|
83
|
+
*
|
|
84
|
+
* @param text - The snake_case string.
|
|
85
|
+
* @returns The converted PascalCase string.
|
|
86
|
+
*/
|
|
87
|
+
export declare const snake2pascalcase: (text?: string) => string;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Converts a snake_case string to CONSTANT_CASE.
|
|
91
|
+
*
|
|
92
|
+
* @param text - The snake_case string.
|
|
93
|
+
* @returns The converted CONSTANT_CASE string.
|
|
94
|
+
*/
|
|
95
|
+
export declare const snake2constantcase: (text?: string) => string;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Converts a hyphen-case string to camelCase.
|
|
99
|
+
*
|
|
100
|
+
* @param text - The hyphen-case string.
|
|
101
|
+
* @returns The converted camelCase string.
|
|
102
|
+
*/
|
|
103
|
+
export declare const hyphen2camelcase: (text?: string) => string;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Converts a hyphen-case string to snake_case.
|
|
107
|
+
*
|
|
108
|
+
* @param text - The hyphen-case string.
|
|
109
|
+
* @returns The converted snake_case string.
|
|
110
|
+
*/
|
|
111
|
+
export declare const hyphen2snakecase: (text?: string) => string;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Converts a hyphen-case string to PascalCase.
|
|
115
|
+
*
|
|
116
|
+
* @param text - The hyphen-case string.
|
|
117
|
+
* @returns The converted PascalCase string.
|
|
118
|
+
*/
|
|
119
|
+
export declare const hyphen2pascalcase: (text?: string) => string;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Converts a hyphen-case string to CONSTANT_CASE.
|
|
123
|
+
*
|
|
124
|
+
* @param text - The hyphen-case string.
|
|
125
|
+
* @returns The converted CONSTANT_CASE string.
|
|
126
|
+
*/
|
|
127
|
+
export declare const hyphen2constantcase: (text?: string) => string;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Converts a CONSTANT_CASE string to camelCase.
|
|
131
|
+
*
|
|
132
|
+
* @param text - The CONSTANT_CASE string.
|
|
133
|
+
* @returns The converted camelCase string.
|
|
134
|
+
*/
|
|
135
|
+
export declare const constant2camelcase: (text?: string) => string;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Converts a CONSTANT_CASE string to snake_case.
|
|
139
|
+
*
|
|
140
|
+
* @param text - The CONSTANT_CASE string.
|
|
141
|
+
* @returns The converted snake_case string.
|
|
142
|
+
*/
|
|
143
|
+
export declare const constant2snakecase: (text?: string) => string;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Converts a CONSTANT_CASE string to PascalCase.
|
|
147
|
+
*
|
|
148
|
+
* @param text - The CONSTANT_CASE string.
|
|
149
|
+
* @returns The converted PascalCase string.
|
|
150
|
+
*/
|
|
151
|
+
export declare const constant2pascalcase: (text?: string) => string;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Converts a CONSTANT_CASE string to hyphen-case.
|
|
155
|
+
*
|
|
156
|
+
* @param text - The CONSTANT_CASE string.
|
|
157
|
+
* @returns The converted hyphen-case string.
|
|
158
|
+
*/
|
|
159
|
+
export declare const constant2hyphencase: (text?: string) => string;
|
package/src/data/string/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './converters.js';
|
|
2
|
-
export * from './checkers.js'
|
|
1
|
+
export * from './converters/index.js';
|
|
2
|
+
export * from './checkers/index.js'
|
|
@@ -12,15 +12,17 @@ export class UISwap extends UIElement {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
this.append(...items);
|
|
15
|
-
|
|
15
|
+
requestAnimationFrame(() => {
|
|
16
|
+
this.render();
|
|
17
|
+
});
|
|
16
18
|
}
|
|
17
19
|
get activeItem(){
|
|
18
20
|
return this.items[this.states.activeIndex]
|
|
19
21
|
}
|
|
20
|
-
|
|
22
|
+
render() {
|
|
21
23
|
this.items.forEach((n, i) => {
|
|
22
|
-
|
|
23
|
-
const initialDisplay = n.element
|
|
24
|
+
|
|
25
|
+
const initialDisplay = getComputedStyle(n.element).display;
|
|
24
26
|
this.#DISPLAYS_MAP.set(n, initialDisplay);
|
|
25
27
|
|
|
26
28
|
if (i !== this.states.activeIndex) {
|
|
@@ -28,6 +30,9 @@ export class UISwap extends UIElement {
|
|
|
28
30
|
}
|
|
29
31
|
});
|
|
30
32
|
}
|
|
33
|
+
get DS(){
|
|
34
|
+
return this.#DISPLAYS_MAP
|
|
35
|
+
}
|
|
31
36
|
next(n = 1) {
|
|
32
37
|
return this.activate(this.states.activeIndex + n);
|
|
33
38
|
}
|
|
@@ -36,7 +36,7 @@ class UIElement extends UIElementCore{
|
|
|
36
36
|
ViewListeners,
|
|
37
37
|
);
|
|
38
38
|
|
|
39
|
-
if(element)this.init(element, name, type, render)
|
|
39
|
+
if(element)this.init(element, name, type, render);
|
|
40
40
|
}
|
|
41
41
|
on(event_name, callback, {details_setter, category = 'global', isCustom = false, preventDefault = false} = {}){
|
|
42
42
|
if(event_name instanceof Array) event_name.forEach(
|
|
@@ -58,11 +58,23 @@ class UIElement extends UIElementCore{
|
|
|
58
58
|
return this;
|
|
59
59
|
}
|
|
60
60
|
_off(event, category = 'global'){
|
|
61
|
-
this.exp.events[category].removeListener(event)
|
|
61
|
+
this.exp.events[category].removeListener(event);
|
|
62
|
+
return this
|
|
62
63
|
}
|
|
63
64
|
get element(){
|
|
64
65
|
return this.cache.element;
|
|
65
66
|
}
|
|
67
|
+
get itemsTarget(){
|
|
68
|
+
return this.cache.itemsTarget;
|
|
69
|
+
}
|
|
70
|
+
get itemsTargetElement(){
|
|
71
|
+
return this.itemsTarget.element;
|
|
72
|
+
}
|
|
73
|
+
setItemsTarget(parent){
|
|
74
|
+
this.cache.itemsTarget = parent;
|
|
75
|
+
this.items = parent.items;
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
66
78
|
isInteractive(){
|
|
67
79
|
return this.cache.isInteractive;
|
|
68
80
|
}
|
|
@@ -24,6 +24,7 @@ class UIElementCore extends UINode{
|
|
|
24
24
|
else this.target = element?.parentElement;
|
|
25
25
|
Object.assign(this.cache, {
|
|
26
26
|
name,
|
|
27
|
+
itemsTarget : this,
|
|
27
28
|
isInteractive : false,
|
|
28
29
|
parent:null,
|
|
29
30
|
isBody:false,
|
|
@@ -60,7 +61,7 @@ class UIElementCore extends UINode{
|
|
|
60
61
|
get element(){
|
|
61
62
|
return this.cache.element;
|
|
62
63
|
}
|
|
63
|
-
|
|
64
|
+
[Symbol.iterator](){
|
|
64
65
|
return this.items[Symbol.iterator]();
|
|
65
66
|
}
|
|
66
67
|
maintain() {
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
// import { isStateGetter } from "../../../hooks/use-state.js";
|
|
2
|
-
// import {
|
|
3
|
-
// is_camelcase,
|
|
4
|
-
// camel2hyphencase
|
|
5
|
-
// } from '../../../data/string/index.js';
|
|
6
1
|
import { text } from "../../text/index.js";
|
|
7
2
|
|
|
8
3
|
export function append(...ele) {
|
|
@@ -14,19 +9,30 @@ export function prepend(...ele) {
|
|
|
14
9
|
return this;
|
|
15
10
|
}
|
|
16
11
|
export function insertAt(index, ...ele) {
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
const target = this.itemsTarget;
|
|
13
|
+
|
|
14
|
+
if (index >= target.items.length) return this.append(...ele);
|
|
15
|
+
|
|
19
16
|
for (let i = 0; i < ele.length; i++) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
if (["number", "string"].includes(typeof ele[i]))
|
|
18
|
+
ele[i] = text(ele[i]);
|
|
19
|
+
|
|
20
|
+
target.element?.insertBefore(
|
|
21
|
+
ele[i].element,
|
|
22
|
+
target.items[index].element
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
target.items.splice(index, 0, ele[i]);
|
|
23
26
|
}
|
|
24
|
-
|
|
27
|
+
|
|
28
|
+
target.maintain();
|
|
29
|
+
|
|
30
|
+
return this;
|
|
25
31
|
}
|
|
26
32
|
export function remove(...ele) {
|
|
27
33
|
const remove = (ele) => {
|
|
28
34
|
if (typeof ele === "number") ele = this.items[ele];
|
|
29
|
-
if (ele?.isUIElement) this.element?.removeChild(ele.element);
|
|
35
|
+
if (ele?.isUIElement) this.itemsTarget.element?.removeChild(ele.element);
|
|
30
36
|
this.items = this.items.filter((n) => n !== ele);
|
|
31
37
|
};
|
|
32
38
|
for (let i = 0; i < ele.length; i++) remove(ele[i]);
|
|
@@ -37,7 +43,7 @@ export function remove(...ele) {
|
|
|
37
43
|
}
|
|
38
44
|
export function clear(){
|
|
39
45
|
this?.items?.forEach(n=>n.unmount());
|
|
40
|
-
this.element.innerHTML =
|
|
46
|
+
this.itemsTarget.element.innerHTML = '';
|
|
41
47
|
return this;
|
|
42
48
|
}
|
|
43
49
|
export function replaceElementWith(new_element){
|
|
@@ -49,12 +55,12 @@ export function replaceElementWith(new_element){
|
|
|
49
55
|
}
|
|
50
56
|
export function after(ui){
|
|
51
57
|
if(ui?.isUIElement) ui=ui.element;
|
|
52
|
-
this.element?.after(ui)
|
|
58
|
+
this.itemsTarget.element?.after(ui)
|
|
53
59
|
return this;
|
|
54
60
|
}
|
|
55
61
|
export function before(ui){
|
|
56
62
|
if(ui?.isUIElement) ui=ui.element;
|
|
57
|
-
this.element?.before(ui)
|
|
63
|
+
this.itemsTarget.element?.before(ui)
|
|
58
64
|
return this;
|
|
59
65
|
}
|
|
60
66
|
|
|
@@ -62,6 +68,9 @@ export function before(ui){
|
|
|
62
68
|
|
|
63
69
|
|
|
64
70
|
export async function __addItem__(adder, pusher, ...ele) {
|
|
71
|
+
const itemsTarget_el = this.itemsTarget.element;
|
|
72
|
+
const itemsTarget = this.itemsTarget
|
|
73
|
+
|
|
65
74
|
if (this.cache.isFrozzen) {
|
|
66
75
|
console.warn("You can't append new item to frozzen element");
|
|
67
76
|
return this;
|
|
@@ -77,22 +86,22 @@ export async function __addItem__(adder, pusher, ...ele) {
|
|
|
77
86
|
(newValue) => (ele[i].element.textContent = newValue),
|
|
78
87
|
ele[i]
|
|
79
88
|
);
|
|
80
|
-
// this.element.appendChild(textNode);
|
|
89
|
+
// this.itemsTarget.element.appendChild(textNode);
|
|
81
90
|
}
|
|
82
91
|
}
|
|
83
92
|
if (typeof globalThis?.Node === "function" && ele[i] instanceof globalThis?.Node) ele[i] = new this.constructor(ele[i]);
|
|
84
93
|
if (ele[i]?.isUINode) {
|
|
85
94
|
ele[i].cache.parent = this;
|
|
86
|
-
|
|
87
|
-
ele[i].target = this.element;
|
|
88
|
-
|
|
95
|
+
itemsTarget_el?.[adder](ele[i].element);
|
|
96
|
+
ele[i].target = this.itemsTarget.element;
|
|
97
|
+
itemsTarget.items[pusher](ele[i]);
|
|
89
98
|
}
|
|
90
99
|
else if(ele[i] instanceof Promise){
|
|
91
100
|
const UIEle = await ele[i]
|
|
92
101
|
UIEle.cache.parent = this;
|
|
93
|
-
|
|
94
|
-
UIEle.target = this.element;
|
|
95
|
-
|
|
102
|
+
itemsTarget_el?.[adder](UIEle.element);
|
|
103
|
+
UIEle.target = this.itemsTarget.element;
|
|
104
|
+
itemsTarget.items[pusher](UIEle)
|
|
96
105
|
}
|
|
97
106
|
else if (ele[i] instanceof Object) {
|
|
98
107
|
if (ele[i]?.style) this.style(ele[i]?.style);
|
package/src/data/parser/xml.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
function parseXML(xmlString) {
|
|
2
|
-
const parser = new DOMParser();
|
|
3
|
-
const xmlDoc = parser.parseFromString(xmlString, 'text/xml');
|
|
4
|
-
const rootNode = xmlDoc.documentElement;
|
|
5
|
-
const result = parseNode(rootNode);
|
|
6
|
-
return result;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function parseNode(node) {
|
|
10
|
-
const obj = {
|
|
11
|
-
type: node.nodeName,
|
|
12
|
-
attributes: {},
|
|
13
|
-
children: []
|
|
14
|
-
};
|
|
15
|
-
for (let i = 0; i < node.attributes.length; i++) {
|
|
16
|
-
const attr = node.attributes[i];
|
|
17
|
-
obj.attributes[attr.name] = attr.value;
|
|
18
|
-
}
|
|
19
|
-
for (let i = 0; i < node.childNodes.length; i++) {
|
|
20
|
-
const child = node.childNodes[i];
|
|
21
|
-
if (child.nodeType === Node.ELEMENT_NODE) {
|
|
22
|
-
obj.children.push(parseNode(child));
|
|
23
|
-
} else if (child.nodeType === Node.TEXT_NODE) {
|
|
24
|
-
obj.text = child.textContent.trim();
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return obj;
|
|
28
|
-
}
|
|
29
|
-
export default parseXML;
|
|
30
|
-
|
|
31
|
-
// function htmlParser(element) {
|
|
32
|
-
// const obj = {
|
|
33
|
-
// type: element.tagName,
|
|
34
|
-
// attributes: {},
|
|
35
|
-
// children: [],
|
|
36
|
-
// };
|
|
37
|
-
// for (let i = 0; i < element.attributes.length; i++) {
|
|
38
|
-
// const attr = element.attributes[i];
|
|
39
|
-
// obj.attributes[attr.name] = attr.value;
|
|
40
|
-
// }
|
|
41
|
-
// for (let i = 0; i < element.children.length; i++) {
|
|
42
|
-
// const child = element.children[i];
|
|
43
|
-
// obj.children.push(htmlParser(child));
|
|
44
|
-
// }
|
|
45
|
-
// return obj;
|
|
46
|
-
// }
|
|
47
|
-
|
|
File without changes
|
|
File without changes
|