You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using the compromise-dates plugin, any call to the .dates()functions (.json(), .get(), .format() etc.) mutates the today value in the context param obj to a SpaceTime object, which is an unexpected side-effect:
'use strict'/** @type {import('compromise').default} */constnlp=require('compromise')constnlpDates=require('compromise-dates')nlp.plugin(nlpDates)constdoc=nlp("I'll deal with that bug tomorrow")constcontext={timezone: 'Canada/Eastern',today: '2020-02-20',punt: {weeks: 2},dayStart: '8:00am',dayEnd: '5:30pm',}constdatesViews=doc.dates(context)// context obj is still the same at this pointconsole.log(context)constdateList=datesViews.json()console.log(context)/* context obj is now:{ timezone: 'Canada/Eastern', today: SpaceTime { epoch: 1582174800000, tz: 'canada/eastern', silent: true, british: undefined, _weekStart: 1, _today: {} }, punt: { weeks: 2 }, dayStart: '8:00am', dayEnd: '5:30pm'} */
The text was updated successfully, but these errors were encountered:
Fdawgs
changed the title
Compromise-dates plugin mutates context object on function calls
Compromise-dates plugin mutates context param obj on function calls
May 23, 2024
Thanks @spencermountain, no worries! Just to reiterate, it seems to be all/most of the .dates() functions mutates it, not just .json(). I.e. doc.dates(context).format('{month} {date-ordinal}') also does it.
Node version: 20.13.1
Compromise version: 14.13.0
Compromise-dates version: 3.5.0
Using the compromise-dates plugin, any call to the
.dates()
functions (.json()
,.get()
,.format()
etc.) mutates thetoday
value in the context param obj to a SpaceTime object, which is an unexpected side-effect:The text was updated successfully, but these errors were encountered: