@js-toolkit/web-utils 1.50.0 → 1.51.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/ga/DataLayerProxy.js +1 -1
- package/ga/getHandler.d.ts +16 -8
- package/ga/getHandler.js +1 -1
- package/ga/types.d.ts +9 -28
- package/ga/types.js +1 -1
- package/media/mse/getMediaSource.d.ts +12 -0
- package/package.json +8 -8
- package/platform/getIOSVersion.js +1 -1
- package/platform/getPlatformInfo.d.ts +7 -0
- package/platform/getPlatformInfo.js +1 -0
- package/platform/isAndroid.js +1 -1
- package/platform/isIOS.js +1 -1
- package/platform/isMacOS.js +1 -1
- package/platform/isMobile.js +1 -1
- package/platform/isSafari.js +1 -1
- package/platform/ua.d.ts +0 -6
- package/platform/ua.js +0 -1
package/ga/DataLayerProxy.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getHandler}from"./getHandler";export class DataLayerProxy{constructor(r){const
|
|
1
|
+
import{getHandler}from"./getHandler";export class DataLayerProxy{constructor(r){const t=getHandler("auto",r);if(!t)throw new Error("Google Analytics handler is not created.");this.handler=t}push(r){this.handler(r)}}
|
package/ga/getHandler.d.ts
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
import { type GAEventMessage } from './iframeMessenger';
|
|
2
|
-
import './types';
|
|
2
|
+
import type { GTMEventData } from './types';
|
|
3
3
|
export interface GAEventData {
|
|
4
|
-
eventCategory: string;
|
|
5
|
-
action: string;
|
|
6
|
-
label: string | undefined;
|
|
7
|
-
|
|
4
|
+
readonly eventCategory: string;
|
|
5
|
+
readonly action: string;
|
|
6
|
+
readonly label: string | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Идентификатор потока данных
|
|
9
|
+
* (https://support.google.com/analytics/answer/12270356?hl=ru).
|
|
10
|
+
*
|
|
11
|
+
* Можно не указывать, если:
|
|
12
|
+
* - используется Google Tag Manager (gtm.js) с настроенным тегом, в котором самостоятельно указан идентификатор потока данных.
|
|
13
|
+
* - используется Google Tag (gtag.js) с указанным идентификатором потока данных по умолчанию.
|
|
14
|
+
*/
|
|
15
|
+
readonly measurementId: string | undefined;
|
|
8
16
|
}
|
|
9
17
|
export interface GADataHandler<D extends GAEventData> {
|
|
10
18
|
(data: D): void;
|
|
11
19
|
}
|
|
12
|
-
type GALibType = 'gtm' | 'gtag' | 'ga' | 'iframe' | 'auto';
|
|
20
|
+
type GALibType = 'gtm' | 'gtag' | /* 'ga' | */ 'iframe' | 'auto';
|
|
13
21
|
export type GAEventDataTransformer<D extends GAEventData, L extends Extract<GALibType, 'gtm' | 'iframe'>> = (data: D) => {
|
|
14
|
-
gtm: GTMEventData;
|
|
15
|
-
iframe: GAEventMessage<string, D>;
|
|
22
|
+
readonly gtm: GTMEventData;
|
|
23
|
+
readonly iframe: GAEventMessage<string, D>;
|
|
16
24
|
}[L];
|
|
17
25
|
export type GAEventDataTransformerMap<D extends GAEventData, L extends Extract<GALibType, 'gtm' | 'iframe'> = Extract<GALibType, 'gtm' | 'iframe'>> = L extends L ? Record<L, GAEventDataTransformer<D, L>> : never;
|
|
18
26
|
export declare function getHandler<D extends GAEventData, L extends GALibType>(gaLib: L, transformers: L extends 'auto' | 'gtm' | 'iframe' ? GAEventDataTransformerMap<D> : undefined): GADataHandler<D> | undefined;
|
package/ga/getHandler.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{iframeMessenger}from"./iframeMessenger";
|
|
1
|
+
import{iframeMessenger}from"./iframeMessenger";function gtmHandler(e,t,n){e.push(t(n))}function gtagHandler(e,t){const{action:n,eventCategory:a,measurementId:r,label:o}=t;e("event",n,{send_to:r,event_category:a,event_label:o,value:void 0})}export function getHandler(e,t){switch(e){case"auto":return window.gtag?getHandler("gtag",void 0):window.dataLayer?getHandler("gtm",t):window.parent!==window?getHandler("iframe",t):void 0;case"iframe":return e=>{const n=t.iframe(e);iframeMessenger(n.type,n.event)};case"gtm":{const{dataLayer:e}=window;return e?n=>{gtmHandler(e,t.gtm,n)}:void 0}case"gtag":return window.gtag?gtagHandler.bind(void 0,window.gtag):void 0;default:throw new Error(`Unknown GA lib type '${e}'.`)}}
|
package/ga/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
interface GTMEventData {
|
|
1
|
+
export interface GTMEventData {
|
|
2
2
|
event: string;
|
|
3
3
|
}
|
|
4
4
|
interface GTMDataLayer<D extends GTMEventData> {
|
|
@@ -11,31 +11,12 @@ interface GTagEventData {
|
|
|
11
11
|
send_to: string | undefined;
|
|
12
12
|
}
|
|
13
13
|
type GTagParams = [type: 'event', event: string, data: GTagEventData];
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
type GACommandParams = [command: 'send', data: GAObjectEventData];
|
|
22
|
-
interface GATracker {
|
|
23
|
-
get(field: string): unknown;
|
|
24
|
-
send(data: GAObjectEventData): void;
|
|
25
|
-
}
|
|
26
|
-
interface GAObject {
|
|
27
|
-
readonly loaded?: boolean | undefined;
|
|
28
|
-
getAll(): GATracker[];
|
|
29
|
-
(...params: GACommandParams): void;
|
|
30
|
-
(readyCallback: VoidFunction): void;
|
|
31
|
-
}
|
|
32
|
-
interface Window {
|
|
33
|
-
/** Universal Analytics object name, default `ga`. */
|
|
34
|
-
GoogleAnalyticsObject?: string | undefined;
|
|
35
|
-
/** Universal Analytics without gtag. */
|
|
36
|
-
ga?: GAObject | undefined;
|
|
37
|
-
/** Global Site Tag */
|
|
38
|
-
gtag?: ((...params: GTagParams) => void) | undefined;
|
|
39
|
-
/** Google Tag Manager */
|
|
40
|
-
dataLayer?: GTMDataLayer<GTMEventData> | undefined;
|
|
14
|
+
declare global {
|
|
15
|
+
interface Window {
|
|
16
|
+
/** Google tag */
|
|
17
|
+
gtag?: ((...params: GTagParams) => void) | undefined;
|
|
18
|
+
/** Google Tag Manager */
|
|
19
|
+
dataLayer?: GTMDataLayer<GTMEventData> | undefined;
|
|
20
|
+
}
|
|
41
21
|
}
|
|
22
|
+
export {};
|
package/ga/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export{};
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
declare global {
|
|
2
|
+
interface ManagedMediaSourceEventMap extends MediaSourceEventMap {
|
|
3
|
+
startstreaming: Event;
|
|
4
|
+
endstreaming: Event;
|
|
5
|
+
}
|
|
6
|
+
interface ManagedMediaSource extends MediaSource {
|
|
7
|
+
readonly streaming: boolean;
|
|
8
|
+
onstartstreaming: ((this: ManagedMediaSource, ev: Event) => any) | null;
|
|
9
|
+
onendstreaming: ((this: ManagedMediaSource, ev: Event) => any) | null;
|
|
10
|
+
addEventListener<K extends keyof ManagedMediaSourceEventMap>(type: K, listener: (this: MediaSource, ev: ManagedMediaSourceEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
|
11
|
+
removeEventListener<K extends keyof ManagedMediaSourceEventMap>(type: K, listener: (this: MediaSource, ev: ManagedMediaSourceEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
|
|
12
|
+
}
|
|
2
13
|
interface Window {
|
|
3
14
|
WebKitMediaSource?: typeof MediaSource;
|
|
15
|
+
ManagedMediaSource?: ManagedMediaSource;
|
|
4
16
|
}
|
|
5
17
|
}
|
|
6
18
|
export declare function getMediaSource(): typeof MediaSource | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@js-toolkit/web-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.51.1",
|
|
4
4
|
"description": "Web utils",
|
|
5
5
|
"author": "VZH",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"@js-toolkit/node-utils": "^1.2.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@js-toolkit/configs": "^3.
|
|
24
|
-
"@js-toolkit/utils": "^1.
|
|
23
|
+
"@js-toolkit/configs": "^3.90.0",
|
|
24
|
+
"@js-toolkit/utils": "^1.51.0",
|
|
25
25
|
"@types/uuid": "^9.0.7",
|
|
26
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
27
|
-
"@typescript-eslint/parser": "^6.
|
|
26
|
+
"@typescript-eslint/eslint-plugin": "^6.19.1",
|
|
27
|
+
"@typescript-eslint/parser": "^6.19.1",
|
|
28
28
|
"copyfiles": "^2.4.1",
|
|
29
29
|
"eslint": "^8.56.0",
|
|
30
30
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
@@ -32,14 +32,14 @@
|
|
|
32
32
|
"eslint-plugin-import": "^2.29.1",
|
|
33
33
|
"eslint-plugin-prettier": "^5.1.3",
|
|
34
34
|
"eventemitter3": "^5.0.1",
|
|
35
|
-
"prettier": "^3.2.
|
|
35
|
+
"prettier": "^3.2.4",
|
|
36
36
|
"reconnecting-websocket": "^4.4.0",
|
|
37
37
|
"rimraf": "^5.0.5",
|
|
38
|
-
"terser": "^5.
|
|
38
|
+
"terser": "^5.27.0",
|
|
39
39
|
"typescript": "^5.3.3",
|
|
40
40
|
"ua-parser-js": "^2.0.0-beta.1",
|
|
41
41
|
"uuid": "^9.0.1",
|
|
42
|
-
"webpack": "^5.
|
|
42
|
+
"webpack": "^5.90.0",
|
|
43
43
|
"yargs": "^17.7.2"
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{getCachedPlatformInfo}from"./getPlatformInfo";import{isIOS}from"./isIOS";let memo;export function getIOSVersion(){if(void 0===memo){const o=getCachedPlatformInfo();if(!o)return;const{os:t}=o,r=isIOS()&&t.version&&/(\d+)\.(\d+)(?:\.(\d+))?/.exec(t.version);memo=r?{major:parseInt(r[1],10)||0,minor:parseInt(r[2],10)||0,patch:parseInt(r[3],10)||0,toString(){return`${this.major}_${this.minor}_${this.patch}`}}:null}return null!=memo?memo:void 0}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="ua-parser-js/src/main/ua-parser" />
|
|
2
|
+
type PlatformInfo = DeepReadonly<OmitStrict<UAParser.IResult, 'withClientHints' | 'withFeatureCheck'>> & {
|
|
3
|
+
toStringObject(): Record<Keys<ExcludeKeysOfType<UAParser.IResult, AnyFunction>>, string>;
|
|
4
|
+
};
|
|
5
|
+
export declare function getPlatformInfo(): Promise<PlatformInfo>;
|
|
6
|
+
export declare function getCachedPlatformInfo(): PlatformInfo | undefined;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__awaiter}from"tslib";import{UAParser}from"ua-parser-js";let result,promise;export function getPlatformInfo(){return __awaiter(this,void 0,void 0,(function*(){return null==result&&(promise=null!=promise?promise:Promise.resolve(new UAParser(navigator.userAgent).getResult().withFeatureCheck().withClientHints()),result=Object.assign(Object.assign({},yield promise),{toStringObject(){return Object.getOwnPropertyNames(this).reduce(((t,e)=>{const r=e;return null!=this[r]&&"function"!=typeof this[r]&&(t[r]=this[r].toString()),t}),{})}}),promise=void 0),result}))}export function getCachedPlatformInfo(){return null==result&&(console.warn("PlatformInfo is not ready yet."),getPlatformInfo()),result}
|
package/platform/isAndroid.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{getCachedPlatformInfo}from"./getPlatformInfo";export function isAndroid(){const o=getCachedPlatformInfo();if(!o)return!1;const n=o.os.name;return"Android"===n||"Android-x86"===n}
|
package/platform/isIOS.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{getCachedPlatformInfo}from"./getPlatformInfo";import{isMobile}from"./isMobile";export function isIOS(){const o=getCachedPlatformInfo();return!!o&&("iOS"===o.os.name||isMobile()&&"Apple"===o.device.vendor)}
|
package/platform/isMacOS.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{getCachedPlatformInfo}from"./getPlatformInfo";import{isMobile}from"./isMobile";export function isMacOS(){const o=getCachedPlatformInfo();if(!o)return!1;const t=o.os.name;return("Mac OS"===t||"macOS"===t)&&!isMobile()}
|
package/platform/isMobile.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{getCachedPlatformInfo}from"./getPlatformInfo";export function isMobile(){const o=getCachedPlatformInfo();if(!o)return!1;const t=o.device.type;return!!("mobile"===t||"tablet"===t||!t&&"Apple"===o.device.vendor&&navigator.maxTouchPoints&&navigator.maxTouchPoints>2)}
|
package/platform/isSafari.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{getCachedPlatformInfo}from"./getPlatformInfo";import{isIOS}from"./isIOS";import{isMacOS}from"./isMacOS";export function isSafari(){const r=getCachedPlatformInfo();if(!r)return!1;const o=r.browser.name;return"Safari"===o||"Mobile Safari"===o||"WebKit"===o&&(isIOS()||isMacOS())}
|
package/platform/ua.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
type UAInfo = DeepReadonly<OmitStrict<UAParser.IResult, 'withClientHints' | 'withFeatureCheck'>> & {
|
|
2
|
-
toStringObject(): Record<Keys<ExcludeKeysOfType<UAParser.IResult, AnyFunction>>, string>;
|
|
3
|
-
};
|
|
4
|
-
export declare function getUAInfo(): Promise<UAInfo>;
|
|
5
|
-
export declare function getCachedUAInfo(): UAInfo | undefined;
|
|
6
|
-
export {};
|
package/platform/ua.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{__awaiter}from"tslib";import{UAParser}from"ua-parser-js";let result,promise;export function getUAInfo(){return __awaiter(this,void 0,void 0,(function*(){return null==result&&(promise=null!=promise?promise:Promise.resolve(new UAParser(navigator.userAgent).getResult().withFeatureCheck().withClientHints()),result=Object.assign(Object.assign({},yield promise),{toStringObject(){return Object.getOwnPropertyNames(this).reduce(((e,t)=>{const r=t;return null!=this[r]&&"function"!=typeof this[r]&&(e[r]=this[r].toString()),e}),{})}}),promise=void 0),result}))}export function getCachedUAInfo(){return null==result&&(console.warn("UAInfo is not ready yet."),getUAInfo()),result}
|