utilitas 1995.2.21 → 1995.2.22

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.21",
4
+ "version": "1995.2.22",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
package/lib/uoid.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { assertUrl, basename, ensureString, rotate } from './utilitas.mjs';
2
2
  import { hexToBigInt, md5, randomString, uniqueString } from './encryption.mjs';
3
- import { v1 as uuidv1, v5 as uuidv5 } from 'uuid';
3
+ import { v4 as uuidv4, v5 as uuidv5 } from 'uuid';
4
4
  import manifest from './manifest.mjs';
5
5
 
6
6
  // https://stackoverflow.com/questions/7905929/how-to-test-valid-uuid-guid
@@ -19,7 +19,7 @@ const getTimestampFromUuid = (uuid) => uuid ? Number((BigInt(
19
19
  ) - 122192928000000000n) / 10000n) : 0;
20
20
 
21
21
  const create = (options) => {
22
- options = Object.assign({ file: import.meta.url, id: uuidv1() }, options || {});
22
+ options = Object.assign({ file: import.meta.url, id: uuidv4() }, options || {});
23
23
  options.type = options.type || basename(options.file);
24
24
  if ((options.security = ~~options.security) === 1) {
25
25
  options.security = 128;
package/lib/vision.mjs CHANGED
@@ -7,8 +7,10 @@ import {
7
7
  trim,
8
8
  } from './utilitas.mjs';
9
9
 
10
+ import { v4 as uuidv4 } from 'uuid';
10
11
  import { getApiKeyCredentials } from './encryption.mjs';
11
12
  import fs from 'node:fs';
13
+ import path from 'node:path';
12
14
 
13
15
  const _NEED = [
14
16
  '@google-cloud/vision', 'office-text-extractor', 'pdfjs-dist',
@@ -18,7 +20,7 @@ const _NEED = [
18
20
  const [BASE64, BUFFER, FILE, DEFAULT_LANG] = ['BASE64', 'BUFFER', 'FILE', 'eng'];
19
21
  const ceil = num => num.toFixed(4);
20
22
  const errorMessage = 'Invalid input data.';
21
- const getTextFromBatch = bt => bt.responses.map(p => p.fullTextAnnotation.text);
23
+ const getTextFromBatch = b => b.responses.map(p => p?.fullTextAnnotation?.text || '');
22
24
  const DOCUMENT_TEXT_DETECTION = 'DOCUMENT_TEXT_DETECTION';
23
25
  const features = [{ type: DOCUMENT_TEXT_DETECTION }];
24
26
  const mimeType = 'application/pdf';
@@ -181,7 +183,7 @@ const read = async (image, options) => {
181
183
  const content = await convert(image, {
182
184
  input: options?.input, expected: BASE64, errorMessage,
183
185
  });
184
- let result = await client.batchAnnotateFiles({
186
+ const result = await client.batchAnnotateFiles({
185
187
  requests: [{ inputConfig: { mimeType, content }, features, pages }],
186
188
  });
187
189
  return options?.raw ? result : getTextFromBatch(result[0].responses[0]);
@@ -191,7 +193,8 @@ const readAll = async (image, options) => {
191
193
  assert(client, 'Vision API has not been initialized.', 500);
192
194
  const result = {};
193
195
  result.upload = await uploadToCloud(image, {
194
- gzip: false, prefix: options?.prefix || '_vision', ...options || {},
196
+ destination: path.join(options?.prefix || '_vision', `${uuidv4()}.pdf`),
197
+ ...options || {},
195
198
  });
196
199
  const uri = result.upload?.gs;
197
200
  const destination = `${uri}_result/`;
@@ -240,7 +243,7 @@ const getPdfInfo = async (file, options) => {
240
243
  const result = {
241
244
  numPages: doc.numPages,
242
245
  info: data.info,
243
- metadata: { ...data.metadata.getAll() },
246
+ metadata: { ...data.metadata?.getAll() },
244
247
  pages: options?.withPages ? await getPdfPages(doc) : null,
245
248
  };
246
249
  return result;
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.21",
4
+ "version": "1995.2.22",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",