neobiz 1.3.1 → 1.3.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.
package/index.js CHANGED
@@ -61,12 +61,107 @@ function outFile(source, data) {
61
61
  console.log(`Output file: ${source}`);
62
62
  })();
63
63
  }
64
+ function fromStr(letter, prefix = 0) {
65
+ if (letter == "") return {};
64
66
 
67
+ letter = letter.replace(/[\r\n\t]/gm, "").replace(/>\s{2,}</gm, "><");
68
+ const result = {};
69
+
70
+ if (/<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)$/.exec(letter)?.[1]) {
71
+ result.tag = /<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)$/.exec(letter)[1];
72
+
73
+ result.tag = result.tag + Array(prefix).fill(" ").join("");
74
+
75
+ result.head = /<([a-zA-Z0-9]{1,}).*?>/.exec(letter)[0];
76
+
77
+ result.inner = letter
78
+ .replace(result.head, "")
79
+ .split("")
80
+ .reverse()
81
+ .join("")
82
+ .replace(
83
+ `</${result.tag.replace(Array(prefix).fill(" ").join(""), "")}>`
84
+ .split("")
85
+ .reverse()
86
+ .join(""),
87
+ ""
88
+ )
89
+ .split("")
90
+ .reverse()
91
+ .join("");
92
+ } else {
93
+ result.tag = /<([a-zA-Z0-9]{1,}).*?\/>/.exec(letter)[1];
94
+
95
+ result.tag = result.tag + Array(prefix).fill(" ").join("");
96
+
97
+ result.head = /<([a-zA-Z0-9]{1,}).*?>/.exec(letter)[0];
98
+ result.inner = "";
99
+ }
100
+ result.props = result.head.match(/[a-zA-Z0-9]{1,}=(["']).*?\1/g);
101
+
102
+ let temp = { [result.tag]: {} };
103
+ if (result.props)
104
+ result.attr = result.props.forEach((e) => {
105
+ let y = e.replace(/.*=(['"])/, "");
106
+ y = y.substring(0, y.length - 1);
107
+ let w = e.substring(0, e.indexOf("="));
108
+ temp[result.tag][w] = y;
109
+ });
110
+
111
+ let s = [];
112
+ let ttexr = result.inner;
113
+ while (
114
+ /<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)/.exec(ttexr) ||
115
+ /<([a-zA-Z0-9]{1,}).*?\/>/.exec(ttexr)
116
+ ) {
117
+ let ss;
118
+ if (/<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)/.exec(ttexr)) {
119
+ ss = /<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)/.exec(ttexr)[0];
120
+ const h = /<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)$/.exec(ss)[1];
121
+ const sss = ttexr.slice(ttexr.indexOf(ss));
122
+ const f = {
123
+ a: sss.replace("<" + h, "").indexOf(`</${h}>`),
124
+ b: sss.replace("<" + h, "").indexOf(`<${h}`),
125
+ };
126
+
127
+ ss = f.a > f.b && f.b > -1 ? sss : ss;
128
+ } else {
129
+ ss = /<([a-zA-Z0-9]{1,}).*?\/>/.exec(ttexr)[0];
130
+ }
131
+ ttexr = ttexr.replace(ss, "");
132
+ s.push(ss);
133
+ }
134
+ s.sort((a, b) => {
135
+ const r = { a: result.inner.indexOf(a), b: result.inner.indexOf(b) };
136
+ return r.a > r.b ? 1 : r.a < r.b ? -1 : 0;
137
+ });
138
+ result.status = s;
139
+ result.puretext = ttexr ? ttexr : ttexr + " ";
140
+ // result.temp = temp;
141
+ if (result.puretext != " ") temp[result.tag].text = result.puretext;
142
+ if (result.status) {
143
+ const ss = new Set();
144
+ const current = {};
145
+ s.forEach((e) => {
146
+ const hh = /<[a-zA-Z0-9]{1,}\s?/.exec(e)[0].substring(1);
147
+ if (ss.has(hh)) {
148
+ current[hh] = current[hh] + 1;
149
+ } else {
150
+ current[hh] = 0;
151
+ ss.add(hh);
152
+ }
153
+ temp = {
154
+ [result.tag]: { ...temp[result.tag], ...fromStr(e, current[hh]) },
155
+ };
156
+ });
157
+ }
158
+ return temp;
159
+ }
65
160
  module.exports = {
66
161
  render,
67
162
  range,
68
163
  outFile,
69
- fromStr: require("./str.h.js"),
164
+ fromStr,
70
165
  partial: async (src) => {
71
166
  const { default: i } = await import(
72
167
  path.join("file:\\\\", process.cwd(), src)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "neobiz",
3
- "version": "1.3.1",
4
- "description": "A simple view engine powered by JS",
3
+ "version": "1.3.5",
4
+ "description": "A simple view engine with JS features",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
package/readme.md CHANGED
@@ -1,10 +1,14 @@
1
1
  <!-- @format -->
2
2
 
3
+ <!-- @format -->
4
+
3
5
  # Documentation Neobiz.js
4
6
 
7
+ <img src="https://raw.githubusercontent.com/harakun24/assets-neobiz/main/icon.png" style="width:150px" />
8
+
5
9
  > A simple view engine that has 100% JS features
6
10
 
7
- [[Github]](https://github.com/harakun24/neobiz.js)
11
+ [[Github example]](https://github.com/harakun24/assets-neobiz)
8
12
  Neobiz.js is pure in JS lang, transform Object into HTML
9
13
 
10
14
  `read /example dir to understanding`
@@ -44,6 +48,20 @@ It's just an Object!
44
48
  // <h1>Hello World!</h1>
45
49
  ```
46
50
 
51
+ Comments:
52
+
53
+ ```js
54
+ {
55
+ // this is comment
56
+ /*
57
+ this is multi line
58
+ */
59
+ h1: {
60
+ text: "This is heading";
61
+ }
62
+ }
63
+ ```
64
+
47
65
  properties dom
48
66
 
49
67
  ```js
@@ -1,23 +0,0 @@
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
- });
19
-
20
- // properties
21
- render({
22
- h1: { class: "heading", id: "main", text: "Hello World!" },
23
- });
@@ -1,56 +0,0 @@
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
- );
@@ -1,3 +0,0 @@
1
- /** @format */
2
-
3
- export default (title) => ({ title: { text: title } });
@@ -1,27 +0,0 @@
1
- /** @format */
2
-
3
- import { outFile, fromStr } from "../index.js";
4
-
5
- const temp = `
6
- <div id="first">
7
- <ul id="outer">
8
- <li>1</li>
9
- <li>2</li>
10
- </ul>
11
- <div id="inner-div">
12
- <ul id="inner-ul">
13
- <li>3</li>
14
- <li>4</li>
15
- </ul>
16
- </div>
17
- </div>
18
- `;
19
-
20
- const { div } = fromStr(temp);
21
-
22
- div.ul.li.text = "data-1";
23
- div.div.ul.class = "inner";
24
-
25
- outFile("./temp.html", { div });
26
-
27
- console.dir({ div }, { depth: null });
package/example/index.js DELETED
@@ -1,3 +0,0 @@
1
- /** @format */
2
-
3
- import "./basic_syntax.v.js";
@@ -1,15 +0,0 @@
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
- });
@@ -1,16 +0,0 @@
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
- });
@@ -1,53 +0,0 @@
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
- );
@@ -1,13 +0,0 @@
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,17 +0,0 @@
1
- {
2
- "name": "example",
3
- "version": "1.0.0",
4
- "type": "module",
5
- "description": "example of neobiz.js cases",
6
- "main": "index.js",
7
- "scripts": {
8
- "test": "echo \"Error: no test specified\" && exit 1"
9
- },
10
- "keywords": [
11
- "neobiz.js",
12
- "view",
13
- "template"
14
- ],
15
- "author": "",
16
- "license": "ISC"
17
- }
@@ -1,11 +0,0 @@
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
- );
@@ -1,17 +0,0 @@
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")));
package/example/temp.html DELETED
@@ -1 +0,0 @@
1
- <div id='first'><ul id='outer'><li>data-1</li><li>2</li></ul><div id='inner-div'><ul id='inner-ul' class='inner'><li>3</li><li>4</li></ul></div></div>
@@ -1,20 +0,0 @@
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/str.h.js DELETED
@@ -1,78 +0,0 @@
1
- /** @format */
2
-
3
- function fromStr(letter, prefix = 0) {
4
- if (letter == "") return;
5
- letter = letter.replace(/[\r\n\t]/gm, "").replace(/>\s{2,}</gm, "><");
6
- const result = {};
7
-
8
- result.tag = /<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)$/.exec(letter)[1];
9
-
10
- result.tag = result.tag + Array(prefix).fill(" ").join("");
11
-
12
- result.head = /<([a-zA-Z0-9]{1,}).*?>/.exec(letter)[0];
13
-
14
- result.props = result.head.match(/[a-zA-Z0-9]{1,}=(["']).*?\1/g);
15
-
16
- result.inner = letter
17
- .replace(result.head, "")
18
- .split("")
19
- .reverse()
20
- .join("")
21
- .replace(
22
- `</${result.tag.replace(Array(prefix).fill(" ").join(""), "")}>`
23
- .split("")
24
- .reverse()
25
- .join(""),
26
- ""
27
- )
28
- .split("")
29
- .reverse()
30
- .join("");
31
- let temp = { [result.tag]: {} };
32
- if (result.props)
33
- result.attr = result.props.forEach((e) => {
34
- let y = e.replace(/.*=(['"])/, "");
35
- y = y.substring(0, y.length - 1);
36
- let w = e.substring(0, e.indexOf("="));
37
- temp[result.tag][w] = y;
38
- });
39
-
40
- let s = [];
41
- let ttexr = result.inner;
42
-
43
- while (/<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)/.exec(ttexr)) {
44
- let ss = /<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)/.exec(ttexr)[0];
45
- const h = /<([a-zA-Z0-9]{1,}).*?>.*?(<\/\1>)$/.exec(ss)[1];
46
- const sss = ttexr.slice(ttexr.indexOf(ss));
47
- const f = {
48
- a: sss.replace("<" + h, "").indexOf(`</${h}>`),
49
- b: sss.replace("<" + h, "").indexOf(`<${h}`),
50
- };
51
-
52
- ss = f.a > f.b ? sss : ss;
53
- ttexr = ttexr.replace(ss, "");
54
- s.push(ss);
55
- }
56
- result.status = s;
57
- result.puretext = ttexr ? ttexr : ttexr + " ";
58
- // result.temp = temp;
59
- if (result.puretext != " ") temp[result.tag].text = result.puretext;
60
- if (result.status) {
61
- const ss = new Set();
62
- const current = {};
63
- s.forEach((e) => {
64
- const hh = /<[a-zA-Z0-9]{1,}\s?/.exec(e)[0].substring(1);
65
- if (ss.has(hh)) {
66
- current[hh] = current[hh] + 1;
67
- } else {
68
- current[hh] = 0;
69
- ss.add(hh);
70
- }
71
- temp = {
72
- [result.tag]: { ...temp[result.tag], ...fromStr(e, current[hh]) },
73
- };
74
- });
75
- }
76
- return temp;
77
- }
78
- module.exports = fromStr;