uibee 2.0.0 → 2.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uibee",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Shared components, functions and hooks for reuse across Login projects",
5
5
  "homepage": "https://github.com/Login-Linjeforening-for-IT/uibee#readme",
6
6
  "bugs": {
@@ -1,13 +1,17 @@
1
1
  export function getCookie(name: string): string | null {
2
+ if (typeof document === 'undefined') return null
2
3
  const matches = document.cookie.match(
3
4
  new RegExp(
4
- '(?:^|; )' + name.replace(/([.$?*|{}()[\]/\\+^])/g, '\\$1') + '=([^;]*)'
5
+ '(?:^|; )' +
6
+ name.replace(/([.$?*|{}()[\]/\\+^])/g, '\\$1') +
7
+ '=([^;]*)'
5
8
  )
6
9
  )
7
10
  return matches ? decodeURIComponent(matches[1]) : null
8
11
  }
9
12
 
10
13
  export function setCookie(name: string, value: string, days?: number) {
14
+ if (typeof document === 'undefined') return
11
15
  let expires = ''
12
16
 
13
17
  if (!value) {
@@ -25,14 +29,15 @@ export function setCookie(name: string, value: string, days?: number) {
25
29
  `${expires} path=/; SameSite=Lax`
26
30
  }
27
31
 
28
- export function removeCookies(...cookies: string[]) {
29
- for (const cookie of cookies) {
30
- removeCookie(cookie)
31
- }
32
- }
33
-
34
32
  export function removeCookie(name: string) {
33
+ if (typeof document === 'undefined') return
35
34
  document.cookie =
36
35
  `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; ` +
37
36
  'path=/; SameSite=Lax'
38
37
  }
38
+
39
+ export function removeCookies(...cookies: string[]) {
40
+ for (const cookie of cookies) {
41
+ removeCookie(cookie)
42
+ }
43
+ }