tiny-essentials
Version:
Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.
142 lines • 5.83 kB
text/typescript
export default TinyLevelUp;
/**
* Represents a user object used.
*/
export type UserEditor = {
/**
* - Current experience points of the user.
*/
exp: number;
/**
* - Current level of the user.
*/
level: number;
/**
* - Total accumulated experience.
*/
totalExp: number;
};
/**
* Represents a user object used.
*
* @typedef {Object} UserEditor
* @property {number} exp - Current experience points of the user.
* @property {number} level - Current level of the user.
* @property {number} totalExp - Total accumulated experience.
*/
/**
* Class to manage user level-up logic based on experience points.
*/
declare class TinyLevelUp {
/**
* Constructor
* @param {number} giveExp - Base experience value for random experience generation.
* @param {number} expLevel - Base experience needed to level up (per level).
*/
constructor(giveExp: number, expLevel: number);
giveExp: number;
expLevel: number;
/**
* Creates a new user object starting at level 0 with 0 experience.
* @returns {UserEditor} A fresh user object.
*/
createUser(): UserEditor;
/**
* Validates if the given user object has valid numeric properties.
* Throws an error if any property is invalid.
*
* @param {UserEditor} user - The user object to validate.
* @throws {Error} If any property (exp, level, totalExp) is not a valid number.
*/
validateUser(user: UserEditor): void;
/**
* Checks if the given user object is valid by verifying its numeric properties.
*
* @param {UserEditor} user - The user object to check.
* @returns {boolean} `true` if all properties (exp, level, totalExp) are valid numbers; otherwise `false`.
*/
isValidUser(user: UserEditor): boolean;
/**
* Returns the base experience value used for random experience generation.
* Throws an error if the internal giveExp value is not a valid number.
*
* @returns {number} The base experience value.
* @throws {Error} If giveExp is not a valid number.
*/
getGiveExpBase(): number;
/**
* Returns the base experience required to level up.
* Throws an error if the internal expLevel value is not a valid number.
*
* @returns {number} The base experience needed per level.
* @throws {Error} If expLevel is not a valid number.
*/
getExpLevelBase(): number;
/**
* Validates and adjusts the user's level based on their current experience.
* @param {UserEditor} user - The user object containing experience and level properties.
* @returns {UserEditor} The updated user object.
* @throws {Error} If any property (exp, level, totalExp) is not a valid number.
*/
expValidator(user: UserEditor): UserEditor;
/**
* Calculates the total experience based on the user's level.
* @param {UserEditor} user - The user object containing experience and level properties.
* @returns {number} The total experience of the user.
* @throws {Error} If any property (exp, level, totalExp) is not a valid number.
*/
getTotalExp(user: UserEditor): number;
/**
* Generates random experience points based on the configured multiplier.
* @param {number} [multi] - A multiplier for the generated experience.
* @returns {number} The generated experience points.
*/
expGenerator(multi?: number): number;
/**
* Calculates how much experience is missing to next level.
* @param {UserEditor} user
* @returns {number}
* @throws {Error} If any property (exp, level, totalExp) is not a valid number.
*/
getMissingExp(user: UserEditor): number;
/**
* Gets the experience points required to reach the next level.
* @param {UserEditor} user - The user object containing the level.
* @returns {number} The experience required for the next level.
* @throws {Error} If any property (exp, level, totalExp) is not a valid number.
*/
progress(user: UserEditor): number;
/**
* Gets the experience points required to reach the next level.
* @param {UserEditor} user - The user object containing the level.
* @returns {number} The experience required for the next level.
* @throws {Error} If any property (exp, level, totalExp) is not a valid number.
*/
getProgress(user: UserEditor): number;
/**
* Sets the experience value for the user, adjusting their level if necessary.
* @param {UserEditor} user - The user object.
* @param {number} value - The new experience value to set.
* @returns {UserEditor} The updated user object.
*/
set(user: UserEditor, value: number): UserEditor;
/**
* Adds experience to the user, adjusting their level if necessary.
* @param {UserEditor} user - The user object.
* @param {number} [extraExp] - Additional experience to be added.
* @param {'add' | 'extra'} [type] - Type of addition ('add' or 'extra').
* @param {number} [multi] - Multiplier for experience generation.
* @returns {UserEditor} The updated user object.
*/
give(user: UserEditor, extraExp?: number, type?: "add" | "extra", multi?: number): UserEditor;
/**
* Removes experience from the user, adjusting their level if necessary.
* @param {UserEditor} user - The user object.
* @param {number} [extraExp] - Additional experience to remove.
* @param {'add' | 'extra'} [type] - Type of removal ('add' or 'extra').
* @param {number} [multi] - Multiplier for experience generation.
* @returns {UserEditor} The updated user object.
*/
remove(user: UserEditor, extraExp?: number, type?: "add" | "extra", multi?: number): UserEditor;
}
//# sourceMappingURL=TinyLevelUp.d.mts.map