neobiz 1.3.4 → 1.3.5

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