tiny-essentials 1.21.1 → 1.21.2

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.
@@ -1 +1 @@
1
- (()=>{"use strict";var t={d:(e,r)=>{for(var i in r)t.o(r,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:r[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{TinyNeedBar:()=>i});class r{#t=new Map;#e;#r;#i;get factors(){const t={};for(let[e,r]of this.#t.entries())t[e]={...r};return t}get currentPercent(){return this.#r/this.#e*100}set maxValue(t){this.#e=t,this.#r=Math.min(this.#r,t)}get maxValue(){return this.#e}get currentValue(){return this.#r}set infiniteValue(t){this.#i=t,this.#r=Math.max(0,t),this.#r=Math.min(this.#r,this.#e)}get infiniteValue(){return this.#i}constructor(t=100,e=1,r=1){this.#e=t,this.setFactor("main",e,r),this.#r=t,this.#i=t}getFactor(t){const e=this.#t.get(t);if(!e)throw new Error(`Factor with key "${t}" not found.`);return{...e}}hasFactor(t){return this.#t.has(t)}setFactor(t,e,r=1){this.#t.set(t,{amount:e,multiplier:r})}removeFactor(t){this.#t.delete(t)}tick(){let t=0;for(let[e,r]of this.#t.entries())t+=r.amount*r.multiplier;const e=this.#i;return this.#i-=t,this.#r=Math.max(0,this.#r-t),{prevValue:e,removedTotal:t,removedPercent:t/this.#e*100,currentPercent:this.currentPercent,remainingValue:this.#r,infiniteRemaining:this.#i}}toJSON(){return{maxValue:this.#e,currentValue:this.#r,infiniteValue:this.#i,factors:this.factors}}static fromJSON(t){const e=new r(t.maxValue,0,0);e.infiniteValue=t.infiniteValue,e.#t.clear();for(const[r,i]of Object.entries(t.factors))e.setFactor(r,i.amount,i.multiplier);return e}clone(){return r.fromJSON(this.toJSON())}clearFactors(){this.#t.clear()}}const i=r;window.TinyNeedBar=e.TinyNeedBar})();
1
+ (()=>{"use strict";var e={d:(t,r)=>{for(var i in r)e.o(r,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:r[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{TinyNeedBar:()=>i});class r{#e=new Map;#t;#r;#i;get factors(){const e={};for(let[t,r]of this.#e.entries())e[t]={...r};return e}get currentPercent(){return this.#r/this.#t*100}set maxValue(e){if("number"!=typeof e||Number.isNaN(e)||e<=0)throw new TypeError("maxValue must be a positive number.");this.#t=e,this.#r=Math.min(this.#r,e)}get maxValue(){return this.#t}get currentValue(){return this.#r}set infiniteValue(e){if("number"!=typeof e||Number.isNaN(e))throw new TypeError("infiniteValue must be a number.");this.#i=e,this.#r=Math.max(0,e),this.#r=Math.min(this.#r,this.#t)}get infiniteValue(){return this.#i}constructor(e=100,t=1,r=1){if("number"!=typeof e||Number.isNaN(e)||e<=0)throw new TypeError("maxValue must be a positive number.");this.#t=e,this.setFactor("main",t,r),this.#r=e,this.#i=e}getFactor(e){if("string"!=typeof e||!e)throw new TypeError("Key must be a non-empty string.");const t=this.#e.get(e);if(!t)throw new Error(`Factor with key "${e}" not found.`);return{...t}}hasFactor(e){if("string"!=typeof e||!e)throw new TypeError("Key must be a non-empty string.");return this.#e.has(e)}setFactor(e,t,r=1){if("string"!=typeof e||!e)throw new TypeError("Key must be a non-empty string.");if("number"!=typeof t||Number.isNaN(t))throw new TypeError("Amount must be a valid number.");if("number"!=typeof r||Number.isNaN(r))throw new TypeError("Multiplier must be a valid number.");this.#e.set(e,{amount:t,multiplier:r})}removeFactor(e){if("string"!=typeof e||!e)throw new TypeError("Key must be a non-empty string.");return this.#e.delete(e)}#n(e){const t=this.#i;return this.#i-=e,this.#r=Math.max(0,this.#r-e),{prevValue:t,removedTotal:e,removedPercent:e/this.#t*100,currentPercent:this.currentPercent,remainingValue:this.#r,infiniteRemaining:this.#i}}tick(){let e=0;for(let[t,r]of this.#e.entries())e+=r.amount*r.multiplier;return this.#n(e)}tickWithTempFactor(e){if("object"!=typeof e||null===e)throw new TypeError("You must provide a valid factor object.");if("number"!=typeof e.amount||Number.isNaN(e.amount))throw new TypeError('Temp factor "amount" must be a valid number.');if("multiplier"in e&&("number"!=typeof e.multiplier||Number.isNaN(e.multiplier)))throw new TypeError('Temp factor "multiplier" must be a valid number if provided.');let t=0;for(let[e,r]of this.#e.entries())t+=r.amount*r.multiplier;return e&&(t+=e.amount*(e.multiplier??1)),this.#n(t)}tickSingleFactor(e){if("object"!=typeof e||null===e)throw new TypeError("You must provide a valid factor object.");if("number"!=typeof e.amount||Number.isNaN(e.amount))throw new TypeError('Temp factor "amount" must be a valid number.');if("multiplier"in e&&("number"!=typeof e.multiplier||Number.isNaN(e.multiplier)))throw new TypeError('Temp factor "multiplier" must be a valid number if provided.');if(!e)throw new Error("You must provide a factor to apply.");const t=e.amount*(e.multiplier??1);return this.#n(t)}toJSON(){return{maxValue:this.#t,currentValue:this.#r,infiniteValue:this.#i,factors:this.factors}}static fromJSON(e){const t=new r(e.maxValue,0,0);t.infiniteValue=e.infiniteValue,t.#e.clear();for(const[r,i]of Object.entries(e.factors))t.setFactor(r,i.amount,i.multiplier);return t}clone(){return r.fromJSON(this.toJSON())}clearFactors(){this.#e.clear()}}const i=r;window.TinyNeedBar=t.TinyNeedBar})();
@@ -0,0 +1 @@
1
+ (()=>{"use strict";var e={d:(r,o)=>{for(var a in o)e.o(o,a)&&!e.o(r,a)&&Object.defineProperty(r,a,{enumerable:!0,get:o[a]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r)},r={};e.d(r,{TinySimpleDice:()=>o});const o=class{static rollArrayIndex(e){const r=Array.isArray(e),o=e instanceof Set;if(!r&&!o)throw new TypeError("rollArrayIndex expects an array or Set.");return Math.floor(Math.random()*(r?e.length:e.size))}#e;#r;get maxValue(){return this.#e}set maxValue(e){if(!Number.isInteger(e)||e<0)throw new TypeError("maxValue must be an integer greater than -1.");this.#e=e}get allowZero(){return this.#r}set allowZero(e){if("boolean"!=typeof e)throw new TypeError("allowZero must be a boolean.");this.#r=e}constructor({maxValue:e,allowZero:r=!0}){if("boolean"!=typeof r)throw new TypeError("allowZero must be an boolean.");if(!Number.isInteger(e)||e<0)throw new TypeError("maxValue must be an integer greater than -1.");this.#e=e,this.#r=r}roll(){const e=this.#r?0:1;return Math.floor(Math.random()*(this.#e-e+1))+e}};window.TinySimpleDice=r.TinySimpleDice})();
@@ -17,6 +17,7 @@ var collision = require('./collision.cjs');
17
17
  exports.arraySortPositions = arraySortPositions;
18
18
  exports.asyncReplace = replaceAsync;
19
19
  exports.shuffleArray = array.shuffleArray;
20
+ exports.breakdownDuration = clock.breakdownDuration;
20
21
  exports.formatCustomTimer = clock.formatCustomTimer;
21
22
  exports.formatDayTimer = clock.formatDayTimer;
22
23
  exports.formatTimer = clock.formatTimer;
@@ -1,3 +1,4 @@
1
+ import { breakdownDuration } from './clock.mjs';
1
2
  import { calculateMarketcap } from './simpleMath.mjs';
2
3
  import { compareMarketcap } from './simpleMath.mjs';
3
4
  import { getPercentage } from './simpleMath.mjs';
@@ -55,5 +56,5 @@ import { getTimeDuration } from './clock.mjs';
55
56
  import { shuffleArray } from './array.mjs';
56
57
  import { toTitleCase } from './text.mjs';
57
58
  import { toTitleCaseLowerFirst } from './text.mjs';
58
- export { calculateMarketcap, compareMarketcap, getPercentage, areElsCollTop, areElsCollBottom, areElsCollLeft, areElsCollRight, areElsCollPerfTop, areElsCollPerfBottom, areElsCollPerfLeft, areElsCollPerfRight, areElsColliding, areElsPerfColliding, getElsColliding, getElsPerfColliding, getElsCollOverlap, getElsCollOverlapPos, getRectCenter, getElsRelativeCenterOffset, getElsCollDirDepth, getElsCollDetails, safeTextTrim, installWindowHiddenScript, genFibonacciSeq, fetchJson, fetchText, readJsonBlob, readFileBlob, readBase64Blob, saveJsonFile, documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange, isJsonObject, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst };
59
+ export { breakdownDuration, calculateMarketcap, compareMarketcap, getPercentage, areElsCollTop, areElsCollBottom, areElsCollLeft, areElsCollRight, areElsCollPerfTop, areElsCollPerfBottom, areElsCollPerfLeft, areElsCollPerfRight, areElsColliding, areElsPerfColliding, getElsColliding, getElsPerfColliding, getElsCollOverlap, getElsCollOverlapPos, getRectCenter, getElsRelativeCenterOffset, getElsCollDirDepth, getElsCollDetails, safeTextTrim, installWindowHiddenScript, genFibonacciSeq, fetchJson, fetchText, readJsonBlob, readFileBlob, readBase64Blob, saveJsonFile, documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange, isJsonObject, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst };
59
60
  //# sourceMappingURL=index.d.mts.map
@@ -1,7 +1,7 @@
1
1
  import arraySortPositions from '../../legacy/libs/arraySortPositions.mjs';
2
2
  import asyncReplace from '../../legacy/libs/replaceAsync.mjs';
3
3
  import { shuffleArray } from './array.mjs';
4
- import { formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration } from './clock.mjs';
4
+ import { breakdownDuration, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, } from './clock.mjs';
5
5
  import { readJsonBlob, saveJsonFile, fetchJson, installWindowHiddenScript, readFileBlob, readBase64Blob, fetchText, } from './html.mjs';
6
6
  import { extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, objType } from './objFilter.mjs';
7
7
  import { countObj, isJsonObject } from './objChecker.mjs';
@@ -9,4 +9,4 @@ import { documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen
9
9
  import { calculateMarketcap, compareMarketcap, formatBytes, genFibonacciSeq, getAge, getPercentage, getSimplePerc, ruleOfThree, } from './simpleMath.mjs';
10
10
  import { addAiMarkerShortcut, safeTextTrim, toTitleCase, toTitleCaseLowerFirst } from './text.mjs';
11
11
  import { areElsCollTop, areElsCollBottom, areElsCollLeft, areElsCollRight, areElsCollPerfTop, areElsCollPerfBottom, areElsCollPerfLeft, areElsCollPerfRight, areElsColliding, areElsPerfColliding, getElsColliding, getElsPerfColliding, getElsCollOverlap, getElsCollOverlapPos, getRectCenter, getElsRelativeCenterOffset, getElsCollDirDepth, getElsCollDetails, } from './collision.mjs';
12
- export { calculateMarketcap, compareMarketcap, getPercentage, areElsCollTop, areElsCollBottom, areElsCollLeft, areElsCollRight, areElsCollPerfTop, areElsCollPerfBottom, areElsCollPerfLeft, areElsCollPerfRight, areElsColliding, areElsPerfColliding, getElsColliding, getElsPerfColliding, getElsCollOverlap, getElsCollOverlapPos, getRectCenter, getElsRelativeCenterOffset, getElsCollDirDepth, getElsCollDetails, safeTextTrim, installWindowHiddenScript, genFibonacciSeq, fetchJson, fetchText, readJsonBlob, readFileBlob, readBase64Blob, saveJsonFile, documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange, isJsonObject, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst, };
12
+ export { breakdownDuration, calculateMarketcap, compareMarketcap, getPercentage, areElsCollTop, areElsCollBottom, areElsCollLeft, areElsCollRight, areElsCollPerfTop, areElsCollPerfBottom, areElsCollPerfLeft, areElsCollPerfRight, areElsColliding, areElsPerfColliding, getElsColliding, getElsPerfColliding, getElsCollOverlap, getElsCollOverlapPos, getRectCenter, getElsRelativeCenterOffset, getElsCollDirDepth, getElsCollDetails, safeTextTrim, installWindowHiddenScript, genFibonacciSeq, fetchJson, fetchText, readJsonBlob, readFileBlob, readBase64Blob, saveJsonFile, documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange, isJsonObject, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst, };
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ var TinySimpleDice = require('../libs/TinySimpleDice.cjs');
4
+
5
+
6
+
7
+ exports.TinySimpleDice = TinySimpleDice;
@@ -0,0 +1,3 @@
1
+ export { TinySimpleDice };
2
+ import TinySimpleDice from '../libs/TinySimpleDice.mjs';
3
+ //# sourceMappingURL=TinySimpleDice.d.mts.map
@@ -0,0 +1,2 @@
1
+ import TinySimpleDice from '../libs/TinySimpleDice.mjs';
2
+ export { TinySimpleDice };
package/dist/v1/index.cjs CHANGED
@@ -45,6 +45,7 @@ var TinyInventoryTrader = require('./libs/TinyInventoryTrader.cjs');
45
45
  var TinyCookieConsent = require('./libs/TinyCookieConsent.cjs');
46
46
  var TinyI18 = require('./libs/TinyI18.cjs');
47
47
  var TinyNeedBar = require('./libs/TinyNeedBar.cjs');
48
+ var TinySimpleDice = require('./libs/TinySimpleDice.cjs');
48
49
 
49
50
 
50
51
 
@@ -52,6 +53,7 @@ exports.asyncReplace = replaceAsync;
52
53
  exports.TinyLevelUp = userLevel;
53
54
  exports.arraySortPositions = arraySortPositions;
54
55
  exports.shuffleArray = array.shuffleArray;
56
+ exports.breakdownDuration = clock.breakdownDuration;
55
57
  exports.formatCustomTimer = clock.formatCustomTimer;
56
58
  exports.formatDayTimer = clock.formatDayTimer;
57
59
  exports.formatTimer = clock.formatTimer;
@@ -166,3 +168,4 @@ exports.TinyInventoryTrader = TinyInventoryTrader;
166
168
  exports.TinyCookieConsent = TinyCookieConsent;
167
169
  exports.TinyI18 = TinyI18;
168
170
  exports.TinyNeedBar = TinyNeedBar;
171
+ exports.TinySimpleDice = TinySimpleDice;
@@ -1,3 +1,4 @@
1
+ import TinySimpleDice from './libs/TinySimpleDice.mjs';
1
2
  import TinyNeedBar from './libs/TinyNeedBar.mjs';
2
3
  import TinyI18 from './libs/TinyI18.mjs';
3
4
  import TinyCookieConsent from './libs/TinyCookieConsent.mjs';
@@ -30,6 +31,7 @@ import TinyRateLimiter from './libs/TinyRateLimiter.mjs';
30
31
  import ColorSafeStringify from './libs/ColorSafeStringify.mjs';
31
32
  import TinyPromiseQueue from './libs/TinyPromiseQueue.mjs';
32
33
  import TinyLevelUp from '../legacy/libs/userLevel.mjs';
34
+ import { breakdownDuration } from './basics/clock.mjs';
33
35
  import { calculateMarketcap } from './basics/simpleMath.mjs';
34
36
  import { compareMarketcap } from './basics/simpleMath.mjs';
35
37
  import { getPercentage } from './basics/simpleMath.mjs';
@@ -116,5 +118,5 @@ import { getTimeDuration } from './basics/clock.mjs';
116
118
  import { shuffleArray } from './basics/array.mjs';
117
119
  import { toTitleCase } from './basics/text.mjs';
118
120
  import { toTitleCaseLowerFirst } from './basics/text.mjs';
119
- export { TinyNeedBar, TinyI18, TinyCookieConsent, TinyInventory, TinyInventoryTrader, TinyArrayPaginator, TinyAdvancedRaffle, TinyDayNightCycle, TinyGamepad, TinyTextarea, TinyNewWinEvents, TinyIframeEvents, TinyLocalStorage, TinyEvents, TinyTimeout, TinyColorConverter, TinyClipboard, TinyTextRangeEditor, TinySmartScroller, UltraRandomMsgGen, TinyAfterScrollWatcher, TinyHtml, TinyNotifications, TinyDomReadyManager, TinyDragger, TinyDragDropDetector, TinyToastNotify, TinyNotifyCenter, TinyRateLimiter, ColorSafeStringify, TinyPromiseQueue, TinyLevelUp, calculateMarketcap, compareMarketcap, getPercentage, areElsCollTop, areElsCollBottom, areElsCollLeft, areElsCollRight, areElsCollPerfTop, areElsCollPerfBottom, areElsCollPerfLeft, areElsCollPerfRight, areElsColliding, areElsPerfColliding, getElsColliding, getElsPerfColliding, getElsCollOverlap, getElsCollOverlapPos, getRectCenter, getElsRelativeCenterOffset, getElsCollDirDepth, getElsCollDetails, safeTextTrim, installWindowHiddenScript, genFibonacciSeq, isDirEmptyAsync, fileSizeAsync, dirSizeAsync, listFilesAsync, listDirsAsync, getLatestBackupPath, fetchJson, fetchText, readJsonBlob, readFileBlob, readBase64Blob, saveJsonFile, readJsonFile, writeJsonFile, ensureDirectory, clearDirectoryAsync, clearDirectory, fileExists, dirExists, isDirEmpty, ensureCopyFile, tryDeleteFile, writeTextFile, listFiles, listDirs, fileSize, dirSize, backupFile, restoreLatestBackup, renameFileBatch, renameFileRegex, renameFileAddPrefixSuffix, renameFileNormalizeCase, renameFilePadNumbers, documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange, isJsonObject, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, checkObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst };
121
+ export { TinySimpleDice, TinyNeedBar, TinyI18, TinyCookieConsent, TinyInventory, TinyInventoryTrader, TinyArrayPaginator, TinyAdvancedRaffle, TinyDayNightCycle, TinyGamepad, TinyTextarea, TinyNewWinEvents, TinyIframeEvents, TinyLocalStorage, TinyEvents, TinyTimeout, TinyColorConverter, TinyClipboard, TinyTextRangeEditor, TinySmartScroller, UltraRandomMsgGen, TinyAfterScrollWatcher, TinyHtml, TinyNotifications, TinyDomReadyManager, TinyDragger, TinyDragDropDetector, TinyToastNotify, TinyNotifyCenter, TinyRateLimiter, ColorSafeStringify, TinyPromiseQueue, TinyLevelUp, breakdownDuration, calculateMarketcap, compareMarketcap, getPercentage, areElsCollTop, areElsCollBottom, areElsCollLeft, areElsCollRight, areElsCollPerfTop, areElsCollPerfBottom, areElsCollPerfLeft, areElsCollPerfRight, areElsColliding, areElsPerfColliding, getElsColliding, getElsPerfColliding, getElsCollOverlap, getElsCollOverlapPos, getRectCenter, getElsRelativeCenterOffset, getElsCollDirDepth, getElsCollDetails, safeTextTrim, installWindowHiddenScript, genFibonacciSeq, isDirEmptyAsync, fileSizeAsync, dirSizeAsync, listFilesAsync, listDirsAsync, getLatestBackupPath, fetchJson, fetchText, readJsonBlob, readFileBlob, readBase64Blob, saveJsonFile, readJsonFile, writeJsonFile, ensureDirectory, clearDirectoryAsync, clearDirectory, fileExists, dirExists, isDirEmpty, ensureCopyFile, tryDeleteFile, writeTextFile, listFiles, listDirs, fileSize, dirSize, backupFile, restoreLatestBackup, renameFileBatch, renameFileRegex, renameFileAddPrefixSuffix, renameFileNormalizeCase, renameFilePadNumbers, documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange, isJsonObject, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, checkObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst };
120
122
  //# sourceMappingURL=index.d.mts.map
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 arraySortPositions from '../legacy/libs/arraySortPositions.mjs';
4
4
  import { shuffleArray } from './basics/array.mjs';
5
- import { formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, } from './basics/clock.mjs';
5
+ import { breakdownDuration, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, } from './basics/clock.mjs';
6
6
  import { extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, objType, checkObj, } from './basics/objFilter.mjs';
7
7
  import { countObj, isJsonObject } from './basics/objChecker.mjs';
8
8
  import { documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange, } from './basics/fullScreen.mjs';
@@ -43,4 +43,5 @@ import TinyInventoryTrader from './libs/TinyInventoryTrader.mjs';
43
43
  import TinyCookieConsent from './libs/TinyCookieConsent.mjs';
44
44
  import TinyI18 from './libs/TinyI18.mjs';
45
45
  import TinyNeedBar from './libs/TinyNeedBar.mjs';
46
- export { TinyNeedBar, TinyI18, TinyCookieConsent, TinyInventory, TinyInventoryTrader, TinyArrayPaginator, TinyAdvancedRaffle, TinyDayNightCycle, TinyGamepad, TinyTextarea, TinyNewWinEvents, TinyIframeEvents, TinyLocalStorage, TinyEvents, TinyTimeout, TinyColorConverter, TinyClipboard, TinyTextRangeEditor, TinySmartScroller, UltraRandomMsgGen, TinyAfterScrollWatcher, TinyHtml, TinyNotifications, TinyDomReadyManager, TinyDragger, TinyDragDropDetector, TinyToastNotify, TinyNotifyCenter, TinyRateLimiter, ColorSafeStringify, TinyPromiseQueue, TinyLevelUp, calculateMarketcap, compareMarketcap, getPercentage, areElsCollTop, areElsCollBottom, areElsCollLeft, areElsCollRight, areElsCollPerfTop, areElsCollPerfBottom, areElsCollPerfLeft, areElsCollPerfRight, areElsColliding, areElsPerfColliding, getElsColliding, getElsPerfColliding, getElsCollOverlap, getElsCollOverlapPos, getRectCenter, getElsRelativeCenterOffset, getElsCollDirDepth, getElsCollDetails, safeTextTrim, installWindowHiddenScript, genFibonacciSeq, isDirEmptyAsync, fileSizeAsync, dirSizeAsync, listFilesAsync, listDirsAsync, getLatestBackupPath, fetchJson, fetchText, readJsonBlob, readFileBlob, readBase64Blob, saveJsonFile, readJsonFile, writeJsonFile, ensureDirectory, clearDirectoryAsync, clearDirectory, fileExists, dirExists, isDirEmpty, ensureCopyFile, tryDeleteFile, writeTextFile, listFiles, listDirs, fileSize, dirSize, backupFile, restoreLatestBackup, renameFileBatch, renameFileRegex, renameFileAddPrefixSuffix, renameFileNormalizeCase, renameFilePadNumbers, documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange, isJsonObject, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, checkObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst, };
46
+ import TinySimpleDice from './libs/TinySimpleDice.mjs';
47
+ export { TinySimpleDice, TinyNeedBar, TinyI18, TinyCookieConsent, TinyInventory, TinyInventoryTrader, TinyArrayPaginator, TinyAdvancedRaffle, TinyDayNightCycle, TinyGamepad, TinyTextarea, TinyNewWinEvents, TinyIframeEvents, TinyLocalStorage, TinyEvents, TinyTimeout, TinyColorConverter, TinyClipboard, TinyTextRangeEditor, TinySmartScroller, UltraRandomMsgGen, TinyAfterScrollWatcher, TinyHtml, TinyNotifications, TinyDomReadyManager, TinyDragger, TinyDragDropDetector, TinyToastNotify, TinyNotifyCenter, TinyRateLimiter, ColorSafeStringify, TinyPromiseQueue, TinyLevelUp, breakdownDuration, calculateMarketcap, compareMarketcap, getPercentage, areElsCollTop, areElsCollBottom, areElsCollLeft, areElsCollRight, areElsCollPerfTop, areElsCollPerfBottom, areElsCollPerfLeft, areElsCollPerfRight, areElsColliding, areElsPerfColliding, getElsColliding, getElsPerfColliding, getElsCollOverlap, getElsCollOverlapPos, getRectCenter, getElsRelativeCenterOffset, getElsCollDirDepth, getElsCollDetails, safeTextTrim, installWindowHiddenScript, genFibonacciSeq, isDirEmptyAsync, fileSizeAsync, dirSizeAsync, listFilesAsync, listDirsAsync, getLatestBackupPath, fetchJson, fetchText, readJsonBlob, readFileBlob, readBase64Blob, saveJsonFile, readJsonFile, writeJsonFile, ensureDirectory, clearDirectoryAsync, clearDirectory, fileExists, dirExists, isDirEmpty, ensureCopyFile, tryDeleteFile, writeTextFile, listFiles, listDirs, fileSize, dirSize, backupFile, restoreLatestBackup, renameFileBatch, renameFileRegex, renameFileAddPrefixSuffix, renameFileNormalizeCase, renameFilePadNumbers, documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange, isJsonObject, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, checkObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst, };
@@ -93,6 +93,8 @@ class TinyNeedBar {
93
93
  * @param {number} value - New maximum value.
94
94
  */
95
95
  set maxValue(value) {
96
+ if (typeof value !== 'number' || Number.isNaN(value) || value <= 0)
97
+ throw new TypeError('maxValue must be a positive number.');
96
98
  this.#maxValue = value;
97
99
  this.#currentValue = Math.min(this.#currentValue, value);
98
100
  }
@@ -123,6 +125,8 @@ class TinyNeedBar {
123
125
  * @param {number} value - New infinite value.
124
126
  */
125
127
  set infiniteValue(value) {
128
+ if (typeof value !== 'number' || Number.isNaN(value))
129
+ throw new TypeError('infiniteValue must be a number.');
126
130
  this.#infiniteValue = value;
127
131
  this.#currentValue = Math.max(0, value);
128
132
  this.#currentValue = Math.min(this.#currentValue, this.#maxValue);
@@ -146,6 +150,9 @@ class TinyNeedBar {
146
150
  * @param {number} [baseDecayMulti=1] - Multiplier applied to the base decay.
147
151
  */
148
152
  constructor(maxValue = 100, baseDecay = 1, baseDecayMulti = 1) {
153
+ if (typeof maxValue !== 'number' || Number.isNaN(maxValue) || maxValue <= 0)
154
+ throw new TypeError('maxValue must be a positive number.');
155
+
149
156
  this.#maxValue = maxValue;
150
157
  this.setFactor('main', baseDecay, baseDecayMulti);
151
158
 
@@ -161,6 +168,7 @@ class TinyNeedBar {
161
168
  * @throws {Error} If the factor does not exist.
162
169
  */
163
170
  getFactor(key) {
171
+ if (typeof key !== 'string' || !key) throw new TypeError('Key must be a non-empty string.');
164
172
  const result = this.#factors.get(key);
165
173
  if (!result) throw new Error(`Factor with key "${key}" not found.`);
166
174
  return { ...result };
@@ -173,6 +181,7 @@ class TinyNeedBar {
173
181
  * @returns {boolean} `true` if the factor exists, otherwise `false`.
174
182
  */
175
183
  hasFactor(key) {
184
+ if (typeof key !== 'string' || !key) throw new TypeError('Key must be a non-empty string.');
176
185
  return this.#factors.has(key);
177
186
  }
178
187
 
@@ -184,6 +193,11 @@ class TinyNeedBar {
184
193
  * @param {number} [multiplier=1] - Multiplier applied to the amount.
185
194
  */
186
195
  setFactor(key, amount, multiplier = 1) {
196
+ if (typeof key !== 'string' || !key) throw new TypeError('Key must be a non-empty string.');
197
+ if (typeof amount !== 'number' || Number.isNaN(amount))
198
+ throw new TypeError('Amount must be a valid number.');
199
+ if (typeof multiplier !== 'number' || Number.isNaN(multiplier))
200
+ throw new TypeError('Multiplier must be a valid number.');
187
201
  this.#factors.set(key, { amount, multiplier });
188
202
  }
189
203
 
@@ -191,23 +205,22 @@ class TinyNeedBar {
191
205
  * Removes a decay factor by its key.
192
206
  *
193
207
  * @param {string} key - The factor key to remove.
208
+ * @returns {boolean} Returns `true` if the factor existed and was successfully removed,
209
+ * or `false` if the factor did not exist.
194
210
  */
195
211
  removeFactor(key) {
196
- this.#factors.delete(key);
212
+ if (typeof key !== 'string' || !key) throw new TypeError('Key must be a non-empty string.');
213
+ return this.#factors.delete(key);
197
214
  }
198
215
 
199
216
  /**
200
- * Executes one tick of decay, applying all active factors.
217
+ * Applies a total decay value to the bar and updates both current and infinite values.
218
+ * This is a private helper used by the public tick methods.
201
219
  *
202
- * @returns {TickResult}
220
+ * @param {number} removedTotal - The total amount to remove from the bar during this tick.
221
+ * @returns {TickResult} An object containing detailed information about the tick.
203
222
  */
204
- tick() {
205
- let removedTotal = 0;
206
-
207
- for (let [_, factor] of this.#factors.entries()) {
208
- removedTotal += factor.amount * factor.multiplier;
209
- }
210
-
223
+ #tick(removedTotal) {
211
224
  const prevValue = this.#infiniteValue;
212
225
  this.#infiniteValue -= removedTotal;
213
226
  this.#currentValue = Math.max(0, this.#currentValue - removedTotal);
@@ -224,6 +237,66 @@ class TinyNeedBar {
224
237
  };
225
238
  }
226
239
 
240
+ /**
241
+ * Executes one tick of decay, applying all active factors.
242
+ *
243
+ * @returns {TickResult}
244
+ */
245
+ tick() {
246
+ let removedTotal = 0;
247
+ for (let [_, factor] of this.#factors.entries()) {
248
+ removedTotal += factor.amount * factor.multiplier;
249
+ }
250
+ return this.#tick(removedTotal);
251
+ }
252
+
253
+ /**
254
+ * Executes one tick of decay using a temporary factor.
255
+ *
256
+ * @param {BarFactor} tempFactor - Temporary factor to apply only in this tick.
257
+ * @returns {TickResult}
258
+ */
259
+ tickWithTempFactor(tempFactor) {
260
+ if (typeof tempFactor !== 'object' || tempFactor === null)
261
+ throw new TypeError('You must provide a valid factor object.');
262
+ if (typeof tempFactor.amount !== 'number' || Number.isNaN(tempFactor.amount))
263
+ throw new TypeError('Temp factor "amount" must be a valid number.');
264
+ if (
265
+ 'multiplier' in tempFactor &&
266
+ (typeof tempFactor.multiplier !== 'number' || Number.isNaN(tempFactor.multiplier))
267
+ )
268
+ throw new TypeError('Temp factor "multiplier" must be a valid number if provided.');
269
+
270
+ let removedTotal = 0;
271
+ for (let [_, factor] of this.#factors.entries()) {
272
+ removedTotal += factor.amount * factor.multiplier;
273
+ }
274
+ if (tempFactor) removedTotal += tempFactor.amount * (tempFactor.multiplier ?? 1);
275
+ return this.#tick(removedTotal);
276
+ }
277
+
278
+ /**
279
+ * Executes one tick using only the specified factor.
280
+ *
281
+ * @param {BarFactor} factor - The single factor to apply.
282
+ * @returns {TickResult}
283
+ */
284
+ tickSingleFactor(factor) {
285
+ if (typeof factor !== 'object' || factor === null)
286
+ throw new TypeError('You must provide a valid factor object.');
287
+ if (typeof factor.amount !== 'number' || Number.isNaN(factor.amount))
288
+ throw new TypeError('Temp factor "amount" must be a valid number.');
289
+ if (
290
+ 'multiplier' in factor &&
291
+ (typeof factor.multiplier !== 'number' || Number.isNaN(factor.multiplier))
292
+ )
293
+ throw new TypeError('Temp factor "multiplier" must be a valid number if provided.');
294
+
295
+ if (!factor) throw new Error('You must provide a factor to apply.');
296
+ const removedTotal = factor.amount * (factor.multiplier ?? 1);
297
+ return this.#tick(removedTotal);
298
+ }
299
+
227
300
  /**
228
301
  * Serializes the current state of the need bar.
229
302
  * @returns {SerializedData}
@@ -196,14 +196,30 @@ declare class TinyNeedBar {
196
196
  * Removes a decay factor by its key.
197
197
  *
198
198
  * @param {string} key - The factor key to remove.
199
+ * @returns {boolean} Returns `true` if the factor existed and was successfully removed,
200
+ * or `false` if the factor did not exist.
199
201
  */
200
- removeFactor(key: string): void;
202
+ removeFactor(key: string): boolean;
201
203
  /**
202
204
  * Executes one tick of decay, applying all active factors.
203
205
  *
204
206
  * @returns {TickResult}
205
207
  */
206
208
  tick(): TickResult;
209
+ /**
210
+ * Executes one tick of decay using a temporary factor.
211
+ *
212
+ * @param {BarFactor} tempFactor - Temporary factor to apply only in this tick.
213
+ * @returns {TickResult}
214
+ */
215
+ tickWithTempFactor(tempFactor: BarFactor): TickResult;
216
+ /**
217
+ * Executes one tick using only the specified factor.
218
+ *
219
+ * @param {BarFactor} factor - The single factor to apply.
220
+ * @returns {TickResult}
221
+ */
222
+ tickSingleFactor(factor: BarFactor): TickResult;
207
223
  /**
208
224
  * Serializes the current state of the need bar.
209
225
  * @returns {SerializedData}
@@ -82,6 +82,8 @@ class TinyNeedBar {
82
82
  * @param {number} value - New maximum value.
83
83
  */
84
84
  set maxValue(value) {
85
+ if (typeof value !== 'number' || Number.isNaN(value) || value <= 0)
86
+ throw new TypeError('maxValue must be a positive number.');
85
87
  this.#maxValue = value;
86
88
  this.#currentValue = Math.min(this.#currentValue, value);
87
89
  }
@@ -109,6 +111,8 @@ class TinyNeedBar {
109
111
  * @param {number} value - New infinite value.
110
112
  */
111
113
  set infiniteValue(value) {
114
+ if (typeof value !== 'number' || Number.isNaN(value))
115
+ throw new TypeError('infiniteValue must be a number.');
112
116
  this.#infiniteValue = value;
113
117
  this.#currentValue = Math.max(0, value);
114
118
  this.#currentValue = Math.min(this.#currentValue, this.#maxValue);
@@ -130,6 +134,8 @@ class TinyNeedBar {
130
134
  * @param {number} [baseDecayMulti=1] - Multiplier applied to the base decay.
131
135
  */
132
136
  constructor(maxValue = 100, baseDecay = 1, baseDecayMulti = 1) {
137
+ if (typeof maxValue !== 'number' || Number.isNaN(maxValue) || maxValue <= 0)
138
+ throw new TypeError('maxValue must be a positive number.');
133
139
  this.#maxValue = maxValue;
134
140
  this.setFactor('main', baseDecay, baseDecayMulti);
135
141
  this.#currentValue = maxValue;
@@ -143,6 +149,8 @@ class TinyNeedBar {
143
149
  * @throws {Error} If the factor does not exist.
144
150
  */
145
151
  getFactor(key) {
152
+ if (typeof key !== 'string' || !key)
153
+ throw new TypeError('Key must be a non-empty string.');
146
154
  const result = this.#factors.get(key);
147
155
  if (!result)
148
156
  throw new Error(`Factor with key "${key}" not found.`);
@@ -155,6 +163,8 @@ class TinyNeedBar {
155
163
  * @returns {boolean} `true` if the factor exists, otherwise `false`.
156
164
  */
157
165
  hasFactor(key) {
166
+ if (typeof key !== 'string' || !key)
167
+ throw new TypeError('Key must be a non-empty string.');
158
168
  return this.#factors.has(key);
159
169
  }
160
170
  /**
@@ -165,26 +175,34 @@ class TinyNeedBar {
165
175
  * @param {number} [multiplier=1] - Multiplier applied to the amount.
166
176
  */
167
177
  setFactor(key, amount, multiplier = 1) {
178
+ if (typeof key !== 'string' || !key)
179
+ throw new TypeError('Key must be a non-empty string.');
180
+ if (typeof amount !== 'number' || Number.isNaN(amount))
181
+ throw new TypeError('Amount must be a valid number.');
182
+ if (typeof multiplier !== 'number' || Number.isNaN(multiplier))
183
+ throw new TypeError('Multiplier must be a valid number.');
168
184
  this.#factors.set(key, { amount, multiplier });
169
185
  }
170
186
  /**
171
187
  * Removes a decay factor by its key.
172
188
  *
173
189
  * @param {string} key - The factor key to remove.
190
+ * @returns {boolean} Returns `true` if the factor existed and was successfully removed,
191
+ * or `false` if the factor did not exist.
174
192
  */
175
193
  removeFactor(key) {
176
- this.#factors.delete(key);
194
+ if (typeof key !== 'string' || !key)
195
+ throw new TypeError('Key must be a non-empty string.');
196
+ return this.#factors.delete(key);
177
197
  }
178
198
  /**
179
- * Executes one tick of decay, applying all active factors.
199
+ * Applies a total decay value to the bar and updates both current and infinite values.
200
+ * This is a private helper used by the public tick methods.
180
201
  *
181
- * @returns {TickResult}
202
+ * @param {number} removedTotal - The total amount to remove from the bar during this tick.
203
+ * @returns {TickResult} An object containing detailed information about the tick.
182
204
  */
183
- tick() {
184
- let removedTotal = 0;
185
- for (let [_, factor] of this.#factors.entries()) {
186
- removedTotal += factor.amount * factor.multiplier;
187
- }
205
+ #tick(removedTotal) {
188
206
  const prevValue = this.#infiniteValue;
189
207
  this.#infiniteValue -= removedTotal;
190
208
  this.#currentValue = Math.max(0, this.#currentValue - removedTotal);
@@ -198,6 +216,59 @@ class TinyNeedBar {
198
216
  infiniteRemaining: this.#infiniteValue,
199
217
  };
200
218
  }
219
+ /**
220
+ * Executes one tick of decay, applying all active factors.
221
+ *
222
+ * @returns {TickResult}
223
+ */
224
+ tick() {
225
+ let removedTotal = 0;
226
+ for (let [_, factor] of this.#factors.entries()) {
227
+ removedTotal += factor.amount * factor.multiplier;
228
+ }
229
+ return this.#tick(removedTotal);
230
+ }
231
+ /**
232
+ * Executes one tick of decay using a temporary factor.
233
+ *
234
+ * @param {BarFactor} tempFactor - Temporary factor to apply only in this tick.
235
+ * @returns {TickResult}
236
+ */
237
+ tickWithTempFactor(tempFactor) {
238
+ if (typeof tempFactor !== 'object' || tempFactor === null)
239
+ throw new TypeError('You must provide a valid factor object.');
240
+ if (typeof tempFactor.amount !== 'number' || Number.isNaN(tempFactor.amount))
241
+ throw new TypeError('Temp factor "amount" must be a valid number.');
242
+ if ('multiplier' in tempFactor &&
243
+ (typeof tempFactor.multiplier !== 'number' || Number.isNaN(tempFactor.multiplier)))
244
+ throw new TypeError('Temp factor "multiplier" must be a valid number if provided.');
245
+ let removedTotal = 0;
246
+ for (let [_, factor] of this.#factors.entries()) {
247
+ removedTotal += factor.amount * factor.multiplier;
248
+ }
249
+ if (tempFactor)
250
+ removedTotal += tempFactor.amount * (tempFactor.multiplier ?? 1);
251
+ return this.#tick(removedTotal);
252
+ }
253
+ /**
254
+ * Executes one tick using only the specified factor.
255
+ *
256
+ * @param {BarFactor} factor - The single factor to apply.
257
+ * @returns {TickResult}
258
+ */
259
+ tickSingleFactor(factor) {
260
+ if (typeof factor !== 'object' || factor === null)
261
+ throw new TypeError('You must provide a valid factor object.');
262
+ if (typeof factor.amount !== 'number' || Number.isNaN(factor.amount))
263
+ throw new TypeError('Temp factor "amount" must be a valid number.');
264
+ if ('multiplier' in factor &&
265
+ (typeof factor.multiplier !== 'number' || Number.isNaN(factor.multiplier)))
266
+ throw new TypeError('Temp factor "multiplier" must be a valid number if provided.');
267
+ if (!factor)
268
+ throw new Error('You must provide a factor to apply.');
269
+ const removedTotal = factor.amount * (factor.multiplier ?? 1);
270
+ return this.#tick(removedTotal);
271
+ }
201
272
  /**
202
273
  * Serializes the current state of the need bar.
203
274
  * @returns {SerializedData}
@@ -0,0 +1,91 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * TinySimpleDice
5
+ *
6
+ * A lightweight, flexible dice rolling utility for generating random numbers.
7
+ * You can configure the dice to allow zero, set a maximum value, and even roll
8
+ * values suitable for indexing arrays or Sets.
9
+ */
10
+ class TinySimpleDice {
11
+ /**
12
+ * Rolls a dice specifically for choosing an array or Set index.
13
+ * @param {any[]|Set<any>} arr - The array or Set to get a random index from.
14
+ * @returns {number} - Valid index for the array or Set.
15
+ * @throws {TypeError} If the input is not an array or Set.
16
+ */
17
+ static rollArrayIndex(arr) {
18
+ const isArray = Array.isArray(arr);
19
+ const isSet = arr instanceof Set;
20
+ if (!isArray && !isSet) throw new TypeError('rollArrayIndex expects an array or Set.');
21
+ return Math.floor(Math.random() * (isArray ? arr.length : arr.size));
22
+ }
23
+
24
+ /** @type {number} */
25
+ #maxValue;
26
+ /** @type {boolean} */
27
+ #allowZero;
28
+
29
+ /**
30
+ * Maximum value the dice can roll.
31
+ * @type {number}
32
+ */
33
+ get maxValue() {
34
+ return this.#maxValue;
35
+ }
36
+
37
+ /**
38
+ * Set the maximum value the dice can roll.
39
+ * @param {number} value - New maximum value (must be a non-negative integer)
40
+ * @throws {TypeError} If value is not a non-negative integer
41
+ */
42
+ set maxValue(value) {
43
+ if (!Number.isInteger(value) || value < 0)
44
+ throw new TypeError('maxValue must be an integer greater than -1.');
45
+ this.#maxValue = value;
46
+ }
47
+
48
+ /**
49
+ * Whether 0 is allowed as a result.
50
+ * @type {boolean}
51
+ */
52
+ get allowZero() {
53
+ return this.#allowZero;
54
+ }
55
+
56
+ /**
57
+ * Set whether 0 is allowed as a result.
58
+ * @param {boolean} value - true to allow 0, false to disallow
59
+ * @throws {TypeError} If value is not a boolean
60
+ */
61
+ set allowZero(value) {
62
+ if (typeof value !== 'boolean') throw new TypeError('allowZero must be a boolean.');
63
+ this.#allowZero = value;
64
+ }
65
+
66
+ /**
67
+ * Creates a new TinySimpleDice instance.
68
+ * @param {Object} options - Configuration options for the dice.
69
+ * @param {number} options.maxValue - Maximum value the dice can roll.
70
+ * @param {boolean} [options.allowZero=true] - Whether 0 is allowed as a result.
71
+ * @throws {TypeError} If maxValue is not a non-negative integer or allowZero is not boolean.
72
+ */
73
+ constructor({ maxValue, allowZero = true }) {
74
+ if (typeof allowZero !== 'boolean') throw new TypeError('allowZero must be an boolean.');
75
+ if (!Number.isInteger(maxValue) || maxValue < 0)
76
+ throw new TypeError('maxValue must be an integer greater than -1.');
77
+ this.#maxValue = maxValue;
78
+ this.#allowZero = allowZero;
79
+ }
80
+
81
+ /**
82
+ * Rolls the dice according to the configuration.
83
+ * @returns {number} - Random number according to the dice configuration.
84
+ */
85
+ roll() {
86
+ const min = this.#allowZero ? 0 : 1;
87
+ return Math.floor(Math.random() * (this.#maxValue - min + 1)) + min;
88
+ }
89
+ }
90
+
91
+ module.exports = TinySimpleDice;
@@ -0,0 +1,57 @@
1
+ export default TinySimpleDice;
2
+ /**
3
+ * TinySimpleDice
4
+ *
5
+ * A lightweight, flexible dice rolling utility for generating random numbers.
6
+ * You can configure the dice to allow zero, set a maximum value, and even roll
7
+ * values suitable for indexing arrays or Sets.
8
+ */
9
+ declare class TinySimpleDice {
10
+ /**
11
+ * Rolls a dice specifically for choosing an array or Set index.
12
+ * @param {any[]|Set<any>} arr - The array or Set to get a random index from.
13
+ * @returns {number} - Valid index for the array or Set.
14
+ * @throws {TypeError} If the input is not an array or Set.
15
+ */
16
+ static rollArrayIndex(arr: any[] | Set<any>): number;
17
+ /**
18
+ * Creates a new TinySimpleDice instance.
19
+ * @param {Object} options - Configuration options for the dice.
20
+ * @param {number} options.maxValue - Maximum value the dice can roll.
21
+ * @param {boolean} [options.allowZero=true] - Whether 0 is allowed as a result.
22
+ * @throws {TypeError} If maxValue is not a non-negative integer or allowZero is not boolean.
23
+ */
24
+ constructor({ maxValue, allowZero }: {
25
+ maxValue: number;
26
+ allowZero?: boolean | undefined;
27
+ });
28
+ /**
29
+ * Set the maximum value the dice can roll.
30
+ * @param {number} value - New maximum value (must be a non-negative integer)
31
+ * @throws {TypeError} If value is not a non-negative integer
32
+ */
33
+ set maxValue(value: number);
34
+ /**
35
+ * Maximum value the dice can roll.
36
+ * @type {number}
37
+ */
38
+ get maxValue(): number;
39
+ /**
40
+ * Set whether 0 is allowed as a result.
41
+ * @param {boolean} value - true to allow 0, false to disallow
42
+ * @throws {TypeError} If value is not a boolean
43
+ */
44
+ set allowZero(value: boolean);
45
+ /**
46
+ * Whether 0 is allowed as a result.
47
+ * @type {boolean}
48
+ */
49
+ get allowZero(): boolean;
50
+ /**
51
+ * Rolls the dice according to the configuration.
52
+ * @returns {number} - Random number according to the dice configuration.
53
+ */
54
+ roll(): number;
55
+ #private;
56
+ }
57
+ //# sourceMappingURL=TinySimpleDice.d.mts.map