@squarecloud/utils
Advanced tools
Comparing version 1.0.2 to 2.0.0
{ | ||
"name": "@squarecloud/utils", | ||
"version": "1.0.2", | ||
"version": "2.0.0", | ||
"description": "Module designed to support Square Cloud activities.", | ||
@@ -23,4 +23,3 @@ "main": "src/index.js", | ||
"dependencies": { | ||
"@squarecloudofc/status": "latest", | ||
"node-fetch": "latest" | ||
"@squarecloud/status": "latest" | ||
}, | ||
@@ -36,2 +35,2 @@ "devDependencies": {}, | ||
"homepage": "https://github.com/squarecloudofc/squarecloud-utils#readme" | ||
} | ||
} |
@@ -21,18 +21,18 @@ ## Informações | ||
add("Another message in same log", "log.txt"); | ||
add("Another timeZone?", "uscentralLogs.txt", "US/Central"); | ||
add("Another timeZone?", "US_Logs.txt", "US/Central"); | ||
del("uscentralLogs.txt"); // Delete the uscentralLogs file. | ||
del("US_Logs.txt"); // Delete the US_Logs file. | ||
if (check("uscentralLogs.txt")) { | ||
console.log("uscentralLogs exists!"); | ||
if (check("US_Logs.txt")) { | ||
console.log("US_Logs exists!"); | ||
} | ||
const Utils = require("@squarecloud/utils"); | ||
const { webhook, apply, prototypes } = require("@squarecloud/utils"); | ||
// Discord Easy Webhook | ||
Utils.webhook("hi friend", "https://discord......"); | ||
Utils.webhook({ content: "example object webhook" }, "https://discord......"); | ||
webhook("hi friend", "https://discord......"); | ||
webhook({ content: "example object webhook" }, "https://discord......"); | ||
// Protect your code | ||
Utils.apply(() => { console.log(USER) }, "log.txt"); | ||
apply(() => { console.log(USER) }, "log.txt"); | ||
// support file or webhook (discord); | ||
@@ -44,6 +44,6 @@ | ||
// Add Util prototypes; | ||
Utils.prototypes(); | ||
prototypes(); | ||
String.firstUpper("potato") -> "Potato"; | ||
Array.random() -> Give random array value; | ||
"potato".capitalize -> "Potato"; | ||
[1, 2, 3, 4, 5].random() -> 3 // Give random array value; | ||
@@ -50,0 +50,0 @@ ``` |
/* | ||
Copyright 2021 Square Cloud - All rights reserved. | ||
Copyright 2021-2023 Square Cloud - All rights reserved. | ||
*/ | ||
const fs = require('fs') | ||
, fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args)) | ||
, { ram, ramTotal, ramUsed } = require('@squarecloudofc/status'); | ||
const { appendFile, unlinkSync, existsSync } = require("node:fs"); | ||
const { ram, ramTotal, ramUsed } = require("@squarecloud/status"); | ||
module.exports = { | ||
@@ -32,4 +30,4 @@ | ||
*/ | ||
add: (message, archive, timeZone = 'America/Sao_Paulo') => { | ||
fs.appendFile(archive ?? "square.log", `${new Date().toLocaleString('pt-br', { timeZone })} -> ${message}\n`, (err) => { | ||
add: (message, archive, timeZone = "America/Sao_Paulo") => { | ||
appendFile(archive ?? "square.log", `${new Date().toLocaleString("pt-br", { timeZone })} -> ${message}\n`, (err) => { | ||
if (err) throw new Error("Unable to log, check file directory location."); | ||
@@ -43,3 +41,3 @@ }); | ||
*/ | ||
del: (archive) => fs.unlinkSync(archive), | ||
del: (archive) => unlinkSync(archive), | ||
@@ -50,3 +48,3 @@ /** | ||
*/ | ||
check: (archive) => fs.existsSync(archive), | ||
check: (archive) => existsSync(archive), | ||
@@ -56,4 +54,4 @@ }, | ||
prototypes: () => { | ||
String.prototype.firstUpper = function () { return this.toString().charAt(0).toUpperCase() + this.toString().slice(1)}; | ||
Array.prototype.random = function () { return this[Math.floor((Math.random() * this.length))]; } | ||
String.prototype.capitalize = function () { return this.charAt(0).toUpperCase() + this.slice(1); } | ||
Array.prototype.random = function () { return this[Math.floor((Math.random() * this.length))]; } | ||
}, | ||
@@ -69,5 +67,7 @@ | ||
return await fn.apply(this, arguments); | ||
} catch (e) { | ||
if (path.match(/discord.com\/api\/webhooks/)) return fetch(path, { method: "POST", headers: { 'Content-type': 'application/json' }, body: JSON.stringify({ content: `${e}` }) }); | ||
require('./index').Registry.add(e, path); | ||
} catch (exception) { | ||
if (path.match(/discord.com\/api\/webhooks/)) { | ||
return fetch(path, { method: "POST", headers: { "Content-type": "application/json" }, body: JSON.stringify({ content: exception }) }); | ||
} | ||
require("./index").Registry.add(exception, path); | ||
} | ||
@@ -83,3 +83,3 @@ }, | ||
try { | ||
return fetch(webhook, { method: "POST", headers: { 'Content-type': 'application/json' }, body: JSON.stringify(typeof object == "string" ? { content: object } : object ?? { content: "hello world" }) }); | ||
return fetch(webhook, { method: "POST", headers: { "Content-type": "application/json" }, body: JSON.stringify(typeof object == "string" ? { content: object } : object ?? { content: "hello world" }) }); | ||
} catch { | ||
@@ -86,0 +86,0 @@ throw new Error("Could not send webhook."); |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
1
119
0
2
18494
+ Added@squarecloud/status@latest
+ Added@squarecloud/status@2.0.0(transitive)
- Removed@squarecloudofc/status@latest
- Removednode-fetch@latest
- Removed@squarecloudofc/status@1.0.0(transitive)
- Removeddata-uri-to-buffer@4.0.1(transitive)
- Removedfetch-blob@3.2.0(transitive)
- Removedformdata-polyfill@4.0.10(transitive)
- Removednode-domexception@1.0.0(transitive)
- Removednode-fetch@3.3.2(transitive)
- Removedweb-streams-polyfill@3.3.3(transitive)