npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

imgbb-client

v1.0.0

Published

A push client for the ImgBB service

Downloads

5

Readme

Claro! Aqui está um exemplo de um arquivo README.md para a sua biblioteca de upload de imagens no ImgBB:


ImgBB Client Library

A simple and easy-to-use client library for uploading images to ImgBB.

Features

  • Upload images to ImgBB using a Base64 string, Buffer, or Blob.
  • Supports optional expiration time for images.
  • Supports custom filenames for uploaded images.
  • Provides callback functionality for handling responses.

Installation

Install the package via npm:

bun add imgbb-client
npm i imgbb-client
yarn add imgbb-client

Usage

Importing the library

import { ImgBBClient } from 'imgbb-client';

Creating an ImgBBClient instance

const apiKey = 'your-imgbb-api-key';
const imgbbClient = new ImgBBClient(apiKey);

Uploading an image

You can upload an image using a Base64 string, Buffer, or Blob.

Using a Base64 string

const options: ImgBBOptions = { image: 'data:image/png;base64,iVBORw0...' };

imgbbClient.upload(options)
  .then((response: ImgbbResponse) => {
    console.log('Upload successful:', response);
  })
  .catch((error) => {
    console.error('Upload failed:', error);
  });

Using a Buffer

const fs = require('fs');
const imageBuffer = fs.readFileSync('path/to/your/image.png');

const options: ImgBBOptions = { image: imageBuffer };

imgbbClient.upload(options)
  .then((response: ImgbbResponse) => {
    console.log('Upload successful:', response);
  })
  .catch((error) => {
    console.error('Upload failed:', error);
  });

Using a Blob

const fileInput = document.querySelector('input[type="file"]');
const file = fileInput.files[0];

const options: ImgBBOptions = { image: file, filename: file.name };

imgbbClient.upload(options)
  .then((response: ImgbbResponse) => {
    console.log('Upload successful:', response);
  })
  .catch((error) => {
    console.error('Upload failed:', error);
  });

Using a callback

You can provide a callback function to handle the response.

const options: ImgBBOptions = { image: 'data:image/png;base64,iVBORw0...' };

imgbbClient.upload(options, (response: ImgbbResponse) => {
  console.log('Upload callback:', response);
});

Handling errors

Errors can be caught using the .catch method.

const options: ImgBBOptions = { image: 'data:image/png;base64,iVBORw0...' };

imgbbClient.upload(options)
  .then((response: ImgbbResponse) => {
    console.log('Upload successful:', response);
  })
  .catch((error) => {
    console.error('Upload failed:', error);
  });

API

ImgBBClient

constructor(apiKey: string)

Creates a new instance of the ImgBBClient class.

  • apiKey: Your ImgBB API key.

upload(options: ImgBBOptions, callback?: (response: ImgbbResponse) => void): Promise<ImgbbResponse>

Uploads an image to ImgBB.

  • options: An object containing the image and optional expiration time.
  • callback: An optional callback function that will be called with the response.

ImgBBOptions

An object containing the image data and optional expiration time.

  • image: The image to upload. Can be a Base64 string, Buffer, or Blob.
  • expiration?: Optional. The expiration time for the image in seconds.
  • filename?: Optional. The filename for the uploaded image.

ImgbbResponse

The response object from ImgBB.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any changes or improvements.

License

This project is licensed under the MIT License.


This README provides an overview of the library, including installation instructions, usage examples, and API documentation. It should help users get started with your ImgBB client library quickly and easily.