tiny-essentials 1.0.0 → 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.
@@ -0,0 +1,77 @@
1
+ # ⏰ clock.mjs
2
+
3
+ A versatile time utility module for JavaScript that helps you calculate and format time durations with style. Whether you're building countdowns, timers, or just need a nice "HH:MM:SS" string, this module has your back!
4
+
5
+ ## ✨ Features
6
+
7
+ - 🔢 Calculate time differences in various units
8
+ - 🧭 Format durations into clean, readable timer strings
9
+ - 🧱 Support for years, months, days, hours, minutes, and seconds
10
+ - 🎛️ Customizable output with template-based formatting
11
+ - 🛠️ Built-in presets for classic timer formats
12
+ - 🪶 Zero dependencies, lightweight and modular (ESM-ready!)
13
+
14
+ ---
15
+
16
+ ## 🧠 API Overview
17
+
18
+ ### 🔹 `getTimeDuration(timeData, durationType = 'asSeconds', now = null)`
19
+
20
+ Calculates how much time remains (or has passed) between now and a given time.
21
+
22
+ | Param | Type | Description |
23
+ |---------------|----------|-----------------------------------------------------------------------------|
24
+ | `timeData` | `Date` | The target time |
25
+ | `durationType`| `string` | Format to return (`asMilliseconds`, `asSeconds`, `asMinutes`, etc.) |
26
+ | `now` | `Date` | Optional custom "now". Defaults to current time. |
27
+
28
+ **Returns:** `number|null` — The duration in the chosen unit.
29
+
30
+ ---
31
+
32
+ ### 🔹 `formatCustomTimer(totalSeconds, level = 'seconds', format = '{time}')`
33
+
34
+ Turns seconds into a custom timer string with fine-grained control.
35
+
36
+ | Param | Type | Description |
37
+ |-------------|----------|----------------------------------------------------------------------------------------------|
38
+ | `totalSeconds` | `number` | The duration to format (in seconds) |
39
+ | `level` | `string` | Highest level to show: `'seconds'`, `'minutes'`, `'hours'`, `'days'`, `'months'`, `'years'` |
40
+ | `format` | `string` | Output string template. Supports placeholders like `{days}`, `{hours}`, `{time}`, `{total}` |
41
+
42
+ **Returns:** `string` — A formatted string with padded units.
43
+
44
+ ---
45
+
46
+ ### 🔹 `formatTimer(seconds)`
47
+
48
+ Formats a duration into the classic `HH:MM:SS`.
49
+
50
+ ```js
51
+ formatTimer(3670); // "01:01:10"
52
+ ```
53
+
54
+ ---
55
+
56
+ ### 🔹 `formatDayTimer(seconds)`
57
+
58
+ Formats a duration into `Xd HH:MM:SS`, perfect for countdowns.
59
+
60
+ ```js
61
+ formatDayTimer(190000); // "2d 04:46:40"
62
+ ```
63
+
64
+ ---
65
+
66
+ ## 🧪 Examples
67
+
68
+ ```js
69
+ const futureTime = new Date(Date.now() + 10000);
70
+ const secondsLeft = getTimeDuration(futureTime, 'asSeconds');
71
+
72
+ console.log(formatTimer(secondsLeft)); // e.g. "00:00:09"
73
+ console.log(formatDayTimer(172800 + 3661)); // "2d 01:01:01"
74
+
75
+ const custom = formatCustomTimer(3600 * 26 + 61, 'days', '{days}d {hours}h {minutes}m {seconds}s');
76
+ console.log(custom); // "1d 2h 1m 1s"
77
+ ```
@@ -0,0 +1,120 @@
1
+ # 🧠 objFilter.mjs
2
+
3
+ Type detection, extension, and analysis made easy — simple and extensible type validation in pure JavaScript.
4
+
5
+ ## Overview
6
+
7
+ `objFilter.mjs` is a utility module that provides a structured and extensible way to validate, infer, and count object types in JavaScript. It’s designed to work in both Node.js and browser environments and is perfect for libraries that need consistent, extensible type-checking logic.
8
+
9
+ Whether you’re validating inputs, writing schema validators, or building tools that need to "understand" JavaScript data — this module has your back!
10
+
11
+ ---
12
+
13
+ ## Features
14
+
15
+ - ✅ Precise type detection (`undefined`, `null`, `array`, `buffer`, `date`, etc.)
16
+ - ➕ Custom type extensions with ordering
17
+ - 🔄 Reorder type checking priority
18
+ - 🔍 Safe and predictable type checks
19
+ - 🧮 Count values in arrays and objects
20
+ - 🚫 No dependencies
21
+
22
+ ---
23
+
24
+ ## Usage
25
+
26
+ ### 🔍 `objType(obj, [type])`
27
+
28
+ Get the type of any value, or check it against a known type.
29
+
30
+ ```js
31
+ objType([], 'array'); // true
32
+ objType('hello'); // "string"
33
+ objType(undefined); // null
34
+ ```
35
+
36
+ Returns:
37
+ - `true` / `false` if a type is provided
38
+ - The detected type name as a string if no type is provided
39
+ - `null` if `undefined` is passed
40
+
41
+ ---
42
+
43
+ ### ➕ `extendObjType(newTypes, [index])`
44
+
45
+ Add your own custom types. You can optionally define where in the check order they go.
46
+
47
+ ```js
48
+ extendObjType({
49
+ customElement: val => val && val.tagName === 'MY-ELEMENT'
50
+ });
51
+ ```
52
+
53
+ This will insert `customElement` before the built-in `object` type unless a position is specified.
54
+
55
+ ---
56
+
57
+ ### 🔁 `reorderObjTypeOrder(newOrder)`
58
+
59
+ Set a custom priority order for how types are checked (must include only known types).
60
+
61
+ ```js
62
+ reorderObjTypeOrder([
63
+ 'string',
64
+ 'number',
65
+ 'array',
66
+ 'object'
67
+ ]);
68
+ ```
69
+
70
+ Returns `true` if successful, or `false` if the order includes unknown types.
71
+
72
+ ---
73
+
74
+ ### 📋 `cloneObjTypeOrder()`
75
+
76
+ Safely get a copy of the current type evaluation order.
77
+
78
+ ```js
79
+ const currentOrder = cloneObjTypeOrder();
80
+ ```
81
+
82
+ ---
83
+
84
+ ### 🧮 `countObj(obj)`
85
+
86
+ Returns the number of elements in an array or the number of keys in an object.
87
+
88
+ ```js
89
+ countObj([1, 2, 3]); // 3
90
+ countObj({ a: 1, b: 2 }); // 2
91
+ countObj('hi'); // 0
92
+ ```
93
+
94
+ ---
95
+
96
+ ## Supported Types
97
+
98
+ Here’s a full list of supported type names (in their default order):
99
+
100
+ - `undefined`
101
+ - `null`
102
+ - `boolean`
103
+ - `number`
104
+ - `bigint`
105
+ - `string`
106
+ - `symbol`
107
+ - `function`
108
+ - `array`
109
+ - `buffer`
110
+ - `date`
111
+ - `regexp`
112
+ - `map`
113
+ - `set`
114
+ - `weakmap`
115
+ - `weakset`
116
+ - `promise`
117
+ - `htmlElement`
118
+ - `object`
119
+
120
+ You can change this order or insert your own types with `extendObjType`.
@@ -0,0 +1,65 @@
1
+ # 🔢 simpleMath.mjs
2
+
3
+ A collection of simple math utilities that make basic calculations a breeze.
4
+
5
+ ## Overview
6
+
7
+ `simpleMath.mjs` offers a set of essential mathematical functions, from the classic Rule of Three (direct and inverse proportions) to calculating percentages and even determining age based on a birthdate. It's an easy-to-use module for anyone who needs to perform fundamental calculations in JavaScript.
8
+
9
+ ---
10
+
11
+ ## Functions
12
+
13
+ ### 🔢 `ruleOfThree(val1, val2, val3, inverse)`
14
+
15
+ **Performs a Rule of Three calculation.**
16
+ This function calculates a proportional relationship between three values, which is commonly used in mathematical and real-world scenarios.
17
+
18
+ - **`val1`**: First reference value (numerator in direct proportion, denominator in inverse).
19
+ - **`val2`**: Second reference value (denominator in direct proportion, numerator in inverse).
20
+ - **`val3`**: Third value (numerator in direct proportion, denominator in inverse).
21
+ - **`inverse`**: Set to `true` for inverse proportion, or `false` for direct proportion.
22
+
23
+ #### Example - Direct Proportion:
24
+
25
+ ```js
26
+ ruleOfThree(2, 6, 3, false); // → 9
27
+ ```
28
+
29
+ #### Example - Inverse Proportion:
30
+
31
+ ```js
32
+ ruleOfThree(2, 6, 3, true); // → 4
33
+ ```
34
+
35
+ ---
36
+
37
+ ### 💯 `getSimplePerc(price, percentage)`
38
+
39
+ **Calculates the percentage of a given base value.**
40
+
41
+ - **`price`**: The base value (for example, the original price of an item).
42
+ - **`percentage`**: The percentage to calculate from the base value.
43
+
44
+ #### Example:
45
+
46
+ ```js
47
+ getSimplePerc(200, 15); // → 30
48
+ ```
49
+
50
+ ---
51
+
52
+ ### 🎂 `getAge(timeData, now)`
53
+
54
+ **Calculates the age based on a birthdate.**
55
+
56
+ - **`timeData`**: The birthdate. It can be a timestamp, an ISO string, or a `Date` object.
57
+ - **`now`**: The current date (`Date` object). If not provided, the current date will be used.
58
+
59
+ If the `timeData` is not provided or is invalid, the function returns `null`.
60
+
61
+ #### Example:
62
+
63
+ ```js
64
+ getAge('1990-01-01'); // → 35 (assuming the current year is 2025)
65
+ ```
@@ -0,0 +1,38 @@
1
+
2
+ # ✍️ text.mjs
3
+
4
+ A simple utility for transforming text into title case formats.
5
+
6
+ ## Overview
7
+
8
+ `text.mjs` provides two functions to help format strings into different types of title case. These functions are useful for formatting titles, headings, or any text that needs consistent capitalization. You can choose between capitalizing the first letter of each word or leaving the first letter of the string in lowercase.
9
+
10
+ ---
11
+
12
+ ## Functions
13
+
14
+ ### 📝 `toTitleCase(str)`
15
+
16
+ **Converts a string to title case**, where the first letter of each word is capitalized, and all other letters are converted to lowercase.
17
+
18
+ - **`str`**: The string to be converted to title case.
19
+
20
+ #### Example:
21
+
22
+ ```js
23
+ toTitleCase('hello world'); // → "Hello World"
24
+ ```
25
+
26
+ ---
27
+
28
+ ### 📝 `toTitleCaseLowerFirst(str)`
29
+
30
+ **Converts a string to title case**, where the first letter of each word is capitalized, but the first letter of the entire string remains lowercase.
31
+
32
+ - **`str`**: The string to be converted to title case with the first letter in lowercase.
33
+
34
+ #### Example:
35
+
36
+ ```js
37
+ toTitleCaseLowerFirst('hello world'); // → "hello World"
38
+ ```
@@ -0,0 +1,177 @@
1
+ # 🔐 Tiny Crypto
2
+
3
+ **Tiny Crypto** is a flexible and browser-compatible encryption utility class built for AES-256-GCM encryption with full support for serialization and deserialization of complex JavaScript data types.
4
+
5
+ Whether you're in Node.js or a browser, Tiny Crypto helps you easily encrypt/decrypt values, save/load configurations, and keep your secrets safe — all while supporting real-world usage like RegExp, Date, Buffer, and even DOM elements (in browsers only)!
6
+
7
+ ---
8
+
9
+ ## ✨ Features
10
+
11
+ - 🔒 AES-256-GCM symmetric encryption
12
+ - 🧠 Automatic serialization of complex types (Date, RegExp, Set, Map, etc.)
13
+ - 📤 Save and load keys/configs from files
14
+ - 🌐 Works in both **Node.js** and **Browsers**
15
+ - ⚠️ Type validation on decryption
16
+ - 💾 Smart support for file APIs (e.g. `FileReader` in browser, `fs` in Node)
17
+
18
+ ---
19
+
20
+ ## 🚀 Getting Started
21
+
22
+ ```js
23
+ const crypto = new TinyCrypto();
24
+
25
+ // Encrypt some data
26
+ const { encrypted, iv, authTag } = crypto.encrypt({ hello: 'world' });
27
+
28
+ // Decrypt it back
29
+ const decrypted = crypto.decrypt({ encrypted, iv, authTag });
30
+
31
+ console.log(decrypted); // { hello: 'world' }
32
+ ```
33
+
34
+ ---
35
+
36
+ ## 🧠 Supported Data Types
37
+
38
+ When you encrypt a value, its type is recorded and restored when decrypted.
39
+
40
+ Supports:
41
+
42
+ - `String`, `Number`, `Boolean`, `BigInt`, `Null`, `Undefined`
43
+ - `Array`, `Object`, `Map`, `Set`, `Buffer`
44
+ - `RegExp`, `Date`, `Symbol`
45
+ - `HTMLElement` _(browser only)_
46
+
47
+ Does NOT support:
48
+
49
+ - `Function`, `Promise`, `WeakMap`, `WeakSet` → ❌ Will throw!
50
+
51
+ ---
52
+
53
+ ## 🔧 API
54
+
55
+ ### `constructor(options)`
56
+
57
+ | Option | Type | Default | Description |
58
+ | ---------------- | ------ | --------------- | --------------------------------- |
59
+ | `algorithm` | string | `'aes-256-gcm'` | AES algorithm used for encryption |
60
+ | `key` | Buffer | auto-generated | The secret key to use (32 bytes) |
61
+ | `outputEncoding` | string | `'hex'` | Encoding used for outputs |
62
+ | `inputEncoding` | string | `'utf8'` | Encoding used for plain data |
63
+ | `authTagLength` | number | `16` | GCM auth tag length |
64
+
65
+ ---
66
+
67
+ ### `encrypt(data, iv?)`
68
+
69
+ Encrypts a value and returns an object with `{ iv, encrypted, authTag }`.
70
+
71
+ ```js
72
+ const result = crypto.encrypt('Hello!');
73
+ ```
74
+
75
+ ---
76
+
77
+ ### `decrypt({ iv, encrypted, authTag }, expectedType?)`
78
+
79
+ Decrypts a previously encrypted value and returns the original data. You can optionally pass an `expectedType` to validate it.
80
+
81
+ ```js
82
+ const plain = crypto.decrypt(result, 'String');
83
+ ```
84
+
85
+ ---
86
+
87
+ ### `getTypeFromEncrypted({ iv, encrypted, authTag })`
88
+
89
+ Returns the type name of the encrypted data without fully decrypting it.
90
+
91
+ ---
92
+
93
+ ### `generateKey(length = 32)`
94
+
95
+ Generates a secure random key. Default: 32 bytes (AES-256).
96
+
97
+ ---
98
+
99
+ ### `generateIV(length = 12)`
100
+
101
+ Generates a secure random IV. Default: 12 bytes (GCM standard).
102
+
103
+ ---
104
+
105
+ ### `saveKeyToFile(filename = 'secret.key')`
106
+
107
+ Saves the current key to a file (browser: prompts download).
108
+
109
+ ---
110
+
111
+ ### `loadKeyFromFile(file)`
112
+
113
+ Loads a key from a file (browser: File object, Node: file path).
114
+
115
+ ---
116
+
117
+ ### `saveConfigToFile(filename = 'crypto-config.json')`
118
+
119
+ Saves the current configuration as JSON.
120
+
121
+ ---
122
+
123
+ ### `loadConfigFromFile(file)`
124
+
125
+ Loads configuration from a JSON file.
126
+
127
+ ---
128
+
129
+ ### `exportConfig()`
130
+
131
+ Returns an object with the current settings:
132
+
133
+ ```json
134
+ {
135
+ "algorithm": "aes-256-gcm",
136
+ "outputEncoding": "hex",
137
+ "inputEncoding": "utf8",
138
+ "authTagLength": 16,
139
+ "key": "..." // hex string
140
+ }
141
+ ```
142
+
143
+ ---
144
+
145
+ ### `importConfig(config)`
146
+
147
+ Applies a configuration object. Throws if invalid types are provided.
148
+
149
+ ---
150
+
151
+ ## 🧪 Type Validation
152
+
153
+ You can ensure the decrypted value matches the original type:
154
+
155
+ ```js
156
+ crypto.decrypt(result, 'map'); // ✅
157
+ crypto.decrypt(result, 'set'); // ❌ throws if type mismatch
158
+ ```
159
+
160
+ ---
161
+
162
+ ## ❗ Errors You Might See
163
+
164
+ - `Unsupported data type for encryption: Function`
165
+ - `Type mismatch: expected Map, but got Set`
166
+ - `Invalid config JSON file`
167
+ - `HTMLElement deserialization is only supported in browsers`
168
+
169
+ ---
170
+
171
+ ## 🛡️ Security Notice
172
+
173
+ This utility is for learning and light usage. For production, ensure:
174
+
175
+ - Proper key management (use secure vaults)
176
+ - Safe IV reuse (IVs must be unique per encryption)
177
+ - Your platform's crypto standards are followed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiny-essentials",
3
- "version": "1.0.0",
3
+ "version": "1.1.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",
@@ -30,7 +30,20 @@
30
30
  "type": "git",
31
31
  "url": "git+https://github.com/JasminDreasond/Tiny-Essentials.git"
32
32
  },
33
- "keywords": [],
33
+ "keywords": [
34
+ "@tinypudding/firebase-lib",
35
+ "@tinypudding/discord-oauth2",
36
+ "@tinypudding/mysql-connector",
37
+ "@tinypudding/puddy-lib",
38
+ "clock",
39
+ "obj-type",
40
+ "simple-math",
41
+ "text",
42
+ "lib",
43
+ "time",
44
+ "shuffle-array",
45
+ "cryptography"
46
+ ],
34
47
  "author": "Yasmin Seidel (Jasmin Dreasond)",
35
48
  "license": "GPL-3.0-only",
36
49
  "bugs": {
@@ -62,6 +75,7 @@
62
75
  "object-hash": "^3.0.0",
63
76
  "prettier": "3.5.3",
64
77
  "rollup": "^4.40.0",
78
+ "rollup-plugin-polyfill-node": "^0.13.0",
65
79
  "rollup-preserve-directives": "^1.1.3",
66
80
  "tinycolor2": "^1.6.0",
67
81
  "tslib": "^2.8.1",