@versini/ui-utilities 1.1.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) Arno Versini
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,170 @@
1
+ # @versini/ui-utilities
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@versini/ui-utilities?style=flat-square)](https://www.npmjs.com/package/@versini/ui-utilities)
4
+ ![npm package minimized gzipped size](<https://img.shields.io/bundlejs/size/%40versini%2Fui-utilities?style=flat-square&label=size%20(gzip)>)
5
+
6
+ > A collection of utility functions for device detection and performance optimization.
7
+
8
+ This package provides lightweight utility functions commonly needed when building UI components, including device detection, viewport analysis, PWA mode detection, and function debouncing.
9
+
10
+ ## Table of Contents
11
+
12
+ - [Features](#features)
13
+ - [Installation](#installation)
14
+ - [Usage](#usage)
15
+ - [API Reference](#api-reference)
16
+
17
+ ## Features
18
+
19
+ - **📱 Device Detection**: Detect mobile devices, tablets, iPhones, and iPads
20
+ - **🚀 PWA Support**: Detect if the app is running in standalone PWA mode
21
+ - **âš¡ Performance**: Debounce utility for optimizing expensive function calls
22
+ - **🔧 TypeScript**: Fully typed with comprehensive type definitions
23
+ - **🌲 Tree-shakeable**: Import only the utilities you need
24
+ - **🪶 Lightweight**: Minimal footprint with no dependencies
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ npm install @versini/ui-utilities
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ ```tsx
35
+ import {
36
+ debounce,
37
+ isProbablyMobile,
38
+ isProbablyTablet,
39
+ isProbablyiPhone,
40
+ isProbablyiPad,
41
+ isPWAMode
42
+ } from "@versini/ui-utilities";
43
+ ```
44
+
45
+ ## API Reference
46
+
47
+ ### debounce
48
+
49
+ Creates a debounced function that delays invoking the provided function until after the specified wait time has elapsed since the last time the debounced function was invoked.
50
+
51
+ ```tsx
52
+ const debouncedFn = debounce(func: (...args: any[]) => void, wait: number)
53
+ ```
54
+
55
+ **Parameters:**
56
+
57
+ - `func` - The function to debounce
58
+ - `wait` - The number of milliseconds to delay
59
+
60
+ **Returns:** A new debounced function
61
+
62
+ **Example:**
63
+
64
+ ```tsx
65
+ const handleResize = debounce(() => {
66
+ console.log("Window resized");
67
+ }, 300);
68
+
69
+ window.addEventListener("resize", handleResize);
70
+ ```
71
+
72
+ ---
73
+
74
+ ### isProbablyMobile
75
+
76
+ Determines if the current viewport width suggests a mobile device. Uses a width threshold of 403 pixels.
77
+
78
+ ```tsx
79
+ const isMobile = isProbablyMobile(): boolean
80
+ ```
81
+
82
+ **Returns:** `true` if the viewport width is less than 403 pixels
83
+
84
+ **Example:**
85
+
86
+ ```tsx
87
+ if (isProbablyMobile()) {
88
+ // Render mobile-specific UI
89
+ }
90
+ ```
91
+
92
+ ---
93
+
94
+ ### isProbablyTablet
95
+
96
+ Determines if the current viewport width suggests a tablet device. Uses a width range between 403 and 1220 pixels.
97
+
98
+ ```tsx
99
+ const isTablet = isProbablyTablet(): boolean
100
+ ```
101
+
102
+ **Returns:** `true` if the viewport width is between 403 and 1220 pixels (inclusive)
103
+
104
+ **Example:**
105
+
106
+ ```tsx
107
+ if (isProbablyTablet()) {
108
+ // Render tablet-specific UI
109
+ }
110
+ ```
111
+
112
+ ---
113
+
114
+ ### isProbablyiPhone
115
+
116
+ Attempts to detect if the current device is likely an iPhone. Uses a combination of platform detection, user agent analysis, screen size, and touch capability checks.
117
+
118
+ ```tsx
119
+ const isiPhone = isProbablyiPhone(): boolean
120
+ ```
121
+
122
+ **Returns:** `true` if the device is likely an iPhone
123
+
124
+ **Example:**
125
+
126
+ ```tsx
127
+ if (isProbablyiPhone()) {
128
+ // Apply iPhone-specific behavior
129
+ }
130
+ ```
131
+
132
+ ---
133
+
134
+ ### isProbablyiPad
135
+
136
+ Attempts to detect if the current device is likely an iPad. Uses a combination of platform detection, user agent analysis, screen size, and touch capability checks.
137
+
138
+ ```tsx
139
+ const isiPad = isProbablyiPad(): boolean
140
+ ```
141
+
142
+ **Returns:** `true` if the device is likely an iPad
143
+
144
+ **Example:**
145
+
146
+ ```tsx
147
+ if (isProbablyiPad()) {
148
+ // Apply iPad-specific behavior
149
+ }
150
+ ```
151
+
152
+ ---
153
+
154
+ ### isPWAMode
155
+
156
+ Detects if the app is running in standalone/PWA mode. Checks for both the standard display-mode media query and the iOS-specific standalone property.
157
+
158
+ ```tsx
159
+ const isPWA = isPWAMode(): boolean
160
+ ```
161
+
162
+ **Returns:** `true` if the app is running as a standalone PWA
163
+
164
+ **Example:**
165
+
166
+ ```tsx
167
+ if (isPWAMode()) {
168
+ // Hide browser-specific UI elements
169
+ }
170
+ ```
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Creates a debounced function that delays invoking the provided function until
3
+ * after the specified wait time has elapsed since the last time the debounced
4
+ * function was invoked.
5
+ *
6
+ * @param func - The function to debounce.
7
+ * @param wait - The number of milliseconds to delay.
8
+ * @returns A new debounced function.
9
+ *
10
+ */
11
+ export declare const debounce: (func: (...args: any[]) => void, wait: number) => (...args: any[]) => void;
12
+
13
+ /**
14
+ * Attempts to detect if the current device is likely an iPad. Uses a
15
+ * combination of platform detection, user agent analysis, screen size, and
16
+ * touch capability checks.
17
+ *
18
+ * @returns True if the device is likely an iPad.
19
+ *
20
+ */
21
+ export declare const isProbablyiPad: () => boolean;
22
+
23
+ /**
24
+ * Attempts to detect if the current device is likely an iPhone. Uses a
25
+ * combination of platform detection, user agent analysis, screen size, and
26
+ * touch capability checks.
27
+ *
28
+ * @returns True if the device is likely an iPhone.
29
+ *
30
+ */
31
+ export declare const isProbablyiPhone: () => boolean;
32
+
33
+ /**
34
+ * Determines if the current viewport width suggests a mobile device. Uses a
35
+ * width threshold of 403 pixels.
36
+ *
37
+ * @returns True if the viewport width is less than 403 pixels.
38
+ *
39
+ */
40
+ export declare const isProbablyMobile: () => boolean;
41
+
42
+ /**
43
+ * Determines if the current viewport width suggests a tablet device. Uses a
44
+ * width range between 403 and 1220 pixels.
45
+ *
46
+ * @returns True if the viewport width is between 403 and 1220 pixels (inclusive).
47
+ *
48
+ */
49
+ export declare const isProbablyTablet: () => boolean;
50
+
51
+ /**
52
+ * Detects if the app is running in standalone/PWA mode. Checks for both the
53
+ * standard display-mode media query and the iOS-specific standalone property.
54
+ *
55
+ * @returns True if the app is running as a standalone PWA.
56
+ *
57
+ */
58
+ export declare const isPWAMode: () => boolean;
59
+
60
+ export { }
package/dist/index.js ADDED
@@ -0,0 +1,97 @@
1
+ /*!
2
+ @versini/ui-utilities v1.1.0
3
+ © 2025 gizmette.com
4
+ */
5
+ try {
6
+ if (!window.__VERSINI_UI_UTILITIES__) {
7
+ window.__VERSINI_UI_UTILITIES__ = {
8
+ version: "1.1.0",
9
+ buildTime: "12/19/2025 03:10 PM EST",
10
+ homepage: "https://www.npmjs.com/package/@versini/ui-utilities",
11
+ license: "MIT",
12
+ };
13
+ }
14
+ } catch (error) {
15
+ // nothing to declare officer
16
+ }
17
+
18
+
19
+ ;// CONCATENATED MODULE: ./src/components/index.ts
20
+ /**
21
+ * Creates a debounced function that delays invoking the provided function until
22
+ * after the specified wait time has elapsed since the last time the debounced
23
+ * function was invoked.
24
+ *
25
+ * @param func - The function to debounce.
26
+ * @param wait - The number of milliseconds to delay.
27
+ * @returns A new debounced function.
28
+ *
29
+ */ const debounce = (func, wait)=>{
30
+ let timeout;
31
+ return (...args)=>{
32
+ window.clearTimeout(timeout);
33
+ timeout = window.setTimeout(()=>func(...args), wait);
34
+ };
35
+ };
36
+ /**
37
+ * Determines if the current viewport width suggests a mobile device. Uses a
38
+ * width threshold of 403 pixels.
39
+ *
40
+ * @returns True if the viewport width is less than 403 pixels.
41
+ *
42
+ */ /* c8 ignore start */ const isProbablyMobile = ()=>{
43
+ return window.innerWidth < 403;
44
+ };
45
+ /* c8 ignore stop */ /**
46
+ * Determines if the current viewport width suggests a tablet device. Uses a
47
+ * width range between 403 and 1220 pixels.
48
+ *
49
+ * @returns True if the viewport width is between 403 and 1220 pixels (inclusive).
50
+ *
51
+ */ /* c8 ignore start */ const isProbablyTablet = ()=>{
52
+ return window.innerWidth >= 403 && window.innerWidth <= 1220;
53
+ };
54
+ /* c8 ignore stop */ /**
55
+ * Attempts to detect if the current device is likely an iPhone. Uses a
56
+ * combination of platform detection, user agent analysis, screen size, and
57
+ * touch capability checks.
58
+ *
59
+ * @returns True if the device is likely an iPhone.
60
+ *
61
+ */ /* c8 ignore start */ const isProbablyiPhone = ()=>{
62
+ const flagDevice = [
63
+ "iPhone Simulator",
64
+ "iPhone"
65
+ ].includes(navigator.platform) || navigator.userAgent.includes("Mac") && "ontouchend" in document || window.indexedDB !== null;
66
+ const flagUA = /iPhone/.test(navigator.userAgent);
67
+ const flagScreen = isProbablyMobile();
68
+ const flagIOS = navigator.maxTouchPoints > 1;
69
+ return flagDevice && flagUA && flagScreen && flagIOS;
70
+ };
71
+ /* c8 ignore stop */ /**
72
+ * Attempts to detect if the current device is likely an iPad. Uses a
73
+ * combination of platform detection, user agent analysis, screen size, and
74
+ * touch capability checks.
75
+ *
76
+ * @returns True if the device is likely an iPad.
77
+ *
78
+ */ /* c8 ignore start */ const isProbablyiPad = ()=>{
79
+ const flagDevice = [
80
+ "iPad Simulator",
81
+ "iPad"
82
+ ].includes(navigator.platform) || navigator.userAgent.includes("Mac") && "ontouchend" in document || window.indexedDB !== null;
83
+ const flagScreen = isProbablyTablet();
84
+ const flagIOS = navigator.maxTouchPoints > 1;
85
+ return flagDevice && flagScreen && flagIOS;
86
+ };
87
+ /* c8 ignore stop */ /**
88
+ * Detects if the app is running in standalone/PWA mode. Checks for both the
89
+ * standard display-mode media query and the iOS-specific standalone property.
90
+ *
91
+ * @returns True if the app is running as a standalone PWA.
92
+ *
93
+ */ /* c8 ignore start */ const isPWAMode = ()=>{
94
+ return window.matchMedia("(display-mode: standalone)").matches || window.navigator.standalone === true;
95
+ }; /* c8 ignore stop */
96
+
97
+ export { debounce, isPWAMode, isProbablyMobile, isProbablyTablet, isProbablyiPad, isProbablyiPhone };
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@versini/ui-utilities",
3
+ "version": "1.1.0",
4
+ "license": "MIT",
5
+ "author": "Arno Versini",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "homepage": "https://www.npmjs.com/package/@versini/ui-utilities",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git@github.com:aversini/ui-components.git"
13
+ },
14
+ "type": "module",
15
+ "main": "dist/index.js",
16
+ "types": "dist/index.d.ts",
17
+ "files": [
18
+ "dist",
19
+ "README.md"
20
+ ],
21
+ "scripts": {
22
+ "build:check": "tsc",
23
+ "build:js": "rslib build",
24
+ "build:types": "echo 'Types now built with rslib'",
25
+ "build": "npm-run-all --serial clean build:check build:js",
26
+ "clean": "rimraf dist tmp",
27
+ "dev:js": "rslib build --watch",
28
+ "dev:types": "echo 'Types now watched with rslib'",
29
+ "dev": "rslib build --watch",
30
+ "lint": "biome lint src",
31
+ "lint:fix": "biome check src --write --no-errors-on-unmatched",
32
+ "prettier": "biome check --write --no-errors-on-unmatched",
33
+ "start": "static-server dist --port 5173",
34
+ "test:coverage:ui": "vitest --coverage --ui",
35
+ "test:coverage": "vitest run --coverage",
36
+ "test:watch": "vitest",
37
+ "test": "vitest run"
38
+ },
39
+ "sideEffects": [
40
+ "**/*.css"
41
+ ],
42
+ "gitHead": "8c05a346766c79bba8ecbeb68c7adbb1e8c5e50c"
43
+ }