imdone-core 1.44.0 → 1.44.1

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.
Files changed (3) hide show
  1. package/lib/file.js +20 -24
  2. package/lib/task.js +1 -1
  3. package/package.json +1 -1
package/lib/file.js CHANGED
@@ -160,35 +160,30 @@ File.addCompleted = function ({ task, content, config }) {
160
160
  }
161
161
 
162
162
  File.parseDueDate = function (config, text) {
163
- if (text.includes(`due${config.getMetaSep()}`)) return text
164
- let dueString
165
- return text.replace(/(\sdue)\s.*?\./gi, (dueMatch, p1) => {
166
- if (dueString) return dueMatch
167
- try {
168
- const due = chrono.parseDate(dueMatch, new Date(), {forwardDate: true})
169
- if (!due) return dueMatch
170
- dueString = getIsoDateWithOffset(due)
171
- return `${p1.toLowerCase()}${config.getMetaSep()}${dueString}`
172
- } catch (e) {
173
- console.log(`Unable to parse due date for ${text}`)
174
- return dueMatch
175
- }
176
- })
163
+ return File.parseDate(config, text, 'due')
177
164
  }
178
165
 
179
166
  File.parseRemindDate = function (config, text) {
180
- if (text.includes(`remind${config.getMetaSep()}`)) return text
181
- let remindString
182
- return text.replace(/(\sremind)\s.*?\./gi, (remindMatch, p1) => {
183
- if (remindString) return remindMatch
167
+ return File.parseDate(config, text, 'remind')
168
+ }
169
+
170
+ File.parseDeferDate = function (config, text) {
171
+ return File.parseDate(config, text, 'defer')
172
+ }
173
+
174
+ File.parseDate = function (config, text, dateType) {
175
+ if (text.includes(`${dateType}${config.getMetaSep()}`)) return text
176
+ let dateString
177
+ return text.replace(new RegExp(`(\\s${dateType})\\s.*?\\.`,'gi'), (match, p1) => {
178
+ if (dateString) return match
184
179
  try {
185
- const remind = chrono.parseDate(remindMatch, new Date(), {forwardDate: true})
186
- if (!remind) return remindMatch
187
- remindString = getIsoDateWithOffset(remind)
188
- return `${p1.toLowerCase()}${config.getMetaSep()}${remindString}`
180
+ const date = chrono.parseDate(match, new Date(), {forwardDate: true})
181
+ if (!date) return match
182
+ dateString = getIsoDateWithOffset(date)
183
+ return `${p1.toLowerCase()}${config.getMetaSep()}${dateString}`
189
184
  } catch (e) {
190
- console.log(`Unable to parse remind date for ${text}`)
191
- return remindMatch
185
+ console.log(`Unable to parse ${dateType} date for ${text}`)
186
+ return match
192
187
  }
193
188
  })
194
189
  }
@@ -281,6 +276,7 @@ File.prototype.transformTask = function ({config, modify, task}) {
281
276
  content = trackListChanges.content
282
277
  content = File.parseDueDate(config, content)
283
278
  content = File.parseRemindDate(config, content)
279
+ content = File.parseDeferDate(config, content)
284
280
  content = File.addCompleted({ task, content, config })
285
281
  if (
286
282
  content.trim() !== task.content.trim()
package/lib/task.js CHANGED
@@ -26,7 +26,7 @@ const {
26
26
  * @param {} obj
27
27
  * @return
28
28
  */
29
- const DATE_META_KEYS = ['due', 'created', 'remind', 'completed']
29
+ const DATE_META_KEYS = ['due', 'defer', 'created', 'remind', 'completed']
30
30
  class Task {
31
31
  constructor(config, obj, dontParse) {
32
32
  if (!_isObject(obj)) throw new Error('obj must be an Object')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imdone-core",
3
- "version": "1.44.0",
3
+ "version": "1.44.1",
4
4
  "description": "imdone-core",
5
5
  "main": "index.js",
6
6
  "scripts": {