@regardio/js 0.8.1 → 0.8.3
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/dist/http/index.d.mts +22 -6
- package/dist/http/index.mjs +62 -10
- package/package.json +7 -7
package/dist/http/index.d.mts
CHANGED
|
@@ -20,18 +20,34 @@ declare function setCookie(name: string, value: string, options?: CookieOptions)
|
|
|
20
20
|
*/
|
|
21
21
|
declare function getCookie(name: string): Promise<string | null>;
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* Delete a cookie by name using Cookie Store API with document.cookie fallback
|
|
24
|
+
* @param name - The name of the cookie to delete
|
|
25
|
+
* @param options - Cookie options (path and domain should match the original cookie)
|
|
26
|
+
*/
|
|
27
|
+
declare function deleteCookie(name: string, options?: Pick<CookieOptions, "path" | "domain">): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Set a cookie synchronously using document.cookie (client-side only)
|
|
24
30
|
* @param name - The name of the cookie
|
|
25
|
-
* @param value - The
|
|
31
|
+
* @param value - The value to set
|
|
26
32
|
* @param options - Cookie options
|
|
33
|
+
* @returns void
|
|
34
|
+
* @note This function is synchronous and only works in browser environments
|
|
27
35
|
*/
|
|
28
|
-
declare function
|
|
36
|
+
declare function setCookieSync(name: string, value: string, options?: CookieOptions): void;
|
|
29
37
|
/**
|
|
30
|
-
*
|
|
38
|
+
* Get a cookie by name synchronously using document.cookie (client-side only)
|
|
39
|
+
* @param name - The name of the cookie to get
|
|
40
|
+
* @returns The cookie value or null if not found
|
|
41
|
+
* @note This function is synchronous and only works in browser environments
|
|
42
|
+
*/
|
|
43
|
+
declare function getCookieSync(name: string): string | null;
|
|
44
|
+
/**
|
|
45
|
+
* Delete a cookie by name synchronously using document.cookie (client-side only)
|
|
31
46
|
* @param name - The name of the cookie to delete
|
|
32
47
|
* @param options - Cookie options (path and domain should match the original cookie)
|
|
48
|
+
* @note This function is synchronous and only works in browser environments
|
|
33
49
|
*/
|
|
34
|
-
declare function
|
|
50
|
+
declare function deleteCookieSync(name: string, options?: Pick<CookieOptions, "path" | "domain">): void;
|
|
35
51
|
//#endregion
|
|
36
52
|
//#region src/http/cookie.server.d.ts
|
|
37
53
|
interface CookieSerializeOptions {
|
|
@@ -120,4 +136,4 @@ declare function checkIfRouteIsActive(targetLink: string, currentRoute: string,
|
|
|
120
136
|
//#region src/http/request-helpers.d.ts
|
|
121
137
|
declare function getCleanUrl(request: Request): string;
|
|
122
138
|
//#endregion
|
|
123
|
-
export { type CookieOptions, type CookieSerializeOptions, checkIfRouteIsActive, createDomain, deleteCookie, deleteCookieFromResponse, getAllCookiesFromRequest, getCleanUrl, getCookie, getCookieFromRequest, isRouteActive, parseCookies, serializeCookie, setCookie, setCookieOnResponse,
|
|
139
|
+
export { type CookieOptions, type CookieSerializeOptions, checkIfRouteIsActive, createDomain, deleteCookie, deleteCookieFromResponse, deleteCookieSync, getAllCookiesFromRequest, getCleanUrl, getCookie, getCookieFromRequest, getCookieSync, isRouteActive, parseCookies, serializeCookie, setCookie, setCookieOnResponse, setCookieSync };
|
package/dist/http/index.mjs
CHANGED
|
@@ -77,15 +77,6 @@ async function getCookie(name) {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
|
-
* Update a cookie (alias for setCookie for clarity)
|
|
81
|
-
* @param name - The name of the cookie
|
|
82
|
-
* @param value - The new value to set
|
|
83
|
-
* @param options - Cookie options
|
|
84
|
-
*/
|
|
85
|
-
function updateCookie(name, value, options = {}) {
|
|
86
|
-
return setCookie(name, value, options);
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
80
|
* Delete a cookie by name using Cookie Store API with document.cookie fallback
|
|
90
81
|
* @param name - The name of the cookie to delete
|
|
91
82
|
* @param options - Cookie options (path and domain should match the original cookie)
|
|
@@ -113,6 +104,67 @@ async function deleteCookie(name, options = {}) {
|
|
|
113
104
|
else console.error(`Failed to delete cookie '${name}': Unknown error`);
|
|
114
105
|
}
|
|
115
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Set a cookie synchronously using document.cookie (client-side only)
|
|
109
|
+
* @param name - The name of the cookie
|
|
110
|
+
* @param value - The value to set
|
|
111
|
+
* @param options - Cookie options
|
|
112
|
+
* @returns void
|
|
113
|
+
* @note This function is synchronous and only works in browser environments
|
|
114
|
+
*/
|
|
115
|
+
function setCookieSync(name, value, options = {}) {
|
|
116
|
+
if (typeof window === "undefined") {
|
|
117
|
+
console.warn("Cannot set cookie on server side");
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
setViaDocumentCookie(name, value, options);
|
|
122
|
+
} catch (error) {
|
|
123
|
+
if (error instanceof Error) console.error(`Failed to set cookie '${name}':`, error.message);
|
|
124
|
+
else console.error(`Failed to set cookie '${name}': Unknown error`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Get a cookie by name synchronously using document.cookie (client-side only)
|
|
129
|
+
* @param name - The name of the cookie to get
|
|
130
|
+
* @returns The cookie value or null if not found
|
|
131
|
+
* @note This function is synchronous and only works in browser environments
|
|
132
|
+
*/
|
|
133
|
+
function getCookieSync(name) {
|
|
134
|
+
if (typeof window === "undefined") {
|
|
135
|
+
console.warn("Cannot get cookie on server side");
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
return getViaDocumentCookie(name);
|
|
140
|
+
} catch (error) {
|
|
141
|
+
if (error instanceof Error) console.error(`Failed to get cookie '${name}':`, error.message);
|
|
142
|
+
else console.error(`Failed to get cookie '${name}': Unknown error`);
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Delete a cookie by name synchronously using document.cookie (client-side only)
|
|
148
|
+
* @param name - The name of the cookie to delete
|
|
149
|
+
* @param options - Cookie options (path and domain should match the original cookie)
|
|
150
|
+
* @note This function is synchronous and only works in browser environments
|
|
151
|
+
*/
|
|
152
|
+
function deleteCookieSync(name, options = {}) {
|
|
153
|
+
if (typeof window === "undefined") {
|
|
154
|
+
console.warn("Cannot delete cookie on server side");
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
const expires = /* @__PURE__ */ new Date(0);
|
|
159
|
+
setViaDocumentCookie(name, "", {
|
|
160
|
+
...options,
|
|
161
|
+
expires
|
|
162
|
+
});
|
|
163
|
+
} catch (error) {
|
|
164
|
+
if (error instanceof Error) console.error(`Failed to delete cookie '${name}':`, error.message);
|
|
165
|
+
else console.error(`Failed to delete cookie '${name}': Unknown error`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
116
168
|
//#endregion
|
|
117
169
|
//#region src/http/cookie.server.ts
|
|
118
170
|
/**
|
|
@@ -268,4 +320,4 @@ function getCleanUrl(request) {
|
|
|
268
320
|
return url.toString();
|
|
269
321
|
}
|
|
270
322
|
//#endregion
|
|
271
|
-
export { checkIfRouteIsActive, createDomain, deleteCookie, deleteCookieFromResponse, getAllCookiesFromRequest, getCleanUrl, getCookie, getCookieFromRequest, isRouteActive, parseCookies, serializeCookie, setCookie, setCookieOnResponse,
|
|
323
|
+
export { checkIfRouteIsActive, createDomain, deleteCookie, deleteCookieFromResponse, deleteCookieSync, getAllCookiesFromRequest, getCleanUrl, getCookie, getCookieFromRequest, getCookieSync, isRouteActive, parseCookies, serializeCookie, setCookie, setCookieOnResponse, setCookieSync };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://www.schemastore.org/package.json",
|
|
3
3
|
"name": "@regardio/js",
|
|
4
|
-
"version": "0.8.
|
|
4
|
+
"version": "0.8.3",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Regardio JavaScript utilities",
|
|
7
7
|
"keywords": [
|
|
@@ -81,12 +81,12 @@
|
|
|
81
81
|
"react-router": "7.13.1"
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
|
-
"@regardio/dev": "1.
|
|
84
|
+
"@regardio/dev": "1.17.1",
|
|
85
85
|
"@total-typescript/ts-reset": "0.6.1",
|
|
86
|
-
"@types/node": "25.
|
|
87
|
-
"@vitest/coverage-v8": "4.0
|
|
88
|
-
"@vitest/ui": "4.0
|
|
89
|
-
"tsdown": "0.21.
|
|
90
|
-
"vitest": "4.0
|
|
86
|
+
"@types/node": "25.5.0",
|
|
87
|
+
"@vitest/coverage-v8": "4.1.0",
|
|
88
|
+
"@vitest/ui": "4.1.0",
|
|
89
|
+
"tsdown": "0.21.4",
|
|
90
|
+
"vitest": "4.1.0"
|
|
91
91
|
}
|
|
92
92
|
}
|