neobiz 1.3.1 → 1.3.4
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/index.js +96 -1
- package/package.json +2 -2
- package/readme.md +21 -385
- package/example/basic_syntax.v.js +0 -23
- package/example/control_flow.v.js +0 -56
- package/example/exported.v.js +0 -3
- package/example/fromString.v.js +0 -27
- package/example/index.js +0 -3
- package/example/innerText&html.v.js +0 -15
- package/example/interact_withDOM.v.js +0 -16
- package/example/loop_and_Array.v.js +0 -53
- package/example/multi_tag.v.js +0 -13
- package/example/package.json +0 -17
- package/example/partials_usage.v.js +0 -11
- package/example/passing_value.v.js +0 -17
- package/example/temp.html +0 -1
- package/example/templating.v.js +0 -20
- package/str.h.js +0 -78
package/index.js
CHANGED
|
@@ -61,12 +61,107 @@ function outFile(source, data) {
|
|
|
61
61
|
console.log(`Output file: ${source}`);
|
|
62
62
|
})();
|
|
63
63
|
}
|
|
64
|
+
function fromStr(letter, prefix = 0) {
|
|
65
|
+
if (letter == "") return {};
|
|
64
66
|
|
|
67
|
+
letter = letter.replace(/[\r\n\t]/gm, "").replace(/>\s{2,}</gm, "><");
|
|
68
|
+
const result = {};
|
|
69
|
+
|
|
70
|
+
if (/<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)$/.exec(letter)?.[1]) {
|
|
71
|
+
result.tag = /<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)$/.exec(letter)[1];
|
|
72
|
+
|
|
73
|
+
result.tag = result.tag + Array(prefix).fill(" ").join("");
|
|
74
|
+
|
|
75
|
+
result.head = /<([a-zA-Z0-9]{1,}).*?>/.exec(letter)[0];
|
|
76
|
+
|
|
77
|
+
result.inner = letter
|
|
78
|
+
.replace(result.head, "")
|
|
79
|
+
.split("")
|
|
80
|
+
.reverse()
|
|
81
|
+
.join("")
|
|
82
|
+
.replace(
|
|
83
|
+
`</${result.tag.replace(Array(prefix).fill(" ").join(""), "")}>`
|
|
84
|
+
.split("")
|
|
85
|
+
.reverse()
|
|
86
|
+
.join(""),
|
|
87
|
+
""
|
|
88
|
+
)
|
|
89
|
+
.split("")
|
|
90
|
+
.reverse()
|
|
91
|
+
.join("");
|
|
92
|
+
} else {
|
|
93
|
+
result.tag = /<([a-zA-Z0-9]{1,}).*?\/>/.exec(letter)[1];
|
|
94
|
+
|
|
95
|
+
result.tag = result.tag + Array(prefix).fill(" ").join("");
|
|
96
|
+
|
|
97
|
+
result.head = /<([a-zA-Z0-9]{1,}).*?>/.exec(letter)[0];
|
|
98
|
+
result.inner = "";
|
|
99
|
+
}
|
|
100
|
+
result.props = result.head.match(/[a-zA-Z0-9]{1,}=(["']).*?\1/g);
|
|
101
|
+
|
|
102
|
+
let temp = { [result.tag]: {} };
|
|
103
|
+
if (result.props)
|
|
104
|
+
result.attr = result.props.forEach((e) => {
|
|
105
|
+
let y = e.replace(/.*=(['"])/, "");
|
|
106
|
+
y = y.substring(0, y.length - 1);
|
|
107
|
+
let w = e.substring(0, e.indexOf("="));
|
|
108
|
+
temp[result.tag][w] = y;
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
let s = [];
|
|
112
|
+
let ttexr = result.inner;
|
|
113
|
+
while (
|
|
114
|
+
/<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)/.exec(ttexr) ||
|
|
115
|
+
/<([a-zA-Z0-9]{1,}).*?\/>/.exec(ttexr)
|
|
116
|
+
) {
|
|
117
|
+
let ss;
|
|
118
|
+
if (/<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)/.exec(ttexr)) {
|
|
119
|
+
ss = /<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)/.exec(ttexr)[0];
|
|
120
|
+
const h = /<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)$/.exec(ss)[1];
|
|
121
|
+
const sss = ttexr.slice(ttexr.indexOf(ss));
|
|
122
|
+
const f = {
|
|
123
|
+
a: sss.replace("<" + h, "").indexOf(`</${h}>`),
|
|
124
|
+
b: sss.replace("<" + h, "").indexOf(`<${h}`),
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
ss = f.a > f.b && f.b > -1 ? sss : ss;
|
|
128
|
+
} else {
|
|
129
|
+
ss = /<([a-zA-Z0-9]{1,}).*?\/>/.exec(ttexr)[0];
|
|
130
|
+
}
|
|
131
|
+
ttexr = ttexr.replace(ss, "");
|
|
132
|
+
s.push(ss);
|
|
133
|
+
}
|
|
134
|
+
s.sort((a, b) => {
|
|
135
|
+
const r = { a: result.inner.indexOf(a), b: result.inner.indexOf(b) };
|
|
136
|
+
return r.a > r.b ? 1 : r.a < r.b ? -1 : 0;
|
|
137
|
+
});
|
|
138
|
+
result.status = s;
|
|
139
|
+
result.puretext = ttexr ? ttexr : ttexr + " ";
|
|
140
|
+
// result.temp = temp;
|
|
141
|
+
if (result.puretext != " ") temp[result.tag].text = result.puretext;
|
|
142
|
+
if (result.status) {
|
|
143
|
+
const ss = new Set();
|
|
144
|
+
const current = {};
|
|
145
|
+
s.forEach((e) => {
|
|
146
|
+
const hh = /<[a-zA-Z0-9]{1,}\s?/.exec(e)[0].substring(1);
|
|
147
|
+
if (ss.has(hh)) {
|
|
148
|
+
current[hh] = current[hh] + 1;
|
|
149
|
+
} else {
|
|
150
|
+
current[hh] = 0;
|
|
151
|
+
ss.add(hh);
|
|
152
|
+
}
|
|
153
|
+
temp = {
|
|
154
|
+
[result.tag]: { ...temp[result.tag], ...fromStr(e, current[hh]) },
|
|
155
|
+
};
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return temp;
|
|
159
|
+
}
|
|
65
160
|
module.exports = {
|
|
66
161
|
render,
|
|
67
162
|
range,
|
|
68
163
|
outFile,
|
|
69
|
-
fromStr
|
|
164
|
+
fromStr,
|
|
70
165
|
partial: async (src) => {
|
|
71
166
|
const { default: i } = await import(
|
|
72
167
|
path.join("file:\\\\", process.cwd(), src)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "neobiz",
|
|
3
|
-
"version": "1.3.
|
|
4
|
-
"description": "A simple view engine
|
|
3
|
+
"version": "1.3.4",
|
|
4
|
+
"description": "A simple view engine with JS features",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1"
|
package/readme.md
CHANGED
|
@@ -1,388 +1,24 @@
|
|
|
1
1
|
<!-- @format -->
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
| fromStr | str[string] | Object | generate object from HTML string |
|
|
23
|
-
|
|
24
|
-
#### Why use this?
|
|
25
|
-
|
|
26
|
-
- Integrating back-end to view
|
|
27
|
-
- **directly** manipulation data or Model with a view
|
|
28
|
-
- Generate static html file
|
|
29
|
-
- Full control of view. Such as filtering, encrypting the data before serve, or just like conditional and loop case
|
|
30
|
-
- Almost no need to learn anything. Just need to learn how to render
|
|
31
|
-
- Limitless potential, because it's just js. Almost all library should be compatible
|
|
32
|
-
|
|
33
|
-
## Basic syntax
|
|
34
|
-
|
|
35
|
-
It's just an Object!
|
|
36
|
-
|
|
37
|
-
```js
|
|
38
|
-
{
|
|
39
|
-
// text property is same as innerText
|
|
40
|
-
h1: {
|
|
41
|
-
text: "Hello World!",
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
// <h1>Hello World!</h1>
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
properties dom
|
|
48
|
-
|
|
49
|
-
```js
|
|
50
|
-
{
|
|
51
|
-
h1: {
|
|
52
|
-
class:"heading",
|
|
53
|
-
text: "Hello World!",
|
|
54
|
-
style:"color: #DC1E1E",
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
// <h1 class="heading" style="color: #DC1E1E">Hello World!</h1>
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
innerText & innerHTML:
|
|
61
|
-
|
|
62
|
-
```js
|
|
63
|
-
{
|
|
64
|
-
h1: { text: "<b>this is a text</b>" },
|
|
65
|
-
ul: { html: "<li>this will be render as html</li>" },
|
|
66
|
-
}
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
nested dom:
|
|
70
|
-
|
|
71
|
-
```js
|
|
72
|
-
{
|
|
73
|
-
body: {
|
|
74
|
-
h1: {
|
|
75
|
-
text: "Hello World!",
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
expression & operator
|
|
82
|
-
|
|
83
|
-
```js
|
|
84
|
-
{
|
|
85
|
-
span: [
|
|
86
|
-
{ text: 24 + 12 / 6 },
|
|
87
|
-
{ text: !false },
|
|
88
|
-
],
|
|
89
|
-
}
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
siblings dom:
|
|
93
|
-
|
|
94
|
-
There is a case like this:
|
|
95
|
-
|
|
96
|
-
```html
|
|
97
|
-
<li>orange</li>
|
|
98
|
-
<li>banana</li>
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
Object can not use 2 keys with the same name
|
|
102
|
-
|
|
103
|
-
```js
|
|
104
|
-
// Don't do this
|
|
105
|
-
{
|
|
106
|
-
li:{text:"orange"},
|
|
107
|
-
li:{text:"banana"},
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Do this
|
|
111
|
-
{
|
|
112
|
-
li:[
|
|
113
|
-
{text:"orange"},
|
|
114
|
-
{text:"banana"},
|
|
115
|
-
]
|
|
116
|
-
}
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
What if there is somethings in the middle of list?
|
|
120
|
-
|
|
121
|
-
```html
|
|
122
|
-
<li>orange</li>
|
|
123
|
-
<p>
|
|
124
|
-
<span>This is in the middle</span>
|
|
125
|
-
</p>
|
|
126
|
-
<li>banana</li>
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
Can't use array? just use this:
|
|
130
|
-
|
|
131
|
-
> use string as key could distinc an element with just a space
|
|
132
|
-
> no need to worry, it will render without space
|
|
133
|
-
|
|
134
|
-
```js
|
|
135
|
-
{
|
|
136
|
-
li:{text:"orange"},
|
|
137
|
-
p:{span:{text:"This is in the middle"}},
|
|
138
|
-
"li ":{text:"banana"},
|
|
139
|
-
}
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
### Components
|
|
143
|
-
|
|
144
|
-
```js
|
|
145
|
-
import header from "./header.v.js"; //function type
|
|
146
|
-
import footer from "./footer.v.js"; //object type
|
|
147
|
-
|
|
148
|
-
render({
|
|
149
|
-
div: header({ user: "dim24" }),
|
|
150
|
-
p: { text: "this is text" },
|
|
151
|
-
div: footer,
|
|
152
|
-
});
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
header.v.js
|
|
156
|
-
|
|
157
|
-
```js
|
|
158
|
-
export default ({ user }) => ({ h1: { text: `Hi, ${user}` } });
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
footer.v.js
|
|
162
|
-
|
|
163
|
-
```js
|
|
164
|
-
export default {
|
|
165
|
-
script: { src: "/assets/js/main.js" },
|
|
166
|
-
span: { text: "this is footer" },
|
|
167
|
-
};
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
### Interacting with DOM
|
|
171
|
-
|
|
172
|
-
use `script` to interact with browser with **html** property
|
|
173
|
-
|
|
174
|
-
wrap the script with a function, or use string
|
|
175
|
-
|
|
176
|
-
```js
|
|
177
|
-
{
|
|
178
|
-
button:{onclick:"sayHi(this)",id:"hi-button"},
|
|
179
|
-
script:{
|
|
180
|
-
html:()=>{
|
|
181
|
-
document.getElementById("hi-button").innerText="Click me!";
|
|
182
|
-
|
|
183
|
-
function sayHi(el){
|
|
184
|
-
el.innerText="Hi!";
|
|
3
|
+
<script src="https://cdn.jsdelivr.net/npm/showdown@2.1.0/dist/showdown.min.js"></script>
|
|
4
|
+
<script>
|
|
5
|
+
fetch(
|
|
6
|
+
"https://raw.githubusercontent.com/harakun24/assets-neobiz/main/readme.md"
|
|
7
|
+
)
|
|
8
|
+
.then((e) => e.text())
|
|
9
|
+
.then((e) => {
|
|
10
|
+
var converter = new showdown.Converter(),
|
|
11
|
+
text = e;
|
|
12
|
+
try {
|
|
13
|
+
document.getElementById("readme").innerHTML = converter.makeHtml(text);
|
|
14
|
+
} catch {
|
|
15
|
+
const t = document.createElement("a");
|
|
16
|
+
t.setAttribute(
|
|
17
|
+
"href",
|
|
18
|
+
"https://raw.githubusercontent.com/harakun24/assets-neobiz/main/readme.md"
|
|
19
|
+
);
|
|
20
|
+
t.innerText = "Go to readme";
|
|
21
|
+
document.querySelector("body").append(t);
|
|
185
22
|
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
## fromStr
|
|
193
|
-
|
|
194
|
-
If you already have an html file and want to modify it, or make it as a template, just use `fromStr` function
|
|
195
|
-
|
|
196
|
-
> this function is still has some issues, but for simple html fromStr is work fine!
|
|
197
|
-
|
|
198
|
-
- wrap all tag into single parent
|
|
199
|
-
- use external script and css
|
|
200
|
-
- repetitive nested could caused weird behavior (help me, please!)
|
|
201
|
-
|
|
202
|
-
I still try to improve this feature. **if you can provide some help** just tell me please... :)
|
|
203
|
-
|
|
204
|
-
```js
|
|
205
|
-
const { fromStr, render } = require("./index");
|
|
206
|
-
|
|
207
|
-
const { div } = fromStr(`
|
|
208
|
-
<div>
|
|
209
|
-
<h1>Hello dims!</h1>
|
|
210
|
-
</div>
|
|
211
|
-
`);
|
|
212
|
-
|
|
213
|
-
div.id = "main";
|
|
214
|
-
div.h1.class = "heading";
|
|
215
|
-
div.p = { text: "this is a whole text" };
|
|
216
|
-
|
|
217
|
-
console.log(render({ div }));
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
result
|
|
221
|
-
|
|
222
|
-
```html
|
|
223
|
-
<div id="main">
|
|
224
|
-
<h1 class="heading">Hello dims!</h1>
|
|
225
|
-
<p>this is a whole text</p>
|
|
226
|
-
</div>
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
## Pass Value
|
|
230
|
-
|
|
231
|
-
use function
|
|
232
|
-
|
|
233
|
-
```js
|
|
234
|
-
import { render } from "../index.js";
|
|
235
|
-
|
|
236
|
-
console.log(render(((user) => ({ h1: { text: `Hello, ${user}` } }))("Vins")));
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
or
|
|
240
|
-
|
|
241
|
-
```js
|
|
242
|
-
const greeting = (user) => ({ h1: `Hello, ${user}` });
|
|
243
|
-
|
|
244
|
-
console.log(render(greeting("Vins")));
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
## Control Flow
|
|
248
|
-
|
|
249
|
-
ternary:
|
|
250
|
-
|
|
251
|
-
```js
|
|
252
|
-
{
|
|
253
|
-
h1: status
|
|
254
|
-
? { text: "Hello World!" }
|
|
255
|
-
: {
|
|
256
|
-
a: { href: "#", text: "You are offline!" },
|
|
257
|
-
},
|
|
258
|
-
}
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
IIFE if-else
|
|
262
|
-
|
|
263
|
-
```js
|
|
264
|
-
{
|
|
265
|
-
h1: (() => {
|
|
266
|
-
let result;
|
|
267
|
-
if (status) result = { text: "Hello World!" };
|
|
268
|
-
else
|
|
269
|
-
result = {
|
|
270
|
-
a: { href: "#", text: "You are offline!" },
|
|
271
|
-
};
|
|
272
|
-
return result;
|
|
273
|
-
})(),
|
|
274
|
-
}
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
IIFE switch-case
|
|
278
|
-
|
|
279
|
-
```js
|
|
280
|
-
{
|
|
281
|
-
h1: (() => {
|
|
282
|
-
let result;
|
|
283
|
-
switch (status) {
|
|
284
|
-
case true:
|
|
285
|
-
result = { text: "Hello World!" };
|
|
286
|
-
break;
|
|
287
|
-
case false:
|
|
288
|
-
result = {
|
|
289
|
-
a: { href: "#", text: "You are offline!" },
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
return result;
|
|
293
|
-
})(),
|
|
294
|
-
}
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
## Loop & array manipulation
|
|
298
|
-
|
|
299
|
-
range & map:
|
|
300
|
-
|
|
301
|
-
```js
|
|
302
|
-
import { render, range } from "../index.js";
|
|
303
|
-
|
|
304
|
-
{
|
|
305
|
-
ul: {
|
|
306
|
-
li: range(8, 1).map((item) => ({ text: "data-" + item })),
|
|
307
|
-
},
|
|
308
|
-
}
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
map
|
|
312
|
-
|
|
313
|
-
```js
|
|
314
|
-
{
|
|
315
|
-
ul: {
|
|
316
|
-
li: ["grape", "banana", "apple"].map((text) => ({ text })),
|
|
317
|
-
},
|
|
318
|
-
}
|
|
319
|
-
```
|
|
320
|
-
|
|
321
|
-
for
|
|
322
|
-
|
|
323
|
-
```js
|
|
324
|
-
{
|
|
325
|
-
ul: {
|
|
326
|
-
li: (() => {
|
|
327
|
-
const result = [];
|
|
328
|
-
for (let i = 1; i < 9; i++) result.push({ text: "data-" + i });
|
|
329
|
-
return result;
|
|
330
|
-
})(),
|
|
331
|
-
},
|
|
332
|
-
}
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
while
|
|
336
|
-
|
|
337
|
-
```js
|
|
338
|
-
{
|
|
339
|
-
ul: {
|
|
340
|
-
li: (() => {
|
|
341
|
-
const result = [];
|
|
342
|
-
let i = 0;
|
|
343
|
-
while (++i < 9) result.push({ text: "data-" + i });
|
|
344
|
-
return result;
|
|
345
|
-
})(),
|
|
346
|
-
},
|
|
347
|
-
}
|
|
348
|
-
```
|
|
349
|
-
|
|
350
|
-
## partial & templating
|
|
351
|
-
|
|
352
|
-
### partial
|
|
353
|
-
|
|
354
|
-
make sure to default export as a function
|
|
355
|
-
|
|
356
|
-
```js
|
|
357
|
-
import { render, partial } from "../index.js";
|
|
358
|
-
|
|
359
|
-
{
|
|
360
|
-
head: (await partial("./exported.v.js"))("example page"),
|
|
361
|
-
h1: { text: "This is example" },
|
|
362
|
-
}
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
`/exported.v.js`
|
|
366
|
-
|
|
367
|
-
```js
|
|
368
|
-
export default (title) => ({ title: { text: title } });
|
|
369
|
-
```
|
|
370
|
-
|
|
371
|
-
### templating
|
|
372
|
-
|
|
373
|
-
this example use single file usage. for modular usage leave to you, or just read the example dir
|
|
374
|
-
|
|
375
|
-
```js
|
|
376
|
-
import { render } from "../index.js";
|
|
377
|
-
|
|
378
|
-
const template = (content) => ({
|
|
379
|
-
div: {
|
|
380
|
-
class: "main wrapper",
|
|
381
|
-
div: content,
|
|
382
|
-
},
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
template({
|
|
386
|
-
h1: { text: "Hello World!" },
|
|
387
|
-
});
|
|
388
|
-
```
|
|
23
|
+
});
|
|
24
|
+
</script>
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
|
|
3
|
-
//use object literal
|
|
4
|
-
|
|
5
|
-
import { render, outFile } from "../index.js";
|
|
6
|
-
|
|
7
|
-
console.log(
|
|
8
|
-
render({
|
|
9
|
-
h1: { text: "Hello World!" },
|
|
10
|
-
})
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
//output: <h1>Hello World!</h1>
|
|
14
|
-
|
|
15
|
-
// output static file
|
|
16
|
-
outFile("./basic.html", {
|
|
17
|
-
h1: { text: "Hello World!" },
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
// properties
|
|
21
|
-
render({
|
|
22
|
-
h1: { class: "heading", id: "main", text: "Hello World!" },
|
|
23
|
-
});
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
|
|
3
|
-
import { render } from "../index.js";
|
|
4
|
-
|
|
5
|
-
const status = false;
|
|
6
|
-
|
|
7
|
-
// ternary operator
|
|
8
|
-
|
|
9
|
-
console.log(
|
|
10
|
-
render({
|
|
11
|
-
h1: status
|
|
12
|
-
? { text: "Hello World!" }
|
|
13
|
-
: {
|
|
14
|
-
a: { href: "#", text: "You are offline!" },
|
|
15
|
-
},
|
|
16
|
-
})
|
|
17
|
-
//<h1><a href='#'>You are offline!</a></h1
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
// use IIFE
|
|
21
|
-
|
|
22
|
-
// IF
|
|
23
|
-
console.log(
|
|
24
|
-
render({
|
|
25
|
-
h1: (() => {
|
|
26
|
-
let result;
|
|
27
|
-
if (status) result = { text: "Hello World!" };
|
|
28
|
-
else
|
|
29
|
-
result = {
|
|
30
|
-
a: { href: "#", text: "You are offline!" },
|
|
31
|
-
};
|
|
32
|
-
return result;
|
|
33
|
-
})(),
|
|
34
|
-
})
|
|
35
|
-
//<h1><a href='#'>You are offline!</a></h1
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
// SWITCH
|
|
39
|
-
console.log(
|
|
40
|
-
render({
|
|
41
|
-
h1: (() => {
|
|
42
|
-
let result;
|
|
43
|
-
switch (status) {
|
|
44
|
-
case true:
|
|
45
|
-
result = { text: "Hello World!" };
|
|
46
|
-
break;
|
|
47
|
-
case false:
|
|
48
|
-
result = {
|
|
49
|
-
a: { href: "#", text: "You are offline!" },
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
return result;
|
|
53
|
-
})(),
|
|
54
|
-
})
|
|
55
|
-
//<h1><a href='#'>You are offline!</a></h1
|
|
56
|
-
);
|
package/example/exported.v.js
DELETED
package/example/fromString.v.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
|
|
3
|
-
import { outFile, fromStr } from "../index.js";
|
|
4
|
-
|
|
5
|
-
const temp = `
|
|
6
|
-
<div id="first">
|
|
7
|
-
<ul id="outer">
|
|
8
|
-
<li>1</li>
|
|
9
|
-
<li>2</li>
|
|
10
|
-
</ul>
|
|
11
|
-
<div id="inner-div">
|
|
12
|
-
<ul id="inner-ul">
|
|
13
|
-
<li>3</li>
|
|
14
|
-
<li>4</li>
|
|
15
|
-
</ul>
|
|
16
|
-
</div>
|
|
17
|
-
</div>
|
|
18
|
-
`;
|
|
19
|
-
|
|
20
|
-
const { div } = fromStr(temp);
|
|
21
|
-
|
|
22
|
-
div.ul.li.text = "data-1";
|
|
23
|
-
div.div.ul.class = "inner";
|
|
24
|
-
|
|
25
|
-
outFile("./temp.html", { div });
|
|
26
|
-
|
|
27
|
-
console.dir({ div }, { depth: null });
|
package/example/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
|
|
3
|
-
import { outFile, render } from "../index.js";
|
|
4
|
-
|
|
5
|
-
console.log(
|
|
6
|
-
render({
|
|
7
|
-
h1: { text: "Hello World!<b>this is text</b>" },
|
|
8
|
-
ul: { html: "<li>Text hello</li>" },
|
|
9
|
-
})
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
outFile("./select.html", {
|
|
13
|
-
h1: { text: "Hello World! <b>this is \"text\"&'blue'</b>" },
|
|
14
|
-
ul: { html: "<li>Text hello</li>" },
|
|
15
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
|
|
3
|
-
import { outFile } from "../index.js";
|
|
4
|
-
|
|
5
|
-
outFile("./temp.html", {
|
|
6
|
-
button: { onclick: "sayHi(this)", id: "example" },
|
|
7
|
-
script: {
|
|
8
|
-
html: function () {
|
|
9
|
-
document.getElementById("example").innerText = "click me!";
|
|
10
|
-
|
|
11
|
-
function sayHi(el) {
|
|
12
|
-
el.innerText = "hi!";
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
});
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
|
|
3
|
-
import { render, range } from "../index.js";
|
|
4
|
-
|
|
5
|
-
// use range @param= length, startFrom
|
|
6
|
-
|
|
7
|
-
console.log(
|
|
8
|
-
render({
|
|
9
|
-
ul: {
|
|
10
|
-
li: range(8, 1).map((item) => ({ text: "data-" + item })),
|
|
11
|
-
},
|
|
12
|
-
})
|
|
13
|
-
//<ul><li>data-1</li><li>data-2</li><li>data-3</li><li>data-4</li><li>data-5</li><li>data-6</li><li>data-7</li><li>data-8</li></ul>
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
// map
|
|
17
|
-
console.log(
|
|
18
|
-
render({
|
|
19
|
-
ul: {
|
|
20
|
-
li: ["grape", "banana", "apple"].map((text) => ({ text })),
|
|
21
|
-
},
|
|
22
|
-
})
|
|
23
|
-
//<ul><li>grape</li><li>banana</li><li>apple</li></ul>
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
// for
|
|
27
|
-
console.log(
|
|
28
|
-
render({
|
|
29
|
-
ul: {
|
|
30
|
-
li: (() => {
|
|
31
|
-
const result = [];
|
|
32
|
-
for (let i = 1; i < 9; i++) result.push({ text: "data-" + i });
|
|
33
|
-
return result;
|
|
34
|
-
})(),
|
|
35
|
-
},
|
|
36
|
-
})
|
|
37
|
-
//<ul><li>data-1</li><li>data-2</li><li>data-3</li><li>data-4</li><li>data-5</li><li>data-6</li><li>data-7</li><li>data-8</li></ul>
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
// while
|
|
41
|
-
console.log(
|
|
42
|
-
render({
|
|
43
|
-
ul: {
|
|
44
|
-
li: (() => {
|
|
45
|
-
const result = [];
|
|
46
|
-
let i = 0;
|
|
47
|
-
while (++i < 9) result.push({ text: "data-" + i });
|
|
48
|
-
return result;
|
|
49
|
-
})(),
|
|
50
|
-
},
|
|
51
|
-
})
|
|
52
|
-
//<ul><li>data-1</li><li>data-2</li><li>data-3</li><li>data-4</li><li>data-5</li><li>data-6</li><li>data-7</li><li>data-8</li></ul>
|
|
53
|
-
);
|
package/example/multi_tag.v.js
DELETED
package/example/package.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "example",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"type": "module",
|
|
5
|
-
"description": "example of neobiz.js cases",
|
|
6
|
-
"main": "index.js",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
-
},
|
|
10
|
-
"keywords": [
|
|
11
|
-
"neobiz.js",
|
|
12
|
-
"view",
|
|
13
|
-
"template"
|
|
14
|
-
],
|
|
15
|
-
"author": "",
|
|
16
|
-
"license": "ISC"
|
|
17
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
|
|
3
|
-
import { render, partial } from "../index.js";
|
|
4
|
-
|
|
5
|
-
console.log(
|
|
6
|
-
render({
|
|
7
|
-
head: (await partial("./exported.v.js"))("example page"),
|
|
8
|
-
h1: { text: "This is example" },
|
|
9
|
-
})
|
|
10
|
-
//<head><title>example page</title></head><h1>This is example</h1>
|
|
11
|
-
);
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
|
|
3
|
-
//use function, iife recommended :)
|
|
4
|
-
|
|
5
|
-
import { render } from "../index.js";
|
|
6
|
-
|
|
7
|
-
console.log(
|
|
8
|
-
// Ignore this
|
|
9
|
-
render(((user) => ({ h1: { text: `Hello, ${user}` } }))("Vins"))
|
|
10
|
-
//<h1>Hello, Vins</h1>
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
// or just use this below
|
|
14
|
-
|
|
15
|
-
const greeting = (user) => ({ h1: `Hello, ${user}` });
|
|
16
|
-
|
|
17
|
-
console.log(render(greeting("Vins")));
|
package/example/temp.html
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<div id='first'><ul id='outer'><li>data-1</li><li>2</li></ul><div id='inner-div'><ul id='inner-ul' class='inner'><li>3</li><li>4</li></ul></div></div>
|
package/example/templating.v.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
|
|
3
|
-
import { render } from "../index.js";
|
|
4
|
-
|
|
5
|
-
const template = (content) => ({
|
|
6
|
-
div: {
|
|
7
|
-
class: "main wrapper",
|
|
8
|
-
div: content,
|
|
9
|
-
},
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
console.log(
|
|
13
|
-
render(
|
|
14
|
-
template({
|
|
15
|
-
h1: { text: "Hello World!" },
|
|
16
|
-
})
|
|
17
|
-
)
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
//<div class='main wrapper'><div><h1>Hello World!</h1></div></div>
|
package/str.h.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
|
|
3
|
-
function fromStr(letter, prefix = 0) {
|
|
4
|
-
if (letter == "") return;
|
|
5
|
-
letter = letter.replace(/[\r\n\t]/gm, "").replace(/>\s{2,}</gm, "><");
|
|
6
|
-
const result = {};
|
|
7
|
-
|
|
8
|
-
result.tag = /<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)$/.exec(letter)[1];
|
|
9
|
-
|
|
10
|
-
result.tag = result.tag + Array(prefix).fill(" ").join("");
|
|
11
|
-
|
|
12
|
-
result.head = /<([a-zA-Z0-9]{1,}).*?>/.exec(letter)[0];
|
|
13
|
-
|
|
14
|
-
result.props = result.head.match(/[a-zA-Z0-9]{1,}=(["']).*?\1/g);
|
|
15
|
-
|
|
16
|
-
result.inner = letter
|
|
17
|
-
.replace(result.head, "")
|
|
18
|
-
.split("")
|
|
19
|
-
.reverse()
|
|
20
|
-
.join("")
|
|
21
|
-
.replace(
|
|
22
|
-
`</${result.tag.replace(Array(prefix).fill(" ").join(""), "")}>`
|
|
23
|
-
.split("")
|
|
24
|
-
.reverse()
|
|
25
|
-
.join(""),
|
|
26
|
-
""
|
|
27
|
-
)
|
|
28
|
-
.split("")
|
|
29
|
-
.reverse()
|
|
30
|
-
.join("");
|
|
31
|
-
let temp = { [result.tag]: {} };
|
|
32
|
-
if (result.props)
|
|
33
|
-
result.attr = result.props.forEach((e) => {
|
|
34
|
-
let y = e.replace(/.*=(['"])/, "");
|
|
35
|
-
y = y.substring(0, y.length - 1);
|
|
36
|
-
let w = e.substring(0, e.indexOf("="));
|
|
37
|
-
temp[result.tag][w] = y;
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
let s = [];
|
|
41
|
-
let ttexr = result.inner;
|
|
42
|
-
|
|
43
|
-
while (/<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)/.exec(ttexr)) {
|
|
44
|
-
let ss = /<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)/.exec(ttexr)[0];
|
|
45
|
-
const h = /<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)$/.exec(ss)[1];
|
|
46
|
-
const sss = ttexr.slice(ttexr.indexOf(ss));
|
|
47
|
-
const f = {
|
|
48
|
-
a: sss.replace("<" + h, "").indexOf(`</${h}>`),
|
|
49
|
-
b: sss.replace("<" + h, "").indexOf(`<${h}`),
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
ss = f.a > f.b ? sss : ss;
|
|
53
|
-
ttexr = ttexr.replace(ss, "");
|
|
54
|
-
s.push(ss);
|
|
55
|
-
}
|
|
56
|
-
result.status = s;
|
|
57
|
-
result.puretext = ttexr ? ttexr : ttexr + " ";
|
|
58
|
-
// result.temp = temp;
|
|
59
|
-
if (result.puretext != " ") temp[result.tag].text = result.puretext;
|
|
60
|
-
if (result.status) {
|
|
61
|
-
const ss = new Set();
|
|
62
|
-
const current = {};
|
|
63
|
-
s.forEach((e) => {
|
|
64
|
-
const hh = /<[a-zA-Z0-9]{1,}\s?/.exec(e)[0].substring(1);
|
|
65
|
-
if (ss.has(hh)) {
|
|
66
|
-
current[hh] = current[hh] + 1;
|
|
67
|
-
} else {
|
|
68
|
-
current[hh] = 0;
|
|
69
|
-
ss.add(hh);
|
|
70
|
-
}
|
|
71
|
-
temp = {
|
|
72
|
-
[result.tag]: { ...temp[result.tag], ...fromStr(e, current[hh]) },
|
|
73
|
-
};
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
return temp;
|
|
77
|
-
}
|
|
78
|
-
module.exports = fromStr;
|