tickbin-parser
Advanced tools
Comparing version 0.0.2 to 0.1.0
@@ -38,3 +38,3 @@ 'use strict'; | ||
var Entry = function () { | ||
function Entry(user, message) { | ||
function Entry(user, originalMessage) { | ||
var opts = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
@@ -54,3 +54,3 @@ var timezoneOffset = arguments[3]; | ||
if ((typeof message === 'undefined' ? 'undefined' : _typeof(message)) === 'object') return this._fromObject(message); | ||
if ((typeof originalMessage === 'undefined' ? 'undefined' : _typeof(originalMessage)) === 'object') return this._fromObject(originalMessage); | ||
@@ -60,7 +60,7 @@ this.version = version; | ||
this._id = _shortid2.default.generate(); | ||
this.message = message; | ||
this.original = originalMessage; | ||
// ensure ref is a date and not a moment | ||
this.ref = new Date(date); | ||
this.parse(message, date, timezoneOffset); | ||
this.parseTags(message); | ||
this.parse(originalMessage, date, timezoneOffset); | ||
this.parseTags(originalMessage); | ||
} | ||
@@ -75,3 +75,4 @@ | ||
var text = this.time; | ||
this.setDates({ start: start, end: end, text: text }); | ||
var message = this.message; | ||
this.setParsedFields({ start: start, end: end, text: text, message: message }); | ||
this.tags = new Set(doc.tags); | ||
@@ -84,3 +85,3 @@ return this; | ||
var d = (0, _parser2.default)(msg, date, timezoneOffset); | ||
if (d.isRange) this.setDates(d); | ||
if (d.isRange) this.setParsedFields(d); | ||
} | ||
@@ -94,4 +95,4 @@ }, { | ||
}, { | ||
key: 'setDates', | ||
value: function setDates(opts) { | ||
key: 'setParsedFields', | ||
value: function setParsedFields(opts) { | ||
this.hasDates = true; | ||
@@ -103,2 +104,3 @@ this.start = opts.start; | ||
this.time = opts.text; | ||
this.message = opts.message; | ||
this.duration = new _duration2.default(this.start, this.end); | ||
@@ -121,2 +123,3 @@ } | ||
user: this.user, | ||
original: this.original, | ||
message: this.message, | ||
@@ -123,0 +126,0 @@ hasDates: this.hasDates, |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.parser = exports.Entry = undefined; | ||
exports.parser = exports.version = exports.hashPattern = exports.Entry = undefined; | ||
@@ -20,2 +20,4 @@ var _entry = require('./entry'); | ||
exports.Entry = _entry2.default; | ||
exports.hashPattern = _entry.hashPattern; | ||
exports.version = _entry.version; | ||
exports.parser = _parser2.default; |
@@ -9,3 +9,4 @@ 'use strict'; | ||
var rslt = parser.parse(str, ref)[0]; | ||
var isRange = rslt && rslt.start && rslt.end; | ||
// ... && true || false makes sure isRange is a boolean | ||
var isRange = rslt && rslt.start && rslt.end && true || false; | ||
@@ -12,0 +13,0 @@ // sets timezone to where user is located |
@@ -38,3 +38,3 @@ 'use strict'; | ||
t.ok(e.hasDates, 'entry has dates'); | ||
t.equals(e.message, '8am-10am worked on things'); | ||
t.equals(e.original, '8am-10am worked on things'); | ||
t.equals(start.getHours(), 8, 'start is 8am'); | ||
@@ -55,3 +55,3 @@ t.equals(end.getHours(), 10, 'start is 10am'); | ||
t.ok(e.hasDates, 'entry has dates'); | ||
t.equals(e.message, '8am-5pm worked on things'); | ||
t.equals(e.original, '8am-5pm worked on things'); | ||
t.equals(start.getHours(), 8, 'start is 8am'); | ||
@@ -263,3 +263,4 @@ t.equals(end.getHours(), 17, 'end is 5pm'); | ||
var obj = e.toObject(); | ||
t.equals(obj.message, '8am-10am worked on some things #tag1 #tag2', 'message'); | ||
t.equals(obj.original, '8am-10am worked on some things #tag1 #tag2', 'original'); | ||
t.equals(obj.message, 'worked on some things #tag1 #tag2', 'message'); | ||
t.ok(obj.hasDates, 'hasDates'); | ||
@@ -289,2 +290,3 @@ t.equals(e.start, obj.start, 'start'); | ||
t.equals(existing.version, e.version, 'version matches'); | ||
t.equals(existing.original, e.original, 'original matches'); | ||
t.equals(existing.message, e.message, 'message matches'); | ||
@@ -298,2 +300,16 @@ t.equals(e.tags.size, 2, '2 tags'); | ||
t.end(); | ||
}); | ||
(0, _tape2.default)('return message with time stripped out', function (t) { | ||
var e = new _entry2.default(userId, '8-10am worked on some things #tag1 #tag2'); | ||
t.equals(e.message, 'worked on some things #tag1 #tag2'); | ||
t.end(); | ||
}); | ||
(0, _tape2.default)('return message with date stripped out', function (t) { | ||
var e = new _entry2.default(userId, 'Feb 1 8-10am worked on some things #tag1 #tag2'); | ||
t.equals(e.message, 'worked on some things #tag1 #tag2'); | ||
t.end(); | ||
}); |
'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
var _tape = require('tape'); | ||
@@ -11,5 +13,5 @@ | ||
var _parser25 = require('../parser'); | ||
var _parser27 = require('../parser'); | ||
var _parser26 = _interopRequireDefault(_parser25); | ||
var _parser28 = _interopRequireDefault(_parser27); | ||
@@ -19,3 +21,3 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
(0, _tape2.default)('simple am times: 8am-10am', function (t) { | ||
var _parser = (0, _parser26.default)('8am-10am'); | ||
var _parser = (0, _parser28.default)('8am-10am'); | ||
@@ -32,3 +34,3 @@ var start = _parser.start; | ||
(0, _tape2.default)('simple am to pm times: 9am-2pm', function (t) { | ||
var _parser2 = (0, _parser26.default)('9am-2pm'); | ||
var _parser2 = (0, _parser28.default)('9am-2pm'); | ||
@@ -45,3 +47,3 @@ var start = _parser2.start; | ||
(0, _tape2.default)('simple pm times: 1pm-4pm', function (t) { | ||
var _parser3 = (0, _parser26.default)('1pm-4pm'); | ||
var _parser3 = (0, _parser28.default)('1pm-4pm'); | ||
@@ -58,3 +60,3 @@ var start = _parser3.start; | ||
(0, _tape2.default)('infer meridiem: 1-3pm', function (t) { | ||
var _parser4 = (0, _parser26.default)('1-3pm'); | ||
var _parser4 = (0, _parser28.default)('1-3pm'); | ||
@@ -73,3 +75,3 @@ var start = _parser4.start; | ||
var _parser5 = (0, _parser26.default)('1pm-3'); | ||
var _parser5 = (0, _parser28.default)('1pm-3'); | ||
@@ -90,3 +92,3 @@ var start = _parser5.start; | ||
var _parser6 = (0, _parser26.default)('11pm-2'); | ||
var _parser6 = (0, _parser28.default)('11pm-2'); | ||
@@ -106,3 +108,3 @@ var start = _parser6.start; | ||
(0, _tape2.default)('minutes: 9:15am-2:30pm', function (t) { | ||
var _parser7 = (0, _parser26.default)('9:15am-2:30pm'); | ||
var _parser7 = (0, _parser28.default)('9:15am-2:30pm'); | ||
@@ -121,3 +123,3 @@ var start = _parser7.start; | ||
(0, _tape2.default)('colon segmented 24 times: 08:00-13:00', function (t) { | ||
var _parser8 = (0, _parser26.default)('0800-1330'); | ||
var _parser8 = (0, _parser28.default)('0800-1330'); | ||
@@ -135,3 +137,3 @@ var start = _parser8.start; | ||
(0, _tape2.default)('proper 24h times: 0800-1330', function (t) { | ||
var _parser9 = (0, _parser26.default)('0800-1330'); | ||
var _parser9 = (0, _parser28.default)('0800-1330'); | ||
@@ -150,3 +152,3 @@ var start = _parser9.start; | ||
(0, _tape2.default)('no leading zero 24h times: 800-1300', function (t) { | ||
var _parser10 = (0, _parser26.default)('800-1300'); | ||
var _parser10 = (0, _parser28.default)('800-1300'); | ||
@@ -166,3 +168,3 @@ var start = _parser10.start; | ||
(0, _tape2.default)('anchored: dates relative to anchor', function (t) { | ||
var _parser11 = (0, _parser26.default)('8am-1pm', anchor); | ||
var _parser11 = (0, _parser28.default)('8am-1pm', anchor); | ||
@@ -180,3 +182,3 @@ var start = _parser11.start; | ||
(0, _tape2.default)('anchored: dates relative to anchor2', function (t) { | ||
var _parser12 = (0, _parser26.default)('8am-1pm', anchor2); | ||
var _parser12 = (0, _parser28.default)('8am-1pm', anchor2); | ||
@@ -194,3 +196,3 @@ var start = _parser12.start; | ||
(0, _tape2.default)('overlapping times: 11pm-2am', function (t) { | ||
var _parser13 = (0, _parser26.default)('11pm-2am', anchor); | ||
var _parser13 = (0, _parser28.default)('11pm-2am', anchor); | ||
@@ -211,3 +213,3 @@ var start = _parser13.start; | ||
var _parser14 = (0, _parser26.default)('11pm-2am'); | ||
var _parser14 = (0, _parser28.default)('11pm-2am'); | ||
@@ -227,3 +229,3 @@ var start = _parser14.start; | ||
var _parser15 = (0, _parser26.default)('11pm-2am', refDate); | ||
var _parser15 = (0, _parser28.default)('11pm-2am', refDate); | ||
@@ -241,7 +243,7 @@ var start = _parser15.start; | ||
(0, _tape2.default)('matching text is returned', function (t) { | ||
var _parser16 = (0, _parser26.default)('1-3pm'); | ||
var _parser16 = (0, _parser28.default)('1-3pm'); | ||
var text = _parser16.text; | ||
var _parser17 = (0, _parser26.default)('1-3pm did some things'); | ||
var _parser17 = (0, _parser28.default)('1-3pm did some things'); | ||
@@ -261,3 +263,3 @@ var only = _parser17.text; | ||
var _parser18 = (0, _parser26.default)('10-4pm'); | ||
var _parser18 = (0, _parser28.default)('10-4pm'); | ||
@@ -280,3 +282,3 @@ var start = _parser18.start; | ||
var _parser19 = (0, _parser26.default)('9:30-12pm'); | ||
var _parser19 = (0, _parser28.default)('9:30-12pm'); | ||
@@ -299,3 +301,3 @@ var start = _parser19.start; | ||
var _parser20 = (0, _parser26.default)('8-4pm Good Friday #stat', today); | ||
var _parser20 = (0, _parser28.default)('8-4pm Good Friday #stat', today); | ||
@@ -313,3 +315,3 @@ var start = _parser20.start; | ||
(0, _tape2.default)('returns original message without time', function (t) { | ||
var _parser21 = (0, _parser26.default)('1-2pm did some #stuff'); | ||
var _parser21 = (0, _parser28.default)('1-2pm did some #stuff'); | ||
@@ -325,3 +327,3 @@ var message = _parser21.message; | ||
(0, _tape2.default)('no time needed', function (t) { | ||
var _parser22 = (0, _parser26.default)('did some #stuff'); | ||
var _parser22 = (0, _parser28.default)('did some #stuff'); | ||
@@ -341,3 +343,3 @@ var text = _parser22.text; | ||
(0, _tape2.default)('one time unit is set to start', function (t) { | ||
var _parser23 = (0, _parser26.default)('12pm did some #stuff'); | ||
var _parser23 = (0, _parser28.default)('12pm did some #stuff'); | ||
@@ -355,3 +357,3 @@ var start = _parser23.start; | ||
(0, _tape2.default)('use timezone offset', function (t) { | ||
var _parser24 = (0, _parser26.default)('8am-10am', undefined, -480); | ||
var _parser24 = (0, _parser28.default)('8am-10am', undefined, -480); | ||
@@ -366,2 +368,22 @@ var start = _parser24.start; | ||
t.end(); | ||
}); | ||
(0, _tape2.default)('isRange should be a boolean', function (t) { | ||
// Test TRUE | ||
var _parser25 = (0, _parser28.default)('8am-10am'); | ||
var isTrue = _parser25.isRange; | ||
t.equal(typeof isTrue === 'undefined' ? 'undefined' : _typeof(isTrue), 'boolean', 'is a boolean when true'); | ||
// Test FALSE | ||
var _parser26 = (0, _parser28.default)('8am'); | ||
var isFalse = _parser26.isRange; | ||
t.equal(typeof isFalse === 'undefined' ? 'undefined' : _typeof(isFalse), 'boolean', 'is a boolean when false'); | ||
t.end(); | ||
}); |
{ | ||
"name": "tickbin-parser", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "parse strings into entries", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -8,3 +8,3 @@ [![Build Status](https://semaphoreci.com/api/v1/jonotron/entry-parser/branches/master/shields_badge.svg)](https://semaphoreci.com/jonotron/entry-parser) | ||
``` | ||
npm install tickbin-entry-parser | ||
npm install tickbin-parser | ||
``` | ||
@@ -15,11 +15,12 @@ | ||
```javascript | ||
import Parser from 'tickbin-entry-parser' | ||
import { Entry, parser } from 'tickbin-parser' | ||
// userId may be undefined if you don't wish to associate entry with user | ||
const entry = new Parser(userId, 'May 4 2-4pm I did some #stuff') | ||
const entry = new Entry(userId, 'May 4 2-4pm I did some #stuff') | ||
// entry = { | ||
// version: 4, | ||
// version: 5, | ||
// user: undefined, | ||
// _id: 'H1yifd_4', | ||
// message: 'May 4 2-4pm I did some #stuff', | ||
// original: 'May 4 2-4pm I did some #stuff', | ||
// message: 'I did some #stuff', | ||
// ref: Fri Jun 10 2016 10:02:14 GMT-0700 (PDT), | ||
@@ -39,2 +40,11 @@ // hasDates: true, | ||
// } | ||
const parse = parser('8am-10am test message') | ||
// parse = { | ||
// start: Thu Jul 21 2016 08:00:00 GMT-0700 (PDT), | ||
// end: Thu Jul 21 2016 10:00:00 GMT-0700 (PDT), | ||
// text: '8am-10am', | ||
// message: 'test message', | ||
// isRange: true | ||
// } | ||
``` | ||
@@ -41,0 +51,0 @@ |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
84263
1005
58
0