unprint 0.10.10 → 0.10.12

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 (3) hide show
  1. package/README.md +2 -2
  2. package/package.json +1 -1
  3. package/src/app.js +14 -2
package/README.md CHANGED
@@ -24,14 +24,14 @@ For optimal flexibility, unprint query methods can be used with or without initi
24
24
  Both `unprint.get()` and `unprint.init()` return its `query` methods pre-initialized, removing the element argument in favor of the element retrieved or received. Initialized query methods therefore will *not* accept a custom element, usually expecting the selector as the first argument instead.
25
25
 
26
26
  ```javascript
27
- const result = await unprint.get('http://localhot:3101/html');
27
+ const result = await unprint.get('http://localhost:3101/html');
28
28
  const { query } = result.context;
29
29
 
30
30
  query.element('h1#title'); // HTMLHeadingElement
31
31
  ```
32
32
 
33
33
  ```javascript
34
- const result = await fetch('http://localhot:3101/html');
34
+ const result = await fetch('http://localhost:3101/html');
35
35
  const body = await res.text();
36
36
  const { query } = await unprint.init(body);
37
37
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unprint",
3
- "version": "0.10.10",
3
+ "version": "0.10.12",
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
@@ -135,7 +135,9 @@ function extractContent(element, options) {
135
135
 
136
136
  if (attributeKey) {
137
137
  // handle attribute extraction in content method so all methods can easily optionally query a specific attribute
138
- const attribute = element[attributeKey] || element.getAttribute(attributeKey);
138
+ const attribute = options.forceGetAttribute
139
+ ? element.getAttribute(attributeKey)
140
+ : element[attributeKey] || element.getAttribute(attributeKey);
139
141
 
140
142
  if (attribute && options.trim) {
141
143
  return trim(attribute);
@@ -182,7 +184,11 @@ function queryAttributes(context, selector, attribute, customOptions) {
182
184
  function queryDataset(context, selector, dataAttribute, customOptions) {
183
185
  const target = queryElement(context, selector, customOptions);
184
186
 
185
- return target.dataset[dataAttribute];
187
+ if (target) {
188
+ return target.dataset[dataAttribute];
189
+ }
190
+
191
+ return null;
186
192
  }
187
193
 
188
194
  function queryDatasets(context, selector, dataAttribute, customOptions) {
@@ -350,6 +356,7 @@ function queryUrl(context, selector = 'a', customOptions) {
350
356
  const options = {
351
357
  ...context.options,
352
358
  attribute: 'href',
359
+ forceGetAttribute: true, // don't get origin URL when empty
353
360
  ...customOptions,
354
361
  };
355
362
 
@@ -362,6 +369,7 @@ function queryUrls(context, selector = 'a', customOptions) {
362
369
  const options = {
363
370
  ...context.options,
364
371
  attribute: 'href',
372
+ forceGetAttribute: true, // don't get origin URL when empty
365
373
  ...customOptions,
366
374
  };
367
375
 
@@ -401,6 +409,7 @@ function queryImage(context, selector = 'img', customOptions) {
401
409
  const options = {
402
410
  ...context.options,
403
411
  ...customOptions,
412
+ forceGetAttribute: true, // don't get origin URL when empty
404
413
  };
405
414
 
406
415
  const imageUrl = getImageUrl(context, selector, options);
@@ -412,6 +421,7 @@ function queryImages(context, selector = 'img', customOptions) {
412
421
  const options = {
413
422
  ...context.options,
414
423
  ...customOptions,
424
+ forceGetAttribute: true, // don't get origin URL when empty
415
425
  };
416
426
 
417
427
  const imageUrls = getImageUrls(context, selector, options);
@@ -477,6 +487,7 @@ function queryVideo(context, selector = 'source', customOptions) {
477
487
  const options = {
478
488
  ...context.options,
479
489
  attribute: 'src',
490
+ forceGetAttribute: true, // don't get origin URL when empty
480
491
  ...customOptions,
481
492
  };
482
493
 
@@ -489,6 +500,7 @@ function queryVideos(context, selector = 'source', customOptions) {
489
500
  const options = {
490
501
  ...context.options,
491
502
  attribute: 'src',
503
+ forceGetAttribute: true, // don't get origin URL when empty
492
504
  ...customOptions,
493
505
  };
494
506