* Converts a free-text description into a kebab-case slug of at most 6 * meaningful words. Stop words and non-alphanumeric characters are stripped.
(description: string)
| 191 | * meaningful words. Stop words and non-alphanumeric characters are stripped. |
| 192 | */ |
| 193 | function toSlug(description: string): string { |
| 194 | return ( |
| 195 | description |
| 196 | .toLowerCase() |
| 197 | .replace(/[^a-z0-9\s]/g, "") |
| 198 | .trim() |
| 199 | .split(/\s+/) |
| 200 | .filter((w) => !STOP_WORDS.has(w)) |
| 201 | .slice(0, 6) |
| 202 | .join("-") || "change" |
| 203 | ); |
| 204 | } |