unprint 0.10.3 → 0.10.5
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 +1 -1
- package/src/app.js +5 -5
- package/tests/index.html +1 -0
- package/tests/init.js +1 -0
package/package.json
CHANGED
package/src/app.js
CHANGED
|
@@ -191,7 +191,7 @@ function queryDatasets(context, selector, dataAttribute, customOptions) {
|
|
|
191
191
|
return targets.map((target) => target.dataset[dataAttribute]);
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
-
const defaultNumberRegexp = /\d+(
|
|
194
|
+
const defaultNumberRegexp = /\d+([.,]\d+)?/;
|
|
195
195
|
|
|
196
196
|
function matchNumberString(numberString, options) {
|
|
197
197
|
if (numberString && options.match) {
|
|
@@ -603,12 +603,12 @@ function extractDuration(durationString, match) {
|
|
|
603
603
|
}
|
|
604
604
|
|
|
605
605
|
function extractTimestamp(durationString) {
|
|
606
|
-
const timestampMatch = durationString?.match(/(\d
|
|
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
|
|
610
|
-
const minutes = timestampMatch
|
|
611
|
-
const seconds = timestampMatch
|
|
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 }));
|