unprint 0.10.3 → 0.10.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unprint",
3
- "version": "0.10.3",
3
+ "version": "0.10.4",
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
@@ -603,12 +603,12 @@ function extractDuration(durationString, match) {
603
603
  }
604
604
 
605
605
  function extractTimestamp(durationString) {
606
- const timestampMatch = durationString?.match(/(\d+H)?\s*(\d+M)?\s*\d+S?/i);
606
+ const timestampMatch = durationString?.match(/(\d+\s*H)?.*(\d+\s*M)?.*(\d+\s*(S|$))?/i)?.[0];
607
607
 
608
608
  if (timestampMatch) {
609
- const hours = timestampMatch[0].match(/(\d+)H/i)?.[1] || 0;
610
- const minutes = timestampMatch[0].match(/(\d+)M/i)?.[1] || 0;
611
- const seconds = timestampMatch[0].match(/(\d+)(S|$)/i)?.[1] || 0;
609
+ const hours = timestampMatch.match(/(\d+)\s*H/i)?.[1] || 0;
610
+ const minutes = timestampMatch.match(/(\d+)\s*M/i)?.[1] || 0;
611
+ const seconds = timestampMatch.match(/(\d+)\s*(s(ec\w*)?)|$/i)?.[1] || 0;
612
612
 
613
613
  return (Number(hours) * 3600) + (Number(minutes) * 60) + Number(seconds);
614
614
  }
package/tests/index.html CHANGED
@@ -32,6 +32,7 @@
32
32
 
33
33
  <div id="duration">01:15:33</div>
34
34
  <div id="timestamp">PT1H34M18S</div>
35
+ <div id="timestring">1 hour 40 minutes 5 seconds</div>
35
36
 
36
37
  <img class="image" src="https://i.redd.it/vn9h981hlx281.png">
37
38
  <img class="image" src="https://i.redd.it/1s22dsrqy0181.jpg">
package/tests/init.js CHANGED
@@ -21,6 +21,7 @@ async function initTest() {
21
21
  console.log('date xpath', res.context.query.date('//div[contains(text(), "Today:")]', 'MMM DD, YYYY'));
22
22
  console.log('duration', res.context.query.duration('#duration'));
23
23
  console.log('timestamp', res.context.query.duration('#timestamp'));
24
+ console.log('timestring', res.context.query.duration('#timestring'));
24
25
  console.log('number', res.context.query.number('.number'));
25
26
  console.log('numbers', res.context.query.numbers('.number'));
26
27
  console.log('number indexed', res.context.query.number('.number', { match: /(\d+)/, matchIndex: 1 }));