@20syldev/api 4.7.0 → 4.9.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.
Files changed (191) hide show
  1. package/README.md +84 -47
  2. package/dist/app.js +6 -6
  3. package/dist/app.js.map +1 -1
  4. package/dist/config/env.js.map +1 -1
  5. package/dist/config/versions.js +22 -3
  6. package/dist/config/versions.js.map +1 -1
  7. package/dist/constants.js +27 -12
  8. package/dist/constants.js.map +1 -1
  9. package/dist/middleware/error.js +2 -2
  10. package/dist/middleware/error.js.map +1 -1
  11. package/dist/middleware/logger.js.map +1 -1
  12. package/dist/middleware/ratelimit.js +2 -2
  13. package/dist/middleware/ratelimit.js.map +1 -1
  14. package/dist/middleware/version.js.map +1 -1
  15. package/dist/modules/v3.js +1 -1
  16. package/dist/modules/v3.js.map +1 -1
  17. package/{src/modules/v4/address.ts → dist/modules/v4/address.js} +14 -46
  18. package/dist/modules/v4/address.js.map +1 -0
  19. package/{src/modules/v4/agent.ts → dist/modules/v4/agent.js} +26 -38
  20. package/dist/modules/v4/agent.js.map +1 -0
  21. package/dist/modules/v4/algorithms.js +79 -0
  22. package/dist/modules/v4/algorithms.js.map +1 -1
  23. package/dist/modules/v4/avatar.js +136 -0
  24. package/dist/modules/v4/avatar.js.map +1 -0
  25. package/dist/modules/v4/barcode.js +440 -0
  26. package/dist/modules/v4/barcode.js.map +1 -0
  27. package/dist/modules/v4/captcha.js +7 -0
  28. package/dist/modules/v4/captcha.js.map +1 -1
  29. package/dist/modules/v4/chat.js +9 -1
  30. package/dist/modules/v4/chat.js.map +1 -1
  31. package/dist/modules/v4/color.js +8 -1
  32. package/dist/modules/v4/color.js.map +1 -1
  33. package/dist/modules/v4/convert.js +9 -0
  34. package/dist/modules/v4/convert.js.map +1 -1
  35. package/dist/modules/v4/credit.js +104 -0
  36. package/dist/modules/v4/credit.js.map +1 -0
  37. package/dist/modules/v4/cron.js +202 -0
  38. package/dist/modules/v4/cron.js.map +1 -0
  39. package/dist/modules/v4/dice.js +7 -0
  40. package/dist/modules/v4/dice.js.map +1 -1
  41. package/dist/modules/v4/domain.js +6 -1
  42. package/dist/modules/v4/domain.js.map +1 -1
  43. package/dist/modules/v4/encode.js +71 -0
  44. package/dist/modules/v4/encode.js.map +1 -1
  45. package/dist/modules/v4/geo.js +11 -1
  46. package/dist/modules/v4/geo.js.map +1 -1
  47. package/dist/modules/v4/hash.js +10 -1
  48. package/dist/modules/v4/hash.js.map +1 -1
  49. package/dist/modules/v4/hyperplanning.js +9 -1
  50. package/dist/modules/v4/hyperplanning.js.map +1 -1
  51. package/{src/modules/v4/ip.ts → dist/modules/v4/ip.js} +58 -60
  52. package/dist/modules/v4/ip.js.map +1 -0
  53. package/dist/modules/v4/levenshtein.js +8 -0
  54. package/dist/modules/v4/levenshtein.js.map +1 -1
  55. package/dist/modules/v4/palette.js +9 -1
  56. package/dist/modules/v4/palette.js.map +1 -1
  57. package/{src/modules/v4/password.ts → dist/modules/v4/password.js} +25 -63
  58. package/dist/modules/v4/password.js.map +1 -0
  59. package/dist/modules/v4/personal.js +14 -18
  60. package/dist/modules/v4/personal.js.map +1 -1
  61. package/dist/modules/v4/placeholder.js +8 -0
  62. package/dist/modules/v4/placeholder.js.map +1 -1
  63. package/dist/modules/v4/qrcode.js +10 -3
  64. package/dist/modules/v4/qrcode.js.map +1 -1
  65. package/dist/modules/v4/regex.js +48 -0
  66. package/dist/modules/v4/regex.js.map +1 -0
  67. package/dist/modules/v4/statistics.js +7 -0
  68. package/dist/modules/v4/statistics.js.map +1 -1
  69. package/dist/modules/v4/text.js +30 -0
  70. package/dist/modules/v4/text.js.map +1 -1
  71. package/dist/modules/v4/tic_tac_toe.js +9 -1
  72. package/dist/modules/v4/tic_tac_toe.js.map +1 -1
  73. package/dist/modules/v4/time.js +62 -11
  74. package/dist/modules/v4/time.js.map +1 -1
  75. package/dist/modules/v4/token.js +17 -8
  76. package/dist/modules/v4/token.js.map +1 -1
  77. package/dist/modules/v4/username.js +5 -0
  78. package/dist/modules/v4/username.js.map +1 -1
  79. package/dist/modules/v4/validate.js +21 -0
  80. package/dist/modules/v4/validate.js.map +1 -1
  81. package/dist/modules/v4.js +10 -1
  82. package/dist/modules/v4.js.map +1 -1
  83. package/dist/routes/delete.js.map +1 -1
  84. package/dist/routes/get.js +208 -48
  85. package/dist/routes/get.js.map +1 -1
  86. package/dist/routes/index.js +2 -2
  87. package/dist/routes/index.js.map +1 -1
  88. package/dist/routes/patch.js.map +1 -1
  89. package/dist/routes/post.js +2 -2
  90. package/dist/routes/post.js.map +1 -1
  91. package/dist/utils/response.js.map +1 -1
  92. package/package.json +2 -1
  93. package/.github/FUNDING.yml +0 -1
  94. package/.prettierrc +0 -7
  95. package/eslint.config.js +0 -24
  96. package/robots.txt +0 -74
  97. package/src/app.ts +0 -53
  98. package/src/config/env.ts +0 -87
  99. package/src/config/plans.ts +0 -61
  100. package/src/config/versions.ts +0 -119
  101. package/src/constants.ts +0 -46
  102. package/src/favicon.ico +0 -0
  103. package/src/middleware/cors.ts +0 -23
  104. package/src/middleware/error.ts +0 -16
  105. package/src/middleware/json.ts +0 -9
  106. package/src/middleware/logger.ts +0 -32
  107. package/src/middleware/ratelimit.ts +0 -89
  108. package/src/middleware/version.ts +0 -40
  109. package/src/modules/v3/algorithms.js +0 -218
  110. package/src/modules/v3/captcha.js +0 -60
  111. package/src/modules/v3/chat.js +0 -111
  112. package/src/modules/v3/color.js +0 -60
  113. package/src/modules/v3/convert.js +0 -39
  114. package/src/modules/v3/domain.js +0 -86
  115. package/src/modules/v3/hash.js +0 -16
  116. package/src/modules/v3/hyperplanning.js +0 -56
  117. package/src/modules/v3/levenshtein.js +0 -46
  118. package/src/modules/v3/personal.js +0 -139
  119. package/src/modules/v3/qrcode.js +0 -20
  120. package/src/modules/v3/tic_tac_toe.js +0 -242
  121. package/src/modules/v3/time.js +0 -98
  122. package/src/modules/v3/token.js +0 -54
  123. package/src/modules/v3/username.js +0 -94
  124. package/src/modules/v3/utils.js +0 -77
  125. package/src/modules/v3.js +0 -15
  126. package/src/modules/v4/algorithms.ts +0 -276
  127. package/src/modules/v4/captcha.ts +0 -114
  128. package/src/modules/v4/chat.ts +0 -130
  129. package/src/modules/v4/color.ts +0 -75
  130. package/src/modules/v4/convert.ts +0 -127
  131. package/src/modules/v4/dice.ts +0 -46
  132. package/src/modules/v4/domain.ts +0 -86
  133. package/src/modules/v4/encode.ts +0 -241
  134. package/src/modules/v4/geo.ts +0 -63
  135. package/src/modules/v4/hash.ts +0 -32
  136. package/src/modules/v4/hyperplanning.ts +0 -93
  137. package/src/modules/v4/levenshtein.ts +0 -46
  138. package/src/modules/v4/palette.ts +0 -71
  139. package/src/modules/v4/personal.ts +0 -140
  140. package/src/modules/v4/placeholder.ts +0 -197
  141. package/src/modules/v4/qrcode.ts +0 -121
  142. package/src/modules/v4/statistics.ts +0 -62
  143. package/src/modules/v4/text.ts +0 -330
  144. package/src/modules/v4/tic_tac_toe.ts +0 -264
  145. package/src/modules/v4/time.ts +0 -103
  146. package/src/modules/v4/token.ts +0 -53
  147. package/src/modules/v4/username.ts +0 -94
  148. package/src/modules/v4/validate.ts +0 -76
  149. package/src/modules/v4.ts +0 -27
  150. package/src/routes/delete.ts +0 -72
  151. package/src/routes/get.ts +0 -835
  152. package/src/routes/index.ts +0 -59
  153. package/src/routes/patch.ts +0 -45
  154. package/src/routes/post.ts +0 -209
  155. package/src/storage/index.ts +0 -16
  156. package/src/types/express.d.ts +0 -17
  157. package/src/types/storage.ts +0 -48
  158. package/src/utils/colors.ts +0 -91
  159. package/src/utils/helpers.ts +0 -90
  160. package/src/utils/response.ts +0 -28
  161. package/tests/integration/api.test.ts +0 -716
  162. package/tests/tsconfig.json +0 -3
  163. package/tests/unit/address.test.ts +0 -84
  164. package/tests/unit/agent.test.ts +0 -113
  165. package/tests/unit/algorithms.test.ts +0 -121
  166. package/tests/unit/captcha.test.ts +0 -62
  167. package/tests/unit/chat.test.ts +0 -54
  168. package/tests/unit/color.test.ts +0 -54
  169. package/tests/unit/convert.test.ts +0 -68
  170. package/tests/unit/dice.test.ts +0 -58
  171. package/tests/unit/domain.test.ts +0 -48
  172. package/tests/unit/encode.test.ts +0 -109
  173. package/tests/unit/geo.test.ts +0 -46
  174. package/tests/unit/hash.test.ts +0 -45
  175. package/tests/unit/hyperplanning.test.ts +0 -97
  176. package/tests/unit/ip.test.ts +0 -140
  177. package/tests/unit/levenshtein.test.ts +0 -35
  178. package/tests/unit/palette.test.ts +0 -54
  179. package/tests/unit/password.test.ts +0 -86
  180. package/tests/unit/personal.test.ts +0 -66
  181. package/tests/unit/placeholder.test.ts +0 -58
  182. package/tests/unit/qrcode.test.ts +0 -83
  183. package/tests/unit/statistics.test.ts +0 -58
  184. package/tests/unit/text.test.ts +0 -108
  185. package/tests/unit/tic_tac_toe.test.ts +0 -56
  186. package/tests/unit/time.test.ts +0 -68
  187. package/tests/unit/token.test.ts +0 -62
  188. package/tests/unit/username.test.ts +0 -35
  189. package/tests/unit/validate.test.ts +0 -72
  190. package/tsconfig.json +0 -17
  191. package/tsconfig.test.json +0 -9
@@ -1,218 +0,0 @@
1
- /**
2
- * Check if two strings are anagrams of each other
3
- *
4
- * @param {string} value - First string to compare
5
- * @param {string} value2 - Second string to compare
6
- * @returns {boolean} - True if strings are anagrams, false otherwise
7
- * @throws {Error} - If inputs are invalid
8
- */
9
- export function anagram(value, value2) {
10
- if (!value) throw new Error('First value is required');
11
- if (!value2) throw new Error('Second value is required');
12
-
13
- if (typeof value !== 'string') throw new Error('First value must be a string');
14
- if (typeof value2 !== 'string') throw new Error('Second value must be a string');
15
-
16
- if (value.length < 2) throw new Error('First value must be at least two characters long');
17
- if (value.length > 1000) throw new Error('First value must be less than 1000 characters long');
18
-
19
- if (value2.length < 2) throw new Error('Second value must be at least two characters long');
20
- if (value2.length > 1000) throw new Error('Second value must be less than 1000 characters long');
21
-
22
- return value.split('').sort().join('') === value2.split('').sort().join('');
23
- }
24
-
25
- /**
26
- * Sort an array using bubble sort algorithm
27
- *
28
- * @param {string} value - Comma-separated list of numbers
29
- * @returns {number[]} - Sorted array of numbers
30
- * @throws {Error} - If input is invalid
31
- */
32
- export function bubblesort(value) {
33
- if (!value) throw new Error('A value is required');
34
-
35
- if (typeof value !== 'string') throw new Error('Value must be a string');
36
-
37
- const arr = value.split(',').map(Number);
38
-
39
- if (arr.some(isNaN)) throw new Error('Array must contain only numbers');
40
- if (arr.length < 2) throw new Error('Array must contain at least two numbers');
41
- if (arr.length > 1000) throw new Error('Array must contain less than 1000 numbers');
42
-
43
- for (let i = 0; i < arr.length - 1; i++) {
44
- for (let j = 0; j < arr.length - i - 1; j++) {
45
- if (arr[j] > arr[j + 1]) [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];
46
- }
47
- }
48
-
49
- return arr;
50
- }
51
-
52
- /**
53
- * Calculate the factorial of a number
54
- *
55
- * @param {number} value - Number to calculate factorial for
56
- * @returns {number} - Factorial result
57
- * @throws {Error} - If input is invalid or out of range
58
- */
59
- export function factorial(value) {
60
- if (isNaN(value)) throw new Error('Value must be a number');
61
- if (value < 0) throw new Error('Number must be positive');
62
- if (value > 170) throw new Error('Number must be between 0 and 170');
63
-
64
- return value <= 1 ? 1 : value * factorial(value - 1);
65
- }
66
-
67
- /**
68
- * Generate a Fibonacci sequence up to the specified length
69
- *
70
- * @param {number} value - Length of Fibonacci sequence to generate
71
- * @returns {number[]} - Array of Fibonacci numbers
72
- * @throws {Error} - If input is invalid or out of range
73
- */
74
- export function fibonacci(value) {
75
- if (isNaN(value)) throw new Error('Value must be a number');
76
- if (value < 0) throw new Error('Number must be positive');
77
- if (value > 1000) throw new Error('Number must be between 0 and 1000');
78
-
79
- let fib = [0, 1];
80
-
81
- for (let i = 2; i < parseInt(value); i++) {
82
- fib.push(fib[i - 1] + fib[i - 2]);
83
- }
84
-
85
- return fib.slice(0, parseInt(value));
86
- }
87
-
88
- /**
89
- * Calculate the greatest common divisor (GCD) of two numbers
90
- *
91
- * @param {number} value - First number
92
- * @param {number} value2 - Second number
93
- * @returns {number} - Greatest common divisor
94
- * @throws {Error} - If inputs are invalid or out of range
95
- */
96
- export function gcd(value, value2) {
97
- if (isNaN(value)) throw new Error('First value must be a number');
98
- if (isNaN(value2)) throw new Error('Second value must be a number');
99
-
100
- if (value <= 0) throw new Error('First number must be strictly positive');
101
- if (value2 <= 0) throw new Error('Second number must be strictly positive');
102
-
103
- if (value > 100000) throw new Error('First number must be between 0 and 100000');
104
- if (value2 > 100000) throw new Error('Second number must be between 0 and 100000');
105
-
106
- value = Math.abs(value);
107
- value2 = Math.abs(value2);
108
-
109
- while (value2) [value, value2] = [value2, value % value2];
110
-
111
- return value;
112
- }
113
-
114
- /**
115
- * Check if a number is prime
116
- *
117
- * @param {number} value - Number to check
118
- * @returns {boolean} - True if the number is prime, false otherwise
119
- * @throws {Error} - If input is invalid or out of range
120
- */
121
- export function isprime(value) {
122
- if (isNaN(value)) throw new Error('Value must be a number');
123
- if (value < 1) throw new Error('Number must be positive');
124
- if (value > 100000) throw new Error('Number must be between 1 and 100000');
125
-
126
- for (let i = 2; i <= Math.sqrt(value); i++) {
127
- if (value % i === 0) return false;
128
- }
129
-
130
- return true;
131
- }
132
-
133
- /**
134
- * Check if a string is a palindrome
135
- *
136
- * @param {string} value - String to check
137
- * @returns {boolean} - True if the string is a palindrome, false otherwise
138
- * @throws {Error} - If input is invalid
139
- */
140
- export function palindrome(value) {
141
- if (!value) throw new Error('A value is required');
142
-
143
- if (typeof value !== 'string') throw new Error('Value must be a string');
144
-
145
- if (value.length < 2) throw new Error('Value must be at least two characters long');
146
- if (value.length > 1000) throw new Error('Value must be less than 1000 characters long');
147
-
148
- return value === value.split('').reverse().join('');
149
- }
150
-
151
- /**
152
- * Find all prime factors of a number
153
- *
154
- * @param {number} value - Number to factorize
155
- * @returns {number[]} - Array of prime factors
156
- * @throws {Error} - If input is invalid or out of range
157
- */
158
- export function primefactors(value) {
159
- if (isNaN(value)) throw new Error('Value must be a number');
160
- if (value < 2) throw new Error('Number must be positive and greater than 1');
161
- if (value > 100000) throw new Error('Number must be between 2 and 100000');
162
-
163
- const factors = [];
164
-
165
- for (let i = 2; i <= value; i++) {
166
- while (value % i === 0) {
167
- factors.push(i);
168
- value /= i;
169
- }
170
- }
171
-
172
- return factors;
173
- }
174
-
175
- /**
176
- * Generate a list of all prime numbers up to the specified limit
177
- *
178
- * @param {number} value - Upper limit to check for primes
179
- * @returns {number[]} - Array of prime numbers
180
- * @throws {Error} - If input is invalid or out of range
181
- */
182
- export function primelist(value) {
183
- if (isNaN(value)) throw new Error('Value must be a number');
184
- if (value < 2) throw new Error('Number must be positive and greater than 1');
185
- if (value > 10000) throw new Error('Number must be between 2 and 10000');
186
-
187
- const primes = [];
188
-
189
- for (let i = 2; i <= value; i++) {
190
- let isPrime = true;
191
-
192
- for (let j = 2; j <= Math.sqrt(i); j++) {
193
- if (i % j === 0) {
194
- isPrime = false;
195
- break;
196
- }
197
- }
198
-
199
- if (isPrime) primes.push(i);
200
- }
201
-
202
- return primes;
203
- }
204
-
205
- /**
206
- * Reverse a string
207
- *
208
- * @param {string} value - String to reverse
209
- * @returns {string} - Reversed string
210
- * @throws {Error} - If input is invalid
211
- */
212
- export function reverse(value) {
213
- if (!value) throw new Error('A value is required');
214
-
215
- if (typeof value !== 'string') throw new Error('Value must be a string');
216
-
217
- return value.split('').reverse().join('');
218
- }
@@ -1,60 +0,0 @@
1
- import { createCanvas } from 'canvas';
2
-
3
- /**
4
- * Generate a captcha image from the provided text
5
- *
6
- * @param {string} text - Text to render in the captcha image
7
- * @returns {Buffer} - PNG image buffer of the rendered captcha
8
- * @throws {Error} - If text is not provided
9
- */
10
- export default function captcha(text) {
11
- if (!text) throw new Error('Text is required to generate a captcha.');
12
-
13
- const size = 60,
14
- font = '60px Comic Sans Ms',
15
- width = text.length * size,
16
- height = 120;
17
- const canvas = createCanvas(width, height),
18
- ctx = canvas.getContext('2d');
19
-
20
- // Set white background
21
- ctx.fillStyle = 'white';
22
- ctx.fillRect(0, 0, width, height);
23
-
24
- // Add random lines for noise
25
- for (let i = 0; i < 20; i++) {
26
- ctx.strokeStyle = 'rgba(0, 0, 0, 0.3)';
27
- ctx.beginPath();
28
- ctx.moveTo(Math.random() * width, Math.random() * height);
29
- ctx.lineTo(Math.random() * width, Math.random() * height);
30
- ctx.lineWidth = Math.random() * 2;
31
- ctx.stroke();
32
- }
33
-
34
- let x = (canvas.width + 20 - width) / 2;
35
-
36
- // Draw each character with random rotation and color
37
- for (let i = 0; i < text.length; i++) {
38
- const offsetX = Math.cos(i * 0.3) * 10,
39
- y = height / 2.5 + Math.floor(Math.random() * (height / 2));
40
-
41
- ctx.font = font;
42
- ctx.fillStyle = `rgb(${Math.floor(Math.random() * 192)}, ${Math.floor(Math.random() * 192)}, ${Math.floor(Math.random() * 192)})`;
43
-
44
- ctx.save();
45
- ctx.translate(x + size / 2, y);
46
- ctx.rotate((Math.random() - 0.5) * 0.5);
47
- ctx.fillText(text[i], -size / 2 + offsetX, 0);
48
- ctx.restore();
49
-
50
- x += size;
51
- }
52
-
53
- // Add noise dots
54
- for (let i = 0; i < 200; i++) {
55
- ctx.fillStyle = 'black';
56
- ctx.fillRect(Math.floor(Math.random() * width), Math.floor(Math.random() * height), 1.2, 1.2);
57
- }
58
-
59
- return canvas.toBuffer('image/png');
60
- }
@@ -1,111 +0,0 @@
1
- import { checkRateLimit } from './utils.js';
2
-
3
- /**
4
- * Manages a chat system with public and private messages
5
- *
6
- * @param {string} action - The action to perform ('message' or 'private')
7
- * @param {Object} params - The parameters for the action
8
- * @returns {Object} - The result of the action
9
- * @throws {Error} - If parameters are invalid
10
- */
11
- export default function chat(action, params = {}) {
12
- // In-memory storage
13
- const storage = params.storage || {};
14
-
15
- // Initialize storage
16
- storage.messages ??= [];
17
- storage.privateChats ??= {};
18
- storage.sessions ??= {};
19
- storage.rateLimits ??= {};
20
-
21
- // Reference the storage properties
22
- const { messages, privateChats, sessions, rateLimits } = storage;
23
-
24
- // Input validation for common parameters
25
- if (!params.username) throw new Error('Please provide a username');
26
-
27
- const u = params.username.toLowerCase();
28
- const now = Date.now();
29
-
30
- // Rate limiting
31
- checkRateLimit(rateLimits, u, now);
32
-
33
- // Handle different actions
34
- if (action === 'message') {
35
- return sendMessage(params, messages, privateChats, sessions, u, now);
36
- } else if (action === 'private') {
37
- return getPrivateChat(params, privateChats);
38
- } else if (action === 'fetch') {
39
- return fetchMessages(messages);
40
- } else {
41
- throw new Error('Invalid action. Use "message", "private", or "fetch"');
42
- }
43
- }
44
-
45
- /**
46
- * Send a new message
47
- */
48
- function sendMessage(params, messages, privateChats, sessions, u, now) {
49
- const { message, session, token } = params;
50
-
51
- // Input validation for message action
52
- if (!message) throw new Error('Please provide a message');
53
- if (!session) throw new Error('Please provide a valid session ID');
54
-
55
- // Session validation
56
- if (sessions[u] && sessions[u].user !== session) {
57
- throw new Error('Session ID mismatch');
58
- }
59
-
60
- // Create message object
61
- const msg = {
62
- username: params.username,
63
- message,
64
- timestamp: params.timestamp || new Date().toISOString(),
65
- };
66
-
67
- // Store message based on whether it's private or public
68
- if (token) {
69
- privateChats[token] = privateChats[token] || [];
70
- privateChats[token].push(msg);
71
- setTimeout(() => {
72
- delete privateChats[token];
73
- }, 3600000);
74
- } else {
75
- messages.push(msg);
76
- setTimeout(() => messages.splice(messages.indexOf(msg), 1), 3600000);
77
- }
78
-
79
- // Update session
80
- sessions[u] = sessions[u] || { user: session, last: now };
81
- sessions[u].last = now;
82
-
83
- setTimeout(() => {
84
- if (now - sessions[u].last >= 3600000) delete sessions[u];
85
- }, 3600000);
86
-
87
- return { message: 'Message sent successfully' };
88
- }
89
-
90
- /**
91
- * Get private chat messages
92
- */
93
- function getPrivateChat(params, privateChats) {
94
- const { token } = params;
95
-
96
- // Input validation for private action
97
- if (!token) throw new Error('Please provide a valid token');
98
-
99
- // Return messages if token exists
100
- if (privateChats[token]) return privateChats[token];
101
-
102
- throw new Error('Invalid or expired token.');
103
- }
104
-
105
- /**
106
- * Fetch all public messages
107
- */
108
- function fetchMessages(messages) {
109
- if (messages.length > 0) return messages;
110
- throw new Error('No messages stored.');
111
- }
@@ -1,60 +0,0 @@
1
- /**
2
- * Generate a random color in multiple formats
3
- *
4
- * @returns {Object} Color in various formats (hex, rgb, hsl, hsv, hwb, cmyk)
5
- */
6
- export default function color() {
7
- const r = Math.floor(Math.random() * 256),
8
- g = Math.floor(Math.random() * 256),
9
- b = Math.floor(Math.random() * 256);
10
-
11
- const hsl = (() => {
12
- const r1 = r / 255,
13
- g1 = g / 255,
14
- b1 = b / 255,
15
- max = Math.max(r1, g1, b1),
16
- min = Math.min(r1, g1, b1),
17
- l = (max + min) / 2;
18
- if (max === min) return [0, 0, l * 100];
19
- const d = max - min,
20
- s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
21
- let h = { [r1]: (g1 - b1) / d + (g1 < b1 ? 6 : 0), [g1]: (b1 - r1) / d + 2, [b1]: (r1 - g1) / d + 4 }[max];
22
- return [(h * 60) % 360, s * 100, l * 100];
23
- })();
24
-
25
- const hsv = (() => {
26
- const max = Math.max(r, g, b),
27
- min = Math.min(r, g, b),
28
- v = max / 255,
29
- s = max ? (max - min) / max : 0;
30
- let h =
31
- max === min
32
- ? 0
33
- : { [r]: (g - b) / (max - min), [g]: 2 + (b - r) / (max - min), [b]: 4 + (r - g) / (max - min) }[max];
34
- return [(h * 60) % 360, s * 100, v * 100];
35
- })();
36
-
37
- const hwb = (() => {
38
- const [h] = hsv,
39
- whiteness = Math.min(r, g, b) / 255,
40
- blackness = 1 - Math.max(r, g, b) / 255;
41
- return [h, whiteness * 100, blackness * 100];
42
- })();
43
-
44
- const cmyk = (() => {
45
- const k = 1 - Math.max(r, g, b) / 255,
46
- c = (1 - r / 255 - k) / (1 - k) || 0,
47
- m = (1 - g / 255 - k) / (1 - k) || 0,
48
- y = (1 - b / 255 - k) / (1 - k) || 0;
49
- return [c, m, y, k].map((x) => x * 100);
50
- })();
51
-
52
- return {
53
- hex: `#${[r, g, b].map((x) => x.toString(16).padStart(2, '0')).join('')}`,
54
- rgb: `rgb(${r}, ${g}, ${b})`,
55
- hsl: `hsl(${hsl[0].toFixed(1)}, ${hsl[1].toFixed(1)}%, ${hsl[2].toFixed(1)}%)`,
56
- hsv: `hsv(${hsv[0].toFixed(1)}, ${hsv[1].toFixed(1)}%, ${hsv[2].toFixed(1)}%)`,
57
- hwb: `hwb(${hwb[0].toFixed(1)}, ${hwb[1].toFixed(1)}%, ${hwb[2].toFixed(1)}%)`,
58
- cmyk: `cmyk(${cmyk.map((x) => x.toFixed(1)).join('%, ')}%)`,
59
- };
60
- }
@@ -1,39 +0,0 @@
1
- /**
2
- * Converts values between different temperature units
3
- *
4
- * @param {number|string} value - The value to convert
5
- * @param {string} from - The source unit (celsius, fahrenheit, or kelvin)
6
- * @param {string} to - The target unit (celsius, fahrenheit, or kelvin)
7
- * @returns {Object} - Object containing the conversion details
8
- * @throws {Error} - If conversion parameters are invalid
9
- */
10
- export default function convert(value, from, to) {
11
- const conversions = {
12
- celsius: {
13
- fahrenheit: (val) => (val * 9) / 5 + 32,
14
- kelvin: (val) => val + 273.15,
15
- },
16
- fahrenheit: {
17
- celsius: (val) => ((val - 32) * 5) / 9,
18
- kelvin: (val) => ((val - 32) * 5) / 9 + 273.15,
19
- },
20
- kelvin: {
21
- celsius: (val) => val - 273.15,
22
- fahrenheit: (val) => ((val - 273.15) * 9) / 5 + 32,
23
- },
24
- };
25
-
26
- const convert = conversions[from.toLowerCase()]?.[to.toLowerCase()];
27
-
28
- if (!convert) throw new Error('Invalid conversion unit');
29
- if (isNaN(value)) throw new Error('Value must be a number');
30
- if (value < -273.15) throw new Error('Value must be greater than absolute zero');
31
- if (value > 1e6) throw new Error('Value must be less than 1,000,000');
32
-
33
- return {
34
- from,
35
- to,
36
- value: parseFloat(value),
37
- result: convert(parseFloat(value)),
38
- };
39
- }
@@ -1,86 +0,0 @@
1
- import { random, genIP } from './utils.js';
2
-
3
- /**
4
- * Generate random domain information
5
- *
6
- * @returns {Object} Domain details including DNS, hosting, and SEO metrics
7
- */
8
- export default function domain() {
9
- const subdomains = [
10
- 'fr.',
11
- 'en.',
12
- 'docs.',
13
- 'api.',
14
- 'projects.',
15
- 'app.',
16
- 'web.',
17
- 'info.',
18
- 'dev.',
19
- 'shop.',
20
- 'blog.',
21
- 'support.',
22
- 'mail.',
23
- 'forum.',
24
- ];
25
- const domains = [
26
- 'example',
27
- 'site',
28
- 'test',
29
- 'demo',
30
- 'page',
31
- 'store',
32
- 'portfolio',
33
- 'platform',
34
- 'hub',
35
- 'network',
36
- 'service',
37
- 'cloud',
38
- 'solutions',
39
- 'company',
40
- ];
41
- const tlds = [
42
- '.com',
43
- '.fr',
44
- '.eu',
45
- '.dev',
46
- '.net',
47
- '.org',
48
- '.io',
49
- '.tech',
50
- '.biz',
51
- '.info',
52
- '.co',
53
- '.app',
54
- '.store',
55
- '.online',
56
- '.shop',
57
- '.tv',
58
- ];
59
-
60
- const domain = `${random(domains)}${random(tlds)}`;
61
- const fulldomain = `${random(subdomains)}${domain}`;
62
-
63
- const ips = Array.from({ length: Math.floor(Math.random() * 3) + 1 }, genIP);
64
- const dns = Array.from({ length: Math.floor(Math.random() * 5) + 1 }, genIP);
65
-
66
- return {
67
- domain,
68
- full_domain: fulldomain,
69
- ip_address: ips,
70
- ssl_certified: Math.random() > 0.5,
71
- hosting_provider: random(['AWS', 'Bluehost', 'DigitalOcean', 'GitHub', 'HostGator', 'Render', 'SiteGround']),
72
- dns_servers: dns,
73
- dns_provider: random(['AWS Route 53', 'Cloudflare', 'GoDaddy', 'Google DNS', 'Namecheap']),
74
- traffic: `${Math.floor(Math.random() * 10000)} visits/day`,
75
- seo_score: Math.floor(Math.random() * 100),
76
- page_rank: Math.floor(Math.random() * 10),
77
- country: random(['Australia', 'Canada', 'France', 'Germany', 'India', 'Japan', 'UK', 'USA']),
78
- website_type: random(['Blog', 'Community', 'Corporate', 'Educational', 'E-commerce', 'Personal', 'Portfolio']),
79
- random_name: domain.split('.')[0],
80
- random_subdomain: fulldomain.split('.')[0],
81
- random_tld: domain.split('.').pop(),
82
- backlinks_count: Math.floor(Math.random() * 1000),
83
- creation_date: new Date(Date.now() - Math.floor(Math.random() * 10000000000)).toISOString(),
84
- expiration_date: new Date(Date.now() + Math.floor(Math.random() * 10000000000)).toISOString(),
85
- };
86
- }
@@ -1,16 +0,0 @@
1
- import { getHashes, createHash } from 'crypto';
2
-
3
- /**
4
- * Generate a hash of text using the specified algorithm
5
- *
6
- * @param {string} text - The text to hash
7
- * @param {string} method - The hash algorithm to use
8
- * @returns {Object} Object containing the method and resulting hash
9
- */
10
- export default function hash(text, method) {
11
- const methods = getHashes();
12
- if (!methods.includes(method)) return { error: `Unsupported method. Use one of: ${methods.join(', ')}` };
13
-
14
- const hash = createHash(method).update(text).digest('hex');
15
- return { method, hash };
16
- }
@@ -1,56 +0,0 @@
1
- import { formatDate } from './utils.js';
2
- import ical from 'ical.js';
3
-
4
- /**
5
- * Parse an ICS calendar file and extract event information
6
- *
7
- * @param {string} url - URL to the ICS file
8
- * @param {string} [detail] - Detail level of returned information ('full', 'list', or undefined)
9
- * @returns {Promise<Array>} Array of calendar events
10
- * @throws {Error} If the ICS file is invalid or inaccessible
11
- */
12
- export default async function hyperplanning(url, detail) {
13
- const response = await fetch(url);
14
-
15
- if (!response.ok || !(response.headers.get('content-type') || '').includes('text/calendar')) {
16
- throw new Error('Invalid ICS file format.');
17
- }
18
-
19
- const events = new ical.Component(ical.parse(await response.text()))
20
- .getAllSubcomponents('vevent')
21
- .map((e) => {
22
- const evt = new ical.Event(e);
23
- const summary = (evt.summary || '').split(' ').filter((part) => part !== '-');
24
- const start = formatDate(evt.startDate.toJSDate());
25
- const end = formatDate(evt.endDate.toJSDate());
26
-
27
- if (detail === 'full') {
28
- const desc = (evt.description || '').split('\n').map((l) => l.trim());
29
- const extract = (p) => (desc.find((l) => l.startsWith(p)) || '').replace(p, '').trim();
30
-
31
- return {
32
- summary,
33
- subject: extract('Matière :'),
34
- teacher: extract('Enseignant :'),
35
- classes: extract('Promotions :')
36
- .split(', ')
37
- .map((c) => c.trim()),
38
- type: extract('Salle :') || undefined,
39
- start,
40
- end,
41
- };
42
- }
43
-
44
- if (detail === 'list') return { summary, start, end };
45
-
46
- return {
47
- summary: evt.summary || '',
48
- start,
49
- end,
50
- };
51
- })
52
- .sort((a, b) => new Date(a.start) - new Date(b.start))
53
- .filter((e) => new Date(e.end) >= new Date());
54
-
55
- return events;
56
- }
@@ -1,46 +0,0 @@
1
- /**
2
- * Calculate the Levenshtein distance between two strings.
3
- *
4
- * @param {string} str1 - The first string
5
- * @param {string} str2 - The second string
6
- * @returns {object} - Object containing the strings and their Levenshtein distance
7
- * @throws {Error} - If inputs are invalid
8
- */
9
- export default function levenshtein(str1, str2) {
10
- // Input validation
11
- if (!str1 || typeof str1 !== 'string') {
12
- throw new Error('Please provide a valid first string');
13
- }
14
-
15
- if (!str2 || typeof str2 !== 'string') {
16
- throw new Error('Please provide a valid second string');
17
- }
18
-
19
- if (str1.length > 1000) {
20
- throw new Error('First string exceeds 1000 characters');
21
- }
22
-
23
- if (str2.length > 1000) {
24
- throw new Error('Second string exceeds 1000 characters');
25
- }
26
-
27
- // Calculate Levenshtein distance
28
- const m = Array.from({ length: str1.length + 1 }, (_, i) => [i]);
29
- for (let j = 0; j <= str2.length; j++) m[0][j] = j;
30
-
31
- for (let i = 1; i <= str1.length; i++) {
32
- for (let j = 1; j <= str2.length; j++) {
33
- m[i][j] = Math.min(
34
- m[i - 1][j] + 1,
35
- m[i][j - 1] + 1,
36
- m[i - 1][j - 1] + (str1[i - 1] !== str2[j - 1] ? 1 : 0),
37
- );
38
- }
39
- }
40
-
41
- return {
42
- str1,
43
- str2,
44
- distance: m[str1.length][str2.length],
45
- };
46
- }