2.0.0 • Published 4 years ago

captionbot.js v2.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

captionbot.js

A tiny JavaScript wrapper for Microsoft's Captionbot API.

All image recognition is made by the Captionbot; this package only makes requesting the captions a little easier.

Installation

npm install captionbot.js

Usage

const { caption } = require("captionbot.js")
const imageURL = "https://zuwanu.com/wp-content/uploads/2019/09/cars-zuwanu.jpg"

// using then()
caption(imageURL)
    .then(imageCaption => console.log(`Caption: ${imageCaption}`))
    .catch(error => console.log(`Error: ${error.message}`))
    // => Caption: I think it's a car parked in a parking lot.

// using async/await
async function logCaption(imageURL) {
    try {
        const imageCaption = await caption(imageURL)
        console.log(`Caption: ${caption}`)
    } catch (error) {
        console.log(`Error: ${error.message}`)
    }
}
logCaption()
// => Caption: I think it's a car parked in a parking lot.

API

captionbot.caption()

Caption an image given its URL.

Parameters

namedescriptiondefault
imageURLThe URL of the image to caption
options{}
options.errorWhether to throw an error/reject when the provided URL is invalid/missing, but a response is still obtained—this will be irrelevant if there's a network error, for examplefalse

Returns

Promise<String>

captionbot.URLError extends TypeError

Thrown by caption() when the specified URL is invalid, and the error option is true.

new URLError(message)

captionbot.ERROR_CAPTIONS

A list of captions the API returns when the specified URL is invalid.

Type

Array<String>

Example captions

Some examples of captions returned by the API.

"I think it's a dog standing on grass."

"I think it's a car parked in a parking lot."

"I think it's a view of water and a mountain in the background."

2.0.0

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago