tiny-essentials 1.3.1 → 1.4.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.
@@ -6,7 +6,7 @@
6
6
  * @param {number} val1 - The first reference value (numerator in direct proportion, denominator in inverse).
7
7
  * @param {number} val2 - The second reference value (denominator in direct proportion, numerator in inverse).
8
8
  * @param {number} val3 - The third value (numerator in direct proportion, denominator in inverse).
9
- * @param {boolean} inverse - Whether the calculation should use inverse proportion (true for inverse, false for direct).
9
+ * @param {boolean} [inverse] - Whether the calculation should use inverse proportion (true for inverse, false for direct).
10
10
  * @returns {number} The result of the Rule of Three operation.
11
11
  *
12
12
  * Rule of Three Formula (Direct Proportion):
@@ -35,7 +35,7 @@
35
35
  * // Inverse proportion:
36
36
  * ruleOfThree.execute(2, 6, 3, true); // → 4
37
37
  */
38
- function ruleOfThree(val1, val2, val3, inverse) {
38
+ function ruleOfThree(val1, val2, val3, inverse = false) {
39
39
  return inverse ? Number(val1 * val2) / val3 : Number(val3 * val2) / val1;
40
40
  }
41
41
 
@@ -4,7 +4,7 @@
4
4
  * @param {number} val1 - The first reference value (numerator in direct proportion, denominator in inverse).
5
5
  * @param {number} val2 - The second reference value (denominator in direct proportion, numerator in inverse).
6
6
  * @param {number} val3 - The third value (numerator in direct proportion, denominator in inverse).
7
- * @param {boolean} inverse - Whether the calculation should use inverse proportion (true for inverse, false for direct).
7
+ * @param {boolean} [inverse] - Whether the calculation should use inverse proportion (true for inverse, false for direct).
8
8
  * @returns {number} The result of the Rule of Three operation.
9
9
  *
10
10
  * Rule of Three Formula (Direct Proportion):
@@ -33,7 +33,7 @@
33
33
  * // Inverse proportion:
34
34
  * ruleOfThree.execute(2, 6, 3, true); // → 4
35
35
  */
36
- export function ruleOfThree(val1: number, val2: number, val3: number, inverse: boolean): number;
36
+ export function ruleOfThree(val1: number, val2: number, val3: number, inverse?: boolean): number;
37
37
  /**
38
38
  * Calculates a percentage of a given base value.
39
39
  * @param {number} price - The base value.
@@ -4,7 +4,7 @@
4
4
  * @param {number} val1 - The first reference value (numerator in direct proportion, denominator in inverse).
5
5
  * @param {number} val2 - The second reference value (denominator in direct proportion, numerator in inverse).
6
6
  * @param {number} val3 - The third value (numerator in direct proportion, denominator in inverse).
7
- * @param {boolean} inverse - Whether the calculation should use inverse proportion (true for inverse, false for direct).
7
+ * @param {boolean} [inverse] - Whether the calculation should use inverse proportion (true for inverse, false for direct).
8
8
  * @returns {number} The result of the Rule of Three operation.
9
9
  *
10
10
  * Rule of Three Formula (Direct Proportion):
@@ -33,7 +33,7 @@
33
33
  * // Inverse proportion:
34
34
  * ruleOfThree.execute(2, 6, 3, true); // → 4
35
35
  */
36
- export function ruleOfThree(val1, val2, val3, inverse) {
36
+ export function ruleOfThree(val1, val2, val3, inverse = false) {
37
37
  return inverse ? Number(val1 * val2) / val3 : Number(val3 * val2) / val1;
38
38
  }
39
39
  /**
package/dist/v1/index.cjs CHANGED
@@ -17,6 +17,7 @@ exports.formatCustomTimer = clock.formatCustomTimer;
17
17
  exports.formatDayTimer = clock.formatDayTimer;
18
18
  exports.formatTimer = clock.formatTimer;
19
19
  exports.getTimeDuration = clock.getTimeDuration;
20
+ exports.checkObj = objFilter.checkObj;
20
21
  exports.cloneObjTypeOrder = objFilter.cloneObjTypeOrder;
21
22
  exports.countObj = objFilter.countObj;
22
23
  exports.extendObjType = objFilter.extendObjType;
@@ -3,6 +3,7 @@ import { extendObjType } from './basics/objFilter.mjs';
3
3
  import { reorderObjTypeOrder } from './basics/objFilter.mjs';
4
4
  import { cloneObjTypeOrder } from './basics/objFilter.mjs';
5
5
  import { countObj } from './basics/objFilter.mjs';
6
+ import { checkObj } from './basics/objFilter.mjs';
6
7
  import { objType } from './basics/objFilter.mjs';
7
8
  import { ruleOfThree } from './basics/simpleMath.mjs';
8
9
  import { getSimplePerc } from './basics/simpleMath.mjs';
@@ -15,4 +16,4 @@ import { getTimeDuration } from './basics/clock.mjs';
15
16
  import { shuffleArray } from './basics/array.mjs';
16
17
  import { toTitleCase } from './basics/text.mjs';
17
18
  import { toTitleCaseLowerFirst } from './basics/text.mjs';
18
- export { TinyLevelUp, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst };
19
+ export { TinyLevelUp, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, checkObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst };
package/dist/v1/index.mjs CHANGED
@@ -2,7 +2,7 @@ import asyncReplace from '../legacy/libs/replaceAsync.mjs';
2
2
  import TinyLevelUp from '../legacy/libs/userLevel.mjs';
3
3
  import { shuffleArray } from './basics/array.mjs';
4
4
  import { formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, } from './basics/clock.mjs';
5
- import { countObj, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, objType, } from './basics/objFilter.mjs';
5
+ import { countObj, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, objType, checkObj, } from './basics/objFilter.mjs';
6
6
  import { getAge, getSimplePerc, ruleOfThree } from './basics/simpleMath.mjs';
7
7
  import { toTitleCase, toTitleCaseLowerFirst } from './basics/text.mjs';
8
- export { TinyLevelUp, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst, };
8
+ export { TinyLevelUp, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, checkObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst, };
@@ -40,6 +40,39 @@ Returns:
40
40
 
41
41
  ---
42
42
 
43
+ ### 🔍 `checkObj(obj)`
44
+
45
+ Checks the type of a given object and returns the validation result if a known type is detected.
46
+
47
+ ```js
48
+ checkObj('hello');
49
+ // { valid: true, type: "string" }
50
+
51
+ checkObj(123);
52
+ // { valid: true, type: "number" }
53
+
54
+ checkObj(undefined);
55
+ // { valid: true, type: "undefined" }
56
+
57
+ checkObj(Symbol('sym'));
58
+ // { valid: true, type: "symbol" }
59
+
60
+ checkObj(() => {});
61
+ // { valid: true, type: "function" }
62
+
63
+ checkObj(null);
64
+ // { valid: true, type: "null" }
65
+
66
+ checkObj(Object.create(null));
67
+ // { valid: true, type: "object" }
68
+ ```
69
+
70
+ Returns:
71
+ - `{ valid: true, type: "<type>" }` if the type is recognized
72
+ - `{ valid: null, type: null }` if no matching type is found
73
+
74
+ ---
75
+
43
76
  ### ➕ `extendObjType(newTypes, [index])`
44
77
 
45
78
  Add your own custom types. You can optionally define where in the check order they go.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiny-essentials",
3
- "version": "1.3.1",
3
+ "version": "1.4.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",