imdone-core 1.43.7 → 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 +24 -10
  2. package/lib/task.js +3 -3
  3. package/package.json +1 -1
package/lib/file.js CHANGED
@@ -160,18 +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
163
+ return File.parseDate(config, text, 'due')
164
+ }
165
+
166
+ File.parseRemindDate = function (config, text) {
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
167
179
  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}`
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}`
172
184
  } catch (e) {
173
- console.log(`Unable to parse due date for ${text}`)
174
- return dueMatch
185
+ console.log(`Unable to parse ${dateType} date for ${text}`)
186
+ return match
175
187
  }
176
188
  })
177
189
  }
@@ -263,6 +275,8 @@ File.prototype.transformTask = function ({config, modify, task}) {
263
275
  })
264
276
  content = trackListChanges.content
265
277
  content = File.parseDueDate(config, content)
278
+ content = File.parseRemindDate(config, content)
279
+ content = File.parseDeferDate(config, content)
266
280
  content = File.addCompleted({ task, content, config })
267
281
  if (
268
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')
@@ -291,7 +291,7 @@ Task.MetaRegExp = new RegExp(
291
291
  )
292
292
  Task.getMetaRegExp = function (config) {
293
293
  return new RegExp(
294
- `(^|\\s)([a-zA-Z-_]+?)${config.getMetaSep()}(?!\\*+)(?!\\/\\/)([${
294
+ `(^|\\s)([a-zA-Z-_]+?)${config.getMetaSep()}(?![*_]+)(?!\\/\\/)([${
295
295
  Task.AnyLanguageGroup
296
296
  }${Task.EmojiGroup}]+)`,
297
297
  'gu'
@@ -299,7 +299,7 @@ Task.getMetaRegExp = function (config) {
299
299
  }
300
300
  Task.getMetaRegExpQuotes = function (config) {
301
301
  return new RegExp(
302
- `(^|\\s)([a-zA-Z-_]+?)${config.getMetaSep()}(?!\\*+)"((?${config.getMetaSep()}""|[^"]|[${
302
+ `(^|\\s)([a-zA-Z-_]+?)${config.getMetaSep()}(?![*_]+)"((?${config.getMetaSep()}""|[^"]|[${
303
303
  Task.AnyLanguageGroup
304
304
  }${Task.EmojiGroup}])*)"`,
305
305
  'gu'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imdone-core",
3
- "version": "1.43.7",
3
+ "version": "1.44.1",
4
4
  "description": "imdone-core",
5
5
  "main": "index.js",
6
6
  "scripts": {