@magicyan/core
Advanced tools
@@ -7,21 +7,21 @@ 'use strict'; | ||
| const random = { | ||
| int(min, max) { | ||
| return Math.floor(this.float(min, max + 1)); | ||
| }, | ||
| float(min, max) { | ||
| return Math.random() * (max - min) + min; | ||
| }, | ||
| int(min, max) { | ||
| return Math.floor(this.float(min, max + 1)); | ||
| } | ||
| }; | ||
| function parseIntOr(value, orValue, radix) { | ||
| function parseIntOrDefault(value, defaultValue, radix) { | ||
| const parsed = Number.parseInt(value, radix); | ||
| return Number.isNaN(parsed) ? orValue : parsed; | ||
| return Number.isNaN(parsed) ? defaultValue : parsed; | ||
| } | ||
| function parseFloatOr(value, orValue) { | ||
| function parseFloatOrDefault(value, defaultValue) { | ||
| const parsed = Number.parseFloat(value); | ||
| return Number.isNaN(parsed) ? orValue : parsed; | ||
| return Number.isNaN(parsed) ? defaultValue : parsed; | ||
| } | ||
| exports.parseFloatOr = parseFloatOr; | ||
| exports.parseIntOr = parseIntOr; | ||
| exports.parseFloatOrDefault = parseFloatOrDefault; | ||
| exports.parseIntOrDefault = parseIntOrDefault; | ||
| exports.random = random; | ||
| exports.randomNumber = randomNumber; |
@@ -5,18 +5,18 @@ function randomNumber(min, max) { | ||
| const random = { | ||
| int(min, max) { | ||
| return Math.floor(this.float(min, max + 1)); | ||
| }, | ||
| float(min, max) { | ||
| return Math.random() * (max - min) + min; | ||
| }, | ||
| int(min, max) { | ||
| return Math.floor(this.float(min, max + 1)); | ||
| } | ||
| }; | ||
| function parseIntOr(value, orValue, radix) { | ||
| function parseIntOrDefault(value, defaultValue, radix) { | ||
| const parsed = Number.parseInt(value, radix); | ||
| return Number.isNaN(parsed) ? orValue : parsed; | ||
| return Number.isNaN(parsed) ? defaultValue : parsed; | ||
| } | ||
| function parseFloatOr(value, orValue) { | ||
| function parseFloatOrDefault(value, defaultValue) { | ||
| const parsed = Number.parseFloat(value); | ||
| return Number.isNaN(parsed) ? orValue : parsed; | ||
| return Number.isNaN(parsed) ? defaultValue : parsed; | ||
| } | ||
| export { parseFloatOr, parseIntOr, random, randomNumber }; | ||
| export { parseFloatOrDefault, parseIntOrDefault, random, randomNumber }; |
@@ -13,3 +13,3 @@ 'use strict'; | ||
| function createTimeout(options) { | ||
| const { time, run } = options; | ||
| const { delay: time, run } = options; | ||
| const timer = setTimeout(() => run(), time); | ||
@@ -16,0 +16,0 @@ return { timer, stop: () => clearTimeout(timer) }; |
@@ -11,3 +11,3 @@ export { setTimeout as sleep } from 'node:timers/promises'; | ||
| function createTimeout(options) { | ||
| const { time, run } = options; | ||
| const { delay: time, run } = options; | ||
| const timer = setTimeout(() => run(), time); | ||
@@ -14,0 +14,0 @@ return { timer, stop: () => clearTimeout(timer) }; |
@@ -9,4 +9,8 @@ 'use strict'; | ||
| } | ||
| function isNumeric(text) { | ||
| return new RegExp(/^\d+$/).test(text); | ||
| } | ||
| exports.isEmail = isEmail; | ||
| exports.isNumeric = isNumeric; | ||
| exports.isUrl = isUrl; |
@@ -7,3 +7,6 @@ function isEmail(email) { | ||
| } | ||
| function isNumeric(text) { | ||
| return new RegExp(/^\d+$/).test(text); | ||
| } | ||
| export { isEmail, isUrl }; | ||
| export { isEmail, isNumeric, isUrl }; |
+3
-2
@@ -23,4 +23,4 @@ 'use strict'; | ||
| exports.toNull = format.toNull; | ||
| exports.parseFloatOr = math.parseFloatOr; | ||
| exports.parseIntOr = math.parseIntOr; | ||
| exports.parseFloatOrDefault = math.parseFloatOrDefault; | ||
| exports.parseIntOrDefault = math.parseIntOrDefault; | ||
| exports.random = math.random; | ||
@@ -34,2 +34,3 @@ exports.randomNumber = math.randomNumber; | ||
| exports.isEmail = validation.isEmail; | ||
| exports.isNumeric = validation.isNumeric; | ||
| exports.isUrl = validation.isUrl; | ||
@@ -36,0 +37,0 @@ exports.copyObject = utils.copyObject; |
+6
-5
@@ -102,7 +102,7 @@ export { setTimeout as sleep } from 'node:timers/promises'; | ||
| declare const random: { | ||
| int(min: number, max: number): number; | ||
| float(min: number, max: number): number; | ||
| int(min: number, max: number): number; | ||
| }; | ||
| declare function parseIntOr(value: string, orValue: number, radix?: number): number; | ||
| declare function parseFloatOr(value: string, orValue: number): number; | ||
| declare function parseIntOrDefault(value: string, defaultValue: number, radix?: number): number; | ||
| declare function parseFloatOrDefault(value: string, defaultValue: number): number; | ||
@@ -118,3 +118,3 @@ interface CreateIntervalOptions { | ||
| interface CreateTimeoutOptions { | ||
| time: number; | ||
| delay: number; | ||
| run(): void; | ||
@@ -147,2 +147,3 @@ } | ||
| declare function isUrl(url: string): boolean; | ||
| declare function isNumeric(text: string): boolean; | ||
@@ -157,2 +158,2 @@ type ObjectRecord = Record<string | number | symbol, any>; | ||
| export { brBuilder, captalize, copyObject, createInterval, createLoopInterval, createTimeout, equalsIgnoreCase, hexToRgb, includesIgnoreCase, isEmail, isUrl, limitText, mergeObject, notFound, parseFloatOr, parseIntOr, random, randomNumber, replaceText, rgbToHex, spaceBuilder, toMergeObject, toNull }; | ||
| export { brBuilder, captalize, copyObject, createInterval, createLoopInterval, createTimeout, equalsIgnoreCase, hexToRgb, includesIgnoreCase, isEmail, isNumeric, isUrl, limitText, mergeObject, notFound, parseFloatOrDefault, parseIntOrDefault, random, randomNumber, replaceText, rgbToHex, spaceBuilder, toMergeObject, toNull }; |
+6
-5
@@ -102,7 +102,7 @@ export { setTimeout as sleep } from 'node:timers/promises'; | ||
| declare const random: { | ||
| int(min: number, max: number): number; | ||
| float(min: number, max: number): number; | ||
| int(min: number, max: number): number; | ||
| }; | ||
| declare function parseIntOr(value: string, orValue: number, radix?: number): number; | ||
| declare function parseFloatOr(value: string, orValue: number): number; | ||
| declare function parseIntOrDefault(value: string, defaultValue: number, radix?: number): number; | ||
| declare function parseFloatOrDefault(value: string, defaultValue: number): number; | ||
@@ -118,3 +118,3 @@ interface CreateIntervalOptions { | ||
| interface CreateTimeoutOptions { | ||
| time: number; | ||
| delay: number; | ||
| run(): void; | ||
@@ -147,2 +147,3 @@ } | ||
| declare function isUrl(url: string): boolean; | ||
| declare function isNumeric(text: string): boolean; | ||
@@ -157,2 +158,2 @@ type ObjectRecord = Record<string | number | symbol, any>; | ||
| export { brBuilder, captalize, copyObject, createInterval, createLoopInterval, createTimeout, equalsIgnoreCase, hexToRgb, includesIgnoreCase, isEmail, isUrl, limitText, mergeObject, notFound, parseFloatOr, parseIntOr, random, randomNumber, replaceText, rgbToHex, spaceBuilder, toMergeObject, toNull }; | ||
| export { brBuilder, captalize, copyObject, createInterval, createLoopInterval, createTimeout, equalsIgnoreCase, hexToRgb, includesIgnoreCase, isEmail, isNumeric, isUrl, limitText, mergeObject, notFound, parseFloatOrDefault, parseIntOrDefault, random, randomNumber, replaceText, rgbToHex, spaceBuilder, toMergeObject, toNull }; |
+6
-5
@@ -102,7 +102,7 @@ export { setTimeout as sleep } from 'node:timers/promises'; | ||
| declare const random: { | ||
| int(min: number, max: number): number; | ||
| float(min: number, max: number): number; | ||
| int(min: number, max: number): number; | ||
| }; | ||
| declare function parseIntOr(value: string, orValue: number, radix?: number): number; | ||
| declare function parseFloatOr(value: string, orValue: number): number; | ||
| declare function parseIntOrDefault(value: string, defaultValue: number, radix?: number): number; | ||
| declare function parseFloatOrDefault(value: string, defaultValue: number): number; | ||
@@ -118,3 +118,3 @@ interface CreateIntervalOptions { | ||
| interface CreateTimeoutOptions { | ||
| time: number; | ||
| delay: number; | ||
| run(): void; | ||
@@ -147,2 +147,3 @@ } | ||
| declare function isUrl(url: string): boolean; | ||
| declare function isNumeric(text: string): boolean; | ||
@@ -157,2 +158,2 @@ type ObjectRecord = Record<string | number | symbol, any>; | ||
| export { brBuilder, captalize, copyObject, createInterval, createLoopInterval, createTimeout, equalsIgnoreCase, hexToRgb, includesIgnoreCase, isEmail, isUrl, limitText, mergeObject, notFound, parseFloatOr, parseIntOr, random, randomNumber, replaceText, rgbToHex, spaceBuilder, toMergeObject, toNull }; | ||
| export { brBuilder, captalize, copyObject, createInterval, createLoopInterval, createTimeout, equalsIgnoreCase, hexToRgb, includesIgnoreCase, isEmail, isNumeric, isUrl, limitText, mergeObject, notFound, parseFloatOrDefault, parseIntOrDefault, random, randomNumber, replaceText, rgbToHex, spaceBuilder, toMergeObject, toNull }; |
+2
-2
| export { hexToRgb, rgbToHex } from './functions/convert.mjs'; | ||
| export { brBuilder, captalize, limitText, notFound, replaceText, spaceBuilder, toNull } from './functions/format.mjs'; | ||
| export { parseFloatOr, parseIntOr, random, randomNumber } from './functions/math.mjs'; | ||
| export { parseFloatOrDefault, parseIntOrDefault, random, randomNumber } from './functions/math.mjs'; | ||
| export { createInterval, createLoopInterval, createTimeout } from './functions/timers.mjs'; | ||
| export { equalsIgnoreCase, includesIgnoreCase } from './functions/check.mjs'; | ||
| export { isEmail, isUrl } from './functions/validation.mjs'; | ||
| export { isEmail, isNumeric, isUrl } from './functions/validation.mjs'; | ||
| export { copyObject, mergeObject, toMergeObject } from './functions/utils.mjs'; | ||
| export { setTimeout as sleep } from 'node:timers/promises'; |
+1
-1
| { | ||
| "name": "@magicyan/core", | ||
| "version": "1.0.17", | ||
| "version": "1.0.18", | ||
| "description": "Very simple functions for you to use in your code", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
+4
-3
@@ -64,2 +64,3 @@ <div align="center"> | ||
| // command.ts | ||
| import { replaceText } from "@magicyan/discord"; | ||
| import lang from "./lang" | ||
@@ -70,3 +71,3 @@ // ... | ||
| const text = textReplacer(lang.welcome[locale], { | ||
| const text = replaceText(lang.welcome[locale], { | ||
| "var(name)": user.displayName // "Rincko Dev", | ||
@@ -78,6 +79,6 @@ "var(libname)": lib.getName() // "@magicyan/core" | ||
| const capitalizedWord = capitalize("hello world"); | ||
| const captalizedWord = captalize("hello world"); | ||
| console.log(capitalizedWord); // Output: "Hello world" | ||
| const capitalizedText = capitalize("i love brazil", true); | ||
| const captalizedText = captalize("i love brazil", true); | ||
| console.log(capitalizedText); // Output: "I Love Brazil" | ||
@@ -84,0 +85,0 @@ |
31460
2.44%473
1.94%161
0.63%