neobiz 1.4.0 → 3.3.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/browser.js CHANGED
@@ -1,9 +1,110 @@
1
1
  /** @format */
2
2
 
3
+ "use strict";
4
+ function render(val = {}) {
5
+ let result = "";
6
+ try {
7
+ Object.entries(val).forEach((e) => {
8
+ if (Array.isArray(e[1])) {
9
+ e[1].forEach((g) => {
10
+ result += render({ [e[0]]: g });
11
+ });
12
+ } else if (typeof e[1] == "object") {
13
+ e[0] = e[0].replace(/\s/g, "");
14
+ result += `<${e[0]}`;
15
+ const temp = [];
16
+ let inn = "";
17
+ Object.entries(e[1]).forEach((k) => {
18
+ if (typeof k[1] == "string" && k[0] != "text" && k[0] != "html") {
19
+ result += ` ${k[0]}='${k[1].toString()}'`;
20
+ }
21
+ if (typeof k[1] == "function" && k[0] != "text" && k[0] != "html") {
22
+ result += ` ${k[0]}='${(k[1] + "")
23
+ .replace(/.*{/, "")
24
+ .split("")
25
+ .reverse()
26
+ .join("")
27
+ .replace(/}/, "")
28
+ .split("")
29
+ .reverse()
30
+ .join("")}'`;
31
+ } else if (k[0] == "text")
32
+ inn = `${
33
+ typeof k[1] == "string"
34
+ ? k[1]
35
+ .replace(/&/g, "&amp;")
36
+ .replace(/</g, "&lt;")
37
+ .replace(/>/g, "&gt;")
38
+ .replace(/"/g, "&quot;")
39
+ .replace(/'/g, "&#39;")
40
+ : k[1].toString()
41
+ }`;
42
+ else if (k[0] == "html") {
43
+ inn = `${
44
+ typeof k[1] != "function"
45
+ ? k[1]
46
+ : (k[1] + "")
47
+ .replace(/.*{/, "")
48
+ .split("")
49
+ .reverse()
50
+ .join("")
51
+ .replace(/}/, "")
52
+ .split("")
53
+ .reverse()
54
+ .join("")
55
+ }`;
56
+ // typeof k[1] == "string" ? inn : inn.substring(0, inn.length - 1);
57
+ } else temp.push(k);
58
+ });
59
+
60
+ const stat = ![
61
+ "input",
62
+ "link",
63
+ "br",
64
+ "hr",
65
+ "area",
66
+ "base",
67
+ "br",
68
+ "col",
69
+ "embed",
70
+ "img",
71
+ "meta",
72
+ "param",
73
+ "source",
74
+ "track",
75
+ "wbr",
76
+ ].includes(e[0]);
77
+ if (stat) {
78
+ result += ">";
79
+ result += inn;
80
+ for (let i of temp) {
81
+ result += render({ [i[0]]: i[1] });
82
+ }
83
+ result += `</${e[0]}>`;
84
+ } else {
85
+ if (!stat) result += "/>";
86
+ }
87
+ }
88
+ });
89
+ result = result.replace(/[\r\n\t]/gm, "");
90
+ result = result.replace(/\s{2,}/gm, " ");
91
+ } catch (e) {
92
+ result = `<p>Error: ${e.message}</p>`;
93
+ }
94
+ return result;
95
+ }
96
+ function rdr(val = {}) {
97
+ let result = "<!DOCTYPE html>";
98
+ if (Array.isArray(val)) {
99
+ val.forEach((value) => {
100
+ result += render(value);
101
+ });
102
+ } else result = render(val);
103
+ return result;
104
+ }
3
105
  function range(length, start = 0) {
4
106
  return [...Array(length)].map(() => start++);
5
107
  }
6
-
7
108
  function fromStr(letter, prefix = 0) {
8
109
  if (letter == "") return {};
9
110
 
@@ -100,80 +201,54 @@ function fromStr(letter, prefix = 0) {
100
201
  }
101
202
  return temp;
102
203
  }
103
- function render(val = {}) {
104
- let result = "";
105
- Object.entries(val).forEach((e) => {
106
- if (e[1].length) {
107
- e[1].forEach((g) => {
108
- result += render({ [e[0]]: g });
109
- });
110
- } else if (typeof e[1] == "object") {
111
- e[0] = e[0].replace(/\s/g, "");
112
- result += `<${e[0]}`;
113
- const temp = [];
114
- let inn = "";
115
- Object.entries(e[1]).forEach((k) => {
116
- if (typeof k[1] == "string" && k[0] != "text" && k[0] != "html") {
117
- result += ` ${k[0]}='${k[1].toString()}'`;
118
- } else if (k[0] == "text")
119
- inn = `${
120
- typeof k[1] == "string"
121
- ? k[1]
122
- .replace(/&/g, "&amp;")
123
- .replace(/</g, "&lt;")
124
- .replace(/>/g, "&gt;")
125
- .replace(/"/g, "&quot;")
126
- .replace(/'/g, "&#39;")
127
- : k[1].toString()
128
- }`;
129
- else if (k[0] == "html") {
130
- inn = `${
131
- typeof k[1] != "function"
132
- ? k[1]
133
- : (k[1] + "")
134
- .replace(/.*{/, "")
135
- .split("")
136
- .reverse()
137
- .join("")
138
- .replace(/}/, "")
139
- .split("")
140
- .reverse()
141
- .join("")
142
- }`;
143
- // typeof k[1] == "string" ? inn : inn.substring(0, inn.length - 1);
144
- } else temp.push(k);
204
+
205
+ Object.defineProperty({}.__proto__, "render", {
206
+ get: function () {
207
+ return "<!DOCTYPE html>" + rdr(this);
208
+ },
209
+ });
210
+ Object.defineProperty({}.__proto__, "css", {
211
+ get: function () {
212
+ let y = "";
213
+ Object.entries(this).forEach((item) => {
214
+ y += `${item[0]}{`;
215
+ Object.entries(item[1]).forEach((itm) => {
216
+ y += `${itm[0].replace(/[A-Z]/g, (m) => "-" + m.toLowerCase())}${
217
+ typeof itm[1] == "object" ? "" : ":"
218
+ }${typeof itm[1] == "object" ? "{" + itm[1].cssText + "}" : itm[1]}${
219
+ typeof itm[1] == "object" ? "" : ";"
220
+ }`;
145
221
  });
222
+ y += "}";
223
+ });
224
+ return { text: y };
225
+ },
226
+ });
227
+ Object.defineProperty({}.__proto__, "cssText", {
228
+ get: function () {
229
+ let y = "";
230
+ Object.entries(this).forEach((itm) => {
231
+ y += `${itm[0].replace(/[A-Z]/g, (m) => "-" + m.toLowerCase())}:${
232
+ itm[1]
233
+ };`;
234
+ });
235
+ return y;
236
+ },
237
+ });
238
+ Object.defineProperty({}.__proto__, "neobiz", {
239
+ get: function () {
240
+ return { render, fromStr, range };
241
+ },
242
+ });
146
243
 
147
- const stat = ![
148
- "input",
149
- "link",
150
- "br",
151
- "hr",
152
- "area",
153
- "base",
154
- "br",
155
- "col",
156
- "embed",
157
- "img",
158
- "meta",
159
- "param",
160
- "source",
161
- "track",
162
- "wbr",
163
- ].includes(e[0]);
164
- if (stat) {
165
- result += ">";
166
- result += inn;
167
- for (let i of temp) {
168
- result += render({ [i[0]]: i[1] });
169
- }
170
- result += `</${e[0]}>`;
171
- } else {
172
- if (!stat) result += "/>";
173
- }
174
- }
175
- });
176
- result = result.replace(/[\r\n\t]/gm, "");
177
- result = result.replace(/\s{2,}/gm, " ");
178
- return result;
179
- }
244
+ Object.defineProperty("".__proto__, "repulse", {
245
+ get: function () {
246
+ return fromStr(this);
247
+ },
248
+ });
249
+
250
+ Object.defineProperty([].__proto__, "range", {
251
+ value: function (range2, start = 0) {
252
+ return range(range2, start);
253
+ },
254
+ });
@@ -0,0 +1,25 @@
1
+ /** @format */
2
+
3
+ //use object literal
4
+
5
+ import "../index.js";
6
+
7
+ console.log(
8
+ {
9
+ h1: { text: "Hello World!" },
10
+ }.render
11
+ );
12
+
13
+ //output: <h1>Hello World!</h1>
14
+
15
+ // output static file
16
+ console.log(
17
+ {
18
+ h1: { text: "Hello World!" },
19
+ }.outFile("./basic_syntax.html:")
20
+ );
21
+
22
+ // properties
23
+ const page = {
24
+ h1: { class: "heading", id: "main", text: "Hello World!" },
25
+ }.render;
@@ -0,0 +1,56 @@
1
+ /** @format */
2
+
3
+ import "../index.js";
4
+
5
+ const status = false;
6
+
7
+ // ternary operator
8
+
9
+ console.log(
10
+ {
11
+ h1: status
12
+ ? { text: "Hello World!" }
13
+ : {
14
+ a: { href: "#", text: "You are offline!" },
15
+ },
16
+ }.render
17
+ //<h1><a href='#'>You are offline!</a></h1
18
+ );
19
+
20
+ // use IIFE
21
+
22
+ // IF
23
+ console.log(
24
+ {
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
+ }.render
35
+ //<h1><a href='#'>You are offline!</a></h1
36
+ );
37
+
38
+ // SWITCH
39
+ console.log(
40
+ {
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
+ }.render
55
+ //<h1><a href='#'>You are offline!</a></h1
56
+ );
@@ -0,0 +1,3 @@
1
+ /** @format */
2
+
3
+ export default (title) => ({ title: { text: title } });
@@ -0,0 +1,27 @@
1
+ /** @format */
2
+
3
+ import "../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 } = temp.repulse;
21
+
22
+ div.ul.li.text = "data-1";
23
+ div.div.ul.class = "inner";
24
+
25
+ ({ div }.outFile("./temp.html"));
26
+
27
+ console.dir({ div }, { depth: null });
@@ -0,0 +1,3 @@
1
+ /** @format */
2
+
3
+ import "./basic_syntax.v.js";
@@ -0,0 +1,15 @@
1
+ /** @format */
2
+
3
+ import "../index.js";
4
+
5
+ console.log(
6
+ {
7
+ h1: { text: "Hello World!<b>this is text</b>" },
8
+ ul: { html: "<li>Text hello</li>" },
9
+ }.render
10
+ );
11
+
12
+ ({
13
+ h1: { text: "Hello World! <b>this is \"text\"&'blue'</b>" },
14
+ ul: { html: "<li>Text hello</li>" },
15
+ }.outFile("./select.html"));
@@ -0,0 +1,18 @@
1
+ /** @format */
2
+
3
+ import "../index.js";
4
+
5
+ ({
6
+ button: {
7
+ text: "click me",
8
+ onclick() {
9
+ this.innerText = "hi!";
10
+ },
11
+ id: "example",
12
+ },
13
+ script: {
14
+ html() {
15
+ document.getElementById("example").innerText = "click me!";
16
+ },
17
+ },
18
+ }.outFile("./temp.html"));
@@ -0,0 +1,53 @@
1
+ /** @format */
2
+
3
+ import "../index.js";
4
+
5
+ // use range @param= length, startFrom
6
+
7
+ console.log(
8
+ {
9
+ ul: {
10
+ li: [].range(8, 1).map((item) => ({ text: "data-" + item })),
11
+ },
12
+ }.render
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
+ {
19
+ ul: {
20
+ li: ["grape", "banana", "apple"].map((text) => ({ text })),
21
+ },
22
+ }.render
23
+ //<ul><li>grape</li><li>banana</li><li>apple</li></ul>
24
+ );
25
+
26
+ // for
27
+ console.log(
28
+ {
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
+ }.render
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
+ {
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
+ }.render
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
+ );
@@ -0,0 +1,13 @@
1
+ /** @format */
2
+
3
+ import "../index.js";
4
+
5
+ console.log(
6
+ {
7
+ ul: {
8
+ li: [{ text: "one" }, { text: "two" }, { text: "3" }],
9
+ },
10
+ }.render
11
+ );
12
+
13
+ // <ul><li>one</li><li>two</li><li>3</li></ul>
@@ -0,0 +1,17 @@
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
+ }
@@ -0,0 +1,11 @@
1
+ /** @format */
2
+
3
+ import "../index.js";
4
+ import head from "./exported.v.js";
5
+ console.log(
6
+ render({
7
+ head: head("example page"),
8
+ h1: { text: "This is example" },
9
+ })
10
+ //<head><title>example page</title></head><h1>This is example</h1>
11
+ );
@@ -0,0 +1,17 @@
1
+ /** @format */
2
+
3
+ //use function, iife recommended :)
4
+
5
+ import "../index.js";
6
+
7
+ console.log(
8
+ // Ignore this
9
+ ((user) => ({ h1: { text: `Hello, ${user}` } }))("Vins").render
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(greeting("Vins").render);
@@ -0,0 +1,18 @@
1
+ /** @format */
2
+
3
+ import "../index.js";
4
+
5
+ const template = (content) => ({
6
+ div: {
7
+ class: "main wrapper",
8
+ div: content,
9
+ },
10
+ });
11
+
12
+ console.log(
13
+ template({
14
+ h1: { text: "Hello World!" },
15
+ }).render
16
+ );
17
+
18
+ //<div class='main wrapper'><div><h1>Hello World!</h1></div></div>
package/index.js CHANGED
@@ -1,201 +1,20 @@
1
1
  /** @format */
2
- "use strict";
2
+ require("./browser");
3
3
  const path = require("path");
4
- function render(val = {}) {
5
- let result = "";
6
- Object.entries(val).forEach((e) => {
7
- if (e[1].length) {
8
- e[1].forEach((g) => {
9
- result += render({ [e[0]]: g });
10
- });
11
- } else if (typeof e[1] == "object") {
12
- e[0] = e[0].replace(/\s/g, "");
13
- result += `<${e[0]}`;
14
- const temp = [];
15
- let inn = "";
16
- Object.entries(e[1]).forEach((k) => {
17
- if (typeof k[1] == "string" && k[0] != "text" && k[0] != "html") {
18
- result += ` ${k[0]}='${k[1].toString()}'`;
19
- } else if (k[0] == "text")
20
- inn = `${
21
- typeof k[1] == "string"
22
- ? k[1]
23
- .replace(/&/g, "&amp;")
24
- .replace(/</g, "&lt;")
25
- .replace(/>/g, "&gt;")
26
- .replace(/"/g, "&quot;")
27
- .replace(/'/g, "&#39;")
28
- : k[1].toString()
29
- }`;
30
- else if (k[0] == "html") {
31
- inn = `${
32
- typeof k[1] != "function"
33
- ? k[1]
34
- : (k[1] + "")
35
- .replace(/.*{/, "")
36
- .split("")
37
- .reverse()
38
- .join("")
39
- .replace(/}/, "")
40
- .split("")
41
- .reverse()
42
- .join("")
43
- }`;
44
- // typeof k[1] == "string" ? inn : inn.substring(0, inn.length - 1);
45
- } else temp.push(k);
46
- });
47
-
48
- const stat = ![
49
- "input",
50
- "link",
51
- "br",
52
- "hr",
53
- "area",
54
- "base",
55
- "br",
56
- "col",
57
- "embed",
58
- "img",
59
- "meta",
60
- "param",
61
- "source",
62
- "track",
63
- "wbr",
64
- ].includes(e[0]);
65
- if (stat) {
66
- result += ">";
67
- result += inn;
68
- for (let i of temp) {
69
- result += render({ [i[0]]: i[1] });
70
- }
71
- result += `</${e[0]}>`;
72
- } else {
73
- if (!stat) result += "/>";
74
- }
75
- }
76
- });
77
- result = result.replace(/[\r\n\t]/gm, "");
78
- result = result.replace(/\s{2,}/gm, " ");
79
- return result;
80
- }
81
- function range(length, start = 0) {
82
- return [...Array(length)].map(() => start++);
83
- }
84
4
 
85
5
  function outFile(source, data) {
86
6
  const fs = require("fs");
87
7
  (function () {
88
8
  const dir = path.dirname(path.resolve(source));
89
9
  if (!fs.existsSync(dir)) fs.mkdirSync(dir);
90
- fs.writeFileSync(source, render(data));
10
+ fs.writeFileSync(source, data.render);
91
11
  console.log(`Output file: ${source}`);
92
12
  })();
13
+ return data.render;
93
14
  }
94
- function fromStr(letter, prefix = 0) {
95
- if (letter == "") return {};
96
-
97
- letter = letter.replace(/[\r\n\t]/gm, "").replace(/>\s{2,}</gm, "><");
98
- const result = {};
99
-
100
- if (/<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)$/.exec(letter)?.[1]) {
101
- result.tag = /<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)$/.exec(letter)[1];
102
-
103
- result.tag = result.tag + Array(prefix).fill(" ").join("");
104
-
105
- result.head = /<([a-zA-Z0-9]{1,}).*?>/.exec(letter)[0];
106
15
 
107
- result.inner = letter
108
- .replace(result.head, "")
109
- .split("")
110
- .reverse()
111
- .join("")
112
- .replace(
113
- `</${result.tag.replace(Array(prefix).fill(" ").join(""), "")}>`
114
- .split("")
115
- .reverse()
116
- .join(""),
117
- ""
118
- )
119
- .split("")
120
- .reverse()
121
- .join("");
122
- } else {
123
- result.tag = /<([a-zA-Z0-9]{1,}).*?\/>/.exec(letter)[1];
124
-
125
- result.tag = result.tag + Array(prefix).fill(" ").join("");
126
-
127
- result.head = /<([a-zA-Z0-9]{1,}).*?>/.exec(letter)[0];
128
- result.inner = "";
129
- }
130
- result.props = result.head.match(/[a-zA-Z0-9]{1,}=(["']).*?\1/g);
131
-
132
- let temp = { [result.tag]: {} };
133
- if (result.props)
134
- result.attr = result.props.forEach((e) => {
135
- let y = e.replace(/.*=(['"])/, "");
136
- y = y.substring(0, y.length - 1);
137
- let w = e.substring(0, e.indexOf("="));
138
- temp[result.tag][w] = y;
139
- });
140
-
141
- let s = [];
142
- let ttexr = result.inner;
143
- while (
144
- /<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)/.exec(ttexr) ||
145
- /<([a-zA-Z0-9]{1,}).*?\/>/.exec(ttexr)
146
- ) {
147
- let ss;
148
- if (/<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)/.exec(ttexr)) {
149
- ss = /<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)/.exec(ttexr)[0];
150
- const h = /<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)$/.exec(ss)[1];
151
- const sss = ttexr.slice(ttexr.indexOf(ss));
152
- const f = {
153
- a: sss.replace("<" + h, "").indexOf(`</${h}>`),
154
- b: sss.replace("<" + h, "").indexOf(`<${h}`),
155
- };
156
-
157
- ss = f.a > f.b && f.b > -1 ? sss : ss;
158
- } else {
159
- ss = /<([a-zA-Z0-9]{1,}).*?\/>/.exec(ttexr)[0];
160
- }
161
- ttexr = ttexr.replace(ss, "");
162
- s.push(ss);
163
- }
164
- s.sort((a, b) => {
165
- const r = { a: result.inner.indexOf(a), b: result.inner.indexOf(b) };
166
- return r.a > r.b ? 1 : r.a < r.b ? -1 : 0;
167
- });
168
- result.status = s;
169
- result.puretext = ttexr ? ttexr : ttexr + " ";
170
- // result.temp = temp;
171
- if (result.puretext != " ") temp[result.tag].text = result.puretext;
172
- if (result.status) {
173
- const ss = new Set();
174
- const current = {};
175
- s.forEach((e) => {
176
- const hh = /<[a-zA-Z0-9]{1,}\s?/.exec(e)[0].substring(1);
177
- if (ss.has(hh)) {
178
- current[hh] = current[hh] + 1;
179
- } else {
180
- current[hh] = 0;
181
- ss.add(hh);
182
- }
183
- temp = {
184
- [result.tag]: { ...temp[result.tag], ...fromStr(e, current[hh]) },
185
- };
186
- });
187
- }
188
- return temp;
189
- }
190
- module.exports = {
191
- render,
192
- range,
193
- outFile,
194
- fromStr,
195
- partial: async (src) => {
196
- const { default: i } = await import(
197
- path.join("file:\\\\", process.cwd(), src)
198
- );
199
- return i;
16
+ Object.defineProperty({}.__proto__, "outFile", {
17
+ value: function (goes) {
18
+ return outFile(goes, this);
200
19
  },
201
- };
20
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neobiz",
3
- "version": "1.4.0",
3
+ "version": "3.3.0",
4
4
  "description": "A simple view engine with JS features",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/readme.md CHANGED
@@ -1,12 +1,9 @@
1
1
  <!-- @format -->
2
2
 
3
- <!-- @format -->
4
-
5
- # Documentation Neobiz.js
3
+ # Documentation Neobiz.js 3.3
6
4
 
7
5
  > A simple view engine that has 100% JS features
8
6
 
9
- [[Github example]](https://github.com/harakun24/assets-neobiz)
10
7
  Neobiz.js is pure in JS lang, transform Object into HTML
11
8
 
12
9
  `read /example dir to understanding`
@@ -20,13 +17,13 @@ Neobiz.js is pure in JS lang, transform Object into HTML
20
17
  page.js
21
18
 
22
19
  ```js
23
- import { outFile } from "neobiz";
20
+ import "neobiz";
24
21
 
25
- outFile("./welcome.html", {
22
+ ({
26
23
  div: {
27
24
  script: [
28
25
  { src: "https://unpkg.com/vue@3/dist/vue.global.js" },
29
- { src: "https://unpkg.com/neobiz@1.4.0/browser.js" },
26
+ { src: "https://unpkg.com/neobiz@3.1.0/browser.js" },
30
27
  { src: "./my-component.js" },
31
28
  ],
32
29
  id: "app",
@@ -38,7 +35,7 @@ outFile("./welcome.html", {
38
35
  createApp(myComponent).mount("#app");
39
36
  },
40
37
  },
41
- });
38
+ }.outFile("./welcome.html"));
42
39
  ```
43
40
 
44
41
  my-component.js
@@ -48,19 +45,20 @@ const myComponent = {
48
45
  data() {
49
46
  return { msg: "hi, this is example" };
50
47
  },
51
- template: render({ h1: { text: "{{msg}}" } }),
48
+ template: { h1: { text: "{{msg}}" } }.render,
52
49
  };
53
50
  ```
54
51
 
55
52
  <br>
56
53
 
57
- | function | params | return-type | description |
58
- | -------- | ------------------------------------ | ----------- | -------------------------------- |
59
- | render | content[object] | string | rendering to HTML |
60
- | outFile | destination[string], content[object] | void | generate static HTML file |
61
- | range | length[int], start[int] | Array | shortcut for looping in a range |
62
- | partial | source[string] | AsyncFn | including other file |
63
- | fromStr | str[string] | Object | generate object from HTML string |
54
+ | properties | caller | return-type | description |
55
+ | ---------- | ------------------------------------- | ----------- | -------------------------------- |
56
+ | render | Object | string | rendering to HTML |
57
+ | outFile | Object @params[destination] | void | generate static HTML file |
58
+ | range | Array @params length[int], start[int] | Array | shortcut for looping in a range |
59
+ | repulse | String | Object | generate object from HTML string |
60
+ | css | Object | Object | generate css from object |
61
+ | cssText | Object | String | inline css |
64
62
 
65
63
  #### Why use this?
66
64
 
@@ -73,15 +71,21 @@ const myComponent = {
73
71
 
74
72
  ## Basic syntax
75
73
 
76
- It's just an Object!
74
+ How to use? just import this:
75
+
76
+ ```js
77
+ import "neobiz";
78
+ ```
79
+
80
+ It's just an Object! `wrap in () to create a statement or just assign to a var`
77
81
 
78
82
  ```js
79
83
  {
80
84
  // text property is same as innerText
81
85
  h1: {
82
86
  text: "Hello World!",
83
- }
84
- }
87
+ },
88
+ }.render;
85
89
  // <h1>Hello World!</h1>
86
90
  ```
87
91
 
@@ -194,17 +198,17 @@ Can't use array? just use this:
194
198
  }
195
199
  ```
196
200
 
197
- ### Components
201
+ ### Components / Partials
198
202
 
199
203
  ```js
200
204
  import header from "./header.v.js"; //function type
201
205
  import footer from "./footer.v.js"; //object type
202
206
 
203
- render({
207
+ {
204
208
  div: header({ user: "dim24" }),
205
209
  p: { text: "this is text" },
206
210
  div: footer,
207
- });
211
+ }.render;
208
212
  ```
209
213
 
210
214
  header.v.js
@@ -222,6 +226,59 @@ export default {
222
226
  };
223
227
  ```
224
228
 
229
+ ### Style
230
+
231
+ use camel case to css properties
232
+
233
+ #### inline CSS:
234
+
235
+ ```js
236
+ {
237
+ h1:{
238
+ text:"Hello World",
239
+ style:{
240
+ color:"#1B73F8",
241
+ fontSize:"150%"
242
+ }.cssText
243
+ }
244
+ }
245
+ ```
246
+
247
+ use style :
248
+
249
+ `global-style.js`:
250
+
251
+ ```js
252
+ export default {
253
+ h1: {
254
+ color: "red",
255
+ },
256
+ body: {
257
+ margin: "0px",
258
+ textAlign: "center",
259
+ },
260
+ };
261
+ ```
262
+
263
+ why should use object css rather than direct css?
264
+
265
+ we can easily modify the style
266
+
267
+ `main-page.js`:
268
+
269
+ ```js
270
+ import style from "./global-style.js";
271
+
272
+ style.body.margin = "12px";
273
+
274
+ {
275
+ style:style.css,
276
+ div:{
277
+ h1:{text:"Hello World!"}
278
+ }
279
+ }.render
280
+ ```
281
+
225
282
  ### Interacting with DOM
226
283
 
227
284
  use `script` to interact with browser with **html** property
@@ -232,7 +289,7 @@ wrap the script with a function, or use string
232
289
  {
233
290
  button:{onclick:"sayHi(this)",id:"hi-button"},
234
291
  script:{
235
- html:()=>{
292
+ html(){
236
293
  document.getElementById("hi-button").innerText="Click me!";
237
294
 
238
295
  function sayHi(el){
@@ -244,32 +301,46 @@ wrap the script with a function, or use string
244
301
 
245
302
  ```
246
303
 
247
- ## fromStr
304
+ ### Event
305
+
306
+ you can add an event `this` keyword always refered to the node itseft
307
+
308
+ ```js
309
+ {
310
+ input:{type:"password",onkeypress(){
311
+ if(event.keyCode==13)
312
+ alert(this.value)
313
+ }},
314
+ button:{text:"Click me!",onclick(){
315
+ this.innerText = this.innerText=="clicked"?"Click me!":"clicked";
316
+ }}
317
+ }
318
+ ```
319
+
320
+ ## Repulse
248
321
 
249
- If you already have an html file and want to modify it, or make it as a template, just use `fromStr` function
322
+ If you already have an html file and want to modify it, or make it as a template, just use this
250
323
 
251
- > this function is still has some issues, but for simple html fromStr is work fine!
324
+ > this function is still has a lot issues, use only in a simple case
252
325
 
253
- - wrap all tag into single parent
254
- - use external script and css
255
- - repetitive nested could caused weird behavior (help me, please!)
326
+ - need to wrap all tag into a single parent
327
+ - recommended to use external script and css
328
+ - repetitive / nested could caused weird behavior (help me, please!)
256
329
 
257
330
  I still try to improve this feature. **if you can provide some help** just tell me please... :)
258
331
 
259
332
  ```js
260
- const { fromStr, render } = require("./index");
261
-
262
- const { div } = fromStr(`
333
+ const { div } = `
263
334
  <div>
264
335
  <h1>Hello dims!</h1>
265
336
  </div>
266
- `);
337
+ `.repulse;
267
338
 
268
339
  div.id = "main";
269
340
  div.h1.class = "heading";
270
341
  div.p = { text: "this is a whole text" };
271
342
 
272
- console.log(render({ div }));
343
+ console.log({ div }.render);
273
344
  ```
274
345
 
275
346
  result
@@ -286,9 +357,7 @@ result
286
357
  use function
287
358
 
288
359
  ```js
289
- import { render } from "../index.js";
290
-
291
- console.log(render(((user) => ({ h1: { text: `Hello, ${user}` } }))("Vins")));
360
+ console.log(((user) => ({ h1: { text: `Hello, ${user}` } }))("Vins").render);
292
361
  ```
293
362
 
294
363
  or
@@ -296,7 +365,7 @@ or
296
365
  ```js
297
366
  const greeting = (user) => ({ h1: `Hello, ${user}` });
298
367
 
299
- console.log(render(greeting("Vins")));
368
+ console.log(greeting("Vins").render);
300
369
  ```
301
370
 
302
371
  ## Control Flow
@@ -354,11 +423,10 @@ IIFE switch-case
354
423
  range & map:
355
424
 
356
425
  ```js
357
- import { render, range } from "../index.js";
358
426
 
359
427
  {
360
428
  ul: {
361
- li: range(8, 1).map((item) => ({ text: "data-" + item })),
429
+ li: [].range(8, 1).map((item) => ({ text: "data-" + item })),
362
430
  },
363
431
  }
364
432
  ```
@@ -402,34 +470,12 @@ while
402
470
  }
403
471
  ```
404
472
 
405
- ## partial & templating
406
-
407
- ### partial
408
-
409
- make sure to default export as a function
410
-
411
- ```js
412
- import { render, partial } from "../index.js";
413
-
414
- {
415
- head: (await partial("./exported.v.js"))("example page"),
416
- h1: { text: "This is example" },
417
- }
418
- ```
419
-
420
- `/exported.v.js`
421
-
422
- ```js
423
- export default (title) => ({ title: { text: title } });
424
- ```
425
-
426
- ### templating
473
+ ## templating
427
474
 
428
475
  this example use single file usage. for modular usage leave to you, or just read the example dir
429
476
 
430
477
  ```js
431
- import { render } from "../index.js";
432
-
478
+ //template file
433
479
  const template = (content) => ({
434
480
  div: {
435
481
  class: "main wrapper",
@@ -437,6 +483,7 @@ const template = (content) => ({
437
483
  },
438
484
  });
439
485
 
486
+ //content file
440
487
  template({
441
488
  h1: { text: "Hello World!" },
442
489
  });