Skip to content

Commit cc1155c

Browse files
committed
moved reused function to module
1 parent a842c39 commit cc1155c

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

lib/getProductData.js

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,17 @@
1010
* @property {string} condition
1111
* @property {boolean} condition
1212
* @property {Number} price
13+
* @property {Number} trend
1314
*/
1415

16+
var runRegex = require('./runRegex');
17+
1518
// regex to get the text on the showMsgBox function
1619
var MSG_BOX_PATTERN = /showMsgBox\('(.+)'/;
1720

1821
// the price cell contains the number followed by a space and the euro symbol
1922
var PRICE_PATTERN = /(.*)\s/;
2023

21-
/**
22-
* Match the provided text and regular expression, which must contain one capturing parenthesis
23-
*
24-
* @param {RegExp} regex
25-
* @param {string} text
26-
* @returns {string|void} The captured text
27-
*/
28-
function runRegex(regex, text) {
29-
var result = regex.exec(text);
30-
31-
if (result === null) {
32-
console.error('No result matching regex', regex, 'against the text', text);
33-
34-
return phantom.exit();
35-
}
36-
37-
return result[1];
38-
}
39-
4024
/**
4125
* Get the data of the product on the provided row
4226
*

lib/runRegex.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* global phantom */
2+
3+
/**
4+
* Match the provided text and regular expression, which must contain one capturing parenthesis
5+
*
6+
* @param {RegExp} regex
7+
* @param {string} text
8+
* @returns {string|void} The captured text
9+
*/
10+
function runRegex(regex, text) {
11+
var result = regex.exec(text);
12+
13+
if (result === null) {
14+
console.error('No result matching regex', regex, 'against the text', text);
15+
16+
return phantom.exit();
17+
}
18+
19+
return result[1];
20+
}
21+
22+
module.exports = runRegex;

0 commit comments

Comments
 (0)