neobiz 4.3.12 → 4.7.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
@@ -3,37 +3,67 @@
3
3
  "use strict";
4
4
 
5
5
  const adp = {};
6
- let d = render ? "_render" : "render";
7
6
  let option = {
8
7
  camelCase: false,
8
+ prefix: false,
9
+ prefixAttr: false,
9
10
  };
10
11
  ({}.__proto__.renderOption = (opt) => {
11
12
  option = opt;
12
13
  });
13
- function render(val = {}) {
14
+ ({}.__proto__.Null = Symbol("@null"));
15
+ function renderz(val = {}) {
14
16
  let result = "";
17
+ let status = option.prefix;
18
+ let status2 = option.prefixAttr;
15
19
  try {
16
20
  Object.entries(val).forEach((e) => {
17
21
  if (Array.isArray(e[1])) {
18
22
  e[1].forEach((g) => {
19
- result += render({ [e[0]]: g });
23
+ result += renderz({ [e[0]]: g });
20
24
  });
21
25
  } else if (typeof e[1] == "object") {
26
+ // const { noprefix = null, nopAttr = null } = e[1];
27
+ e[1].noprefix = e[1].noprefix || false;
28
+ e[1].nopAttr = e[1].nopAttr || false;
29
+ if (e[1].noprefix == "true") option.prefix = false;
30
+ if (e[1].nopAttr == "true") option.prefixAttr = false;
31
+ // if (nopAttr) option.prefixAttr = false;
32
+
22
33
  e[0] = e[0].replace(/\s/g, "");
23
- e[0] = e[1].tag || e[0];
34
+ if (!option.ignoreTag) {
35
+ e[0] = e[1].tag || e[0];
36
+ }
24
37
  delete e[1].tag;
25
38
  if (option.camelCase)
26
39
  e[0] = e[0].replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
27
- result += `<${e[0]}`;
40
+ result += `<${(option.prefix ? option.prefix : "") + e[0]}`;
28
41
  const temp = [];
29
42
  let inn = "";
30
43
  Object.entries(e[1]).forEach((k) => {
31
- if (typeof k[1] == "string" && k[0] != "text" && k[0] != "html") {
44
+ if (typeof k[1] == "symbol" && k[1].toString() == "Symbol(@null)")
45
+ result += ` ${k[0]}`;
46
+ else if (
47
+ typeof k[1] != "object" &&
48
+ typeof k[1] != "function" &&
49
+ k[0] != "text" &&
50
+ k[0] != "html" &&
51
+ k[0] != "noprefix" &&
52
+ k[0] != "nopAttr"
53
+ ) {
32
54
  if (option.camelCase)
33
- k[0] = k[0].replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
34
- result += ` ${k[0]}='${k[1].toString()}'`;
55
+ k[0] = k[0].replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
56
+ result += ` ${
57
+ (option.prefixAttr ? option.prefixAttr : "") + k[0]
58
+ }='${k[1].toString()}'`;
35
59
  }
36
- if (typeof k[1] == "function" && k[0] != "text" && k[0] != "html") {
60
+ if (
61
+ typeof k[1] == "function" &&
62
+ k[0] != "text" &&
63
+ k[0] != "html" &&
64
+ k[0] != "noprefix" &&
65
+ k[0] != "nopAttr"
66
+ ) {
37
67
  result += ` ${k[0]}='${(k[1] + "")
38
68
  .replace(/.*{/, "")
39
69
  .split("")
@@ -43,7 +73,7 @@ function render(val = {}) {
43
73
  .split("")
44
74
  .reverse()
45
75
  .join("")}'`;
46
- } else if (k[0] == "text")
76
+ } else if (k[0] == "text") {
47
77
  inn = `${
48
78
  typeof k[1] == "string"
49
79
  ? k[1]
@@ -54,7 +84,8 @@ function render(val = {}) {
54
84
  .replace(/'/g, "&#39;")
55
85
  : k[1].toString()
56
86
  }`;
57
- else if (k[0] == "html") {
87
+ temp.push(inn);
88
+ } else if (k[0] == "html") {
58
89
  inn = `${
59
90
  typeof k[1] != "function"
60
91
  ? k[1]
@@ -68,6 +99,7 @@ function render(val = {}) {
68
99
  .reverse()
69
100
  .join("")
70
101
  }`;
102
+ temp.push(inn);
71
103
  // typeof k[1] == "string" ? inn : inn.substring(0, inn.length - 1);
72
104
  } else temp.push(k);
73
105
  });
@@ -91,11 +123,11 @@ function render(val = {}) {
91
123
  ].includes(e[0]);
92
124
  if (stat) {
93
125
  result += ">";
94
- result += inn;
126
+ // result += inn;
95
127
  for (let i of temp) {
96
- result += render({ [i[0]]: i[1] });
128
+ result += typeof i == "string" ? i : renderz({ [i[0]]: i[1] });
97
129
  }
98
- result += `</${e[0]}>`;
130
+ result += `</${(option.prefix ? option.prefix : "") + e[0]}>`;
99
131
  } else {
100
132
  if (!stat) result += "/>";
101
133
  }
@@ -104,20 +136,22 @@ function render(val = {}) {
104
136
  result = result.replace(/[\r\n\t]/gm, "");
105
137
  result = result.replace(/\s{2,}/gm, " ");
106
138
  } catch (e) {
107
- result = `<p>Error: ${e.message}</p>`;
139
+ result = `<p>Error: ${e}</p>`;
108
140
  }
141
+ option.prefixAttr = status2;
142
+ option.prefix = status;
109
143
  return result;
110
144
  }
111
145
  function rdr(val = {}) {
112
146
  let result = "<!DOCTYPE html>";
113
147
  if (Array.isArray(val)) {
114
148
  val.forEach((value) => {
115
- result += render(value);
149
+ result += renderz(value);
116
150
  });
117
- } else result = render(val);
151
+ } else result = renderz(val);
118
152
  if (option.once)
119
153
  option = {
120
- camelCase: false,
154
+ // camelCase: false,
121
155
  };
122
156
  return result;
123
157
  }
@@ -221,11 +255,9 @@ function fromStr(letter, prefix = 0) {
221
255
  return temp;
222
256
  }
223
257
 
224
- console.log(d);
225
-
226
- Object.defineProperty({}.__proto__, d, {
258
+ Object.defineProperty({}.__proto__, "_render", {
227
259
  get: function () {
228
- return "<!DOCTYPE html>" + rdr(this);
260
+ return (option.nodoctype ? "" : "<!DOCTYPE html>") + rdr(this);
229
261
  },
230
262
  });
231
263
  Object.defineProperty({}.__proto__, "reg", {
@@ -0,0 +1,17 @@
1
+ /** @format */
2
+
3
+ import "../index.js";
4
+ renderOption({
5
+ prefix: "ion-",
6
+ });
7
+ console.log(
8
+ {
9
+ button: {
10
+ text: "Hello World!",
11
+ disabled: Null,
12
+ onclick() {
13
+ alert("hi");
14
+ },
15
+ },
16
+ }._render
17
+ );
@@ -0,0 +1,15 @@
1
+ /** @format */
2
+
3
+ import "../index.js";
4
+ renderOption({
5
+ // ignoreTag: false,
6
+ nodoctype: true,
7
+ prefix: "u-",
8
+ });
9
+ console.log(
10
+ {
11
+ div: {
12
+ h1: { noprefix: true, id: "hi", text: "hello", tag: "p" },
13
+ },
14
+ }._render
15
+ );
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "neobiz",
3
- "version": "4.3.12",
4
- "description": "A simple view engine with JS features",
3
+ "version": "4.7.0",
4
+ "description": "A simple tool to convert Object to HTML string",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
package/readme.md CHANGED
@@ -1,6 +1,6 @@
1
1
  <!-- @format -->
2
2
 
3
- # Documentation Neobiz.js 4.3.12
3
+ # Documentation Neobiz.js 4.7
4
4
 
5
5
  > A simple view engine that has 100% JS features
6
6
 
@@ -8,12 +8,18 @@ Neobiz.js is pure in JS lang, transform Object into HTML
8
8
 
9
9
  ## Updates:
10
10
 
11
- - `render` method will rename to `**\_render**` if there is already exist render method, to avoid conflict with another script
12
- - render option props
11
+ - fix event bugs
12
+ - Boolean attributes / non-value attribute (example: disabled, readonly)
13
13
 
14
- New features:
14
+ ## prev update:
15
15
 
16
- - Sanitized eventHandler
16
+ - `render` method change to `**\_render**`to avoid conflict with another library and add safety check
17
+ - render option props improve
18
+ - fix bug on child order
19
+
20
+ features:
21
+
22
+ - eventHandler
17
23
  - Reusable & editable style/css
18
24
  - Altering object
19
25
  - Registering component
@@ -60,31 +66,30 @@ const myComponent = {
60
66
  data() {
61
67
  return { msg: "hi, this is example" };
62
68
  },
63
- template: { h1: { text: "{{msg}}" } }.render,
69
+ template: { h1: { text: "{{msg}}" } }._render,
64
70
  };
65
71
  ```
66
72
 
67
73
  <br>
68
74
 
69
- | properties | caller | return-type | description |
70
- | ----------------- | ------------------------------------- | ----------- | --------------------------------------- |
71
- | render / \_render | Object | string | rendering to HTML |
72
- | outFile | Object @params destination[string] | void | generate static HTML file |
73
- | range | Array @params length[int], start[int] | Array | shortcut for looping in a range |
74
- | repulse | String | Object | generate object from HTML string |
75
- | css | Object | Object | generate css from object |
76
- | cssText | Object | Object | inline css |
77
- | alter [trials] | Object @params cb[function] | Object | altering object before rendering |
78
- | reg | Object | void | registring an object |
79
- | regm | Object | void | updating the existing registered object |
80
- | load | Object | Object | read an existing registered object |
81
- | unred | Object | void | removing an existing registered object |
82
- | renderOption | Object @params option[Object] | void | set the option for rendering |
75
+ | properties | caller | return-type | description |
76
+ | -------------- | ------------------------------------- | ----------- | --------------------------------------- |
77
+ | \_render | Object | string | rendering to HTML |
78
+ | outFile | Object @params destination[string] | void | generate static HTML file |
79
+ | range | Array @params length[int], start[int] | Array | shortcut for looping in a range |
80
+ | repulse | String | Object | generate object from HTML string |
81
+ | css | Object | Object | generate css from object |
82
+ | cssText | Object | Object | inline css |
83
+ | alter [trials] | Object @params cb[function] | Object | altering object before rendering |
84
+ | reg | Object | void | registring an object |
85
+ | regm | Object | void | updating the existing registered object |
86
+ | load | Object | Object | read an existing registered object |
87
+ | unred | Object | void | removing an existing registered object |
88
+ | renderOption | Object @params option[Object] | void | set the option for rendering |
83
89
 
84
90
  #### Why use this?
85
91
 
86
- - Integrating back-end to view
87
- - **directly** manipulation data or Model with a view
92
+ - Easy maintance innerHTML rather than literal string
88
93
  - Generate static html file
89
94
  - Full control of view. Such as filtering, encrypting the data before serve, or just like conditional and loop case
90
95
  - Almost no need to learn anything. Just need to learn how to render
@@ -106,14 +111,14 @@ It's just an Object! `wrap in () to create a statement or just assign to a var`
106
111
  h1: {
107
112
  text: "Hello World!",
108
113
  },
109
- }.render;
114
+ }._render;
110
115
  // <h1>Hello World!</h1>
111
116
  ```
112
117
 
113
118
  or use call method
114
119
 
115
120
  ```js
116
- render.call({
121
+ _render.call({
117
122
  // text property is same as innerText
118
123
  h1: {
119
124
  text: "Hello World!",
@@ -148,6 +153,16 @@ properties dom
148
153
  // <h1 class="heading" style="color: #DC1E1E">Hello World!</h1>
149
154
  ```
150
155
 
156
+ boolean attributes
157
+
158
+ use `Null` to indicate non-value attributes, do not confuse `Null` to `null`
159
+
160
+ ```js
161
+ {
162
+ button: { text: "Hello World!", disabled: Null },
163
+ }._render
164
+ ```
165
+
151
166
  innerText & innerHTML:
152
167
 
153
168
  ```js
@@ -213,6 +228,10 @@ Object can not use 2 keys with the same name
213
228
  renderOption({
214
229
  camelCase: false,
215
230
  once: false,
231
+ nodoctype: false,
232
+ ignoreTag: false,
233
+ prefixTag: false,
234
+ prefixAttr: false,
216
235
  });
217
236
  ```
218
237
 
@@ -220,6 +239,24 @@ set once to `true` to use option only for once,
220
239
  <br>
221
240
  <br>
222
241
 
242
+ set nodoctype to `true` to remove `<!doctype html>` in the beninging,
243
+ <br>
244
+ <br>
245
+
246
+ set ignoreTag to `true` to unused `tag` properties,
247
+ <br>
248
+ <br>
249
+
250
+ set prefixTag to `something` to add text before `tag`,
251
+ <br>
252
+ use `noprefix:true` to skip on specific object
253
+ <br>
254
+
255
+ set prefixAttr to `something` to add text before `attribute`,
256
+ <br>
257
+ use `nopAttr:true` to skip in specific object
258
+ <br>
259
+
223
260
  set `camelCase` `true` to convert **camelCase** properties to **kebab-case**
224
261
 
225
262
  make sure to set the option before rendering