@massimo-cassandro/minimo 1.20.4 → 1.20.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@massimo-cassandro/minimo",
3
- "version": "1.20.4",
3
+ "version": "1.20.5",
4
4
  "description": "Light css framework & utilities",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -4,12 +4,19 @@
4
4
  /**
5
5
  * Returns the value of a cookie by name.
6
6
  * @param {string} name
7
- * @returns {string | undefined}
7
+ * @param {object} [options]
8
+ * @param {boolean} [options.parseJson=false] - If true, JSON-parses the value and returns an object instead of a string.
9
+ * @returns {string | object | null}
8
10
  */
9
- export function getCookie(name) {
11
+ export function getCookie(name, {parseJson = false} = {}) {
10
12
  const value = `; ${document.cookie}`;
11
13
  const parts = value.split(`; ${name}=`);
12
- if (parts.length === 2) return parts.pop()?.split(';').shift();
14
+ if (parts.length !== 2) return null;
15
+
16
+ const cookieValue = parts.pop()?.split(';').shift();
17
+ if (cookieValue === undefined) return null;
18
+
19
+ return parseJson ? JSON.parse(cookieValue) : cookieValue;
13
20
  }
14
21
 
15
22