neobiz 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/index.js ADDED
@@ -0,0 +1,3 @@
1
+ /** @format */
2
+
3
+ module.exports = require("./simple.js");
package/minify.js ADDED
@@ -0,0 +1,11 @@
1
+ /** @format */
2
+ const fs = require("fs");
3
+
4
+ fs.writeFileSync(
5
+ "./simple.min.js",
6
+ fs
7
+ .readFileSync("./simple.js")
8
+ .toString()
9
+ .replace(/[\r\n\t]/gm, "")
10
+ .replace(/\s{2,}/gm, " ")
11
+ );
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "neobiz",
3
+ "version": "1.0.0",
4
+ "description": "simple view engine yet powerful with javascript features",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [
10
+ "view engine",
11
+ "template engine",
12
+ "view"
13
+ ],
14
+ "license": "ISC"
15
+ }
package/readme.md ADDED
@@ -0,0 +1,300 @@
1
+ <!-- @format -->
2
+
3
+ # Documentation
4
+
5
+ ## NEOBIZ
6
+
7
+ A simple view engine, minimalist yet powerful with **JavaScript** Features.
8
+
9
+ ```js
10
+ import head from "./partials/head.v.js";
11
+
12
+ {
13
+ html:{
14
+ head:head("this is title"),
15
+ body:{
16
+ h1:{text:"Hello World!"},
17
+ b:range(10,13).filter(i=>i%2).map(i=>{text:`${i}- index`})
18
+ ul:[
19
+ {
20
+ li:[
21
+ {text:"one"},
22
+ {text:"two"},
23
+ {text:"3"},
24
+ ]
25
+ },
26
+ {
27
+ li:["apple","banana","orange"].map(item=>({text:item}))
28
+ }
29
+ ]
30
+ }
31
+ }
32
+ }
33
+ ```
34
+
35
+ ### 1.0.0 Basic
36
+
37
+ #### 1.1.0 Format
38
+
39
+ It's just _JS Object_!
40
+
41
+ ```js
42
+ {
43
+ tag: {
44
+ //properties
45
+ }
46
+ }
47
+ ```
48
+
49
+ Then render to HTML `:example`:
50
+
51
+ ```js
52
+ //use text property as innerHTML
53
+ {
54
+ h1: {
55
+ text: "Hello World!";
56
+ }
57
+ }
58
+ ```
59
+
60
+ ```html
61
+ <h1>Hello World!</h1>
62
+ ```
63
+
64
+ #### 1.2.0 Why use js Object?
65
+
66
+ - **JS Features**
67
+ - **Unlimited Library** to handle data
68
+ - **Lite view engine yet full of power**
69
+
70
+ #### 1.3.0 File extension
71
+
72
+ `.js` is fine, but it's better to use `.v.js` to separate view
73
+
74
+ ### 2.0.0 Render
75
+
76
+ there is 2 ways to outputing view.
77
+
78
+ 1. String `Recomended to send as response server`
79
+ 2. File `Static file serve / docs`
80
+
81
+ #### 2.1.0 render method
82
+
83
+ ```js
84
+ import { render } from "neobiz";
85
+
86
+ return render({ p: { text: "This is a p" } });
87
+
88
+ //<p>This is a p</p>
89
+ ```
90
+
91
+ #### 2.2.0 outFile
92
+
93
+ outFile([filepath],[object-view])
94
+
95
+ ```js
96
+ import { outFile } from "neobiz";
97
+
98
+ outFile("./index.html", { button: { text: "This is button" } });
99
+ ```
100
+
101
+ #### 2.3.0 range
102
+
103
+ It's just bonus
104
+
105
+ range([length],[start])
106
+
107
+ ### 3.0.0 Data
108
+
109
+ #### 3.1.0 use variable
110
+
111
+ ```js
112
+ //import neobiz
113
+ const msg = "Welcome page!";
114
+
115
+ render({ h1: { text: msg } });
116
+ render({ h1: { text: `Message: ${msg}` } });
117
+ ```
118
+
119
+ ### 4.0.0 Syntax
120
+
121
+ #### 4.1.0 props
122
+
123
+ ```js
124
+ {h1:{text:"example",class:"heading1",id:"mainHead",style:"color:red;"}}
125
+
126
+ //to
127
+
128
+ <h1 class="heading1" id="mainHead" style="color:red;">example</h1>
129
+ ```
130
+
131
+ #### 4.2.0 conflict key
132
+
133
+ sometimes this case will happened:
134
+
135
+ ```html
136
+ <li>this is 1st li</li>
137
+ <p>this is middle content</p>
138
+ <li>this is 2nd li</li>
139
+ ```
140
+
141
+ don't do this:
142
+ `the 2nd li will rewrite 1st li`
143
+
144
+ ```js
145
+ {
146
+ li:{text:"this is 1st li"},
147
+ p:{text:"this is middle content"},
148
+ li:{text:"this is 2nd li"}
149
+ }
150
+
151
+ // just use this instead
152
+
153
+ {
154
+ li:{text:"this is 1st li"},
155
+ p:{text:"this is middle content"},
156
+ "li ":{text:"this is 2nd li"}
157
+ }
158
+ ```
159
+
160
+ #### 4.3.0 passing value
161
+
162
+ just use function expression
163
+
164
+ for example in express.js response:
165
+
166
+ `express server`
167
+
168
+ ```js
169
+ import profile from "./Views/profile.v.js";
170
+ import { render } from "neobiz";
171
+
172
+ res.send(render(profile("Dimas")));
173
+ ```
174
+
175
+ `profile.v.js`
176
+
177
+ ```js
178
+ export default (username) => ({ h1: { text: `Welcome, ${username}` } });
179
+ ```
180
+
181
+ #### 4.4.0 Structural concepts
182
+
183
+ ##### 4.4.1 partial
184
+
185
+ ```js
186
+ import header from "./partials/header.v.js";
187
+
188
+ export default (...args) => ({
189
+ body: {
190
+ div: header(...args),
191
+ //contents
192
+ },
193
+ });
194
+ ```
195
+
196
+ ##### 4.4.2 template
197
+
198
+ `template.v.js`
199
+
200
+ ```js
201
+ export default (contents, ...args) => ({
202
+ html: {
203
+ head: {
204
+ /*...*/
205
+ },
206
+ body: {
207
+ id: "main",
208
+ div: contents,
209
+ },
210
+ },
211
+ });
212
+ ```
213
+
214
+ `contents.v.js`
215
+
216
+ ```js
217
+ import template from "./template.v.js";
218
+
219
+ export default (...args) =>
220
+ template(
221
+ {
222
+ h1: "this is heading",
223
+ //some contents
224
+ },
225
+ ...args
226
+ );
227
+ ```
228
+
229
+ #### 4.5.0 Control flow
230
+
231
+ just use IIFE
232
+
233
+ ##### 4.5.1 IF else
234
+
235
+ `Ternary operator`
236
+
237
+ ```js
238
+ const status = false;
239
+
240
+ const result = {
241
+ h1: status
242
+ ? { text: "already active" }
243
+ : { button: { onclick: "...", text: "activate" } },
244
+ };
245
+ ```
246
+
247
+ `IIFE`
248
+
249
+ ```js
250
+ const status = false;
251
+
252
+ const result = {
253
+ h1: status
254
+ ? { text: "already active" }
255
+ : { button: { onclick: "...", text: "activate" } },
256
+ };
257
+ ```
258
+
259
+ ##### 4.5.2 for loop
260
+
261
+ maps in range
262
+
263
+ ```js
264
+ import { range } from "neobiz";
265
+
266
+ return {
267
+ ul: {
268
+ li: range(8).map((item) => ({ text: item })),
269
+ },
270
+ };
271
+ ```
272
+
273
+ maps in array
274
+
275
+ ```js
276
+ import { range } from "neobiz";
277
+
278
+ return {
279
+ ul: {
280
+ li: ["one", "two"].map((item) => ({ text: item })),
281
+ },
282
+ };
283
+ ```
284
+
285
+ IIFE
286
+
287
+ ```js
288
+ return {
289
+ ul: {
290
+ li: ((array) => {
291
+ for (let i = 0; i < 10; i++) array[i] = { text: array[i] };
292
+ return array;
293
+ })(),
294
+ },
295
+ };
296
+ ```
297
+
298
+ ##### 4.5.3 while loop
299
+
300
+ just same as `4.5.2` section
package/simple.js ADDED
@@ -0,0 +1,63 @@
1
+ /** @format */
2
+ "use strict";
3
+
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(" ", "");
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")
18
+ result += ` ${k[0]}='${k[1]}'`;
19
+ else if (typeof k[1] == "function") result += ` ${k[0]}='${k[1] + ""}'`;
20
+ else if (k[0] == "text") inn = `${k[1]}`;
21
+ else temp.push(k);
22
+ });
23
+ const stat = !["input", "link", "br", "hr"].includes(e[0]);
24
+ if (stat) result += ">";
25
+ result += inn;
26
+ for (let i of temp) result += render({ [i[0]]: i[1] });
27
+ if (stat) result += `</${e[0]}>`;
28
+ else result += "/>";
29
+ } else {
30
+ }
31
+ });
32
+ result = result.replace(/[\r\n\t]/gm, "");
33
+ result = result.replace(/\s{2,}/gm, " ");
34
+ return result;
35
+ }
36
+ function range(length, start = 0) {
37
+ return [...Array(length)].map(() => start++);
38
+ }
39
+
40
+ function outFile(source, data) {
41
+ const fs = require("fs");
42
+ const path = require("path");
43
+ (function () {
44
+ const dir = path.dirname(path.resolve(source));
45
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir);
46
+ fs.writeFileSync(source, render(data));
47
+ console.log(`Output file: ${source}`);
48
+ })();
49
+ }
50
+
51
+ function readf(source) {
52
+ const fs = require("fs");
53
+ const path = require("path");
54
+
55
+ return fs.readFileSync(path.resolve(source)).toString();
56
+ }
57
+
58
+ module.exports = {
59
+ render,
60
+ range,
61
+ outFile,
62
+ readf,
63
+ };
package/simple.min.js ADDED
@@ -0,0 +1 @@
1
+ /** @format */"use strict";function render(val = {}) { let result = ""; Object.entries(val).forEach((e) => { if (e[1].length) { e[1].forEach((g) => { result += render({ [e[0]]: g }); }); } else if (typeof e[1] == "object") { e[0] = e[0].replace(" ", ""); result += `<${e[0]}`; const temp = []; let inn = ""; Object.entries(e[1]).forEach((k) => { if (typeof k[1] == "string" && k[0] != "text") result += ` ${k[0]}='${k[1]}'`; else if (typeof k[1] == "function") result += ` ${k[0]}='${k[1] + ""}'`; else if (k[0] == "text") inn = `${k[1]}`; else temp.push(k); }); const stat = !["input", "link", "br", "hr"].includes(e[0]); if (stat) result += ">"; result += inn; for (let i of temp) result += render({ [i[0]]: i[1] }); if (stat) result += `</${e[0]}>`; else result += "/>"; } else { } }); result = result.replace(/[\r\n\t]/gm, ""); result = result.replace(/\s{2,}/gm, " "); return result;}function range(length, start = 0) { return [...Array(length)].map(() => start++);}function outFile(source, data) { const fs = require("fs"); const path = require("path"); (function () { const dir = path.dirname(path.resolve(source)); if (!fs.existsSync(dir)) fs.mkdirSync(dir); fs.writeFileSync(source, render(data)); console.log(`Output file: ${source}`); })();}function readf(source) { const fs = require("fs"); const path = require("path"); return fs.readFileSync(path.resolve(source)).toString();}module.exports = { render, range, outFile, readf,};
package/test/index.js ADDED
@@ -0,0 +1,8 @@
1
+ /** @format */
2
+
3
+ import { outFile } from "object-view";
4
+ import header from "./s.js";
5
+
6
+ outFile("./temp.html", {
7
+ h1: header("Dimas"),
8
+ });
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "test",
3
+ "version": "1.0.0",
4
+ "lockfileVersion": 2,
5
+ "requires": true,
6
+ "packages": {
7
+ "..": {
8
+ "version": "1.0.0",
9
+ "license": "ISC"
10
+ },
11
+ "node_modules/object-view": {
12
+ "resolved": "..",
13
+ "link": true
14
+ }
15
+ }
16
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "test",
3
+ "type": "module",
4
+ "version": "1.0.0",
5
+ "description": "",
6
+ "main": "index.js",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "author": "",
11
+ "license": "ISC"
12
+ }
package/test/s.js ADDED
@@ -0,0 +1,3 @@
1
+ /** @format */
2
+
3
+ export default (data) => ({ text: `hello ${data}!` });
package/test/temp.html ADDED
@@ -0,0 +1 @@
1
+ <h1>hello Dimas!</h1>