Socket
Socket
Sign inDemoInstall

imgbb-uploader

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

imgbb-uploader - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

lib/esm/fileToString.d.ts

4

lib/cjs/fileToString.js

@@ -15,3 +15,3 @@ "use strict";

*/
exports.fileToString = function (imagePath) { return fs_1.default.promises.readFile(imagePath, "base64"); };
//# sourceMappingURL=fileToString.js.map
var fileToString = function (imagePath) { return fs_1.default.promises.readFile(imagePath, "base64"); };
exports.fileToString = fileToString;

@@ -22,3 +22,8 @@ import { IOptionObject, IResponseObject } from "./interfaces";

* @example
* imgbbUploader("your-api-key", "path/to/file.jpg")
* imgbbUploader({
* apiKey: process.env.IMGBB_API_KEY,
* name: "customFilename",
* expiration: 3600,
* imagePath: "./your/image/path.png"
* })
* .then(res => console.log(res))

@@ -25,0 +30,0 @@ * .catch(err => console.error(err))

@@ -73,3 +73,8 @@ "use strict";

* @example
* imgbbUploader("your-api-key", "path/to/file.jpg")
* imgbbUploader({
* apiKey: process.env.IMGBB_API_KEY,
* name: "customFilename",
* expiration: 3600,
* imagePath: "./your/image/path.png"
* })
* .then(res => console.log(res))

@@ -89,9 +94,9 @@ * .catch(err => console.error(err))

if (!(args.length === 2)) return [3 /*break*/, 5];
return [4 /*yield*/, validateInput_1.validateStringInput(String(args[0]), String(args[1]))];
return [4 /*yield*/, (0, validateInput_1.validateStringInput)(String(args[0]), String(args[1]))];
case 1:
if (!_b.sent()) return [3 /*break*/, 3];
return [4 /*yield*/, fileToString_1.fileToString(String(args[1]))];
return [4 /*yield*/, (0, fileToString_1.fileToString)(String(args[1]))];
case 2:
image = _b.sent();
return [2 /*return*/, postToImgbb_1.postToImgbb({
return [2 /*return*/, (0, postToImgbb_1.postToImgbb)({
apiKey: String(args[0]),

@@ -108,3 +113,3 @@ image: image,

_b.trys.push([6, 8, , 9]);
return [4 /*yield*/, validateInput_1.validateOptionObject(__assign({}, args[0]))];
return [4 /*yield*/, (0, validateInput_1.validateOptionObject)(__assign({}, args[0]))];
case 7:

@@ -114,3 +119,3 @@ image = _b.sent();

if (!cheveretoHost) {
return [2 /*return*/, postToImgbb_1.postToImgbb({
return [2 /*return*/, (0, postToImgbb_1.postToImgbb)({
apiKey: String(apiKey),

@@ -124,3 +129,3 @@ image: image,

else {
return [2 /*return*/, postToChevereto_1.postToChevereto({
return [2 /*return*/, (0, postToChevereto_1.postToChevereto)({
apiKey: String(apiKey),

@@ -144,2 +149,1 @@ image: image,

module.exports = imgbbUploader;
//# sourceMappingURL=index.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=interfaces.js.map

@@ -5,6 +5,8 @@ import { IOptionObject, IResponseObject } from "./interfaces";

*
* To tweak the method, edit 'postToImgbb.ts' with the help of [the docs](https://nodejs.org/api/https.html#https_https_request_options_callback)
* To tweak the method, edit 'postToChevereto.ts' with the help of [the docs](https://nodejs.org/api/https.html#https_https_request_options_callback)
*
* @param {string} apiKey - Your imgBB API key
* @param {string} apiKey - Your Chevereto API key
* @param {string} image - Typically, the output of fileToString("path") function
* @param {string} cheveretoHost - Chevereto host; ccepts explicit protocol & port
* @param {Object} customPayload - Custom payload object that'll be spreaded into the request payload
*

@@ -11,0 +13,0 @@ * @returns A promise. Use `.then` as shown in [the README](https://github.com/TheRealBarenziah/imgbb-uploader#use) :

@@ -15,3 +15,7 @@ "use strict";

if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -29,3 +33,3 @@ if (k2 === undefined) k2 = k;

var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);

@@ -40,3 +44,3 @@ return result;

var querystring = __importStar(require("querystring"));
exports.postToChevereto = function (params) {
var postToChevereto = function (params) {
return new Promise(function (resolve, reject) {

@@ -46,3 +50,3 @@ var _a = __assign({}, params), apiKey = _a.apiKey, image = _a.image, cheveretoHost = _a.cheveretoHost, _b = _a.customPayload, customPayload = _b === void 0 ? {} : _b;

if (customPayload) {
if ((customPayload === null || customPayload === void 0 ? void 0 : customPayload.format) === "txt" || (customPayload === null || customPayload === void 0 ? void 0 : customPayload.format) === "redirect") {
if (customPayload.format === "txt" || customPayload.format === "redirect") {
throw new Error("'options.customPayload.format' standard alternatives to 'json' are not supported; see USE_WITH_CHEVERETO.md for more details.");

@@ -54,3 +58,3 @@ }

// Parse cheveretoHost to infer relevant request module; default to https unless explicitly given 'http://'
var goodOldHttp = cheveretoHost.split("://")[0] === "http";
var goodOldHttp = cheveretoHost.includes("http://");
var requestFn = goodOldHttp ? http_1.request : https_1.request;

@@ -70,3 +74,3 @@ var hostname = cheveretoHost.includes("://") ? cheveretoHost.split("://")[1] : cheveretoHost;

method: "POST",
timeout: 5000,
timeout: 15000,
path: "/api/1/upload",

@@ -92,3 +96,3 @@ headers: {

var error = {
message: cheveretoHost + " API returned an error",
message: "".concat(cheveretoHost, " API returned an error"),
cheveretoResponse: output,

@@ -103,3 +107,3 @@ };

else {
reject(new Error(String(cheveretoHost + " returned an empty response")));
reject(new Error(String("".concat(cheveretoHost, " returned an empty response"))));
}

@@ -123,2 +127,2 @@ }

};
//# sourceMappingURL=postToChevereto.js.map
exports.postToChevereto = postToChevereto;

@@ -15,3 +15,7 @@ "use strict";

if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -29,3 +33,3 @@ if (k2 === undefined) k2 = k;

var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);

@@ -39,7 +43,7 @@ return result;

var querystring = __importStar(require("querystring"));
exports.postToImgbb = function (params) {
var postToImgbb = function (params) {
return new Promise(function (resolve, reject) {
var _a = __assign({}, params), apiKey = _a.apiKey, image = _a.image, _b = _a.name, name = _b === void 0 ? null : _b, _c = _a.expiration, expiration = _c === void 0 ? null : _c;
// query string & payload structures are different for imgBB & chevereto-free
var query = "/1/upload?key=" + apiKey;
var query = "/1/upload?key=".concat(apiKey);
var payload = querystring.stringify({

@@ -49,5 +53,5 @@ image: image,

if (name)
query += "&name=" + encodeURIComponent(name);
query += "&name=".concat(encodeURIComponent(name));
if (expiration)
query += "&expiration=" + expiration;
query += "&expiration=".concat(expiration);
var options = {

@@ -91,2 +95,2 @@ hostname: "api.imgbb.com",

};
//# sourceMappingURL=postToImgbb.js.map
exports.postToImgbb = postToImgbb;

@@ -56,3 +56,3 @@ "use strict";

var fileToString_1 = require("./fileToString");
exports.isFile = function (path) { return __awaiter(void 0, void 0, void 0, function () {
var isFile = function (path) { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {

@@ -68,2 +68,3 @@ switch (_a.label) {

}); };
exports.isFile = isFile;
/**

@@ -78,6 +79,6 @@ * Formally validate input 2 strings params

*/
exports.validateStringInput = function (apiKey, path) { return __awaiter(void 0, void 0, void 0, function () {
var validateStringInput = function (apiKey, path) { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, exports.isFile(path)];
case 0: return [4 /*yield*/, (0, exports.isFile)(path)];
case 1: return [2 /*return*/, (_a.sent()) && apiKey ? true : false];

@@ -87,2 +88,3 @@ }

}); };
exports.validateStringInput = validateStringInput;
var validateImageInput = function (_a) {

@@ -97,3 +99,3 @@ var imagePath = _a.imagePath, base64string = _a.base64string, imageUrl = _a.imageUrl;

if (!imagePath) return [3 /*break*/, 6];
return [4 /*yield*/, exports.isFile(imagePath)];
return [4 /*yield*/, (0, exports.isFile)(imagePath)];
case 1:

@@ -105,4 +107,4 @@ validPath = _b.sent();

if (!!validPath) return [3 /*break*/, 3];
throw Error("'imagePath' seem invalid (" + imagePath + ")");
case 3: return [4 /*yield*/, fileToString_1.fileToString(imagePath)];
throw Error("'imagePath' seem invalid (".concat(imagePath, ")"));
case 3: return [4 /*yield*/, (0, fileToString_1.fileToString)(imagePath)];
case 4: return [2 /*return*/, _b.sent()];

@@ -139,3 +141,3 @@ case 5: return [3 /*break*/, 7];

*/
exports.validateOptionObject = function (options) { return __awaiter(void 0, void 0, void 0, function () {
var validateOptionObject = function (options) { return __awaiter(void 0, void 0, void 0, function () {
var _a, _b, imagePath, _c, apiKey, _d, expiration, _e, base64string, _f, imageUrl, _g, cheveretoHost;

@@ -180,2 +182,2 @@ return __generator(this, function (_h) {

}); };
//# sourceMappingURL=validateInput.js.map
exports.validateOptionObject = validateOptionObject;
{
"name": "imgbb-uploader",
"version": "1.4.0",
"version": "1.5.0",
"description": "Lightweight module to upload images through imgBB and other chevereto-based APIs.",

@@ -10,13 +10,16 @@ "main": "lib/cjs/index.js",

"scripts": {
"dev": "npm run build && npm run format && npm run lint && npm run test && npm run remap",
"test": "jest --config jestconfig.json",
"build": "node clean.js && tsc -p tsconfig-cjs.json",
"dev": "npm run build && npm run format && npm run test && npm run lint",
"test": "node src/__tests__/codegen.js && NODE_OPTIONS=--experimental-vm-modules jest --verbose",
"testWithoutCodegen": "NODE_OPTIONS=--experimental-vm-modules jest",
"build": "node clean.js && node updateExport.js es5 && tsc -p tsconfig-cjs.json && node updateExport.js es6 && tsc -p tsconfig.json",
"build:cjs": "node clean.js && tsc -p tsconfig-cjs.json",
"build:esm": "node clean.js && tsc -p tsconfig.json",
"remap": "node --no-warnings ./node_modules/.bin/remap-istanbul -i coverage/coverage-final.json -o coverage/ts-report -t html -e src/__tests__/images/image,src/__tests__/utils.js",
"build:cjs:prod": "tsc -p tsconfig-cjs.json --sourceMap false",
"build:esm:prod": "tsc -p tsconfig.json --sourceMap false",
"build:prod": "node clean.js && node updateExport.js es5 && npm run build:cjs:prod && node updateExport.js es6 && npm run build:esm:prod",
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
"lint": "eslint --fix .",
"clean": "node clean.js",
"prepare": "npm run build",
"prepublishOnly": "npm run build && npm test && npm run lint",
"prepare": "npm run build:prod",
"prepublishOnly": "npm run build:prod && npm test && npm run lint",
"preversion": "npm run lint",

@@ -32,11 +35,13 @@ "version": "npm run format && git add -A src",

"devDependencies": {
"@babel/core": "^7.18.2",
"@babel/preset-env": "^7.18.2",
"@babel/preset-typescript": "^7.17.12",
"@babel/types": "^7.11.0",
"@types/dotenv": "^8.2.0",
"@types/jest": "^26.0.9",
"@types/node": "^14.0.27",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"axios": "^0.21.4",
"@typescript-eslint/eslint-plugin": "^5.26.0",
"@typescript-eslint/parser": "^5.26.0",
"babel-jest": "^28.1.0",
"dotenv": "^8.2.0",
"eslint": "^7.32.0",
"eslint": "^8.16.0",
"eslint-config-prettier": "^8.5.0",

@@ -48,13 +53,14 @@ "eslint-plugin-import": "^2.22.0",

"eslint-plugin-prettier": "^4.0.0",
"export-helper": "1.0.0",
"husky": "^4.2.5",
"jest": "^26.4.0",
"jest": "^28.1.0",
"js-image-generator": "^1.0.3",
"prettier": "^2.0.5",
"pretty-quick": "^2.0.1",
"remap-istanbul": "0.13.0",
"rimraf": "^3.0.2",
"sharp": "^0.26.3",
"tfaker": "^0.1.0",
"ts-jest": "^26.2.0",
"typescript": "^3.9.9",
"waifu-generator": "^2.0.4"
"ts-jest": "^28.0.3",
"typescript": "^4.7.2",
"waifu-generator": "3.0.0"
},

@@ -61,0 +67,0 @@ "repository": {

@@ -9,2 +9,3 @@ # imgbb-uploader

[![dependencies](https://img.shields.io/badge/dependencies-0-brightgreen)](https://www.npmjs.com/package/imgbb-uploader?activeTab=dependencies)
[![DeepScan grade](https://deepscan.io/api/teams/17873/projects/21210/branches/601598/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=17873&pid=21210&bid=601598)
![Test suite](https://github.com/TheRealBarenziah/imgbb-uploader/actions/workflows/tests.yml/badge.svg)

@@ -20,3 +21,3 @@

**Node >= 8** ( [Promises/await](https://node.green/) )
**Node >= 8** ( [Promises/await](https://node.green/) ) _ESM projects are supported from 1.5 onward_
_Care: this module uses `fs` under the hood. **It WON'T work outside the node environment !**_

@@ -42,2 +43,5 @@

const imgbbUploader = require("imgbb-uploader");
/* or use import in ESM projects:
import { imgbbUploader } from "imgbb-uploader";
*/

@@ -101,2 +105,5 @@ imgbbUploader("your-imgbb-api-key-string", "path/to/your/image.png")

const imgbbUploader = require("imgbb-uploader");
/* or use import in ESM projects:
import { imgbbUploader } from "imgbb-uploader";
*/

@@ -103,0 +110,0 @@ const options = {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc