tiny-essentials 1.20.3 → 1.21.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/README.md +13 -11
- package/dist/_/numbers.cjs +136 -0
- package/dist/_/numbers.d.mts +24 -0
- package/dist/_/numbers.mjs +102 -0
- package/dist/v1/TinyAdvancedRaffle.min.js +1 -0
- package/dist/v1/TinyArrayPaginator.min.js +1 -0
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyCookieConsent.min.js +1 -0
- package/dist/v1/TinyDayNightCycle.min.js +1 -0
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyGamepad.min.js +1 -0
- package/dist/v1/TinyI18.min.js +1 -0
- package/dist/v1/TinyInventory.min.js +1 -0
- package/dist/v1/TinyInventoryTrader.min.js +1 -0
- package/dist/v1/TinyLocalStorage.min.js +1 -1
- package/dist/v1/TinyRateLimiter.min.js +1 -1
- package/dist/v1/TinySmartScroller.min.js +1 -1
- package/dist/v1/TinyToastNotify.min.js +1 -1
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/basics/array.cjs +21 -0
- package/dist/v1/basics/array.d.mts +8 -0
- package/dist/v1/basics/array.mjs +18 -0
- package/dist/v1/basics/index.cjs +2 -8
- package/dist/v1/basics/index.d.mts +3 -8
- package/dist/v1/basics/index.mjs +2 -3
- package/dist/v1/basics/simpleMath.cjs +46 -0
- package/dist/v1/basics/simpleMath.d.mts +27 -0
- package/dist/v1/basics/simpleMath.mjs +42 -0
- package/dist/v1/build/TinyAdvancedRaffle.cjs +7 -0
- package/dist/v1/build/TinyAdvancedRaffle.d.mts +3 -0
- package/dist/v1/build/TinyAdvancedRaffle.mjs +2 -0
- package/dist/v1/build/TinyArrayPaginator.cjs +7 -0
- package/dist/v1/build/TinyArrayPaginator.d.mts +3 -0
- package/dist/v1/build/TinyArrayPaginator.mjs +2 -0
- package/dist/v1/build/TinyCookieConsent.cjs +7 -0
- package/dist/v1/build/TinyCookieConsent.d.mts +3 -0
- package/dist/v1/build/TinyCookieConsent.mjs +2 -0
- package/dist/v1/build/TinyDayNightCycle.cjs +7 -0
- package/dist/v1/build/TinyDayNightCycle.d.mts +3 -0
- package/dist/v1/build/TinyDayNightCycle.mjs +2 -0
- package/dist/v1/build/TinyGamepad.cjs +7 -0
- package/dist/v1/build/TinyGamepad.d.mts +3 -0
- package/dist/v1/build/TinyGamepad.mjs +2 -0
- package/dist/v1/build/TinyI18.cjs +7 -0
- package/dist/v1/build/TinyI18.d.mts +3 -0
- package/dist/v1/build/TinyI18.mjs +2 -0
- package/dist/v1/build/TinyInventory.cjs +7 -0
- package/dist/v1/build/TinyInventory.d.mts +3 -0
- package/dist/v1/build/TinyInventory.mjs +2 -0
- package/dist/v1/build/TinyInventoryTrader.cjs +7 -0
- package/dist/v1/build/TinyInventoryTrader.d.mts +3 -0
- package/dist/v1/build/TinyInventoryTrader.mjs +2 -0
- package/dist/v1/css/TinyCookieConsent.min.css +1 -0
- package/dist/v1/index.cjs +18 -8
- package/dist/v1/index.d.mts +11 -8
- package/dist/v1/index.mjs +10 -3
- package/dist/v1/libs/TinyAdvancedRaffle.cjs +1654 -0
- package/dist/v1/libs/TinyAdvancedRaffle.d.mts +851 -0
- package/dist/v1/libs/TinyAdvancedRaffle.mjs +1477 -0
- package/dist/v1/libs/TinyArrayPaginator.cjs +132 -0
- package/dist/v1/libs/TinyArrayPaginator.d.mts +78 -0
- package/dist/v1/libs/TinyArrayPaginator.mjs +119 -0
- package/dist/v1/libs/TinyCookieConsent.cjs +278 -0
- package/dist/v1/libs/TinyCookieConsent.d.mts +142 -0
- package/dist/v1/libs/TinyCookieConsent.mjs +248 -0
- package/dist/v1/libs/TinyDayNightCycle.cjs +1389 -0
- package/dist/v1/libs/TinyDayNightCycle.d.mts +673 -0
- package/dist/v1/libs/TinyDayNightCycle.mjs +1232 -0
- package/dist/v1/libs/TinyGamepad.cjs +2690 -0
- package/dist/v1/libs/TinyGamepad.d.mts +1286 -0
- package/dist/v1/libs/TinyGamepad.mjs +2386 -0
- package/dist/v1/libs/TinyHtml.d.mts +2 -2
- package/dist/v1/libs/TinyI18.cjs +946 -0
- package/dist/v1/libs/TinyI18.d.mts +418 -0
- package/dist/v1/libs/TinyI18.mjs +873 -0
- package/dist/v1/libs/TinyInventory.cjs +1788 -0
- package/dist/v1/libs/TinyInventory.d.mts +871 -0
- package/dist/v1/libs/TinyInventory.mjs +1650 -0
- package/dist/v1/libs/TinyInventoryTrader.cjs +242 -0
- package/dist/v1/libs/TinyInventoryTrader.d.mts +95 -0
- package/dist/v1/libs/TinyInventoryTrader.mjs +212 -0
- package/dist/v1/libs/TinyLocalStorage.cjs +14 -1
- package/dist/v1/libs/TinyLocalStorage.mjs +8 -1
- package/dist/v1/libs/TinyRateLimiter.cjs +0 -13
- package/dist/v1/libs/TinyRateLimiter.d.mts +0 -8
- package/dist/v1/libs/TinyRateLimiter.mjs +0 -12
- package/dist/v1/libs/TinySmartScroller.cjs +0 -51
- package/dist/v1/libs/TinySmartScroller.d.mts +0 -36
- package/dist/v1/libs/TinySmartScroller.mjs +0 -46
- package/dist/v1/libs/TinyToastNotify.cjs +2 -2
- package/dist/v1/libs/TinyToastNotify.mjs +2 -2
- package/dist/v1/libs/TinyUploadClicker.cjs +1 -1
- package/docs/v1/Ai-Tips.md +51 -0
- package/docs/v1/Personal-Ai-Prompts(portuguese).md +134 -0
- package/docs/v1/Personal-Ai-Prompts.md +113 -0
- package/docs/v1/README.md +23 -0
- package/docs/v1/basics/array.md +17 -0
- package/docs/v1/basics/simpleMath.md +73 -0
- package/docs/v1/libs/TinyAdvancedRaffle.md +674 -0
- package/docs/v1/libs/TinyArrayPaginator.md +150 -0
- package/docs/v1/libs/TinyCookieConsent.md +152 -0
- package/docs/v1/libs/TinyDayNightCycle.md +711 -0
- package/docs/v1/libs/TinyGamepad.md +980 -0
- package/docs/v1/libs/TinyI18.md +515 -0
- package/docs/v1/libs/TinyInventory.md +777 -0
- package/docs/v1/libs/TinyInventoryTrader.md +114 -0
- package/package.json +7 -5
- package/dist/v1/basics/html_deprecated.cjs +0 -124
- package/dist/v1/basics/html_deprecated.d.mts +0 -40
- package/dist/v1/basics/html_deprecated.mjs +0 -97
- package/dist/v1/css/TinyDraggerExample.css +0 -21
- package/dist/v1/css/TinyNotify.css +0 -350
- package/dist/v1/css/aiMarker.css +0 -4
- package/docs/v1/basics/html_deprecated.md +0 -127
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# 📚 TinyArrayPaginator
|
|
2
|
+
|
|
3
|
+
A small but powerful utility for **paginating arrays or sets** 🔄.
|
|
4
|
+
It allows you to filter data using **objects**, **functions**, or **regular expressions**, and retrieve paginated results along with useful metadata.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 🔍 GetFilter — Predicate Function
|
|
9
|
+
|
|
10
|
+
A predicate function used to determine whether an item should be included in the filtered results.
|
|
11
|
+
Works similarly to the callback function of `Array.prototype.filter`.
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
/**
|
|
15
|
+
* @callback GetFilter
|
|
16
|
+
* @param {any} value - The current element being processed in the array.
|
|
17
|
+
* @param {number} index - The index of the current element within the array.
|
|
18
|
+
* @param {any[]} array - The full array being processed.
|
|
19
|
+
* @returns {boolean} - `true` to include the element, `false` to exclude it.
|
|
20
|
+
*/
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 🛠 Class: `TinyArrayPaginator`
|
|
26
|
+
|
|
27
|
+
### ✨ Features
|
|
28
|
+
|
|
29
|
+
* **Immutable source safety** — The original array/set is never modified.
|
|
30
|
+
* **Flexible filtering** — Supports:
|
|
31
|
+
|
|
32
|
+
* Object key-value filters
|
|
33
|
+
* Custom filter functions
|
|
34
|
+
* RegExp matching
|
|
35
|
+
* **Pagination metadata** — Returns total items, total pages, and navigation info.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
### 🏗 Constructor
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
new TinyArrayPaginator(data)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Parameters:**
|
|
46
|
+
|
|
47
|
+
* `data` (`any[] | Set<any>`) — The data source to paginate.
|
|
48
|
+
|
|
49
|
+
**Throws:**
|
|
50
|
+
|
|
51
|
+
* `TypeError` if `data` is not an array or set.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
### 📥 `.data` (Getter)
|
|
56
|
+
|
|
57
|
+
Gets the current stored array/set.
|
|
58
|
+
|
|
59
|
+
**Returns:**
|
|
60
|
+
`any[] | Set<any>`
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
### 📤 `.data` (Setter)
|
|
65
|
+
|
|
66
|
+
Replaces the current data source.
|
|
67
|
+
|
|
68
|
+
**Parameters:**
|
|
69
|
+
|
|
70
|
+
* `value` (`any[] | Set<any>`) — The new data source.
|
|
71
|
+
|
|
72
|
+
**Throws:**
|
|
73
|
+
|
|
74
|
+
* `TypeError` if the value is not an array or set.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
### 📏 `.size`
|
|
79
|
+
|
|
80
|
+
Gets the total number of items in the current data source.
|
|
81
|
+
|
|
82
|
+
**Returns:**
|
|
83
|
+
`number`
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
### 📄 `.get({ page, perPage, filter })`
|
|
88
|
+
|
|
89
|
+
Filters and paginates the stored data.
|
|
90
|
+
|
|
91
|
+
**Parameters:**
|
|
92
|
+
|
|
93
|
+
* `page` (`number`) — The page number (1-based).
|
|
94
|
+
* `perPage` (`number`) — Number of items per page.
|
|
95
|
+
* `filter` (`Record<string, any> | GetFilter`, optional) — Filtering criteria:
|
|
96
|
+
|
|
97
|
+
* **Object** — Key-value pairs for exact match, substring match, or RegExp.
|
|
98
|
+
* **RegExp** values in the object are matched using `.test()`.
|
|
99
|
+
|
|
100
|
+
**Returns:**
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
{
|
|
104
|
+
items: any[], // Items for the current page
|
|
105
|
+
page: number, // Current page number (validated)
|
|
106
|
+
perPage: number, // Items per page
|
|
107
|
+
totalItems: number, // Total filtered items
|
|
108
|
+
totalPages: number, // Total available pages
|
|
109
|
+
hasPrev: boolean, // True if a previous page exists
|
|
110
|
+
hasNext: boolean // True if a next page exists
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**Throws:**
|
|
115
|
+
|
|
116
|
+
* `RangeError` if `page` or `perPage` is not a positive integer.
|
|
117
|
+
* `TypeError` if `filter` is neither an object nor a function.
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
### 📌 Example Usage
|
|
122
|
+
|
|
123
|
+
```js
|
|
124
|
+
import TinyArrayPaginator from './TinyArrayPaginator.js';
|
|
125
|
+
|
|
126
|
+
const paginator = new TinyArrayPaginator([
|
|
127
|
+
{ id: 1, category: 'fruit' },
|
|
128
|
+
{ id: 2, category: 'vegetable' },
|
|
129
|
+
{ id: 3, category: 'fruit' },
|
|
130
|
+
{ id: 4, category: 'grain' }
|
|
131
|
+
]);
|
|
132
|
+
|
|
133
|
+
// Example: Filter only fruits and get the first page
|
|
134
|
+
const result = paginator.get({
|
|
135
|
+
page: 1,
|
|
136
|
+
perPage: 2,
|
|
137
|
+
filter: { category: 'fruit' }
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
console.log(result);
|
|
141
|
+
// {
|
|
142
|
+
// items: [{ id: 1, category: 'fruit' }, { id: 3, category: 'fruit' }],
|
|
143
|
+
// page: 1,
|
|
144
|
+
// perPage: 2,
|
|
145
|
+
// totalItems: 2,
|
|
146
|
+
// totalPages: 1,
|
|
147
|
+
// hasPrev: false,
|
|
148
|
+
// hasNext: false
|
|
149
|
+
// }
|
|
150
|
+
```
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# 🍪 TinyCookieConsent
|
|
2
|
+
|
|
3
|
+
A flexible and customizable **cookie consent manager** for the web.
|
|
4
|
+
It displays a consent bar, lets users manage categories, and stores preferences in `localStorage`.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## ✨ Features
|
|
9
|
+
|
|
10
|
+
* 📊 Displays a **consent bar** with customizable text and buttons
|
|
11
|
+
* 🗂️ Supports **multiple categories** (required, analytics, ads, etc.)
|
|
12
|
+
* 💾 Stores preferences in **localStorage**
|
|
13
|
+
* 🔔 Provides **callbacks** when preferences are saved
|
|
14
|
+
* 🎨 Fully customizable with **custom renderers**
|
|
15
|
+
* 🎬 Smooth **animations** for showing/hiding elements
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## 📦 Typedefs
|
|
20
|
+
|
|
21
|
+
### 🗂️ `Category`
|
|
22
|
+
|
|
23
|
+
| Property | Type | Description |
|
|
24
|
+
| ---------- | --------- | ---------------------------------------------------- |
|
|
25
|
+
| `label` | `string` | Category label displayed to the user |
|
|
26
|
+
| `required` | `boolean` | If `true`, category cannot be disabled |
|
|
27
|
+
| `default` | `boolean` | Default state (`true = enabled`, `false = disabled`) |
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
### ⚙️ `Config`
|
|
32
|
+
|
|
33
|
+
| Property | Type | Description |
|
|
34
|
+
| ------------------- | -------------------------------------- | ----------------------------------------------- |
|
|
35
|
+
| `message` | `string` | Consent message shown in the bar |
|
|
36
|
+
| `acceptText` | `string` | Text for the **"Accept All"** button |
|
|
37
|
+
| `rejectText` | `string` | Text for the **"Reject All"** button |
|
|
38
|
+
| `settingsText` | `string` | Text for the **"Manage Settings"** button |
|
|
39
|
+
| `categories` | `Category[]` | List of cookie categories |
|
|
40
|
+
| `storageKey` | `string` | Key used in `localStorage` |
|
|
41
|
+
| `onSave` | `(preferences: Object) => void` | Callback fired when preferences are saved |
|
|
42
|
+
| `animationDuration` | `number` (default: `400`) | Animation duration in milliseconds |
|
|
43
|
+
| `renderBar` | `((config: Config) => string) \| null` | Optional custom HTML renderer for the **bar** |
|
|
44
|
+
| `renderModal` | `((config: Config) => string) \| null` | Optional custom HTML renderer for the **modal** |
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## 🏗️ Class: `TinyCookieConsent`
|
|
49
|
+
|
|
50
|
+
### 🔑 Constructor
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
new TinyCookieConsent(config: Config)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
* Creates a new cookie consent manager instance.
|
|
57
|
+
* Automatically loads stored preferences, or shows the consent bar if none are saved.
|
|
58
|
+
|
|
59
|
+
Throws:
|
|
60
|
+
|
|
61
|
+
* `TypeError` if `config` is not a valid object.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
### 📖 Properties
|
|
66
|
+
|
|
67
|
+
| Property | Type | Description |
|
|
68
|
+
| ------------- | ------------------------- | -------------------------------------------------- |
|
|
69
|
+
| `preferences` | `Record<string, boolean>` | Returns stored preferences (or `{}` if none exist) |
|
|
70
|
+
| `config` | `Config` | Returns the current configuration |
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
### 🛠️ Methods
|
|
75
|
+
|
|
76
|
+
#### 🔍 `validateConfig(config: Partial<Config>): void`
|
|
77
|
+
|
|
78
|
+
Validates a config object.
|
|
79
|
+
Throws `TypeError` if any field is invalid.
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
#### 🗂️ `validateCategory(cat: Category, index: number): void`
|
|
84
|
+
|
|
85
|
+
Ensures a category object is valid.
|
|
86
|
+
Throws if fields are missing or of the wrong type.
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
#### 💾 `loadPreferences(): Record<string, boolean> \| null`
|
|
91
|
+
|
|
92
|
+
Loads preferences from `localStorage`.
|
|
93
|
+
Returns `null` if no preferences are saved.
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
#### 🎬 `removeWithAnimation(el: HTMLElement): void`
|
|
98
|
+
|
|
99
|
+
Removes an element with a fade/slide animation.
|
|
100
|
+
Uses `config.animationDuration`.
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
#### 💾 `savePreferences(prefs: Record<string, boolean>): void`
|
|
105
|
+
|
|
106
|
+
Saves preferences to `localStorage` and fires the `onSave` callback.
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
#### 📊 `showConsentBar(): void`
|
|
111
|
+
|
|
112
|
+
Displays the initial **consent bar**.
|
|
113
|
+
Includes buttons:
|
|
114
|
+
|
|
115
|
+
* ✅ Accept All
|
|
116
|
+
* ❌ Reject All
|
|
117
|
+
* ⚙️ Manage Settings
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
#### ⚙️ `showSettingsModal(bar: HTMLElement): void`
|
|
122
|
+
|
|
123
|
+
Displays a modal for fine-grained category control.
|
|
124
|
+
Allows toggling each category, then saving preferences.
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
#### 🔎 `isAllowed(category: string): boolean`
|
|
129
|
+
|
|
130
|
+
Checks whether a given category is enabled.
|
|
131
|
+
Returns `false` if preferences are missing or category is not allowed.
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## 🧩 Example Usage
|
|
136
|
+
|
|
137
|
+
```js
|
|
138
|
+
import TinyCookieConsent from './TinyCookieConsent.mjs';
|
|
139
|
+
|
|
140
|
+
const consent = new TinyCookieConsent({
|
|
141
|
+
message: "We use cookies to personalize your experience.",
|
|
142
|
+
acceptText: "Accept All",
|
|
143
|
+
rejectText: "Reject All",
|
|
144
|
+
settingsText: "Cookie Settings",
|
|
145
|
+
categories: [
|
|
146
|
+
{ label: "Essential", required: true, default: true },
|
|
147
|
+
{ label: "Analytics", required: false, default: false },
|
|
148
|
+
{ label: "Ads", required: false, default: false }
|
|
149
|
+
],
|
|
150
|
+
onSave: (prefs) => console.log("Saved preferences:", prefs),
|
|
151
|
+
});
|
|
152
|
+
```
|