diff --git a/plugins/dates/src/api/dates.js b/plugins/dates/src/api/dates.js index 0615b7884..8e0b98f62 100644 --- a/plugins/dates/src/api/dates.js +++ b/plugins/dates/src/api/dates.js @@ -40,7 +40,9 @@ const api = function (View) { let json = m.toView().json(opts)[0] || {} if (opts && opts.dates !== false) { let parsed = parseDates(m, this.opts) - json.dates = toJSON(parsed[0]) + if (parsed.length > 0) { + json.dates = toJSON(parsed[0]) + } } return json }, []) diff --git a/plugins/dates/src/api/toJSON.js b/plugins/dates/src/api/toJSON.js index 40d7c428c..3a6d2e67f 100644 --- a/plugins/dates/src/api/toJSON.js +++ b/plugins/dates/src/api/toJSON.js @@ -6,14 +6,6 @@ const getDuration = function (range) { return diff } -// const getRange = function (diff) { -// if (diff.years) { -// return 'decade' -// } -// // console.log(diff) -// return null -// } - const toJSON = function (range) { if (!range.start) { return { diff --git a/scratch.js b/scratch.js index e70e603eb..2b2035fa1 100644 --- a/scratch.js +++ b/scratch.js @@ -4,10 +4,14 @@ import plg from './plugins/dates/src/plugin.js' nlp.plugin(plg) // nlp.verbose('tagger') +const text = `May 2015, 61138`; -const doc = nlp('one match match after') +const processed = nlp(text); +const dateTimes = processed.dates().json(); // Error + +// const doc = nlp('one match match after') // doc.match('one .* after').debug() // works -doc.match('[one match+ after]', 0).debug() //bad +// doc.match('[one match+ after]', 0).debug() //bad // -bury // -ford