@seedcord/utils 0.1.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,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2025 Dhruv Jain (materwelonDhruv)
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ <p align="center">
2
+ <img src="../../assets/banner.png" alt="seedcord" width="100%" />
3
+ </p>
4
+
5
+ ---
package/dist/index.cjs ADDED
@@ -0,0 +1,250 @@
1
+ 'use strict';
2
+
3
+ var promises = require('fs/promises');
4
+ var path = require('path');
5
+
6
+ function _interopNamespace(e) {
7
+ if (e && e.__esModule) return e;
8
+ var n = Object.create(null);
9
+ if (e) {
10
+ Object.keys(e).forEach(function (k) {
11
+ if (k !== 'default') {
12
+ var d = Object.getOwnPropertyDescriptor(e, k);
13
+ Object.defineProperty(n, k, d.get ? d : {
14
+ enumerable: true,
15
+ get: function () { return e[k]; }
16
+ });
17
+ }
18
+ });
19
+ }
20
+ n.default = e;
21
+ return Object.freeze(n);
22
+ }
23
+
24
+ var path__namespace = /*#__PURE__*/_interopNamespace(path);
25
+
26
+ var __defProp = Object.defineProperty;
27
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
28
+
29
+ // src/numbers/currentTime.ts
30
+ function currentTime() {
31
+ return Math.floor(Date.now() / 1e3);
32
+ }
33
+ __name(currentTime, "currentTime");
34
+
35
+ // src/numbers/generateCode.ts
36
+ function generateCode(digits) {
37
+ const min = Math.pow(10, digits - 1);
38
+ const max = Math.pow(10, digits) - 1;
39
+ return Math.floor(Math.random() * (max - min + 1) + min);
40
+ }
41
+ __name(generateCode, "generateCode");
42
+
43
+ // src/numbers/hexToNumber.ts
44
+ function hexToNumber(hex) {
45
+ if (typeof hex !== "string") {
46
+ throw new TypeError("hexToNumber expects a string input");
47
+ }
48
+ const normalized = hex.replace(/^#/, "");
49
+ if (!/^[0-9a-fA-F]+$/.test(normalized)) {
50
+ throw new Error("Invalid hex string");
51
+ }
52
+ const converted = parseInt(normalized, 16);
53
+ if (Number.isNaN(converted)) {
54
+ throw new Error("Invalid hex string");
55
+ }
56
+ return converted;
57
+ }
58
+ __name(hexToNumber, "hexToNumber");
59
+
60
+ // src/numbers/ordinal.ts
61
+ function ordinal(n) {
62
+ const s = [
63
+ "th",
64
+ "st",
65
+ "nd",
66
+ "rd"
67
+ ];
68
+ const v = n % 100;
69
+ const index = (v - 20) % 10;
70
+ const suffix = s[index] ?? s[v] ?? s[0];
71
+ if (!suffix) return `${n}th`;
72
+ return `${n}${suffix}`;
73
+ }
74
+ __name(ordinal, "ordinal");
75
+
76
+ // src/numbers/percentage.ts
77
+ function percentage(num1, num2) {
78
+ return Number((num1 / num2 * 100).toFixed(2));
79
+ }
80
+ __name(percentage, "percentage");
81
+
82
+ // src/numbers/round.ts
83
+ function round(num, precision) {
84
+ const factor = Math.pow(10, precision);
85
+ return Math.round((num + Number.EPSILON) * factor) / factor;
86
+ }
87
+ __name(round, "round");
88
+
89
+ // src/numbers/roundToDenomination.ts
90
+ function roundToDenomination(num, opts) {
91
+ const { suffixes = [
92
+ "K",
93
+ "M",
94
+ "B",
95
+ "T",
96
+ "Q"
97
+ ], precision = 1 } = opts ?? {};
98
+ if (num < 1e4) {
99
+ return num.toString();
100
+ }
101
+ let index = -1;
102
+ let temp = num;
103
+ while (temp >= 1e3 && index < suffixes.length - 1) {
104
+ temp /= 1e3;
105
+ index++;
106
+ }
107
+ let result;
108
+ if (temp % 1 === 0) {
109
+ result = temp.toString();
110
+ } else {
111
+ const adjustedTemp = Math.round(temp * Math.pow(10, precision + 1)) / Math.pow(10, precision + 1);
112
+ result = adjustedTemp.toFixed(precision);
113
+ }
114
+ if (result.endsWith(".9")) {
115
+ result = Math.ceil(Number(result)).toString();
116
+ }
117
+ if (result.endsWith(".0")) {
118
+ result = result.substring(0, result.length - 2);
119
+ }
120
+ if (result === "1000") {
121
+ index += 1;
122
+ result = "1";
123
+ }
124
+ return result + (index >= 0 ? suffixes[index] : "");
125
+ }
126
+ __name(roundToDenomination, "roundToDenomination");
127
+
128
+ // src/strings/capitalize.ts
129
+ function capitalize(word) {
130
+ return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
131
+ }
132
+ __name(capitalize, "capitalize");
133
+
134
+ // src/strings/longestStringLength.ts
135
+ function longestStringLength(arr) {
136
+ return Math.max(...arr.map((el) => el.toString().length));
137
+ }
138
+ __name(longestStringLength, "longestStringLength");
139
+
140
+ // src/strings/generateAsciiTable.ts
141
+ function generateAsciiTable(data) {
142
+ if (data.length === 0) return "";
143
+ const firstRow = data[0];
144
+ if (!firstRow || firstRow.length === 0) return "";
145
+ let table = "";
146
+ const columnWidths = [];
147
+ for (let i = 0; i < firstRow.length; i++) {
148
+ let maxWidth = 0;
149
+ for (const row of data) {
150
+ const cell = row[i];
151
+ if (cell !== void 0) maxWidth = Math.max(maxWidth, cell.length);
152
+ }
153
+ columnWidths.push(maxWidth);
154
+ }
155
+ const createLine = /* @__PURE__ */ __name((char, left, intersect, right) => {
156
+ let line = left;
157
+ columnWidths.forEach((width, index) => {
158
+ line += char.repeat(width + 2);
159
+ if (index < columnWidths.length - 1) line += intersect;
160
+ else line += right;
161
+ });
162
+ line += "\n";
163
+ return line;
164
+ }, "createLine");
165
+ table += createLine("\u2550", "\u2554", "\u2566", "\u2557");
166
+ data.forEach((row, rowIndex) => {
167
+ table += "\u2551";
168
+ row.forEach((cell, columnIndex) => {
169
+ const columnWidth = columnWidths[columnIndex];
170
+ if (columnWidth !== void 0) table += ` ${cell.padEnd(columnWidth)} \u2551`;
171
+ });
172
+ table += "\n";
173
+ if (rowIndex < data.length - 1) table += createLine("\u2500", "\u2560", "\u256C", "\u2563");
174
+ else table += createLine("\u2550", "\u255A", "\u2569", "\u255D");
175
+ });
176
+ return table;
177
+ }
178
+ __name(generateAsciiTable, "generateAsciiTable");
179
+
180
+ // src/strings/prettify.ts
181
+ function prettify(key, opts) {
182
+ const result = key.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[_-]/g, " ").trim();
183
+ if (opts?.capitalize) return capitalize(result);
184
+ return result;
185
+ }
186
+ __name(prettify, "prettify");
187
+
188
+ // src/strings/prettyDifference.ts
189
+ function prettyDifference(numBefore, numAfter) {
190
+ return (numAfter - numBefore > 0 ? `+${numAfter - numBefore}` : numAfter - numBefore).toString();
191
+ }
192
+ __name(prettyDifference, "prettyDifference");
193
+
194
+ // src/fyShuffle.ts
195
+ function fyShuffle(items) {
196
+ const array = items.slice();
197
+ for (let i = array.length - 1; i > 0; i--) {
198
+ const j = Math.floor(Math.random() * (i + 1));
199
+ [array[i], array[j]] = [
200
+ array[j],
201
+ array[i]
202
+ ];
203
+ }
204
+ return array;
205
+ }
206
+ __name(fyShuffle, "fyShuffle");
207
+ function isTsOrJsFile(entry) {
208
+ return entry.isFile() && (entry.name.endsWith(".ts") || entry.name.endsWith(".js")) && !entry.name.endsWith(".d.ts") && !entry.name.endsWith(".map");
209
+ }
210
+ __name(isTsOrJsFile, "isTsOrJsFile");
211
+ async function traverseDirectory(dir, callback, logger) {
212
+ let entries;
213
+ try {
214
+ entries = await promises.readdir(dir, {
215
+ withFileTypes: true
216
+ });
217
+ } catch {
218
+ logger.error("Failed to read this directory");
219
+ entries = [];
220
+ }
221
+ for (const entry of entries) {
222
+ const fullPath = path__namespace.join(dir, entry.name);
223
+ const relativePath = path__namespace.relative(process.cwd(), fullPath);
224
+ if (entry.isDirectory()) {
225
+ await traverseDirectory(fullPath, callback, logger);
226
+ } else if (isTsOrJsFile(entry)) {
227
+ const imported = await import(fullPath);
228
+ await callback(fullPath, relativePath, imported);
229
+ }
230
+ }
231
+ }
232
+ __name(traverseDirectory, "traverseDirectory");
233
+
234
+ exports.capitalize = capitalize;
235
+ exports.currentTime = currentTime;
236
+ exports.fyShuffle = fyShuffle;
237
+ exports.generateAsciiTable = generateAsciiTable;
238
+ exports.generateCode = generateCode;
239
+ exports.hexToNumber = hexToNumber;
240
+ exports.isTsOrJsFile = isTsOrJsFile;
241
+ exports.longestStringLength = longestStringLength;
242
+ exports.ordinal = ordinal;
243
+ exports.percentage = percentage;
244
+ exports.prettify = prettify;
245
+ exports.prettyDifference = prettyDifference;
246
+ exports.round = round;
247
+ exports.roundToDenomination = roundToDenomination;
248
+ exports.traverseDirectory = traverseDirectory;
249
+ //# sourceMappingURL=index.cjs.map
250
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/numbers/currentTime.ts","../src/numbers/generateCode.ts","../src/numbers/hexToNumber.ts","../src/numbers/ordinal.ts","../src/numbers/percentage.ts","../src/numbers/round.ts","../src/numbers/roundToDenomination.ts","../src/strings/capitalize.ts","../src/strings/longestStringLength.ts","../src/strings/generateAsciiTable.ts","../src/strings/prettify.ts","../src/strings/prettyDifference.ts","../src/fyShuffle.ts","../src/directory.ts"],"names":["currentTime","Math","floor","Date","now","generateCode","digits","min","pow","max","random","hexToNumber","hex","TypeError","normalized","replace","test","Error","converted","parseInt","Number","isNaN","ordinal","n","s","v","index","suffix","percentage","num1","num2","toFixed","round","num","precision","factor","EPSILON","roundToDenomination","opts","suffixes","toString","temp","length","result","adjustedTemp","endsWith","ceil","substring","capitalize","word","charAt","toUpperCase","slice","toLowerCase","longestStringLength","arr","map","el","generateAsciiTable","data","firstRow","table","columnWidths","i","maxWidth","row","cell","undefined","push","createLine","char","left","intersect","right","line","forEach","width","repeat","rowIndex","columnIndex","columnWidth","padEnd","prettify","key","trim","prettyDifference","numBefore","numAfter","fyShuffle","items","array","j","isTsOrJsFile","entry","isFile","name","traverseDirectory","dir","callback","logger","entries","readdir","withFileTypes","error","fullPath","join","relativePath","relative","process","cwd","isDirectory","imported"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGO,SAASA,WAAAA,GAAAA;AACd,EAAA,OAAOC,IAAAA,CAAKC,KAAAA,CAAMC,IAAAA,CAAKC,GAAAA,KAAQ,GAAA,CAAA;AACjC;AAFgBJ,MAAAA,CAAAA,WAAAA,EAAAA,aAAAA,CAAAA;;;ACGT,SAASK,aAAaC,MAAAA,EAAc;AACzC,EAAA,MAAMC,GAAAA,GAAMN,IAAAA,CAAKO,GAAAA,CAAI,EAAA,EAAIF,SAAS,CAAA,CAAA;AAClC,EAAA,MAAMG,GAAAA,GAAMR,IAAAA,CAAKO,GAA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AAAA,CAAaC,KAAAA,CAAAA,EAAQ;AAC9B,MAAA,MAAMkB,QAAAA,GAAY,MAAM,OAAOP,QAAAA,CAAAA;AAC/B,MAAA,MAAMN,QAAAA,CAASM,QAAAA,EAAUE,YAAAA,EAAcK,QAAAA,CAAAA;AACzC,IAAA;AACF,EAAA;AACF;AAzBsBf,MAAAA,CAAAA,iBAAAA,EAAAA,mBAAAA,CAAAA","file":"index.cjs","sourcesContent":["/**\n * Return current time in seconds\n */\nexport function currentTime(): number {\n return Math.floor(Date.now() / 1000);\n}\n","/**\n * Generates a random numeric code with the specified number of digits.\n *\n * @param digits - The number of digits for the generated code.\n * @returns A random numeric code with the specified number of digits.\n */\nexport function generateCode(digits: number): number {\n const min = Math.pow(10, digits - 1);\n const max = Math.pow(10, digits) - 1;\n return Math.floor(Math.random() * (max - min + 1) + min);\n}\n","/**\n * Converts hexcode to number\n *\n * @param hex - The hex code to convert.\n * @returns The converted number.\n */\nexport function hexToNumber(hex: string): number {\n if (typeof hex !== 'string') {\n throw new TypeError('hexToNumber expects a string input');\n }\n\n const normalized = hex.replace(/^#/, '');\n if (!/^[0-9a-fA-F]+$/.test(normalized)) {\n throw new Error('Invalid hex string');\n }\n\n const converted = parseInt(normalized, 16);\n if (Number.isNaN(converted)) {\n throw new Error('Invalid hex string');\n }\n\n return converted;\n}\n","/**\n * Returns the ordinal suffix for a given number.\n *\n * @param n - The number to get the ordinal for\n * @returns The number with its ordinal suffix\n *\n * @example\n * ordinal(1); // \"1st\"\n * ordinal(22); // \"22nd\"\n * ordinal(13); // \"13th\"\n */\nexport function ordinal(n: number): string {\n const s = ['th', 'st', 'nd', 'rd'];\n const v = n % 100;\n const index = (v - 20) % 10;\n const suffix = s[index] ?? s[v] ?? s[0];\n if (!suffix) return `${n}th`;\n\n return `${n}${suffix}`;\n}\n","/**\n * Takes two numbers and returns the percentage of the first number in the second number with two decimal places.\n *\n * @param num1 - The first number.\n * @param num2 - The second number.\n *\n * @returns The percentage of the first number in the second number with two decimal places.\n */\n\nexport function percentage(num1: number, num2: number): number {\n return Number(((num1 / num2) * 100).toFixed(2));\n}\n","/**\n * Rounds a number to a specified number of decimal places.\n *\n * @param num - The number to be rounded.\n * @param precision - The number of decimal places to round to.\n * @returns The rounded number.\n */\n\nexport function round(num: number, precision: number): number {\n const factor = Math.pow(10, precision);\n return Math.round((num + Number.EPSILON) * factor) / factor;\n}\n","import type { TupleOf } from '@seedcord/types';\n\n/**\n * Rounds a number to a string representation with a denomination suffix.\n * @param num - The number to round.\n * @example\n * ```ts\n * roundToDenomination(1234); // \"1.2K\"\n * roundToDenomination(10000, ['k', 'm', 'b', 't', 'q']); // \"10k\"\n * roundToDenomination(12345678); // \"12.3M\"\n * ```\n * @returns The rounded number as a string with a denomination suffix.\n */\nexport function roundToDenomination(\n num: number,\n opts?: {\n suffixes?: TupleOf<string, 5>;\n precision?: number;\n }\n): string {\n const { suffixes = ['K', 'M', 'B', 'T', 'Q'], precision = 1 } = opts ?? {};\n\n if (num < 10000) {\n return num.toString();\n }\n\n let index = -1;\n let temp = num;\n\n while (temp >= 1000 && index < suffixes.length - 1) {\n temp /= 1000;\n index++;\n }\n\n let result;\n\n if (temp % 1 === 0) {\n result = temp.toString();\n } else {\n const adjustedTemp = Math.round(temp * Math.pow(10, precision + 1)) / Math.pow(10, precision + 1);\n result = adjustedTemp.toFixed(precision);\n }\n\n if (result.endsWith('.9')) {\n result = Math.ceil(Number(result)).toString();\n }\n\n if (result.endsWith('.0')) {\n result = result.substring(0, result.length - 2);\n }\n\n if (result === '1000') {\n index += 1;\n result = '1';\n }\n\n return result + (index >= 0 ? suffixes[index] : '');\n}\n","/**\n * Returns the word with it's first letter capitalized and the rest in lowercase.\n * @param word - The word to be formatted.\n * @returns The formatted word.\n */\nexport function capitalize(word: string): string {\n return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();\n}\n","/**\n * Function takes an array of strings or numbers and returns the number of characters in the longest string/number\n *\n * @param arr - The array of strings or numbers\n * @returns The length of the longest element when converted to string\n */\n\nexport function longestStringLength(arr: (string | number)[]): number {\n return Math.max(...arr.map((el) => el.toString().length));\n}\n","/**\n * Generates an ASCII table from the provided data.\n *\n * @param data - The data to be displayed in the table.\n * @returns The generated ASCII table as a string.\n */\n\nexport function generateAsciiTable(data: string[][]): string {\n if (data.length === 0) return '';\n\n const firstRow = data[0];\n if (!firstRow || firstRow.length === 0) return '';\n\n let table = '';\n const columnWidths: number[] = [];\n\n // Determine the maximum width for each column\n for (let i = 0; i < firstRow.length; i++) {\n let maxWidth = 0;\n for (const row of data) {\n const cell = row[i];\n if (cell !== undefined) maxWidth = Math.max(maxWidth, cell.length);\n }\n columnWidths.push(maxWidth);\n }\n\n // Function to create a horizontal line\n const createLine = (char: string, left: string, intersect: string, right: string): string => {\n let line = left;\n columnWidths.forEach((width, index) => {\n line += char.repeat(width + 2);\n if (index < columnWidths.length - 1) line += intersect;\n else line += right;\n });\n line += '\\n';\n return line;\n };\n\n // Top border\n table += createLine('═', '╔', '╦', '╗');\n\n data.forEach((row, rowIndex) => {\n // Row content\n table += '║';\n row.forEach((cell, columnIndex) => {\n const columnWidth = columnWidths[columnIndex];\n if (columnWidth !== undefined) table += ` ${cell.padEnd(columnWidth)} ║`;\n });\n table += '\\n';\n\n // Separator or bottom border\n if (rowIndex < data.length - 1) table += createLine('─', '╠', '╬', '╣');\n else table += createLine('═', '╚', '╩', '╝');\n });\n\n return table;\n}\n","import { capitalize } from './capitalize';\n\ninterface PrettifyOptions {\n capitalize?: boolean;\n}\n/**\n * Converts a string from any common naming convention to human-readable format.\n * Handles camelCase, PascalCase, snake_case, and kebab-case.\n *\n * @param key - The string to convert\n * @param opts - Optional configuration\n * @returns A space-separated, human-readable string\n *\n * @example\n * prettify(\"camelCaseString\") // \"camel Case String\"\n * prettify(\"PascalCaseString\") // \"Pascal Case String\"\n * prettify(\"snake_case_string\") // \"snake case string\"\n * prettify(\"kebab-case-string\") // \"kebab case string\"\n * prettify(\"mixedCase_string-name\") // \"mixed Case string name\"\n */\n\nexport function prettify(key: string, opts?: PrettifyOptions): string {\n const result = key\n .replace(/([a-z])([A-Z])/g, '$1 $2') // camelCase/PascalCase\n .replace(/[_-]/g, ' ') // snake_case and kebab-case\n .trim();\n\n if (opts?.capitalize) return capitalize(result);\n\n return result;\n}\n","/**\n * Calculates the difference between two numbers and formats it as a string with a '+' prefix for positive differences.\n *\n * @param numBefore - The initial number value\n * @param numAfter - The final number value\n * @returns A string representing the difference, with a '+' sign for positive differences\n *\n * @example\n * // Returns \"+5\"\n * prettyDifference(10, 15);\n *\n * @example\n * // Returns \"-3\"\n * prettyDifference(10, 7);\n */\n\nexport function prettyDifference(numBefore: number, numAfter: number): string {\n return (numAfter - numBefore > 0 ? `+${numAfter - numBefore}` : numAfter - numBefore).toString();\n}\n","/**\n * Shuffles an array using the Fisher-Yates algorithm.\n * This function creates a new array with the same elements in a random order,\n * without modifying the original array.\n *\n * @typeParam TArray - The type of elements in the array\n * @param items - The array to shuffle\n * @returns A new array with the same elements in a random order\n *\n * @example\n * ```typescript\n * const numbers = [1, 2, 3, 4, 5];\n * const shuffled = fyShuffle(numbers);\n * // shuffled might be [3, 1, 5, 2, 4]\n * // numbers is still [1, 2, 3, 4, 5]\n * ```\n */\nexport function fyShuffle<TArray>(items: TArray[]): TArray[] {\n const array = items.slice();\n for (let i = array.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n // @ts-expect-error - TypeScript doesn't recognize that TArray can be swapped\n [array[i], array[j]] = [array[j], array[i]];\n }\n return array;\n}\n","import { readdir } from 'node:fs/promises';\nimport * as path from 'node:path';\n\nimport type { Logger } from '@seedcord/services';\nimport type * as fs from 'node:fs';\n/**\n * Determines if a directory entry is a TypeScript or JavaScript file.\n *\n * @param entry - The directory entry to check.\n * @returns True if the entry is a file ending with .ts or .js.\n */\nexport function isTsOrJsFile(entry: fs.Dirent): boolean {\n return (\n entry.isFile() &&\n (entry.name.endsWith('.ts') || entry.name.endsWith('.js')) &&\n !entry.name.endsWith('.d.ts') &&\n !entry.name.endsWith('.map')\n );\n}\n\n/**\n * Recursively traverses through a directory, importing all .ts and .js files and applying a callback to each import.\n *\n * @param dir - The directory path to traverse.\n * @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.\n * @returns A Promise that resolves when the traversal is complete.\n */\nexport async function traverseDirectory(\n dir: string,\n callback: (fullPath: string, relativePath: string, imported: Record<string, unknown>) => Promise<void> | void,\n logger: Logger\n): Promise<void> {\n let entries: fs.Dirent[];\n\n try {\n entries = await readdir(dir, { withFileTypes: true });\n } catch {\n logger.error('Failed to read this directory');\n entries = [];\n }\n\n for (const entry of entries) {\n const fullPath = path.join(dir, entry.name);\n const relativePath = path.relative(process.cwd(), fullPath);\n\n if (entry.isDirectory()) {\n await traverseDirectory(fullPath, callback, logger);\n } else if (isTsOrJsFile(entry)) {\n const imported = (await import(fullPath)) as Record<string, unknown>;\n await callback(fullPath, relativePath, imported);\n }\n }\n}\n"]}
@@ -0,0 +1,169 @@
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 };
@@ -0,0 +1,169 @@
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 };
@@ -0,0 +1,169 @@
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 };
package/dist/index.mjs ADDED
@@ -0,0 +1,214 @@
1
+ import { readdir } from 'fs/promises';
2
+ import * as path from 'path';
3
+
4
+ var __defProp = Object.defineProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+
7
+ // src/numbers/currentTime.ts
8
+ function currentTime() {
9
+ return Math.floor(Date.now() / 1e3);
10
+ }
11
+ __name(currentTime, "currentTime");
12
+
13
+ // src/numbers/generateCode.ts
14
+ function generateCode(digits) {
15
+ const min = Math.pow(10, digits - 1);
16
+ const max = Math.pow(10, digits) - 1;
17
+ return Math.floor(Math.random() * (max - min + 1) + min);
18
+ }
19
+ __name(generateCode, "generateCode");
20
+
21
+ // src/numbers/hexToNumber.ts
22
+ function hexToNumber(hex) {
23
+ if (typeof hex !== "string") {
24
+ throw new TypeError("hexToNumber expects a string input");
25
+ }
26
+ const normalized = hex.replace(/^#/, "");
27
+ if (!/^[0-9a-fA-F]+$/.test(normalized)) {
28
+ throw new Error("Invalid hex string");
29
+ }
30
+ const converted = parseInt(normalized, 16);
31
+ if (Number.isNaN(converted)) {
32
+ throw new Error("Invalid hex string");
33
+ }
34
+ return converted;
35
+ }
36
+ __name(hexToNumber, "hexToNumber");
37
+
38
+ // src/numbers/ordinal.ts
39
+ function ordinal(n) {
40
+ const s = [
41
+ "th",
42
+ "st",
43
+ "nd",
44
+ "rd"
45
+ ];
46
+ const v = n % 100;
47
+ const index = (v - 20) % 10;
48
+ const suffix = s[index] ?? s[v] ?? s[0];
49
+ if (!suffix) return `${n}th`;
50
+ return `${n}${suffix}`;
51
+ }
52
+ __name(ordinal, "ordinal");
53
+
54
+ // src/numbers/percentage.ts
55
+ function percentage(num1, num2) {
56
+ return Number((num1 / num2 * 100).toFixed(2));
57
+ }
58
+ __name(percentage, "percentage");
59
+
60
+ // src/numbers/round.ts
61
+ function round(num, precision) {
62
+ const factor = Math.pow(10, precision);
63
+ return Math.round((num + Number.EPSILON) * factor) / factor;
64
+ }
65
+ __name(round, "round");
66
+
67
+ // src/numbers/roundToDenomination.ts
68
+ function roundToDenomination(num, opts) {
69
+ const { suffixes = [
70
+ "K",
71
+ "M",
72
+ "B",
73
+ "T",
74
+ "Q"
75
+ ], precision = 1 } = opts ?? {};
76
+ if (num < 1e4) {
77
+ return num.toString();
78
+ }
79
+ let index = -1;
80
+ let temp = num;
81
+ while (temp >= 1e3 && index < suffixes.length - 1) {
82
+ temp /= 1e3;
83
+ index++;
84
+ }
85
+ let result;
86
+ if (temp % 1 === 0) {
87
+ result = temp.toString();
88
+ } else {
89
+ const adjustedTemp = Math.round(temp * Math.pow(10, precision + 1)) / Math.pow(10, precision + 1);
90
+ result = adjustedTemp.toFixed(precision);
91
+ }
92
+ if (result.endsWith(".9")) {
93
+ result = Math.ceil(Number(result)).toString();
94
+ }
95
+ if (result.endsWith(".0")) {
96
+ result = result.substring(0, result.length - 2);
97
+ }
98
+ if (result === "1000") {
99
+ index += 1;
100
+ result = "1";
101
+ }
102
+ return result + (index >= 0 ? suffixes[index] : "");
103
+ }
104
+ __name(roundToDenomination, "roundToDenomination");
105
+
106
+ // src/strings/capitalize.ts
107
+ function capitalize(word) {
108
+ return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
109
+ }
110
+ __name(capitalize, "capitalize");
111
+
112
+ // src/strings/longestStringLength.ts
113
+ function longestStringLength(arr) {
114
+ return Math.max(...arr.map((el) => el.toString().length));
115
+ }
116
+ __name(longestStringLength, "longestStringLength");
117
+
118
+ // src/strings/generateAsciiTable.ts
119
+ function generateAsciiTable(data) {
120
+ if (data.length === 0) return "";
121
+ const firstRow = data[0];
122
+ if (!firstRow || firstRow.length === 0) return "";
123
+ let table = "";
124
+ const columnWidths = [];
125
+ for (let i = 0; i < firstRow.length; i++) {
126
+ let maxWidth = 0;
127
+ for (const row of data) {
128
+ const cell = row[i];
129
+ if (cell !== void 0) maxWidth = Math.max(maxWidth, cell.length);
130
+ }
131
+ columnWidths.push(maxWidth);
132
+ }
133
+ const createLine = /* @__PURE__ */ __name((char, left, intersect, right) => {
134
+ let line = left;
135
+ columnWidths.forEach((width, index) => {
136
+ line += char.repeat(width + 2);
137
+ if (index < columnWidths.length - 1) line += intersect;
138
+ else line += right;
139
+ });
140
+ line += "\n";
141
+ return line;
142
+ }, "createLine");
143
+ table += createLine("\u2550", "\u2554", "\u2566", "\u2557");
144
+ data.forEach((row, rowIndex) => {
145
+ table += "\u2551";
146
+ row.forEach((cell, columnIndex) => {
147
+ const columnWidth = columnWidths[columnIndex];
148
+ if (columnWidth !== void 0) table += ` ${cell.padEnd(columnWidth)} \u2551`;
149
+ });
150
+ table += "\n";
151
+ if (rowIndex < data.length - 1) table += createLine("\u2500", "\u2560", "\u256C", "\u2563");
152
+ else table += createLine("\u2550", "\u255A", "\u2569", "\u255D");
153
+ });
154
+ return table;
155
+ }
156
+ __name(generateAsciiTable, "generateAsciiTable");
157
+
158
+ // src/strings/prettify.ts
159
+ function prettify(key, opts) {
160
+ const result = key.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[_-]/g, " ").trim();
161
+ if (opts?.capitalize) return capitalize(result);
162
+ return result;
163
+ }
164
+ __name(prettify, "prettify");
165
+
166
+ // src/strings/prettyDifference.ts
167
+ function prettyDifference(numBefore, numAfter) {
168
+ return (numAfter - numBefore > 0 ? `+${numAfter - numBefore}` : numAfter - numBefore).toString();
169
+ }
170
+ __name(prettyDifference, "prettyDifference");
171
+
172
+ // src/fyShuffle.ts
173
+ function fyShuffle(items) {
174
+ const array = items.slice();
175
+ for (let i = array.length - 1; i > 0; i--) {
176
+ const j = Math.floor(Math.random() * (i + 1));
177
+ [array[i], array[j]] = [
178
+ array[j],
179
+ array[i]
180
+ ];
181
+ }
182
+ return array;
183
+ }
184
+ __name(fyShuffle, "fyShuffle");
185
+ function isTsOrJsFile(entry) {
186
+ return entry.isFile() && (entry.name.endsWith(".ts") || entry.name.endsWith(".js")) && !entry.name.endsWith(".d.ts") && !entry.name.endsWith(".map");
187
+ }
188
+ __name(isTsOrJsFile, "isTsOrJsFile");
189
+ async function traverseDirectory(dir, callback, logger) {
190
+ let entries;
191
+ try {
192
+ entries = await readdir(dir, {
193
+ withFileTypes: true
194
+ });
195
+ } catch {
196
+ logger.error("Failed to read this directory");
197
+ entries = [];
198
+ }
199
+ for (const entry of entries) {
200
+ const fullPath = path.join(dir, entry.name);
201
+ const relativePath = path.relative(process.cwd(), fullPath);
202
+ if (entry.isDirectory()) {
203
+ await traverseDirectory(fullPath, callback, logger);
204
+ } else if (isTsOrJsFile(entry)) {
205
+ const imported = await import(fullPath);
206
+ await callback(fullPath, relativePath, imported);
207
+ }
208
+ }
209
+ }
210
+ __name(traverseDirectory, "traverseDirectory");
211
+
212
+ export { capitalize, currentTime, fyShuffle, generateAsciiTable, generateCode, hexToNumber, isTsOrJsFile, longestStringLength, ordinal, percentage, prettify, prettyDifference, round, roundToDenomination, traverseDirectory };
213
+ //# sourceMappingURL=index.mjs.map
214
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/numbers/currentTime.ts","../src/numbers/generateCode.ts","../src/numbers/hexToNumber.ts","../src/numbers/ordinal.ts","../src/numbers/percentage.ts","../src/numbers/round.ts","../src/numbers/roundToDenomination.ts","../src/strings/capitalize.ts","../src/strings/longestStringLength.ts","../src/strings/generateAsciiTable.ts","../src/strings/prettify.ts","../src/strings/prettyDifference.ts","../src/fyShuffle.ts","../src/directory.ts"],"names":["currentTime","Math","floor","Date","now","generateCode","digits","min","pow","max","random","hexToNumber","hex","TypeError","normalized","replace","test","Error","converted","parseInt","Number","isNaN","ordinal","n","s","v","index","suffix","percentage","num1","num2","toFixed","round","num","precision","factor","EPSILON","roundToDenomination","opts","suffixes","toString","temp","length","result","adjustedTemp","endsWith","ceil","substring","capitalize","word","charAt","toUpperCase","slice","toLowerCase","longestStringLength","arr","map","el","generateAsciiTable","data","firstRow","table","columnWidths","i","maxWidth","row","cell","undefined","push","createLine","char","left","intersect","right","line","forEach","width","repeat","rowIndex","columnIndex","columnWidth","padEnd","prettify","key","trim","prettyDifference","numBefore","numAfter","fyShuffle","items","array","j","isTsOrJsFile","entry","isFile","name","traverseDirectory","dir","callback","logger","entries","readdir","withFileTypes","error","fullPath","join","relativePath","relative","process","cwd","isDirectory","imported"],"mappings":";;;;;;;AAGO,SAASA,WAAAA,GAAAA;AACd,EAAA,OAAOC,IAAAA,CAAKC,KAAAA,CAAMC,IAAAA,CAAKC,GAAAA,KAAQ,GAAA,CAAA;AACjC;AAFgBJ,MAAAA,CAAAA,WAAAA,EAAAA,aAAAA,CAAAA;;;ACGT,SAASK,aAAaC,MAAAA,EAAc;AACzC,EAAA,MAAMC,GAAAA,GAAMN,IAAAA,CAAKO,GAAAA,CAAI,EAAA,EAAIF,SAAS,CAAA,CAAA;AAClC,EAAA,MAAMG,GAAAA,GAA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CAAA,MAAA,IAAWP,YAAAA,CAAaC,KAAAA,CAAAA,EAAQ;AAC9B,MAAA,MAAMkB,QAAAA,GAAY,MAAM,OAAOP,QAAAA,CAAAA;AAC/B,MAAA,MAAMN,QAAAA,CAASM,QAAAA,EAAUE,YAAAA,EAAcK,QAAAA,CAAAA;AACzC,IAAA;AACF,EAAA;AACF;AAzBsBf,MAAAA,CAAAA,iBAAAA,EAAAA,mBAAAA,CAAAA","file":"index.mjs","sourcesContent":["/**\n * Return current time in seconds\n */\nexport function currentTime(): number {\n return Math.floor(Date.now() / 1000);\n}\n","/**\n * Generates a random numeric code with the specified number of digits.\n *\n * @param digits - The number of digits for the generated code.\n * @returns A random numeric code with the specified number of digits.\n */\nexport function generateCode(digits: number): number {\n const min = Math.pow(10, digits - 1);\n const max = Math.pow(10, digits) - 1;\n return Math.floor(Math.random() * (max - min + 1) + min);\n}\n","/**\n * Converts hexcode to number\n *\n * @param hex - The hex code to convert.\n * @returns The converted number.\n */\nexport function hexToNumber(hex: string): number {\n if (typeof hex !== 'string') {\n throw new TypeError('hexToNumber expects a string input');\n }\n\n const normalized = hex.replace(/^#/, '');\n if (!/^[0-9a-fA-F]+$/.test(normalized)) {\n throw new Error('Invalid hex string');\n }\n\n const converted = parseInt(normalized, 16);\n if (Number.isNaN(converted)) {\n throw new Error('Invalid hex string');\n }\n\n return converted;\n}\n","/**\n * Returns the ordinal suffix for a given number.\n *\n * @param n - The number to get the ordinal for\n * @returns The number with its ordinal suffix\n *\n * @example\n * ordinal(1); // \"1st\"\n * ordinal(22); // \"22nd\"\n * ordinal(13); // \"13th\"\n */\nexport function ordinal(n: number): string {\n const s = ['th', 'st', 'nd', 'rd'];\n const v = n % 100;\n const index = (v - 20) % 10;\n const suffix = s[index] ?? s[v] ?? s[0];\n if (!suffix) return `${n}th`;\n\n return `${n}${suffix}`;\n}\n","/**\n * Takes two numbers and returns the percentage of the first number in the second number with two decimal places.\n *\n * @param num1 - The first number.\n * @param num2 - The second number.\n *\n * @returns The percentage of the first number in the second number with two decimal places.\n */\n\nexport function percentage(num1: number, num2: number): number {\n return Number(((num1 / num2) * 100).toFixed(2));\n}\n","/**\n * Rounds a number to a specified number of decimal places.\n *\n * @param num - The number to be rounded.\n * @param precision - The number of decimal places to round to.\n * @returns The rounded number.\n */\n\nexport function round(num: number, precision: number): number {\n const factor = Math.pow(10, precision);\n return Math.round((num + Number.EPSILON) * factor) / factor;\n}\n","import type { TupleOf } from '@seedcord/types';\n\n/**\n * Rounds a number to a string representation with a denomination suffix.\n * @param num - The number to round.\n * @example\n * ```ts\n * roundToDenomination(1234); // \"1.2K\"\n * roundToDenomination(10000, ['k', 'm', 'b', 't', 'q']); // \"10k\"\n * roundToDenomination(12345678); // \"12.3M\"\n * ```\n * @returns The rounded number as a string with a denomination suffix.\n */\nexport function roundToDenomination(\n num: number,\n opts?: {\n suffixes?: TupleOf<string, 5>;\n precision?: number;\n }\n): string {\n const { suffixes = ['K', 'M', 'B', 'T', 'Q'], precision = 1 } = opts ?? {};\n\n if (num < 10000) {\n return num.toString();\n }\n\n let index = -1;\n let temp = num;\n\n while (temp >= 1000 && index < suffixes.length - 1) {\n temp /= 1000;\n index++;\n }\n\n let result;\n\n if (temp % 1 === 0) {\n result = temp.toString();\n } else {\n const adjustedTemp = Math.round(temp * Math.pow(10, precision + 1)) / Math.pow(10, precision + 1);\n result = adjustedTemp.toFixed(precision);\n }\n\n if (result.endsWith('.9')) {\n result = Math.ceil(Number(result)).toString();\n }\n\n if (result.endsWith('.0')) {\n result = result.substring(0, result.length - 2);\n }\n\n if (result === '1000') {\n index += 1;\n result = '1';\n }\n\n return result + (index >= 0 ? suffixes[index] : '');\n}\n","/**\n * Returns the word with it's first letter capitalized and the rest in lowercase.\n * @param word - The word to be formatted.\n * @returns The formatted word.\n */\nexport function capitalize(word: string): string {\n return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();\n}\n","/**\n * Function takes an array of strings or numbers and returns the number of characters in the longest string/number\n *\n * @param arr - The array of strings or numbers\n * @returns The length of the longest element when converted to string\n */\n\nexport function longestStringLength(arr: (string | number)[]): number {\n return Math.max(...arr.map((el) => el.toString().length));\n}\n","/**\n * Generates an ASCII table from the provided data.\n *\n * @param data - The data to be displayed in the table.\n * @returns The generated ASCII table as a string.\n */\n\nexport function generateAsciiTable(data: string[][]): string {\n if (data.length === 0) return '';\n\n const firstRow = data[0];\n if (!firstRow || firstRow.length === 0) return '';\n\n let table = '';\n const columnWidths: number[] = [];\n\n // Determine the maximum width for each column\n for (let i = 0; i < firstRow.length; i++) {\n let maxWidth = 0;\n for (const row of data) {\n const cell = row[i];\n if (cell !== undefined) maxWidth = Math.max(maxWidth, cell.length);\n }\n columnWidths.push(maxWidth);\n }\n\n // Function to create a horizontal line\n const createLine = (char: string, left: string, intersect: string, right: string): string => {\n let line = left;\n columnWidths.forEach((width, index) => {\n line += char.repeat(width + 2);\n if (index < columnWidths.length - 1) line += intersect;\n else line += right;\n });\n line += '\\n';\n return line;\n };\n\n // Top border\n table += createLine('═', '╔', '╦', '╗');\n\n data.forEach((row, rowIndex) => {\n // Row content\n table += '║';\n row.forEach((cell, columnIndex) => {\n const columnWidth = columnWidths[columnIndex];\n if (columnWidth !== undefined) table += ` ${cell.padEnd(columnWidth)} ║`;\n });\n table += '\\n';\n\n // Separator or bottom border\n if (rowIndex < data.length - 1) table += createLine('─', '╠', '╬', '╣');\n else table += createLine('═', '╚', '╩', '╝');\n });\n\n return table;\n}\n","import { capitalize } from './capitalize';\n\ninterface PrettifyOptions {\n capitalize?: boolean;\n}\n/**\n * Converts a string from any common naming convention to human-readable format.\n * Handles camelCase, PascalCase, snake_case, and kebab-case.\n *\n * @param key - The string to convert\n * @param opts - Optional configuration\n * @returns A space-separated, human-readable string\n *\n * @example\n * prettify(\"camelCaseString\") // \"camel Case String\"\n * prettify(\"PascalCaseString\") // \"Pascal Case String\"\n * prettify(\"snake_case_string\") // \"snake case string\"\n * prettify(\"kebab-case-string\") // \"kebab case string\"\n * prettify(\"mixedCase_string-name\") // \"mixed Case string name\"\n */\n\nexport function prettify(key: string, opts?: PrettifyOptions): string {\n const result = key\n .replace(/([a-z])([A-Z])/g, '$1 $2') // camelCase/PascalCase\n .replace(/[_-]/g, ' ') // snake_case and kebab-case\n .trim();\n\n if (opts?.capitalize) return capitalize(result);\n\n return result;\n}\n","/**\n * Calculates the difference between two numbers and formats it as a string with a '+' prefix for positive differences.\n *\n * @param numBefore - The initial number value\n * @param numAfter - The final number value\n * @returns A string representing the difference, with a '+' sign for positive differences\n *\n * @example\n * // Returns \"+5\"\n * prettyDifference(10, 15);\n *\n * @example\n * // Returns \"-3\"\n * prettyDifference(10, 7);\n */\n\nexport function prettyDifference(numBefore: number, numAfter: number): string {\n return (numAfter - numBefore > 0 ? `+${numAfter - numBefore}` : numAfter - numBefore).toString();\n}\n","/**\n * Shuffles an array using the Fisher-Yates algorithm.\n * This function creates a new array with the same elements in a random order,\n * without modifying the original array.\n *\n * @typeParam TArray - The type of elements in the array\n * @param items - The array to shuffle\n * @returns A new array with the same elements in a random order\n *\n * @example\n * ```typescript\n * const numbers = [1, 2, 3, 4, 5];\n * const shuffled = fyShuffle(numbers);\n * // shuffled might be [3, 1, 5, 2, 4]\n * // numbers is still [1, 2, 3, 4, 5]\n * ```\n */\nexport function fyShuffle<TArray>(items: TArray[]): TArray[] {\n const array = items.slice();\n for (let i = array.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n // @ts-expect-error - TypeScript doesn't recognize that TArray can be swapped\n [array[i], array[j]] = [array[j], array[i]];\n }\n return array;\n}\n","import { readdir } from 'node:fs/promises';\nimport * as path from 'node:path';\n\nimport type { Logger } from '@seedcord/services';\nimport type * as fs from 'node:fs';\n/**\n * Determines if a directory entry is a TypeScript or JavaScript file.\n *\n * @param entry - The directory entry to check.\n * @returns True if the entry is a file ending with .ts or .js.\n */\nexport function isTsOrJsFile(entry: fs.Dirent): boolean {\n return (\n entry.isFile() &&\n (entry.name.endsWith('.ts') || entry.name.endsWith('.js')) &&\n !entry.name.endsWith('.d.ts') &&\n !entry.name.endsWith('.map')\n );\n}\n\n/**\n * Recursively traverses through a directory, importing all .ts and .js files and applying a callback to each import.\n *\n * @param dir - The directory path to traverse.\n * @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.\n * @returns A Promise that resolves when the traversal is complete.\n */\nexport async function traverseDirectory(\n dir: string,\n callback: (fullPath: string, relativePath: string, imported: Record<string, unknown>) => Promise<void> | void,\n logger: Logger\n): Promise<void> {\n let entries: fs.Dirent[];\n\n try {\n entries = await readdir(dir, { withFileTypes: true });\n } catch {\n logger.error('Failed to read this directory');\n entries = [];\n }\n\n for (const entry of entries) {\n const fullPath = path.join(dir, entry.name);\n const relativePath = path.relative(process.cwd(), fullPath);\n\n if (entry.isDirectory()) {\n await traverseDirectory(fullPath, callback, logger);\n } else if (isTsOrJsFile(entry)) {\n const imported = (await import(fullPath)) as Record<string, unknown>;\n await callback(fullPath, relativePath, imported);\n }\n }\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@seedcord/utils",
3
+ "type": "module",
4
+ "version": "0.1.0",
5
+ "description": "Utility functions for Seedcord packages",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/materwelondhruv/seedcord.git",
9
+ "directory": "packages/utils"
10
+ },
11
+ "exports": {
12
+ ".": {
13
+ "import": {
14
+ "types": "./dist/index.d.mts",
15
+ "default": "./dist/index.mjs"
16
+ },
17
+ "require": {
18
+ "types": "./dist/index.d.cts",
19
+ "default": "./dist/index.cjs"
20
+ }
21
+ }
22
+ },
23
+ "files": [
24
+ "dist",
25
+ "package.json",
26
+ "README.md",
27
+ "LICENSE"
28
+ ],
29
+ "peerDependencies": {
30
+ "typescript": "5.9.2"
31
+ },
32
+ "dependencies": {
33
+ "discord.js": "14.22.1",
34
+ "@seedcord/services": "^0.1.0",
35
+ "@seedcord/types": "^0.1.2"
36
+ },
37
+ "devDependencies": {
38
+ "@seedcord/eslint-config": "^1.1.1",
39
+ "@seedcord/tsup-config": "^1.0.2",
40
+ "@seedcord/tsconfig": "^1.0.2"
41
+ },
42
+ "scripts": {
43
+ "build": "tsup && cp dist/index.d.cts dist/index.d.mts",
44
+ "clean": "rm -rf dist",
45
+ "lint": "eslint 'src/**/*.{ts,tsx}' --cache",
46
+ "lint:fix": "eslint 'src/**/*.{ts,tsx}' --fix --cache",
47
+ "fmt": "prettier --write 'src/**/*.{ts,tsx,json,md}' --cache",
48
+ "fmt:check": "prettier --check 'src/**/*.{ts,tsx,json,md}' --cache",
49
+ "tc": "tsc --noEmit",
50
+ "test": "vitest run",
51
+ "test:watch": "vitest dev",
52
+ "coverage": "vitest run --coverage"
53
+ }
54
+ }