aprog 1.6.1 → 1.6.2
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 +3 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/src/aprog.js +44 -84
- package/src/paginate.js +1 -1
- package/src/redirect.js +1 -1
- package/src/router.js +22 -14
package/README.md
CHANGED
|
@@ -151,7 +151,9 @@ onInput: (event) => {
|
|
|
151
151
|
- *_get, _getAll, GUID, apState, date, pause, apFetch, chars, elementToObject, copyText, scrollToTop, scrollToBottom, firstKey, checkArrays, ucfirst, deepEqual, nodeListToObject*
|
|
152
152
|
- *isEmpty, isNull, isFloat, isNumeric, isObject, isArray, isNumber, isString, isPromise, isNull, isFloat, isNumeric, isObject*
|
|
153
153
|
|
|
154
|
-
- *router({ routes, main
|
|
154
|
+
- *router({ routes, main })*
|
|
155
|
+
|
|
156
|
+
- *navi("/path", {data: "Можливість передачі даних між сторінками"})*
|
|
155
157
|
|
|
156
158
|
- *gemini(message)*
|
|
157
159
|
|
package/index.js
CHANGED
|
@@ -7,7 +7,7 @@ export {
|
|
|
7
7
|
} from './src/aprog.js';
|
|
8
8
|
export { dump, dd } from './src/debugger.js';
|
|
9
9
|
export { redirect, reload } from './src/redirect.js';
|
|
10
|
-
export { router, navigateTo } from './src/router.js';
|
|
10
|
+
export { router, navigateTo, navi } from './src/router.js';
|
|
11
11
|
export { encrypt, decrypt } from './src/shifrator.js';
|
|
12
12
|
export { gemini } from './src/OpenAI.js';
|
|
13
13
|
export { mathInput } from './src/math.js';
|
package/package.json
CHANGED
package/src/aprog.js
CHANGED
|
@@ -13,8 +13,7 @@ export const pause = (variable) => {
|
|
|
13
13
|
checkVariable();
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
|
-
}
|
|
17
|
-
|
|
16
|
+
};
|
|
18
17
|
|
|
19
18
|
export const date = (format, timestamp = Date.now()) => {
|
|
20
19
|
const date = new Date(timestamp);
|
|
@@ -29,8 +28,7 @@ export const date = (format, timestamp = Date.now()) => {
|
|
|
29
28
|
};
|
|
30
29
|
|
|
31
30
|
return format.replace(/[YmdHis]/g, match => map[match]);
|
|
32
|
-
}
|
|
33
|
-
|
|
31
|
+
};
|
|
34
32
|
|
|
35
33
|
export const chars = (word) => {
|
|
36
34
|
const cyrillicToLatin = {
|
|
@@ -45,50 +43,41 @@ export const chars = (word) => {
|
|
|
45
43
|
'Ь': '', 'ь': '', 'Ъ': '', 'ъ': '', 'Э': 'E', 'э': 'e', 'Ы': 'Y', 'ы': 'y'
|
|
46
44
|
};
|
|
47
45
|
return word.split('').map(char => cyrillicToLatin[char] || char).join('');
|
|
48
|
-
}
|
|
49
|
-
|
|
46
|
+
};
|
|
50
47
|
|
|
51
48
|
// Validates
|
|
52
49
|
export const isArray = (value) => {
|
|
53
50
|
return Object.prototype.toString.call(value) === '[object Array]';
|
|
54
|
-
}
|
|
55
|
-
|
|
51
|
+
};
|
|
56
52
|
|
|
57
53
|
export const isObject = (value) => {
|
|
58
54
|
return Object.prototype.toString.call(value) === '[object Object]';
|
|
59
|
-
}
|
|
60
|
-
|
|
55
|
+
};
|
|
61
56
|
|
|
62
57
|
export const isPromise = (value) => {
|
|
63
58
|
return Object.prototype.toString.call(value) === '[object Promise]' ||
|
|
64
59
|
(typeof value === 'object' && value !== null && typeof value.then === 'function' && typeof value.catch === 'function');
|
|
65
|
-
}
|
|
66
|
-
|
|
60
|
+
};
|
|
67
61
|
|
|
68
62
|
export const isNumber = (value) => {
|
|
69
63
|
return typeof value === 'number' && !Number.isNaN(value);
|
|
70
|
-
}
|
|
71
|
-
|
|
64
|
+
};
|
|
72
65
|
|
|
73
66
|
export const isNumeric = (value) => {
|
|
74
67
|
return /^-?\d+(\.\d+)?$/.test(value);
|
|
75
|
-
}
|
|
76
|
-
|
|
68
|
+
};
|
|
77
69
|
|
|
78
70
|
export const isFloat = (value) => {
|
|
79
71
|
return !isNaN(value) && Number(value) === value && !Number.isInteger(value);
|
|
80
|
-
}
|
|
81
|
-
|
|
72
|
+
};
|
|
82
73
|
|
|
83
74
|
export const isString = (value) => {
|
|
84
75
|
return typeof value === 'string';
|
|
85
|
-
}
|
|
86
|
-
|
|
76
|
+
};
|
|
87
77
|
|
|
88
78
|
export const isNull = (value) => {
|
|
89
79
|
return value === null || value === undefined;
|
|
90
|
-
}
|
|
91
|
-
|
|
80
|
+
};
|
|
92
81
|
|
|
93
82
|
const isHtmlElement = (value) => {
|
|
94
83
|
const htmlElements = [
|
|
@@ -107,8 +96,7 @@ const isHtmlElement = (value) => {
|
|
|
107
96
|
return htmlElements.some((element) => {
|
|
108
97
|
return Object.prototype.toString.call(value) === `[object ${element}]`;
|
|
109
98
|
});
|
|
110
|
-
}
|
|
111
|
-
|
|
99
|
+
};
|
|
112
100
|
|
|
113
101
|
export const isEmpty = (variable) => {
|
|
114
102
|
if (variable === undefined || variable === null) {
|
|
@@ -127,8 +115,7 @@ export const isEmpty = (variable) => {
|
|
|
127
115
|
return false;
|
|
128
116
|
}
|
|
129
117
|
return !variable;
|
|
130
|
-
}
|
|
131
|
-
|
|
118
|
+
};
|
|
132
119
|
|
|
133
120
|
export const elementToObject = (element) => {
|
|
134
121
|
const obj = {};
|
|
@@ -141,8 +128,7 @@ export const elementToObject = (element) => {
|
|
|
141
128
|
obj['selectValue'] = element.value;
|
|
142
129
|
}
|
|
143
130
|
return obj;
|
|
144
|
-
}
|
|
145
|
-
|
|
131
|
+
};
|
|
146
132
|
|
|
147
133
|
export const nodeListToObject = (nodeList) => {
|
|
148
134
|
return Array.from(nodeList).map((el, index) => ({
|
|
@@ -159,8 +145,7 @@ export const nodeListToObject = (nodeList) => {
|
|
|
159
145
|
...(el.innerText && {value: el.innerText}),
|
|
160
146
|
index: index
|
|
161
147
|
}));
|
|
162
|
-
}
|
|
163
|
-
|
|
148
|
+
};
|
|
164
149
|
|
|
165
150
|
export const deepEqual = (obj1, obj2) => {
|
|
166
151
|
if (obj1 === obj2) return true;
|
|
@@ -175,19 +160,16 @@ export const deepEqual = (obj1, obj2) => {
|
|
|
175
160
|
}
|
|
176
161
|
}
|
|
177
162
|
return true;
|
|
178
|
-
}
|
|
179
|
-
|
|
163
|
+
};
|
|
180
164
|
|
|
181
165
|
export const ucfirst = (str) => {
|
|
182
166
|
if (!str) return str;
|
|
183
167
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
184
|
-
}
|
|
185
|
-
|
|
168
|
+
};
|
|
186
169
|
|
|
187
170
|
export const firstKey = (object) => {
|
|
188
171
|
return Object.keys(object)[0] || null;
|
|
189
|
-
}
|
|
190
|
-
|
|
172
|
+
};
|
|
191
173
|
|
|
192
174
|
export const copyText = async (element) => {
|
|
193
175
|
try {
|
|
@@ -197,8 +179,7 @@ export const copyText = async (element) => {
|
|
|
197
179
|
} catch (err) {
|
|
198
180
|
console.error('Помилка копіювання! Error:', err);
|
|
199
181
|
}
|
|
200
|
-
}
|
|
201
|
-
|
|
182
|
+
};
|
|
202
183
|
|
|
203
184
|
// HTML Elements
|
|
204
185
|
export const options = (object, selected = null, disabled = null) => {
|
|
@@ -234,8 +215,7 @@ export const options = (object, selected = null, disabled = null) => {
|
|
|
234
215
|
}
|
|
235
216
|
});
|
|
236
217
|
}
|
|
237
|
-
}
|
|
238
|
-
|
|
218
|
+
};
|
|
239
219
|
|
|
240
220
|
export const input = (attributes = {}) => {
|
|
241
221
|
let input = document.createElement("input");
|
|
@@ -282,8 +262,7 @@ export const input = (attributes = {}) => {
|
|
|
282
262
|
});
|
|
283
263
|
}
|
|
284
264
|
return input;
|
|
285
|
-
}
|
|
286
|
-
|
|
265
|
+
};
|
|
287
266
|
|
|
288
267
|
export const label = (attributes = {}) => {
|
|
289
268
|
let label = document.createElement("label");
|
|
@@ -334,8 +313,7 @@ export const label = (attributes = {}) => {
|
|
|
334
313
|
});
|
|
335
314
|
}
|
|
336
315
|
return label;
|
|
337
|
-
}
|
|
338
|
-
|
|
316
|
+
};
|
|
339
317
|
|
|
340
318
|
export const form = (attributes = {}) => {
|
|
341
319
|
let form = document.createElement("form");
|
|
@@ -394,8 +372,7 @@ export const form = (attributes = {}) => {
|
|
|
394
372
|
});
|
|
395
373
|
}
|
|
396
374
|
return form;
|
|
397
|
-
}
|
|
398
|
-
|
|
375
|
+
};
|
|
399
376
|
|
|
400
377
|
export const div = (attributes = {}) => {
|
|
401
378
|
let div = document.createElement("div");
|
|
@@ -445,8 +422,7 @@ export const div = (attributes = {}) => {
|
|
|
445
422
|
});
|
|
446
423
|
}
|
|
447
424
|
return div;
|
|
448
|
-
}
|
|
449
|
-
|
|
425
|
+
};
|
|
450
426
|
|
|
451
427
|
export const a = (attributes = {}) => {
|
|
452
428
|
let a = document.createElement("a");
|
|
@@ -496,8 +472,7 @@ export const a = (attributes = {}) => {
|
|
|
496
472
|
});
|
|
497
473
|
}
|
|
498
474
|
return a;
|
|
499
|
-
}
|
|
500
|
-
|
|
475
|
+
};
|
|
501
476
|
|
|
502
477
|
export const span = (attributes = {}) => {
|
|
503
478
|
let span = document.createElement("span");
|
|
@@ -547,8 +522,7 @@ export const span = (attributes = {}) => {
|
|
|
547
522
|
});
|
|
548
523
|
}
|
|
549
524
|
return span;
|
|
550
|
-
}
|
|
551
|
-
|
|
525
|
+
};
|
|
552
526
|
|
|
553
527
|
export const textarea = (attributes = {}) => {
|
|
554
528
|
let textarea = document.createElement("textarea");
|
|
@@ -598,8 +572,7 @@ export const textarea = (attributes = {}) => {
|
|
|
598
572
|
});
|
|
599
573
|
}
|
|
600
574
|
return textarea;
|
|
601
|
-
}
|
|
602
|
-
|
|
575
|
+
};
|
|
603
576
|
|
|
604
577
|
export const pre = (attributes = {}) => {
|
|
605
578
|
let pre = document.createElement("pre");
|
|
@@ -649,8 +622,7 @@ export const pre = (attributes = {}) => {
|
|
|
649
622
|
});
|
|
650
623
|
}
|
|
651
624
|
return pre;
|
|
652
|
-
}
|
|
653
|
-
|
|
625
|
+
};
|
|
654
626
|
|
|
655
627
|
export const button = (attributes = {}) => {
|
|
656
628
|
let button = document.createElement("button");
|
|
@@ -700,8 +672,7 @@ export const button = (attributes = {}) => {
|
|
|
700
672
|
});
|
|
701
673
|
}
|
|
702
674
|
return button;
|
|
703
|
-
}
|
|
704
|
-
|
|
675
|
+
};
|
|
705
676
|
|
|
706
677
|
export const select = (attributes = {}) => {
|
|
707
678
|
let select = document.createElement("select");
|
|
@@ -786,8 +757,6 @@ export const select = (attributes = {}) => {
|
|
|
786
757
|
return select;
|
|
787
758
|
};
|
|
788
759
|
|
|
789
|
-
|
|
790
|
-
|
|
791
760
|
export const option = (attributes = {}) => {
|
|
792
761
|
let option = document.createElement("option");
|
|
793
762
|
if (attributes) {
|
|
@@ -801,8 +770,7 @@ export const option = (attributes = {}) => {
|
|
|
801
770
|
});
|
|
802
771
|
}
|
|
803
772
|
return option;
|
|
804
|
-
}
|
|
805
|
-
|
|
773
|
+
};
|
|
806
774
|
|
|
807
775
|
export const hr = (attributes = {}) => {
|
|
808
776
|
let hr = document.createElement("hr");
|
|
@@ -821,8 +789,7 @@ export const hr = (attributes = {}) => {
|
|
|
821
789
|
});
|
|
822
790
|
}
|
|
823
791
|
return hr;
|
|
824
|
-
}
|
|
825
|
-
|
|
792
|
+
};
|
|
826
793
|
|
|
827
794
|
export const meta = (attributes = {}) => {
|
|
828
795
|
let meta = document.createElement("meta");
|
|
@@ -841,8 +808,7 @@ export const meta = (attributes = {}) => {
|
|
|
841
808
|
});
|
|
842
809
|
}
|
|
843
810
|
return meta;
|
|
844
|
-
}
|
|
845
|
-
|
|
811
|
+
};
|
|
846
812
|
|
|
847
813
|
export const table = (attributes = {}) => {
|
|
848
814
|
let table = document.createElement("table");
|
|
@@ -892,8 +858,7 @@ export const table = (attributes = {}) => {
|
|
|
892
858
|
});
|
|
893
859
|
}
|
|
894
860
|
return table;
|
|
895
|
-
}
|
|
896
|
-
|
|
861
|
+
};
|
|
897
862
|
|
|
898
863
|
export const caption = (attributes = {}) => {
|
|
899
864
|
let caption = document.createElement("caption");
|
|
@@ -946,8 +911,7 @@ export const caption = (attributes = {}) => {
|
|
|
946
911
|
});
|
|
947
912
|
}
|
|
948
913
|
return caption;
|
|
949
|
-
}
|
|
950
|
-
|
|
914
|
+
};
|
|
951
915
|
|
|
952
916
|
export const thead = (attributes = {}) => {
|
|
953
917
|
let thead = document.createElement("thead");
|
|
@@ -997,8 +961,7 @@ export const thead = (attributes = {}) => {
|
|
|
997
961
|
});
|
|
998
962
|
}
|
|
999
963
|
return thead;
|
|
1000
|
-
}
|
|
1001
|
-
|
|
964
|
+
};
|
|
1002
965
|
|
|
1003
966
|
export const tbody = (attributes = {}) => {
|
|
1004
967
|
let tbody = document.createElement("tbody");
|
|
@@ -1048,8 +1011,7 @@ export const tbody = (attributes = {}) => {
|
|
|
1048
1011
|
});
|
|
1049
1012
|
}
|
|
1050
1013
|
return tbody;
|
|
1051
|
-
}
|
|
1052
|
-
|
|
1014
|
+
};
|
|
1053
1015
|
|
|
1054
1016
|
export const tr = (attributes = {}) => {
|
|
1055
1017
|
let tr = document.createElement("tr");
|
|
@@ -1099,8 +1061,7 @@ export const tr = (attributes = {}) => {
|
|
|
1099
1061
|
});
|
|
1100
1062
|
}
|
|
1101
1063
|
return tr;
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1064
|
+
};
|
|
1104
1065
|
|
|
1105
1066
|
export const th = (attributes = {}) => {
|
|
1106
1067
|
let th = document.createElement("th");
|
|
@@ -1150,8 +1111,7 @@ export const th = (attributes = {}) => {
|
|
|
1150
1111
|
});
|
|
1151
1112
|
}
|
|
1152
1113
|
return th;
|
|
1153
|
-
}
|
|
1154
|
-
|
|
1114
|
+
};
|
|
1155
1115
|
|
|
1156
1116
|
export const td = (attributes = {}) => {
|
|
1157
1117
|
let td = document.createElement("td");
|
|
@@ -1201,7 +1161,7 @@ export const td = (attributes = {}) => {
|
|
|
1201
1161
|
});
|
|
1202
1162
|
}
|
|
1203
1163
|
return td;
|
|
1204
|
-
}
|
|
1164
|
+
};
|
|
1205
1165
|
|
|
1206
1166
|
export const img = (attributes = {}) => {
|
|
1207
1167
|
let img = document.createElement("img");
|
|
@@ -1249,7 +1209,7 @@ export const img = (attributes = {}) => {
|
|
|
1249
1209
|
});
|
|
1250
1210
|
}
|
|
1251
1211
|
return img;
|
|
1252
|
-
}
|
|
1212
|
+
};
|
|
1253
1213
|
|
|
1254
1214
|
export const apState = (initialValue) => {
|
|
1255
1215
|
let state = initialValue;
|
|
@@ -1262,7 +1222,7 @@ export const apState = (initialValue) => {
|
|
|
1262
1222
|
}
|
|
1263
1223
|
}
|
|
1264
1224
|
return [getState, setState];
|
|
1265
|
-
}
|
|
1225
|
+
};
|
|
1266
1226
|
|
|
1267
1227
|
export const apFetch = async (url, params = {}) => {
|
|
1268
1228
|
const [data, setData] = apState(null);
|
|
@@ -1289,21 +1249,21 @@ export const apFetch = async (url, params = {}) => {
|
|
|
1289
1249
|
await fetchData();
|
|
1290
1250
|
|
|
1291
1251
|
return [data, error, isLoading];
|
|
1292
|
-
}
|
|
1252
|
+
};
|
|
1293
1253
|
|
|
1294
1254
|
export const scrollToTop = () => {
|
|
1295
1255
|
window.scrollTo({
|
|
1296
1256
|
top: 0,
|
|
1297
1257
|
behavior: "smooth",
|
|
1298
1258
|
});
|
|
1299
|
-
}
|
|
1259
|
+
};
|
|
1300
1260
|
|
|
1301
1261
|
export const scrollToBottom = () => {
|
|
1302
1262
|
window.scrollTo({
|
|
1303
1263
|
top: document.documentElement.scrollHeight,
|
|
1304
1264
|
behavior: "smooth",
|
|
1305
1265
|
});
|
|
1306
|
-
}
|
|
1266
|
+
};
|
|
1307
1267
|
|
|
1308
1268
|
export const _get = (name, defaulting = null) => {
|
|
1309
1269
|
let url = new URL(window.location.href);
|
package/src/paginate.js
CHANGED
|
@@ -103,7 +103,7 @@ export const paginate = ({ count = 0, currentPage = 1, onPageChange = () => {},
|
|
|
103
103
|
buttons.push(createPageButton(count));
|
|
104
104
|
}
|
|
105
105
|
return buttons;
|
|
106
|
-
}
|
|
106
|
+
};
|
|
107
107
|
|
|
108
108
|
const createPageButton = (page) => button({
|
|
109
109
|
class: `paginate-btn ${page === currentPage ? "active" : ""}`,
|
package/src/redirect.js
CHANGED
package/src/router.js
CHANGED
|
@@ -1,28 +1,36 @@
|
|
|
1
1
|
import NotFound from "./NotFound.js";
|
|
2
2
|
|
|
3
|
-
const router = async ({ routes, main
|
|
3
|
+
export const router = async ({ routes, main }) => {
|
|
4
4
|
const renderRoute = async () => {
|
|
5
|
-
const routeComponent = await useRoutes(routes
|
|
5
|
+
const { routeComponent, props } = await useRoutes(routes);
|
|
6
6
|
main.innerHTML = "";
|
|
7
7
|
if (routeComponent) {
|
|
8
|
-
|
|
8
|
+
const component = await routeComponent(props);
|
|
9
|
+
main.appendChild(component);
|
|
9
10
|
}
|
|
10
|
-
}
|
|
11
|
+
};
|
|
12
|
+
|
|
11
13
|
window.addEventListener('popstate', renderRoute);
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
+
window.renderRoute = renderRoute;
|
|
14
15
|
|
|
16
|
+
await renderRoute();
|
|
17
|
+
};
|
|
15
18
|
|
|
16
|
-
const navigateTo = (path) => {
|
|
17
|
-
window.history.pushState(
|
|
18
|
-
}
|
|
19
|
+
export const navigateTo = (path, props = {}) => {
|
|
20
|
+
window.history.pushState(props, "", path);
|
|
21
|
+
};
|
|
19
22
|
|
|
23
|
+
export const navi = (path, props = {}) => {
|
|
24
|
+
window.history.pushState(props, "", path);
|
|
25
|
+
window.renderRoute().then();
|
|
26
|
+
};
|
|
20
27
|
|
|
21
|
-
const useRoutes = async (routes
|
|
28
|
+
const useRoutes = async (routes) => {
|
|
22
29
|
const path = window.location.pathname;
|
|
23
30
|
const matchingRoute = routes.find(route => route.path === path);
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
31
|
+
const props = window.history.state || {};
|
|
27
32
|
|
|
28
|
-
|
|
33
|
+
return matchingRoute
|
|
34
|
+
? { routeComponent: matchingRoute.component, props }
|
|
35
|
+
: { routeComponent: NotFound, props };
|
|
36
|
+
};
|