Compare View
Commits (2)
Changes
Showing 4 changed files Side-by-side Diff
lib/st24.js
... | ... | @@ -38,16 +38,16 @@ function extractSnFromMessage(msg, custom_rule) { |
38 | 38 | } |
39 | 39 | |
40 | 40 | function extractPriceFromMsg(msg, custom_rule) { |
41 | - const default_pattern = "\\d,HRG=(.*?),ID="; | |
41 | + const default_pattern = "\\d,HRG= *(?:RP)*\\.* *(.*?),ID="; | |
42 | 42 | const default_match_idx = 1; |
43 | 43 | |
44 | 44 | let price = extractFromMessage(msg, default_pattern, default_match_idx, custom_rule); |
45 | - price = (typeof price === 'string') ? Number(price.replace(/\./g, '')) : null; | |
45 | + price = (typeof price === 'string') ? Number(price.replace(/[^\d]/g, '')) : null; | |
46 | 46 | return price; |
47 | 47 | } |
48 | 48 | |
49 | 49 | function extractBalanceFromMsg(msg, custom_rule) { |
50 | - const default_pattern = "SAL=([\\d\\.]+)"; | |
50 | + const default_pattern = 'SAL= *(?:RP)*\\.* *([\\d\\.,]+)'; | |
51 | 51 | const default_match_idx = 1; |
52 | 52 | |
53 | 53 | let balance = extractFromMessage(msg, default_pattern, default_match_idx, custom_rule); |
package-lock.json
package.json
test.js
... | ... | @@ -46,6 +46,7 @@ describe('#st24', function() { |
46 | 46 | it('should return correct balance', function() { |
47 | 47 | st24.extractBalanceFromMsg('SN=0516150344145563101; 16/05/18 15:03 ISI TR5 KE 0895350249796, SUKSES.SAL=426.078,HRG=5.250,ID=47285513,SN=0516150344145563101; ..trx lancar').should.equal(426078); |
48 | 48 | st24.extractBalanceFromMsg('15/05/18 17:19 ISI SAN10 KE 08535686667, NOMOR YANG ANDA MASUKKAN SALAH, MOHON TELITI KEMBALI..SAL=1.144.578,ID=47250459, ..trx lancar').should.equal(1144578) |
49 | + st24.extractBalanceFromMsg('SN=3527-7416-4999-5485-7433/SARJUNI/R1/1300/31;11/05/20 17:24 TRANSAKSI PLNB50 KE 45019534903, (ISO00) BERHASIL. SAL=RP 4,729,975,HRG=RP 50,005,ID=62102710,SN=3527-7416-4999-5485-7433/SARJUNI/R1/1300/31@ *[Gaspolll_TanpaBatas] CS: @CSMETROH2H | 62 85810555505 . Channel : https://t.me/metroreloadinfoh2h').should.equal(4729975, 'metro'); | |
49 | 50 | }) |
50 | 51 | |
51 | 52 | it('should return null if there is no balance info', function() { |
... | ... | @@ -74,6 +75,7 @@ describe('#st24', function() { |
74 | 75 | it('should return correct price', function() { |
75 | 76 | st24.extractPriceFromMsg('SN=0041002635395450;;19/07/18 21:01 ISI SPT20 KE 08125100091, SUKSES. SAL=798.500,HRG=19.700,ID=48761075,SN=0041002635395450;; ..trx lancar').should.equal(19700); |
76 | 77 | st24.extractPriceFromMsg('SN=0516150344145563101; 16/05/18 15:03 ISI TR5 KE 0895350249796, SUKSES.SAL=426.078,HRG=5.250,ID=47285513,SN=0516150344145563101; ..trx lancar').should.equal(5250); |
78 | + st24.extractPriceFromMsg('SN=3527-7416-4999-5485-7433/SARJUNI/R1/1300/31;11/05/20 17:24 TRANSAKSI PLNB50 KE 45019534903, (ISO00) BERHASIL. SAL=RP 4,729,975,HRG=RP 50,005,ID=62102710,SN=3527-7416-4999-5485-7433/SARJUNI/R1/1300/31@ *[Gaspolll_TanpaBatas] CS: @CSMETROH2H | 62 85810555505 . Channel : https://t.me/metroreloadinfoh2h').should.equal(50005, 'metro'); | |
77 | 79 | }); |
78 | 80 | }) |
79 | 81 |