@flexzap/utilities 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Vitor Azevedo
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,134 @@
1
+ # @flexzap/utilities
2
+
3
+ Essential utility services and helpers for Angular applications. Part of the FlexZap Library ecosystem.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @flexzap/utilities
9
+ ```
10
+
11
+ ### Peer Dependencies
12
+
13
+ This library requires the following peer dependencies:
14
+
15
+ ```bash
16
+ npm install @angular/common@^21.1.0 @angular/core@^21.1.0 @angular/platform-browser@^21.1.0
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ### ZapNavigation
22
+
23
+ The `ZapNavigation` service provides safe, platform-agnostic navigation methods.
24
+
25
+ ```typescript
26
+ import { Component, inject } from '@angular/core';
27
+ import { ZapNavigation } from '@flexzap/utilities';
28
+
29
+ @Component({
30
+ template: `
31
+ <button (click)="goToExternal()">Go to Google</button>
32
+ <button (click)="sendEmail()">Contact Us</button>
33
+ <button (click)="callSupport()">Call Support</button>
34
+ `
35
+ })
36
+ export class MyComponent {
37
+ private navigation = inject(ZapNavigation);
38
+
39
+ goToExternal() {
40
+ // Safely navigates to URL (sanitized and browser-check included)
41
+ this.navigation.goToUrl('https://google.com', '_blank');
42
+ }
43
+
44
+ sendEmail() {
45
+ this.navigation.mailTo('support@example.com', 'Help', 'I need assistance');
46
+ }
47
+
48
+ callSupport() {
49
+ this.navigation.callTo('+1234567890');
50
+ }
51
+ }
52
+ ```
53
+
54
+ ## API Reference
55
+
56
+ ### ZapNavigation Service
57
+
58
+ Service for handling navigation and URL opening in a safe, platform-agnostic way.
59
+
60
+ #### Methods
61
+
62
+ | Method | Parameters | Description |
63
+ | -------------- | ---------------------------------------------------- | -------------------------------------------------------------- |
64
+ | `goToUrl` | `url: string`, `target?: string` | Navigates to the specified URL. Default target is `_self`. |
65
+ | `mailTo` | `email: string`, `subject?: string`, `body?: string` | Opens the default email client with optional subject and body. |
66
+ | `callTo` | `tel: string` | Initiates a phone call to the specified number. |
67
+ | `smsTo` | `tel: string` | Initiates an SMS to the specified number. |
68
+ | `linkTo` | `id: string` | Smoothly scrolls to the element with the specified ID. |
69
+ | `downloadFile` | `url: string` | Downloads a file from the specified URL. |
70
+
71
+ #### Features
72
+
73
+ - **Platform Agnostic**: Safe to call in SSR environments (checks `PLATFORM_ID`).
74
+ - **Security**: Automatically sanitizes URLs to prevent XSS.
75
+ - **SSR Safe**: Prevents `window` access on the server.
76
+
77
+ ## Testing
78
+
79
+ This library uses Jest for unit testing with zoneless Angular configuration.
80
+
81
+ ### Running Tests
82
+
83
+ ```bash
84
+ # From the monorepo root
85
+ npm run utilities:test # Run all unit tests with coverage
86
+ npm run utilities:test:watch # Run tests in watch mode (no coverage)
87
+ ```
88
+
89
+ ### Test Configuration
90
+
91
+ - **Framework**: Jest with jest-preset-angular
92
+ - **Environment**: jsdom
93
+ - **Configuration**: Zoneless Angular (mandatory)
94
+ - **Coverage**: Reports generated at `coverage/flexzap/utilities/`
95
+
96
+ ## Development
97
+
98
+ ### Building the Library
99
+
100
+ ```bash
101
+ # From the monorepo root
102
+ npm run utilities:build # Build directly
103
+ ng build @flexzap/utilities # Build using Angular CLI
104
+ ```
105
+
106
+ ## Publishing
107
+
108
+ ### Build for Publication
109
+
110
+ ```bash
111
+ # From the monorepo root
112
+ npm run utilities:build
113
+ ```
114
+
115
+ ### Publish to NPM
116
+
117
+ ```bash
118
+ cd dist/flexzap/utilities
119
+ npm publish --access public
120
+ ```
121
+
122
+ ## Contributing
123
+
124
+ This library is part of the FlexZap Library monorepo. Please refer to the [main repository](../../../README.md) for contribution guidelines.
125
+
126
+ ## License
127
+
128
+ MIT License - see the [LICENSE](../../../LICENSE) file for details.
129
+
130
+ ## Links
131
+
132
+ - **Homepage**: [https://www.flexzap.dev](https://www.flexzap.dev)
133
+ - **Repository**: [https://github.com/vitorazevedo/flexzap-library](https://github.com/vitorazevedo/flexzap-library)
134
+ - **Monorepo Documentation**: [Main README](../../../README.md)
@@ -0,0 +1,134 @@
1
+ import { isPlatformBrowser } from '@angular/common';
2
+ import * as i0 from '@angular/core';
3
+ import { SecurityContext, PLATFORM_ID, Inject, Injectable } from '@angular/core';
4
+ import * as i1 from '@angular/platform-browser';
5
+
6
+ /**
7
+ * Service for handling navigation and URL opening in a safe, platform-agnostic way.
8
+ * It ensures that URLs are sanitized (rejecting 'unsafe:' prefixes) and that window operations are only performed in the browser environment.
9
+ */
10
+ class ZapNavigation {
11
+ platformId;
12
+ sanitizer;
13
+ constructor(platformId, sanitizer) {
14
+ this.platformId = platformId;
15
+ this.sanitizer = sanitizer;
16
+ }
17
+ /**
18
+ * Navigates to the specified URL in the given target window/tab.
19
+ *
20
+ * This method performs the following safety checks:
21
+ * 1. Verifies the code is running in a browser environment.
22
+ * 2. Sanitizes the URL to prevent security vulnerabilities (like XSS) and rejects URLs prefixed with 'unsafe:'.
23
+ * 3. When target is '_blank', automatically adds 'noopener,noreferrer' and clears the opener to prevent reverse tabnabbing.
24
+ *
25
+ * @param {string} url - The URL to navigate to.
26
+ * @param {string} [target='_self'] - The target context for opening the URL (e.g., '_self', '_blank'). Defaults to '_self'.
27
+ */
28
+ goToUrl(url, target = '_self') {
29
+ if (isPlatformBrowser(this.platformId)) {
30
+ const sanitizedUrl = this.sanitizer.sanitize(SecurityContext.URL, url);
31
+ if (sanitizedUrl && !sanitizedUrl.startsWith('unsafe:')) {
32
+ if (target === '_blank') {
33
+ const newWindow = window.open(sanitizedUrl, target, 'noopener,noreferrer');
34
+ if (newWindow) {
35
+ newWindow.opener = null;
36
+ }
37
+ }
38
+ else {
39
+ window.open(sanitizedUrl, target);
40
+ }
41
+ }
42
+ }
43
+ }
44
+ /**
45
+ * Opens the default email client with the specified email, subject, and body.
46
+ *
47
+ * @param {string} email - The recipient's email address.
48
+ * @param {string} [subject] - The subject of the email (optional).
49
+ * @param {string} [body] - The body of the email (optional).
50
+ */
51
+ mailTo(email, subject, body) {
52
+ const params = [];
53
+ if (subject) {
54
+ params.push(`subject=${encodeURIComponent(subject)}`);
55
+ }
56
+ if (body) {
57
+ params.push(`body=${encodeURIComponent(body)}`);
58
+ }
59
+ let url = `mailto:${email}`;
60
+ if (params.length > 0) {
61
+ url += `?${params.join('&')}`;
62
+ }
63
+ this.goToUrl(url);
64
+ }
65
+ /**
66
+ * Initiates a phone call to the specified telephone number.
67
+ *
68
+ * @param {string} tel - The telephone number to call.
69
+ */
70
+ callTo(tel) {
71
+ this.goToUrl(`tel:${tel}`);
72
+ }
73
+ /**
74
+ * Initiates a SMS to the specified telephone number.
75
+ *
76
+ * @param {string} tel - The telephone number to send SMS to.
77
+ */
78
+ smsTo(tel) {
79
+ this.goToUrl(`sms:${tel}`);
80
+ }
81
+ /**
82
+ * Navigates to the specified element id on the current page.
83
+ *
84
+ * This method performs a smooth scroll to the element. It is safe to call in SSR environments (no-op on server).
85
+ *
86
+ * @param {string} id - The element id to navigate to.
87
+ */
88
+ linkTo(id) {
89
+ if (isPlatformBrowser(this.platformId)) {
90
+ const element = document.getElementById(id);
91
+ if (element) {
92
+ element.scrollIntoView({ behavior: 'smooth' });
93
+ }
94
+ }
95
+ }
96
+ /**
97
+ * Downloads a file from the specified URL.
98
+ *
99
+ * @param {string} url - The URL of the file to download. It will be sanitized to prevent security vulnerabilities and rejected if prefixed with 'unsafe:'.
100
+ */
101
+ downloadFile(url) {
102
+ if (isPlatformBrowser(this.platformId)) {
103
+ const sanitizedUrl = this.sanitizer.sanitize(SecurityContext.URL, url);
104
+ if (sanitizedUrl && !sanitizedUrl.startsWith('unsafe:')) {
105
+ const link = document.createElement('a');
106
+ link.href = sanitizedUrl;
107
+ link.download = 'file';
108
+ link.click();
109
+ }
110
+ }
111
+ }
112
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: ZapNavigation, deps: [{ token: PLATFORM_ID }, { token: i1.DomSanitizer }], target: i0.ɵɵFactoryTarget.Injectable });
113
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: ZapNavigation, providedIn: 'root' });
114
+ }
115
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: ZapNavigation, decorators: [{
116
+ type: Injectable,
117
+ args: [{
118
+ providedIn: 'root'
119
+ }]
120
+ }], ctorParameters: () => [{ type: Object, decorators: [{
121
+ type: Inject,
122
+ args: [PLATFORM_ID]
123
+ }] }, { type: i1.DomSanitizer }] });
124
+
125
+ /*
126
+ * Public API Surface of utilities
127
+ */
128
+
129
+ /**
130
+ * Generated bundle index. Do not edit.
131
+ */
132
+
133
+ export { ZapNavigation };
134
+ //# sourceMappingURL=flexzap-utilities.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flexzap-utilities.mjs","sources":["../../../../projects/flexzap/utilities/src/lib/navigation/navigation.ts","../../../../projects/flexzap/utilities/src/public-api.ts","../../../../projects/flexzap/utilities/src/flexzap-utilities.ts"],"sourcesContent":["import { isPlatformBrowser } from '@angular/common';\nimport { Inject, Injectable, PLATFORM_ID, SecurityContext } from '@angular/core';\nimport { DomSanitizer } from '@angular/platform-browser';\n\n/**\n * Service for handling navigation and URL opening in a safe, platform-agnostic way.\n * It ensures that URLs are sanitized (rejecting 'unsafe:' prefixes) and that window operations are only performed in the browser environment.\n */\n@Injectable({\n providedIn: 'root'\n})\nexport class ZapNavigation {\n constructor(\n @Inject(PLATFORM_ID) private platformId: Object,\n private sanitizer: DomSanitizer\n ) {}\n\n /**\n * Navigates to the specified URL in the given target window/tab.\n *\n * This method performs the following safety checks:\n * 1. Verifies the code is running in a browser environment.\n * 2. Sanitizes the URL to prevent security vulnerabilities (like XSS) and rejects URLs prefixed with 'unsafe:'.\n * 3. When target is '_blank', automatically adds 'noopener,noreferrer' and clears the opener to prevent reverse tabnabbing.\n *\n * @param {string} url - The URL to navigate to.\n * @param {string} [target='_self'] - The target context for opening the URL (e.g., '_self', '_blank'). Defaults to '_self'.\n */\n goToUrl(url: string, target: '_self' | '_blank' | '_parent' | '_top' = '_self') {\n if (isPlatformBrowser(this.platformId)) {\n const sanitizedUrl = this.sanitizer.sanitize(SecurityContext.URL, url);\n\n if (sanitizedUrl && !sanitizedUrl.startsWith('unsafe:')) {\n if (target === '_blank') {\n const newWindow = window.open(sanitizedUrl, target, 'noopener,noreferrer');\n if (newWindow) {\n newWindow.opener = null;\n }\n } else {\n window.open(sanitizedUrl, target);\n }\n }\n }\n }\n\n /**\n * Opens the default email client with the specified email, subject, and body.\n *\n * @param {string} email - The recipient's email address.\n * @param {string} [subject] - The subject of the email (optional).\n * @param {string} [body] - The body of the email (optional).\n */\n mailTo(email: string, subject?: string, body?: string) {\n const params: string[] = [];\n if (subject) {\n params.push(`subject=${encodeURIComponent(subject)}`);\n }\n if (body) {\n params.push(`body=${encodeURIComponent(body)}`);\n }\n\n let url = `mailto:${email}`;\n if (params.length > 0) {\n url += `?${params.join('&')}`;\n }\n\n this.goToUrl(url);\n }\n\n /**\n * Initiates a phone call to the specified telephone number.\n *\n * @param {string} tel - The telephone number to call.\n */\n callTo(tel: string) {\n this.goToUrl(`tel:${tel}`);\n }\n\n /**\n * Initiates a SMS to the specified telephone number.\n *\n * @param {string} tel - The telephone number to send SMS to.\n */\n smsTo(tel: string) {\n this.goToUrl(`sms:${tel}`);\n }\n\n /**\n * Navigates to the specified element id on the current page.\n *\n * This method performs a smooth scroll to the element. It is safe to call in SSR environments (no-op on server).\n *\n * @param {string} id - The element id to navigate to.\n */\n linkTo(id: string) {\n if (isPlatformBrowser(this.platformId)) {\n const element = document.getElementById(id);\n\n if (element) {\n element.scrollIntoView({ behavior: 'smooth' });\n }\n }\n }\n\n /**\n * Downloads a file from the specified URL.\n *\n * @param {string} url - The URL of the file to download. It will be sanitized to prevent security vulnerabilities and rejected if prefixed with 'unsafe:'.\n */\n downloadFile(url: string) {\n if (isPlatformBrowser(this.platformId)) {\n const sanitizedUrl = this.sanitizer.sanitize(SecurityContext.URL, url);\n\n if (sanitizedUrl && !sanitizedUrl.startsWith('unsafe:')) {\n const link = document.createElement('a');\n link.href = sanitizedUrl;\n link.download = 'file';\n link.click();\n }\n }\n }\n}\n","/*\n * Public API Surface of utilities\n */\n\nexport * from './lib/navigation/index';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AAIA;;;AAGG;MAIU,aAAa,CAAA;AAEO,IAAA,UAAA;AACrB,IAAA,SAAA;IAFV,WAAA,CAC+B,UAAkB,EACvC,SAAuB,EAAA;QADF,IAAA,CAAA,UAAU,GAAV,UAAU;QAC/B,IAAA,CAAA,SAAS,GAAT,SAAS;IAChB;AAEH;;;;;;;;;;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AA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAFV,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,aAAa,cAFZ,MAAM,EAAA,CAAA;;2FAEP,aAAa,EAAA,UAAA,EAAA,CAAA;kBAHzB,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE;AACb,iBAAA;;0BAGI,MAAM;2BAAC,WAAW;;;ACbvB;;AAEG;;ACFH;;AAEG;;;;"}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@flexzap/utilities",
3
+ "version": "1.0.0",
4
+ "description": "All the utilities that makes part of the flexzap library",
5
+ "keywords": [
6
+ "flexzap",
7
+ "library",
8
+ "utilities",
9
+ "navigation"
10
+ ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/vitorazevedo/flexzap-library"
14
+ },
15
+ "author": "flexzap",
16
+ "license": "MIT",
17
+ "homepage": "https://www.flexzap.dev",
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "peerDependencies": {
22
+ "@angular/common": "^21.1.0",
23
+ "@angular/core": "^21.1.0",
24
+ "@angular/platform-browser": "^21.1.0"
25
+ },
26
+ "dependencies": {
27
+ "tslib": "^2.8.1"
28
+ },
29
+ "sideEffects": false,
30
+ "module": "fesm2022/flexzap-utilities.mjs",
31
+ "typings": "types/flexzap-utilities.d.ts",
32
+ "exports": {
33
+ "./package.json": {
34
+ "default": "./package.json"
35
+ },
36
+ ".": {
37
+ "types": "./types/flexzap-utilities.d.ts",
38
+ "default": "./fesm2022/flexzap-utilities.mjs"
39
+ }
40
+ }
41
+ }
@@ -0,0 +1,62 @@
1
+ import { DomSanitizer } from '@angular/platform-browser';
2
+ import * as i0 from '@angular/core';
3
+
4
+ /**
5
+ * Service for handling navigation and URL opening in a safe, platform-agnostic way.
6
+ * It ensures that URLs are sanitized (rejecting 'unsafe:' prefixes) and that window operations are only performed in the browser environment.
7
+ */
8
+ declare class ZapNavigation {
9
+ private platformId;
10
+ private sanitizer;
11
+ constructor(platformId: Object, sanitizer: DomSanitizer);
12
+ /**
13
+ * Navigates to the specified URL in the given target window/tab.
14
+ *
15
+ * This method performs the following safety checks:
16
+ * 1. Verifies the code is running in a browser environment.
17
+ * 2. Sanitizes the URL to prevent security vulnerabilities (like XSS) and rejects URLs prefixed with 'unsafe:'.
18
+ * 3. When target is '_blank', automatically adds 'noopener,noreferrer' and clears the opener to prevent reverse tabnabbing.
19
+ *
20
+ * @param {string} url - The URL to navigate to.
21
+ * @param {string} [target='_self'] - The target context for opening the URL (e.g., '_self', '_blank'). Defaults to '_self'.
22
+ */
23
+ goToUrl(url: string, target?: '_self' | '_blank' | '_parent' | '_top'): void;
24
+ /**
25
+ * Opens the default email client with the specified email, subject, and body.
26
+ *
27
+ * @param {string} email - The recipient's email address.
28
+ * @param {string} [subject] - The subject of the email (optional).
29
+ * @param {string} [body] - The body of the email (optional).
30
+ */
31
+ mailTo(email: string, subject?: string, body?: string): void;
32
+ /**
33
+ * Initiates a phone call to the specified telephone number.
34
+ *
35
+ * @param {string} tel - The telephone number to call.
36
+ */
37
+ callTo(tel: string): void;
38
+ /**
39
+ * Initiates a SMS to the specified telephone number.
40
+ *
41
+ * @param {string} tel - The telephone number to send SMS to.
42
+ */
43
+ smsTo(tel: string): void;
44
+ /**
45
+ * Navigates to the specified element id on the current page.
46
+ *
47
+ * This method performs a smooth scroll to the element. It is safe to call in SSR environments (no-op on server).
48
+ *
49
+ * @param {string} id - The element id to navigate to.
50
+ */
51
+ linkTo(id: string): void;
52
+ /**
53
+ * Downloads a file from the specified URL.
54
+ *
55
+ * @param {string} url - The URL of the file to download. It will be sanitized to prevent security vulnerabilities and rejected if prefixed with 'unsafe:'.
56
+ */
57
+ downloadFile(url: string): void;
58
+ static ɵfac: i0.ɵɵFactoryDeclaration<ZapNavigation, never>;
59
+ static ɵprov: i0.ɵɵInjectableDeclaration<ZapNavigation>;
60
+ }
61
+
62
+ export { ZapNavigation };