@20syldev/api 4.8.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +93 -55
- package/dist/config/versions.js +16 -0
- package/dist/config/versions.js.map +1 -1
- package/dist/constants.js +5 -0
- package/dist/constants.js.map +1 -1
- package/dist/modules/v5/chart.js +379 -0
- package/dist/modules/v5/chart.js.map +1 -0
- package/dist/modules/v5/evaluate.js +281 -0
- package/dist/modules/v5/evaluate.js.map +1 -0
- package/dist/modules/v5/matrix.js +238 -0
- package/dist/modules/v5/matrix.js.map +1 -0
- package/dist/modules/v5.js +5 -0
- package/dist/modules/v5.js.map +1 -0
- package/dist/routes/get.js +191 -162
- package/dist/routes/get.js.map +1 -1
- package/dist/routes/post.js +69 -0
- package/dist/routes/post.js.map +1 -1
- package/package.json +4 -2
- package/recap.md +98 -0
- package/.github/FUNDING.yml +0 -1
- package/.prettierrc +0 -7
- package/eslint.config.js +0 -24
- package/robots.txt +0 -74
- package/src/app.ts +0 -53
- package/src/config/env.ts +0 -87
- package/src/config/plans.ts +0 -61
- package/src/config/versions.ts +0 -121
- package/src/constants.ts +0 -61
- package/src/favicon.ico +0 -0
- package/src/middleware/cors.ts +0 -23
- package/src/middleware/error.ts +0 -16
- package/src/middleware/json.ts +0 -9
- package/src/middleware/logger.ts +0 -32
- package/src/middleware/ratelimit.ts +0 -89
- package/src/middleware/version.ts +0 -40
- package/src/modules/v3/algorithms.js +0 -218
- package/src/modules/v3/captcha.js +0 -60
- package/src/modules/v3/chat.js +0 -111
- package/src/modules/v3/color.js +0 -60
- package/src/modules/v3/convert.js +0 -39
- package/src/modules/v3/domain.js +0 -86
- package/src/modules/v3/hash.js +0 -16
- package/src/modules/v3/hyperplanning.js +0 -56
- package/src/modules/v3/levenshtein.js +0 -46
- package/src/modules/v3/personal.js +0 -139
- package/src/modules/v3/qrcode.js +0 -20
- package/src/modules/v3/tic_tac_toe.js +0 -242
- package/src/modules/v3/time.js +0 -98
- package/src/modules/v3/token.js +0 -54
- package/src/modules/v3/username.js +0 -94
- package/src/modules/v3/utils.js +0 -77
- package/src/modules/v3.js +0 -15
- package/src/modules/v4/address.ts +0 -412
- package/src/modules/v4/agent.ts +0 -104
- package/src/modules/v4/algorithms.ts +0 -276
- package/src/modules/v4/captcha.ts +0 -114
- package/src/modules/v4/chat.ts +0 -130
- package/src/modules/v4/color.ts +0 -75
- package/src/modules/v4/convert.ts +0 -127
- package/src/modules/v4/cron.ts +0 -221
- package/src/modules/v4/dice.ts +0 -46
- package/src/modules/v4/domain.ts +0 -86
- package/src/modules/v4/encode.ts +0 -241
- package/src/modules/v4/geo.ts +0 -64
- package/src/modules/v4/hash.ts +0 -32
- package/src/modules/v4/hyperplanning.ts +0 -93
- package/src/modules/v4/ip.ts +0 -134
- package/src/modules/v4/levenshtein.ts +0 -46
- package/src/modules/v4/palette.ts +0 -71
- package/src/modules/v4/password.ts +0 -379
- package/src/modules/v4/personal.ts +0 -140
- package/src/modules/v4/placeholder.ts +0 -197
- package/src/modules/v4/qrcode.ts +0 -121
- package/src/modules/v4/regex.ts +0 -67
- package/src/modules/v4/statistics.ts +0 -62
- package/src/modules/v4/text.ts +0 -330
- package/src/modules/v4/tic_tac_toe.ts +0 -264
- package/src/modules/v4/time.ts +0 -149
- package/src/modules/v4/token.ts +0 -53
- package/src/modules/v4/username.ts +0 -94
- package/src/modules/v4/validate.ts +0 -76
- package/src/modules/v4.ts +0 -29
- package/src/routes/delete.ts +0 -72
- package/src/routes/get.ts +0 -856
- package/src/routes/index.ts +0 -59
- package/src/routes/patch.ts +0 -45
- package/src/routes/post.ts +0 -209
- package/src/storage/index.ts +0 -16
- package/src/types/express.d.ts +0 -17
- package/src/types/storage.ts +0 -48
- package/src/utils/colors.ts +0 -91
- package/src/utils/helpers.ts +0 -90
- package/src/utils/response.ts +0 -28
- package/tests/integration/api.test.ts +0 -772
- package/tests/tsconfig.json +0 -3
- package/tests/unit/address.test.ts +0 -84
- package/tests/unit/agent.test.ts +0 -113
- package/tests/unit/algorithms.test.ts +0 -121
- package/tests/unit/captcha.test.ts +0 -62
- package/tests/unit/chat.test.ts +0 -54
- package/tests/unit/color.test.ts +0 -54
- package/tests/unit/convert.test.ts +0 -68
- package/tests/unit/cron.test.ts +0 -110
- package/tests/unit/dice.test.ts +0 -58
- package/tests/unit/domain.test.ts +0 -48
- package/tests/unit/encode.test.ts +0 -109
- package/tests/unit/geo.test.ts +0 -46
- package/tests/unit/hash.test.ts +0 -45
- package/tests/unit/hyperplanning.test.ts +0 -97
- package/tests/unit/ip.test.ts +0 -140
- package/tests/unit/levenshtein.test.ts +0 -35
- package/tests/unit/palette.test.ts +0 -54
- package/tests/unit/password.test.ts +0 -86
- package/tests/unit/personal.test.ts +0 -66
- package/tests/unit/placeholder.test.ts +0 -58
- package/tests/unit/qrcode.test.ts +0 -83
- package/tests/unit/regex.test.ts +0 -95
- package/tests/unit/statistics.test.ts +0 -58
- package/tests/unit/text.test.ts +0 -108
- package/tests/unit/tic_tac_toe.test.ts +0 -56
- package/tests/unit/time.test.ts +0 -115
- package/tests/unit/token.test.ts +0 -62
- package/tests/unit/username.test.ts +0 -35
- package/tests/unit/validate.test.ts +0 -72
- package/tsconfig.json +0 -17
- package/tsconfig.test.json +0 -9
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { MAX_EXPR_DEPTH, MAX_EXPR_LENGTH } from '../../constants.js';
|
|
2
|
+
function tokenize(expr) {
|
|
3
|
+
const tokens = [];
|
|
4
|
+
let i = 0;
|
|
5
|
+
while (i < expr.length) {
|
|
6
|
+
const ch = expr[i];
|
|
7
|
+
if (' \t\r\n'.includes(ch)) {
|
|
8
|
+
i++;
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
if ((ch >= '0' && ch <= '9') || ch === '.') {
|
|
12
|
+
let num = '';
|
|
13
|
+
while (i < expr.length && ((expr[i] >= '0' && expr[i] <= '9') || expr[i] === '.')) {
|
|
14
|
+
num += expr[i++];
|
|
15
|
+
}
|
|
16
|
+
tokens.push({ type: 'NUMBER', value: num });
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch === '_') {
|
|
20
|
+
let ident = '';
|
|
21
|
+
while (i < expr.length &&
|
|
22
|
+
((expr[i] >= 'a' && expr[i] <= 'z') ||
|
|
23
|
+
(expr[i] >= 'A' && expr[i] <= 'Z') ||
|
|
24
|
+
expr[i] === '_' ||
|
|
25
|
+
(expr[i] >= '0' && expr[i] <= '9'))) {
|
|
26
|
+
ident += expr[i++];
|
|
27
|
+
}
|
|
28
|
+
tokens.push({ type: 'IDENT', value: ident });
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if ('+-*/%^'.includes(ch)) {
|
|
32
|
+
tokens.push({ type: 'OP', value: ch });
|
|
33
|
+
i++;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (ch === '(') {
|
|
37
|
+
tokens.push({ type: 'LPAREN', value: '(' });
|
|
38
|
+
i++;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (ch === ')') {
|
|
42
|
+
tokens.push({ type: 'RPAREN', value: ')' });
|
|
43
|
+
i++;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (ch === ',') {
|
|
47
|
+
tokens.push({ type: 'COMMA', value: ',' });
|
|
48
|
+
i++;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
throw new Error(`Unexpected character: '${ch}'`);
|
|
52
|
+
}
|
|
53
|
+
return tokens;
|
|
54
|
+
}
|
|
55
|
+
// ─── Binding powers ───
|
|
56
|
+
const LEFT_BP = { '+': 10, '-': 10, '*': 20, '/': 20, '%': 20, '^': 31 };
|
|
57
|
+
const RIGHT_BP = { '+': 10, '-': 10, '*': 20, '/': 20, '%': 20, '^': 30 };
|
|
58
|
+
const CONSTANTS = { pi: Math.PI, e: Math.E };
|
|
59
|
+
const FUNCTIONS = new Set([
|
|
60
|
+
'sqrt',
|
|
61
|
+
'abs',
|
|
62
|
+
'ceil',
|
|
63
|
+
'floor',
|
|
64
|
+
'round',
|
|
65
|
+
'sin',
|
|
66
|
+
'cos',
|
|
67
|
+
'tan',
|
|
68
|
+
'log',
|
|
69
|
+
'log2',
|
|
70
|
+
'log10',
|
|
71
|
+
'exp',
|
|
72
|
+
'min',
|
|
73
|
+
'max',
|
|
74
|
+
]);
|
|
75
|
+
// ─── Parser ───
|
|
76
|
+
class Parser {
|
|
77
|
+
tokens;
|
|
78
|
+
pos = 0;
|
|
79
|
+
depth = 0;
|
|
80
|
+
constructor(tokens) {
|
|
81
|
+
this.tokens = tokens;
|
|
82
|
+
}
|
|
83
|
+
peek() {
|
|
84
|
+
return this.tokens[this.pos];
|
|
85
|
+
}
|
|
86
|
+
consume() {
|
|
87
|
+
const t = this.tokens[this.pos];
|
|
88
|
+
if (!t)
|
|
89
|
+
throw new Error('Unexpected end of expression');
|
|
90
|
+
this.pos++;
|
|
91
|
+
return t;
|
|
92
|
+
}
|
|
93
|
+
expect(type) {
|
|
94
|
+
const t = this.consume();
|
|
95
|
+
if (t.type !== type)
|
|
96
|
+
throw new Error(`Expected ${type}, got ${t.type} ('${t.value}')`);
|
|
97
|
+
return t;
|
|
98
|
+
}
|
|
99
|
+
parse(minBp = 0) {
|
|
100
|
+
if (++this.depth > MAX_EXPR_DEPTH)
|
|
101
|
+
throw new Error('Expression is too deeply nested');
|
|
102
|
+
let left = this.parsePrefix();
|
|
103
|
+
while (true) {
|
|
104
|
+
const t = this.peek();
|
|
105
|
+
if (!t || t.type !== 'OP')
|
|
106
|
+
break;
|
|
107
|
+
const lbp = LEFT_BP[t.value];
|
|
108
|
+
if (lbp === undefined || lbp <= minBp)
|
|
109
|
+
break;
|
|
110
|
+
this.consume();
|
|
111
|
+
const rbp = RIGHT_BP[t.value];
|
|
112
|
+
const right = this.parse(rbp);
|
|
113
|
+
left = { kind: 'binary', op: t.value, left, right };
|
|
114
|
+
}
|
|
115
|
+
this.depth--;
|
|
116
|
+
return left;
|
|
117
|
+
}
|
|
118
|
+
parsePrefix() {
|
|
119
|
+
const t = this.peek();
|
|
120
|
+
if (!t)
|
|
121
|
+
throw new Error('Unexpected end of expression');
|
|
122
|
+
// Unary +/-
|
|
123
|
+
if (t.type === 'OP' && (t.value === '+' || t.value === '-')) {
|
|
124
|
+
this.consume();
|
|
125
|
+
const operand = this.parse(40);
|
|
126
|
+
if (t.value === '+')
|
|
127
|
+
return operand;
|
|
128
|
+
return { kind: 'unary', op: '-', operand };
|
|
129
|
+
}
|
|
130
|
+
// Number
|
|
131
|
+
if (t.type === 'NUMBER') {
|
|
132
|
+
this.consume();
|
|
133
|
+
const v = parseFloat(t.value);
|
|
134
|
+
if (isNaN(v))
|
|
135
|
+
throw new Error(`Invalid number: ${t.value}`);
|
|
136
|
+
return { kind: 'number', value: v };
|
|
137
|
+
}
|
|
138
|
+
// Parenthesized expression
|
|
139
|
+
if (t.type === 'LPAREN') {
|
|
140
|
+
this.consume();
|
|
141
|
+
const node = this.parse(0);
|
|
142
|
+
this.expect('RPAREN');
|
|
143
|
+
return node;
|
|
144
|
+
}
|
|
145
|
+
// Identifier: constant or function call
|
|
146
|
+
if (t.type === 'IDENT') {
|
|
147
|
+
this.consume();
|
|
148
|
+
const name = t.value;
|
|
149
|
+
// Function call
|
|
150
|
+
if (this.peek()?.type === 'LPAREN') {
|
|
151
|
+
if (!FUNCTIONS.has(name))
|
|
152
|
+
throw new Error(`Unknown function: '${name}'`);
|
|
153
|
+
this.consume(); // (
|
|
154
|
+
const args = [];
|
|
155
|
+
if (this.peek()?.type !== 'RPAREN') {
|
|
156
|
+
args.push(this.parse(0));
|
|
157
|
+
while (this.peek()?.type === 'COMMA') {
|
|
158
|
+
this.consume();
|
|
159
|
+
args.push(this.parse(0));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
this.expect('RPAREN');
|
|
163
|
+
return { kind: 'call', name, args };
|
|
164
|
+
}
|
|
165
|
+
// Constant
|
|
166
|
+
if (Object.hasOwn(CONSTANTS, name))
|
|
167
|
+
return { kind: 'const', name };
|
|
168
|
+
throw new Error(`Unknown identifier: '${name}'`);
|
|
169
|
+
}
|
|
170
|
+
throw new Error(`Unexpected token: '${t.value}'`);
|
|
171
|
+
}
|
|
172
|
+
run() {
|
|
173
|
+
const ast = this.parse(0);
|
|
174
|
+
if (this.pos < this.tokens.length) {
|
|
175
|
+
throw new Error(`Unexpected token after expression: '${this.tokens[this.pos].value}'`);
|
|
176
|
+
}
|
|
177
|
+
return ast;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
// ─── Evaluator ───
|
|
181
|
+
function evalNode(node) {
|
|
182
|
+
switch (node.kind) {
|
|
183
|
+
case 'number':
|
|
184
|
+
return node.value;
|
|
185
|
+
case 'const':
|
|
186
|
+
return CONSTANTS[node.name];
|
|
187
|
+
case 'unary':
|
|
188
|
+
return -evalNode(node.operand);
|
|
189
|
+
case 'binary': {
|
|
190
|
+
const l = evalNode(node.left);
|
|
191
|
+
const r = evalNode(node.right);
|
|
192
|
+
switch (node.op) {
|
|
193
|
+
case '+':
|
|
194
|
+
return l + r;
|
|
195
|
+
case '-':
|
|
196
|
+
return l - r;
|
|
197
|
+
case '*':
|
|
198
|
+
return l * r;
|
|
199
|
+
case '/':
|
|
200
|
+
if (r === 0)
|
|
201
|
+
throw new Error('Division by zero');
|
|
202
|
+
return l / r;
|
|
203
|
+
case '%':
|
|
204
|
+
if (r === 0)
|
|
205
|
+
throw new Error('Division by zero');
|
|
206
|
+
return l % r;
|
|
207
|
+
case '^':
|
|
208
|
+
return Math.pow(l, r);
|
|
209
|
+
default:
|
|
210
|
+
throw new Error(`Unknown operator: '${node.op}'`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
case 'call': {
|
|
214
|
+
const args = node.args.map(evalNode);
|
|
215
|
+
switch (node.name) {
|
|
216
|
+
case 'sqrt':
|
|
217
|
+
return Math.sqrt(args[0]);
|
|
218
|
+
case 'abs':
|
|
219
|
+
return Math.abs(args[0]);
|
|
220
|
+
case 'ceil':
|
|
221
|
+
return Math.ceil(args[0]);
|
|
222
|
+
case 'floor':
|
|
223
|
+
return Math.floor(args[0]);
|
|
224
|
+
case 'round':
|
|
225
|
+
return Math.round(args[0]);
|
|
226
|
+
case 'sin':
|
|
227
|
+
return Math.sin(args[0]);
|
|
228
|
+
case 'cos':
|
|
229
|
+
return Math.cos(args[0]);
|
|
230
|
+
case 'tan':
|
|
231
|
+
return Math.tan(args[0]);
|
|
232
|
+
case 'log':
|
|
233
|
+
return Math.log(args[0]);
|
|
234
|
+
case 'log2':
|
|
235
|
+
return Math.log2(args[0]);
|
|
236
|
+
case 'log10':
|
|
237
|
+
return Math.log10(args[0]);
|
|
238
|
+
case 'exp':
|
|
239
|
+
return Math.exp(args[0]);
|
|
240
|
+
case 'min':
|
|
241
|
+
if (args.length !== 2)
|
|
242
|
+
throw new Error('min() requires exactly 2 arguments');
|
|
243
|
+
return Math.min(args[0], args[1]);
|
|
244
|
+
case 'max':
|
|
245
|
+
if (args.length !== 2)
|
|
246
|
+
throw new Error('max() requires exactly 2 arguments');
|
|
247
|
+
return Math.max(args[0], args[1]);
|
|
248
|
+
default:
|
|
249
|
+
throw new Error(`Unknown function: '${node.name}'`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Evaluates a mathematical expression string and returns the result.
|
|
256
|
+
*
|
|
257
|
+
* @param expr - Math expression; supports +, -, *, /, %, ^, unary -, parentheses, constants (pi, e) and functions (sin, cos, tan, sqrt, abs, ceil, floor, round, log, log2, log10, exp, min, max)
|
|
258
|
+
* @param precision - Number of decimal places in the result (0–15, default 10)
|
|
259
|
+
* @returns Object with the original expression, numeric result, and applied precision
|
|
260
|
+
* @throws Error if the expression is empty, exceeds the maximum length, contains unknown identifiers, or produces a non-finite result
|
|
261
|
+
*/
|
|
262
|
+
export default function evaluate(expr, precision) {
|
|
263
|
+
if (!expr || typeof expr !== 'string' || expr.trim() === '') {
|
|
264
|
+
throw new Error('Please provide a math expression');
|
|
265
|
+
}
|
|
266
|
+
if (expr.length > MAX_EXPR_LENGTH) {
|
|
267
|
+
throw new Error(`Expression cannot exceed ${MAX_EXPR_LENGTH} characters`);
|
|
268
|
+
}
|
|
269
|
+
const prec = Math.min(15, Math.max(0, precision !== undefined ? Math.floor(precision) : 10));
|
|
270
|
+
const tokens = tokenize(expr.trim());
|
|
271
|
+
if (tokens.length === 0)
|
|
272
|
+
throw new Error('Please provide a math expression');
|
|
273
|
+
const parser = new Parser(tokens);
|
|
274
|
+
const ast = parser.run();
|
|
275
|
+
const raw = evalNode(ast);
|
|
276
|
+
if (!isFinite(raw))
|
|
277
|
+
throw new Error('Result is not finite (overflow or undefined operation)');
|
|
278
|
+
const result = Number(raw.toFixed(prec));
|
|
279
|
+
return { expression: expr, result, precision: prec };
|
|
280
|
+
}
|
|
281
|
+
//# sourceMappingURL=evaluate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluate.js","sourceRoot":"","sources":["../../../src/modules/v5/evaluate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAgBrE,SAAS,QAAQ,CAAC,IAAY;IAC1B,MAAM,MAAM,GAAY,EAAE,CAAC;IAC3B,IAAI,CAAC,GAAG,CAAC,CAAC;IAEV,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QACrB,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC;QAEpB,IAAI,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;YACzB,CAAC,EAAE,CAAC;YACJ,SAAS;QACb,CAAC;QAED,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,EAAE,IAAI,GAAG,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,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAE9F,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAEzC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { MAX_MATRIX_SIZE } from '../../constants.js';
|
|
2
|
+
// ─── Validation ───
|
|
3
|
+
function validateMatrix(m, name = 'matrix') {
|
|
4
|
+
if (!Array.isArray(m) || m.length === 0) {
|
|
5
|
+
throw new Error(`'${name}' must be a non-empty 2D array`);
|
|
6
|
+
}
|
|
7
|
+
const cols = m[0].length;
|
|
8
|
+
if (cols === 0)
|
|
9
|
+
throw new Error(`'${name}' rows must be non-empty`);
|
|
10
|
+
for (const row of m) {
|
|
11
|
+
if (!Array.isArray(row) || row.length !== cols) {
|
|
12
|
+
throw new Error(`All rows in '${name}' must have the same length`);
|
|
13
|
+
}
|
|
14
|
+
for (const cell of row) {
|
|
15
|
+
if (typeof cell !== 'number' || !isFinite(cell)) {
|
|
16
|
+
throw new Error(`'${name}' must contain finite numbers only`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (m.length > MAX_MATRIX_SIZE || cols > MAX_MATRIX_SIZE) {
|
|
21
|
+
throw new Error(`Matrix dimensions cannot exceed ${MAX_MATRIX_SIZE}×${MAX_MATRIX_SIZE}`);
|
|
22
|
+
}
|
|
23
|
+
return m;
|
|
24
|
+
}
|
|
25
|
+
function dims(m) {
|
|
26
|
+
return { rows: m.length, cols: m[0].length };
|
|
27
|
+
}
|
|
28
|
+
function assertSquare(m, op) {
|
|
29
|
+
const { rows, cols } = dims(m);
|
|
30
|
+
if (rows !== cols)
|
|
31
|
+
throw new Error(`'${op}' requires a square matrix`);
|
|
32
|
+
}
|
|
33
|
+
function assertSameDimensions(a, b) {
|
|
34
|
+
if (a.length !== b.length || a[0].length !== b[0].length) {
|
|
35
|
+
throw new Error('Both matrices must have the same dimensions');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function copy(m) {
|
|
39
|
+
return m.map((row) => [...row]);
|
|
40
|
+
}
|
|
41
|
+
// ─── Operations ───
|
|
42
|
+
/**
|
|
43
|
+
* Adds two matrices element-wise.
|
|
44
|
+
*
|
|
45
|
+
* @param matrix - First matrix (2D array of finite numbers)
|
|
46
|
+
* @param matrix2 - Second matrix (must have the same dimensions as matrix)
|
|
47
|
+
* @returns MatrixResult with the resulting matrix and its dimensions
|
|
48
|
+
* @throws Error if either argument is not a valid matrix or dimensions do not match
|
|
49
|
+
*/
|
|
50
|
+
export function add(matrix, matrix2) {
|
|
51
|
+
const a = validateMatrix(matrix);
|
|
52
|
+
const b = validateMatrix(matrix2, 'matrix2');
|
|
53
|
+
assertSameDimensions(a, b);
|
|
54
|
+
const result = a.map((row, i) => row.map((v, j) => v + b[i][j]));
|
|
55
|
+
return { operation: 'add', result, dimensions: dims(result) };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Subtracts the second matrix from the first element-wise.
|
|
59
|
+
*
|
|
60
|
+
* @param matrix - Matrix to subtract from (2D array of finite numbers)
|
|
61
|
+
* @param matrix2 - Matrix to subtract (must have the same dimensions as matrix)
|
|
62
|
+
* @returns MatrixResult with the resulting matrix and its dimensions
|
|
63
|
+
* @throws Error if either argument is not a valid matrix or dimensions do not match
|
|
64
|
+
*/
|
|
65
|
+
export function subtract(matrix, matrix2) {
|
|
66
|
+
const a = validateMatrix(matrix);
|
|
67
|
+
const b = validateMatrix(matrix2, 'matrix2');
|
|
68
|
+
assertSameDimensions(a, b);
|
|
69
|
+
const result = a.map((row, i) => row.map((v, j) => v - b[i][j]));
|
|
70
|
+
return { operation: 'subtract', result, dimensions: dims(result) };
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Multiplies two matrices using standard matrix multiplication.
|
|
74
|
+
*
|
|
75
|
+
* @param matrix - Left-hand matrix (2D array of finite numbers)
|
|
76
|
+
* @param matrix2 - Right-hand matrix; its row count must equal matrix's column count
|
|
77
|
+
* @returns MatrixResult with the resulting matrix and its dimensions
|
|
78
|
+
* @throws Error if either argument is not a valid matrix or inner dimensions are incompatible
|
|
79
|
+
*/
|
|
80
|
+
export function multiply(matrix, matrix2) {
|
|
81
|
+
const a = validateMatrix(matrix);
|
|
82
|
+
const b = validateMatrix(matrix2, 'matrix2');
|
|
83
|
+
const { rows: ar, cols: ac } = dims(a);
|
|
84
|
+
const { rows: br, cols: bc } = dims(b);
|
|
85
|
+
if (ac !== br) {
|
|
86
|
+
throw new Error(`Cannot multiply: columns of first matrix (${ac}) must equal rows of second (${br})`);
|
|
87
|
+
}
|
|
88
|
+
const result = Array.from({ length: ar }, () => new Array(bc).fill(0));
|
|
89
|
+
for (let i = 0; i < ar; i++) {
|
|
90
|
+
for (let j = 0; j < bc; j++) {
|
|
91
|
+
let sum = 0;
|
|
92
|
+
for (let k = 0; k < ac; k++) {
|
|
93
|
+
sum += a[i][k] * b[k][j];
|
|
94
|
+
}
|
|
95
|
+
result[i][j] = sum;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return { operation: 'multiply', result, dimensions: dims(result) };
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Multiplies every element of a matrix by a scalar value.
|
|
102
|
+
*
|
|
103
|
+
* @param matrix - Matrix to scale (2D array of finite numbers)
|
|
104
|
+
* @param scalarVal - Finite number to multiply each element by
|
|
105
|
+
* @returns MatrixResult with the scaled matrix and its dimensions
|
|
106
|
+
* @throws Error if matrix is invalid or scalarVal is not a finite number
|
|
107
|
+
*/
|
|
108
|
+
export function scalar(matrix, scalarVal) {
|
|
109
|
+
const a = validateMatrix(matrix);
|
|
110
|
+
if (typeof scalarVal !== 'number' || !isFinite(scalarVal)) {
|
|
111
|
+
throw new Error("'scalar' must be a finite number");
|
|
112
|
+
}
|
|
113
|
+
const result = a.map((row) => row.map((v) => v * scalarVal));
|
|
114
|
+
return { operation: 'scalar', result, dimensions: dims(result) };
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Transposes a matrix, swapping its rows and columns.
|
|
118
|
+
*
|
|
119
|
+
* @param matrix - Matrix to transpose (2D array of finite numbers)
|
|
120
|
+
* @returns MatrixResult with the transposed matrix and its dimensions
|
|
121
|
+
* @throws Error if matrix is not a valid 2D array of finite numbers
|
|
122
|
+
*/
|
|
123
|
+
export function transpose(matrix) {
|
|
124
|
+
const a = validateMatrix(matrix);
|
|
125
|
+
const { rows, cols } = dims(a);
|
|
126
|
+
const result = Array.from({ length: cols }, (_, j) => Array.from({ length: rows }, (__, i) => a[i][j]));
|
|
127
|
+
return { operation: 'transpose', result, dimensions: dims(result) };
|
|
128
|
+
}
|
|
129
|
+
function gaussElim(m) {
|
|
130
|
+
const n = m.length;
|
|
131
|
+
const lu = copy(m);
|
|
132
|
+
let sign = 1;
|
|
133
|
+
for (let col = 0; col < n; col++) {
|
|
134
|
+
// Partial pivoting
|
|
135
|
+
let maxRow = col;
|
|
136
|
+
for (let row = col + 1; row < n; row++) {
|
|
137
|
+
if (Math.abs(lu[row][col]) > Math.abs(lu[maxRow][col]))
|
|
138
|
+
maxRow = row;
|
|
139
|
+
}
|
|
140
|
+
if (maxRow !== col) {
|
|
141
|
+
[lu[col], lu[maxRow]] = [lu[maxRow], lu[col]];
|
|
142
|
+
sign *= -1;
|
|
143
|
+
}
|
|
144
|
+
const pivot = lu[col][col];
|
|
145
|
+
if (pivot === 0)
|
|
146
|
+
continue;
|
|
147
|
+
for (let row = col + 1; row < n; row++) {
|
|
148
|
+
const factor = lu[row][col] / pivot;
|
|
149
|
+
for (let k = col; k < n; k++) {
|
|
150
|
+
lu[row][k] -= factor * lu[col][k];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return { lu, sign };
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Computes the determinant of a square matrix using Gaussian elimination with partial pivoting.
|
|
158
|
+
*
|
|
159
|
+
* @param matrix - Square matrix (2D array of finite numbers)
|
|
160
|
+
* @returns MatrixResult with the determinant as a scalar result and the input dimensions
|
|
161
|
+
* @throws Error if matrix is not a valid square matrix
|
|
162
|
+
*/
|
|
163
|
+
export function determinant(matrix) {
|
|
164
|
+
const a = validateMatrix(matrix);
|
|
165
|
+
assertSquare(a, 'determinant');
|
|
166
|
+
const n = a.length;
|
|
167
|
+
if (n === 1)
|
|
168
|
+
return { operation: 'determinant', result: a[0][0], dimensions: dims(a) };
|
|
169
|
+
if (n === 2) {
|
|
170
|
+
const det = a[0][0] * a[1][1] - a[0][1] * a[1][0];
|
|
171
|
+
return { operation: 'determinant', result: det, dimensions: dims(a) };
|
|
172
|
+
}
|
|
173
|
+
const { lu, sign } = gaussElim(a);
|
|
174
|
+
let det = sign;
|
|
175
|
+
for (let i = 0; i < n; i++)
|
|
176
|
+
det *= lu[i][i];
|
|
177
|
+
const result = Number(det.toFixed(10));
|
|
178
|
+
return { operation: 'determinant', result, dimensions: dims(a) };
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Computes the inverse of a square matrix using Gauss-Jordan elimination.
|
|
182
|
+
*
|
|
183
|
+
* @param matrix - Square matrix (2D array of finite numbers)
|
|
184
|
+
* @returns MatrixResult with the inverted matrix and its dimensions
|
|
185
|
+
* @throws Error if matrix is not a valid square matrix or is singular (determinant is 0)
|
|
186
|
+
*/
|
|
187
|
+
export function inverse(matrix) {
|
|
188
|
+
const a = validateMatrix(matrix);
|
|
189
|
+
assertSquare(a, 'inverse');
|
|
190
|
+
const n = a.length;
|
|
191
|
+
// Build augmented matrix [A | I]
|
|
192
|
+
const aug = a.map((row, i) => [...row, ...Array.from({ length: n }, (_, j) => (i === j ? 1 : 0))]);
|
|
193
|
+
// Gauss-Jordan elimination
|
|
194
|
+
for (let col = 0; col < n; col++) {
|
|
195
|
+
// Partial pivoting
|
|
196
|
+
let maxRow = col;
|
|
197
|
+
for (let row = col + 1; row < n; row++) {
|
|
198
|
+
if (Math.abs(aug[row][col]) > Math.abs(aug[maxRow][col]))
|
|
199
|
+
maxRow = row;
|
|
200
|
+
}
|
|
201
|
+
if (maxRow !== col)
|
|
202
|
+
[aug[col], aug[maxRow]] = [aug[maxRow], aug[col]];
|
|
203
|
+
const pivot = aug[col][col];
|
|
204
|
+
if (Math.abs(pivot) < 1e-12)
|
|
205
|
+
throw new Error('Matrix is singular (determinant is 0)');
|
|
206
|
+
for (let k = 0; k < 2 * n; k++)
|
|
207
|
+
aug[col][k] /= pivot;
|
|
208
|
+
for (let row = 0; row < n; row++) {
|
|
209
|
+
if (row === col)
|
|
210
|
+
continue;
|
|
211
|
+
const factor = aug[row][col];
|
|
212
|
+
for (let k = 0; k < 2 * n; k++) {
|
|
213
|
+
aug[row][k] -= factor * aug[col][k];
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
// Extract right half
|
|
218
|
+
const result = aug.map((row) => row.slice(n).map((v) => Number(v.toFixed(10))));
|
|
219
|
+
return { operation: 'inverse', result, dimensions: dims(result) };
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Generates an n×n identity matrix.
|
|
223
|
+
*
|
|
224
|
+
* @param n - Size of the identity matrix (positive integer, max MAX_MATRIX_SIZE)
|
|
225
|
+
* @returns MatrixResult with the identity matrix and its dimensions
|
|
226
|
+
* @throws Error if n is not a positive integer or exceeds the maximum allowed size
|
|
227
|
+
*/
|
|
228
|
+
export function identity(n) {
|
|
229
|
+
if (typeof n !== 'number' || !Number.isInteger(n) || n <= 0) {
|
|
230
|
+
throw new Error("'scalar' must be a positive integer for the identity operation");
|
|
231
|
+
}
|
|
232
|
+
if (n > MAX_MATRIX_SIZE) {
|
|
233
|
+
throw new Error(`Identity size cannot exceed ${MAX_MATRIX_SIZE}`);
|
|
234
|
+
}
|
|
235
|
+
const result = Array.from({ length: n }, (_, i) => Array.from({ length: n }, (__, j) => (i === j ? 1 : 0)));
|
|
236
|
+
return { operation: 'identity', result, dimensions: { rows: n, cols: n } };
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=matrix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matrix.js","sourceRoot":"","sources":["../../../src/modules/v5/matrix.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAUrD,qBAAqB;AACrB,SAAS,cAAc,CAAC,CAAU,EAAE,IAAI,GAAG,QAAQ;IAC/C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,IAAI,IAAI,gCAAgC,CAAC,CAAC;IAC9D,CAAC;IACD,MAAM,IAAI,GAAI,CAAC,CAAC,CAAC,CAAe,CAAC,MAAM,CAAC;IACxC,IAAI,IAAI,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,IAAI,IAAI,0BAA0B,CAAC,CAAC;IACpE,KAAK,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;QAClB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;YAC7C,MAAM,IAAI,KAAK,CAAC,gBAAgB,IAAI,6BAA6B,CAAC,CAAC;QACvE,CAAC;QACD,KAAK,MAAM,IAAI,IAAI,GAAG,EAAE,CAAC;YACrB,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC9C,MAAM,IAAI,KAAK,CAAC,IAAI,IAAI,oCAAoC,CAAC,CAAC;YAClE,CAAC;QACL,CAAC;IACL,CAAC;IACD,IAA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AAE,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;IACtF,CAAC;IACD,IAAI,CAAC,GAAG,eAAe,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,+BAA+B,eAAe,EAAE,CAAC,CAAC;IACtE,CAAC;IACD,MAAM,MAAM,GAAW,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACpH,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC;AAC/E,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { address, agent, algorithms, avatar, barcode, captcha, chat, color, convert, credit, cron, dice, domain, encode, geo, hash, hyperplanning, ip, levenshtein, palette, password, personal, placeholder, qrcode, regex, statistics, text, tic_tac_toe, time, token, username, validate, } from './v4.js';
|
|
2
|
+
export * as chart from './v5/chart.js';
|
|
3
|
+
export { default as evaluate } from './v5/evaluate.js';
|
|
4
|
+
export * as matrix from './v5/matrix.js';
|
|
5
|
+
//# sourceMappingURL=v5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v5.js","sourceRoot":"","sources":["../../src/modules/v5.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,OAAO,EACP,KAAK,EACL,UAAU,EACV,MAAM,EACN,OAAO,EACP,OAAO,EACP,IAAI,EACJ,KAAK,EACL,OAAO,EACP,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,MAAM,EACN,GAAG,EACH,IAAI,EACJ,aAAa,EACb,EAAE,EACF,WAAW,EACX,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,MAAM,EACN,KAAK,EACL,UAAU,EACV,IAAI,EACJ,WAAW,EACX,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,QAAQ,GACX,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,KAAK,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,MAAM,MAAM,gBAAgB,CAAC"}
|