neobiz 1.2.4 → 1.2.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.
@@ -0,0 +1,16 @@
1
+ /** @format */
2
+
3
+ import { outFile } from "../index.js";
4
+
5
+ outFile("./temp.html", {
6
+ button: { onclick: "sayHi(this)", id: "example" },
7
+ script: {
8
+ html: function () {
9
+ document.getElementById("example").innerText = "click me!";
10
+
11
+ function sayHi(el) {
12
+ el.innerText = "hi!";
13
+ }
14
+ },
15
+ },
16
+ });
package/index.js CHANGED
@@ -19,14 +19,23 @@ function render(val = {}) {
19
19
  result += ` ${k[0]}='${k[1]}'`;
20
20
  // else if (typeof k[1] == "function") result += ` ${k[0]}='${k[1] + ""}'`;
21
21
  else if (k[0] == "text")
22
- inn = `${k[1]
23
- .replace(/&/g, "&")
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]}`;
29
- else temp.push(k);
22
+ inn = `${
23
+ typeof k[1] == "string"
24
+ ? k[1]
25
+ .replace(/&/g, "&amp;")
26
+ .replace(/</g, "&lt;")
27
+ .replace(/>/g, "&gt;")
28
+ .replace(/"/g, "&quot;")
29
+ .replace(/'/g, "&#39;")
30
+ : k[1].toString()
31
+ }`;
32
+ else if (k[0] == "html") {
33
+ inn = `${
34
+ typeof k[1] != "function" ? k[1] : (k[1] + "").replace(/.*{/, "")
35
+ }`;
36
+ inn =
37
+ typeof k[1] == "string" ? inn : inn.substring(0, inn.length - 1);
38
+ } else temp.push(k);
30
39
  });
31
40
  const stat = !["input", "link", "br", "hr"].includes(e[0]);
32
41
  if (stat) result += ">";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neobiz",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
4
4
  "description": "simple view engine yet powerful with javascript features",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -8,7 +8,10 @@
8
8
  },
9
9
  "keywords": [
10
10
  "view engine",
11
- "template engine",
11
+ "template",
12
+ "dom",
13
+ "html",
14
+ "",
12
15
  "view"
13
16
  ],
14
17
  "license": "ISC"
package/readme.md CHANGED
@@ -4,14 +4,14 @@
4
4
 
5
5
  > A simple view engine that has 100% JS features
6
6
 
7
- [Github](https://www.npmjs.com/package/neobiz-express?activeTab=dependencies)
7
+ [[Github]](https://github.com/harakun24/neobiz.js)
8
8
  Neobiz.js is pure in JS lang, transform Object into HTML
9
9
 
10
10
  `read /example dir to understanding`
11
11
 
12
- [this link to usage in express.js](https://www.npmjs.com/package/neobiz-express?activeTab=dependencies)
12
+ [link to usage in express.js](https://www.npmjs.com/package/neobiz-express?activeTab=dependencies)
13
13
 
14
- **Features**
14
+ **Function**
15
15
 
16
16
  | function | params | return-type | description |
17
17
  | -------- | ---------------------------------- | ----------- | ------------------------------- |
@@ -22,10 +22,10 @@ Neobiz.js is pure in JS lang, transform Object into HTML
22
22
 
23
23
  #### Why use this?
24
24
 
25
- - One lang for all, back end - view - browser script all js!
26
- - **directly** interact data or Model with a view
25
+ - Integrating back-end to view
26
+ - **directly** manipulation data or Model with a view
27
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
28
+ - Full control of view. Such as filtering, encrypting the data before serve, or just like conditional and loop case
29
29
  - Almost no need to learn anything. Just need to learn how to render
30
30
  - Limitless potential, because it's just js. Almost all library should be compatible
31
31
 
@@ -35,7 +35,7 @@ It's just an Object!
35
35
 
36
36
  ```js
37
37
  {
38
- // text property is same as innerHTML
38
+ // text property is same as innerText
39
39
  h1: {
40
40
  text: "Hello World!",
41
41
  }
@@ -77,6 +77,17 @@ nested dom:
77
77
  }
78
78
  ```
79
79
 
80
+ expression & operator
81
+
82
+ ```js
83
+ {
84
+ span: [
85
+ { text: 24 + 12 / 6 },
86
+ { text: !false },
87
+ ],
88
+ }
89
+ ```
90
+
80
91
  siblings dom:
81
92
 
82
93
  There is a case like this:
@@ -86,7 +97,7 @@ There is a case like this:
86
97
  <li>banana</li>
87
98
  ```
88
99
 
89
- Object can not use 2 keys with the same name, instead use this:
100
+ Object can not use 2 keys with the same name
90
101
 
91
102
  ```js
92
103
  // Don't do this
@@ -127,6 +138,56 @@ Can't use array? just use this:
127
138
  }
128
139
  ```
129
140
 
141
+ ### Components
142
+
143
+ ```js
144
+ import header from "./header.v.js"; //function type
145
+ import footer from "./footer.v.js"; //object type
146
+
147
+ render({
148
+ div: header({ user: "dim24" }),
149
+ p: { text: "this is text" },
150
+ div: footer,
151
+ });
152
+ ```
153
+
154
+ header.v.js
155
+
156
+ ```js
157
+ export default ({ user }) => ({ h1: { text: `Hi, ${user}` } });
158
+ ```
159
+
160
+ footer.v.js
161
+
162
+ ```js
163
+ export default {
164
+ script: { src: "/assets/js/main.js" },
165
+ span: { text: "this is footer" },
166
+ };
167
+ ```
168
+
169
+ ### Interacting with DOM
170
+
171
+ use `script` to interact with browser with **html** property
172
+
173
+ wrap the script with a function, or use string
174
+
175
+ ```js
176
+ {
177
+ button:{onclick:"sayHi(this)",id:"hi-button"},
178
+ script:{
179
+ html:()=>{
180
+ document.getElementById("hi-button").innerText="Click me!";
181
+
182
+ function sayHi(el){
183
+ el.innerText="Hi!";
184
+ }
185
+ }
186
+ }
187
+ }
188
+
189
+ ```
190
+
130
191
  ## Pass Value
131
192
 
132
193
  use function
package/minify.js DELETED
@@ -1,11 +0,0 @@
1
- /** @format */
2
- const fs = require("fs");
3
-
4
- fs.writeFileSync(
5
- "./neobiz.min.js",
6
- fs
7
- .readFileSync("./index.js")
8
- .toString()
9
- .replace(/[\r\n\t]/gm, "")
10
- .replace(/\s{2,}/gm, " ")
11
- );
package/neobiz.min.js DELETED
@@ -1 +0,0 @@
1
- /** @format */"use strict";const path = require("path");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"); (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}`); })();}module.exports = { render, range, outFile, partial: async (src) => { console.log(path.join("file:\\\\", process.cwd(), src)); const { default: i } = await import( path.join("file:\\\\", process.cwd(), src) ); return i; },};