refactor: replace bcp-47-normalize with lightweight BCP-47 normalization (-185 KB)#4970
Open
PascalThuet wants to merge 2 commits intoDash-Industry-Forum:developmentfrom
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR removes the heavyweight bcp-47-normalize dependency and replaces it with a small internal BCP-47 normalization utility to reduce the shipped bundle size, while keeping the language-tag normalization behavior needed by dash.js.
Changes:
- Added
normalizeBcp47()utility with RFC 5646 case normalization + ISO 639-2 → 639-1 mapping. - Updated DASH parsing/selection code paths to use
normalizeBcp47()instead ofbcp47Normalize(). - Removed
bcp-47-normalizefrompackage.jsondependencies.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/streaming/utils/BCP47Utils.js |
Introduces internal BCP-47 normalization + ISO 639-2→1 mapping table. |
src/streaming/controllers/MediaController.js |
Switches language matching normalization to the new internal utility. |
src/dash/parser/matchers/LangMatcher.js |
Switches MPD lang attribute normalization to the new internal utility. |
src/dash/DashAdapter.js |
Switches CEA-608 caption language normalization to the new internal utility. |
package.json |
Removes the bcp-47-normalize dependency entry. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Remove the bcp-47-normalize dependency (~185 KB minified including transitive deps) and replace it with a ~75-line internal utility that covers the two features dash.js actually uses: RFC 5646 case normalization and ISO 639-2 to 639-1 conversion. Fixes Dash-Industry-Forum#4969
716b1cc to
d0b9192
Compare
- Add standard dash.js BSD license header to BCP47Utils.js - Use Object.create(null) for ISO_639_2_TO_1 to prevent prototype pollution - Regenerate package-lock.json to remove bcp-47-normalize and transitive deps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
bcp-47-normalizedependency and its transitive deps (bcp-47,is-alphabetical,is-alphanumerical,is-decimal)src/streaming/utils/BCP47Utils.jsdash.all.min.js(-18.9%)What changed
New file:
src/streaming/utils/BCP47Utils.jsnormalizeBcp47(tag): RFC 5646 case normalization (language → lowercase, script → titlecase, region → uppercase) + complete ISO 639-2/B and 639-2/T → ISO 639-1 lookup table (184 entries)Modified files: replaced
import {bcp47Normalize} from 'bcp-47-normalize'withimport {normalizeBcp47} from '...BCP47Utils.js'in:src/streaming/controllers/MediaController.js(2 call sites)src/dash/parser/matchers/LangMatcher.js(1 call site)src/dash/DashAdapter.js(1 call site)package.json: removedbcp-47-normalizefrom dependencies.bcp-47-match(providesextendedFilter()) is unchanged.Bundle size
Measured on
developmentbranch (v5.2.0), modern prod build:dash.all.min.jsdash.all.debug.jsWhat is NOT covered
The full
bcp-47-normalizealso handles features dash.js never uses:iw→he,in→id): rare in real MPDs. A small table could be added later if needed.zh→zh-Hans-CN): unnecessary becauseextendedFilter()already matches via RFC 4647 prefix matching.Test plan
spa→es,fre→fr)Fixes #4969