@su-labs/visit-tracker 1.0.1 → 21.0.4
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/CHANGELOG.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [21.0.4] - 2026-02-03
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- **BREAKING:** Updated to Angular 21 support. This version requires Angular 21.0.0 or higher.
|
|
12
|
+
- Updated peer dependencies to `@angular/common: ^21.0.0` and `@angular/core: ^21.0.0`.
|
|
13
|
+
- Aligned package version with Angular major version for clearer compatibility (v21.x.x = Angular 21 support).
|
|
14
|
+
|
|
15
|
+
### Notes
|
|
16
|
+
- Projects using Angular 20 or below should continue using version 1.0.3.
|
|
17
|
+
- This release maintains full backward compatibility with the 1.x API - only the Angular version requirement has changed.
|
|
18
|
+
s
|
|
19
|
+
|
|
20
|
+
## [1.0.3] - 2025-08-30
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
- Removed unintended `.spec.ts` exports from the public API surface.
|
|
24
|
+
- Ensured `"license": "MIT"` is correctly reflected in the published package metadata.
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## [1.0.2] - 2025-08-30
|
|
28
|
+
|
|
29
|
+
### Note
|
|
30
|
+
- This version was published with incorrect package content and is deprecated. Please use `1.0.4`.
|
|
31
|
+
|
|
32
|
+
## [1.0.1] - 2025-08-27
|
|
33
|
+
|
|
34
|
+
### Changed
|
|
35
|
+
- Updated documentation (`README.md`) to reflect new scoped package import:
|
|
36
|
+
from `./su-visit-tracker.service` → `@su-labs/visit-tracker`.
|
|
37
|
+
|
|
38
|
+
## [1.0.0] - 2024-08-26
|
|
39
|
+
|
|
40
|
+
### Added
|
|
41
|
+
|
|
42
|
+
- Initial public release of the @su-labs/visit-tracker library.
|
|
43
|
+
- Introduction of SuVisitTrackerService, a lightweight service for tracking user visits.
|
|
44
|
+
- Reactive `Signal`s for `count`, `lastVisit`, `isTenthVisit`, and `isHundredthVisit`.
|
|
45
|
+
- Persistent storage of visit data in `localStorage`.
|
|
46
|
+
- Support for custom milestone visits via `milestoneVisits` configuration.
|
|
47
|
+
- Full support for modern Angular applications using `inject()` and `provideAppInitializer`.
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { signal, Injectable } from '@angular/core';
|
|
3
|
-
import { describe, beforeEach, vi, it, expect } from 'vitest';
|
|
4
3
|
|
|
5
4
|
class SuVisitTrackerService {
|
|
6
5
|
/** Key used for localStorage */
|
|
@@ -36,91 +35,14 @@ class SuVisitTrackerService {
|
|
|
36
35
|
const reachedMilestone = this._milestones.find(m => m === count);
|
|
37
36
|
this.milestone.set(reachedMilestone ?? null);
|
|
38
37
|
}
|
|
39
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
40
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
38
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: SuVisitTrackerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
39
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: SuVisitTrackerService, providedIn: 'root' });
|
|
41
40
|
}
|
|
42
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
41
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: SuVisitTrackerService, decorators: [{
|
|
43
42
|
type: Injectable,
|
|
44
43
|
args: [{ providedIn: 'root' }]
|
|
45
44
|
}] });
|
|
46
45
|
|
|
47
|
-
describe('SuVisitTrackerService', () => {
|
|
48
|
-
let service;
|
|
49
|
-
beforeEach(() => {
|
|
50
|
-
// Mock localStorage
|
|
51
|
-
const store = {};
|
|
52
|
-
vi.stubGlobal('localStorage', {
|
|
53
|
-
getItem: (key) => store[key] ?? null,
|
|
54
|
-
setItem: (key, value) => (store[key] = value),
|
|
55
|
-
removeItem: (key) => delete store[key],
|
|
56
|
-
clear: () => Object.keys(store).forEach((k) => delete store[k]),
|
|
57
|
-
});
|
|
58
|
-
service = new SuVisitTrackerService();
|
|
59
|
-
});
|
|
60
|
-
it('should initialize with count = 1 if localStorage is empty', () => {
|
|
61
|
-
service.init();
|
|
62
|
-
expect(service.count()).toBe(1);
|
|
63
|
-
expect(service.lastVisit()).toBeNull();
|
|
64
|
-
expect(service.milestone()).toBeNull();
|
|
65
|
-
});
|
|
66
|
-
it('should increment the count from existing localStorage data', () => {
|
|
67
|
-
// Simulate a previous visit count of 2
|
|
68
|
-
localStorage.setItem('su:visits', JSON.stringify({ count: 2, lastVisit: null }));
|
|
69
|
-
service.init();
|
|
70
|
-
// The new count should be 3
|
|
71
|
-
expect(service.count()).toBe(3);
|
|
72
|
-
});
|
|
73
|
-
it('should set the last visit date as an ISO string', () => {
|
|
74
|
-
service.init();
|
|
75
|
-
const storedStr = localStorage.getItem('su:visits');
|
|
76
|
-
expect(storedStr).not.toBeNull();
|
|
77
|
-
if (storedStr) {
|
|
78
|
-
const stored = JSON.parse(storedStr);
|
|
79
|
-
// Verify that a lastVisit property exists and is a valid ISO string
|
|
80
|
-
expect(typeof stored.lastVisit).toBe('string');
|
|
81
|
-
expect(new Date(stored.lastVisit).toISOString()).toBe(stored.lastVisit);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
it('should mark default milestone visits correctly', () => {
|
|
85
|
-
// Test for the default 10th visit milestone
|
|
86
|
-
localStorage.setItem('su:visits', JSON.stringify({ count: 9, lastVisit: null }));
|
|
87
|
-
service.init();
|
|
88
|
-
expect(service.milestone()).toBe(10);
|
|
89
|
-
// Test for the default 100th visit milestone
|
|
90
|
-
localStorage.setItem('su:visits', JSON.stringify({ count: 99, lastVisit: null }));
|
|
91
|
-
service.init();
|
|
92
|
-
expect(service.milestone()).toBe(100);
|
|
93
|
-
});
|
|
94
|
-
it('should accept a custom storage key', () => {
|
|
95
|
-
// Set a value in the custom key
|
|
96
|
-
localStorage.setItem('my-visits', JSON.stringify({ count: 0, lastVisit: null }));
|
|
97
|
-
// Initialize the service with the custom key
|
|
98
|
-
service.init({ storageKey: 'my-visits' });
|
|
99
|
-
const storedStr = localStorage.getItem('my-visits');
|
|
100
|
-
expect(storedStr).not.toBeNull();
|
|
101
|
-
if (storedStr) {
|
|
102
|
-
const stored = JSON.parse(storedStr);
|
|
103
|
-
expect(stored.count).toBe(1);
|
|
104
|
-
}
|
|
105
|
-
// Verify the default key was not used
|
|
106
|
-
expect(localStorage.getItem('su:visits')).toBeNull();
|
|
107
|
-
});
|
|
108
|
-
it('should mark custom milestone visits correctly with a single signal', () => {
|
|
109
|
-
// Test for a custom 3rd visit milestone
|
|
110
|
-
localStorage.setItem('su:visits', JSON.stringify({ count: 2, lastVisit: null }));
|
|
111
|
-
service.init({ milestoneVisits: [3, 5] });
|
|
112
|
-
expect(service.milestone()).toBe(3);
|
|
113
|
-
// Test for a custom 5th visit milestone
|
|
114
|
-
localStorage.setItem('su:visits', JSON.stringify({ count: 4, lastVisit: null }));
|
|
115
|
-
service.init({ milestoneVisits: [3, 5] });
|
|
116
|
-
expect(service.milestone()).toBe(5);
|
|
117
|
-
// Test for a non-milestone visit
|
|
118
|
-
localStorage.setItem('su:visits', JSON.stringify({ count: 5, lastVisit: null }));
|
|
119
|
-
service.init({ milestoneVisits: [3, 5] });
|
|
120
|
-
expect(service.milestone()).toBeNull();
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
|
|
124
46
|
/*
|
|
125
47
|
* Public API Surface of visit-tracker
|
|
126
48
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"su-labs-visit-tracker.mjs","sources":["../../../../projects/su-labs/visit-tracker/src/lib/visit-tracker.service.ts","../../../../projects/su-labs/visit-tracker/src/lib/visit-tracker.service.spec.ts","../../../../projects/su-labs/visit-tracker/src/public-api.ts","../../../../projects/su-labs/visit-tracker/src/su-labs-visit-tracker.ts"],"sourcesContent":["import { Injectable, signal, WritableSignal } from '@angular/core';\nimport { SuVisitData, SuVisitTrackerConfig } from './visit-tracker.types';\n\n@Injectable({ providedIn: 'root' })\nexport class SuVisitTrackerService {\n /** Key used for localStorage */\n private storageKey = 'su:visits';\n\n /** Milestones to track */\n private _milestones: number[] = [10, 100];\n\n /** Current visit count */\n public count: WritableSignal<number> = signal(0);\n\n /** Last visit date as ISO string */\n public lastVisit: WritableSignal<string | null> = signal(null);\n\n /** The number of the milestone reached on the current visit, or null */\n public milestone: WritableSignal<number | null> = signal(null);\n\n /** Initialize the service and update signals */\n public init(config?: SuVisitTrackerConfig): void {\n if (config?.storageKey) {\n this.storageKey = config.storageKey;\n }\n if (config?.milestoneVisits && Array.isArray(config.milestoneVisits)) {\n this._milestones = config.milestoneVisits.sort((a, b) => a - b);\n }\n\n const storedData = localStorage.getItem(this.storageKey);\n const stored: Partial<SuVisitData> = storedData ? JSON.parse(storedData) : {};\n\n const prevCount = stored.count ?? 0;\n const prevDate = stored.lastVisit ?? null;\n const newCount = prevCount + 1;\n\n this.count.set(newCount);\n this.lastVisit.set(prevDate);\n\n this.updateMilestone(newCount);\n\n localStorage.setItem(\n this.storageKey,\n JSON.stringify({ count: newCount, lastVisit: new Date().toISOString() }),\n );\n }\n\n /** Update the milestone signal based on the current count */\n private updateMilestone(count: number): void {\n const reachedMilestone = this._milestones.find(m => m === count);\n this.milestone.set(reachedMilestone ?? null);\n }\n}\n","import { beforeEach, describe, expect, it, vi } from 'vitest';\nimport { SuVisitTrackerService } from './visit-tracker.service';\n\ndescribe('SuVisitTrackerService', () => {\n let service: SuVisitTrackerService;\n\n beforeEach(() => {\n // Mock localStorage\n const store: Record<string, string> = {};\n vi.stubGlobal('localStorage', {\n getItem: (key: string) => store[key] ?? null,\n setItem: (key: string, value: string) => (store[key] = value),\n removeItem: (key: string) => delete store[key],\n clear: () => Object.keys(store).forEach((k) => delete store[k]),\n });\n\n service = new SuVisitTrackerService();\n });\n\n it('should initialize with count = 1 if localStorage is empty', () => {\n service.init();\n expect(service.count()).toBe(1);\n expect(service.lastVisit()).toBeNull();\n expect(service.milestone()).toBeNull();\n });\n\n it('should increment the count from existing localStorage data', () => {\n // Simulate a previous visit count of 2\n localStorage.setItem(\n 'su:visits',\n JSON.stringify({ count: 2, lastVisit: null }),\n );\n service.init();\n // The new count should be 3\n expect(service.count()).toBe(3);\n });\n\n it('should set the last visit date as an ISO string', () => {\n service.init();\n const storedStr = localStorage.getItem('su:visits');\n expect(storedStr).not.toBeNull();\n if (storedStr) {\n const stored = JSON.parse(storedStr);\n // Verify that a lastVisit property exists and is a valid ISO string\n expect(typeof stored.lastVisit).toBe('string');\n expect(new Date(stored.lastVisit).toISOString()).toBe(stored.lastVisit);\n }\n });\n\n it('should mark default milestone visits correctly', () => {\n // Test for the default 10th visit milestone\n localStorage.setItem(\n 'su:visits',\n JSON.stringify({ count: 9, lastVisit: null }),\n );\n service.init();\n expect(service.milestone()).toBe(10);\n\n // Test for the default 100th visit milestone\n localStorage.setItem(\n 'su:visits',\n JSON.stringify({ count: 99, lastVisit: null }),\n );\n service.init();\n expect(service.milestone()).toBe(100);\n });\n\n it('should accept a custom storage key', () => {\n // Set a value in the custom key\n localStorage.setItem(\n 'my-visits',\n JSON.stringify({ count: 0, lastVisit: null }),\n );\n // Initialize the service with the custom key\n service.init({ storageKey: 'my-visits' });\n const storedStr = localStorage.getItem('my-visits');\n expect(storedStr).not.toBeNull();\n if (storedStr) {\n const stored = JSON.parse(storedStr);\n expect(stored.count).toBe(1);\n }\n // Verify the default key was not used\n expect(localStorage.getItem('su:visits')).toBeNull();\n });\n\n it('should mark custom milestone visits correctly with a single signal', () => {\n // Test for a custom 3rd visit milestone\n localStorage.setItem(\n 'su:visits',\n JSON.stringify({ count: 2, lastVisit: null }),\n );\n service.init({ milestoneVisits: [3, 5] });\n expect(service.milestone()).toBe(3);\n\n // Test for a custom 5th visit milestone\n localStorage.setItem(\n 'su:visits',\n JSON.stringify({ count: 4, lastVisit: null }),\n );\n service.init({ milestoneVisits: [3, 5] });\n expect(service.milestone()).toBe(5);\n\n // Test for a non-milestone visit\n localStorage.setItem(\n 'su:visits',\n JSON.stringify({ count: 5, lastVisit: null }),\n );\n service.init({ milestoneVisits: [3, 5] });\n expect(service.milestone()).toBeNull();\n });\n});","/*\n * Public API Surface of visit-tracker\n */\n\nexport * from './lib/visit-tracker.types';\nexport * from './lib/visit-tracker.service';\nexport * from './lib/visit-tracker.service.spec';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;MAIa,qBAAqB,CAAA;;IAExB,UAAU,GAAG,WAAW;;AAGxB,IAAA,WAAW,GAAa,CAAC,EAAE,EAAE,GAAG,CAAC;;AAGlC,IAAA,KAAK,GAA2B,MAAM,CAAC,CAAC,iDAAC;;AAGzC,IAAA,SAAS,GAAkC,MAAM,CAAC,IAAI,qDAAC;;AAGvD,IAAA,SAAS,GAAkC,MAAM,CAAC,IAAI,qDAAC;;AAGvD,IAAA,IAAI,CAAC,MAA6B,EAAA;AACvC,QAAA,IAAI,MAAM,EAAE,UAAU,EAAE;AACtB,YAAA,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU;;AAErC,QAAA,IAAI,MAAM,EAAE,eAAe,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC,EAAE;YACpE,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,E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EACX,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAC9C;AACD,QAAA,OAAO,CAAC,IAAI,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QACzC,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,QAAQ,EAAE;AACxC,KAAC,CAAC;AACJ,CAAC,CAAC;;AC9GF;;AAEG;;ACFH;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"su-labs-visit-tracker.mjs","sources":["../../../../projects/su-labs/visit-tracker/src/lib/visit-tracker.service.ts","../../../../projects/su-labs/visit-tracker/src/public-api.ts","../../../../projects/su-labs/visit-tracker/src/su-labs-visit-tracker.ts"],"sourcesContent":["import { Injectable, signal, WritableSignal } from '@angular/core';\nimport { SuVisitData, SuVisitTrackerConfig } from './visit-tracker.types';\n\n@Injectable({ providedIn: 'root' })\nexport class SuVisitTrackerService {\n /** Key used for localStorage */\n private storageKey = 'su:visits';\n\n /** Milestones to track */\n private _milestones: number[] = [10, 100];\n\n /** Current visit count */\n public count: WritableSignal<number> = signal(0);\n\n /** Last visit date as ISO string */\n public lastVisit: WritableSignal<string | null> = signal(null);\n\n /** The number of the milestone reached on the current visit, or null */\n public milestone: WritableSignal<number | null> = signal(null);\n\n /** Initialize the service and update signals */\n public init(config?: SuVisitTrackerConfig): void {\n if (config?.storageKey) {\n this.storageKey = config.storageKey;\n }\n if (config?.milestoneVisits && Array.isArray(config.milestoneVisits)) {\n this._milestones = config.milestoneVisits.sort((a, b) => a - b);\n }\n\n const storedData = localStorage.getItem(this.storageKey);\n const stored: Partial<SuVisitData> = storedData ? JSON.parse(storedData) : {};\n\n const prevCount = stored.count ?? 0;\n const prevDate = stored.lastVisit ?? null;\n const newCount = prevCount + 1;\n\n this.count.set(newCount);\n this.lastVisit.set(prevDate);\n\n this.updateMilestone(newCount);\n\n localStorage.setItem(\n this.storageKey,\n JSON.stringify({ count: newCount, lastVisit: new Date().toISOString() }),\n );\n }\n\n /** Update the milestone signal based on the current count */\n private updateMilestone(count: number): void {\n const reachedMilestone = this._milestones.find(m => m === count);\n this.milestone.set(reachedMilestone ?? null);\n }\n}\n","/*\n * Public API Surface of visit-tracker\n */\n\nexport * from './lib/visit-tracker.types';\nexport * from './lib/visit-tracker.service';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;MAIa,qBAAqB,CAAA;;IAExB,UAAU,GAAG,WAAW;;AAGxB,IAAA,WAAW,GAAa,CAAC,EAAE,EAAE,GAAG,CAAC;;AAGlC,IAAA,KAAK,GAA2B,MAAM,CAAC,CAAC,iDAAC;;AAGzC,IAAA,SAAS,GAAkC,MAAM,CAAC,IAAI,qDAAC;;AAGvD,IAAA,SAAS,GAAkC,MAAM,CAAC,IAAI,qDAAC;;AAGvD,IAAA,IAAI,CAAC,MAA6B,EAAA;AACvC,QAAA,IAAI,MAAM,EAAE,UAAU,EAAE;AACtB,YAAA,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU;QACrC;AACA,QAAA,IAAI,MAAM,EAAE,eAAe,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC,EAAE;YACpE,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACjE;QAEA,MAAM,UAAU,GAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC;AACxD,QAAA,MAAM,MAAM,GAAyB,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE;AAE7E,QAAA,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,IAAI,CAAC;AACnC,QAAA,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,IAAI,IAAI;AACzC,QAAA,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",
|
|
8
|
+
"localStorage",
|
|
9
|
+
"milestones",
|
|
10
|
+
"signals",
|
|
11
|
+
"reactive",
|
|
12
|
+
"utility",
|
|
13
|
+
"service",
|
|
14
|
+
"metrics"
|
|
15
|
+
],
|
|
4
16
|
"peerDependencies": {
|
|
5
|
-
"@angular/common": "^
|
|
6
|
-
"@angular/core": "^
|
|
17
|
+
"@angular/common": "^21.0.0",
|
|
18
|
+
"@angular/core": "^21.0.0"
|
|
7
19
|
},
|
|
8
20
|
"dependencies": {
|
|
9
21
|
"tslib": "^2.3.0"
|
|
10
22
|
},
|
|
23
|
+
"homepage": "https://github.com/Greezaaa/settings-utils-lib/tree/main/projects/su-labs/font-size#readme",
|
|
24
|
+
"author": {
|
|
25
|
+
"name": "Yevheniy Alekseyev",
|
|
26
|
+
"email": "yev.alekseyev@gmail.com",
|
|
27
|
+
"url": "https://github.com/Greezaaa"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/Greezaaa/settings-utils-lib.git",
|
|
32
|
+
"directory": "projects/su-labs/font-size"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/Greezaaa/settings-utils-lib/issues"
|
|
36
|
+
},
|
|
11
37
|
"sideEffects": false,
|
|
38
|
+
"license": "MIT",
|
|
12
39
|
"module": "fesm2022/su-labs-visit-tracker.mjs",
|
|
13
|
-
"typings": "
|
|
40
|
+
"typings": "types/su-labs-visit-tracker.d.ts",
|
|
14
41
|
"exports": {
|
|
15
42
|
"./package.json": {
|
|
16
43
|
"default": "./package.json"
|
|
17
44
|
},
|
|
18
45
|
".": {
|
|
19
|
-
"types": "./
|
|
46
|
+
"types": "./types/su-labs-visit-tracker.d.ts",
|
|
20
47
|
"default": "./fesm2022/su-labs-visit-tracker.mjs"
|
|
21
48
|
}
|
|
22
49
|
}
|
|
File without changes
|