Skip to content

Compromise-Payloads plugin: Payloads removed if they occur after a View that is removed #1188

@Fdawgs

Description

@Fdawgs

Node version: 22.17.1
Compromise version: 14.14.4
Compromise-payloads version: 0.0.3

Using the compromise-payloads plugin, payloads disappear if they occur after a View that is removed using .remove() from the View they are in.

Example:

'use strict'

/** @type {import('compromise').default} */
const nlp = require('compromise')
const nlpPayload = require('compromise-payload')

nlp.plugin(nlpPayload)

const text = `Diary date 30 Jul 2025 11:00
The West Midlands is a hellscape of misery.

I had to travel there today, and i'm convinced the M6/M42 interchange is one of the circles of hell.

I needed a lot of cider afterwards.
I will have to go back again in a month and the thought of it fills me with dread.`

const doc = nlp(text)
const medication = doc.match('I needed a lot of cider afterwards')

doc.match('#Date+').forEach((d) => {
  d.addPayload({ sentence: d.text() })
})

// OUTPUTS: 3
console.log(doc.getPayloads().length)
// OUTPUTS: [ '30 Jul 2025 11:00', 'today', 'month' ]
console.log(doc.getPayloads().map((p) => p.val.sentence))

doc.remove(medication)

// OUTPUTS: 2, EXPECTED: 3
console.log(doc.getPayloads().length)
// OUTPUTS: [ '30 Jul 2025 11:00', 'today' ], EXPECTED: [ '30 Jul 2025 11:00', 'today', 'month' ]
console.log(doc.getPayloads().map((p) => p.val.sentence))

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions