Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

saucenao

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

saucenao - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

11

index.js

@@ -7,2 +7,3 @@ const fs = require('fs')

const FormData = require('form-data')
const fileType = require('file-type')

@@ -13,3 +14,3 @@ exports = module.exports = fnProto(function SauceNAO(...args) {

api_key = args[0]
if(typeof api_key !== 'string')
if(!api_key || typeof api_key !== 'string')
throw new TypeError('no api_key passed to constructor')

@@ -39,2 +40,10 @@ return fnProto(getSauce)

case (input instanceof Buffer):
let inputType = fileType(input)
form.append('file', input, {
filename: `file.${inputType.ext}`,
contentType: inputType.mime
})
break
default: throw new TypeError('unrecognized input format')

@@ -41,0 +50,0 @@ }

2

package.json
{
"name": "saucenao",
"version": "0.0.1",
"version": "0.0.2",
"description": "saucenao api wrapper",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -15,3 +15,3 @@ # saucenao-node

## SauceNAO(input[, options])
* `input` *string or object.* An image url, filename, or `fs` input stream.
* `input` *string or object.* An image url, filename, `Buffer`, or `fs` readable stream.
* `options` *object.* Any extra parameters you would like to pass in the request body.

@@ -26,23 +26,21 @@ * **Returns** *Promise.*

This function is fairly simple.
This function is fairly simple. It mostly just performs a request to SauceNAO for you, so that you can skip a couple function calls. It can work with local filepaths, urls that begin with `http://` or `https://`, `fs` input streams, or even buffers.
If you provide a filename or a `fs` input stream as an input, it'll read your file for you so that you don't have to. If you instead pass it a url, it'll set the `url` parameter with it.
After it receives a reply from SauceNAO, it'll attempt to parse it as JSON and add it to the Response object for your convenience. It'll return a promise that either resolves to this extended Response object or rejects an error containing as much of this extended Response object as it generated.
Then it'll send a request for you and attempt to parse the JSON in SauceNAO's response. It'll give you a promise that resolves to the HTTP response, with these values available as properties. If anything goes wrong, it'll reject an error with a `response` property so you can debug.
## new SauceNAO(api_key)
If you have [an api key](https://saucenao.com/user.php?page=search-api), you can specify it by passing it to SauceNAO's "constructor." This gives you a new function that works exactly the same way as the function above, but your requests will be authenticated.
If you have [an api key](https://saucenao.com/user.php?page=search-api), you can specify it by using this function like a constructor. This gives you a new function that works exactly the same way as the function above, but your requests will be authenticated.
```js
const SauceNAO = require('saucenao')
let mysauce = new SauceNAO('api_key here')
let mySauce = new SauceNAO('api_key here')
mysauce('picture.png').then((response) => {
console.log('Request successful:')
mySauce(imageDataBuffer).then((response) => {
console.log('Request successful')
console.dir(response.json)
}, (error) => {
console.log('Request encountered an error:')
console.error('Request encountered an error')
console.dir(error.request)
})
```
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