utilitas 1998.2.21 → 1998.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": "1998.2.21",
4
+ "version": "1998.2.22",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
package/lib/shot.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { distillHtml } from './web.mjs';
2
1
  import { fileTypeFromBuffer } from 'file-type';
3
- import { join } from 'path';
4
2
  import { promises as fs } from 'fs';
3
+ import { join } from 'path';
5
4
  import { sha256 } from './encryption.mjs';
5
+ import { distillHtml } from './web.mjs';
6
6
 
7
7
  import {
8
8
  ensureString, extract, ignoreErrFunc, inBrowser, parseJson, parseVersion,
@@ -148,6 +148,20 @@ const get = async (url, options) => {
148
148
  };
149
149
  };
150
150
 
151
+ const search = async (query, options) => {
152
+ assert(query, 'Query is required.');
153
+ assert(options?.apiKey, 'API key is required.');
154
+ assert(options?.cx, 'CX is required.');
155
+ const resp = await get(
156
+ `https://www.googleapis.com/customsearch/v1?key=${options.apiKey}&cx=${options.cx}&q=${encodeURIComponent(query)}`,
157
+ { encode: _JSON, ...options || {} }
158
+ )
159
+ return options?.raw ? resp.content : resp.content.items.map(x => ({
160
+ title: x.title, link: x.link, snippet: x.snippet,
161
+ image: x.pagemap?.cse_image?.[0]?.src,
162
+ }));
163
+ };
164
+
151
165
  export default get;
152
166
  export {
153
167
  checkVersion,
@@ -157,4 +171,5 @@ export {
157
171
  getJson,
158
172
  getParsedHtml,
159
173
  getVersionOnNpm,
174
+ search
160
175
  };
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.21",
4
+ "version": "1998.2.22",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",