tiny-essentials 1.13.2 โ†’ 1.14.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.
@@ -0,0 +1,189 @@
1
+ # ๐Ÿ“ฃ TinyNotifications
2
+
3
+ > A utility class to manage browser notifications with sound, custom icons, text truncation, and click behavior.
4
+
5
+ ---
6
+
7
+ ## ๐Ÿš€ Features
8
+
9
+ * โœ… Request and manage user permission for notifications
10
+ * ๐Ÿ”” Play a sound when a notification is shown
11
+ * ๐Ÿ–ผ๏ธ Support for default avatar/icon
12
+ * โœ‚๏ธ Automatic body text truncation
13
+ * ๐Ÿ’ฅ Strong validation with `TypeError` and runtime checks
14
+ * โ— Prevents use of `send()` before permission request
15
+
16
+ ---
17
+
18
+ ## ๐Ÿ—๏ธ Constructor
19
+
20
+ ```js
21
+ new TinyNotifications(options?)
22
+ ```
23
+
24
+ ### Parameters
25
+
26
+ | Name | Type | Default | Description |
27
+ | ---------------- | ----------------------------------------- | ------- | -------------------------------------------------- |
28
+ | `audio` | `string` \| `HTMLAudioElement` \| `null` | `null` | Sound to be played with the notification |
29
+ | `defaultIcon` | `string` \| `null` | `null` | Default icon to use in notifications |
30
+ | `bodyLimit` | `number` | `100` | Maximum number of characters in body text |
31
+ | `defaultOnClick` | `(this: Notification, evt: Event) => any` | `fn` | Function executed when the notification is clicked |
32
+
33
+ ### Throws
34
+
35
+ * `TypeError` if any parameter is of invalid type.
36
+
37
+ ---
38
+
39
+ ## ๐Ÿง  Methods
40
+
41
+ ### ๐Ÿ” `requestPerm()`
42
+
43
+ ```js
44
+ requestPerm(): Promise<boolean>
45
+ ```
46
+
47
+ Requests permission from the browser to send notifications.
48
+
49
+ * Sets internal `#allowed` and `#permissionRequested` flags.
50
+ * Must be called before using `send()`.
51
+
52
+ **Returns:** `Promise<boolean>` โ€” `true` if permission was granted.
53
+
54
+ ---
55
+
56
+ ### โš™๏ธ `isCompatible()`
57
+
58
+ ```js
59
+ isCompatible(): boolean
60
+ ```
61
+
62
+ Checks if the current browser supports the Notification API.
63
+
64
+ **Returns:** `true` or `false`
65
+
66
+ ---
67
+
68
+ ### ๐Ÿ“ค `send(title, config?)`
69
+
70
+ ```js
71
+ send(title: string, config?: NotificationOptions): Notification | null
72
+ ```
73
+
74
+ Sends a notification to the user with optional configuration.
75
+ Truncates long body texts and plays a sound if set.
76
+
77
+ #### Parameters
78
+
79
+ * `title`: *(string)* โ€” Title of the notification
80
+ * `config`: *(object)* โ€” Optional notification settings (`body`, `icon`, `vibrate`, etc.)
81
+
82
+ #### Throws
83
+
84
+ * `Error` if `requestPerm()` was never called
85
+ * `TypeError` if `title` is not a string or `config` is not an object
86
+
87
+ #### Returns
88
+
89
+ * `Notification` instance if allowed
90
+ * `null` if permission was denied
91
+
92
+ ---
93
+
94
+ ## ๐Ÿ“ฅ Getters & Setters
95
+
96
+ ### ๐Ÿ“Œ `wasPermissionRequested()`
97
+
98
+ ```js
99
+ wasPermissionRequested(): boolean
100
+ ```
101
+
102
+ Checks if `requestPerm()` was called.
103
+
104
+ ---
105
+
106
+ ### ๐ŸŸข `isAllowed()`
107
+
108
+ ```js
109
+ isAllowed(): boolean
110
+ ```
111
+
112
+ Checks if permission has been granted.
113
+
114
+ ---
115
+
116
+ ### ๐Ÿ”Š `getAudio()` / `setAudio(value)`
117
+
118
+ ```js
119
+ getAudio(): HTMLAudioElement | null
120
+ setAudio(value: HTMLAudioElement | string | null)
121
+ ```
122
+
123
+ Set or retrieve the notification sound.
124
+ **Throws:** `TypeError` if invalid type is used.
125
+
126
+ ---
127
+
128
+ ### ๐Ÿ“ `getBodyLimit()` / `setBodyLimit(value)`
129
+
130
+ ```js
131
+ getBodyLimit(): number
132
+ setBodyLimit(value: number)
133
+ ```
134
+
135
+ Set or retrieve the maximum number of characters in the notification body.
136
+ **Throws:** `TypeError` if value is not a non-negative number.
137
+
138
+ ---
139
+
140
+ ### ๐Ÿ–ผ๏ธ `getDefaultAvatar()` / `setDefaultAvatar(value)`
141
+
142
+ ```js
143
+ getDefaultAvatar(): string | null
144
+ setDefaultAvatar(value: string | null)
145
+ ```
146
+
147
+ Get or set the default icon for notifications.
148
+ **Throws:** `TypeError` if value is not a string or `null`.
149
+
150
+ ---
151
+
152
+ ### ๐Ÿ–ฑ๏ธ `getDefaultOnClick()` / `setDefaultOnClick(value)`
153
+
154
+ ```js
155
+ getDefaultOnClick(): (this: Notification, evt: Event) => any
156
+ setDefaultOnClick(value: function)
157
+ ```
158
+
159
+ Set or retrieve the default click handler for all notifications.
160
+ **Throws:** `TypeError` if value is not a function.
161
+
162
+ ---
163
+
164
+ ## ๐Ÿ“ฆ Example
165
+
166
+ ```js
167
+ import TinyNotifications from './TinyNotifications.js';
168
+
169
+ const notify = new TinyNotifications({
170
+ audio: '/sounds/ping.mp3',
171
+ defaultIcon: '/img/icon.png',
172
+ bodyLimit: 80
173
+ });
174
+
175
+ await notify.requestPerm();
176
+
177
+ notify.send('Hello World!', {
178
+ body: 'This message will be truncated if too long.',
179
+ vibrate: [100, 50, 100]
180
+ });
181
+ ```
182
+
183
+ ---
184
+
185
+ ## ๐Ÿงช Safety Notes
186
+
187
+ * Always call `requestPerm()` **before** using `send()`
188
+ * Invalid or unsafe inputs throw strong errors
189
+ * Compatible with all modern browsers that support `Notification` API
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiny-essentials",
3
- "version": "1.13.2",
3
+ "version": "1.14.0",
4
4
  "description": "Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.",
5
5
  "scripts": {
6
6
  "test": "npm run test:mjs && npm run test:cjs && npm run test:js",