@seedcord/utils 0.1.1 → 0.2.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/package.json +12 -15
- package/dist/index.d.mts +0 -169
package/package.json
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seedcord/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"description": "Utility functions for Seedcord packages",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/materwelondhruv/seedcord.git",
|
|
9
9
|
"directory": "packages/utils"
|
|
10
10
|
},
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
11
12
|
"exports": {
|
|
12
13
|
".": {
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"require": {
|
|
18
|
-
"types": "./dist/index.d.cts",
|
|
19
|
-
"default": "./dist/index.cjs"
|
|
20
|
-
}
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.mjs",
|
|
16
|
+
"require": "./dist/index.cjs",
|
|
17
|
+
"default": "./dist/index.mjs"
|
|
21
18
|
}
|
|
22
19
|
},
|
|
23
20
|
"files": [
|
|
@@ -31,16 +28,16 @@
|
|
|
31
28
|
},
|
|
32
29
|
"dependencies": {
|
|
33
30
|
"discord.js": "14.22.1",
|
|
34
|
-
"@seedcord/
|
|
35
|
-
"@seedcord/
|
|
31
|
+
"@seedcord/types": "^0.2.0",
|
|
32
|
+
"@seedcord/services": "^0.2.0"
|
|
36
33
|
},
|
|
37
34
|
"devDependencies": {
|
|
38
|
-
"@seedcord/eslint-config": "^1.
|
|
39
|
-
"@seedcord/
|
|
40
|
-
"@seedcord/
|
|
35
|
+
"@seedcord/eslint-config": "^1.2.0",
|
|
36
|
+
"@seedcord/tsconfig": "^1.0.3",
|
|
37
|
+
"@seedcord/tsup-config": "^1.0.3"
|
|
41
38
|
},
|
|
42
39
|
"scripts": {
|
|
43
|
-
"build": "tsup
|
|
40
|
+
"build": "tsup",
|
|
44
41
|
"clean": "rm -rf dist",
|
|
45
42
|
"lint": "eslint 'src/**/*.{ts,tsx}' --cache",
|
|
46
43
|
"lint:fix": "eslint 'src/**/*.{ts,tsx}' --fix --cache",
|
package/dist/index.d.mts
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { TupleOf } from '@seedcord/types';
|
|
2
|
-
import { Logger } from '@seedcord/services';
|
|
3
|
-
import * as fs from 'node:fs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Return current time in seconds
|
|
7
|
-
*/
|
|
8
|
-
declare function currentTime(): number;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Generates a random numeric code with the specified number of digits.
|
|
12
|
-
*
|
|
13
|
-
* @param digits - The number of digits for the generated code.
|
|
14
|
-
* @returns A random numeric code with the specified number of digits.
|
|
15
|
-
*/
|
|
16
|
-
declare function generateCode(digits: number): number;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Converts hexcode to number
|
|
20
|
-
*
|
|
21
|
-
* @param hex - The hex code to convert.
|
|
22
|
-
* @returns The converted number.
|
|
23
|
-
*/
|
|
24
|
-
declare function hexToNumber(hex: string): number;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Returns the ordinal suffix for a given number.
|
|
28
|
-
*
|
|
29
|
-
* @param n - The number to get the ordinal for
|
|
30
|
-
* @returns The number with its ordinal suffix
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ordinal(1); // "1st"
|
|
34
|
-
* ordinal(22); // "22nd"
|
|
35
|
-
* ordinal(13); // "13th"
|
|
36
|
-
*/
|
|
37
|
-
declare function ordinal(n: number): string;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Takes two numbers and returns the percentage of the first number in the second number with two decimal places.
|
|
41
|
-
*
|
|
42
|
-
* @param num1 - The first number.
|
|
43
|
-
* @param num2 - The second number.
|
|
44
|
-
*
|
|
45
|
-
* @returns The percentage of the first number in the second number with two decimal places.
|
|
46
|
-
*/
|
|
47
|
-
declare function percentage(num1: number, num2: number): number;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Rounds a number to a specified number of decimal places.
|
|
51
|
-
*
|
|
52
|
-
* @param num - The number to be rounded.
|
|
53
|
-
* @param precision - The number of decimal places to round to.
|
|
54
|
-
* @returns The rounded number.
|
|
55
|
-
*/
|
|
56
|
-
declare function round(num: number, precision: number): number;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Rounds a number to a string representation with a denomination suffix.
|
|
60
|
-
* @param num - The number to round.
|
|
61
|
-
* @example
|
|
62
|
-
* ```ts
|
|
63
|
-
* roundToDenomination(1234); // "1.2K"
|
|
64
|
-
* roundToDenomination(10000, ['k', 'm', 'b', 't', 'q']); // "10k"
|
|
65
|
-
* roundToDenomination(12345678); // "12.3M"
|
|
66
|
-
* ```
|
|
67
|
-
* @returns The rounded number as a string with a denomination suffix.
|
|
68
|
-
*/
|
|
69
|
-
declare function roundToDenomination(num: number, opts?: {
|
|
70
|
-
suffixes?: TupleOf<string, 5>;
|
|
71
|
-
precision?: number;
|
|
72
|
-
}): string;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Returns the word with it's first letter capitalized and the rest in lowercase.
|
|
76
|
-
* @param word - The word to be formatted.
|
|
77
|
-
* @returns The formatted word.
|
|
78
|
-
*/
|
|
79
|
-
declare function capitalize(word: string): string;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Function takes an array of strings or numbers and returns the number of characters in the longest string/number
|
|
83
|
-
*
|
|
84
|
-
* @param arr - The array of strings or numbers
|
|
85
|
-
* @returns The length of the longest element when converted to string
|
|
86
|
-
*/
|
|
87
|
-
declare function longestStringLength(arr: (string | number)[]): number;
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Generates an ASCII table from the provided data.
|
|
91
|
-
*
|
|
92
|
-
* @param data - The data to be displayed in the table.
|
|
93
|
-
* @returns The generated ASCII table as a string.
|
|
94
|
-
*/
|
|
95
|
-
declare function generateAsciiTable(data: string[][]): string;
|
|
96
|
-
|
|
97
|
-
interface PrettifyOptions {
|
|
98
|
-
capitalize?: boolean;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Converts a string from any common naming convention to human-readable format.
|
|
102
|
-
* Handles camelCase, PascalCase, snake_case, and kebab-case.
|
|
103
|
-
*
|
|
104
|
-
* @param key - The string to convert
|
|
105
|
-
* @param opts - Optional configuration
|
|
106
|
-
* @returns A space-separated, human-readable string
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* prettify("camelCaseString") // "camel Case String"
|
|
110
|
-
* prettify("PascalCaseString") // "Pascal Case String"
|
|
111
|
-
* prettify("snake_case_string") // "snake case string"
|
|
112
|
-
* prettify("kebab-case-string") // "kebab case string"
|
|
113
|
-
* prettify("mixedCase_string-name") // "mixed Case string name"
|
|
114
|
-
*/
|
|
115
|
-
declare function prettify(key: string, opts?: PrettifyOptions): string;
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Calculates the difference between two numbers and formats it as a string with a '+' prefix for positive differences.
|
|
119
|
-
*
|
|
120
|
-
* @param numBefore - The initial number value
|
|
121
|
-
* @param numAfter - The final number value
|
|
122
|
-
* @returns A string representing the difference, with a '+' sign for positive differences
|
|
123
|
-
*
|
|
124
|
-
* @example
|
|
125
|
-
* // Returns "+5"
|
|
126
|
-
* prettyDifference(10, 15);
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* // Returns "-3"
|
|
130
|
-
* prettyDifference(10, 7);
|
|
131
|
-
*/
|
|
132
|
-
declare function prettyDifference(numBefore: number, numAfter: number): string;
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Shuffles an array using the Fisher-Yates algorithm.
|
|
136
|
-
* This function creates a new array with the same elements in a random order,
|
|
137
|
-
* without modifying the original array.
|
|
138
|
-
*
|
|
139
|
-
* @typeParam TArray - The type of elements in the array
|
|
140
|
-
* @param items - The array to shuffle
|
|
141
|
-
* @returns A new array with the same elements in a random order
|
|
142
|
-
*
|
|
143
|
-
* @example
|
|
144
|
-
* ```typescript
|
|
145
|
-
* const numbers = [1, 2, 3, 4, 5];
|
|
146
|
-
* const shuffled = fyShuffle(numbers);
|
|
147
|
-
* // shuffled might be [3, 1, 5, 2, 4]
|
|
148
|
-
* // numbers is still [1, 2, 3, 4, 5]
|
|
149
|
-
* ```
|
|
150
|
-
*/
|
|
151
|
-
declare function fyShuffle<TArray>(items: TArray[]): TArray[];
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Determines if a directory entry is a TypeScript or JavaScript file.
|
|
155
|
-
*
|
|
156
|
-
* @param entry - The directory entry to check.
|
|
157
|
-
* @returns True if the entry is a file ending with .ts or .js.
|
|
158
|
-
*/
|
|
159
|
-
declare function isTsOrJsFile(entry: fs.Dirent): boolean;
|
|
160
|
-
/**
|
|
161
|
-
* Recursively traverses through a directory, importing all .ts and .js files and applying a callback to each import.
|
|
162
|
-
*
|
|
163
|
-
* @param dir - The directory path to traverse.
|
|
164
|
-
* @param callback - A function that will be called for each imported module. It receives the full file path, the file's relative path, and the imported module as arguments.
|
|
165
|
-
* @returns A Promise that resolves when the traversal is complete.
|
|
166
|
-
*/
|
|
167
|
-
declare function traverseDirectory(dir: string, callback: (fullPath: string, relativePath: string, imported: Record<string, unknown>) => Promise<void> | void, logger: Logger): Promise<void>;
|
|
168
|
-
|
|
169
|
-
export { capitalize, currentTime, fyShuffle, generateAsciiTable, generateCode, hexToNumber, isTsOrJsFile, longestStringLength, ordinal, percentage, prettify, prettyDifference, round, roundToDenomination, traverseDirectory };
|