utilitas 1995.2.21 → 1995.2.23
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/README.md +3 -2
- package/dist/utilitas.lite.mjs +1 -1
- package/dist/utilitas.lite.mjs.map +1 -1
- package/lib/email.mjs +13 -2
- package/lib/manifest.mjs +2 -1
- package/lib/uoid.mjs +2 -2
- package/lib/vision.mjs +21 -12
- package/lib/web.mjs +6 -1
- package/package.json +2 -1
package/lib/email.mjs
CHANGED
|
@@ -3,11 +3,13 @@ import {
|
|
|
3
3
|
which
|
|
4
4
|
} from './utilitas.mjs';
|
|
5
5
|
|
|
6
|
+
import { convert } from './storage.mjs';
|
|
6
7
|
import { isPrimary } from './callosum.mjs';
|
|
7
8
|
|
|
8
|
-
const _NEED = ['form-data', 'mailgun.js', 'node-mailjet'];
|
|
9
|
+
const _NEED = ['form-data', 'mailgun.js', 'mailparser', 'node-mailjet'];
|
|
9
10
|
const getSenderName = () => senderName;
|
|
10
11
|
const log = (content) => _log(content, import.meta.url);
|
|
12
|
+
const TEXT = 'TEXT';
|
|
11
13
|
|
|
12
14
|
let domain, senderName, senderEmail, provider, client;
|
|
13
15
|
|
|
@@ -90,13 +92,22 @@ const send = async (email, subject, text, html, args, options) => {
|
|
|
90
92
|
senderName: options.senderName, senderEmail: options.senderEmail,
|
|
91
93
|
to: uniqueArray(email), subject, text
|
|
92
94
|
}, html ? { html } : {}));
|
|
93
|
-
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const parse = async (input, options) => {
|
|
98
|
+
const { simpleParser } = await need('mailparser');
|
|
99
|
+
const email = await convert(input, {
|
|
100
|
+
input: TEXT, expected: TEXT, ...options || {},
|
|
101
|
+
});
|
|
102
|
+
return await simpleParser(email, options);
|
|
103
|
+
};
|
|
94
104
|
|
|
95
105
|
export default init;
|
|
96
106
|
export {
|
|
97
107
|
_NEED,
|
|
98
108
|
getSenderName,
|
|
99
109
|
init,
|
|
110
|
+
parse,
|
|
100
111
|
rawSend,
|
|
101
112
|
send,
|
|
102
113
|
};
|
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
|
+
"version": "1995.2.23",
|
|
5
5
|
"private": false,
|
|
6
6
|
"homepage": "https://github.com/Leask/utilitas",
|
|
7
7
|
"main": "index.mjs",
|
|
@@ -44,6 +44,7 @@ const manifest = {
|
|
|
44
44
|
"jsdom": "^23.0.1",
|
|
45
45
|
"lorem-ipsum": "^2.0.8",
|
|
46
46
|
"mailgun.js": "^9.3.0",
|
|
47
|
+
"mailparser": "^3.6.5",
|
|
47
48
|
"mime-types": "^2.1.35",
|
|
48
49
|
"mysql2": "^3.6.5",
|
|
49
50
|
"node-mailjet": "^6.0.5",
|
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 {
|
|
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:
|
|
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,14 +20,14 @@ 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 =
|
|
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';
|
|
25
27
|
const pages = [1, 2, 3, 4, 5]; // max 5 pages limit for batchAnnotateFiles API
|
|
26
28
|
const log = content => _log(content, import.meta.url);
|
|
27
29
|
|
|
28
|
-
let client
|
|
30
|
+
let client;
|
|
29
31
|
|
|
30
32
|
const init = async (options) => {
|
|
31
33
|
if (options) {
|
|
@@ -49,16 +51,22 @@ const parseOfficeFile = async (source, options) => {
|
|
|
49
51
|
}];
|
|
50
52
|
switch (ensureString(options?.lib || OTE, { case: 'LOW' })) {
|
|
51
53
|
case OTE:
|
|
52
|
-
|
|
53
|
-
await need(OTE)
|
|
54
|
-
).getTextExtractor());
|
|
54
|
+
const officeParser = (await need(OTE)).getTextExtractor();
|
|
55
55
|
const input = await convert(source, { ...opts, expected: BUFFER });
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
try {
|
|
57
|
+
return await officeParser.extractText({
|
|
58
|
+
input, type: BUFFER.toLowerCase(),
|
|
59
|
+
});
|
|
60
|
+
} catch (err) {
|
|
61
|
+
if (/application\/x\-cfb$/.test(err.message)) {
|
|
62
|
+
err.message += ` (https://github.com/gamemaker1/office-text-extractor/issues/10)`;
|
|
63
|
+
}
|
|
64
|
+
throwError(err.message);
|
|
65
|
+
}
|
|
59
66
|
case XLSX:
|
|
60
67
|
// https://docs.sheetjs.com/docs/getting-started/installation/nodejs
|
|
61
|
-
|
|
68
|
+
const xlsx = await need(XLSX)
|
|
69
|
+
xlsx.set_fs(fs);
|
|
62
70
|
const { content, cleanup } = await convert(source, {
|
|
63
71
|
...opts, expected: FILE, withCleanupFunc: true
|
|
64
72
|
});
|
|
@@ -181,7 +189,7 @@ const read = async (image, options) => {
|
|
|
181
189
|
const content = await convert(image, {
|
|
182
190
|
input: options?.input, expected: BASE64, errorMessage,
|
|
183
191
|
});
|
|
184
|
-
|
|
192
|
+
const result = await client.batchAnnotateFiles({
|
|
185
193
|
requests: [{ inputConfig: { mimeType, content }, features, pages }],
|
|
186
194
|
});
|
|
187
195
|
return options?.raw ? result : getTextFromBatch(result[0].responses[0]);
|
|
@@ -191,7 +199,8 @@ const readAll = async (image, options) => {
|
|
|
191
199
|
assert(client, 'Vision API has not been initialized.', 500);
|
|
192
200
|
const result = {};
|
|
193
201
|
result.upload = await uploadToCloud(image, {
|
|
194
|
-
|
|
202
|
+
destination: path.join(options?.prefix || '_vision', `${uuidv4()}.pdf`),
|
|
203
|
+
...options || {},
|
|
195
204
|
});
|
|
196
205
|
const uri = result.upload?.gs;
|
|
197
206
|
const destination = `${uri}_result/`;
|
|
@@ -240,7 +249,7 @@ const getPdfInfo = async (file, options) => {
|
|
|
240
249
|
const result = {
|
|
241
250
|
numPages: doc.numPages,
|
|
242
251
|
info: data.info,
|
|
243
|
-
metadata: { ...data.metadata
|
|
252
|
+
metadata: { ...data.metadata?.getAll() },
|
|
244
253
|
pages: options?.withPages ? await getPdfPages(doc) : null,
|
|
245
254
|
};
|
|
246
255
|
return result;
|
package/lib/web.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assembleUrl, ignoreErrFunc, need, throwError } from './utilitas.mjs';
|
|
2
2
|
import { getJson, getParsedHtml } from './shot.mjs';
|
|
3
|
+
import { convert } from './storage.mjs';
|
|
3
4
|
|
|
4
5
|
const _NEED = [
|
|
5
6
|
'jsdom', 'youtube-transcript', '@mozilla/readability', '@ngrok/ngrok'
|
|
@@ -9,8 +10,12 @@ const _NEED = [
|
|
|
9
10
|
const YT_REGEXP = /^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube(-nocookie)?\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?$/i;
|
|
10
11
|
const isYoutubeUrl = url => (url || '').match(YT_REGEXP)?.[6];
|
|
11
12
|
const distillPage = async (url, op) => (await getParsedHtml(url, op))?.content;
|
|
13
|
+
const TEXT = 'TEXT';
|
|
12
14
|
|
|
13
|
-
const distillHtml = async (
|
|
15
|
+
const distillHtml = async (input, options) => {
|
|
16
|
+
const html = await convert(input, {
|
|
17
|
+
input: TEXT, expected: TEXT, ...options || {},
|
|
18
|
+
});
|
|
14
19
|
const lib = await Promise.all([need('jsdom'), need('@mozilla/readability')]);
|
|
15
20
|
const [JSDOM, Readability] = [lib[0].JSDOM, lib[1].Readability];
|
|
16
21
|
const _doc = new JSDOM(html)?.window?.document;
|
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
|
+
"version": "1995.2.23",
|
|
5
5
|
"private": false,
|
|
6
6
|
"homepage": "https://github.com/Leask/utilitas",
|
|
7
7
|
"main": "index.mjs",
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"jsdom": "^23.0.1",
|
|
56
56
|
"lorem-ipsum": "^2.0.8",
|
|
57
57
|
"mailgun.js": "^9.3.0",
|
|
58
|
+
"mailparser": "^3.6.5",
|
|
58
59
|
"mime-types": "^2.1.35",
|
|
59
60
|
"mysql2": "^3.6.5",
|
|
60
61
|
"node-mailjet": "^6.0.5",
|