@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,139 +0,0 @@
1
- import { random, randomNumber } from './utils.js';
2
-
3
- /**
4
- * Generate random personal information
5
- *
6
- * @returns {Object} Comprehensive personal profile with contact info, financial data, and more
7
- */
8
- export default function personal() {
9
- const people = [
10
- { name: 'John Doe', social: 'john_doe', email: 'john@example.com', country: 'US' },
11
- { name: 'Jane Martin', social: 'jane_martin', email: 'jane@example.com', country: 'FR' },
12
- { name: 'Michael Johnson', social: 'mike_johnson', email: 'michael@example.com', country: 'UK' },
13
- { name: 'Emily Davis', social: 'emily_davis', email: 'emily@example.com', country: 'ES' },
14
- { name: 'Alexis Barbos', social: 'alexis_barbos', email: 'alexis@example.com', country: 'DE' },
15
- { name: 'Sarah Williams', social: 'sarah_williams', email: 'sarah@example.com', country: 'IT' },
16
- { name: 'Daniel Brown', social: 'daniel_brown', email: 'daniel@example.com', country: 'JP' },
17
- { name: 'Sophia Wilson', social: 'sophia_wilson', email: 'sophia@example.com', country: 'BR' },
18
- { name: 'James Taylor', social: 'james_taylor', email: 'james@example.com', country: 'CA' },
19
- { name: 'Olivia Thomas', social: 'olivia_thomas', email: 'olivia@example.com', country: 'AU' },
20
- ];
21
-
22
- const countries = {
23
- US: { tel: '123-456-7890', code: '1', lang: 'English' },
24
- FR: { tel: '06 78 90 12 34', code: '33', lang: 'French' },
25
- UK: { tel: '7911 123456', code: '44', lang: 'English' },
26
- ES: { tel: '678 901 234', code: '34', lang: 'Spanish' },
27
- DE: { tel: '163 555 1584', code: '49', lang: 'German' },
28
- IT: { tel: '345 678 9012', code: '39', lang: 'Italian' },
29
- JP: { tel: '080-1234-5678', code: '81', lang: 'Japanese' },
30
- BR: { tel: '(11) 98765-4321', code: '55', lang: 'Portuguese' },
31
- CA: { tel: '416-123-4567', code: '1', lang: 'English' },
32
- AU: { tel: '0412 345 678', code: '61', lang: 'English' },
33
- };
34
-
35
- const jobs = ['Writer', 'Artist', 'Musician', 'Explorer', 'Scientist', 'Engineer', 'Athlete', 'Doctor'];
36
- const hobbies = ['Reading', 'Traveling', 'Gaming', 'Cooking', 'Fitness', 'Music', 'Photography', 'Writing'];
37
- const cities = [
38
- 'New York',
39
- 'Paris',
40
- 'London',
41
- 'Madrid',
42
- 'Berlin',
43
- 'Rome',
44
- 'Tokyo',
45
- 'Los Angeles',
46
- 'Sydney',
47
- 'São Paulo',
48
- 'Toronto',
49
- ];
50
- const streets = ['Main St', '2nd Ave', 'Broadway', 'Park Lane', 'Elm St', 'Sunset Blvd', 'Maple St', 'Highland Rd'];
51
-
52
- const card = Array.from({ length: 4 }, () => randomNumber(1000, 9999)).join(' ');
53
- const cvc = randomNumber(100, 999);
54
- const expiration = `${String(randomNumber(1, 12)).padStart(2, '0')}/${(new Date().getFullYear() + randomNumber(0, 3)).toString().slice(-2)}`;
55
-
56
- const person = random(people);
57
- const social = person.social;
58
- const country = person.country;
59
- const phone = countries[country].tel;
60
- const lang = countries[country].lang;
61
-
62
- const age = randomNumber(18, 67);
63
- const birthday = new Date(Date.now() - randomNumber(18, 67) * 365.25 * 24 * 60 * 60 * 1000).toISOString();
64
-
65
- let emergencyContacts = [];
66
- let yearIncome = randomNumber(20000, 100000);
67
- let subscriptions = [];
68
- let pets = [];
69
- let vehicles = [];
70
- let civilStatus = 'Single';
71
- let children = 0;
72
-
73
- if (age >= 21 && Math.random() > 0.7) civilStatus = 'Married';
74
-
75
- if (civilStatus === 'Married' && age >= 25) children = randomNumber(0, 3);
76
-
77
- while (emergencyContacts.length < randomNumber(1, 3)) {
78
- let emergencyContact = random(people);
79
- while (
80
- emergencyContact.email === person.email ||
81
- emergencyContacts.some((e) => e.email === emergencyContact.email)
82
- ) {
83
- emergencyContact = random(people);
84
- }
85
- const emergencyPhone = `${randomNumber(100, 999)}-${randomNumber(100, 999)}-${randomNumber(1000, 9999)}`;
86
- emergencyContacts.push({
87
- name: emergencyContact.name,
88
- relationship: random(['Spouse', 'Parent', 'Sibling', 'Friend']),
89
- phone: `+${countries[country].code} ${emergencyPhone}`,
90
- });
91
- }
92
-
93
- while (subscriptions.length < randomNumber(1, 3)) {
94
- let subscription = random(['Netflix', 'Spotify', 'Amazon Prime', 'Disney+', 'Hulu']);
95
- if (!subscriptions.includes(subscription)) subscriptions.push(subscription);
96
- }
97
-
98
- while (pets.length < randomNumber(1, 3)) {
99
- let pet = random(['Dog', 'Cat', 'Fish', 'Bird', 'None']);
100
- if (!pets.includes(pet)) pets.push(pet);
101
- }
102
-
103
- while (vehicles.length < randomNumber(1, 3)) {
104
- let vehicle = random(['Car', 'Bike', 'Motorcycle', 'Bus', 'None']);
105
- if (!vehicles.includes(vehicle)) vehicles.push(vehicle);
106
- }
107
-
108
- return {
109
- name: person.name,
110
- email: person.email,
111
- localisation: country,
112
- phone: `+${countries[country].code} ${phone}`,
113
- job: random(jobs),
114
- hobbies: random(hobbies),
115
- language: lang,
116
- card,
117
- cvc,
118
- expiration,
119
- address: `${randomNumber(1, 9999)} ${random(streets)}, ${random(cities)}`,
120
- birthday,
121
- civil_status: civilStatus,
122
- children,
123
- vehicle: vehicles,
124
- social_profiles: {
125
- twitter: `@${social}`,
126
- facebook: `facebook.com/${social}`,
127
- linkedin: `linkedin.com/in/${social}`,
128
- instagram: `instagram.com/${social}`,
129
- },
130
- year_income: `${yearIncome} USD/year`,
131
- month_income: `${(yearIncome / 12).toFixed(2)} USD/month`,
132
- education: random(['High School', "Bachelor's", "Master's", 'PhD']),
133
- work_experience: `${randomNumber(0, 20)} years`,
134
- health_status: random(['Healthy', 'Minor Issues', 'Chronic Conditions']),
135
- emergency_contacts: emergencyContacts,
136
- subscriptions,
137
- pets,
138
- };
139
- }
@@ -1,20 +0,0 @@
1
- import { toDataURL } from 'qrcode';
2
-
3
- /**
4
- * Generate a QR code for the provided URL.
5
- *
6
- * @param {string} url - The URL to encode in the QR code
7
- * @returns {Promise<string>} - Base64 encoded QR code image
8
- * @throws {Error} - If URL is invalid or QR code generation fails
9
- */
10
- export default async function qrcode(url) {
11
- // Input validation
12
- if (!url || typeof url !== 'string') throw new Error('Please provide a valid URL');
13
-
14
- try {
15
- // Generate QR code
16
- return await toDataURL(url);
17
- } catch (error) {
18
- throw new Error(`Failed to generate QR code: ${error.message}`);
19
- }
20
- }
@@ -1,242 +0,0 @@
1
- import { randomBytes } from 'crypto';
2
-
3
- /**
4
- * Manages a Tic-Tac-Toe game session
5
- *
6
- * @param {string} action - The action to perform ('play', 'fetch', or 'list')
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 tic_tac_toe(action, params = {}) {
12
- // In-memory storage
13
- const storage = params.storage || {};
14
-
15
- // Initialize storage
16
- storage.games ??= {};
17
- storage.sessions ??= {};
18
- storage.rateLimits ??= {};
19
-
20
- // Reference the storage properties
21
- const { games, sessions, rateLimits } = storage;
22
-
23
- // List public games
24
- if (action === 'list') return listGames(games);
25
-
26
- // Input validation for common parameters
27
- if (!params.username) throw new Error('Please provide a username');
28
-
29
- const u = params.username.toLowerCase();
30
- const now = Date.now();
31
-
32
- // Rate limiting
33
- rateLimits[u] = (rateLimits[u] || []).filter((ts) => now - ts < 10000);
34
- if (rateLimits[u].length > 50) {
35
- const remainingTime = Math.ceil((rateLimits[u][0] + 10000 - now) / 1000);
36
- throw new Error(`Rate limit exceeded. Try again in ${remainingTime} seconds.`);
37
- }
38
- rateLimits[u].push(now);
39
-
40
- // Handle different actions
41
- if (action === 'play') {
42
- return playMove(params, games, sessions, u, now);
43
- } else if (action === 'fetch') {
44
- return fetchGame(params, games, u);
45
- } else {
46
- throw new Error('Invalid action. Use "play", "fetch", or "list"');
47
- }
48
- }
49
-
50
- /**
51
- * Process a player's move
52
- */
53
- function playMove(params, games, sessions, u, now) {
54
- const { move, session, game } = params;
55
- const validMoves = ['1-1', '1-2', '1-3', '2-1', '2-2', '2-3', '3-1', '3-2', '3-3'];
56
-
57
- // Input validation for play action
58
- if (!move) throw new Error('Please provide a valid move');
59
- if (!session) throw new Error('Please provide a valid session ID');
60
- if (!game) throw new Error('Please provide a valid game ID');
61
- if (!validMoves.includes(move)) throw new Error('Invalid move. Please provide a valid move (e.g., 1-1, 2-2, 3-3).');
62
-
63
- // Session validation
64
- if (sessions[u] && sessions[u].user !== session) {
65
- throw new Error('Session ID mismatch');
66
- }
67
-
68
- // Initialize game if needed
69
- games[game] = games[game] || {
70
- moves: [],
71
- players: [],
72
- private: params.private || false,
73
- creation: Date.now(),
74
- };
75
- const moves = games[game].moves;
76
-
77
- // Check if game is full
78
- const players = [...new Set(moves.map((play) => play.username))];
79
- if (players.length >= 2 && !players.includes(params.username)) {
80
- throw new Error('Game is full, you can only watch.');
81
- }
82
-
83
- // Check if it's player's turn
84
- if (moves.length > 0 && moves[moves.length - 1].username === params.username) {
85
- throw new Error('Please wait for the other player to make a move.');
86
- }
87
-
88
- // Check if move is already made
89
- if (moves.some((play) => play.move === move)) {
90
- throw new Error('Move already made. Please choose a different move.');
91
- }
92
-
93
- // Add move to game
94
- const play = { username: params.username, move, session };
95
- moves.push(play);
96
-
97
- // Check game result
98
- const result = checkGame(moves);
99
- if (result.winner || result.tie) {
100
- setTimeout(() => delete games[game], 600000);
101
- return {
102
- message: `Move sent successfully. ${result.winner ? result.winner + ' wins. ' + result.loser + ' loses.' : "It's a tie."}`,
103
- ...result,
104
- };
105
- }
106
-
107
- // Set cleanup timeout
108
- setTimeout(() => delete games[game], 3600000);
109
-
110
- // Update session
111
- sessions[u] = sessions[u] || { user: session, last: now };
112
- sessions[u].last = now;
113
- setTimeout(() => {
114
- if (now - sessions[u].last >= 3600000) delete sessions[u];
115
- }, 3600000);
116
-
117
- return { message: 'Move sent successfully' };
118
- }
119
-
120
- /**
121
- * Fetch a game state
122
- */
123
- function fetchGame(params, games, u) {
124
- const id = params.game || generateGameId();
125
- if (!games[id]) {
126
- games[id] = {
127
- moves: [],
128
- players: [],
129
- private: params.private || false,
130
- creation: Date.now(),
131
- };
132
- }
133
- if (!games[id].players.includes(u)) {
134
- games[id].players.push(u);
135
- }
136
-
137
- const moves = games[id].moves;
138
- const players = games[id].players;
139
- const privateGame = games[id].private;
140
- const lastPlayer = moves.length ? moves[moves.length - 1].username : null;
141
- const turn = players.find((p) => p !== lastPlayer) || players[0];
142
- const status = players.length >= 2 ? 'ready' : 'waiting';
143
- const result = moves.length ? checkGame(moves) : {};
144
-
145
- return {
146
- id,
147
- moves,
148
- players,
149
- turn,
150
- status,
151
- private: privateGame,
152
- ...result,
153
- };
154
- }
155
-
156
- /**
157
- * List all public games in progress
158
- */
159
- function listGames(games) {
160
- const publicGames = [];
161
- const now = Date.now();
162
-
163
- for (const [gameId, game] of Object.entries(games)) {
164
- // Only include public games
165
- if (!game.private) {
166
- const result = game.moves.length ? checkGame(game.moves) : {};
167
- const isFinished = result.winner || result.tie;
168
-
169
- // Only include active games (not finished)
170
- if (!isFinished) {
171
- const lastPlayer = game.moves.length ? game.moves[game.moves.length - 1].username : null;
172
- const turn = game.players.find((p) => p !== lastPlayer) || game.players[0];
173
- const status = game.players.length >= 2 ? 'ready' : 'waiting';
174
-
175
- publicGames.push({
176
- id: gameId,
177
- players: game.players,
178
- playersCount: game.players.length,
179
- moves: game.moves.length,
180
- turn,
181
- status,
182
- creation: game.creation || now,
183
- });
184
- }
185
- }
186
- }
187
-
188
- // Sort by creation time (newest first)
189
- publicGames.sort((a, b) => b.creation - a.creation);
190
-
191
- return {
192
- message: 'Public games available',
193
- count: publicGames.length,
194
- games: publicGames,
195
- };
196
- }
197
-
198
- /**
199
- * Generate a random game ID
200
- */
201
- function generateGameId() {
202
- const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
203
- return Array.from(randomBytes(5))
204
- .map((b) => chars[b % chars.length])
205
- .join('');
206
- }
207
-
208
- /**
209
- * Check the game result
210
- */
211
- function checkGame(moves) {
212
- let board = Array(3)
213
- .fill()
214
- .map(() => Array(3).fill(null));
215
- let playerSymbols = {};
216
- let playersOrder = [];
217
-
218
- moves.forEach(({ username, move }) => {
219
- if (!playerSymbols[username]) {
220
- playersOrder.push(username);
221
- playerSymbols[username] = playersOrder.length === 1 ? 'X' : 'O';
222
- }
223
- let [row, col] = move.split('-').map(Number);
224
- board[row - 1][col - 1] = playerSymbols[username];
225
- });
226
-
227
- const checkWinner = (symbol) => {
228
- for (let i = 0; i < 3; i++) {
229
- if (board[i][0] === symbol && board[i][1] === symbol && board[i][2] === symbol) return true;
230
- if (board[0][i] === symbol && board[1][i] === symbol && board[2][i] === symbol) return true;
231
- }
232
- if (board[0][0] === symbol && board[1][1] === symbol && board[2][2] === symbol) return true;
233
- if (board[0][2] === symbol && board[1][1] === symbol && board[2][0] === symbol) return true;
234
- return false;
235
- };
236
-
237
- let winner = Object.keys(playerSymbols).find((player) => checkWinner(playerSymbols[player]));
238
- let isTie = !winner && moves.length === 9;
239
- let loser = winner && playersOrder.length === 2 ? playersOrder.find((player) => player !== winner) : null;
240
-
241
- return { winner, loser, tie: isTie };
242
- }
@@ -1,98 +0,0 @@
1
- /**
2
- * Generate time information based on specified parameters.
3
- *
4
- * @param {string} type - The type of time information ('live' or 'random')
5
- * @param {string} start - Start date for random generation (ISO format)
6
- * @param {string} end - End date for random generation (ISO format)
7
- * @param {string} format - Specific time format to return
8
- * @param {string} timezone - Timezone to use
9
- * @returns {object} - Time information in various formats
10
- * @throws {Error} - If inputs are invalid
11
- */
12
- export default function time(type = 'live', start, end, format, timezone) {
13
- const validFormats = [
14
- 'iso',
15
- 'utc',
16
- 'timestamp',
17
- 'locale',
18
- 'date',
19
- 'time',
20
- 'year',
21
- 'month',
22
- 'day',
23
- 'hour',
24
- 'minute',
25
- 'second',
26
- 'ms',
27
- 'dayOfWeek',
28
- 'dayOfYear',
29
- 'weekNumber',
30
- 'timezone',
31
- 'timezoneOffset',
32
- ];
33
-
34
- const validTimezones = ['UTC', 'America/New_York', 'Europe/Paris', 'Asia/Tokyo', 'Australia/Sydney'];
35
-
36
- // Input validation
37
- if (type !== 'live' && type !== 'random') {
38
- throw new Error('Please provide a valid type (live or random)');
39
- }
40
-
41
- if (start && !Date.parse(start)) {
42
- throw new Error('Please provide a valid start date (YYYY-MM-DD)');
43
- }
44
-
45
- if (end && !Date.parse(end)) {
46
- throw new Error('Please provide a valid end date (YYYY-MM-DD)');
47
- }
48
-
49
- if (format && !validFormats.includes(format)) {
50
- throw new Error(`Please provide a valid format. Options: ${validFormats.join(', ')}`);
51
- }
52
-
53
- if (timezone && !validTimezones.includes(timezone)) {
54
- throw new Error(`Please provide a valid timezone. Options: ${validTimezones.join(', ')}`);
55
- }
56
-
57
- // Helper function to get all time formats for a date
58
- const getTimeFormats = (date, tz) => {
59
- return {
60
- iso: date.toISOString(),
61
- utc: date.toUTCString(),
62
- timestamp: date.getTime(),
63
- locale: date.toLocaleString('en-US', { timeZone: tz, timeZoneName: 'long' }),
64
- date: date.toLocaleDateString('en-US', { timeZone: tz }),
65
- time: date.toLocaleTimeString('en-US', { timeZone: tz }),
66
- year: date.getFullYear(),
67
- month: date.getMonth() + 1,
68
- day: date.getDate(),
69
- hour: date.getHours(),
70
- minute: date.getMinutes(),
71
- second: date.getSeconds(),
72
- ms: date.getMilliseconds(),
73
- dayOfWeek: date.getDay(),
74
- dayOfYear: Math.floor((date - new Date(date.getFullYear(), 0, 0)) / 86400000),
75
- weekNumber: Math.ceil(((date - new Date(date.getFullYear(), 0, 0)) / 86400000 + 1) / 7),
76
- timezone: tz,
77
- timezoneOffset: date.getTimezoneOffset(),
78
- };
79
- };
80
-
81
- // Generate time information based on type
82
- if (type === 'random') {
83
- const startDate = start ? new Date(start).getTime() : new Date('1900-01-01').getTime();
84
- const endDate = end ? new Date(end).getTime() : new Date('2100-12-31').getTime();
85
- const randomDate = new Date(startDate + Math.random() * (endDate - startDate));
86
- const tz = timezone || validTimezones[Math.floor(Math.random() * validTimezones.length)];
87
- const formats = getTimeFormats(randomDate, tz);
88
-
89
- return format ? { date: formats[format] } : formats;
90
- }
91
-
92
- // Live time information
93
- const now = new Date();
94
- const tz = timezone || 'UTC';
95
- const formats = getTimeFormats(now, tz);
96
-
97
- return format ? { date: formats[format] } : formats;
98
- }
@@ -1,54 +0,0 @@
1
- import { randomBytes } from 'crypto';
2
- import { v4 } from 'uuid';
3
-
4
- /**
5
- * Generate a random token of specified length and type.
6
- *
7
- * @param {number} len - Length of the token
8
- * @param {string} type - Type of token to generate
9
- * @returns {string} - The generated token
10
- * @throws {Error} - If inputs are invalid
11
- */
12
- export default function token(len, type = 'alphanum') {
13
- // Input validation
14
- if (isNaN(len) || len < 12) {
15
- throw new Error('Length must be a number greater than or equal to 12');
16
- }
17
-
18
- if (len > 4096) {
19
- throw new Error('Length cannot exceed 4096');
20
- }
21
-
22
- // Helper function to generate token from character set
23
- const genToken = (chars, length) => {
24
- return Array.from({ length }, () => {
25
- return chars[Math.floor(Math.random() * chars.length)];
26
- }).join('');
27
- };
28
-
29
- // Token type definitions
30
- const tokenTypes = {
31
- alpha: () => genToken('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', len),
32
- alphanum: () => genToken('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', len),
33
- base64: () =>
34
- randomBytes(Math.ceil(len * 0.75))
35
- .toString('base64')
36
- .slice(0, len),
37
- hex: () =>
38
- randomBytes(Math.ceil(len * 0.5))
39
- .toString('hex')
40
- .slice(0, len),
41
- num: () => genToken('0123456789', len),
42
- punct: () => genToken('!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~', len),
43
- urlsafe: () => genToken('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_', len),
44
- uuid: () => v4().replace(/-/g, '').slice(0, len),
45
- };
46
-
47
- // Generate token based on type or default to alphanum
48
- if (!tokenTypes[type.toLowerCase()]) {
49
- throw new Error(`Invalid token type. Valid types: ${Object.keys(tokenTypes).join(', ')}`);
50
- }
51
-
52
- // Generate token based on type or default to alphanum
53
- return (tokenTypes[type.toLowerCase()] || tokenTypes.alphanum)();
54
- }
@@ -1,94 +0,0 @@
1
- import { random, randomNumber } from './utils.js';
2
-
3
- /**
4
- * Generate a random username with related information
5
- *
6
- * @returns {Object} Object containing username and component parts
7
- */
8
- export default function username() {
9
- const adj = [
10
- 'Happy',
11
- 'Silly',
12
- 'Clever',
13
- 'Creative',
14
- 'Brave',
15
- 'Gentle',
16
- 'Kind',
17
- 'Funny',
18
- 'Wise',
19
- 'Charming',
20
- 'Sincere',
21
- 'Resourceful',
22
- 'Patient',
23
- 'Energetic',
24
- 'Adventurous',
25
- 'Ambitious',
26
- 'Courageous',
27
- 'Courteous',
28
- 'Determined',
29
- ];
30
- const ani = [
31
- 'Cat',
32
- 'Dog',
33
- 'Tiger',
34
- 'Elephant',
35
- 'Monkey',
36
- 'Penguin',
37
- 'Dolphin',
38
- 'Lion',
39
- 'Bear',
40
- 'Fox',
41
- 'Owl',
42
- 'Giraffe',
43
- 'Zebra',
44
- 'Koala',
45
- 'Rabbit',
46
- 'Squirrel',
47
- 'Panda',
48
- 'Horse',
49
- 'Wolf',
50
- 'Eagle',
51
- ];
52
- const job = [
53
- 'Writer',
54
- 'Artist',
55
- 'Musician',
56
- 'Explorer',
57
- 'Scientist',
58
- 'Engineer',
59
- 'Athlete',
60
- 'Chef',
61
- 'Doctor',
62
- 'Teacher',
63
- 'Lawyer',
64
- 'Entrepreneur',
65
- 'Actor',
66
- 'Dancer',
67
- 'Photographer',
68
- 'Architect',
69
- 'Pilot',
70
- 'Designer',
71
- 'Journalist',
72
- 'Veterinarian',
73
- ];
74
-
75
- const nombre = randomNumber(0, 99);
76
- const choix = {
77
- adj_num: () => random(adj) + nombre,
78
- ani_num: () => random(ani) + nombre,
79
- pro_num: () => random(job) + nombre,
80
- adj_ani: () => random(adj) + random(ani),
81
- adj_ani_num: () => random(adj) + random(ani) + nombre,
82
- adj_pro: () => random(adj) + random(job),
83
- pro_ani: () => random(job) + random(ani),
84
- pro_ani_num: () => random(job) + random(ani) + nombre,
85
- };
86
-
87
- return {
88
- username: choix[random(Object.keys(choix))](),
89
- number: nombre,
90
- adjective: random(adj),
91
- animal: random(ani),
92
- job: random(job),
93
- };
94
- }