aprog 1.0.0 → 1.1.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/README.md CHANGED
@@ -1,2 +1,151 @@
1
- # aprog-js
1
+ # aprog
2
+
2
3
  Допоміжна бібліотека js
4
+
5
+ *require for dev*
6
+
7
+ ### Installation
8
+
9
+ ```shell
10
+ npm install aprog --save-dev
11
+ ```
12
+
13
+ or
14
+
15
+ ```shell
16
+ npm i aprog -D
17
+ ```
18
+
19
+ ### Basic Usage
20
+
21
+ Підключення router:
22
+
23
+ ```shell
24
+ import Categories from "./pages/Categories";
25
+ import Access from "./pages/Access";
26
+ import Unauthorized from "./pages/Unauthorized";
27
+
28
+ const routes = [
29
+ {
30
+ path: "/categories",
31
+ component: Categories,
32
+ },
33
+ {
34
+ path: "/access/denied",
35
+ component: Access,
36
+ },
37
+ {
38
+ path: "/unauthorized",
39
+ component: Unauthorized,
40
+ }
41
+ ];
42
+
43
+ document.addEventListener("DOMContentLoaded", async function() {
44
+ // router
45
+ const body = document.body;
46
+ await router({ routes, body, "Page Not Found" });
47
+ });
48
+
49
+ ```
50
+
51
+ Створення Pages:
52
+
53
+ ```shell
54
+
55
+ const NamePage = () => {
56
+ return div({
57
+ class: "w-full h-screen flex flex-col items-center justify-center text-3xl",
58
+ value: [
59
+ div({
60
+ class: "text-red font-bold text-5xl",
61
+ value: "Блок №1"
62
+ }),
63
+ div({value: "Блок №2"})
64
+ ]
65
+ });
66
+ }
67
+
68
+ export default NamePage;
69
+
70
+ ```
71
+
72
+ Приклад використання методів формування HTML елементів:
73
+
74
+ ```shell
75
+
76
+ const elDiv = div({
77
+ id: "id-елементу",
78
+ class: "class-елементу",
79
+ style: {
80
+ width: "30px",
81
+ height: "40px"
82
+ },
83
+ onClick: () => {
84
+ console.log("Приклад роботи onClick");
85
+ },
86
+ value: "Приклад блоку div"
87
+ });
88
+
89
+ document.body.appendChild(elDiv);
90
+
91
+ ```
92
+
93
+ Приклад використання методів дебагу:
94
+
95
+ ```shell
96
+
97
+ const int = 0;
98
+ const array = [1,2,3,4];
99
+ const boolean = true;
100
+
101
+ // виводить всі змінні в одній групі вкладок
102
+ dump(int, array, boolean);
103
+
104
+ // or
105
+
106
+ // виводить всі змінні в одній групі вкладок та зупиняє подальше виконання скрипту
107
+ dd(int, array, boolean);
108
+
109
+ ```
110
+
111
+ Загальний список методів:
112
+
113
+ - *dump(...args), dd(...args)*
114
+ - *redirect(url, { newTab: bool, replace: bool })*
115
+ - *encrypt(str), decrypt(encryptedStr)*
116
+
117
+
118
+ - *div, span, button, a, img, meta, label, input, select, option, options, form, hr, textarea, table, thead, tbody, tr, th, td, pre*
119
+ - *_get, GUID, apState, cookie, date, pause, apFetch, chars, elementToObject, copyText, scrollToTop, scrollToBottom, firstKey, checkArrays, ucfirst, deepEqual, nodeListToObject*
120
+ - *isEmpty, isNull, isFloat, isNumeric, isObject, isArray, isNumber, isString, isPromise, isNull, isFloat, isNumeric, isObject*
121
+
122
+
123
+ ### Info
124
+
125
+ - З часом будуть додаватися можливості створення додаткових інструментів
126
+
127
+
128
+ ### License
129
+ MIT License
130
+
131
+ Copyright (c) 2025 AlexProger
132
+
133
+ Permission is hereby granted, free of charge, to any person obtaining a copy
134
+ of this software and associated documentation files (the "Software"), to deal
135
+ in the Software without restriction, including without limitation the rights
136
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
137
+ copies of the Software, and to permit persons to whom the Software is
138
+ furnished to do so, subject to the following conditions:
139
+
140
+ The above copyright notice and this permission notice shall be included in all
141
+ copies or substantial portions of the Software.
142
+
143
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
144
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
145
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
146
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
147
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
148
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
149
+ SOFTWARE.
150
+
151
+ *© AlexProger 2025*
package/index.js CHANGED
@@ -6,4 +6,5 @@ export {
6
6
  } from './src/aprog.js';
7
7
  export { dump, dd } from './src/debugger.js';
8
8
  export { redirect } from './src/redirect.js';
9
+ export { router } from './src/router.js';
9
10
  export { encrypt, decrypt } from './src/shifrator.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aprog",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Допоміжна бібліотека js",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,32 @@
1
+ import {div} from "./aprog.js";
2
+
3
+ const NotFound = (message = "Page Not Found") => {
4
+ return div({
5
+ style: style,
6
+ value: [
7
+ div({
8
+ style: style2,
9
+ value: "404"
10
+ }),
11
+ div({value: message})
12
+ ]
13
+ });
14
+ }
15
+
16
+ const style = {
17
+ width: "100%",
18
+ height: "100vh",
19
+ display: "flex",
20
+ flexDirection: "column",
21
+ alignItems: "center",
22
+ justifyContent: "center",
23
+ fontSize: "1.875rem"
24
+ };
25
+
26
+ const style2 = {
27
+ fontSize: "3rem",
28
+ fontWeight: "bold",
29
+ color: "#ff2800"
30
+ }
31
+
32
+ export default NotFound;
package/src/router.js ADDED
@@ -0,0 +1,28 @@
1
+ import NotFound from "NotFound";
2
+
3
+ const router = async ({ routes, main, message = "Page Not Found" }) => {
4
+ const renderRoute = async () => {
5
+ const routeComponent = await useRoutes(routes, message);
6
+ main.innerHTML = "";
7
+ if (routeComponent) {
8
+ main.appendChild(routeComponent);
9
+ }
10
+ }
11
+ window.addEventListener('popstate', renderRoute);
12
+ await renderRoute();
13
+ }
14
+
15
+
16
+ const navigateTo = (path) => {
17
+ window.history.pushState("", "", path);
18
+ }
19
+
20
+
21
+ const useRoutes = async (routes, message) => {
22
+ const path = window.location.pathname;
23
+ const matchingRoute = routes.find(route => route.path === path);
24
+ return matchingRoute ? await matchingRoute.component() : NotFound(message);
25
+ }
26
+
27
+
28
+ export { router, navigateTo };