Skip to content

Commit

Permalink
fix for #1145
Browse files Browse the repository at this point in the history
  • Loading branch information
spencermountain committed Sep 23, 2024
1 parent 0a0dfcb commit dbb4e99
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
4 changes: 3 additions & 1 deletion plugins/dates/src/api/dates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}, [])
Expand Down
8 changes: 0 additions & 8 deletions plugins/dates/src/api/toJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions scratch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dbb4e99

Please sign in to comment.