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