@cocreate/utils 1.41.2 → 1.42.1

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.
@@ -0,0 +1,5 @@
1
+ import { clickedElement } from "./clickedElement.js";
2
+
3
+ if (typeof window !== "undefined" && typeof document !== "undefined") {
4
+ clickedElement();
5
+ }
@@ -0,0 +1,17 @@
1
+ export function isValidDate(value) {
2
+ if (
3
+ typeof value === "string" &&
4
+ value.length >= 20 &&
5
+ value.length <= 24
6
+ ) {
7
+ if (
8
+ /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?([-+]\d{2}:\d{2}|Z)?$/i.test(
9
+ value
10
+ )
11
+ ) {
12
+ return true;
13
+ }
14
+ }
15
+
16
+ return false;
17
+ }
@@ -0,0 +1,35 @@
1
+ export function objectToDotNotation(input) {
2
+ const results = {};
3
+
4
+ function traverse(currentValue, path) {
5
+ if (typeof currentValue !== "object" || currentValue === null) {
6
+ if (path !== undefined && path !== null && path !== "") {
7
+ results[path] = currentValue;
8
+ }
9
+ return;
10
+ }
11
+
12
+ if (Array.isArray(currentValue)) {
13
+ if (currentValue.length > 0) {
14
+ currentValue.forEach((item, index) => {
15
+ const nextPath = `${path}[${index}]`;
16
+ traverse(item, nextPath);
17
+ });
18
+ } else if (path) {
19
+ }
20
+ } else {
21
+ const keys = Object.keys(currentValue);
22
+ if (keys.length > 0) {
23
+ keys.forEach((key) => {
24
+ const nextPath = path ? `${path}.${key}` : key;
25
+ traverse(currentValue[key], nextPath);
26
+ });
27
+ } else if (path) {
28
+ }
29
+ }
30
+ }
31
+
32
+ traverse(input, "");
33
+
34
+ return results;
35
+ }
@@ -0,0 +1,28 @@
1
+ export function objectToSearchParams(paramsObj) {
2
+ if (
3
+ !paramsObj ||
4
+ typeof paramsObj !== "object" ||
5
+ Array.isArray(paramsObj)
6
+ ) {
7
+ return "";
8
+ }
9
+
10
+ const filteredObj = {};
11
+ for (const key in paramsObj) {
12
+ if (Object.hasOwn(paramsObj, key)) {
13
+ const value = paramsObj[key];
14
+ if (value !== null && value !== undefined) {
15
+ filteredObj[key] = value;
16
+ }
17
+ }
18
+ }
19
+
20
+ if (Object.keys(filteredObj).length === 0) {
21
+ return "";
22
+ }
23
+
24
+ const searchParams = new URLSearchParams(filteredObj);
25
+ const queryString = searchParams.toString();
26
+
27
+ return queryString ? `?${queryString}` : "";
28
+ }