@zadytach/core 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Helzady
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # BlackMagic-Core
@@ -0,0 +1,3 @@
1
+ declare function equalsIgnoreCase(text1: string, text2: string): boolean;
2
+ declare function includesIgnoreCase(text: string, query: string): boolean;
3
+ export { equalsIgnoreCase, includesIgnoreCase };
@@ -0,0 +1,7 @@
1
+ function equalsIgnoreCase(text1, text2) {
2
+ return text1.toLowerCase() === text2.toLowerCase();
3
+ }
4
+ function includesIgnoreCase(text, query) {
5
+ return text.toLowerCase().includes(query.toLowerCase());
6
+ }
7
+ export { equalsIgnoreCase, includesIgnoreCase };
@@ -0,0 +1,3 @@
1
+ declare function hexToRgb(color: string): number;
2
+ declare function rgbToHex(rgb: number, includeHash?: boolean): string;
3
+ export { hexToRgb, rgbToHex };
@@ -0,0 +1,9 @@
1
+ function hexToRgb(color) {
2
+ return Number.parseInt(color.startsWith("#") ? color.slice(1) : color, 16);
3
+ }
4
+ function rgbToHex(rgb, includeHash = true) {
5
+ const hexValue = rgb.toString(16);
6
+ const hexColor = hexValue.padStart(6, "0");
7
+ return includeHash ? `#${hexColor}` : hexColor;
8
+ }
9
+ export { hexToRgb, rgbToHex };
@@ -0,0 +1,2 @@
1
+ declare function createDate(date: Date | string | number): any;
2
+ export { createDate };
@@ -0,0 +1,88 @@
1
+ function createDate(date) {
2
+ const _date = new Date(date ?? Date.now());
3
+ return Object.assign(_date, {
4
+ add(unit, value) {
5
+ switch (unit) {
6
+ case "days":
7
+ _date.setDate(_date.getDate() + value);
8
+ break;
9
+ case "hours":
10
+ _date.setHours(_date.getHours() + value);
11
+ break;
12
+ case "minutes":
13
+ _date.setMinutes(_date.getMinutes() + value);
14
+ break;
15
+ case "seconds":
16
+ _date.setSeconds(_date.getSeconds() + value);
17
+ break;
18
+ case "milliseconds":
19
+ _date.setMilliseconds(_date.getMilliseconds() + value);
20
+ break;
21
+ case "months":
22
+ _date.setMonth(_date.getMonth() + value);
23
+ break;
24
+ case "years":
25
+ _date.setFullYear(_date.getFullYear() + value);
26
+ break;
27
+ }
28
+ return this;
29
+ },
30
+ sub(unit, value) {
31
+ return this.add(unit, -value);
32
+ },
33
+ set(unit, value) {
34
+ switch (unit) {
35
+ case "days":
36
+ _date.setDate(value);
37
+ break;
38
+ case "hours":
39
+ _date.setHours(value);
40
+ break;
41
+ case "minutes":
42
+ _date.setMinutes(value);
43
+ break;
44
+ case "seconds":
45
+ _date.setSeconds(value);
46
+ break;
47
+ case "milliseconds":
48
+ _date.setMilliseconds(value);
49
+ break;
50
+ case "months":
51
+ _date.setMonth(value);
52
+ break;
53
+ case "years":
54
+ _date.setFullYear(value);
55
+ break;
56
+ }
57
+ return this;
58
+ },
59
+ diff(other, unit = "milliseconds") {
60
+ const msDiff = Math.abs(_date.getTime() - other.getTime());
61
+ switch (unit) {
62
+ case "milliseconds":
63
+ return msDiff;
64
+ case "seconds":
65
+ return Math.floor(msDiff / 1e3);
66
+ case "minutes":
67
+ return Math.floor(msDiff / (1e3 * 60));
68
+ case "hours":
69
+ return Math.floor(msDiff / (1e3 * 60 * 60));
70
+ case "days":
71
+ return Math.floor(msDiff / (1e3 * 60 * 60 * 24));
72
+ case "months": {
73
+ const years = _date.getFullYear() - other.getFullYear();
74
+ const months = _date.getMonth() - other.getMonth();
75
+ return Math.abs(years * 12 + months);
76
+ }
77
+ case "years":
78
+ return Math.abs(_date.getFullYear() - other.getFullYear());
79
+ default:
80
+ return msDiff;
81
+ }
82
+ },
83
+ clone() {
84
+ return createDate(_date.getTime());
85
+ },
86
+ });
87
+ }
88
+ export { createDate };
@@ -0,0 +1,10 @@
1
+ declare function joinBuilder(separator: string, ...text: (string | undefined | null)[]): string;
2
+ declare function notFound(value: any): any;
3
+ declare function brBuilder(...text: (string | undefined | null)[]): string;
4
+ declare function spaceBuilder(...text: (string | undefined | null)[]): string;
5
+ declare function replaceText(text: string, replacements: {
6
+ [key: string]: string | Function;
7
+ }): string;
8
+ declare function capitalize(word: string, allWords?: boolean): string;
9
+ declare function limitText(text: string, maxLength: number, endText?: string): string;
10
+ export { brBuilder, capitalize, joinBuilder, limitText, notFound, replaceText, spaceBuilder };
@@ -0,0 +1,34 @@
1
+ import { isDefined } from '@functions';
2
+ function joinBuilder(separator, ...text) {
3
+ return text.flat(Infinity).filter(isDefined).filter((bol) => typeof bol === "string").join(separator);
4
+ }
5
+ function notFound(value) {
6
+ return value !== null ? value : void 0;
7
+ }
8
+ function brBuilder(...text) {
9
+ return joinBuilder("\n", ...text);
10
+ }
11
+ function spaceBuilder(...text) {
12
+ return joinBuilder(" ", ...text);
13
+ }
14
+ function replaceText(text, replacements) {
15
+ const keys = Object.keys(replacements);
16
+ if (keys.length === 0)
17
+ return text;
18
+ keys.sort((a, b) => b.length - a.length);
19
+ const pattern = new RegExp(keys.map((str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"), "g");
20
+ return text.replace(pattern, (match) => {
21
+ const value = replacements[match];
22
+ return typeof value === "function" ? value(match) : value;
23
+ });
24
+ }
25
+ function capitalize(word, allWords = false) {
26
+ word = word.trim();
27
+ if (!word)
28
+ return word;
29
+ return allWords ? word.split(" ").map((w) => w[0].toUpperCase() + w.slice(1).toLowerCase()).join(" ") : word[0].toUpperCase() + word.slice(1).toLowerCase();
30
+ }
31
+ function limitText(text, maxLength, endText = "") {
32
+ return text.length >= maxLength ? text.slice(0, maxLength) + endText : text;
33
+ }
34
+ export { brBuilder, capitalize, joinBuilder, limitText, notFound, replaceText, spaceBuilder };
@@ -0,0 +1,10 @@
1
+ export * from "./check.js";
2
+ export * from "./convert.js";
3
+ export * from "./date.js";
4
+ export * from "./format.js";
5
+ export * from "./validation.js";
6
+ export * from "./with.js";
7
+ export * from "./ms.js";
8
+ export * from "./math.js";
9
+ export * from "./timers.js";
10
+ export * from "./sleep.js";
@@ -0,0 +1,10 @@
1
+ export * from "./check.js";
2
+ export * from "./convert.js";
3
+ export * from "./date.js";
4
+ export * from "./format.js";
5
+ export * from "./validation.js";
6
+ export * from "./with.js";
7
+ export * from "./ms.js";
8
+ export * from "./math.js";
9
+ export * from "./timers.js";
10
+ export * from "./sleep.js";
@@ -0,0 +1,8 @@
1
+ declare function randomNumber(min: number, max: number): number;
2
+ declare const random: {
3
+ int(min: number, max: number): number;
4
+ float(min: number, max: number): number;
5
+ };
6
+ declare function parseIntOrDefault(value: string, defaultValue: number, radix: number): number;
7
+ declare function parseFloatOrDefault(value: string, defaultValue: number): number;
8
+ export { parseFloatOrDefault, parseIntOrDefault, random, randomNumber };
@@ -0,0 +1,20 @@
1
+ function randomNumber(min, max) {
2
+ return Math.floor(Math.random() * (max - min + 1) + min);
3
+ }
4
+ const random = {
5
+ int(min, max) {
6
+ return Math.floor(this.float(min, max + 1));
7
+ },
8
+ float(min, max) {
9
+ return Math.random() * (max - min) + min;
10
+ }
11
+ };
12
+ function parseIntOrDefault(value, defaultValue, radix) {
13
+ const parsed = Number.parseInt(value, radix);
14
+ return Number.isNaN(parsed) ? defaultValue : parsed;
15
+ }
16
+ function parseFloatOrDefault(value, defaultValue) {
17
+ const parsed = Number.parseFloat(value);
18
+ return Number.isNaN(parsed) ? defaultValue : parsed;
19
+ }
20
+ export { parseFloatOrDefault, parseIntOrDefault, random, randomNumber };
@@ -0,0 +1,4 @@
1
+ declare const toMs: Function & {
2
+ [key: string]: any;
3
+ };
4
+ export { toMs };
@@ -0,0 +1,12 @@
1
+ import { withProperties } from '@functions';
2
+ const timeUnits = Object.freeze({
3
+ seconds: (value) => value * 1e3,
4
+ minutes: (value) => timeUnits.seconds(value * 60),
5
+ hours: (value) => timeUnits.minutes(value * 60),
6
+ days: (value) => timeUnits.hours(value * 24)
7
+ });
8
+ function toMsFunc(value, unit = "seconds") {
9
+ return timeUnits[unit](value);
10
+ }
11
+ const toMs = withProperties(toMsFunc, timeUnits);
12
+ export { toMs };
@@ -0,0 +1,4 @@
1
+ declare const sleep: Function & {
2
+ [key: string]: any;
3
+ };
4
+ export { sleep };
@@ -0,0 +1,18 @@
1
+ import { setTimeout } from 'node:timers/promises';
2
+ import { withProperties } from '@functions';
3
+ async function baseSleep(time, value) {
4
+ await setTimeout(time);
5
+ return typeof value === "function" ? value() : value;
6
+ }
7
+ const sleep = withProperties(baseSleep, {
8
+ async seconds(time, value) {
9
+ return sleep(time * 1e3, value);
10
+ },
11
+ async minutes(time, value) {
12
+ return sleep.seconds(time * 60, value);
13
+ },
14
+ async hours(time, value) {
15
+ return sleep.minutes(time * 60, value);
16
+ }
17
+ });
18
+ export { sleep };
@@ -0,0 +1,25 @@
1
+ declare function createInterval(options: {
2
+ time: number;
3
+ run: (stop: () => void) => void;
4
+ immediately?: boolean;
5
+ }): {
6
+ timer: NodeJS.Timeout;
7
+ stop: () => void;
8
+ };
9
+ declare function createTimeout(options: {
10
+ delay: number;
11
+ run: () => void;
12
+ }): {
13
+ timer: NodeJS.Timeout;
14
+ stop: () => void;
15
+ };
16
+ declare function createLoopInterval(options: {
17
+ run: (item: any, stop: () => void, lap: number, array: any[]) => void;
18
+ time: number;
19
+ array: any[];
20
+ immediately?: boolean;
21
+ }): {
22
+ timer: NodeJS.Timeout;
23
+ stop: () => void;
24
+ };
25
+ export { createInterval, createLoopInterval, createTimeout };
@@ -0,0 +1,33 @@
1
+ function createInterval(options) {
2
+ const { time, run, immediately } = options;
3
+ if (immediately)
4
+ run(() => {
5
+ });
6
+ const timer = setInterval(() => {
7
+ run(() => clearInterval(timer));
8
+ }, time);
9
+ return { timer, stop: () => clearInterval(timer) };
10
+ }
11
+ function createTimeout(options) {
12
+ const { delay, run } = options;
13
+ const timer = setTimeout(() => run(), delay);
14
+ return { timer, stop: () => clearTimeout(timer) };
15
+ }
16
+ function createLoopInterval(options) {
17
+ const { run, time, array, immediately } = options;
18
+ let lap = 0;
19
+ let loop = 0;
20
+ return createInterval({
21
+ immediately,
22
+ time,
23
+ run(stop) {
24
+ if (loop === array.length) {
25
+ lap++;
26
+ loop = 0;
27
+ }
28
+ run(array[loop], stop, lap, array);
29
+ loop++;
30
+ }
31
+ });
32
+ }
33
+ export { createInterval, createLoopInterval, createTimeout };
@@ -0,0 +1,6 @@
1
+ declare function isEmail(email: string): boolean;
2
+ declare function isUrl(url: string): boolean;
3
+ declare function isNumeric(text: string): boolean;
4
+ declare function isDefined(value: any): boolean;
5
+ declare function isPromise(value: any): boolean;
6
+ export { isDefined, isEmail, isNumeric, isPromise, isUrl };
@@ -0,0 +1,16 @@
1
+ function isEmail(email) {
2
+ return new RegExp(/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/).test(email);
3
+ }
4
+ function isUrl(url) {
5
+ return new RegExp(/^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/).test(url);
6
+ }
7
+ function isNumeric(text) {
8
+ return new RegExp(/^\d+$/).test(text);
9
+ }
10
+ function isDefined(value) {
11
+ return value !== null && value !== void 0;
12
+ }
13
+ function isPromise(value) {
14
+ return typeof value === "object" && value !== null && typeof value.then === "function";
15
+ }
16
+ export { isDefined, isEmail, isNumeric, isPromise, isUrl };
@@ -0,0 +1,7 @@
1
+ declare function withProperties(fn: Function, props: {
2
+ [key: string]: any;
3
+ }): Function & {
4
+ [key: string]: any;
5
+ };
6
+ declare function withTimeout(promise: Promise<any>, time: number, fallback?: any): Promise<any>;
7
+ export { withProperties, withTimeout };
@@ -0,0 +1,8 @@
1
+ function withProperties(fn, props) {
2
+ return Object.assign(fn, props);
3
+ }
4
+ function withTimeout(promise, time, fallback) {
5
+ const timeout = new Promise((resolve) => setTimeout(() => resolve(fallback ?? null), time));
6
+ return Promise.race([promise, timeout]);
7
+ }
8
+ export { withProperties, withTimeout };
@@ -0,0 +1 @@
1
+ export { equalsIgnoreCase, includesIgnoreCase, hexToRgb, rgbToHex, brBuilder, capitalize, joinBuilder, limitText, notFound, replaceText, spaceBuilder, parseFloatOrDefault, parseIntOrDefault, random, randomNumber, toMs, createInterval, createLoopInterval, createTimeout, isDefined, isEmail, isNumeric, isPromise, isUrl, withProperties, withTimeout, createDate, sleep, } from "@functions";
package/build/index.js ADDED
@@ -0,0 +1 @@
1
+ export { equalsIgnoreCase, includesIgnoreCase, hexToRgb, rgbToHex, brBuilder, capitalize, joinBuilder, limitText, notFound, replaceText, spaceBuilder, parseFloatOrDefault, parseIntOrDefault, random, randomNumber, toMs, createInterval, createLoopInterval, createTimeout, isDefined, isEmail, isNumeric, isPromise, isUrl, withProperties, withTimeout, createDate, sleep, } from "@functions";
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@zadytach/core",
3
+ "version": "1.0.0",
4
+ "description": "Uma coleção de funções utilitárias simples e leves para tarefas comuns em projetos.",
5
+ "main": "build/index.js",
6
+ "types": "build/index.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "files": [
11
+ "build"
12
+ ],
13
+ "scripts": {
14
+ "build": "tsc"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/HelzadyDev/BlackMagic-Core.git"
19
+ },
20
+ "keywords": [
21
+ "discord",
22
+ "discordjs",
23
+ "typescript"
24
+ ],
25
+ "author": {
26
+ "url": "https://github.com/HelzadyDev",
27
+ "name": "HelzadyDev"
28
+ },
29
+ "license": "ISC",
30
+ "type": "module",
31
+ "bugs": {
32
+ "url": "https://github.com/HelzadyDev/BlackMagic-Core/issues"
33
+ },
34
+ "homepage": "https://github.com/HelzadyDev/BlackMagic-Core#readme",
35
+ "devDependencies": {
36
+ "@types/node": "^25.8.0",
37
+ "tsx": "^4.22.0",
38
+ "typescript": "^6.0.3"
39
+ },
40
+ "paths": {
41
+ "@functions": [
42
+ "./build/functions/index.js"
43
+ ]
44
+ }
45
+ }