neobiz 1.0.0 → 1.2.1

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 @@
1
+ <h1>Hello World!</h1>
@@ -0,0 +1,18 @@
1
+ /** @format */
2
+
3
+ //use object literal
4
+
5
+ import { render, outFile } from "../index.js";
6
+
7
+ console.log(
8
+ render({
9
+ h1: { text: "Hello World!" },
10
+ })
11
+ );
12
+
13
+ //output: <h1>Hello World!</h1>
14
+
15
+ // output static file
16
+ outFile("./basic.html", {
17
+ h1: { text: "Hello World!" },
18
+ });
@@ -0,0 +1,56 @@
1
+ /** @format */
2
+
3
+ import { render } from "../index.js";
4
+
5
+ const status = false;
6
+
7
+ // ternary operator
8
+
9
+ console.log(
10
+ render({
11
+ h1: status
12
+ ? { text: "Hello World!" }
13
+ : {
14
+ a: { href: "#", text: "You are offline!" },
15
+ },
16
+ })
17
+ //<h1><a href='#'>You are offline!</a></h1
18
+ );
19
+
20
+ // use IIFE
21
+
22
+ // IF
23
+ console.log(
24
+ render({
25
+ h1: (() => {
26
+ let result;
27
+ if (status) result = { text: "Hello World!" };
28
+ else
29
+ result = {
30
+ a: { href: "#", text: "You are offline!" },
31
+ };
32
+ return result;
33
+ })(),
34
+ })
35
+ //<h1><a href='#'>You are offline!</a></h1
36
+ );
37
+
38
+ // SWITCH
39
+ console.log(
40
+ render({
41
+ h1: (() => {
42
+ let result;
43
+ switch (status) {
44
+ case true:
45
+ result = { text: "Hello World!" };
46
+ break;
47
+ case false:
48
+ result = {
49
+ a: { href: "#", text: "You are offline!" },
50
+ };
51
+ }
52
+ return result;
53
+ })(),
54
+ })
55
+ //<h1><a href='#'>You are offline!</a></h1
56
+ );
@@ -0,0 +1,3 @@
1
+ /** @format */
2
+
3
+ export default (title) => ({ title: { text: title } });
@@ -0,0 +1,3 @@
1
+ /** @format */
2
+
3
+ import "./basic_syntax.v.js";
@@ -0,0 +1,53 @@
1
+ /** @format */
2
+
3
+ import { render, range } from "../index.js";
4
+
5
+ // use range @param= length, startFrom
6
+
7
+ console.log(
8
+ render({
9
+ ul: {
10
+ li: range(8, 1).map((item) => ({ text: "data-" + item })),
11
+ },
12
+ })
13
+ //<ul><li>data-1</li><li>data-2</li><li>data-3</li><li>data-4</li><li>data-5</li><li>data-6</li><li>data-7</li><li>data-8</li></ul>
14
+ );
15
+
16
+ // map
17
+ console.log(
18
+ render({
19
+ ul: {
20
+ li: ["grape", "banana", "apple"].map((text) => ({ text })),
21
+ },
22
+ })
23
+ //<ul><li>grape</li><li>banana</li><li>apple</li></ul>
24
+ );
25
+
26
+ // for
27
+ console.log(
28
+ render({
29
+ ul: {
30
+ li: (() => {
31
+ const result = [];
32
+ for (let i = 1; i < 9; i++) result.push({ text: "data-" + i });
33
+ return result;
34
+ })(),
35
+ },
36
+ })
37
+ //<ul><li>data-1</li><li>data-2</li><li>data-3</li><li>data-4</li><li>data-5</li><li>data-6</li><li>data-7</li><li>data-8</li></ul>
38
+ );
39
+
40
+ // while
41
+ console.log(
42
+ render({
43
+ ul: {
44
+ li: (() => {
45
+ const result = [];
46
+ let i = 0;
47
+ while (++i < 9) result.push({ text: "data-" + i });
48
+ return result;
49
+ })(),
50
+ },
51
+ })
52
+ //<ul><li>data-1</li><li>data-2</li><li>data-3</li><li>data-4</li><li>data-5</li><li>data-6</li><li>data-7</li><li>data-8</li></ul>
53
+ );
@@ -0,0 +1,13 @@
1
+ /** @format */
2
+
3
+ import { render } from "../index.js";
4
+
5
+ console.log(
6
+ render({
7
+ ul: {
8
+ li: [{ text: "one" }, { text: "two" }, { text: "3" }],
9
+ },
10
+ })
11
+ );
12
+
13
+ // <ul><li>one</li><li>two</li><li>3</li></ul>
@@ -1,12 +1,17 @@
1
1
  {
2
- "name": "test",
3
- "type": "module",
2
+ "name": "example",
4
3
  "version": "1.0.0",
5
- "description": "",
4
+ "type": "module",
5
+ "description": "example of neobiz.js cases",
6
6
  "main": "index.js",
7
7
  "scripts": {
8
8
  "test": "echo \"Error: no test specified\" && exit 1"
9
9
  },
10
+ "keywords": [
11
+ "neobiz.js",
12
+ "view",
13
+ "template"
14
+ ],
10
15
  "author": "",
11
16
  "license": "ISC"
12
17
  }
@@ -0,0 +1,11 @@
1
+ /** @format */
2
+
3
+ import { render, partial } from "../index.js";
4
+
5
+ console.log(
6
+ render({
7
+ head: (await partial("./exported.v.js"))("example page"),
8
+ h1: { text: "This is example" },
9
+ })
10
+ //<head><title>example page</title></head><h1>This is example</h1>
11
+ );
@@ -0,0 +1,17 @@
1
+ /** @format */
2
+
3
+ //use function, iife recommended :)
4
+
5
+ import { render } from "../index.js";
6
+
7
+ console.log(
8
+ // Ignore this
9
+ render(((user) => ({ h1: { text: `Hello, ${user}` } }))("Vins"))
10
+ //<h1>Hello, Vins</h1>
11
+ );
12
+
13
+ // or just use this below
14
+
15
+ const greeting = (user) => ({ h1: `Hello, ${user}` });
16
+
17
+ console.log(render(greeting("Vins")));
@@ -0,0 +1,20 @@
1
+ /** @format */
2
+
3
+ import { render } from "../index.js";
4
+
5
+ const template = (content) => ({
6
+ div: {
7
+ class: "main wrapper",
8
+ div: content,
9
+ },
10
+ });
11
+
12
+ console.log(
13
+ render(
14
+ template({
15
+ h1: { text: "Hello World!" },
16
+ })
17
+ )
18
+ );
19
+
20
+ //<div class='main wrapper'><div><h1>Hello World!</h1></div></div>
package/index.js CHANGED
@@ -1,3 +1,61 @@
1
1
  /** @format */
2
+ "use strict";
3
+ const path = require("path");
2
4
 
3
- module.exports = require("./simple.js");
5
+ function render(val = {}) {
6
+ let result = "";
7
+ Object.entries(val).forEach((e) => {
8
+ if (e[1].length) {
9
+ e[1].forEach((g) => {
10
+ result += render({ [e[0]]: g });
11
+ });
12
+ } else if (typeof e[1] == "object") {
13
+ e[0] = e[0].replace(" ", "");
14
+ result += `<${e[0]}`;
15
+ const temp = [];
16
+ let inn = "";
17
+ Object.entries(e[1]).forEach((k) => {
18
+ if (typeof k[1] == "string" && k[0] != "text")
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]}`;
22
+ else temp.push(k);
23
+ });
24
+ const stat = !["input", "link", "br", "hr"].includes(e[0]);
25
+ if (stat) result += ">";
26
+ result += inn;
27
+ for (let i of temp) result += render({ [i[0]]: i[1] });
28
+ if (stat) result += `</${e[0]}>`;
29
+ else result += "/>";
30
+ } else {
31
+ }
32
+ });
33
+ result = result.replace(/[\r\n\t]/gm, "");
34
+ result = result.replace(/\s{2,}/gm, " ");
35
+ return result;
36
+ }
37
+ function range(length, start = 0) {
38
+ return [...Array(length)].map(() => start++);
39
+ }
40
+
41
+ function outFile(source, data) {
42
+ const fs = require("fs");
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
+ module.exports = {
52
+ render,
53
+ range,
54
+ outFile,
55
+ partial: async (src) => {
56
+ const { default: i } = await import(
57
+ path.join("file:\\\\", process.cwd(), src)
58
+ );
59
+ return i;
60
+ },
61
+ };
package/minify.js CHANGED
@@ -2,9 +2,9 @@
2
2
  const fs = require("fs");
3
3
 
4
4
  fs.writeFileSync(
5
- "./simple.min.js",
5
+ "./neobiz.min.js",
6
6
  fs
7
- .readFileSync("./simple.js")
7
+ .readFileSync("./index.js")
8
8
  .toString()
9
9
  .replace(/[\r\n\t]/gm, "")
10
10
  .replace(/\s{2,}/gm, " ")
package/neobiz.min.js ADDED
@@ -0,0 +1 @@
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; },};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neobiz",
3
- "version": "1.0.0",
3
+ "version": "1.2.1",
4
4
  "description": "simple view engine yet powerful with javascript features",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/readme.md CHANGED
@@ -1,300 +1,268 @@
1
1
  <!-- @format -->
2
2
 
3
- # Documentation
3
+ # Documentation Neobiz.js
4
4
 
5
- ## NEOBIZ
5
+ > A simple view engine that has 100% JS features
6
6
 
7
- A simple view engine, minimalist yet powerful with **JavaScript** Features.
7
+ Neobiz.js is pure JS lang, transpile Object to HTML as string
8
8
 
9
- ```js
10
- import head from "./partials/head.v.js";
9
+ `read /example dir to understanding`
11
10
 
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
- ```
11
+ [this link to usage in express.js](https://www.npmjs.com/package/neobiz-express?activeTab=dependencies)
12
+
13
+ **Features**
34
14
 
35
- ### 1.0.0 Basic
15
+ | function | params | return-type | description |
16
+ | -------- | ---------------------------------- | ----------- | ------------------------------- |
17
+ | render | content:object | string | rendering to HTML |
18
+ | outFile | destination:string, content:object | | generate static HTML file |
19
+ | range | length:int, start:int | Array | shortcut for looping in a range |
20
+ | partial | source:string | AsyncFn | including other file |
36
21
 
37
- #### 1.1.0 Format
22
+ ## Basic syntax
38
23
 
39
- It's just _JS Object_!
24
+ It's just Object in js!
40
25
 
41
26
  ```js
42
27
  {
43
- tag: {
44
- //properties
28
+ // text property is same as innerHTML
29
+ h1: {
30
+ text: "Hello World!";
45
31
  }
46
32
  }
33
+ // <h1>Hello World!</h1>
47
34
  ```
48
35
 
49
- Then render to HTML `:example`:
36
+ properties dom
50
37
 
51
38
  ```js
52
- //use text property as innerHTML
53
39
  {
40
+ // text property is same as innerHTML
54
41
  h1: {
42
+ class:"heading",
55
43
  text: "Hello World!";
44
+ style:"color: #DC1E1E"
56
45
  }
57
46
  }
47
+ // <h1 class="heading" style="color: #DC1E1E">Hello World!</h1>
58
48
  ```
59
49
 
60
- ```html
61
- <h1>Hello World!</h1>
62
- ```
63
-
64
- #### 1.2.0 Why use js Object?
50
+ nested dom:
65
51
 
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
52
+ ```js
53
+ {
54
+ body: {
55
+ h1: {
56
+ text: "Hello World!";
57
+ }
58
+ }
59
+ }
60
+ ```
73
61
 
74
- ### 2.0.0 Render
62
+ siblings dom:
75
63
 
76
- there is 2 ways to outputing view.
64
+ There is a case like this:
77
65
 
78
- 1. String `Recomended to send as response server`
79
- 2. File `Static file serve / docs`
66
+ ```html
67
+ <li>orange</li>
68
+ <li>banana</li>
69
+ ```
80
70
 
81
- #### 2.1.0 render method
71
+ Object can not use 2 keys with same name, instead use this:
82
72
 
83
73
  ```js
84
- import { render } from "neobiz";
85
-
86
- return render({ p: { text: "This is a p" } });
74
+ // Don't do this
75
+ {
76
+ li:{text:"orange"},
77
+ li:{text:"banana"},
78
+ }
87
79
 
88
- //<p>This is a p</p>
80
+ // Do this
81
+ {
82
+ li:[
83
+ {text:"orange"},
84
+ {text:"banana"},
85
+ ]
86
+ }
89
87
  ```
90
88
 
91
- #### 2.2.0 outFile
92
-
93
- outFile([filepath],[object-view])
89
+ What if there is somethings in the middle of list?
94
90
 
95
- ```js
96
- import { outFile } from "neobiz";
97
-
98
- outFile("./index.html", { button: { text: "This is button" } });
91
+ ```html
92
+ <li>orange</li>
93
+ <p>
94
+ <span>This is in the middle</span>
95
+ </p>
96
+ <li>banana</li>
99
97
  ```
100
98
 
101
- #### 2.3.0 range
99
+ Can't use array? just use this:
102
100
 
103
- It's just bonus
104
-
105
- range([length],[start])
101
+ ```js
102
+ {
103
+ li:{text:"orange"},
104
+ p:{span:{text:"This is in the middle"}}
105
+ li:{text:"banana"},
106
+ }
107
+ ```
106
108
 
107
- ### 3.0.0 Data
109
+ ## Pass Value
108
110
 
109
- #### 3.1.0 use variable
111
+ use function
110
112
 
111
113
  ```js
112
- //import neobiz
113
- const msg = "Welcome page!";
114
+ import { render } from "../index.js";
114
115
 
115
- render({ h1: { text: msg } });
116
- render({ h1: { text: `Message: ${msg}` } });
116
+ console.log(render(((user) => ({ h1: { text: `Hello, ${user}` } }))("Vins")));
117
117
  ```
118
118
 
119
- ### 4.0.0 Syntax
120
-
121
- #### 4.1.0 props
119
+ or
122
120
 
123
121
  ```js
124
- {h1:{text:"example",class:"heading1",id:"mainHead",style:"color:red;"}}
125
-
126
- //to
122
+ const greeting = (user) => ({ h1: `Hello, ${user}` });
127
123
 
128
- <h1 class="heading1" id="mainHead" style="color:red;">example</h1>
124
+ console.log(render(greeting("Vins")));
129
125
  ```
130
126
 
131
- #### 4.2.0 conflict key
127
+ ## Control Flow
132
128
 
133
- sometimes this case will happened:
129
+ ternary:
134
130
 
135
- ```html
136
- <li>this is 1st li</li>
137
- <p>this is middle content</p>
138
- <li>this is 2nd li</li>
131
+ ```js
132
+ {
133
+ h1: status
134
+ ? { text: "Hello World!" }
135
+ : {
136
+ a: { href: "#", text: "You are offline!" },
137
+ },
138
+ }
139
139
  ```
140
140
 
141
- don't do this:
142
- `the 2nd li will rewrite 1st li`
141
+ IIFE if-else
143
142
 
144
143
  ```js
145
144
  {
146
- li:{text:"this is 1st li"},
147
- p:{text:"this is middle content"},
148
- li:{text:"this is 2nd li"}
145
+ h1: (() => {
146
+ let result;
147
+ if (status) result = { text: "Hello World!" };
148
+ else
149
+ result = {
150
+ a: { href: "#", text: "You are offline!" },
151
+ };
152
+ return result;
153
+ })(),
149
154
  }
155
+ ```
150
156
 
151
- // just use this instead
157
+ IIFE switch-case
152
158
 
159
+ ```js
153
160
  {
154
- li:{text:"this is 1st li"},
155
- p:{text:"this is middle content"},
156
- "li ":{text:"this is 2nd li"}
161
+ h1: (() => {
162
+ let result;
163
+ switch (status) {
164
+ case true:
165
+ result = { text: "Hello World!" };
166
+ break;
167
+ case false:
168
+ result = {
169
+ a: { href: "#", text: "You are offline!" },
170
+ };
171
+ }
172
+ return result;
173
+ })(),
157
174
  }
158
175
  ```
159
176
 
160
- #### 4.3.0 passing value
177
+ ## Loop & array manipulation
161
178
 
162
- just use function expression
163
-
164
- for example in express.js response:
165
-
166
- `express server`
179
+ range & map:
167
180
 
168
181
  ```js
169
- import profile from "./Views/profile.v.js";
170
- import { render } from "neobiz";
182
+ import { render, range } from "../index.js";
171
183
 
172
- res.send(render(profile("Dimas")));
173
- ```
174
-
175
- `profile.v.js`
176
-
177
- ```js
178
- export default (username) => ({ h1: { text: `Welcome, ${username}` } });
184
+ {
185
+ ul: {
186
+ li: range(8, 1).map((item) => ({ text: "data-" + item })),
187
+ },
188
+ }
179
189
  ```
180
190
 
181
- #### 4.4.0 Structural concepts
182
-
183
- ##### 4.4.1 partial
191
+ map
184
192
 
185
193
  ```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
+ ul: {
196
+ li: ["grape", "banana", "apple"].map((text) => ({ text })),
197
+ },
198
+ }
194
199
  ```
195
200
 
196
- ##### 4.4.2 template
197
-
198
- `template.v.js`
201
+ for
199
202
 
200
203
  ```js
201
- export default (contents, ...args) => ({
202
- html: {
203
- head: {
204
- /*...*/
205
- },
206
- body: {
207
- id: "main",
208
- div: contents,
204
+ {
205
+ ul: {
206
+ li: (() => {
207
+ const result = [];
208
+ for (let i = 1; i < 9; i++) result.push({ text: "data-" + i });
209
+ return result;
210
+ })(),
209
211
  },
210
- },
211
- });
212
+ }
212
213
  ```
213
214
 
214
- `contents.v.js`
215
+ while
215
216
 
216
217
  ```js
217
- import template from "./template.v.js";
218
-
219
- export default (...args) =>
220
- template(
221
- {
222
- h1: "this is heading",
223
- //some contents
218
+ {
219
+ ul: {
220
+ li: (() => {
221
+ const result = [];
222
+ let i = 0;
223
+ while (++i < 9) result.push({ text: "data-" + i });
224
+ return result;
225
+ })(),
224
226
  },
225
- ...args
226
- );
227
+ }
227
228
  ```
228
229
 
229
- #### 4.5.0 Control flow
230
+ ## partial & templating
230
231
 
231
- just use IIFE
232
+ ### partial
232
233
 
233
- ##### 4.5.1 IF else
234
-
235
- `Ternary operator`
234
+ make sure to export as function & default
236
235
 
237
236
  ```js
238
- const status = false;
237
+ import { render, partial } from "../index.js";
239
238
 
240
- const result = {
241
- h1: status
242
- ? { text: "already active" }
243
- : { button: { onclick: "...", text: "activate" } },
244
- };
239
+ {
240
+ head: (await partial("./exported.v.js"))("example page"),
241
+ h1: { text: "This is example" },
242
+ }
245
243
  ```
246
244
 
247
- `IIFE`
245
+ `/exported.v.js`
248
246
 
249
247
  ```js
250
- const status = false;
251
-
252
- const result = {
253
- h1: status
254
- ? { text: "already active" }
255
- : { button: { onclick: "...", text: "activate" } },
256
- };
248
+ export default (title) => ({ title: { text: title } });
257
249
  ```
258
250
 
259
- ##### 4.5.2 for loop
251
+ ### templating
260
252
 
261
- maps in range
253
+ this example use single file usage. for modular usage leave to you
262
254
 
263
255
  ```js
264
- import { range } from "neobiz";
256
+ import { render } from "../index.js";
265
257
 
266
- return {
267
- ul: {
268
- li: range(8).map((item) => ({ text: item })),
258
+ const template = (content) => ({
259
+ div: {
260
+ class: "main wrapper",
261
+ div: content,
269
262
  },
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
263
+ });
286
264
 
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
- };
265
+ template({
266
+ h1: { text: "Hello World!" },
267
+ });
296
268
  ```
297
-
298
- ##### 4.5.3 while loop
299
-
300
- just same as `4.5.2` section
package/simple.js DELETED
@@ -1,63 +0,0 @@
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 DELETED
@@ -1 +0,0 @@
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 DELETED
@@ -1,8 +0,0 @@
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
- });
@@ -1,16 +0,0 @@
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
- }
package/test/s.js DELETED
@@ -1,3 +0,0 @@
1
- /** @format */
2
-
3
- export default (data) => ({ text: `hello ${data}!` });
package/test/temp.html DELETED
@@ -1 +0,0 @@
1
- <h1>hello Dimas!</h1>