---
title: "compromise: syntax, contractions and dates in JS | VulCode"
description: "In compromise, a JavaScript NLP library, we fixed main clause verbs, contractions like can't and he's not, fortnight dates, payloads and match parsing."
url: "https://vulcode.com/en/opensource/contributions/compromise"
lang: "en"
---

[All contributions](https://vulcode.com/en/opensource/contributions)

spencermountain/compromise

# compromise

A natural language processing library in JavaScript: it splits text into sentences and words, tags parts of speech, conjugates verbs and inflects nouns, and reads dates through a plugin. It runs in the browser and in Node.js.

[See the repository](https://github.com/spencermountain/compromise) [All contributions](https://vulcode.com/en/opensource/contributions)

- **Language**: JavaScript
- **GitHub stars**: 12,176
- **Merged changes**: 23
- **Project site**: [compromise.cool](http://compromise.cool)

## What we changed

We fixed how the main clause verb is chosen, how contractions are built and expanded (can't, he's not, wanna), verb and noun conversions, dates (fortnight, a month's time) and the match pattern parser. We also fixed the payload and speech plugins and a test that crashed the test run against the built library.

### What this work shows

- Natural language processing (NLP)

- Syntax parsing: subject, verb, subordinate clauses

- Tokenisation and match pattern parsing

- Regression tests with tape

What was broken

### The verb came from a secondary clause

mainClause dropped every part of a sentence containing that or who, so in a sentence with a list after "that included" the verb came out as "state engineering" instead of "led". Sentences opening with "To win", "Had I known" or "In case", and a relative clause right after the subject ("The boy who you saw..."), also took the verb from the wrong part.

How we fixed it

### The verb comes from the main clause

A part of a sentence is now dropped only when the subordinator or relative pronoun comes before its own verb, and "since 2010" or "once upon a time" no longer count as subordinators. We recognise more openers of a secondary clause and skip the verb of a relative clause after the subject: on a probe of 20 sentences with such openers, 18 now come out right instead of 14.

[#1225](https://github.com/spencermountain/compromise/pull/1225) [#1224](https://github.com/spencermountain/compromise/pull/1224) [#1222](https://github.com/spencermountain/compromise/pull/1222)

What was broken

### Contractions came out mangled

contract() turned "can not" into "cann't" and "he is not" into "he'sn't", and treated two matches in one sentence as one: "he is here and she is there" became "he'shere and there". Expanding "I wanna pickle" added a stray "to", and "Leonard's was Randall" became "Leonard has was".

How we fixed it

### Each contraction is built on its own

Each match is contracted on its own, "can not" gives "can't", "he is not" gives "he's not", and the n't list now covers "did not" and "were not". "wanna" before a noun expands to "want" without "to", and 's before is, are, was, were or am is read as possessive.

[#1244](https://github.com/spencermountain/compromise/pull/1244) [#1243](https://github.com/spencermountain/compromise/pull/1243) [#1240](https://github.com/spencermountain/compromise/pull/1240) [#1237](https://github.com/spencermountain/compromise/pull/1237) [#1230](https://github.com/spencermountain/compromise/pull/1230)

What was broken

### Conversions lost meaning and letter case

toPositive() only turned "He does not like camels" into "He does like camels", and going to the infinitive turned "I will never do that" into "I do not never do that". toSingular made "Great Danes" into "great dane", and a capitalised "Higher" before "than" was tagged as a proper noun.

How we fixed it

### Correct forms and original letter case

toPositive() drops does and did and inflects the verb ("He likes camels", "she went home"), and toNegative() still restores the original. never stays without an extra "do not", toSingular gives each word back its original case, all caps included, and a known comparative right before "than" stays an adjective.

[#1242](https://github.com/spencermountain/compromise/pull/1242) [#1239](https://github.com/spencermountain/compromise/pull/1239) [#1229](https://github.com/spencermountain/compromise/pull/1229) [#1228](https://github.com/spencermountain/compromise/pull/1228)

What was broken

### The dates plugin missed some phrases

fortnight was not in the duration lexicon, so "in a fortnight" did not work, and "in a month's time" matched no unit because parseUnit only stripped a trailing s. In "2025-05-11 - They have taken the bridge", .dates().text() returned the dash as well.

How we fixed it

### Two weeks, a month and a clean date

fortnight is in the duration lexicon and counts as two weeks, and parseUnit also strips 's, so "in a month's time" lands a month out. A spaced dash after the last word of a match is dropped like other end punctuation, while the range "june 5 - june 7" stays whole.

[#1247](https://github.com/spencermountain/compromise/pull/1247) [#1236](https://github.com/spencermountain/compromise/pull/1236) [#1231](https://github.com/spencermountain/compromise/pull/1231)

What was broken

### Matching ignored some characters

The tokeniser cut the closing bracket off "foo(bar)", and lexicon words starting with # or @, such as #GoJetsGo, never matched. The match parser split hyphens differently from the tokeniser, so has("x-ray") looked for "x ray", and + or / escaped with a backslash still acted as an operator and a regex.

How we fixed it

### The parser reads characters like the tokeniser

A closing bracket that closes one inside the word stays in the word, for [] and {} too. The lexicon lookup also tries the normal form with # or @, the match parser splits hyphens with the tokeniser's own hasHyphen, and escaped + and / are read as plain characters.

[#1253](https://github.com/spencermountain/compromise/pull/1253) [#1249](https://github.com/spencermountain/compromise/pull/1249) [#1248](https://github.com/spencermountain/compromise/pull/1248) [#1241](https://github.com/spencermountain/compromise/pull/1241)

What was broken

### The payload and speech plugins went wrong

The payload plugin looked data up by sentence number, so after .remove() of an earlier sentence later payloads landed on the wrong words or went missing, and a new document could see an old one's payloads. The speech plugin merged the -ent syllable into the first one in silent, talent, parent and agent, and pnpm testb crashed with doc.normalize is not a function.

How we fixed it

### Payloads survive .remove(), syllables split

Payloads are found by the ids of their first and last terms, so they survive .remove(), and the limitations section is gone from the README. silent, talent, parent and agent now have two syllables, and the regex-boundaries test uses the full build, which includes normalize.

[#1246](https://github.com/spencermountain/compromise/pull/1246) [#1233](https://github.com/spencermountain/compromise/pull/1233) [#1232](https://github.com/spencermountain/compromise/pull/1232)

What was broken

### An empty string replaced the whole document

replace('dog', '') on the document "the dog sat on the mat" turned the whole text into "dog". The empty string was read as a missing second argument, so the call went to replaceWith('dog').

How we fixed it

### An empty string removes the match

replace now hands over to replaceWith only when the second argument is undefined. replace('dog', '') gives "the sat on the mat", just like match('dog').replaceWith(''), and a new test also checks a document with two sentences.

[#1278](https://github.com/spencermountain/compromise/pull/1278)

## Merged changes 23

- [#1278 let replace() remove a match when the replacement is an empty string Merged 21 November 2026](https://github.com/spencermountain/compromise/pull/1278)

- [#1253 fix match escaping for + and / Merged 28 October 2026](https://github.com/spencermountain/compromise/pull/1253)

- [#1246 find payloads by term id so they survive a .remove() Merged 6 October 2026](https://github.com/spencermountain/compromise/pull/1246)

- [#1242 keep a titlecase comparative before 'than' as an adjective Merged 6 October 2026](https://github.com/spencermountain/compromise/pull/1242)

- [#1249 keep a closing bracket in the word when it closes one inside it Merged 5 October 2026](https://github.com/spencermountain/compromise/pull/1249)

- [#1248 match lexicon words that start with # or @ Merged 5 October 2026](https://github.com/spencermountain/compromise/pull/1248)

- [#1247 leave a spaced dash out of a match's text Merged 5 October 2026](https://github.com/spencermountain/compromise/pull/1247)

- [#1244 contract each match on its own Merged 5 October 2026](https://github.com/spencermountain/compromise/pull/1244)

- [#1243 don't add an implicit 'to' after 'wanna' before a noun Merged 5 October 2026](https://github.com/spencermountain/compromise/pull/1243)

- [#1241 split hyphens in a match the same way the tokenizer does Merged 5 October 2026](https://github.com/spencermountain/compromise/pull/1241)

- [#1240 contract 'he is not' to he's not instead of he'sn't Merged 5 October 2026](https://github.com/spencermountain/compromise/pull/1240)

- [#1239 drop does/did when turning a negative verb positive Merged 5 October 2026](https://github.com/spencermountain/compromise/pull/1239)

- [#1237 contract 'can not' to can't Merged 5 October 2026](https://github.com/spencermountain/compromise/pull/1237)

- [#1236 dates: read singular possessive durations Merged 5 October 2026](https://github.com/spencermountain/compromise/pull/1236)

- [#1233 don't merge an -ent syllable back into an open first syllable Merged 5 October 2026](https://github.com/spencermountain/compromise/pull/1233)

- [#1232 run the regex-boundaries tests on the full build Merged 5 October 2026](https://github.com/spencermountain/compromise/pull/1232)

- [#1231 parse 'fortnight' as two weeks Merged 5 October 2026](https://github.com/spencermountain/compromise/pull/1231)

- [#1230 Treat 's before a copula as possessive Merged 29 September 2026](https://github.com/spencermountain/compromise/pull/1230)

- [#1229 Keep the case in toSingular Merged 29 September 2026](https://github.com/spencermountain/compromise/pull/1229)

- [#1228 Keep "never" when going to the infinitive Merged 29 September 2026](https://github.com/spencermountain/compromise/pull/1228)

- [#1225 Skip the verb of a relative clause following the subject Merged 19 September 2026](https://github.com/spencermountain/compromise/pull/1225)

- [#1224 Recognize more openers of a secondary clause in mainClause Merged 19 September 2026](https://github.com/spencermountain/compromise/pull/1224)

- [#1222 Only treat subordinators as secondary-clause signals before the verb Merged 14 September 2026](https://github.com/spencermountain/compromise/pull/1222)

## What it taught us

In a large rule-based parser changing one rule easily breaks another, so every fix ships with its own test cases. For the mainClause change we also measured the effect on performance.

[More about this technology: TypeScript, React and Node](https://vulcode.com/en/technologies/typescript-react-and-node)

## Other projects we write code for

- [**Material UI** JavaScript · 99,391 stars A React component library that implements Google's Material Design: ready-made text fields, selects, buttons and other interface elements.](https://vulcode.com/en/opensource/contributions/material-ui)

- [**Grafana** TypeScript · 78,050 stars An open observability and data visualisation platform that shows metrics, logs and traces from Prometheus, Loki, Elasticsearch, PostgreSQL and many other sources on dashboards.](https://vulcode.com/en/opensource/contributions/grafana)

- [**Marked** TypeScript · 37,323 stars A fast Markdown parser and compiler to HTML, written in TypeScript and following CommonMark and GitHub Flavored Markdown.](https://vulcode.com/en/opensource/contributions/marked)

- [**Autoprefixer** JavaScript · 22,197 stars A PostCSS plugin that adds browser prefixes to CSS based on Can I Use data, including the -ms-grid syntax for CSS Grid layouts.](https://vulcode.com/en/opensource/contributions/autoprefixer)

- [**Lichess** TypeScript · 19,013 stars The lichess.org chess server: free, ad-free and open source, focused on real-time play. The back end is written in Scala, the interface in TypeScript.](https://vulcode.com/en/opensource/contributions/lichess)

- [**Pterodactyl** PHP · 9,537 stars A free, open source game server management panel built with PHP, React and Go. Every game server runs in its own isolated Docker container.](https://vulcode.com/en/opensource/contributions/pterodactyl)

## Describe your project.

A free quote comes back within an hour during working hours.

### Rather skip the form?

Ask in the chat or write to us directly.

Open the chat

- **Email**: [hello@vulcode.com](mailto:hello@vulcode.com)
- **Phone**: [+48 576 043 920](tel:+48576043920)
- **Discord**: [discord.gg/vulcode](https://discord.gg/vulcode)
