fix(slugger): optimize trailing/leading regex#610
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #610 +/- ##
==========================================
- Coverage 78.66% 78.65% -0.01%
==========================================
Files 128 128
Lines 12456 12454 -2
Branches 883 883
==========================================
- Hits 9798 9796 -2
Misses 2653 2653
Partials 5 5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
| File | Base | Head | Diff |
|---|---|---|---|
cli.html |
281.51 KB | 283.20 KB | +1.69 KB (+0.60%) |
deprecations.html |
258.86 KB | 258.89 KB | +32.00 B (+0.01%) |
single-executable-applications.html |
83.02 KB | 83.05 KB | +24.00 B (+0.03%) |
esm.html |
122.59 KB | 122.60 KB | +16.00 B (+0.01%) |
globals.html |
120.17 KB | 120.18 KB | +16.00 B (+0.01%) |
modules.html |
148.53 KB | 148.55 KB | +16.00 B (+0.01%) |
buffer.html |
1.06 MB | 1.06 MB | +8.00 B (+0.00%) |
packages.html |
118.86 KB | 118.87 KB | +8.00 B (+0.01%) |
repl.html |
215.26 KB | 215.26 KB | +8.00 B (+0.00%) |
tls.html |
259.31 KB | 259.32 KB | +8.00 B (+0.00%) |
module.html |
322.94 KB | 322.94 KB | +4.00 B (+0.00%) |
webstreams.html |
266.19 KB | 266.20 KB | +4.00 B (+0.00%) |
orama-db Generator
| File | Base | Head | Diff |
|---|---|---|---|
orama-db.json |
8.03 MB | 8.03 MB | +3.29 KB (+0.04%) |
web Generator
| File | Base | Head | Diff |
|---|---|---|---|
cli.js |
325.51 KB | 327.85 KB | +2.34 KB (+0.72%) |
cli.html |
502.93 KB | 504.50 KB | +1.57 KB (+0.31%) |
deprecations.js |
313.52 KB | 313.57 KB | +48.00 B (+0.01%) |
single-executable-applications.js |
83.41 KB | 83.45 KB | +36.00 B (+0.04%) |
deprecations.html |
509.91 KB | 509.94 KB | +32.00 B (+0.01%) |
globals.js |
139.24 KB | 139.26 KB | +24.00 B (+0.02%) |
modules.js |
158.24 KB | 158.26 KB | +24.00 B (+0.01%) |
single-executable-applications.html |
101.24 KB | 101.26 KB | +24.00 B (+0.02%) |
globals.html |
231.61 KB | 231.62 KB | +16.00 B (+0.01%) |
modules.html |
177.98 KB | 177.99 KB | +16.00 B (+0.01%) |
buffer.js |
1.13 MB | 1.13 MB | +12.00 B (+0.00%) |
packages.js |
126.22 KB | 126.24 KB | +12.00 B (+0.01%) |
tls.js |
349.38 KB | 349.40 KB | +12.00 B (+0.00%) |
buffer.html |
855.53 KB | 855.54 KB | +8.00 B (+0.00%) |
esm.html |
152.69 KB | 152.70 KB | +8.00 B (+0.01%) |
esm.js |
139.78 KB | 139.79 KB | +8.00 B (+0.01%) |
packages.html |
155.45 KB | 155.46 KB | +8.00 B (+0.01%) |
tls.html |
353.23 KB | 353.24 KB | +8.00 B (+0.00%) |
repl.html |
176.85 KB | 176.86 KB | +4.00 B (+0.00%) |
repl.js |
215.40 KB | 215.40 KB | +4.00 B (+0.00%) |
module.html |
310.90 KB | 310.91 KB | +2.00 B (+0.00%) |
module.js |
351.50 KB | 351.50 KB | +2.00 B (+0.00%) |
webstreams.html |
343.87 KB | 343.87 KB | +2.00 B (+0.00%) |
webstreams.js |
320.81 KB | 320.82 KB | +2.00 B (+0.00%) |
There was a problem hiding this comment.
Pull request overview
This PR updates the Node.js API doc slug normalization logic by consolidating the “trim leading/trailing hyphen” behavior into a single regex replacement in the parser constants.
Changes:
- Replaces two separate leading/trailing hyphen replacements with one combined regex in
DOC_API_SLUGS_REPLACEMENTS.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Note: The anchors are slightly different (i.e. |
| { from: /--+/g, to: '-' }, // Replace multiple hyphens with single | ||
| { from: /^-/, to: '' }, // Remove any leading hyphen | ||
| { from: /-$/, to: '' }, // Remove any trailing hyphen | ||
| { from: /^-(?!$|-)|(?<!^|-)-$/g, to: '' }, // Remove any trailing or leading hyphen |
There was a problem hiding this comment.
| { from: /^-(?!$|-)|(?<!^|-)-$/g, to: '' }, // Remove any trailing or leading hyphen | |
| { from: /^-+(?!-*$)/g, to: '' }, // Remove any leading hyphens | |
| { from: /(?<!^-*)-+$/g, to: '' }, // Remove any trailing hyphens |
I think this does the same, but is a bit clearer to me, matching one or more hyphens, as long as we don't see the start/end around.
| { from: /node.js/i, to: 'nodejs' }, // Replace Node.js | ||
| { from: /&/, to: '-and-' }, // Replace & | ||
| { from: /[/_,:;\\ ]/g, to: '-' }, // Replace /_,:;\. and whitespace | ||
| { from: /--+/g, to: '-' }, // Replace multiple hyphens with single |
There was a problem hiding this comment.
I think we probably want to keep this deduplication somehow?
There was a problem hiding this comment.
(?<!^-*)--+(?!-*$) might work for this?
Fixes https://openjs-foundation.slack.com/archives/C09EXEEHFKP/p1771022712509279