3636 * A count belongs to Sim when "Sim" comes before it in the same clause and no other product's
3737 * possessive directly precedes it, or when it sits in a table row whose label cell is Sim.
3838 * Sentence ends and contrasts ("while", "unlike", "compared with") start a new clause.
39+ * A count whose owner is ambiguous within its clause is treated as Sim's; when it belongs to
40+ * another product, name that product as its owner ("Zapier's 9,000+") or give it a sentence.
3941 * Blog and changelog posts are dated, so their counts are true as of publication.
4042 *
4143 * Run one post with `--slug <section>/<slug>` or `--slug <slug>`.
@@ -146,35 +148,36 @@ const LINE_PREFIX = /^\s*(?:(?:[-*+>]|\d+[.)]|#{1,6})\s+)*(?:\w+:\s*["'])?/
146148const SIM_NAME = / \b S i m \b /
147149/** Words that turn a sentence toward another product: "while Zapier lists ...", "unlike Zapier". */
148150const CONTRAST = String . raw `(?:while|whereas|but|unlike|compared (?:with|to)|versus|vs\.?)`
149- /** A comparison set off by commas inside a sentence, as in "Sim, unlike Zapier, has ...". */
150- const PARENTHETICAL_COMPARISON = new RegExp ( String . raw `,\s+(?:like|${ CONTRAST } )\s+[^,\d]*,` , 'gi' )
151151/**
152- * A sentence end, a contrast that hands the rest of the sentence to another subject, or a
153- * relative clause about a product other than Sim ("Zapier, which has ...") .
152+ * A comparison set off by commas right after Sim, as in "Sim, unlike Zapier, has ...". The span
153+ * ends at the first comma that is not a thousands separator, so "Sim, unlike n8n, ..." matches .
154154 */
155- const CLAUSE_BREAK = new RegExp (
156- String . raw `(?<=[.!?;])\s+|,? \s+${ CONTRAST } \s+|(?<!\bSim),\s+(?:which|who)\s+ ` ,
157- 'i '
155+ const SIM_PARENTHETICAL = new RegExp (
156+ String . raw `\bSim, \s+(?:like| ${ CONTRAST } ) \s+(?:[^,]|,(?=\d))*?,(?!\d) ` ,
157+ 'gi '
158158)
159+ /** A sentence end, or a contrast that hands the rest of the sentence to another subject. */
160+ const CLAUSE_BREAK = new RegExp ( String . raw `(?<=[.!?;])\s+|,?\s+${ CONTRAST } \s+` , 'i' )
159161/** An opening comparison ("Unlike Sim, ...") whose main clause is about another product. */
160162const LEADING_COMPARISON = new RegExp ( String . raw `^(?:like|${ CONTRAST } )\b[^,]*,\s*` , 'i' )
161163/** The product whose possessive directly precedes a count, as in "Zapier's 9,000+". */
162164const POSSESSIVE_OWNER = / ( [ \w . - ] + ) [ ' ’ ] s \s * $ /
163165/** A Sim count below this share of the catalog total is left from an older catalog. */
164166const SIM_COUNT_FLOOR = 0.9
165167
166- /** Every count in a table row whose first cell names Sim. */
167- function simTableRowCounts ( row : string ) : RegExpMatchArray [ ] {
168- return SIM_NAME . test ( row . split ( '|' ) [ 1 ] ?. trim ( ) . split ( / \s / ) [ 0 ] ?? '' )
169- ? [ ...row . matchAll ( COUNT_CLAIM ) ]
168+ /** Every count in a table row whose label (first non-empty cell) names Sim. */
169+ function simTableRowCounts ( cells : string [ ] ) : RegExpMatchArray [ ] {
170+ const label = cells . map ( ( cell ) => cell . trim ( ) ) . find ( ( cell ) => cell !== '' ) ?? ''
171+ return SIM_NAME . test ( label . split ( / \s / ) [ 0 ] )
172+ ? cells . flatMap ( ( cell ) => [ ...cell . matchAll ( COUNT_CLAIM ) ] )
170173 : [ ]
171174}
172175
173176/** Each count whose clause names Sim before it, unless another product's possessive owns it. */
174177function simProseCounts ( text : string ) : RegExpMatchArray [ ] {
175178 const sentences = text
176179 . replace ( LINE_PREFIX , '' )
177- . replace ( PARENTHETICAL_COMPARISON , '' )
180+ . replace ( SIM_PARENTHETICAL , 'Sim ' )
178181 . split ( CLAUSE_BREAK )
179182 return sentences . flatMap ( ( sentence ) => {
180183 const clause = sentence . replace ( LEADING_COMPARISON , '' )
@@ -189,7 +192,8 @@ function simProseCounts(text: string): RegExpMatchArray[] {
189192/** The counts on one line of text that belong to Sim, with the claim as written. */
190193function simCountClaims ( line : string ) : { claim : string ; count : number ; unit : SimCountUnit } [ ] {
191194 const text = line . replace ( INLINE_MARKERS , '' ) . replace ( LINK_TEXT , '$1' )
192- const matches = text . trimStart ( ) . startsWith ( '|' ) ? simTableRowCounts ( text ) : simProseCounts ( text )
195+ const cells = text . split ( '|' )
196+ const matches = cells . length > 2 ? simTableRowCounts ( cells ) : simProseCounts ( text )
193197 return matches . map ( ( match ) => ( {
194198 claim : match [ 0 ] ,
195199 count : Number . parseInt ( match [ 1 ] . replaceAll ( ',' , '' ) , 10 ) ,
@@ -486,7 +490,7 @@ export async function checkPost(
486490 count > total
487491 ? `"${ claim } " overstates Sim's catalog, which has ${ total } ${ unit } .`
488492 : `"${ claim } " is stale: Sim's catalog has ${ total } ${ unit } .` ,
489- `Write ${ formatLowerBound ( total ) } ${ unit } , the catalog-derived figure (INTEGRATION_TOTALS in packages/deployment-config/src/integration-totals.ts).`
493+ `Write ${ formatLowerBound ( total ) } ${ unit } , the catalog-derived figure (INTEGRATION_TOTALS in packages/deployment-config/src/integration-totals.ts). If the count is another product's, name it as the owner ("Zapier's 9,000+") or give it its own sentence. `
490494 )
491495 }
492496 }
0 commit comments