aprog 1.6.6 → 1.6.7

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
@@ -144,7 +144,7 @@ onInput: (event) => {
144
144
  Загальний список методів:
145
145
 
146
146
  - *dump(...args), dd(...args)*
147
- - *redirect(url, { newTab: bool, replace: bool }), reload(delaySeconds)*
147
+ - *redirect(url, { newTab: bool, replace: bool }), reload(delaySeconds), validateEmail(email), validatePassword(password)*
148
148
  - *encrypt(str), decrypt(encryptedStr)*
149
149
 
150
150
  - *div, span, button, a, img, meta, label, input, select, option, options, form, hr, textarea, table, caption, thead, tbody, tr, th, td, pre, attachCustomTitle*
package/index.js CHANGED
@@ -6,7 +6,7 @@ export {
6
6
  firstKey, isArray, checkArrays, isNumber, isString, isPromise, ucfirst, deepEqual, nodeListToObject
7
7
  } from './src/aprog.js';
8
8
  export { dump, dd } from './src/debugger.js';
9
- export { redirect, reload } from './src/redirect.js';
9
+ export { redirect, reload, validateEmail, validatePassword } from './src/redirect.js';
10
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';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aprog",
3
- "version": "1.6.6",
3
+ "version": "1.6.7",
4
4
  "description": "Допоміжна бібліотека js",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/redirect.js CHANGED
@@ -9,3 +9,11 @@ export const redirect = (url, { newTab = false, replace = false } = {}) => {
9
9
  };
10
10
 
11
11
  export const reload = (delaySeconds = 0.7) => setTimeout(() => window.location.reload(), (delaySeconds * 1000));
12
+
13
+ export const validateEmail = (email) => {
14
+ return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
15
+ };
16
+
17
+ export const validatePassword = (password) => {
18
+ return /^(?=.*[A-Z])(?=.*\d)(?=.*[\W_]).{6,}$/.test(password);
19
+ };
package/src/storage.js CHANGED
@@ -1,8 +1,18 @@
1
1
  export const cookie = {
2
+ /**
3
+ * Отримати значення cookie по імені
4
+ * @param {string} name
5
+ * @returns {string|null}
6
+ */
2
7
  get(name) {
3
8
  const cookies = document.cookie.split('; ');
4
9
  for (let cookie of cookies) {
5
- let [key, value] = cookie.split('=');
10
+ const index = cookie.indexOf('=');
11
+ if (index === -1) continue;
12
+
13
+ const key = cookie.substring(0, index);
14
+ const value = cookie.substring(index + 1);
15
+
6
16
  if (key === name) {
7
17
  return decodeURIComponent(value);
8
18
  }
@@ -10,18 +20,29 @@ export const cookie = {
10
20
  return null;
11
21
  },
12
22
 
23
+ /**
24
+ * Встановити cookie
25
+ * @param {string} name
26
+ * @param {string} value
27
+ * @param {number} days
28
+ */
13
29
  set(name, value, days = 7) {
14
30
  let expires = "";
15
31
  if (days) {
16
- let date = new Date();
32
+ const date = new Date();
17
33
  date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
18
34
  expires = "; expires=" + date.toUTCString();
19
35
  }
20
- document.cookie = name + "=" + encodeURIComponent(value) + expires + "; path=/";
36
+ const safeValue = encodeURIComponent(value);
37
+ document.cookie = `${name}=${safeValue}${expires}; path=/`;
21
38
  },
22
39
 
40
+ /**
41
+ * Видалити cookie
42
+ * @param {string} name
43
+ */
23
44
  delete(name) {
24
- document.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
45
+ document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
25
46
  }
26
47
  };
27
48