@20syldev/api 3.4.0 → 3.4.1

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.
@@ -1,32 +1,32 @@
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 = ['Happy', 'Silly', 'Clever', 'Creative', 'Brave', 'Gentle', 'Kind', 'Funny', 'Wise', 'Charming', 'Sincere', 'Resourceful', 'Patient', 'Energetic', 'Adventurous', 'Ambitious', 'Courageous', 'Courteous', 'Determined'];
10
- const ani = ['Cat', 'Dog', 'Tiger', 'Elephant', 'Monkey', 'Penguin', 'Dolphin', 'Lion', 'Bear', 'Fox', 'Owl', 'Giraffe', 'Zebra', 'Koala', 'Rabbit', 'Squirrel', 'Panda', 'Horse', 'Wolf', 'Eagle'];
11
- const job = ['Writer', 'Artist', 'Musician', 'Explorer', 'Scientist', 'Engineer', 'Athlete', 'Chef', 'Doctor', 'Teacher', 'Lawyer', 'Entrepreneur', 'Actor', 'Dancer', 'Photographer', 'Architect', 'Pilot', 'Designer', 'Journalist', 'Veterinarian'];
12
-
13
- const nombre = randomNumber(0, 99);
14
- const choix = {
15
- adj_num: () => random(adj) + nombre,
16
- ani_num: () => random(ani) + nombre,
17
- pro_num: () => random(job) + nombre,
18
- adj_ani: () => random(adj) + random(ani),
19
- adj_ani_num: () => random(adj) + random(ani) + nombre,
20
- adj_pro: () => random(adj) + random(job),
21
- pro_ani: () => random(job) + random(ani),
22
- pro_ani_num: () => random(job) + random(ani) + nombre
23
- };
24
-
25
- return {
26
- username: choix[random(Object.keys(choix))](),
27
- number: nombre,
28
- adjective: random(adj),
29
- animal: random(ani),
30
- job: random(job)
31
- };
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 = ['Happy', 'Silly', 'Clever', 'Creative', 'Brave', 'Gentle', 'Kind', 'Funny', 'Wise', 'Charming', 'Sincere', 'Resourceful', 'Patient', 'Energetic', 'Adventurous', 'Ambitious', 'Courageous', 'Courteous', 'Determined'];
10
+ const ani = ['Cat', 'Dog', 'Tiger', 'Elephant', 'Monkey', 'Penguin', 'Dolphin', 'Lion', 'Bear', 'Fox', 'Owl', 'Giraffe', 'Zebra', 'Koala', 'Rabbit', 'Squirrel', 'Panda', 'Horse', 'Wolf', 'Eagle'];
11
+ const job = ['Writer', 'Artist', 'Musician', 'Explorer', 'Scientist', 'Engineer', 'Athlete', 'Chef', 'Doctor', 'Teacher', 'Lawyer', 'Entrepreneur', 'Actor', 'Dancer', 'Photographer', 'Architect', 'Pilot', 'Designer', 'Journalist', 'Veterinarian'];
12
+
13
+ const nombre = randomNumber(0, 99);
14
+ const choix = {
15
+ adj_num: () => random(adj) + nombre,
16
+ ani_num: () => random(ani) + nombre,
17
+ pro_num: () => random(job) + nombre,
18
+ adj_ani: () => random(adj) + random(ani),
19
+ adj_ani_num: () => random(adj) + random(ani) + nombre,
20
+ adj_pro: () => random(adj) + random(job),
21
+ pro_ani: () => random(job) + random(ani),
22
+ pro_ani_num: () => random(job) + random(ani) + nombre
23
+ };
24
+
25
+ return {
26
+ username: choix[random(Object.keys(choix))](),
27
+ number: nombre,
28
+ adjective: random(adj),
29
+ animal: random(ani),
30
+ job: random(job)
31
+ };
32
32
  }
@@ -1,66 +1,66 @@
1
- /**
2
- * Shared utility functions for the API modules
3
- */
4
-
5
- /**
6
- * Return a random element from an array.
7
- *
8
- * @param {Array} arr - The array to choose from.
9
- * @returns {*} - A random element from the array.
10
- */
11
- export function random(arr) {
12
- return arr[Math.floor(Math.random() * arr.length)];
13
- }
14
-
15
- /**
16
- * Return a random number between min and max (inclusive).
17
- *
18
- * @param {number} min - The minimum number.
19
- * @param {number} max - The maximum number.
20
- * @returns {number} - A random number between min and max.
21
- */
22
- export function randomNumber(min, max) {
23
- return Math.floor(Math.random() * (max - min + 1)) + min;
24
- }
25
-
26
- /**
27
- * Generate a random IP address.
28
- *
29
- * @returns {string} - A random IP address in the format "X.X.X.X".
30
- */
31
- export function genIP() {
32
- return `${randomNumber(0, 255)}.${randomNumber(0, 255)}.${randomNumber(0, 255)}.${randomNumber(0, 255)}`;
33
- }
34
-
35
- /**
36
- * Format a JavaScript Date object to ISO format without timezone.
37
- *
38
- * @param {Date} date - Date object to format
39
- * @returns {string} - Formatted date string
40
- */
41
- export function formatDate(date) {
42
- return new Date(date.getTime() - date.getTimezoneOffset() * 60000).toISOString().replace('Z', '');
43
- }
44
-
45
- /**
46
- * Manage rate limiting for users
47
- *
48
- * @param {Object} rateLimits - Rate limits object
49
- * @param {string} userId - User ID
50
- * @param {number} timestamp - Current timestamp
51
- * @param {number} window - Time window in milliseconds
52
- * @param {number} limit - Maximum requests in window
53
- * @returns {boolean} - True if rate limit is exceeded
54
- * @throws {Error} - If rate limit is exceeded
55
- */
56
- export function checkRateLimit(rateLimits, userId, timestamp, window = 10000, limit = 50) {
57
- rateLimits[userId] = (rateLimits[userId] || []).filter(ts => timestamp - ts < window);
58
-
59
- if (rateLimits[userId].length > limit) {
60
- const remainingTime = Math.ceil((rateLimits[userId][0] + window - timestamp) / 1000);
61
- throw new Error(`Rate limit exceeded. Try again in ${remainingTime} seconds.`);
62
- }
63
-
64
- rateLimits[userId].push(timestamp);
65
- return false;
1
+ /**
2
+ * Shared utility functions for the API modules
3
+ */
4
+
5
+ /**
6
+ * Return a random element from an array.
7
+ *
8
+ * @param {Array} arr - The array to choose from.
9
+ * @returns {*} - A random element from the array.
10
+ */
11
+ export function random(arr) {
12
+ return arr[Math.floor(Math.random() * arr.length)];
13
+ }
14
+
15
+ /**
16
+ * Return a random number between min and max (inclusive).
17
+ *
18
+ * @param {number} min - The minimum number.
19
+ * @param {number} max - The maximum number.
20
+ * @returns {number} - A random number between min and max.
21
+ */
22
+ export function randomNumber(min, max) {
23
+ return Math.floor(Math.random() * (max - min + 1)) + min;
24
+ }
25
+
26
+ /**
27
+ * Generate a random IP address.
28
+ *
29
+ * @returns {string} - A random IP address in the format "X.X.X.X".
30
+ */
31
+ export function genIP() {
32
+ return `${randomNumber(0, 255)}.${randomNumber(0, 255)}.${randomNumber(0, 255)}.${randomNumber(0, 255)}`;
33
+ }
34
+
35
+ /**
36
+ * Format a JavaScript Date object to ISO format without timezone.
37
+ *
38
+ * @param {Date} date - Date object to format
39
+ * @returns {string} - Formatted date string
40
+ */
41
+ export function formatDate(date) {
42
+ return new Date(date.getTime() - date.getTimezoneOffset() * 60000).toISOString().replace('Z', '');
43
+ }
44
+
45
+ /**
46
+ * Manage rate limiting for users
47
+ *
48
+ * @param {Object} rateLimits - Rate limits object
49
+ * @param {string} userId - User ID
50
+ * @param {number} timestamp - Current timestamp
51
+ * @param {number} window - Time window in milliseconds
52
+ * @param {number} limit - Maximum requests in window
53
+ * @returns {boolean} - True if rate limit is exceeded
54
+ * @throws {Error} - If rate limit is exceeded
55
+ */
56
+ export function checkRateLimit(rateLimits, userId, timestamp, window = 10000, limit = 50) {
57
+ rateLimits[userId] = (rateLimits[userId] || []).filter(ts => timestamp - ts < window);
58
+
59
+ if (rateLimits[userId].length > limit) {
60
+ const remainingTime = Math.ceil((rateLimits[userId][0] + window - timestamp) / 1000);
61
+ throw new Error(`Rate limit exceeded. Try again in ${remainingTime} seconds.`);
62
+ }
63
+
64
+ rateLimits[userId].push(timestamp);
65
+ return false;
66
66
  }
package/modules/v3.js CHANGED
@@ -1,15 +1,15 @@
1
- export * as algorithms from './v3/algorithms.js';
2
- export { default as chat } from './v3/chat.js';
3
- export { default as captcha } from './v3/captcha.js';
4
- export { default as color } from './v3/color.js';
5
- export { default as convert } from './v3/convert.js';
6
- export { default as domain } from './v3/domain.js';
7
- export { default as hash } from './v3/hash.js';
8
- export { default as hyperplanning } from './v3/hyperplanning.js';
9
- export { default as levenshtein } from './v3/levenshtein.js';
10
- export { default as personal } from './v3/personal.js';
11
- export { default as qrcode } from './v3/qrcode.js';
12
- export { default as tic_tac_toe } from './v3/tic_tac_toe.js';
13
- export { default as time } from './v3/time.js';
14
- export { default as token } from './v3/token.js';
1
+ export * as algorithms from './v3/algorithms.js';
2
+ export { default as chat } from './v3/chat.js';
3
+ export { default as captcha } from './v3/captcha.js';
4
+ export { default as color } from './v3/color.js';
5
+ export { default as convert } from './v3/convert.js';
6
+ export { default as domain } from './v3/domain.js';
7
+ export { default as hash } from './v3/hash.js';
8
+ export { default as hyperplanning } from './v3/hyperplanning.js';
9
+ export { default as levenshtein } from './v3/levenshtein.js';
10
+ export { default as personal } from './v3/personal.js';
11
+ export { default as qrcode } from './v3/qrcode.js';
12
+ export { default as tic_tac_toe } from './v3/tic_tac_toe.js';
13
+ export { default as time } from './v3/time.js';
14
+ export { default as token } from './v3/token.js';
15
15
  export { default as username } from './v3/username.js';
package/package.json CHANGED
@@ -1,53 +1,53 @@
1
- {
2
- "version": "3.4.0",
3
- "name": "@20syldev/api",
4
- "description": "Node.js API with multiple features. Check the documentation at https://docs.sylvain.pro",
5
- "main": "app.js",
6
- "type": "module",
7
- "scripts": {
8
- "start": "node app.js",
9
- "dev": "nodemon app.js",
10
- "build": "npm install && node app.js",
11
- "lint": "prettier --write .",
12
- "upgrade:minor": "npm upgrade",
13
- "upgrade:major": "npx npm-check-updates -u && npm install",
14
- "upgrade:build": "npm upgrade && npm install && node app.js"
15
- },
16
- "exports": {
17
- "./v1": "./modules/v1.js",
18
- "./v2": "./modules/v2.js",
19
- "./v3": "./modules/v3.js"
20
- },
21
- "dependencies": {
22
- "canvas": "latest",
23
- "cors": "latest",
24
- "dotenv": "latest",
25
- "express": "latest",
26
- "ical.js": "latest",
27
- "node-fetch": "latest",
28
- "qrcode": "latest",
29
- "random": "latest",
30
- "uuid": "latest"
31
- },
32
- "devDependencies": {
33
- "nodemon": "latest",
34
- "npm-check-updates": "latest",
35
- "prettier": "latest"
36
- },
37
- "repository": {
38
- "type": "git",
39
- "url": "git+https://github.com/20syldev/api.git"
40
- },
41
- "keywords": [
42
- "api",
43
- "express",
44
- "utility",
45
- "math"
46
- ],
47
- "author": "Sylvain L.",
48
- "license": "BSD 3-Clause",
49
- "bugs": {
50
- "url": "https://github.com/20syldev/api/issues"
51
- },
52
- "homepage": "https://api.sylvain.pro"
53
- }
1
+ {
2
+ "version": "3.4.1",
3
+ "name": "@20syldev/api",
4
+ "description": "Node.js API with multiple features. Check the documentation at https://docs.sylvain.pro",
5
+ "main": "app.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "start": "node app.js",
9
+ "dev": "nodemon app.js",
10
+ "build": "npm install && node app.js",
11
+ "lint": "prettier --write .",
12
+ "upgrade:minor": "npm upgrade",
13
+ "upgrade:major": "npx npm-check-updates -u && npm install",
14
+ "upgrade:build": "npm upgrade && npm install && node app.js"
15
+ },
16
+ "exports": {
17
+ "./v1": "./modules/v1.js",
18
+ "./v2": "./modules/v2.js",
19
+ "./v3": "./modules/v3.js"
20
+ },
21
+ "dependencies": {
22
+ "canvas": "latest",
23
+ "cors": "latest",
24
+ "dotenv": "latest",
25
+ "express": "latest",
26
+ "ical.js": "latest",
27
+ "node-fetch": "latest",
28
+ "qrcode": "latest",
29
+ "random": "latest",
30
+ "uuid": "latest"
31
+ },
32
+ "devDependencies": {
33
+ "nodemon": "latest",
34
+ "npm-check-updates": "latest",
35
+ "prettier": "latest"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/20syldev/api.git"
40
+ },
41
+ "keywords": [
42
+ "api",
43
+ "express",
44
+ "utility",
45
+ "math"
46
+ ],
47
+ "author": "Sylvain L.",
48
+ "license": "BSD 3-Clause",
49
+ "bugs": {
50
+ "url": "https://github.com/20syldev/api/issues"
51
+ },
52
+ "homepage": "https://api.sylvain.pro"
53
+ }
package/robots.txt CHANGED
@@ -1,74 +1,74 @@
1
- User-agent: 360Spider
2
- User-agent: 360Spider-Image
3
- User-agent: 360Spider-Video
4
- User-agent: AdsBot-Google
5
- User-agent: AdsBot-Google-Mobile
6
- User-agent: AdsBot-Google-Mobile-Apps
7
- User-agent: adidxbot
8
- User-agent: Applebot
9
- User-agent: AppleNewsBot
10
- User-agent: Baiduspider
11
- User-agent: Baiduspider-image
12
- User-agent: Baiduspider-news
13
- User-agent: Baiduspider-video
14
- User-agent: bingbot
15
- User-agent: BingPreview
16
- User-agent: BublupBot
17
- User-agent: CCBot
18
- User-agent: Cliqzbot
19
- User-agent: coccoc
20
- User-agent: coccocbot-image
21
- User-agent: coccocbot-web
22
- User-agent: Daumoa
23
- User-agent: Dazoobot
24
- User-agent: DeuSu
25
- User-agent: DuckDuckBot
26
- User-agent: DuckDuckGo-Favicons-Bot
27
- User-agent: EuripBot
28
- User-agent: Exploratodo
29
- User-agent: Facebot
30
- User-agent: Feedly
31
- User-agent: Findxbot
32
- User-agent: Googlebot
33
- User-agent: Googlebot-Image
34
- User-agent: Googlebot-Mobile
35
- User-agent: Googlebot-News
36
- User-agent: Googlebot-Video
37
- User-agent: HaoSouSpider
38
- User-agent: ichiro
39
- User-agent: istellabot
40
- User-agent: JikeSpider
41
- User-agent: Lycos
42
- User-agent: Mail.Ru
43
- User-agent: Mediapartners-Google
44
- User-agent: MojeekBot
45
- User-agent: msnbot
46
- User-agent: msnbot-media
47
- User-agent: OrangeBot
48
- User-agent: Pinterest
49
- User-agent: Plukkie
50
- User-agent: Qwantify
51
- User-agent: Rambler
52
- User-agent: SeznamBot
53
- User-agent: Sosospider
54
- User-agent: Slurp
55
- User-agent: Sogou blog
56
- User-agent: Sogou inst spider
57
- User-agent: Sogou News Spider
58
- User-agent: Sogou Orion spider
59
- User-agent: Sogou spider2
60
- User-agent: Sogou web spider
61
- User-agent: SputnikBot
62
- User-agent: Teoma
63
- User-agent: Twitterbot
64
- User-agent: wotbox
65
- User-agent: yacybot
66
- User-agent: Yandex
67
- User-agent: YandexMobileBot
68
- User-agent: Yeti
69
- User-agent: YioopBot
70
- User-agent: yoozBot
71
- User-agent: YoudaoBot
72
- Disallow:
73
- User-agent: *
1
+ User-agent: 360Spider
2
+ User-agent: 360Spider-Image
3
+ User-agent: 360Spider-Video
4
+ User-agent: AdsBot-Google
5
+ User-agent: AdsBot-Google-Mobile
6
+ User-agent: AdsBot-Google-Mobile-Apps
7
+ User-agent: adidxbot
8
+ User-agent: Applebot
9
+ User-agent: AppleNewsBot
10
+ User-agent: Baiduspider
11
+ User-agent: Baiduspider-image
12
+ User-agent: Baiduspider-news
13
+ User-agent: Baiduspider-video
14
+ User-agent: bingbot
15
+ User-agent: BingPreview
16
+ User-agent: BublupBot
17
+ User-agent: CCBot
18
+ User-agent: Cliqzbot
19
+ User-agent: coccoc
20
+ User-agent: coccocbot-image
21
+ User-agent: coccocbot-web
22
+ User-agent: Daumoa
23
+ User-agent: Dazoobot
24
+ User-agent: DeuSu
25
+ User-agent: DuckDuckBot
26
+ User-agent: DuckDuckGo-Favicons-Bot
27
+ User-agent: EuripBot
28
+ User-agent: Exploratodo
29
+ User-agent: Facebot
30
+ User-agent: Feedly
31
+ User-agent: Findxbot
32
+ User-agent: Googlebot
33
+ User-agent: Googlebot-Image
34
+ User-agent: Googlebot-Mobile
35
+ User-agent: Googlebot-News
36
+ User-agent: Googlebot-Video
37
+ User-agent: HaoSouSpider
38
+ User-agent: ichiro
39
+ User-agent: istellabot
40
+ User-agent: JikeSpider
41
+ User-agent: Lycos
42
+ User-agent: Mail.Ru
43
+ User-agent: Mediapartners-Google
44
+ User-agent: MojeekBot
45
+ User-agent: msnbot
46
+ User-agent: msnbot-media
47
+ User-agent: OrangeBot
48
+ User-agent: Pinterest
49
+ User-agent: Plukkie
50
+ User-agent: Qwantify
51
+ User-agent: Rambler
52
+ User-agent: SeznamBot
53
+ User-agent: Sosospider
54
+ User-agent: Slurp
55
+ User-agent: Sogou blog
56
+ User-agent: Sogou inst spider
57
+ User-agent: Sogou News Spider
58
+ User-agent: Sogou Orion spider
59
+ User-agent: Sogou spider2
60
+ User-agent: Sogou web spider
61
+ User-agent: SputnikBot
62
+ User-agent: Teoma
63
+ User-agent: Twitterbot
64
+ User-agent: wotbox
65
+ User-agent: yacybot
66
+ User-agent: Yandex
67
+ User-agent: YandexMobileBot
68
+ User-agent: Yeti
69
+ User-agent: YioopBot
70
+ User-agent: yoozBot
71
+ User-agent: YoudaoBot
72
+ Disallow:
73
+ User-agent: *
74
74
  Disallow: /