tiny-essentials 1.28.8 → 1.28.9

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/docs/v1/README.md CHANGED
@@ -21,6 +21,7 @@ Here, you can navigate through different sections of the project. Below are the
21
21
  - 📺 **[FullScreen](./basics/fullScreen.md)** — A complete fullscreen API manager with detection, event handling, and cross-browser compatibility.
22
22
  - 🧱 **[Collision](./basics/collision.md)** — Full-featured rectangle collision detection system with directional analysis, depth calculation, and center offset metrics.
23
23
  - 🎵 **[MediaContent](./basics/mediaContent.md)** — A comprehensive media processing module for downloading audio, extracting rich ID3 metadata, and managing image blobs for album art.
24
+ - 📦 **[BrowserDetector](./basics/browserDetector.md)** — A multi-layered JavaScript utility for identifying the user's web browser and rendering engine.
24
25
 
25
26
  ### 2. **`libs/`**
26
27
  - 🗂️ **[TinyPromiseQueue](./libs/TinyPromiseQueue.md)** — A class that allows sequential execution of asynchronous tasks, supporting task delays, cancellation, and queue management.
@@ -64,6 +65,7 @@ Here, you can navigate through different sections of the project. Below are the
64
65
  * 🧠 **[TinyMamdaniInferenceSystem](./libs/TinyMamdaniInferenceSystem.md)** — A implementation of a Mamdani Inference System, allowing you to model logic using trapezoidal membership functions.
65
66
  * 📻 **[TinyRadioFm](./libs/TinyRadioFm.md)** — It is designed to handle complex playback sequences, including music and voice playlists, scheduled timeline mutations, and custom content injections, all while maintaining absolute reproducibility through a mathematical seed.
66
67
  * ⏯️ **[TinyMediaPlayer](./libs/TinyMediaPlayer.md)** — A universal media player architecture utilizing an adapter pattern to orchestrate multiple platform APIs, featuring robust playlist management, playback controls, and weighted random selection.
68
+ * 🛠️ **[TinyDebugger](./libs/TinyDebugger.md)** — A lightweight, event-driven debugging utility designed to wrap standard `console` methods. It provides enhanced features such as custom prefixes, color support, and the ability to emit events whenever a log occurs, making it perfect for complex applications where you might want to redirect logs to an external service or a UI component.
67
69
 
68
70
  ### 2.1. **`libs/TinyClassManager`**
69
71
 
@@ -0,0 +1,135 @@
1
+ # 🌐 Browser Detection Toolkit
2
+
3
+ A multi-layered JavaScript utility for identifying the user's web browser and rendering engine.
4
+
5
+ ## 📋 Table of Contents
6
+ 1. [Data Types](#📋-data-types)
7
+ 2. [Core Functions](#🛠️-core-functions)
8
+ - [isBrowserAgent](#1-isbrowseragent)
9
+ - [getBrowserCssPrefix](#2-getbrowsercssprefix)
10
+ - [getDuckTyping](#3-getducktyping)
11
+ 3. [Advanced Detection](#🎯-advanced-detection)
12
+ - [getBrowserPings](#4-getbrowserpings)
13
+ - [browserIs](#5-browseris)
14
+
15
+ ---
16
+
17
+ ## 📋 Data Types
18
+
19
+ To ensure type safety and clarity, the toolkit utilizes the following definitions:
20
+
21
+ ### `BrowserDetected`
22
+ A union type representing the supported browser names:
23
+ `'chrome' | 'firefox' | 'ie' | 'edge' | 'safari' | 'opera' | 'yandex' | 'other'`
24
+
25
+ ### `DuckTypingResult`
26
+ An object returned by feature detection, containing boolean flags:
27
+ | Property | Description |
28
+ | :--- | :--- |
29
+ | `isOpera` | `true` if Opera is detected |
30
+ | `isFirefox` | `true` if Firefox is detected |
31
+ | `isSafari` | `true` if Safari is detected |
32
+ | `isIE` | `true` if Internet Explorer is detected |
33
+ | `isEdge` | `true` if Microsoft Edge is detected |
34
+ | `isChrome` | `true` if Google Chrome is detected |
35
+ | `isBlink` | `true` if the Blink rendering engine is detected |
36
+
37
+ ---
38
+
39
+ ## 🛠️ Core Functions
40
+
41
+ ### 1. `isBrowserAgent()`
42
+ Parses the `navigator.userAgent` string to provide a quick identification of the browser.
43
+
44
+ * **Returns:** `BrowserDetected`
45
+ * **Best use case:** Quick, lightweight checks where absolute precision is not critical.
46
+
47
+ ```javascript
48
+ import { isBrowserAgent } from 'tiny-essentials/basics/browserDetector';
49
+
50
+ const browser = isBrowserAgent();
51
+ console.log(`You are using: ${browser}`);
52
+ // Output example: "chrome"
53
+ ```
54
+
55
+ ### 2. `getBrowserCssPrefix()`
56
+ Inspects the computed styles of the document to determine the CSS rendering engine.
57
+
58
+ * **Returns:** `'gecko' | 'webkit' | 'trident' | 'other'`
59
+ * **Best use case:** When you need to apply CSS vendor prefixes or handle engine-specific rendering quirks.
60
+
61
+ ```javascript
62
+ import { getBrowserCssPrefix } from 'tiny-essentials/basics/browserDetector';
63
+
64
+ const engine = getBrowserCssPrefix();
65
+ if (engine === 'webkit') {
66
+ console.log("Applying WebKit specific styles... 🎨");
67
+ }
68
+ ```
69
+
70
+ ### 3. `getDuckTyping()`
71
+ Performs deep feature detection by checking for the existence of specific global objects and APIs.
72
+
73
+ * **Returns:** `DuckTypingResult`
74
+ * **Best use case:** When you need to know exactly which features are available in the current environment.
75
+
76
+ ```javascript
77
+ import { getDuckTyping } from './browserDetector.js';
78
+
79
+ const features = getDuckTyping();
80
+
81
+ if (features.isChrome) {
82
+ console.log("Chrome-specific API available! ✅");
83
+ }
84
+
85
+ if (features.isBlink) {
86
+ console.log("Blink engine detected. ⚡");
87
+ }
88
+ ```
89
+
90
+ ---
91
+
92
+ ## 🎯 Advanced Detection
93
+
94
+ These functions aggregate the results from the core functions to provide the highest possible accuracy.
95
+
96
+ ### 4. `getBrowserPings(disable = [])`
97
+ Aggregates detection results from all three methods (User Agent, CSS Prefix, and Duck Typing) to provide a "ping count" for each browser.
98
+
99
+ * **Parameters:**
100
+ * `disable` (Array): An optional array of `BrowserDetected` names to exclude from the results.
101
+ * **Returns:** `Object<BrowserDetected, number>` (An object where keys are browsers and values are the number of times they were detected).
102
+ * **Throws:** `TypeError` if `disable` is not an array or contains invalid browser names.
103
+
104
+ ```javascript
105
+ import { getBrowserPings } from 'tiny-essentials/basics/browserDetector';
106
+
107
+ // Get detection counts for all browsers
108
+ const counts = getBrowserPings();
109
+ console.log(counts);
110
+
111
+ // Get counts while ignoring Internet Explorer
112
+ const filteredCounts = getBrowserPings(['ie']);
113
+ console.log(filteredCounts);
114
+ ```
115
+
116
+ ### 5. `browserIs(disable = [])`
117
+ The most reliable method. It runs all detection strategies and returns the browser that received the highest number of "pings."
118
+
119
+ * **Parameters:**
120
+ * `disable` (Array): An optional array of `BrowserDetected` names to exclude.
121
+ * **Returns:** `BrowserDetected` (The most likely browser name).
122
+ * **Throws:** `TypeError` if `disable` is not an array or contains invalid browser names.
123
+
124
+ ```javascript
125
+ import { browserIs } from 'tiny-essentials/basics/browserDetector';
126
+
127
+ // Get the most accurate browser identification
128
+ const currentBrowser = browserIs();
129
+
130
+ if (currentBrowser === 'firefox') {
131
+ console.log("Welcome, Firefox user! 🦊");
132
+ } else {
133
+ console.log(`Detected: ${currentBrowser}`);
134
+ }
135
+ ```
@@ -0,0 +1,119 @@
1
+ # 🛠️ TinyDebugger Documentation
2
+
3
+ `TinyDebugger` is a lightweight, event-driven debugging utility designed to wrap standard `console` methods. It provides enhanced features such as custom prefixes, color support, and the ability to emit events whenever a log occurs, making it perfect for complex applications where you might want to redirect logs to an external service or a UI component.
4
+
5
+ ## 🚀 Quick Start
6
+
7
+ To use `TinyDebugger`, import it into your project and initialize it with a configuration object.
8
+
9
+ ```javascript
10
+ import TinyDebugger from 'tiny-essentials/libs/TinyDebugger';
11
+
12
+ const debuggerInstance = new TinyDebugger({
13
+ logger: console, // You can use standard console or a custom object
14
+ id: 'APP_CORE',
15
+ debugMode: true,
16
+ canEmitLogs: true,
17
+ useLogColors: true
18
+ });
19
+
20
+ debuggerInstance.log('info', 'Hello, Yasmin! The debugger is ready. 🌟');
21
+ ```
22
+
23
+ ---
24
+
25
+ ## ⚙️ Configuration
26
+
27
+ When creating a new instance via the `constructor`, you can pass a configuration object with the following properties:
28
+
29
+ | Property | Type | Required | Default | Description |
30
+ | :--- | :--- | :--- | :--- | :--- |
31
+ | `logger` | `Object` | **Yes** | N/A | An object implementing the `Console` interface. |
32
+ | `id` | `string` | **Yes** | N/A | A unique identifier for this debugger instance. |
33
+ | `debugMode` | `boolean` | **Yes** | N/A | If `false`, all logging methods will return immediately. |
34
+ | `canEmitLogs` | `boolean` | No | `false` | If `true`, the instance will emit events for every log action. |
35
+ | `useLogColors` | `boolean` | No | `false` | Enables ANSI color codes. *Note: Automatically disabled in Firefox.* |
36
+
37
+ ---
38
+
39
+ ## ✨ Key Features
40
+
41
+ ### 🎨 Custom Colors
42
+ You can inject colors into your log messages using the `_colorName_` syntax.
43
+ * **Syntax:** `_color_`
44
+ * **Example:** `debugger.log('info', 'This is _red_ critical error!');`
45
+
46
+ ### 🏷️ Custom Prefixes
47
+ You can use placeholders to insert specific prefix text into your logs.
48
+ * **Syntax:** `:id:`
49
+ * **Example:** `debugger.log('info', ':info: System initialized.');`
50
+
51
+ ### 📡 Event Emission
52
+ If `canEmitLogs` is set to `true`, `TinyDebugger` acts as an `EventEmitter`, allowing you to listen to specific debugging events. This is incredibly useful for building custom developer consoles in web applications.
53
+
54
+ ---
55
+
56
+ ## 📖 API Reference
57
+
58
+ ### `log(logType, message, ...args)`
59
+ The primary method for logging.
60
+ * **logType:** `'log' | 'info' | 'warn' | 'error' | 'debug' | 'dirxml' | 'group' | 'groupCollapsed' | 'trace'`
61
+ * **message:** `string` (The text to display)
62
+ * **args:** `...any` (Additional data to inspect)
63
+
64
+ ### `logLabel(logType, label)`
65
+ Logs a specific console type associated with a label.
66
+ * **logType:** `'count' | 'countReset' | 'time' | 'timeEnd' | 'profile' | 'profileEnd' | 'timeStamp'`
67
+ * **label:** `string`
68
+
69
+ ### `logTimeLabel(label, ...args)`
70
+ Starts a timer with a specific label.
71
+ * **label:** `string`
72
+
73
+ ### `logAssert(condition, ...args)`
74
+ Logs a message only if the provided condition evaluates to `false`.
75
+ * **condition:** `boolean`
76
+
77
+ ### `logDir(item, options)`
78
+ Displays an element as a JavaScript object (similar to `console.dir`).
79
+ * **item:** `any`
80
+ * **options:** `InspectOptions`
81
+
82
+ ### `logTable(tabularData, properties)`
83
+ Displays data in a clean, readable table.
84
+ * **tabularData:** `any`
85
+ * **properties:** `string[]` (Optional array of column properties)
86
+
87
+ ### `logClear()`
88
+ Clears the console.
89
+ ### `logGroupEnd()`
90
+ Ends the current console group.
91
+
92
+ ---
93
+
94
+ ## 🛠️ Advanced Customization
95
+
96
+ You can dynamically modify the behavior of your debugger instance using these internal methods:
97
+
98
+ | Method | Description |
99
+ | :--- | :--- |
100
+ | `_addLogColor(id, code)` | Adds a new color shortcut (e.g., `_mycolor_`). |
101
+ | `_removeLogColor(id)` | Removes a color shortcut. |
102
+ | `_addLogPrefix(id, text)` | Adds a new prefix shortcut (e.g., `:status:`). |
103
+ | `_removeLogPrefix(id)` | Removes a prefix shortcut. |
104
+
105
+ ### Example: Adding a Custom Color
106
+ ```javascript
107
+ debuggerInstance._addLogColor('gold', '\x1b[33m');
108
+ debuggerInstance.log('info', 'This message is _gold_!');
109
+ ```
110
+
111
+ ---
112
+
113
+ ## ⚠️ Error Handling
114
+
115
+ It will throw `TypeError` if:
116
+ 1. The `logger` provided is not a valid object.
117
+ 2. The `id` is not a string.
118
+ 3. Configuration booleans are provided as other types.
119
+ 4. An invalid `logType` is passed to the logging methods.
@@ -252,7 +252,7 @@ When initializing `new TinyMediaPlayer(options)`, you can pass the following `Ti
252
252
  * **`existsTrack(index)`**: Returns `true` if the track exists at the given index.
253
253
  * **`getTrack(index)`**: Retrieves the track at the specified index.
254
254
  * **`removeTrack(index)`**: **(Async)** Removes a track and adjusts the current index/playback accordingly.
255
- * **`searchTrack(query)`**: Searches the playlist.
255
+ * **`searchTrack(query)`**: Searches the playlist (string or function).
256
256
  * `query`: A `string` (searches title, artist, or album) or a `function` (custom logic).
257
257
  * **Returns**: `SearchResult[]` (array of objects containing the track and their corresponding indices).
258
258
  * **`clearPlaylist()`**: **(Async)** Stops playback and empties the entire playlist.
@@ -260,22 +260,22 @@ When initializing `new TinyMediaPlayer(options)`, you can pass the following `Ti
260
260
  #### ⏯️ Playback Controls
261
261
  * **`play()`**: **(Async)** Starts playback of the current track.
262
262
  * **`pause()`**: **(Async)** Pauses the current track.
263
- * **`mute()`**: **(Async)** Mutes the playback.
264
- * **`unMute()`**: **(Async)** Unmutes the playback.
265
263
  * **`stop()`**: **(Async)** Stops the current track completely.
266
264
  * **`next()`**: **(Async)** Advances to the next track (respects `loopMode` and `isRandom`).
267
265
  * **`prev()`**: **(Async)** Returns to the previous track (respects `loopMode` and `isRandom`).
268
266
  * **`skipTo(index)`**: **(Async)** Jumps to a specific index in the playlist.
269
267
  * **`seek(timeMs)`**: **(Async)** Jumps to a specific millisecond in the current track.
270
268
  * **`step(stepMs)`**: **(Async)** Moves the timeline forward (+) or backward (-) by `stepMs`.
269
+ * **`mute()`**: **(Async)** Mutes the current playback.
270
+ * **`unMute()`**: **(Async)** Unmutes the current playback.
271
271
 
272
272
  #### ⏳ Time Utilities
273
273
  * **`getCurrentTime()`**: Gets the current playback time in milliseconds.
274
274
  * **`getTotalDuration()`**: Gets the total duration of the current track in milliseconds.
275
275
  * **`getRemainingTime()`**: Gets the remaining time until the current track ends in milliseconds.
276
276
  * **`getPlaybackPercentage()`**: Gets the percentage of the current track that has been played (0-100).
277
- * **`isPaused` (Getter)**: Checks if the adapter is paused.
278
- * **`isEnded` (Getter)**: Checks if the adapter has ended.
277
+ * **`isPaused`**: **(Getter)** Checks if the adapter is paused.
278
+ * **`isEnded`**: **(Getter)** Checks if the adapter has ended.
279
279
  * **`getContentData()`**: **(Async)** Retrieves structured metadata for the current content.
280
280
  * **`waitIsReady()`**: **(Async)** Waits until the active adapter is fully initialized.
281
281
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiny-essentials",
3
- "version": "1.28.8",
3
+ "version": "1.28.9",
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
  "bin": {
6
6
  "tiny-essentials-fork": "./TinyFork.mjs"
@@ -112,6 +112,10 @@
112
112
  "require": "./dist/v1/basics/promiseUtils.cjs",
113
113
  "import": "./dist/v1/basics/promiseUtils.mjs"
114
114
  },
115
+ "./basics/browserDetector": {
116
+ "require": "./dist/v1/basics/browserDetector.cjs",
117
+ "import": "./dist/v1/basics/browserDetector.mjs"
118
+ },
115
119
  "./fileManager": {
116
120
  "require": "./dist/v1/fileManager/index.cjs",
117
121
  "import": "./dist/v1/fileManager/index.mjs"
File without changes