@ciwergrp/nuxid 1.15.0 → 1.16.0

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/module.d.mts CHANGED
@@ -130,10 +130,12 @@ interface ElementPlusOptions {
130
130
  }
131
131
  type ElementPlusFeatureInput = boolean | Partial<ElementPlusOptions> | Record<string, any> | undefined;
132
132
 
133
- type HelperTimezoneSource = 'query' | 'cookie' | 'localStorage' | 'static';
133
+ type HelperTimezoneSource = 'query' | 'cookie' | 'localStorage' | 'static' | 'browser';
134
134
  interface HelperTimezoneOptions {
135
135
  /**
136
136
  * Where timezone value should be read from
137
+ * `browser` uses `Intl.DateTimeFormat().resolvedOptions().timeZone` on client-side.
138
+ * During SSR, it falls back to `fallback`.
137
139
  * @default 'cookie'
138
140
  */
139
141
  source?: HelperTimezoneSource;
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ciwergrp/nuxid",
3
3
  "configKey": "nuxid",
4
- "version": "1.15.0",
4
+ "version": "1.16.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -4,4 +4,5 @@ export declare function availableTimezones(): TimezoneId[];
4
4
  export declare function currentTimezone(): Readonly<Ref<TimezoneId>>;
5
5
  export declare function isTimezoneId(value: string): value is TimezoneId;
6
6
  export declare function normalizeTimezone(rawValue?: string | null): TimezoneId | undefined;
7
+ export declare function detectBrowserTimezone(): string | undefined;
7
8
  export declare function setCurrentTimezone(value: string | undefined, fallback?: TimezoneId): TimezoneId;
@@ -32,6 +32,13 @@ export function normalizeTimezone(rawValue) {
32
32
  }
33
33
  return void 0;
34
34
  }
35
+ export function detectBrowserTimezone() {
36
+ try {
37
+ return Intl.DateTimeFormat().resolvedOptions().timeZone;
38
+ } catch {
39
+ return void 0;
40
+ }
41
+ }
35
42
  export function setCurrentTimezone(value, fallback = "UTC") {
36
43
  const normalized = normalizeTimezone(value) ?? fallback;
37
44
  currentTimezoneState.value = normalized;
@@ -1,6 +1,6 @@
1
1
  import { defineNuxtPlugin } from "#app";
2
2
  import { useCookie, useRoute, useRuntimeConfig } from "nuxt/app";
3
- import { setCurrentTimezone } from "./date/timezone.js";
3
+ import { detectBrowserTimezone, setCurrentTimezone } from "./date/timezone.js";
4
4
  export default defineNuxtPlugin(() => {
5
5
  const config = useRuntimeConfig();
6
6
  const timezoneConfig = config.public.nuxid?.helper?.config?.timezone ?? {};
@@ -19,7 +19,11 @@ export default defineNuxtPlugin(() => {
19
19
  } else if (source === "cookie") {
20
20
  value = useCookie(key).value;
21
21
  } else if (import.meta.client) {
22
- value = localStorage.getItem(key) ?? void 0;
22
+ if (source === "browser") {
23
+ value = detectBrowserTimezone();
24
+ } else {
25
+ value = localStorage.getItem(key) ?? void 0;
26
+ }
23
27
  }
24
28
  setCurrentTimezone(value, fallback);
25
29
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ciwergrp/nuxid",
3
- "version": "1.15.0",
3
+ "version": "1.16.0",
4
4
  "description": "All-in-one essential modules for Nuxt",
5
5
  "repository": {
6
6
  "type": "git",