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

optiic

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

optiic - npm Package Compare versions

Comparing version 0.0.0 to 0.0.5

17

package.json
{
"name": "optiic",
"version": "0.0.0",
"description": "An advanced free image recognition & analysis API.",
"version": "0.0.5",
"description": "An advanced free OCR & image recognition API.",
"main": "src/index.js",

@@ -21,3 +21,7 @@ "scripts": {

"image recognition",
"image recognition api"
"image recognition api",
"captcha",
"captcha solver",
"captcha api",
"rest api"
],

@@ -29,3 +33,8 @@ "author": "ITW Creative Works",

},
"homepage": "https://optiic.dev"
"homepage": "https://optiic.dev",
"dependencies": {
"form-data": "^3.0.0",
"node-fetch": "^2.6.0"
},
"devDependencies": {}
}

@@ -25,3 +25,3 @@ <p align="center">

<br>
<strong>optiic</strong> is the official npm module of <a href="https://optiic.dev">Optiic</a>, a free service to get SOCKS, HTTP, & HTTPS proxies as well as to check your public IP!
<strong>optiic</strong> is the official npm module of <a href="https://optiic.dev">Optiic</a>, a free image recognition & optical character recognition (OCR) API.
</p>

@@ -37,3 +37,3 @@

* Extract text from the supplied image
* Easily filter by country, speed, and anonymity level
* Detect the language of the text

@@ -60,3 +60,3 @@ ### Getting an API key

```html
<script src="https://cdn.jsdelivr.net/npm/optiic"></script>
<script src="https://cdn.jsdelivr.net/npm/optiic@latest"></script>
<script type="text/javascript">

@@ -70,15 +70,34 @@ let optiic = new Optiic({

### Use without installation
You can use **Optiic** in a variety of ways that require no installation, such as `curl` in terminal/shell. See the **Use without installation** section below.
You can use `optiic` in a variety of ways that require no installation, such as `curl` in terminal/shell. See the **Use without installation** section below.
## Example output
If you want to see how `optiic` works, you can try a sample image such as `https://via.placeholder.com/468x60?text=Sample+text` which will result in an output like this:
```js
{
text: "Sample text",
language: "en",
}
```
## Using Optiic
After you have followed the install step, you can start using `optiic` to get proxy lists and check your public IP!
After you have followed the install step, you can start using `optiic` to analyze images and perform OCR from within your app!
### .process(options)
Submit and image to process and return the text in the image.
#### options
The options for `ocr(options)` are as follows.
* image `string`, `HTML Input Element`, `File`: The image to be processed. Can be a local path, remote URL, an HTML input, or a File object.
* Acceptable Values: `any`
* Default: `null`
* mode `string`: What type of optical recognition will be run, such as OCR.
* Acceptable Values: `ocr`
* Default: `ocr`
#### Remote URL Example
```js
let options = {
url: 'https', // url to the image
image: 'https://via.placeholder.com/468x60?text=Sample+text', // url of the image
mode: 'ocr', // ocr
};
optiic.process(options)

@@ -89,12 +108,39 @@ .then(result => {

```
### options
The options for `ocr(options)` are as follows.
* url `string`: URL of the image.
* Values: `n/a`
* Default: `null`
* mode `string`: What type of optical recognition will be run, such as OCR.
* Values: `ocr`
* Default: `ocr`
#### Local path Example
```js
let options = {
image: '/Users/username/Desktop/my-image.png', // local path to the image
mode: 'ocr', // ocr
};
optiic.process(options)
.then(result => {
console.log(result);
})
```
#### HTML Input Example
```html
<form class="" action="" method="post">
<input type="file" name="image" accept="image/*">
<button type="submit">Submit</button>
</form>
<script type="text/javascript">
var myForm = document.querySelector('form');
myForm.addEventListener('submit', function (event) {
event.preventDefault();
optiic.process({
image: myForm.querySelector('input[type="file"]'),
})
.then(response => {
console.log(response);
})
})
</script>
```
## Extending Capabilities

@@ -106,13 +152,15 @@ For a more in-depth documentation of this library and the Optiic service, please visit the official Optiic website.

```shell
# OCR
# Standard
curl -X POST https://api.optiic.dev/process
# With options
curl -d "url=https://example.com/my-image" -X POST https://api.optiic.dev/process
# With options (alternative)
curl -d '{"url": "https://example.com/my-image"}' -H 'Content-Type: application/json' https://api.optiic.dev/process
# OCR with URL
curl -d '{"apiKey": "test_api_key", "mode": "ocr", "url": "https://via.placeholder.com/468x60?text=Sample+text"}' -H 'Content-Type: application/json' https://api.optiic.dev/process
# OCR with image file
curl \
-F "apiKey=test_api_key" \
-F "mode=ocr" \
-F "image=@/Users/username/Desktop/my-image.png" \
https://api.optiic.dev/process
```
## What Can Optiic do?
[Optiic is a free proxy api](https://optiic.dev) that helps you get free proxy lists and check your public IP.
[Optiic is a free OCR api](https://optiic.dev) that helps you analyze images and perform OCR (optical character recognition)!

@@ -119,0 +167,0 @@ ## Final Words

@@ -17,3 +17,8 @@ (function (root, factory) {

var fs;
var NodeFormData;
var nodeFetch;
var environment = (Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]') ? 'node' : 'browser';
var isRemoteURL = /^https?:\/\/|^\/\//i;

@@ -27,13 +32,43 @@ function Optiic(options) {

if (options.local) {
console.log('Optiic options', options);
}
this.options = options;
};
function checkLocalPathString(input) {
return typeof input === 'string' && !isRemoteURL.test(input);
}
function checkInputElement(input) {
return typeof input === 'object' && input.tagName === 'INPUT' && input.files && input.files[0];
}
function checkFileObject(input) {
return !checkInputElement(input) && typeof input === 'object' && typeof input.name === 'string';
}
Optiic.prototype.process = function (options) {
let This = this;
var This = this;
var formData;
if (!NodeFormData) {
NodeFormData = This.options.environment === 'browser' ? window.FormData : require('form-data');
}
if (!nodeFetch) {
nodeFetch = This.options.environment === 'browser' ? window.fetch : require('node-fetch');
}
options = options || {};
options.url = options.url || '';
options.url = options.url || options.path || options.image || '';
options.mode = options.mode || 'ocr';
delete options.path;
delete options.image;
return new Promise(function(resolve, reject) {
var config = {};
var isLocalPathString = checkLocalPathString(options.url);
var isInputElement = checkInputElement(options.url);
var isFileObject = checkFileObject(options.url);

@@ -43,2 +78,6 @@ // Checks

return reject(new Error('Missing parameter url'))
} else if (typeof options.url !== 'string' && !isInputElement && !isFileObject) {
return reject(new Error('Improperly formatted url or image input'))
} else if (isLocalPathString && This.options.environment !== 'node') {
return reject(new Error('This environment does not have permission to use a local path as the url so use a file input instead'))
}

@@ -51,2 +90,25 @@

if (isLocalPathString || isInputElement || isFileObject) {
var keys = Object.keys(options);
formData = new NodeFormData();
if (This.options.environment === 'node') {
fs = fs || require('fs');
}
if (isLocalPathString) {
formData.append('image', fs.createReadStream(options.url));
} else if (isInputElement) {
formData.append('image', This.options.environment === 'node' ? fs.createReadStream(options.url.files[0].path) : options.url.files[0]);
} else if (isFileObject) {
formData.append('image', This.options.environment === 'node' ? fs.createReadStream(options.url.path) : options.url);
}
for (var i = 0, l = keys.length; i < l; i++) {
var key = keys[i];
if (key === 'url' || key === 'image' || typeof options[key] === 'undefined') {
continue;
}
formData.append(key, options[key]);
}
options = formData;
}
return This._request(config, options)

@@ -64,59 +126,59 @@ .then(function (r) {

Optiic.prototype._request = function (config, body) {
let This = this;
var content = 'application/json';
var This = this;
var method = (config.method || 'post').toLowerCase();
var isForm = body && typeof body.append === 'function';
var contentJSON = 'application/json';
var serverAddy;
var headers = {
'cache-control': 'no-cache',
'Accept': contentJSON,
}
if (This.options.local) {
config.hostname = 'localhost';
config.path = 'process';
// config.port = 5000;
if (isForm) {
body.append('apiKey', This.options.apiKey);
} else {
headers['Content-Type'] = contentJSON;
body.apiKey = This.options.apiKey;
body = stringify(body);
}
return new Promise(function(resolve, reject) {
var https = require('https');
var method = (config.method || 'POST').toUpperCase();
config = {
'method': method,
'hostname': config.hostname || 'api.optiic.dev',
'port': config.port || 443,
'path': config.path,
'headers': {
// 'x-dreamfactory-api-key': 'YOUR_API_KEY',
'cache-control': 'no-cache',
'Content-Type': content,
'Accept': content,
}
if (This.options.local) {
serverAddy = 'http://localhost:5000/' + config.path;
} else {
serverAddy = 'https://api.optiic.dev/' + config.path;
}
console.log('config', config);
// Make request
var req = https.request(config, function(res) {
var chunks = [];
res.on('data', function (chunk) {
chunks.push(chunk);
});
res.on('end', function() {
var body = Buffer.concat(chunks);
if (res.statusCode >= 200 && res.statusCode < 300) {
return resolve(JSON.parse(body.toString()));
} else {
return reject(new Error(res.statusMessage));
}
});
res.on('error', function(e) {
console.log('-----e', e);
return reject(e);
});
});
if (method === 'POST') {
req.write(stringify(body || {}));
}
req.end();
nodeFetch(serverAddy, {
method: method,
body: body,
headers: headers,
})
.then(function (res) {
if (This.options.local) {
console.log('Fetch response:', res);
}
if (res.status >= 200 && res.status < 300) {
res.json()
.then(function (json) {
return resolve(json);
})
.catch(function (e) {
return reject(e);
})
} else {
res.text()
.then(function (text) {
return reject(new Error(text || res.statusText));
})
.catch(function (e) {
return reject(e);
})
}
})
.catch(function (e) {
return reject(e);
})
});

@@ -123,0 +185,0 @@ }

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