From d499514cbcf4cd87ccc9c4fe88009d11b0b65e51 Mon Sep 17 00:00:00 2001 From: Jason Gessner Date: Thu, 6 Feb 2025 20:05:54 -0600 Subject: [PATCH] Generalize handling contractions in textToId. --- src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 816c55733..56fec9f8a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -32,8 +32,8 @@ export function textToId(text: string): string { .normalize('NFD') // remove non-ASCII .replace(/\P{ASCII}/gu, '') - // replace 's followed by a space or end-of-line with s and the space/end match. - .replace(/'s(\s|$)/gu, 's$1') + // replace '\w followed by a space or end-of-line with \w and the space/end match. + .replace(/'(\w)(\s|$)/gu, '$1$2') // split along space or punction. .split(/[\s\p{P}]+/u) // exclude any elements that are empty when trimmed to avoid trailing _ for the join.