@musecat/functionkit 1.0.1 → 1.0.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.
Files changed (120) hide show
  1. package/.agents/references/components/ScrolltoTop.md +36 -0
  2. package/.agents/references/components/SwitchCase.md +47 -0
  3. package/.agents/references/components/ViewportPortal.md +34 -0
  4. package/.agents/references/cookie/cookie.md +47 -0
  5. package/.agents/references/datetime/dateTime.client.md +42 -0
  6. package/.agents/references/datetime/dateTime.server.md +42 -0
  7. package/.agents/references/datetime/dateTime.shared.md +86 -0
  8. package/.agents/references/hooks/useAvoidKeyboard.md +29 -0
  9. package/.agents/references/hooks/useCheckInvisible.md +36 -0
  10. package/.agents/references/hooks/useCheckScroll.md +36 -0
  11. package/.agents/references/hooks/useClientDateTime.md +39 -0
  12. package/.agents/references/hooks/useDebounce.md +46 -0
  13. package/.agents/references/hooks/useDebouncedCallback.md +34 -0
  14. package/.agents/references/hooks/useDoubleClick.md +40 -0
  15. package/.agents/references/hooks/useGeolocation.md +37 -0
  16. package/.agents/references/hooks/useHasMounted.md +27 -0
  17. package/.agents/references/hooks/useIntersectionObserver.md +37 -0
  18. package/.agents/references/hooks/useInterval.md +40 -0
  19. package/.agents/references/hooks/useKeyboardHeight.md +33 -0
  20. package/.agents/references/hooks/useKeyboardListNavigation.md +58 -0
  21. package/.agents/references/hooks/useLongPress.md +48 -0
  22. package/.agents/references/hooks/usePreservedCallback.md +33 -0
  23. package/.agents/references/hooks/usePreservedReference.md +34 -0
  24. package/.agents/references/hooks/useRefEffect.md +35 -0
  25. package/.agents/references/hooks/useRelativeDateTime.md +35 -0
  26. package/.agents/references/hooks/useTimeout.md +42 -0
  27. package/.agents/references/hooks/useToggleState.md +39 -0
  28. package/.agents/references/hooks/useViewportHeight.md +26 -0
  29. package/.agents/references/hooks/useViewportMatch.md +32 -0
  30. package/.agents/references/utils/browserStorage.md +41 -0
  31. package/.agents/references/utils/buildContext.md +47 -0
  32. package/.agents/references/utils/clipboardShare.md +59 -0
  33. package/.agents/references/utils/floatingMotion.md +67 -0
  34. package/.agents/references/utils/getDeviceInfo.md +43 -0
  35. package/.agents/references/utils/isEditableKeyboardTarget.md +35 -0
  36. package/.agents/references/utils/mergeRefs.md +29 -0
  37. package/.agents/references/utils/seen.md +37 -0
  38. package/.agents/references/utils/subscribeKeyboardHeight.md +35 -0
  39. package/AGENTS.md +103 -396
  40. package/README.md +18 -5
  41. package/index.ts +63 -68
  42. package/package.json +27 -13
  43. package/packages/components/ScrolltoTop.tsx +3 -3
  44. package/packages/components/SwitchCase.tsx +7 -7
  45. package/packages/components/ViewportPortal.tsx +23 -23
  46. package/packages/cookie/cookie.shared.ts +97 -101
  47. package/packages/datetime/dateTime.client.ts +86 -86
  48. package/packages/datetime/dateTime.server.ts +86 -86
  49. package/packages/datetime/dateTime.shared.ts +281 -281
  50. package/packages/hooks/useAvoidKeyboard.ts +15 -15
  51. package/packages/hooks/useCheckInvisible.ts +16 -16
  52. package/packages/hooks/useCheckScroll.ts +10 -10
  53. package/packages/hooks/useClientDateTime.ts +33 -33
  54. package/packages/hooks/useDebounce.ts +95 -95
  55. package/packages/hooks/useDebouncedCallback.ts +45 -45
  56. package/packages/hooks/useDoubleClick.ts +43 -43
  57. package/packages/hooks/useGeolocation.ts +130 -130
  58. package/packages/hooks/useHasMounted.ts +5 -5
  59. package/packages/hooks/useIntersectionObserver.ts +20 -20
  60. package/packages/hooks/useInterval.ts +46 -45
  61. package/packages/hooks/useKeyboardHeight.ts +9 -9
  62. package/packages/hooks/useKeyboardListNavigation.ts +156 -156
  63. package/packages/hooks/useLongPress.ts +98 -98
  64. package/packages/hooks/usePreservedCallback.ts +12 -12
  65. package/packages/hooks/usePreservedReference.ts +10 -10
  66. package/packages/hooks/useRefEffect.ts +19 -19
  67. package/packages/hooks/useRelativeDateTime.ts +37 -37
  68. package/packages/hooks/useTimeout.ts +41 -41
  69. package/packages/hooks/useToggleState.ts +5 -5
  70. package/packages/hooks/useViewportHeight.ts +13 -13
  71. package/packages/hooks/useViewportMatch.ts +16 -22
  72. package/packages/utils/browserStorage.ts +26 -26
  73. package/packages/utils/buildContext.tsx +10 -10
  74. package/packages/utils/checkDevice.ts +64 -64
  75. package/packages/utils/clipboardShare.tsx +31 -31
  76. package/packages/utils/clipboardShare.types.ts +7 -7
  77. package/packages/utils/floatingMotion.ts +71 -71
  78. package/packages/utils/keyboardTarget.ts +9 -9
  79. package/packages/utils/mergeRefs.ts +9 -9
  80. package/packages/utils/seen.ts +15 -15
  81. package/packages/utils/subscribeKeyboardHeight.ts +46 -46
  82. package/tests/components/ScrolltoTop.test.tsx +15 -0
  83. package/tests/components/SwitchCase.test.tsx +34 -0
  84. package/tests/components/ViewportPortal.test.tsx +42 -0
  85. package/tests/cookie/cookie.test.ts +156 -0
  86. package/tests/datetime/datetime.test.ts +250 -0
  87. package/tests/hooks/useAvoidKeyboard.test.ts +12 -0
  88. package/tests/hooks/useCheckInvisible.test.ts +28 -0
  89. package/tests/hooks/useCheckScroll.test.ts +23 -0
  90. package/tests/hooks/useClientDateTime.test.ts +14 -0
  91. package/tests/hooks/useDebounce.test.ts +71 -0
  92. package/tests/hooks/useDebouncedCallback.test.ts +34 -0
  93. package/tests/hooks/useDoubleClick.test.ts +31 -0
  94. package/tests/hooks/useGeolocation.test.ts +50 -0
  95. package/tests/hooks/useHasMounted.test.ts +10 -0
  96. package/tests/hooks/useIntersectionObserver.test.ts +13 -0
  97. package/tests/hooks/useInterval.test.ts +31 -0
  98. package/tests/hooks/useKeyboardHeight.test.ts +10 -0
  99. package/tests/hooks/useKeyboardListNavigation.test.ts +82 -0
  100. package/tests/hooks/useLongPress.test.ts +52 -0
  101. package/tests/hooks/usePreservedCallback.test.ts +35 -0
  102. package/tests/hooks/usePreservedReference.test.ts +35 -0
  103. package/tests/hooks/useRefEffect.test.ts +30 -0
  104. package/tests/hooks/useRelativeDateTime.test.ts +19 -0
  105. package/tests/hooks/useTimeout.test.ts +34 -0
  106. package/tests/hooks/useToggleState.test.ts +35 -0
  107. package/tests/hooks/useViewportHeight.test.ts +10 -0
  108. package/tests/hooks/useViewportMatch.test.ts +35 -0
  109. package/tests/setup.ts +9 -0
  110. package/tests/utils/browserStorage.test.ts +54 -0
  111. package/tests/utils/buildContext.test.tsx +27 -0
  112. package/tests/utils/checkDevice.test.ts +84 -0
  113. package/tests/utils/clipboardShare.test.ts +78 -0
  114. package/tests/utils/floatingMotion.test.ts +84 -0
  115. package/tests/utils/keyboardTarget.test.ts +44 -0
  116. package/tests/utils/mergeRefs.test.ts +18 -0
  117. package/tests/utils/seen.test.ts +31 -0
  118. package/tests/utils/subscribeKeyboardHeight.test.ts +50 -0
  119. package/tsconfig.json +16 -16
  120. package/vitest.config.ts +16 -0
package/index.ts CHANGED
@@ -1,53 +1,49 @@
1
- // 컴포넌트
2
1
  export {
3
- getViewportPortalRoot,
4
- ViewportPortal
2
+ getViewportPortalRoot,
3
+ ViewportPortal,
5
4
  } from "./packages/components/ViewportPortal";
6
- // 쿠키
7
5
  export {
8
- clearAllClientCookies,
9
- clearClientCookie,
10
- getClientCookie,
11
- parseClientCookieNames,
12
- setClientCookie
6
+ clearAllClientCookies,
7
+ clearClientCookie,
8
+ getClientCookie,
9
+ parseClientCookieNames,
10
+ setClientCookie,
13
11
  } from "./packages/cookie/cookie.shared";
14
- // 날짜/시간
15
12
  export {
16
- formatClientDate,
17
- formatClientDateTime,
18
- formatClientRelative,
19
- formatClientTime
13
+ formatClientDate,
14
+ formatClientDateTime,
15
+ formatClientRelative,
16
+ formatClientTime,
20
17
  } from "./packages/datetime/dateTime.client";
21
18
  export {
22
- formatServerDate,
23
- formatServerDateTime,
24
- formatServerRelative,
25
- formatServerTime
19
+ formatServerDate,
20
+ formatServerDateTime,
21
+ formatServerRelative,
22
+ formatServerTime,
26
23
  } from "./packages/datetime/dateTime.server";
27
- export {
28
- addUtcDays,
29
- format24HourTime,
30
- formatDotDate,
31
- formatKoreanTime,
32
- formatLongDate,
33
- formatRelativeText,
34
- formatRemainingText,
35
- formatTwelveHourTime,
36
- formatUtcDateKey,
37
- getUtcWeekdayIndex,
38
- normalizeAppLocale,
39
- parseUtcDateInput,
40
- toDate,
41
- toIntlLocale,
42
- toUtcMidnight
43
- } from "./packages/datetime/dateTime.shared";
44
24
  export type {
45
- AppLocale,
46
- DateInput,
47
- DatePreset,
48
- TimePreset
25
+ AppLocale,
26
+ DateInput,
27
+ DatePreset,
28
+ TimePreset,
29
+ } from "./packages/datetime/dateTime.shared";
30
+ export {
31
+ addUtcDays,
32
+ format24HourTime,
33
+ formatDotDate,
34
+ formatKoreanTime,
35
+ formatLongDate,
36
+ formatRelativeText,
37
+ formatRemainingText,
38
+ formatTwelveHourTime,
39
+ formatUtcDateKey,
40
+ getUtcWeekdayIndex,
41
+ normalizeAppLocale,
42
+ parseUtcDateInput,
43
+ toDate,
44
+ toIntlLocale,
45
+ toUtcMidnight,
49
46
  } from "./packages/datetime/dateTime.shared";
50
- // hooks
51
47
  export { useAvoidKeyboard } from "./packages/hooks/useAvoidKeyboard";
52
48
  export { useClientDateTime } from "./packages/hooks/useClientDateTime";
53
49
  export { useDebounce } from "./packages/hooks/useDebounce";
@@ -68,44 +64,43 @@ export { useTimeout } from "./packages/hooks/useTimeout";
68
64
  export { useToggleState } from "./packages/hooks/useToggleState";
69
65
  export { useViewportHeight } from "./packages/hooks/useViewportHeight";
70
66
  export { useViewportMatch } from "./packages/hooks/useViewportMatch";
71
- // 유틸리티
72
67
  export {
73
- getLocalStorage,
74
- getSessionStorage,
75
- removeLocalStorage,
76
- removeSessionStorage,
77
- updateLocalStorage,
78
- updateSessionStorage
68
+ getLocalStorage,
69
+ getSessionStorage,
70
+ removeLocalStorage,
71
+ removeSessionStorage,
72
+ updateLocalStorage,
73
+ updateSessionStorage,
79
74
  } from "./packages/utils/browserStorage";
80
- // 유틸리티
81
75
  export { buildContext } from "./packages/utils/buildContext";
82
- export { getDeviceInfo } from "./packages/utils/checkDevice";
83
76
  export type { DeviceInfo } from "./packages/utils/checkDevice";
84
- export { NavigatorClipboard, NavigatorShare } from "./packages/utils/clipboardShare";
77
+ export { getDeviceInfo } from "./packages/utils/checkDevice";
78
+ export {
79
+ NavigatorClipboard,
80
+ NavigatorShare,
81
+ } from "./packages/utils/clipboardShare";
85
82
  export type {
86
- NavigatorClipboardProps,
87
- NavigatorClipboardResult,
88
- NavigatorShareProps,
89
- NavigatorShareResult
83
+ NavigatorClipboardProps,
84
+ NavigatorClipboardResult,
85
+ NavigatorShareProps,
86
+ NavigatorShareResult,
90
87
  } from "./packages/utils/clipboardShare.types";
91
- export {
92
- getFloatingHiddenTransform,
93
- getFloatingMotionPreset,
94
- getFloatingTransformOrigin
95
- } from "./packages/utils/floatingMotion";
96
88
  export type {
97
- FloatingMotionMode,
98
- FloatingMotionPreset,
99
- FloatingPlacement
89
+ FloatingMotionMode,
90
+ FloatingMotionPreset,
91
+ FloatingPlacement,
92
+ } from "./packages/utils/floatingMotion";
93
+ export {
94
+ getFloatingHiddenTransform,
95
+ getFloatingMotionPreset,
96
+ getFloatingTransformOrigin,
100
97
  } from "./packages/utils/floatingMotion";
101
- // 유틸리티
102
98
  export { isEditableKeyboardTarget } from "./packages/utils/keyboardTarget";
103
99
  export { mergeRefs } from "./packages/utils/mergeRefs";
104
100
  export {
105
- buildSeenValue,
106
- hasSeenKey,
107
- parseSeen,
108
- SEEN_STORAGE_KEY
101
+ buildSeenValue,
102
+ hasSeenKey,
103
+ parseSeen,
104
+ SEEN_STORAGE_KEY,
109
105
  } from "./packages/utils/seen";
110
106
  export { subscribeKeyboardHeight } from "./packages/utils/subscribeKeyboardHeight";
111
-
package/package.json CHANGED
@@ -1,15 +1,29 @@
1
1
  {
2
- "name": "@musecat/functionkit",
3
- "version": "1.0.1",
4
- "type": "module",
5
- "main": "./index.ts",
6
- "types": "./index.ts",
7
- "exports": {
8
- ".": "./index.ts",
9
- "./*": "./*"
10
- },
11
- "peerDependencies": {
12
- "react": "^19.0.0",
13
- "react-dom": "^19.0.0"
14
- }
2
+ "name": "@musecat/functionkit",
3
+ "version": "1.0.2",
4
+ "type": "module",
5
+ "main": "./index.ts",
6
+ "types": "./index.ts",
7
+ "exports": {
8
+ ".": "./index.ts",
9
+ "./*": "./*"
10
+ },
11
+ "scripts": {
12
+ "lint": "biome check",
13
+ "format": "prettier --write . && biome format --write",
14
+ "test": "vitest run"
15
+ },
16
+ "peerDependencies": {
17
+ "react": "^19.0.0",
18
+ "react-dom": "^19.0.0"
19
+ },
20
+ "devDependencies": {
21
+ "@biomejs/biome": "^2.5.4",
22
+ "@testing-library/jest-dom": "^6.6.3",
23
+ "@testing-library/react": "^16.2.0",
24
+ "@testing-library/user-event": "^14.6.1",
25
+ "jsdom": "^26.0.0",
26
+ "prettier": "^3.9.5",
27
+ "vitest": "^4.1.10"
28
+ }
15
29
  }
@@ -3,7 +3,7 @@
3
3
  import { useEffect } from "react";
4
4
 
5
5
  export function ScrolltoTop() {
6
- useEffect(() => {
7
- window.scrollTo(0, 0);
8
- });
6
+ useEffect(() => {
7
+ window.scrollTo(0, 0);
8
+ });
9
9
  }
@@ -1,15 +1,15 @@
1
1
  import type { ReactNode } from "react";
2
2
 
3
3
  type SwitchCaseProps<T extends string | number> = {
4
- value: T;
5
- cases: Partial<Record<T, ReactNode>>;
6
- otherwise?: ReactNode;
4
+ value: T;
5
+ cases: Partial<Record<T, ReactNode>>;
6
+ otherwise?: ReactNode;
7
7
  };
8
8
 
9
9
  export function SwitchCase<T extends string | number>({
10
- value,
11
- cases,
12
- otherwise = null,
10
+ value,
11
+ cases,
12
+ otherwise = null,
13
13
  }: SwitchCaseProps<T>) {
14
- return (cases[value] ?? otherwise) as ReactNode;
14
+ return (cases[value] ?? otherwise) as ReactNode;
15
15
  }
@@ -6,35 +6,35 @@ import { createPortal } from "react-dom";
6
6
  const VIEWPORT_PORTAL_ROOT_ID = "viewport-portal-root";
7
7
 
8
8
  export function getViewportPortalRoot() {
9
- if (typeof document === "undefined") {
10
- return null;
11
- }
12
-
13
- const existingRoot = document.getElementById(VIEWPORT_PORTAL_ROOT_ID);
14
- if (existingRoot instanceof HTMLDivElement) {
15
- return existingRoot;
16
- }
17
-
18
- const root = document.createElement("div");
19
- root.id = VIEWPORT_PORTAL_ROOT_ID;
20
- root.setAttribute("data-viewport-portal-root", "true");
21
- root.style.cssText =
22
- "position:fixed;inset:0;pointer-events:none;z-index:9999;";
23
- document.body.appendChild(root);
24
- return root;
9
+ if (typeof document === "undefined") {
10
+ return null;
11
+ }
12
+
13
+ const existingRoot = document.getElementById(VIEWPORT_PORTAL_ROOT_ID);
14
+ if (existingRoot instanceof HTMLDivElement) {
15
+ return existingRoot;
16
+ }
17
+
18
+ const root = document.createElement("div");
19
+ root.id = VIEWPORT_PORTAL_ROOT_ID;
20
+ root.setAttribute("data-viewport-portal-root", "true");
21
+ root.style.cssText =
22
+ "position:fixed;inset:0;pointer-events:none;z-index:9999;";
23
+ document.body.appendChild(root);
24
+ return root;
25
25
  }
26
26
 
27
27
  type ViewportPortalProps = {
28
- children: React.ReactNode;
28
+ children: React.ReactNode;
29
29
  };
30
30
 
31
31
  export function ViewportPortal({ children }: ViewportPortalProps) {
32
- const [root, setRoot] = useState<HTMLElement | null>(null);
32
+ const [root, setRoot] = useState<HTMLElement | null>(null);
33
33
 
34
- useEffect(() => {
35
- setRoot(getViewportPortalRoot());
36
- }, []);
34
+ useEffect(() => {
35
+ setRoot(getViewportPortalRoot());
36
+ }, []);
37
37
 
38
- if (!root) return null;
39
- return createPortal(children, root);
38
+ if (!root) return null;
39
+ return createPortal(children, root);
40
40
  }
@@ -3,140 +3,136 @@
3
3
  const EXPIRED_COOKIE_DATE = "Thu, 01 Jan 1970 00:00:00 GMT";
4
4
 
5
5
  type CookieStoreLike = {
6
- delete: (name: string) => Promise<void>;
6
+ delete: (name: string) => Promise<void>;
7
7
  };
8
8
 
9
9
  type DocumentCookieRef = {
10
- cookie: string;
10
+ cookie: string;
11
11
  };
12
12
 
13
13
  type ClearClientCookieOptions = {
14
- hostname?: string;
15
- path?: string;
16
- documentRef?: DocumentCookieRef;
17
- cookieStore?: CookieStoreLike;
14
+ hostname?: string;
15
+ path?: string;
16
+ documentRef?: DocumentCookieRef;
17
+ cookieStore?: CookieStoreLike;
18
18
  };
19
19
 
20
20
  type ClearAllClientCookiesOptions = ClearClientCookieOptions & {
21
- /**
22
- * If true, cookies in the hostname's root path ("/") are also deleted.
23
- * Use with caution.
24
- */
25
- includeRoot?: boolean;
26
- cookieString?: string;
21
+ includeRoot?: boolean;
22
+ cookieString?: string;
27
23
  };
28
24
 
29
25
  function findClientCookie(
30
- name: string,
31
- documentRef: DocumentCookieRef,
26
+ name: string,
27
+ documentRef: DocumentCookieRef,
32
28
  ): string | undefined {
33
- const parsed = parseClientCookie(documentRef.cookie);
34
- return parsed[name];
29
+ const parsed = parseClientCookie(documentRef.cookie);
30
+ return parsed[name];
35
31
  }
36
32
 
37
33
  function parseClientCookie(cookieString: string): Record<string, string> {
38
- return cookieString
39
- .split(";")
40
- .map((pair) => pair.trim().split("=") as [string, string])
41
- .reduce<Record<string, string>>((acc, [key, value]) => {
42
- if (key) {
43
- acc[key] = value;
44
- }
45
- return acc;
46
- }, {});
34
+ return cookieString
35
+ .split(";")
36
+ .map((pair) => pair.trim().split("=") as [string, string])
37
+ .reduce<Record<string, string>>((acc, [key, value]) => {
38
+ if (key) {
39
+ acc[key] = value;
40
+ }
41
+ return acc;
42
+ }, {});
47
43
  }
48
44
 
49
45
  export function parseClientCookieNames(cookieString: string): string[] {
50
- return cookieString
51
- .split(";")
52
- .map((entry) => {
53
- const eqPos = entry.indexOf("=");
54
- return eqPos > -1 ? entry.slice(0, eqPos).trim() : entry.trim();
55
- })
56
- .filter(Boolean);
46
+ return cookieString
47
+ .split(";")
48
+ .map((entry) => {
49
+ const eqPos = entry.indexOf("=");
50
+ return eqPos > -1 ? entry.slice(0, eqPos).trim() : entry.trim();
51
+ })
52
+ .filter(Boolean);
57
53
  }
58
54
 
59
55
  export function getClientCookie(name: string): string | undefined {
60
- if (typeof document === "undefined") {
61
- return undefined;
62
- }
56
+ if (typeof document === "undefined") {
57
+ return undefined;
58
+ }
63
59
 
64
- return findClientCookie(name, document);
60
+ return findClientCookie(name, document);
65
61
  }
66
62
 
67
63
  export function setClientCookie(name: string, value: string, days?: number) {
68
- if (typeof document === "undefined") {
69
- return;
70
- }
71
-
72
- let expires = "";
73
- if (days) {
74
- const date = new Date();
75
- date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
76
- expires = `; expires=${date.toUTCString()}`;
77
- }
78
-
79
- document.cookie = `${name}=${encodeURIComponent(value)}${expires}; path=/`;
64
+ if (typeof document === "undefined") {
65
+ return;
66
+ }
67
+
68
+ let expires = "";
69
+ if (days) {
70
+ const date = new Date();
71
+ date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
72
+ expires = `; expires=${date.toUTCString()}`;
73
+ }
74
+
75
+ document.cookie = `${name}=${encodeURIComponent(value)}${expires}; path=/`;
80
76
  }
81
77
 
82
78
  export function clearClientCookie(
83
- name: string,
84
- options: ClearClientCookieOptions = {},
79
+ name: string,
80
+ options: ClearClientCookieOptions = {},
85
81
  ): void {
86
- const {
87
- hostname = window.location.hostname,
88
- path = "/",
89
- documentRef = document,
90
- } = options;
82
+ const {
83
+ hostname = window.location.hostname,
84
+ path = "/",
85
+ documentRef = document,
86
+ } = options;
91
87
 
92
- documentRef.cookie = `${name}=; expires=${EXPIRED_COOKIE_DATE}; path=${path}; domain=${hostname};`;
88
+ documentRef.cookie = `${name}=; expires=${EXPIRED_COOKIE_DATE}; path=${path}; domain=${hostname};`;
93
89
  }
94
90
 
95
91
  export function clearAllClientCookies(
96
- options: ClearAllClientCookiesOptions = {},
92
+ options: ClearAllClientCookiesOptions = {},
97
93
  ): string[] {
98
- const {
99
- documentRef = document,
100
- cookieStore,
101
- includeRoot = false,
102
- cookieString,
103
- } = options;
104
-
105
- const entries = cookieString
106
- ? parseClientCookieNames(cookieString)
107
- : documentRef.cookie
108
- .split(/;\s*/)
109
- .map((entry) => {
110
- const eqPos = entry.indexOf("=");
111
- return eqPos > -1 ? entry.slice(0, eqPos).trim() : entry.trim();
112
- })
113
- .filter(Boolean);
114
-
115
- if (cookieStore) {
116
- for (const name of entries) {
117
- cookieStore.delete(name);
118
- }
119
- return entries;
120
- }
121
-
122
- const hostnameParts = window.location.hostname.split(".");
123
- const { pathname } = window.location;
124
-
125
- const paths = [pathname];
126
- if (includeRoot) {
127
- paths.unshift("/");
128
- }
129
-
130
- for (const name of entries) {
131
- if (!name) continue;
132
-
133
- for (const path of paths) {
134
- for (let i = 0; i < hostnameParts.length; i++) {
135
- const domain = hostnameParts.slice(i).join(".");
136
- documentRef.cookie = `${name}=; expires=${EXPIRED_COOKIE_DATE}; path=${path}; domain=${domain};`;
137
- }
138
- }
139
- }
140
-
141
- return entries;
94
+ const {
95
+ documentRef = document,
96
+ cookieStore,
97
+ includeRoot = false,
98
+ cookieString,
99
+ } = options;
100
+
101
+ const entries = cookieString
102
+ ? parseClientCookieNames(cookieString)
103
+ : documentRef.cookie
104
+ .split(/;\s*/)
105
+ .map((entry) => {
106
+ const eqPos = entry.indexOf("=");
107
+ return eqPos > -1 ? entry.slice(0, eqPos).trim() : entry.trim();
108
+ })
109
+ .filter(Boolean);
110
+
111
+ if (cookieStore) {
112
+ for (const name of entries) {
113
+ cookieStore.delete(name);
114
+ }
115
+ return entries;
116
+ }
117
+
118
+ const hostnameParts = window.location.hostname.split(".");
119
+ const { pathname } = window.location;
120
+
121
+ const paths = [pathname];
122
+ if (includeRoot) {
123
+ paths.unshift("/");
124
+ }
125
+
126
+ for (const name of entries) {
127
+ if (!name) continue;
128
+
129
+ for (const path of paths) {
130
+ for (let i = 0; i < hostnameParts.length; i++) {
131
+ const domain = hostnameParts.slice(i).join(".");
132
+ documentRef.cookie = `${name}=; expires=${EXPIRED_COOKIE_DATE}; path=${path}; domain=${domain};`;
133
+ }
134
+ }
135
+ }
136
+
137
+ return entries;
142
138
  }