tickbin-parser
Advanced tools
Comparing version 0.2.4 to 0.2.5
@@ -8,5 +8,2 @@ 'use strict'; | ||
exports.default = function (str, timezoneOffset) { | ||
var parserWithDurationRefiner = new _chronoNode2.default.Chrono(); | ||
parserWithDurationRefiner.refiners.push(_durationRefiner2.default); | ||
var patternHour = /(\d*\.{0,1}\d+)\s*(hours|hour|hrs|hr|h)\b/i; | ||
@@ -31,4 +28,11 @@ var patternMin = /(\d*\.{0,1}\d+)\s*(minutes|minute|mins|min|m)\b/i; | ||
var parsedDate = parserWithDurationRefiner.parse(str)[0]; | ||
// Strip out time string from message | ||
var message = str.replace(patternChrono, '').replace(patternHour, '').replace(patternMin, ''); | ||
var parsedDate = _chronoNode2.default.parse(message)[0]; | ||
// Strip out date string from message | ||
var dateStr = parsedDate ? parsedDate.text : ''; | ||
message = message.replace(dateStr, '').trim(); | ||
if (parsedDate) { | ||
@@ -43,5 +47,2 @@ parsedDate.start.assign('timezoneOffset', timezoneOffset); | ||
var text = parsedDate ? parsedDate.text : ''; | ||
var message = str.replace(patternChrono, '').replace(patternHour, '').replace(patternMin, '').replace(text, '').trim(); | ||
return { date: date, duration: duration.asSeconds(), message: message }; | ||
@@ -58,6 +59,2 @@ }; | ||
var _durationRefiner = require('./refiners/durationRefiner'); | ||
var _durationRefiner2 = _interopRequireDefault(_durationRefiner); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
@@ -11,5 +11,5 @@ 'use strict'; | ||
var _durationParser35 = require('../durationParser'); | ||
var _durationParser39 = require('../durationParser'); | ||
var _durationParser36 = _interopRequireDefault(_durationParser35); | ||
var _durationParser40 = _interopRequireDefault(_durationParser39); | ||
@@ -19,3 +19,3 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
(0, _tape2.default)('simple hour duration: 5 hours', function (t) { | ||
var _durationParser = (0, _durationParser36.default)('5 hours'), | ||
var _durationParser = (0, _durationParser40.default)('5 hours'), | ||
date = _durationParser.date, | ||
@@ -31,3 +31,3 @@ duration = _durationParser.duration; | ||
(0, _tape2.default)('simple minute duration: 30 minutes', function (t) { | ||
var _durationParser2 = (0, _durationParser36.default)('30 minutes'), | ||
var _durationParser2 = (0, _durationParser40.default)('30 minutes'), | ||
date = _durationParser2.date, | ||
@@ -43,3 +43,3 @@ duration = _durationParser2.duration; | ||
(0, _tape2.default)('hour and minute duration: 5 hours 30 minutes', function (t) { | ||
var _durationParser3 = (0, _durationParser36.default)('5 hours 30 minutes'), | ||
var _durationParser3 = (0, _durationParser40.default)('5 hours 30 minutes'), | ||
date = _durationParser3.date, | ||
@@ -55,3 +55,3 @@ duration = _durationParser3.duration; | ||
(0, _tape2.default)('chrono input: 5:30 hours', function (t) { | ||
var _durationParser4 = (0, _durationParser36.default)('5:30 hours'), | ||
var _durationParser4 = (0, _durationParser40.default)('5:30 hours'), | ||
date = _durationParser4.date, | ||
@@ -67,3 +67,3 @@ duration = _durationParser4.duration; | ||
(0, _tape2.default)('implied date: yesterday 5 hours', function (t) { | ||
var _durationParser5 = (0, _durationParser36.default)('yesterday 5 hours'), | ||
var _durationParser5 = (0, _durationParser40.default)('yesterday 5 hours'), | ||
date = _durationParser5.date, | ||
@@ -79,3 +79,3 @@ duration = _durationParser5.duration; | ||
(0, _tape2.default)('implied date: Yesterday 7.5 hours', function (t) { | ||
var _durationParser6 = (0, _durationParser36.default)('Yesterday 7.5 hours #stat #robot PR 35'), | ||
var _durationParser6 = (0, _durationParser40.default)('Yesterday 7.5 hours #stat #robot PR 35'), | ||
date = _durationParser6.date, | ||
@@ -93,3 +93,3 @@ duration = _durationParser6.duration, | ||
(0, _tape2.default)('implied date: 7.5 hours Yesterday', function (t) { | ||
var _durationParser7 = (0, _durationParser36.default)('7.5 hours Yesterday #stat #robot PR 35'), | ||
var _durationParser7 = (0, _durationParser40.default)('7.5 hours Yesterday #stat #robot PR 35'), | ||
date = _durationParser7.date, | ||
@@ -107,3 +107,3 @@ duration = _durationParser7.duration, | ||
(0, _tape2.default)('implied date: Yesterday 7 hours', function (t) { | ||
var _durationParser8 = (0, _durationParser36.default)('Yesterday 7 hours #stat #robot PR 35'), | ||
var _durationParser8 = (0, _durationParser40.default)('Yesterday 7 hours #stat #robot PR 35'), | ||
date = _durationParser8.date, | ||
@@ -120,7 +120,67 @@ duration = _durationParser8.duration, | ||
(0, _tape2.default)('specified date: Aug 15 5 hours', function (t) { | ||
var _durationParser9 = (0, _durationParser36.default)('Aug 15 5 hours'), | ||
// Please see this issue: https://github.com/tickbin/parser/issues/45 | ||
(0, _tape2.default)('parse out date: March 25 7h did some #stuff', function (t) { | ||
var _durationParser9 = (0, _durationParser40.default)('March 25 7h did some #stuff'), | ||
date = _durationParser9.date, | ||
duration = _durationParser9.duration; | ||
duration = _durationParser9.duration, | ||
message = _durationParser9.message; | ||
t.equal((0, _moment2.default)(date).date(), 25, 'date is the 25th'); | ||
t.equal((0, _moment2.default)(date).month(), 2, 'date is March'); | ||
t.equal(duration, 25200, 'parsed duration'); // 7 hours in seconds | ||
t.equal(message, 'did some #stuff', 'parsed message'); | ||
t.end(); | ||
}); | ||
// Please see this issue: https://github.com/tickbin/parser/issues/45 | ||
(0, _tape2.default)('parse out date: 7h did some #stuff March 25', function (t) { | ||
var _durationParser10 = (0, _durationParser40.default)('7h did some #stuff March 25'), | ||
date = _durationParser10.date, | ||
duration = _durationParser10.duration, | ||
message = _durationParser10.message; | ||
t.equal((0, _moment2.default)(date).date(), 25, 'date is the 25th'); | ||
t.equal((0, _moment2.default)(date).month(), 2, 'date is March'); | ||
t.equal(duration, 25200, 'parsed duration'); // 7 hours in seconds | ||
t.equal(message, 'did some #stuff', 'parsed message'); | ||
t.end(); | ||
}); | ||
// Please see this issue: https://github.com/tickbin/parser/issues/46 | ||
(0, _tape2.default)('parse out date: March 25 6.5h #stat', function (t) { | ||
var _durationParser11 = (0, _durationParser40.default)('March 25 6.5h #stat'), | ||
date = _durationParser11.date, | ||
duration = _durationParser11.duration, | ||
message = _durationParser11.message; | ||
t.equal((0, _moment2.default)(date).date(), 25, 'date is the 25th'); | ||
t.equal((0, _moment2.default)(date).month(), 2, 'date is March'); | ||
t.equal(duration, 23400, 'parsed duration'); // 6.5 hours in seconds | ||
t.equal(message, '#stat', 'parsed message'); | ||
t.end(); | ||
}); | ||
// Please see this issue: https://github.com/tickbin/parser/issues/46 | ||
(0, _tape2.default)('parse out date: March 25th 6h #stat', function (t) { | ||
var _durationParser12 = (0, _durationParser40.default)('March 25th 6h #stat'), | ||
date = _durationParser12.date, | ||
duration = _durationParser12.duration, | ||
message = _durationParser12.message; | ||
t.equal((0, _moment2.default)(date).date(), 25, 'date is the 25th'); | ||
t.equal((0, _moment2.default)(date).month(), 2, 'date is March'); | ||
t.equal(duration, 21600, 'parsed duration'); // 6 hours in seconds | ||
t.equal(message, '#stat', 'parsed message'); | ||
t.end(); | ||
}); | ||
(0, _tape2.default)('specified date: Aug 15 5 hours', function (t) { | ||
var _durationParser13 = (0, _durationParser40.default)('Aug 15 5 hours'), | ||
date = _durationParser13.date, | ||
duration = _durationParser13.duration; | ||
t.equal((0, _moment2.default)(date).date(), 15, 'date is the 15th day'); | ||
@@ -134,5 +194,5 @@ t.equal((0, _moment2.default)(date).month(), 7, 'date is Aug'); | ||
(0, _tape2.default)('units in decimal: 1.5 hours 1.5 minutes', function (t) { | ||
var _durationParser10 = (0, _durationParser36.default)('1.5 hours 1.5 minutes'), | ||
date = _durationParser10.date, | ||
duration = _durationParser10.duration; | ||
var _durationParser14 = (0, _durationParser40.default)('1.5 hours 1.5 minutes'), | ||
date = _durationParser14.date, | ||
duration = _durationParser14.duration; | ||
@@ -146,4 +206,4 @@ t.ok((0, _moment2.default)().isSame(date, 'day'), 'parsed as current date'); | ||
(0, _tape2.default)('returns original message without date or duration', function (t) { | ||
var _durationParser11 = (0, _durationParser36.default)('yesterday 5 hours all the #things'), | ||
message = _durationParser11.message; | ||
var _durationParser15 = (0, _durationParser40.default)('yesterday 5 hours all the #things'), | ||
message = _durationParser15.message; | ||
@@ -156,14 +216,14 @@ t.equal(message, 'all the #things', 'stripped date and time from message'); | ||
(0, _tape2.default)('does not take the first letter from other words', function (t) { | ||
var _durationParser12 = (0, _durationParser36.default)('2 houses'), | ||
dh = _durationParser12.duration; | ||
var _durationParser16 = (0, _durationParser40.default)('2 houses'), | ||
dh = _durationParser16.duration; | ||
t.equal(dh, 0, 'does not take h from \'houses\''); | ||
var _durationParser13 = (0, _durationParser36.default)('2.5 mouses'), | ||
dm = _durationParser13.duration; | ||
var _durationParser17 = (0, _durationParser40.default)('2.5 mouses'), | ||
dm = _durationParser17.duration; | ||
t.equal(dm, 0, 'does not take m from \'mouses\''); | ||
var _durationParser14 = (0, _durationParser36.default)('2:30 houses'), | ||
dc = _durationParser14.duration; | ||
var _durationParser18 = (0, _durationParser40.default)('2:30 houses'), | ||
dc = _durationParser18.duration; | ||
@@ -176,9 +236,9 @@ t.equal(dc, 0, 'does not take h from \'houses\''); | ||
t.test('parses minutes', function (t) { | ||
var _durationParser15 = (0, _durationParser36.default)('30 minutes'), | ||
duration = _durationParser15.duration; | ||
var _durationParser19 = (0, _durationParser40.default)('30 minutes'), | ||
duration = _durationParser19.duration; | ||
t.equal(duration, 1800, 'parsed duration'); | ||
var _durationParser16 = (0, _durationParser36.default)('30minutes'), | ||
duration2 = _durationParser16.duration; | ||
var _durationParser20 = (0, _durationParser40.default)('30minutes'), | ||
duration2 = _durationParser20.duration; | ||
@@ -190,9 +250,9 @@ t.equal(duration2, 1800, 'parsed duration'); | ||
t.test('parses minute', function (t) { | ||
var _durationParser17 = (0, _durationParser36.default)('30 minute'), | ||
duration = _durationParser17.duration; | ||
var _durationParser21 = (0, _durationParser40.default)('30 minute'), | ||
duration = _durationParser21.duration; | ||
t.equal(duration, 1800, 'parsed duration'); | ||
var _durationParser18 = (0, _durationParser36.default)('30minute'), | ||
duration2 = _durationParser18.duration; | ||
var _durationParser22 = (0, _durationParser40.default)('30minute'), | ||
duration2 = _durationParser22.duration; | ||
@@ -204,9 +264,9 @@ t.equal(duration2, 1800, 'parsed duration'); | ||
t.test('parses mins', function (t) { | ||
var _durationParser19 = (0, _durationParser36.default)('30 mins'), | ||
duration = _durationParser19.duration; | ||
var _durationParser23 = (0, _durationParser40.default)('30 mins'), | ||
duration = _durationParser23.duration; | ||
t.equal(duration, 1800, 'parsed duration'); | ||
var _durationParser20 = (0, _durationParser36.default)('30mins'), | ||
duration2 = _durationParser20.duration; | ||
var _durationParser24 = (0, _durationParser40.default)('30mins'), | ||
duration2 = _durationParser24.duration; | ||
@@ -218,9 +278,9 @@ t.equal(duration2, 1800, 'parsed duration'); | ||
t.test('parses min', function (t) { | ||
var _durationParser21 = (0, _durationParser36.default)('30 min'), | ||
duration = _durationParser21.duration; | ||
var _durationParser25 = (0, _durationParser40.default)('30 min'), | ||
duration = _durationParser25.duration; | ||
t.equal(duration, 1800, 'parsed duration'); | ||
var _durationParser22 = (0, _durationParser36.default)('30min'), | ||
duration2 = _durationParser22.duration; | ||
var _durationParser26 = (0, _durationParser40.default)('30min'), | ||
duration2 = _durationParser26.duration; | ||
@@ -232,9 +292,9 @@ t.equal(duration2, 1800, 'parsed duration'); | ||
t.test('parses m', function (t) { | ||
var _durationParser23 = (0, _durationParser36.default)('30 m'), | ||
duration = _durationParser23.duration; | ||
var _durationParser27 = (0, _durationParser40.default)('30 m'), | ||
duration = _durationParser27.duration; | ||
t.equal(duration, 1800, 'parsed duration'); | ||
var _durationParser24 = (0, _durationParser36.default)('30m'), | ||
duration2 = _durationParser24.duration; | ||
var _durationParser28 = (0, _durationParser40.default)('30m'), | ||
duration2 = _durationParser28.duration; | ||
@@ -246,9 +306,9 @@ t.equal(duration2, 1800, 'parsed duration'); | ||
t.test('parses hours', function (t) { | ||
var _durationParser25 = (0, _durationParser36.default)('1 hours'), | ||
duration = _durationParser25.duration; | ||
var _durationParser29 = (0, _durationParser40.default)('1 hours'), | ||
duration = _durationParser29.duration; | ||
t.equal(duration, 3600, 'parsed duration'); | ||
var _durationParser26 = (0, _durationParser36.default)('1hours'), | ||
duration2 = _durationParser26.duration; | ||
var _durationParser30 = (0, _durationParser40.default)('1hours'), | ||
duration2 = _durationParser30.duration; | ||
@@ -260,9 +320,9 @@ t.equal(duration2, 3600, 'parsed duration'); | ||
t.test('parses hour', function (t) { | ||
var _durationParser27 = (0, _durationParser36.default)('1 hour'), | ||
duration = _durationParser27.duration; | ||
var _durationParser31 = (0, _durationParser40.default)('1 hour'), | ||
duration = _durationParser31.duration; | ||
t.equal(duration, 3600, 'parsed duration'); | ||
var _durationParser28 = (0, _durationParser36.default)('1hour'), | ||
duration2 = _durationParser28.duration; | ||
var _durationParser32 = (0, _durationParser40.default)('1hour'), | ||
duration2 = _durationParser32.duration; | ||
@@ -274,9 +334,9 @@ t.equal(duration2, 3600, 'parsed duration'); | ||
t.test('parses hrs', function (t) { | ||
var _durationParser29 = (0, _durationParser36.default)('1 hrs'), | ||
duration = _durationParser29.duration; | ||
var _durationParser33 = (0, _durationParser40.default)('1 hrs'), | ||
duration = _durationParser33.duration; | ||
t.equal(duration, 3600, 'parsed duration'); | ||
var _durationParser30 = (0, _durationParser36.default)('1hrs'), | ||
duration2 = _durationParser30.duration; | ||
var _durationParser34 = (0, _durationParser40.default)('1hrs'), | ||
duration2 = _durationParser34.duration; | ||
@@ -288,9 +348,9 @@ t.equal(duration2, 3600, 'parsed duration'); | ||
t.test('parses hr', function (t) { | ||
var _durationParser31 = (0, _durationParser36.default)('1 hr'), | ||
duration = _durationParser31.duration; | ||
var _durationParser35 = (0, _durationParser40.default)('1 hr'), | ||
duration = _durationParser35.duration; | ||
t.equal(duration, 3600, 'parsed duration'); | ||
var _durationParser32 = (0, _durationParser36.default)('1hr'), | ||
duration2 = _durationParser32.duration; | ||
var _durationParser36 = (0, _durationParser40.default)('1hr'), | ||
duration2 = _durationParser36.duration; | ||
@@ -302,9 +362,9 @@ t.equal(duration2, 3600, 'parsed duration'); | ||
t.test('parses h', function (t) { | ||
var _durationParser33 = (0, _durationParser36.default)('1 h'), | ||
duration = _durationParser33.duration; | ||
var _durationParser37 = (0, _durationParser40.default)('1 h'), | ||
duration = _durationParser37.duration; | ||
t.equal(duration, 3600, 'parsed duration'); | ||
var _durationParser34 = (0, _durationParser36.default)('1h'), | ||
duration2 = _durationParser34.duration; | ||
var _durationParser38 = (0, _durationParser40.default)('1h'), | ||
duration2 = _durationParser38.duration; | ||
@@ -311,0 +371,0 @@ t.equal(duration2, 3600, 'parsed duration'); |
{ | ||
"name": "tickbin-parser", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "parse strings into entries", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
109491
1524
25