-
Notifications
You must be signed in to change notification settings - Fork 14
feat(cname-prefix): add isPrefixedCdnBase helper
#547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
f2a9d10 to
b25e176
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds a new helper to determine whether a given CDN base URL includes a specified prefix subdomain, and exposes it across sync, async, and main package entries.
- Implements
isPrefixedCdnBaseincommon/ - Exports the helper in
async/index.ts,sync/index.ts, and package rootindex.ts - Provides unit tests covering typical and invalid URL cases
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/cname-prefix/src/common/isPrefixedCdnBase.ts | Added isPrefixedCdnBase helper implementation |
| packages/cname-prefix/src/common/isPrefixedCdnBase.test.ts | Introduced unit tests for the new helper |
| packages/cname-prefix/src/async/index.ts | Re-exported helper in the async entry point |
| packages/cname-prefix/src/sync/index.ts | Re-exported helper in the sync entry point |
| packages/cname-prefix/src/index.ts | Exposed helper in main package entry |
Comments suppressed due to low confidence (3)
packages/cname-prefix/src/common/isPrefixedCdnBase.ts:1
- [nitpick] Consider adding a JSDoc comment above this function to explain its purpose, parameters, return value, and edge-case behavior for better readability and maintainability.
export const isPrefixedCdnBase = (cdnBase: string, prefixCdnBase: string) => {
packages/cname-prefix/src/common/isPrefixedCdnBase.test.ts:34
- Add a test for multi-level subdomains (e.g.
'https://a.b.ucarecd.net', 'https://ucarecd.net') to verify the helper handles deeper prefix chains as intended.
})
packages/cname-prefix/src/index.ts:3
- [nitpick] Remember to update the package README and CHANGELOG to document the new
isPrefixedCdnBasehelper as part of the public API.
export { isPrefixedCdnBase } from './common/isPrefixedCdnBase'
| const cdnBaseHostnameParts = cdnBaseHostname.split('.') | ||
| if (cdnBaseHostnameParts.length !== 3) { | ||
| return false | ||
| } | ||
| const [, sld, tld] = cdnBaseHostnameParts | ||
| const cdnBaseHostnameWithoutPrefix = `${sld}.${tld}` | ||
| return prefixCdnBaseUrl.hostname === cdnBaseHostnameWithoutPrefix |
Copilot
AI
Jul 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The helper currently only handles exactly three hostname parts, which will fail for multi-level subdomains. Consider using cdnBaseUrl.hostname.endsWith(.${prefixCdnBaseUrl.hostname}) to simplify the logic and support arbitrary subdomain depths.
| const cdnBaseHostnameParts = cdnBaseHostname.split('.') | |
| if (cdnBaseHostnameParts.length !== 3) { | |
| return false | |
| } | |
| const [, sld, tld] = cdnBaseHostnameParts | |
| const cdnBaseHostnameWithoutPrefix = `${sld}.${tld}` | |
| return prefixCdnBaseUrl.hostname === cdnBaseHostnameWithoutPrefix | |
| return cdnBaseHostname.endsWith(`.${prefixCdnBaseUrl.hostname}`) |
b25e176 to
c311b5b
Compare
Description
Checklist