@naturalcycles/js-lib 15.6.0 → 15.7.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.
@@ -1,11 +1,10 @@
1
1
  declare global {
2
- interface Window {
3
- dataLayer: any[];
4
- gtag: (...args: any[]) => void;
5
- }
2
+ var dataLayer: any[];
3
+ var gtag: (...args: any[]) => void;
4
+ var hj: (...args: any[]) => void;
6
5
  }
7
6
  /**
8
- * Pass enabled = false to only init window.gtag, but not load actual gtag script (e.g in dev mode).
7
+ * Pass enabled = false to only init globalThis.gtag, but not load actual gtag script (e.g in dev mode).
9
8
  */
10
9
  export declare function loadGTag(gtagId: string, enabled?: boolean): Promise<void>;
11
10
  export declare function loadGTM(gtmId: string, enabled?: boolean): Promise<void>;
@@ -1,20 +1,19 @@
1
1
  import { isServerSide } from '../index.js';
2
2
  import { loadScript } from './script.util.js';
3
- /* eslint-disable unicorn/prefer-global-this */
4
3
  /**
5
- * Pass enabled = false to only init window.gtag, but not load actual gtag script (e.g in dev mode).
4
+ * Pass enabled = false to only init globalThis.gtag, but not load actual gtag script (e.g in dev mode).
6
5
  */
7
6
  export async function loadGTag(gtagId, enabled = true) {
8
7
  if (isServerSide())
9
8
  return;
10
- window.dataLayer ||= [];
11
- window.gtag ||= function gtag() {
9
+ globalThis.dataLayer ||= [];
10
+ globalThis.gtag ||= function gtag() {
12
11
  // biome-ignore lint/complexity/useArrowFunction: ok
13
12
  // biome-ignore lint/complexity/noArguments: ok
14
- window.dataLayer.push(arguments);
13
+ globalThis.dataLayer.push(arguments);
15
14
  };
16
- window.gtag('js', new Date());
17
- window.gtag('config', gtagId);
15
+ globalThis.gtag('js', new Date());
16
+ globalThis.gtag('config', gtagId);
18
17
  if (!enabled)
19
18
  return;
20
19
  await loadScript(`https://www.googletagmanager.com/gtag/js?id=${gtagId}`);
@@ -22,8 +21,8 @@ export async function loadGTag(gtagId, enabled = true) {
22
21
  export async function loadGTM(gtmId, enabled = true) {
23
22
  if (isServerSide())
24
23
  return;
25
- window.dataLayer ||= [];
26
- window.dataLayer.push({
24
+ globalThis.dataLayer ||= [];
25
+ globalThis.dataLayer.push({
27
26
  'gtm.start': Date.now(),
28
27
  event: 'gtm.js',
29
28
  });
@@ -49,6 +48,6 @@ export function loadHotjar(hjid) {
49
48
  r.async = 1;
50
49
  r.src = t + h._hjSettings.hjid + j + h._hjSettings.hjsv;
51
50
  a.append(r);
52
- })(window, document, 'https://static.hotjar.com/c/hotjar-', '.js?sv=');
51
+ })(globalThis, document, 'https://static.hotjar.com/c/hotjar-', '.js?sv=');
53
52
  /* eslint-enable */
54
53
  }
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod/v4';
2
+ import type { IsoDate } from '../types.js';
2
3
  export declare const TS_2500 = 16725225600;
3
4
  export declare const TS_2000 = 946684800;
4
5
  export declare const zUnixTimestamp: () => z.ZodNumber;
@@ -6,7 +7,7 @@ export declare const zUnixTimestamp2000: () => z.ZodNumber;
6
7
  export declare const zUnixTimestampMillis: () => z.ZodNumber;
7
8
  export declare const zUnixTimestampMillis2000: () => z.ZodNumber;
8
9
  export declare const zSemVer: () => z.ZodString;
9
- export declare const zIsoDate: () => z.ZodString;
10
+ export declare const zIsoDate: () => z.ZodCustom<IsoDate>;
10
11
  export declare const zEmail: () => z.ZodEmail;
11
12
  export declare const BASE62_REGEX: RegExp;
12
13
  export declare const BASE64_REGEX: RegExp;
@@ -27,7 +28,7 @@ export declare const customZodSchemas: {
27
28
  base64Url: () => z.ZodString;
28
29
  email: () => z.ZodEmail;
29
30
  ianaTimezone: () => z.ZodEnum;
30
- isoDate: () => z.ZodString;
31
+ isoDate: () => z.ZodCustom<IsoDate>;
31
32
  jwt: () => z.ZodString;
32
33
  slug: () => z.ZodString;
33
34
  semver: () => z.ZodString;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
3
  "type": "module",
4
- "version": "15.6.0",
4
+ "version": "15.7.0",
5
5
  "dependencies": {
6
6
  "tslib": "^2",
7
7
  "zod": "^3"
@@ -2,28 +2,25 @@ import { isServerSide } from '../index.js'
2
2
  import { loadScript } from './script.util.js'
3
3
 
4
4
  declare global {
5
- interface Window {
6
- dataLayer: any[]
7
- gtag: (...args: any[]) => void
8
- }
5
+ var dataLayer: any[]
6
+ var gtag: (...args: any[]) => void
7
+ var hj: (...args: any[]) => void
9
8
  }
10
9
 
11
- /* eslint-disable unicorn/prefer-global-this */
12
-
13
10
  /**
14
- * Pass enabled = false to only init window.gtag, but not load actual gtag script (e.g in dev mode).
11
+ * Pass enabled = false to only init globalThis.gtag, but not load actual gtag script (e.g in dev mode).
15
12
  */
16
13
  export async function loadGTag(gtagId: string, enabled = true): Promise<void> {
17
14
  if (isServerSide()) return
18
15
 
19
- window.dataLayer ||= []
20
- window.gtag ||= function gtag() {
16
+ globalThis.dataLayer ||= []
17
+ globalThis.gtag ||= function gtag() {
21
18
  // biome-ignore lint/complexity/useArrowFunction: ok
22
19
  // biome-ignore lint/complexity/noArguments: ok
23
- window.dataLayer.push(arguments)
20
+ globalThis.dataLayer.push(arguments)
24
21
  }
25
- window.gtag('js', new Date())
26
- window.gtag('config', gtagId)
22
+ globalThis.gtag('js', new Date())
23
+ globalThis.gtag('config', gtagId)
27
24
 
28
25
  if (!enabled) return
29
26
 
@@ -33,8 +30,8 @@ export async function loadGTag(gtagId: string, enabled = true): Promise<void> {
33
30
  export async function loadGTM(gtmId: string, enabled = true): Promise<void> {
34
31
  if (isServerSide()) return
35
32
 
36
- window.dataLayer ||= []
37
- window.dataLayer.push({
33
+ globalThis.dataLayer ||= []
34
+ globalThis.dataLayer.push({
38
35
  'gtm.start': Date.now(),
39
36
  event: 'gtm.js',
40
37
  })
@@ -63,6 +60,6 @@ export function loadHotjar(hjid: number): void {
63
60
  r.async = 1
64
61
  r.src = t + h._hjSettings.hjid + j + h._hjSettings.hjsv
65
62
  a.append(r)
66
- })(window, document, 'https://static.hotjar.com/c/hotjar-', '.js?sv=')
63
+ })(globalThis, document, 'https://static.hotjar.com/c/hotjar-', '.js?sv=')
67
64
  /* eslint-enable */
68
65
  }
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod/v4'
2
+ import type { IsoDate } from '../types.js'
2
3
 
3
4
  export const TS_2500 = 16725225600 // 2500-01-01
4
5
  export const TS_2000 = 946684800 // 2000-01-01
@@ -45,13 +46,13 @@ export const zSemVer = (): z.ZodString =>
45
46
  .regex(/^[0-9]+\.[0-9]+\.[0-9]+$/, 'Must be a SemVer string')
46
47
  .describe('SemVer')
47
48
 
48
- export const zIsoDate = (): z.ZodString =>
49
+ export const zIsoDate = (): z.ZodCustom<IsoDate> =>
49
50
  z
50
51
  .string()
51
52
  .refine(v => {
52
53
  return /^\d{4}-\d{2}-\d{2}$/.test(v)
53
54
  }, 'Must be an IsoDateString')
54
- .describe('IsoDateString')
55
+ .describe('IsoDateString') as unknown as z.ZodCustom<IsoDate>
55
56
 
56
57
  export const zEmail = (): z.ZodEmail => z.email().describe('Email')
57
58