utilitas 1995.2.4 → 1995.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/manifest.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  const manifest = {
2
2
  "name": "utilitas",
3
3
  "description": "Just another common utility for JavaScript.",
4
- "version": "1995.2.4",
4
+ "version": "1995.2.5",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
package/lib/vision.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { getApiKeyCredentials } from './encryption.mjs';
2
+ import get from './shot.mjs';
2
3
 
3
4
  import {
4
5
  convert, deleteOnCloud, downloadFromCloud, getIdByGs, uploadToCloud,
@@ -12,6 +13,7 @@ const _NEED = ['@google-cloud/vision', 'tesseract.js'];
12
13
  const [BASE64, BUFFER, FILE, DEFAULT_LANG] = ['BASE64', 'BUFFER', 'FILE', 'eng'];
13
14
  const ceil = num => num.toFixed(4);
14
15
  const errorMessage = 'Invalid image data.';
16
+ const getTextFromBatch = bt => bt.responses.map(p => p.fullTextAnnotation.text);
15
17
  const log = content => _log(content, import.meta.url);
16
18
 
17
19
  let client;
@@ -125,16 +127,14 @@ const read = async (image, options) => {
125
127
  const content = await convert(image, {
126
128
  input: options?.input, expected: BASE64, errorMessage,
127
129
  });
128
- const [response] = await client.batchAnnotateFiles({
130
+ let result = await client.batchAnnotateFiles({
129
131
  requests: [{
130
132
  inputConfig: { mimeType: 'application/pdf', content },
131
133
  features: [{ type: 'DOCUMENT_TEXT_DETECTION' }],
132
134
  pages: [1, 2, 3, 4, 5], // max 5 pages
133
135
  }],
134
136
  });
135
- let pages = response.responses[0].responses;
136
- options?.raw || (pages = pages.map(x => x.fullTextAnnotation.text));
137
- return pages;
137
+ return options?.raw ? result : getTextFromBatch(result[0].responses[0]);
138
138
  };
139
139
 
140
140
  const readAll = async (image, options) => {
@@ -159,14 +159,9 @@ const readAll = async (image, options) => {
159
159
  options?.keep || (result.cleanup = await Promise.all(
160
160
  [getIdByGs(uri), resultId].map(deleteOnCloud)
161
161
  ));
162
- if (options?.raw) { return result; }
163
- const pages = [];
164
- for (let file in result.result) {
165
- result.result[file].responses.map(x => pages.push(
166
- x.fullTextAnnotation.text
167
- ));
168
- }
169
- return pages;
162
+ return options?.raw ? result : Object.keys(result.result).map(
163
+ f => getTextFromBatch(result.result[f])
164
+ ).flat();
170
165
  };
171
166
 
172
167
  export {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "utilitas",
3
3
  "description": "Just another common utility for JavaScript.",
4
- "version": "1995.2.4",
4
+ "version": "1995.2.5",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",