utilitas 1998.2.30 → 1998.2.32

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": "1998.2.30",
4
+ "version": "1998.2.32",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
@@ -33,7 +33,7 @@ const manifest = {
33
33
  "@google-cloud/text-to-speech": "^5.8.0",
34
34
  "@google-cloud/vision": "^4.3.2",
35
35
  "@google/generative-ai": "^0.21.0",
36
- "@mozilla/readability": "^0.5.0",
36
+ "@mozilla/readability": "github:mozilla/readability",
37
37
  "@ngrok/ngrok": "^1.4.1",
38
38
  "@sentry/node": "^8.52.0",
39
39
  "@sentry/profiling-node": "^8.52.0",
package/lib/shot.mjs CHANGED
@@ -19,6 +19,8 @@ const [_JSON, _PARSED] = ['JSON', 'PARSED'];
19
19
  const getJson = async (u, o) => await get(u, { encode: _JSON, ...o || {} });
20
20
  const getParsedHtml = async (u, o) => await get(u, { encode: _PARSED, ...o || {} });
21
21
 
22
+ let searchProvider, googleApiKey, googleCx;
23
+
22
24
  const defFetchOpt = {
23
25
  redirect: 'follow', follow: 3, timeout: 1000 * 10, headers: {
24
26
  'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) '
@@ -148,19 +150,35 @@ const get = async (url, options) => {
148
150
  };
149
151
  };
150
152
 
153
+ const initSearch = (options) => {
154
+ assert(
155
+ options?.provider && options?.apiKey && options?.cx,
156
+ 'Invalid search options.'
157
+ );
158
+ return [searchProvider, googleApiKey, googleCx]
159
+ = [options.provider, options.apiKey, options.cx];
160
+ };
161
+
151
162
  const search = async (query, options) => {
152
163
  assert(query, 'Query is required.');
153
164
  const [GOOGLE, DUCKDUCKGO] = ['GOOGLE', 'DUCKDUCKGO'];
154
- const provider = ensureString(options?.provider, { case: 'UP' }) || DUCKDUCKGO;
155
- let url, parser;
165
+ const provider = ensureString(
166
+ options?.provider || searchProvider || DUCKDUCKGO, { case: 'UP' }
167
+ );
168
+ let apiKey = options?.apiKey || googleApiKey, cx = options?.cx || googleCx,
169
+ url, parser;
156
170
  switch (provider) {
157
171
  case GOOGLE:
158
- assert(options?.apiKey, 'API key is required.');
159
- assert(options?.cx, 'CX is required.');
160
- url = `https://www.googleapis.com/customsearch/v1?key=${options.apiKey}&cx=${options.cx}&q=${encodeURIComponent(query)}`;
172
+ assert(apiKey, 'API key is required.');
173
+ assert(cx, 'CX is required.');
174
+ url = 'https://www.googleapis.com/customsearch/v1'
175
+ + `?key=${encodeURIComponent(apiKey)}`
176
+ + `&cx=${encodeURIComponent(cx)}`
177
+ + `&q=${encodeURIComponent(query)}`;
161
178
  break;
162
179
  case DUCKDUCKGO:
163
- url = `https://api.duckduckgo.com/?q=${encodeURIComponent(query)}&format=json&skip_disambig=1`;
180
+ url = 'https://api.duckduckgo.com/'
181
+ + `?q=${encodeURIComponent(query)}&format=json&skip_disambig=1`;
164
182
  parser = x => x.FirstURL ? {
165
183
  title: x.FirstURL.replace(/^.*\/([^\/]*)$/, '$1').replace(/_/g, ' '),
166
184
  link: x.FirstURL, snippet: x.Text,
@@ -212,6 +230,5 @@ export {
212
230
  getCurrentPosition,
213
231
  getJson,
214
232
  getParsedHtml,
215
- getVersionOnNpm,
216
- search
233
+ getVersionOnNpm, initSearch, search
217
234
  };
package/lib/web.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { assembleUrl, ignoreErrFunc, need, throwError } from './utilitas.mjs';
2
1
  import { getJson, getParsedHtml } from './shot.mjs';
3
2
  import { convert } from './storage.mjs';
3
+ import { assembleUrl, ignoreErrFunc, need, throwError } from './utilitas.mjs';
4
4
 
5
5
  const _NEED = [
6
6
  'jsdom', 'youtube-transcript', '@mozilla/readability', '@ngrok/ngrok'
@@ -123,5 +123,5 @@ export {
123
123
  forward,
124
124
  getYoutubeMetadata,
125
125
  getYoutubeTranscript,
126
- isYoutubeUrl,
126
+ isYoutubeUrl
127
127
  };
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": "1998.2.30",
4
+ "version": "1998.2.32",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
@@ -44,7 +44,7 @@
44
44
  "@google-cloud/text-to-speech": "^5.8.0",
45
45
  "@google-cloud/vision": "^4.3.2",
46
46
  "@google/generative-ai": "^0.21.0",
47
- "@mozilla/readability": "^0.5.0",
47
+ "@mozilla/readability": "github:mozilla/readability",
48
48
  "@ngrok/ngrok": "^1.4.1",
49
49
  "@sentry/node": "^8.52.0",
50
50
  "@sentry/profiling-node": "^8.52.0",