@su-labs/visit-tracker 1.0.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/LICENSE +21 -0
- package/README.md +141 -0
- package/fesm2022/su-labs-visit-tracker.mjs +133 -0
- package/fesm2022/su-labs-visit-tracker.mjs.map +1 -0
- package/index.d.ts +41 -0
- package/package.json +23 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Yevheniy Alekseyev <yev.alekseyev@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# SuVisitTrackerService
|
|
2
|
+
|
|
3
|
+
A lightweight Angular service to track user visits. Provides reactive signals for visit count, last visit date, and milestone visits.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
* Tracks number of visits per user.
|
|
8
|
+
* Persists visit data in `localStorage`.
|
|
9
|
+
* Signals for milestones (e.g., 10th, 100th visit).
|
|
10
|
+
* Reactive last visit date signal.
|
|
11
|
+
* Configurable storage key and milestones.
|
|
12
|
+
* Works seamlessly with standalone components and reactive Angular setups.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
You can install this library via npm:
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm install @su-labs/visit-tracker
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Peer Dependencies
|
|
23
|
+
|
|
24
|
+
This library requires the following peer dependencies:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
npm install @angular/common@^20.1.0 @angular/core@^20.1.0
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
### Example 1: Basic initialization
|
|
32
|
+
The service should be provided at the root level. To use it in a component, simply inject it:
|
|
33
|
+
|
|
34
|
+
```TypeScript
|
|
35
|
+
|
|
36
|
+
import { Component, inject } from '@angular/core';
|
|
37
|
+
import { SuVisitTrackerService } from './su-visit-tracker.service';
|
|
38
|
+
import { CommonModule, DatePipe } from '@angular/common';
|
|
39
|
+
|
|
40
|
+
@Component({
|
|
41
|
+
selector: 'app-root',
|
|
42
|
+
standalone: true,
|
|
43
|
+
imports: [CommonModule, DatePipe],
|
|
44
|
+
template: `
|
|
45
|
+
<h1>Welcome back!</h1>
|
|
46
|
+
<p>You have visited {{ visitService.count() }} times.</p>
|
|
47
|
+
<ng-container *ngIf="visitService.lastVisit() as last">
|
|
48
|
+
<p>Last visit: {{ last | date:'medium' }}</p>
|
|
49
|
+
</ng-container>
|
|
50
|
+
`,
|
|
51
|
+
})
|
|
52
|
+
export class AppComponent {
|
|
53
|
+
public readonly visitService = inject(SuVisitTrackerService);
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
✅ Automatically increments the visit count and updates the last visit timestamp.
|
|
58
|
+
|
|
59
|
+
### Example 2: Checking milestone visits
|
|
60
|
+
You can reactively check if a milestone visit has been reached:
|
|
61
|
+
|
|
62
|
+
```HTML
|
|
63
|
+
|
|
64
|
+
@if(visitService.isTenthVisit()){
|
|
65
|
+
<p>🎉 Congratulations on your 10th visit!</p>
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@if(visitService.isHundredthVisit()){
|
|
69
|
+
<p>🏆 100 visits! You're a power user!</p>
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Signals `isTenthVisit` and `isHundredthVisit` update automatically on service initialization.
|
|
74
|
+
|
|
75
|
+
### Example 3: Custom configuration
|
|
76
|
+
For standalone apps, use provideAppInitializer to initialize the tracker with a custom storage key or milestones:
|
|
77
|
+
|
|
78
|
+
```TypeScript
|
|
79
|
+
|
|
80
|
+
import { provideAppInitializer, inject } from '@angular/core';
|
|
81
|
+
import { SuVisitTrackerService, SuVisitTrackerConfig } from './su-visit-tracker.service';
|
|
82
|
+
|
|
83
|
+
const visitConfig: SuVisitTrackerConfig = {
|
|
84
|
+
storageKey: 'myApp:visits',
|
|
85
|
+
milestoneVisits: [5, 50, 500], // custom milestones
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const appConfig = {
|
|
89
|
+
providers: [
|
|
90
|
+
provideAppInitializer(() => {
|
|
91
|
+
const tracker = inject(SuVisitTrackerService);
|
|
92
|
+
tracker.init(visitConfig);
|
|
93
|
+
}),
|
|
94
|
+
],
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
✅ Allows overriding the localStorage key and defining custom milestone visits.
|
|
99
|
+
|
|
100
|
+
### Example 4: Using last visit date
|
|
101
|
+
|
|
102
|
+
```HTML
|
|
103
|
+
|
|
104
|
+
@if(visitService.lastVisit() as last) {
|
|
105
|
+
<p>
|
|
106
|
+
Your last visit was on {{ last | date:'fullDate' }} at {{ last | date:'shortTime' }}
|
|
107
|
+
</p>
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
The service stores last visit as an ISO string (e.g., "2025-08-25T12:34:56.789Z"), so it can easily be used in Angular date pipes.
|
|
112
|
+
|
|
113
|
+
## Configuration Options
|
|
114
|
+
|
|
115
|
+
The service can be configured to fit your application's needs. You can customize the storage key and milestone values by passing a configuration object to the `init()` method.
|
|
116
|
+
|
|
117
|
+
| Option | Description | Default Value |
|
|
118
|
+
|-------------------|---------------------------------------------------------------|------------------|
|
|
119
|
+
| `storageKey` | The key used to persist the visit data in `localStorage`. | `'su:visits'` |
|
|
120
|
+
| `milestoneVisits` | An array of numbers representing visits to track as milestones. | `[10, 100]` |
|
|
121
|
+
|
|
122
|
+
## Notes
|
|
123
|
+
|
|
124
|
+
- Signals-based API: Perfect for standalone components and reactive Angular templates.
|
|
125
|
+
|
|
126
|
+
- Persistence: Visit count and last visit are automatically stored in localStorage.
|
|
127
|
+
|
|
128
|
+
- Lightweight: No external dependencies and minimal memory footprint.
|
|
129
|
+
|
|
130
|
+
- Custom milestones: Track any number of user visit milestones reactively.
|
|
131
|
+
|
|
132
|
+
## Contributing
|
|
133
|
+
|
|
134
|
+
If you find any bugs or have feature requests, please open an issue or submit a pull request on our [**GitHub repository**](https://github.com/Greezaaa/settings-utils-lib.git).
|
|
135
|
+
|
|
136
|
+
To contribute code, please ensure your changes include unit tests to maintain code quality. Please see the main repository's `README.md` for details on the monorepo structure.
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
This project is licensed under the MIT License. See the [**LICENSE**](https://github.com/Greezaaa/settings-utils-lib/blob/main/projects/su-labs/visit-tracker/LICENSE) file for details.
|
|
141
|
+
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { signal, Injectable } from '@angular/core';
|
|
3
|
+
import { describe, beforeEach, vi, it, expect } from 'vitest';
|
|
4
|
+
|
|
5
|
+
class SuVisitTrackerService {
|
|
6
|
+
/** Key used for localStorage */
|
|
7
|
+
storageKey = 'su:visits';
|
|
8
|
+
/** Milestones to track */
|
|
9
|
+
_milestones = [10, 100];
|
|
10
|
+
/** Current visit count */
|
|
11
|
+
count = signal(0, ...(ngDevMode ? [{ debugName: "count" }] : []));
|
|
12
|
+
/** Last visit date as ISO string */
|
|
13
|
+
lastVisit = signal(null, ...(ngDevMode ? [{ debugName: "lastVisit" }] : []));
|
|
14
|
+
/** The number of the milestone reached on the current visit, or null */
|
|
15
|
+
milestone = signal(null, ...(ngDevMode ? [{ debugName: "milestone" }] : []));
|
|
16
|
+
/** Initialize the service and update signals */
|
|
17
|
+
init(config) {
|
|
18
|
+
if (config?.storageKey) {
|
|
19
|
+
this.storageKey = config.storageKey;
|
|
20
|
+
}
|
|
21
|
+
if (config?.milestoneVisits && Array.isArray(config.milestoneVisits)) {
|
|
22
|
+
this._milestones = config.milestoneVisits.sort((a, b) => a - b);
|
|
23
|
+
}
|
|
24
|
+
const storedData = localStorage.getItem(this.storageKey);
|
|
25
|
+
const stored = storedData ? JSON.parse(storedData) : {};
|
|
26
|
+
const prevCount = stored.count ?? 0;
|
|
27
|
+
const prevDate = stored.lastVisit ?? null;
|
|
28
|
+
const newCount = prevCount + 1;
|
|
29
|
+
this.count.set(newCount);
|
|
30
|
+
this.lastVisit.set(prevDate);
|
|
31
|
+
this.updateMilestone(newCount);
|
|
32
|
+
localStorage.setItem(this.storageKey, JSON.stringify({ count: newCount, lastVisit: new Date().toISOString() }));
|
|
33
|
+
}
|
|
34
|
+
/** Update the milestone signal based on the current count */
|
|
35
|
+
updateMilestone(count) {
|
|
36
|
+
const reachedMilestone = this._milestones.find(m => m === count);
|
|
37
|
+
this.milestone.set(reachedMilestone ?? null);
|
|
38
|
+
}
|
|
39
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.7", ngImport: i0, type: SuVisitTrackerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
40
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.7", ngImport: i0, type: SuVisitTrackerService, providedIn: 'root' });
|
|
41
|
+
}
|
|
42
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.7", ngImport: i0, type: SuVisitTrackerService, decorators: [{
|
|
43
|
+
type: Injectable,
|
|
44
|
+
args: [{ providedIn: 'root' }]
|
|
45
|
+
}] });
|
|
46
|
+
|
|
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
|
+
/*
|
|
125
|
+
* Public API Surface of visit-tracker
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Generated bundle index. Do not edit.
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
export { SuVisitTrackerService };
|
|
133
|
+
//# sourceMappingURL=su-labs-visit-tracker.mjs.map
|
|
@@ -0,0 +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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OAAO,CAAC,IAAI,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QACzC,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;;QAGnC,YAAY,CAAC,OAAO,CAClB,WAAW,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,IAAI,CAAC,CAAC,CAAC;;QAGnC,YAAY,CAAC,OAAO,CAClB,WAAW,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;;;;"}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { WritableSignal } from '@angular/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for SuVisitTrackerService
|
|
6
|
+
*/
|
|
7
|
+
interface SuVisitTrackerConfig {
|
|
8
|
+
/** Key used for storing visit data in localStorage (default: 'su:visits') */
|
|
9
|
+
storageKey?: string;
|
|
10
|
+
/** Milestones to track, e.g., 10th visit, 100th visit */
|
|
11
|
+
milestoneVisits?: number[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Shape of the data stored in localStorage
|
|
15
|
+
*/
|
|
16
|
+
interface SuVisitData {
|
|
17
|
+
count: number;
|
|
18
|
+
lastVisit: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare class SuVisitTrackerService {
|
|
22
|
+
/** Key used for localStorage */
|
|
23
|
+
private storageKey;
|
|
24
|
+
/** Milestones to track */
|
|
25
|
+
private _milestones;
|
|
26
|
+
/** Current visit count */
|
|
27
|
+
count: WritableSignal<number>;
|
|
28
|
+
/** Last visit date as ISO string */
|
|
29
|
+
lastVisit: WritableSignal<string | null>;
|
|
30
|
+
/** The number of the milestone reached on the current visit, or null */
|
|
31
|
+
milestone: WritableSignal<number | null>;
|
|
32
|
+
/** Initialize the service and update signals */
|
|
33
|
+
init(config?: SuVisitTrackerConfig): void;
|
|
34
|
+
/** Update the milestone signal based on the current count */
|
|
35
|
+
private updateMilestone;
|
|
36
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<SuVisitTrackerService, never>;
|
|
37
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<SuVisitTrackerService>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { SuVisitTrackerService };
|
|
41
|
+
export type { SuVisitData, SuVisitTrackerConfig };
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@su-labs/visit-tracker",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"peerDependencies": {
|
|
5
|
+
"@angular/common": "^20.1.0",
|
|
6
|
+
"@angular/core": "^20.1.0"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"tslib": "^2.3.0"
|
|
10
|
+
},
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"module": "fesm2022/su-labs-visit-tracker.mjs",
|
|
13
|
+
"typings": "index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
"./package.json": {
|
|
16
|
+
"default": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./index.d.ts",
|
|
20
|
+
"default": "./fesm2022/su-labs-visit-tracker.mjs"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|