@moxon/api 6.0.0-pre
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/.prettierignore +5 -0
- package/LICENSE +28 -0
- package/README.md +277 -0
- package/dist/app.d.ts +2 -0
- package/dist/app.js +55 -0
- package/dist/app.js.map +1 -0
- package/dist/config/env.d.ts +22 -0
- package/dist/config/env.js +36 -0
- package/dist/config/env.js.map +1 -0
- package/dist/config/plans.d.ts +26 -0
- package/dist/config/plans.js +44 -0
- package/dist/config/plans.js.map +1 -0
- package/dist/config/versions.d.ts +18 -0
- package/dist/config/versions.js +248 -0
- package/dist/config/versions.js.map +1 -0
- package/dist/constants.d.ts +48 -0
- package/dist/constants.js +75 -0
- package/dist/constants.js.map +1 -0
- package/dist/middleware/cors.d.ts +2 -0
- package/dist/middleware/cors.js +31 -0
- package/dist/middleware/cors.js.map +1 -0
- package/dist/middleware/error.d.ts +4 -0
- package/dist/middleware/error.js +8 -0
- package/dist/middleware/error.js.map +1 -0
- package/dist/middleware/json.d.ts +2 -0
- package/dist/middleware/json.js +8 -0
- package/dist/middleware/json.js.map +1 -0
- package/dist/middleware/logger.d.ts +26 -0
- package/dist/middleware/logger.js +65 -0
- package/dist/middleware/logger.js.map +1 -0
- package/dist/middleware/ratelimit.d.ts +2 -0
- package/dist/middleware/ratelimit.js +83 -0
- package/dist/middleware/ratelimit.js.map +1 -0
- package/dist/middleware/version.d.ts +3 -0
- package/dist/middleware/version.js +30 -0
- package/dist/middleware/version.js.map +1 -0
- package/dist/modules/v4/address.d.ts +20 -0
- package/dist/modules/v4/address.js +381 -0
- package/dist/modules/v4/address.js.map +1 -0
- package/dist/modules/v4/agent.d.ts +30 -0
- package/dist/modules/v4/agent.js +92 -0
- package/dist/modules/v4/agent.js.map +1 -0
- package/dist/modules/v4/algorithms.d.ts +90 -0
- package/dist/modules/v4/algorithms.js +279 -0
- package/dist/modules/v4/algorithms.js.map +1 -0
- package/dist/modules/v4/avatar.d.ts +23 -0
- package/dist/modules/v4/avatar.js +136 -0
- package/dist/modules/v4/avatar.js.map +1 -0
- package/dist/modules/v4/barcode.d.ts +27 -0
- package/dist/modules/v4/barcode.js +440 -0
- package/dist/modules/v4/barcode.js.map +1 -0
- package/dist/modules/v4/captcha.d.ts +22 -0
- package/dist/modules/v4/captcha.js +79 -0
- package/dist/modules/v4/captcha.js.map +1 -0
- package/dist/modules/v4/chat.d.ts +21 -0
- package/dist/modules/v4/chat.js +100 -0
- package/dist/modules/v4/chat.js.map +1 -0
- package/dist/modules/v4/color.d.ts +16 -0
- package/dist/modules/v4/color.js +59 -0
- package/dist/modules/v4/color.js.map +1 -0
- package/dist/modules/v4/convert.d.ts +15 -0
- package/dist/modules/v4/convert.js +116 -0
- package/dist/modules/v4/convert.js.map +1 -0
- package/dist/modules/v4/credit.d.ts +22 -0
- package/dist/modules/v4/credit.js +104 -0
- package/dist/modules/v4/credit.js.map +1 -0
- package/dist/modules/v4/cron.d.ts +17 -0
- package/dist/modules/v4/cron.js +202 -0
- package/dist/modules/v4/cron.js.map +1 -0
- package/dist/modules/v4/dice.d.ts +16 -0
- package/dist/modules/v4/dice.js +37 -0
- package/dist/modules/v4/dice.js.map +1 -0
- package/dist/modules/v4/domain.d.ts +6 -0
- package/dist/modules/v4/domain.js +83 -0
- package/dist/modules/v4/domain.js.map +1 -0
- package/dist/modules/v4/encode.d.ts +81 -0
- package/dist/modules/v4/encode.js +236 -0
- package/dist/modules/v4/encode.js.map +1 -0
- package/dist/modules/v4/geo.d.ts +30 -0
- package/dist/modules/v4/geo.js +51 -0
- package/dist/modules/v4/geo.js.map +1 -0
- package/dist/modules/v4/hash.d.ts +15 -0
- package/dist/modules/v4/hash.js +25 -0
- package/dist/modules/v4/hash.js.map +1 -0
- package/dist/modules/v4/hyperplanning.d.ts +19 -0
- package/dist/modules/v4/hyperplanning.js +80 -0
- package/dist/modules/v4/hyperplanning.js.map +1 -0
- package/dist/modules/v4/ip.d.ts +19 -0
- package/dist/modules/v4/ip.js +132 -0
- package/dist/modules/v4/ip.js.map +1 -0
- package/dist/modules/v4/levenshtein.d.ts +13 -0
- package/dist/modules/v4/levenshtein.js +37 -0
- package/dist/modules/v4/levenshtein.js.map +1 -0
- package/dist/modules/v4/palette.d.ts +19 -0
- package/dist/modules/v4/palette.js +56 -0
- package/dist/modules/v4/palette.js.map +1 -0
- package/dist/modules/v4/password.d.ts +25 -0
- package/dist/modules/v4/password.js +343 -0
- package/dist/modules/v4/password.js.map +1 -0
- package/dist/modules/v4/personal.d.ts +6 -0
- package/dist/modules/v4/personal.js +121 -0
- package/dist/modules/v4/personal.js.map +1 -0
- package/dist/modules/v4/placeholder.d.ts +30 -0
- package/dist/modules/v4/placeholder.js +160 -0
- package/dist/modules/v4/placeholder.js.map +1 -0
- package/dist/modules/v4/qrcode.d.ts +25 -0
- package/dist/modules/v4/qrcode.js +92 -0
- package/dist/modules/v4/qrcode.js.map +1 -0
- package/dist/modules/v4/regex.d.ts +23 -0
- package/dist/modules/v4/regex.js +48 -0
- package/dist/modules/v4/regex.js.map +1 -0
- package/dist/modules/v4/statistics.d.ts +20 -0
- package/dist/modules/v4/statistics.js +48 -0
- package/dist/modules/v4/statistics.js.map +1 -0
- package/dist/modules/v4/text.d.ts +43 -0
- package/dist/modules/v4/text.js +323 -0
- package/dist/modules/v4/text.js.map +1 -0
- package/dist/modules/v4/tic_tac_toe.d.ts +19 -0
- package/dist/modules/v4/tic_tac_toe.js +214 -0
- package/dist/modules/v4/tic_tac_toe.js.map +1 -0
- package/dist/modules/v4/time.d.ts +15 -0
- package/dist/modules/v4/time.js +124 -0
- package/dist/modules/v4/time.js.map +1 -0
- package/dist/modules/v4/token.d.ts +9 -0
- package/dist/modules/v4/token.js +45 -0
- package/dist/modules/v4/token.js.map +1 -0
- package/dist/modules/v4/username.d.ts +6 -0
- package/dist/modules/v4/username.js +92 -0
- package/dist/modules/v4/username.js.map +1 -0
- package/dist/modules/v4/validate.d.ts +34 -0
- package/dist/modules/v4/validate.js +75 -0
- package/dist/modules/v4/validate.js.map +1 -0
- package/dist/modules/v4.d.ts +32 -0
- package/dist/modules/v4.js +33 -0
- package/dist/modules/v4.js.map +1 -0
- package/dist/modules/v5/address.d.ts +5 -0
- package/dist/modules/v5/address.js +20 -0
- package/dist/modules/v5/address.js.map +1 -0
- package/dist/modules/v5/algorithms.d.ts +9 -0
- package/dist/modules/v5/algorithms.js +39 -0
- package/dist/modules/v5/algorithms.js.map +1 -0
- package/dist/modules/v5/asymmetric.d.ts +26 -0
- package/dist/modules/v5/asymmetric.js +74 -0
- package/dist/modules/v5/asymmetric.js.map +1 -0
- package/dist/modules/v5/barcode.d.ts +27 -0
- package/dist/modules/v5/barcode.js +424 -0
- package/dist/modules/v5/barcode.js.map +1 -0
- package/dist/modules/v5/base.d.ts +16 -0
- package/dist/modules/v5/base.js +41 -0
- package/dist/modules/v5/base.js.map +1 -0
- package/dist/modules/v5/captcha.d.ts +27 -0
- package/dist/modules/v5/captcha.js +136 -0
- package/dist/modules/v5/captcha.js.map +1 -0
- package/dist/modules/v5/case.d.ts +10 -0
- package/dist/modules/v5/case.js +57 -0
- package/dist/modules/v5/case.js.map +1 -0
- package/dist/modules/v5/chart.d.ts +53 -0
- package/dist/modules/v5/chart.js +385 -0
- package/dist/modules/v5/chart.js.map +1 -0
- package/dist/modules/v5/chat.d.ts +21 -0
- package/dist/modules/v5/chat.js +107 -0
- package/dist/modules/v5/chat.js.map +1 -0
- package/dist/modules/v5/csv.d.ts +29 -0
- package/dist/modules/v5/csv.js +143 -0
- package/dist/modules/v5/csv.js.map +1 -0
- package/dist/modules/v5/diff.d.ts +20 -0
- package/dist/modules/v5/diff.js +81 -0
- package/dist/modules/v5/diff.js.map +1 -0
- package/dist/modules/v5/evaluate.d.ts +14 -0
- package/dist/modules/v5/evaluate.js +284 -0
- package/dist/modules/v5/evaluate.js.map +1 -0
- package/dist/modules/v5/jwt.d.ts +11 -0
- package/dist/modules/v5/jwt.js +42 -0
- package/dist/modules/v5/jwt.js.map +1 -0
- package/dist/modules/v5/matrix.d.ts +77 -0
- package/dist/modules/v5/matrix.js +239 -0
- package/dist/modules/v5/matrix.js.map +1 -0
- package/dist/modules/v5/otp.d.ts +30 -0
- package/dist/modules/v5/otp.js +117 -0
- package/dist/modules/v5/otp.js.map +1 -0
- package/dist/modules/v5/pow.d.ts +29 -0
- package/dist/modules/v5/pow.js +49 -0
- package/dist/modules/v5/pow.js.map +1 -0
- package/dist/modules/v5/read.d.ts +20 -0
- package/dist/modules/v5/read.js +59 -0
- package/dist/modules/v5/read.js.map +1 -0
- package/dist/modules/v5/semver.d.ts +33 -0
- package/dist/modules/v5/semver.js +99 -0
- package/dist/modules/v5/semver.js.map +1 -0
- package/dist/modules/v5/symmetric.d.ts +15 -0
- package/dist/modules/v5/symmetric.js +88 -0
- package/dist/modules/v5/symmetric.js.map +1 -0
- package/dist/modules/v5/text.d.ts +5 -0
- package/dist/modules/v5/text.js +12 -0
- package/dist/modules/v5/text.js.map +1 -0
- package/dist/modules/v5/tic_tac_toe.d.ts +19 -0
- package/dist/modules/v5/tic_tac_toe.js +226 -0
- package/dist/modules/v5/tic_tac_toe.js.map +1 -0
- package/dist/modules/v5/url.d.ts +18 -0
- package/dist/modules/v5/url.js +51 -0
- package/dist/modules/v5/url.js.map +1 -0
- package/dist/modules/v5/uuid.d.ts +25 -0
- package/dist/modules/v5/uuid.js +40 -0
- package/dist/modules/v5/uuid.js.map +1 -0
- package/dist/modules/v5.d.ts +24 -0
- package/dist/modules/v5.js +25 -0
- package/dist/modules/v5.js.map +1 -0
- package/dist/modules/v6.d.ts +1 -0
- package/dist/modules/v6.js +2 -0
- package/dist/modules/v6.js.map +1 -0
- package/dist/routes/delete.d.ts +2 -0
- package/dist/routes/delete.js +73 -0
- package/dist/routes/delete.js.map +1 -0
- package/dist/routes/get.d.ts +2 -0
- package/dist/routes/get.js +857 -0
- package/dist/routes/get.js.map +1 -0
- package/dist/routes/index.d.ts +2 -0
- package/dist/routes/index.js +95 -0
- package/dist/routes/index.js.map +1 -0
- package/dist/routes/patch.d.ts +2 -0
- package/dist/routes/patch.js +45 -0
- package/dist/routes/patch.js.map +1 -0
- package/dist/routes/post.d.ts +2 -0
- package/dist/routes/post.js +604 -0
- package/dist/routes/post.js.map +1 -0
- package/dist/storage/index.d.ts +5 -0
- package/dist/storage/index.js +14 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/types/storage.d.ts +52 -0
- package/dist/types/storage.js +2 -0
- package/dist/types/storage.js.map +1 -0
- package/dist/utils/challenge.d.ts +40 -0
- package/dist/utils/challenge.js +75 -0
- package/dist/utils/challenge.js.map +1 -0
- package/dist/utils/colors.d.ts +44 -0
- package/dist/utils/colors.js +93 -0
- package/dist/utils/colors.js.map +1 -0
- package/dist/utils/helpers.d.ts +55 -0
- package/dist/utils/helpers.js +82 -0
- package/dist/utils/helpers.js.map +1 -0
- package/dist/utils/response.d.ts +9 -0
- package/dist/utils/response.js +24 -0
- package/dist/utils/response.js.map +1 -0
- package/package.json +90 -0
- package/robots.txt +74 -0
- package/src/favicon.ico +0 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { MAX_STRING_LENGTH } from '../../constants.js';
|
|
2
|
+
const MORSE_TABLE = {
|
|
3
|
+
A: '.-',
|
|
4
|
+
B: '-...',
|
|
5
|
+
C: '-.-.',
|
|
6
|
+
D: '-..',
|
|
7
|
+
E: '.',
|
|
8
|
+
F: '..-.',
|
|
9
|
+
G: '--.',
|
|
10
|
+
H: '....',
|
|
11
|
+
I: '..',
|
|
12
|
+
J: '.---',
|
|
13
|
+
K: '-.-',
|
|
14
|
+
L: '.-..',
|
|
15
|
+
M: '--',
|
|
16
|
+
N: '-.',
|
|
17
|
+
O: '---',
|
|
18
|
+
P: '.--.',
|
|
19
|
+
Q: '--.-',
|
|
20
|
+
R: '.-.',
|
|
21
|
+
S: '...',
|
|
22
|
+
T: '-',
|
|
23
|
+
U: '..-',
|
|
24
|
+
V: '...-',
|
|
25
|
+
W: '.--',
|
|
26
|
+
X: '-..-',
|
|
27
|
+
Y: '-.--',
|
|
28
|
+
Z: '--..',
|
|
29
|
+
'0': '-----',
|
|
30
|
+
'1': '.----',
|
|
31
|
+
'2': '..---',
|
|
32
|
+
'3': '...--',
|
|
33
|
+
'4': '....-',
|
|
34
|
+
'5': '.....',
|
|
35
|
+
'6': '-....',
|
|
36
|
+
'7': '--...',
|
|
37
|
+
'8': '---..',
|
|
38
|
+
'9': '----.',
|
|
39
|
+
'.': '.-.-.-',
|
|
40
|
+
',': '--..--',
|
|
41
|
+
'?': '..--..',
|
|
42
|
+
"'": '.----.',
|
|
43
|
+
'!': '-.-.--',
|
|
44
|
+
'/': '-..-.',
|
|
45
|
+
'(': '-.--.',
|
|
46
|
+
')': '-.--.-',
|
|
47
|
+
'&': '.-...',
|
|
48
|
+
':': '---...',
|
|
49
|
+
';': '-.-.-.',
|
|
50
|
+
'=': '-...-',
|
|
51
|
+
'+': '.-.-.',
|
|
52
|
+
'-': '-....-',
|
|
53
|
+
_: '..--.-',
|
|
54
|
+
'"': '.-..-.',
|
|
55
|
+
$: '...-..-',
|
|
56
|
+
'@': '.--.-.',
|
|
57
|
+
};
|
|
58
|
+
const MORSE_REVERSE = Object.fromEntries(Object.entries(MORSE_TABLE).map(([k, v]) => [v, k]));
|
|
59
|
+
function checkText(value) {
|
|
60
|
+
if (!value)
|
|
61
|
+
throw new Error('A value is required');
|
|
62
|
+
if (typeof value !== 'string')
|
|
63
|
+
throw new Error('Value must be a string');
|
|
64
|
+
if (value.length > MAX_STRING_LENGTH)
|
|
65
|
+
throw new Error(`Value must be less than ${MAX_STRING_LENGTH} characters long`);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Encodes a UTF-8 string to Base64.
|
|
69
|
+
*
|
|
70
|
+
* @param value - The string to encode
|
|
71
|
+
* @returns Base64-encoded string
|
|
72
|
+
* @throws Error if value is missing, not a string, or too long
|
|
73
|
+
*/
|
|
74
|
+
export function base64encode(value) {
|
|
75
|
+
checkText(value);
|
|
76
|
+
return Buffer.from(value, 'utf-8').toString('base64');
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Decodes a Base64 string to UTF-8.
|
|
80
|
+
*
|
|
81
|
+
* @param value - The Base64 string to decode
|
|
82
|
+
* @returns Decoded UTF-8 string
|
|
83
|
+
* @throws Error if value is missing, not valid Base64, or too long
|
|
84
|
+
*/
|
|
85
|
+
export function base64decode(value) {
|
|
86
|
+
checkText(value);
|
|
87
|
+
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(value))
|
|
88
|
+
throw new Error('Invalid Base64 string');
|
|
89
|
+
return Buffer.from(value, 'base64').toString('utf-8');
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Percent-encodes a string for safe use in a URL.
|
|
93
|
+
*
|
|
94
|
+
* @param value - The string to encode
|
|
95
|
+
* @returns URL-encoded string
|
|
96
|
+
* @throws Error if value is missing, not a string, or too long
|
|
97
|
+
*/
|
|
98
|
+
export function urlencode(value) {
|
|
99
|
+
checkText(value);
|
|
100
|
+
return encodeURIComponent(value);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Decodes a percent-encoded URL string.
|
|
104
|
+
*
|
|
105
|
+
* @param value - The URL-encoded string to decode
|
|
106
|
+
* @returns Decoded string
|
|
107
|
+
* @throws Error if value is missing, not a valid URL-encoded string, or too long
|
|
108
|
+
*/
|
|
109
|
+
export function urldecode(value) {
|
|
110
|
+
checkText(value);
|
|
111
|
+
try {
|
|
112
|
+
return decodeURIComponent(value);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
throw new Error('Invalid URL-encoded string');
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Converts a plain text string to Morse code.
|
|
120
|
+
*
|
|
121
|
+
* @param value - The text to encode in Morse code
|
|
122
|
+
* @returns Morse code string where letters are separated by spaces and words by " / "
|
|
123
|
+
* @throws Error if value contains unsupported characters or is too long
|
|
124
|
+
*/
|
|
125
|
+
export function morse(value) {
|
|
126
|
+
checkText(value);
|
|
127
|
+
return value
|
|
128
|
+
.toUpperCase()
|
|
129
|
+
.split(' ')
|
|
130
|
+
.map((word) => word
|
|
131
|
+
.split('')
|
|
132
|
+
.map((c) => {
|
|
133
|
+
if (c === '\n' || c === '\t')
|
|
134
|
+
return '';
|
|
135
|
+
const code = MORSE_TABLE[c];
|
|
136
|
+
if (!code)
|
|
137
|
+
throw new Error(`Unsupported character in Morse code: '${c}'`);
|
|
138
|
+
return code;
|
|
139
|
+
})
|
|
140
|
+
.filter(Boolean)
|
|
141
|
+
.join(' '))
|
|
142
|
+
.join(' / ');
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Converts a Morse code string back to plain text.
|
|
146
|
+
*
|
|
147
|
+
* @param value - Morse code string (letters separated by spaces, words by " / ")
|
|
148
|
+
* @returns Decoded plain text string
|
|
149
|
+
* @throws Error if the Morse code contains an unrecognized sequence or is too long
|
|
150
|
+
*/
|
|
151
|
+
export function unmorse(value) {
|
|
152
|
+
checkText(value);
|
|
153
|
+
return value
|
|
154
|
+
.split(' / ')
|
|
155
|
+
.map((word) => word
|
|
156
|
+
.split(' ')
|
|
157
|
+
.map((code) => {
|
|
158
|
+
if (!code)
|
|
159
|
+
return '';
|
|
160
|
+
const char = MORSE_REVERSE[code];
|
|
161
|
+
if (!char)
|
|
162
|
+
throw new Error(`Unsupported Morse sequence: '${code}'`);
|
|
163
|
+
return char;
|
|
164
|
+
})
|
|
165
|
+
.join(''))
|
|
166
|
+
.join(' ');
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Applies the ROT13 substitution cipher to a string.
|
|
170
|
+
*
|
|
171
|
+
* @param value - The string to encode
|
|
172
|
+
* @returns ROT13-encoded string (applying it twice restores the original)
|
|
173
|
+
* @throws Error if value is missing, not a string, or too long
|
|
174
|
+
*/
|
|
175
|
+
export function rot13(value) {
|
|
176
|
+
checkText(value);
|
|
177
|
+
return value.replace(/[a-zA-Z]/g, (c) => {
|
|
178
|
+
const base = c <= 'Z' ? 65 : 97;
|
|
179
|
+
return String.fromCharCode(((c.charCodeAt(0) - base + 13) % 26) + base);
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Applies the Caesar cipher by shifting alphabetic characters by a given amount.
|
|
184
|
+
*
|
|
185
|
+
* @param value - The string to encode
|
|
186
|
+
* @param shift - Number of positions to shift (can be negative for left shift)
|
|
187
|
+
* @returns Caesar-shifted string
|
|
188
|
+
* @throws Error if value is missing or shift is not a number
|
|
189
|
+
*/
|
|
190
|
+
export function caesar(value, shift) {
|
|
191
|
+
checkText(value);
|
|
192
|
+
const n = Number(shift);
|
|
193
|
+
if (isNaN(n))
|
|
194
|
+
throw new Error('Shift must be a number');
|
|
195
|
+
const s = ((n % 26) + 26) % 26;
|
|
196
|
+
return value.replace(/[a-zA-Z]/g, (c) => {
|
|
197
|
+
const base = c <= 'Z' ? 65 : 97;
|
|
198
|
+
return String.fromCharCode(((c.charCodeAt(0) - base + s) % 26) + base);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Converts a string to its binary representation, one byte per character.
|
|
203
|
+
*
|
|
204
|
+
* @param value - The string to convert
|
|
205
|
+
* @returns Space-separated 8-bit binary groups (one per character)
|
|
206
|
+
* @throws Error if value is missing, not a string, or too long
|
|
207
|
+
*/
|
|
208
|
+
export function binary(value) {
|
|
209
|
+
checkText(value);
|
|
210
|
+
return value
|
|
211
|
+
.split('')
|
|
212
|
+
.map((c) => c.charCodeAt(0).toString(2).padStart(8, '0'))
|
|
213
|
+
.join(' ');
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Converts a binary string back to plain text.
|
|
217
|
+
*
|
|
218
|
+
* @param value - Space-separated 8-bit binary groups
|
|
219
|
+
* @returns Decoded string
|
|
220
|
+
* @throws Error if value contains non-binary characters or groups are not 8 bits wide
|
|
221
|
+
*/
|
|
222
|
+
export function unbinary(value) {
|
|
223
|
+
checkText(value);
|
|
224
|
+
if (!/^[01\s]+$/.test(value))
|
|
225
|
+
throw new Error('Invalid binary string');
|
|
226
|
+
return value
|
|
227
|
+
.trim()
|
|
228
|
+
.split(/\s+/)
|
|
229
|
+
.map((b) => {
|
|
230
|
+
if (b.length !== 8)
|
|
231
|
+
throw new Error('Each binary group must contain 8 bits');
|
|
232
|
+
return String.fromCharCode(parseInt(b, 2));
|
|
233
|
+
})
|
|
234
|
+
.join('');
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=encode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode.js","sourceRoot":"","sources":["../../../src/modules/v4/encode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,WAAW,GAA2B;IACxC,CAAC,EAAE,IAAI;IACP,CAAC,EAAE,MAAM;IACT,CAAC,EAAE,MAAM;IACT,CAAC,EAAE,KAAK;IACR,CAAC,EAAE,GAAG;IACN,CAAC,EAAE,MAAM;IACT,CAAC,EAAE,KAAK;IACR,CAAC,EAAE,MAAM;IACT,CAAC,EAAE,IAAI;IACP,CAAC,EAAE,MAAM;IACT,CAAC,EAAE,KAAK;IACR,CAAC,EAAE,MAAM;IACT,CAAC,EAAE,IAAI;IACP,CAAC,EAAE,IAAI;IACP,CAAC,EAAE,KAAK;IACR,CAAC,EAAE,MAAM;IACT,CAAC,EAAE,MAAM;IACT,CAAC,EAAE,KAAK;IACR,CAAC,EAAE,KAAK;IACR,CAAC,EAAE,GAAG;IACN,CAAC,EAAE,KAAK;IACR,CAAC,EAAE,MAAM;IACT,CAAC,EAAE,KAAK;IACR,CAAC,EAAE,MAAM;IACT,CAAC,EAAE,MAAM;IACT,CAAC,EAAE,MAAM;IACT,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,OAAO;IACZ,GAAG,E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KAAK,CAAC,uBAAuB,CAAC,CAAC;IACvE,OAAO,KAAK;SACP,IAAI,EAAE;SACN,KAAK,CAAC,KAAK,CAAC;SACZ,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACP,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC7E,OAAO,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/C,CAAC,CAAC;SACD,IAAI,CAAC,EAAE,CAAC,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface GeoResult {
|
|
2
|
+
distance: {
|
|
3
|
+
km: number;
|
|
4
|
+
miles: number;
|
|
5
|
+
nauticalMiles: number;
|
|
6
|
+
};
|
|
7
|
+
bearing: {
|
|
8
|
+
degrees: number;
|
|
9
|
+
cardinal: string;
|
|
10
|
+
};
|
|
11
|
+
from: {
|
|
12
|
+
lat: number;
|
|
13
|
+
lon: number;
|
|
14
|
+
};
|
|
15
|
+
to: {
|
|
16
|
+
lat: number;
|
|
17
|
+
lon: number;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Calculates the great-circle distance and bearing between two geographic coordinates.
|
|
22
|
+
*
|
|
23
|
+
* @param lat1 - Latitude of the first point (-90 to 90)
|
|
24
|
+
* @param lon1 - Longitude of the first point (-180 to 180)
|
|
25
|
+
* @param lat2 - Latitude of the second point (-90 to 90)
|
|
26
|
+
* @param lon2 - Longitude of the second point (-180 to 180)
|
|
27
|
+
* @returns Distance in km/miles/nautical miles, compass bearing, and both coordinates
|
|
28
|
+
* @throws Error if any coordinate is out of range or not a number
|
|
29
|
+
*/
|
|
30
|
+
export default function geo(lat1: string, lon1: string, lat2: string, lon2: string): GeoResult;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { EARTH_RADIUS_KM } from '../../constants.js';
|
|
2
|
+
const CARDINALS = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW'];
|
|
3
|
+
function toRad(deg) {
|
|
4
|
+
return (deg * Math.PI) / 180;
|
|
5
|
+
}
|
|
6
|
+
function toDeg(rad) {
|
|
7
|
+
return (rad * 180) / Math.PI;
|
|
8
|
+
}
|
|
9
|
+
function parseCoord(value, name, min, max) {
|
|
10
|
+
const n = Number(value);
|
|
11
|
+
if (isNaN(n))
|
|
12
|
+
throw new Error(`${name} must be a number`);
|
|
13
|
+
if (n < min || n > max)
|
|
14
|
+
throw new Error(`${name} must be between ${min} and ${max}`);
|
|
15
|
+
return n;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Calculates the great-circle distance and bearing between two geographic coordinates.
|
|
19
|
+
*
|
|
20
|
+
* @param lat1 - Latitude of the first point (-90 to 90)
|
|
21
|
+
* @param lon1 - Longitude of the first point (-180 to 180)
|
|
22
|
+
* @param lat2 - Latitude of the second point (-90 to 90)
|
|
23
|
+
* @param lon2 - Longitude of the second point (-180 to 180)
|
|
24
|
+
* @returns Distance in km/miles/nautical miles, compass bearing, and both coordinates
|
|
25
|
+
* @throws Error if any coordinate is out of range or not a number
|
|
26
|
+
*/
|
|
27
|
+
export default function geo(lat1, lon1, lat2, lon2) {
|
|
28
|
+
const a = parseCoord(lat1, 'lat1', -90, 90);
|
|
29
|
+
const b = parseCoord(lon1, 'lon1', -180, 180);
|
|
30
|
+
const c = parseCoord(lat2, 'lat2', -90, 90);
|
|
31
|
+
const d = parseCoord(lon2, 'lon2', -180, 180);
|
|
32
|
+
const dLat = toRad(c - a);
|
|
33
|
+
const dLon = toRad(d - b);
|
|
34
|
+
const sa = Math.sin(dLat / 2) ** 2 + Math.cos(toRad(a)) * Math.cos(toRad(c)) * Math.sin(dLon / 2) ** 2;
|
|
35
|
+
const distance = 2 * EARTH_RADIUS_KM * Math.asin(Math.sqrt(sa));
|
|
36
|
+
const y = Math.sin(toRad(d - b)) * Math.cos(toRad(c));
|
|
37
|
+
const x = Math.cos(toRad(a)) * Math.sin(toRad(c)) - Math.sin(toRad(a)) * Math.cos(toRad(c)) * Math.cos(toRad(d - b));
|
|
38
|
+
const bearing = (toDeg(Math.atan2(y, x)) + 360) % 360;
|
|
39
|
+
const cardinal = CARDINALS[Math.round(bearing / 22.5) % 16];
|
|
40
|
+
return {
|
|
41
|
+
distance: {
|
|
42
|
+
km: +distance.toFixed(3),
|
|
43
|
+
miles: +(distance * 0.621371).toFixed(3),
|
|
44
|
+
nauticalMiles: +(distance * 0.539957).toFixed(3),
|
|
45
|
+
},
|
|
46
|
+
bearing: { degrees: +bearing.toFixed(2), cardinal },
|
|
47
|
+
from: { lat: a, lon: b },
|
|
48
|
+
to: { lat: c, lon: d },
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=geo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geo.js","sourceRoot":"","sources":["../../../src/modules/v4/geo.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;AAEvH,SAAS,KAAK,CAAC,GAAW;IACtB,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;AACjC,CAAC;AAED,SAAS,KAAK,CAAC,GAAW;IACtB,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;AACjC,CAAC;AAED,SAAS,UAAU,CAAC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O,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE;QACnD,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE;QACxB,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE;KACzB,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface HashResult {
|
|
2
|
+
method: string;
|
|
3
|
+
hash: string;
|
|
4
|
+
encoding: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Hashes a text string using the specified algorithm and encoding.
|
|
8
|
+
*
|
|
9
|
+
* @param text - The text to hash
|
|
10
|
+
* @param method - Hashing algorithm (e.g. "sha256", "md5")
|
|
11
|
+
* @param encoding - Output encoding: "hex" (default) or "base64"
|
|
12
|
+
* @returns Object containing the method, hash result, and encoding used
|
|
13
|
+
* @throws Error if text is missing, the method is unsupported, or the encoding is invalid
|
|
14
|
+
*/
|
|
15
|
+
export default function hash(text: string, method: string, encoding?: string): HashResult;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createHash, getHashes } from 'crypto';
|
|
2
|
+
const ENCODINGS = new Set(['hex', 'base64']);
|
|
3
|
+
/**
|
|
4
|
+
* Hashes a text string using the specified algorithm and encoding.
|
|
5
|
+
*
|
|
6
|
+
* @param text - The text to hash
|
|
7
|
+
* @param method - Hashing algorithm (e.g. "sha256", "md5")
|
|
8
|
+
* @param encoding - Output encoding: "hex" (default) or "base64"
|
|
9
|
+
* @returns Object containing the method, hash result, and encoding used
|
|
10
|
+
* @throws Error if text is missing, the method is unsupported, or the encoding is invalid
|
|
11
|
+
*/
|
|
12
|
+
export default function hash(text, method, encoding = 'hex') {
|
|
13
|
+
if (!text)
|
|
14
|
+
throw new Error('Text is required');
|
|
15
|
+
const methods = getHashes();
|
|
16
|
+
if (!methods.includes(method))
|
|
17
|
+
throw new Error(`Unsupported method. Use one of: ${methods.join(', ')}`);
|
|
18
|
+
if (!ENCODINGS.has(encoding))
|
|
19
|
+
throw new Error('Encoding must be one of: hex, base64');
|
|
20
|
+
const result = createHash(method)
|
|
21
|
+
.update(text)
|
|
22
|
+
.digest(encoding);
|
|
23
|
+
return { method, hash: result, encoding };
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../../src/modules/v4/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAQ/C,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;AAE7C;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,IAAY,EAAE,MAAc,EAAE,WAAmB,KAAK;IAC/E,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAE/C,MAAM,OAAO,GAAG,SAAS,EAAE,CAAC;IAC5B,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAExG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAEtF,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;SAC5B,MAAM,CAAC,IAAI,CAAC;SACZ,MAAM,CAAC,QAA4B,CAAC,CAAC;IAC1C,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
interface CalendarEvent {
|
|
2
|
+
summary: string[] | string;
|
|
3
|
+
subject?: string;
|
|
4
|
+
teacher?: string;
|
|
5
|
+
classes?: string[];
|
|
6
|
+
type?: string;
|
|
7
|
+
start: string;
|
|
8
|
+
end: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Fetches and parses an ICS calendar from a Hyperplanning URL, filtering out past events.
|
|
12
|
+
*
|
|
13
|
+
* @param url - HTTPS URL to the ICS calendar
|
|
14
|
+
* @param detail - Level of detail: "full" (subject/teacher/classes), "list" (summary/times), or default (summary only)
|
|
15
|
+
* @returns Array of calendar events sorted by start time, excluding past events
|
|
16
|
+
* @throws Error if the URL is invalid, uses HTTP, points to a private host, or does not return a valid ICS file
|
|
17
|
+
*/
|
|
18
|
+
export default function hyperplanning(url: string, detail?: string): Promise<CalendarEvent[]>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import ical from 'ical.js';
|
|
2
|
+
import { formatDate } from '../../utils/helpers.js';
|
|
3
|
+
function blocked(hostname) {
|
|
4
|
+
const list = ['localhost', '127.0.0.1', '0.0.0.0', '[::1]', 'metadata.google.internal'];
|
|
5
|
+
if (list.includes(hostname))
|
|
6
|
+
return true;
|
|
7
|
+
const parts = hostname.split('.').map(Number);
|
|
8
|
+
if (parts.length === 4 && parts.every((n) => !isNaN(n))) {
|
|
9
|
+
if (parts[0] === 10)
|
|
10
|
+
return true;
|
|
11
|
+
if (parts[0] === 172 && parts[1] >= 16 && parts[1] <= 31)
|
|
12
|
+
return true;
|
|
13
|
+
if (parts[0] === 192 && parts[1] === 168)
|
|
14
|
+
return true;
|
|
15
|
+
if (parts[0] === 169 && parts[1] === 254)
|
|
16
|
+
return true;
|
|
17
|
+
if (parts[0] === 0)
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Fetches and parses an ICS calendar from a Hyperplanning URL, filtering out past events.
|
|
24
|
+
*
|
|
25
|
+
* @param url - HTTPS URL to the ICS calendar
|
|
26
|
+
* @param detail - Level of detail: "full" (subject/teacher/classes), "list" (summary/times), or default (summary only)
|
|
27
|
+
* @returns Array of calendar events sorted by start time, excluding past events
|
|
28
|
+
* @throws Error if the URL is invalid, uses HTTP, points to a private host, or does not return a valid ICS file
|
|
29
|
+
*/
|
|
30
|
+
export default async function hyperplanning(url, detail) {
|
|
31
|
+
let parsed;
|
|
32
|
+
try {
|
|
33
|
+
parsed = new URL(url);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
throw new Error('Invalid URL.');
|
|
37
|
+
}
|
|
38
|
+
if (parsed.protocol !== 'https:')
|
|
39
|
+
throw new Error('Only HTTPS URLs are allowed.');
|
|
40
|
+
if (blocked(parsed.hostname))
|
|
41
|
+
throw new Error('Access to private/internal hosts is not allowed.');
|
|
42
|
+
const response = await fetch(url, { signal: AbortSignal.timeout(10_000) });
|
|
43
|
+
if (!response.ok || !(response.headers.get('content-type') || '').includes('text/calendar')) {
|
|
44
|
+
throw new Error('Invalid ICS file format.');
|
|
45
|
+
}
|
|
46
|
+
const events = new ical.Component(ical.parse(await response.text()))
|
|
47
|
+
.getAllSubcomponents('vevent')
|
|
48
|
+
.map((e) => {
|
|
49
|
+
const evt = new ical.Event(e);
|
|
50
|
+
const summary = (evt.summary || '').split(' ').filter((part) => part !== '-');
|
|
51
|
+
const start = formatDate(evt.startDate.toJSDate());
|
|
52
|
+
const end = formatDate(evt.endDate.toJSDate());
|
|
53
|
+
if (detail === 'full') {
|
|
54
|
+
const desc = (evt.description || '').split('\n').map((l) => l.trim());
|
|
55
|
+
const extract = (p) => (desc.find((l) => l.startsWith(p)) || '').replace(p, '').trim();
|
|
56
|
+
return {
|
|
57
|
+
summary,
|
|
58
|
+
subject: extract('Matière :'),
|
|
59
|
+
teacher: extract('Enseignant :'),
|
|
60
|
+
classes: extract('Promotions :')
|
|
61
|
+
.split(', ')
|
|
62
|
+
.map((c) => c.trim()),
|
|
63
|
+
type: extract('Salle :') || undefined,
|
|
64
|
+
start,
|
|
65
|
+
end,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (detail === 'list')
|
|
69
|
+
return { summary, start, end };
|
|
70
|
+
return {
|
|
71
|
+
summary: evt.summary || '',
|
|
72
|
+
start,
|
|
73
|
+
end,
|
|
74
|
+
};
|
|
75
|
+
})
|
|
76
|
+
.sort((a, b) => new Date(a.start).getTime() - new Date(b.start).getTime())
|
|
77
|
+
.filter((e) => new Date(e.end) >= new Date());
|
|
78
|
+
return events;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=hyperplanning.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hyperplanning.js","sourceRoot":"","sources":["../../../src/modules/v4/hyperplanning.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,SAAS,CAAC;AAE3B,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAYpD,SAAS,OAAO,CAAC,QAAgB;IAC7B,MAAM,IAAI,GAAG,CAAC,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,0BAA0B,CAAC,CAAC;IACxF,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,IAAI,CAAC;IAEzC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9C,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACtD,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE;YAAE,OAAO,IAAI,CAAC;QACjC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,CAAC,CAAE,IAAI,EAAE,IAAI,KAAK,CAAC,CAAC,CAAE,IA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AC,IAAI,CAAC;qBACX,GAAG,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;gBACjC,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,IAAI,SAAS;gBACrC,KAAK;gBACL,GAAG;aACN,CAAC;QACN,CAAC;QAED,IAAI,MAAM,KAAK,MAAM;YAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;QAEtD,OAAO;YACH,OAAO,EAAE,GAAG,CAAC,OAAO,IAAI,EAAE;YAC1B,KAAK;YACL,GAAG;SACN,CAAC;IACN,CAAC,CAAC;SACD,IAAI,CAAC,CAAC,CAAgB,EAAE,CAAgB,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;SACvG,MAAM,CAAC,CAAC,CAAgB,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC;IAEjE,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface IpResult {
|
|
2
|
+
ip: string;
|
|
3
|
+
version: 'IPv4' | 'IPv6';
|
|
4
|
+
type: 'public' | 'private' | 'loopback' | 'link-local' | 'multicast' | 'broadcast';
|
|
5
|
+
class?: 'A' | 'B' | 'C' | 'D' | 'E';
|
|
6
|
+
range?: string;
|
|
7
|
+
binary: string;
|
|
8
|
+
decimal?: number;
|
|
9
|
+
reverse: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Analyzes an IPv4 or IPv6 address and returns its type, class, binary
|
|
13
|
+
* representation, decimal value, and reverse DNS notation.
|
|
14
|
+
*
|
|
15
|
+
* @param address - The IP address to analyze
|
|
16
|
+
* @returns Detailed breakdown of the address
|
|
17
|
+
* @throws Error if the address is missing or invalid
|
|
18
|
+
*/
|
|
19
|
+
export default function ip(address: string): IpResult;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { MAX_STRING_LENGTH } from '../../constants.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parses and analyzes an IPv4 address.
|
|
4
|
+
*
|
|
5
|
+
* @param raw - The IPv4 address string (e.g. "192.168.1.1")
|
|
6
|
+
* @returns Detailed information about the address
|
|
7
|
+
* @throws Error if the address is malformed
|
|
8
|
+
*/
|
|
9
|
+
function parseIPv4(raw) {
|
|
10
|
+
const parts = raw.split('.');
|
|
11
|
+
if (parts.length !== 4)
|
|
12
|
+
throw new Error('Invalid IPv4 address');
|
|
13
|
+
const octets = parts.map(Number);
|
|
14
|
+
if (octets.some((o) => isNaN(o) || !Number.isInteger(o) || o < 0 || o > 255))
|
|
15
|
+
throw new Error('Invalid IPv4 address');
|
|
16
|
+
const [a, b, c, d] = octets;
|
|
17
|
+
let cls;
|
|
18
|
+
if (a < 128)
|
|
19
|
+
cls = 'A';
|
|
20
|
+
else if (a < 192)
|
|
21
|
+
cls = 'B';
|
|
22
|
+
else if (a < 224)
|
|
23
|
+
cls = 'C';
|
|
24
|
+
else if (a < 240)
|
|
25
|
+
cls = 'D';
|
|
26
|
+
else
|
|
27
|
+
cls = 'E';
|
|
28
|
+
let type = 'public';
|
|
29
|
+
let range;
|
|
30
|
+
if (a === 127) {
|
|
31
|
+
type = 'loopback';
|
|
32
|
+
range = '127.0.0.0/8';
|
|
33
|
+
}
|
|
34
|
+
else if (a === 10) {
|
|
35
|
+
type = 'private';
|
|
36
|
+
range = '10.0.0.0/8';
|
|
37
|
+
}
|
|
38
|
+
else if (a === 172 && b >= 16 && b <= 31) {
|
|
39
|
+
type = 'private';
|
|
40
|
+
range = '172.16.0.0/12';
|
|
41
|
+
}
|
|
42
|
+
else if (a === 192 && b === 168) {
|
|
43
|
+
type = 'private';
|
|
44
|
+
range = '192.168.0.0/16';
|
|
45
|
+
}
|
|
46
|
+
else if (a === 169 && b === 254) {
|
|
47
|
+
type = 'link-local';
|
|
48
|
+
range = '169.254.0.0/16';
|
|
49
|
+
}
|
|
50
|
+
else if (a >= 224 && a <= 239) {
|
|
51
|
+
type = 'multicast';
|
|
52
|
+
range = '224.0.0.0/4';
|
|
53
|
+
}
|
|
54
|
+
else if (raw === '255.255.255.255') {
|
|
55
|
+
type = 'broadcast';
|
|
56
|
+
}
|
|
57
|
+
const binary = octets.map((o) => o.toString(2).padStart(8, '0')).join('.');
|
|
58
|
+
const decimal = ((a << 24) | (b << 16) | (c << 8) | d) >>> 0;
|
|
59
|
+
const reverse = [...octets].reverse().join('.') + '.in-addr.arpa';
|
|
60
|
+
const result = { ip: raw, version: 'IPv4', type, class: cls, binary, decimal, reverse };
|
|
61
|
+
if (range)
|
|
62
|
+
result.range = range;
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Parses and analyzes an IPv6 address, expanding :: shorthand.
|
|
67
|
+
*
|
|
68
|
+
* @param raw - The IPv6 address string (e.g. "::1" or "fe80::1")
|
|
69
|
+
* @returns Detailed information about the address
|
|
70
|
+
* @throws Error if the address is malformed
|
|
71
|
+
*/
|
|
72
|
+
function parseIPv6(raw) {
|
|
73
|
+
let expanded = raw;
|
|
74
|
+
if (raw.includes('::')) {
|
|
75
|
+
const halves = raw.split('::');
|
|
76
|
+
const left = halves[0] ? halves[0].split(':') : [];
|
|
77
|
+
const right = halves[1] ? halves[1].split(':') : [];
|
|
78
|
+
const fill = Array(8 - left.length - right.length).fill('0');
|
|
79
|
+
expanded = [...left, ...fill, ...right].join(':');
|
|
80
|
+
}
|
|
81
|
+
const groups = expanded.split(':');
|
|
82
|
+
if (groups.length !== 8)
|
|
83
|
+
throw new Error('Invalid IPv6 address');
|
|
84
|
+
const values = groups.map((g) => parseInt(g || '0', 16));
|
|
85
|
+
if (values.some((v) => isNaN(v) || v < 0 || v > 0xffff))
|
|
86
|
+
throw new Error('Invalid IPv6 address');
|
|
87
|
+
let type = 'public';
|
|
88
|
+
let range;
|
|
89
|
+
if (raw === '::1' || values.every((v, i) => (i < 7 ? v === 0 : v === 1))) {
|
|
90
|
+
type = 'loopback';
|
|
91
|
+
range = '::1/128';
|
|
92
|
+
}
|
|
93
|
+
else if ((values[0] & 0xfe00) === 0xfc00) {
|
|
94
|
+
type = 'private';
|
|
95
|
+
range = 'fc00::/7';
|
|
96
|
+
}
|
|
97
|
+
else if ((values[0] & 0xffc0) === 0xfe80) {
|
|
98
|
+
type = 'link-local';
|
|
99
|
+
range = 'fe80::/10';
|
|
100
|
+
}
|
|
101
|
+
else if ((values[0] & 0xff00) === 0xff00) {
|
|
102
|
+
type = 'multicast';
|
|
103
|
+
range = 'ff00::/8';
|
|
104
|
+
}
|
|
105
|
+
const binary = values.map((v) => v.toString(2).padStart(16, '0')).join(':');
|
|
106
|
+
const hex = values.map((v) => v.toString(16).padStart(4, '0')).join('');
|
|
107
|
+
const reverse = hex.split('').reverse().join('.') + '.ip6.arpa';
|
|
108
|
+
const result = { ip: expanded, version: 'IPv6', type, binary, reverse };
|
|
109
|
+
if (range)
|
|
110
|
+
result.range = range;
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Analyzes an IPv4 or IPv6 address and returns its type, class, binary
|
|
115
|
+
* representation, decimal value, and reverse DNS notation.
|
|
116
|
+
*
|
|
117
|
+
* @param address - The IP address to analyze
|
|
118
|
+
* @returns Detailed breakdown of the address
|
|
119
|
+
* @throws Error if the address is missing or invalid
|
|
120
|
+
*/
|
|
121
|
+
export default function ip(address) {
|
|
122
|
+
if (!address || typeof address !== 'string')
|
|
123
|
+
throw new Error('An IP address is required');
|
|
124
|
+
if (address.length > MAX_STRING_LENGTH)
|
|
125
|
+
throw new Error('Address is too long');
|
|
126
|
+
if (address.includes(':'))
|
|
127
|
+
return parseIPv6(address);
|
|
128
|
+
if (address.includes('.'))
|
|
129
|
+
return parseIPv4(address);
|
|
130
|
+
throw new Error('Invalid IP address format');
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=ip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ip.js","sourceRoot":"","sources":["../../../src/modules/v4/ip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAavD;;;;;;GAMG;AACH,SAAS,SAAS,CAAC,GAAW;IAC1B,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAChE,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACjC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;QACxE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAE5C,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,MAA0C,CAAC;IAEhE,IAAI,GAAgC,CAAC;IACrC,IAAI,CAAC,GAAG,GAAG;QAAE,GAAG,GAAG,GAAG,CAAC;SAClB,IAAI,CAAC,GAAG,GAAG;QAAE,GAAG,GAAG,GAAG,CAAC;SACvB,IAAI,CAAC,GAAG,GAAG;QAAE,GAAG,GAAG,GAAG,CAAC;SACvB,IAAI,CAAC,GAAG,GAAG;QAAE,GAAG,GAAG,GAAG,CAAC;;QACvB,GAAG,GAAG,GAAG,CAAC;IAEf,IAAI,IAAI,GAAqB,QAAQ,CAAC;IACtC,IAAI,KAAyB,CAAC;IAE9B,IAA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