unprint 0.18.15 → 0.18.17

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/app.js +3 -59
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unprint",
3
- "version": "0.18.15",
3
+ "version": "0.18.17",
4
4
  "description": "Simplify common web scraping tasks while staying in control of the data.",
5
5
  "main": "src/app.js",
6
6
  "scripts": {},
package/src/app.js CHANGED
@@ -374,68 +374,12 @@ function prefixUrl(urlPath, originUrl, customOptions) {
374
374
  ...customOptions,
375
375
  };
376
376
 
377
- if (/^http/.test(urlPath)) {
378
- // this is already a complete URL
379
- return urlPath;
380
- }
381
-
382
- if (options.protocol && /^\/\//.test(urlPath)) {
383
- return `${options.protocol.replace(/:$/, '')}:${urlPath}`; // allow protocol to be defined either as 'https' or 'https:'
384
- }
385
-
386
- if (!originUrl) {
387
- return urlPath;
388
- }
389
-
390
- const { origin, protocol } = new URL(originUrl);
391
-
392
- if (protocol && /^\/\//.test(urlPath)) {
393
- return `${protocol}${urlPath}`;
394
- }
395
-
396
- if (/^\//.test(urlPath)) {
397
- return `${origin}${urlPath}`;
398
- }
399
-
400
- if (/^\.\//.test(urlPath)) {
401
- return `${originUrl.replace(/\/+$/, '')}${urlPath.slice(1)}`;
402
- }
403
-
404
- return `${origin}/${urlPath}`;
405
- }
406
-
407
- // legacy argument
408
- function getQueryUrlArgs(selectorOrOptions, customOptions) {
409
- if (customOptions) {
410
- return {
411
- selector: selectorOrOptions,
412
- customOptions,
413
- };
414
- }
415
-
416
- if (typeof selectorOrOptions === 'string') {
417
- return {
418
- selector: selectorOrOptions,
419
- customOptions: null,
420
- };
421
- }
377
+ const origin = originUrl?.replace(/^.*?:/, `${options.protocol}:`);
422
378
 
423
- if (!selectorOrOptions) {
424
- return {
425
- selector: 'a',
426
- customOptions: null,
427
- };
428
- }
429
-
430
- return {
431
- selector: 'a',
432
- customOptions: selectorOrOptions,
433
- };
379
+ return new URL(urlPath, origin).href;
434
380
  }
435
381
 
436
- function queryUrl(context, ...args) {
437
- const { selector, customOptions } = getQueryUrlArgs(...args);
438
-
382
+ function queryUrl(context, selector = 'a', customOptions) {
439
383
  const options = {
440
384
  ...context.options,
441
385
  attribute: 'href',