neobiz 1.2.1 → 1.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Abista_VD
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -16,3 +16,8 @@ console.log(
16
16
  outFile("./basic.html", {
17
17
  h1: { text: "Hello World!" },
18
18
  });
19
+
20
+ // properties
21
+ render({
22
+ h1: { class: "heading", id: "main", text: "Hello World!" },
23
+ });
@@ -0,0 +1,15 @@
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
+ });
package/index.js CHANGED
@@ -15,10 +15,17 @@ function render(val = {}) {
15
15
  const temp = [];
16
16
  let inn = "";
17
17
  Object.entries(e[1]).forEach((k) => {
18
- if (typeof k[1] == "string" && k[0] != "text")
18
+ if (typeof k[1] == "string" && k[0] != "text" && k[0] != "html")
19
19
  result += ` ${k[0]}='${k[1]}'`;
20
- else if (typeof k[1] == "function") result += ` ${k[0]}='${k[1] + ""}'`;
21
- else if (k[0] == "text") inn = `${k[1]}`;
20
+ // else if (typeof k[1] == "function") result += ` ${k[0]}='${k[1] + ""}'`;
21
+ else if (k[0] == "text")
22
+ inn = `${k[1]
23
+ .replace(/&/g, "&amp;")
24
+ .replace(/</g, "&lt;")
25
+ .replace(/>/g, "&gt;")
26
+ .replace(/"/g, "&quot;")
27
+ .replace(/'/g, "&#39;")}`;
28
+ else if (k[0] == "html") inn = `${k[1]}`;
22
29
  else temp.push(k);
23
30
  });
24
31
  const stat = !["input", "link", "br", "hr"].includes(e[0]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neobiz",
3
- "version": "1.2.1",
3
+ "version": "1.2.4",
4
4
  "description": "simple view engine yet powerful with javascript features",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/readme.md CHANGED
@@ -4,7 +4,8 @@
4
4
 
5
5
  > A simple view engine that has 100% JS features
6
6
 
7
- Neobiz.js is pure JS lang, transpile Object to HTML as string
7
+ [Github](https://www.npmjs.com/package/neobiz-express?activeTab=dependencies)
8
+ Neobiz.js is pure in JS lang, transform Object into HTML
8
9
 
9
10
  `read /example dir to understanding`
10
11
 
@@ -15,19 +16,28 @@ Neobiz.js is pure JS lang, transpile Object to HTML as string
15
16
  | function | params | return-type | description |
16
17
  | -------- | ---------------------------------- | ----------- | ------------------------------- |
17
18
  | render | content:object | string | rendering to HTML |
18
- | outFile | destination:string, content:object | | generate static HTML file |
19
+ | outFile | destination:string, content:object | void | generate static HTML file |
19
20
  | range | length:int, start:int | Array | shortcut for looping in a range |
20
21
  | partial | source:string | AsyncFn | including other file |
21
22
 
23
+ #### Why use this?
24
+
25
+ - One lang for all, back end - view - browser script all js!
26
+ - **directly** interact data or Model with a view
27
+ - Generate static html file
28
+ - Full control of serving the view. Such as encrypting the data before serve, or just like conditional and loop case
29
+ - Almost no need to learn anything. Just need to learn how to render
30
+ - Limitless potential, because it's just js. Almost all library should be compatible
31
+
22
32
  ## Basic syntax
23
33
 
24
- It's just Object in js!
34
+ It's just an Object!
25
35
 
26
36
  ```js
27
37
  {
28
38
  // text property is same as innerHTML
29
39
  h1: {
30
- text: "Hello World!";
40
+ text: "Hello World!",
31
41
  }
32
42
  }
33
43
  // <h1>Hello World!</h1>
@@ -37,23 +47,31 @@ properties dom
37
47
 
38
48
  ```js
39
49
  {
40
- // text property is same as innerHTML
41
50
  h1: {
42
51
  class:"heading",
43
- text: "Hello World!";
44
- style:"color: #DC1E1E"
52
+ text: "Hello World!",
53
+ style:"color: #DC1E1E",
45
54
  }
46
55
  }
47
56
  // <h1 class="heading" style="color: #DC1E1E">Hello World!</h1>
48
57
  ```
49
58
 
59
+ innerText & innerHTML:
60
+
61
+ ```js
62
+ {
63
+ h1: { text: "<b>this is a text</b>" },
64
+ ul: { html: "<li>this will be render as html</li>" },
65
+ }
66
+ ```
67
+
50
68
  nested dom:
51
69
 
52
70
  ```js
53
71
  {
54
72
  body: {
55
73
  h1: {
56
- text: "Hello World!";
74
+ text: "Hello World!",
57
75
  }
58
76
  }
59
77
  }
@@ -68,7 +86,7 @@ There is a case like this:
68
86
  <li>banana</li>
69
87
  ```
70
88
 
71
- Object can not use 2 keys with same name, instead use this:
89
+ Object can not use 2 keys with the same name, instead use this:
72
90
 
73
91
  ```js
74
92
  // Don't do this
@@ -98,11 +116,14 @@ What if there is somethings in the middle of list?
98
116
 
99
117
  Can't use array? just use this:
100
118
 
119
+ > use string as key could distinc an element with just a space
120
+ > no need to worry, it will render without space
121
+
101
122
  ```js
102
123
  {
103
124
  li:{text:"orange"},
104
- p:{span:{text:"This is in the middle"}}
105
- li:{text:"banana"},
125
+ p:{span:{text:"This is in the middle"}},
126
+ "li ":{text:"banana"},
106
127
  }
107
128
  ```
108
129
 
@@ -231,7 +252,7 @@ while
231
252
 
232
253
  ### partial
233
254
 
234
- make sure to export as function & default
255
+ make sure to default export as a function
235
256
 
236
257
  ```js
237
258
  import { render, partial } from "../index.js";
@@ -250,7 +271,7 @@ export default (title) => ({ title: { text: title } });
250
271
 
251
272
  ### templating
252
273
 
253
- this example use single file usage. for modular usage leave to you
274
+ this example use single file usage. for modular usage leave to you, or just read the example dir
254
275
 
255
276
  ```js
256
277
  import { render } from "../index.js";
@@ -1 +0,0 @@
1
- <h1>Hello World!</h1>