Skip to content

Conversation

@kazupon
Copy link
Member

@kazupon kazupon commented Nov 12, 2025

Description

Linked Issues

Additional context

Summary by CodeRabbit

  • Refactor
    • Public locale/header helpers now accept a single options object (with internal defaults) instead of multiple positional/destructured parameters for header, cookie, path and query flows.
  • New Features
    • Introduced a dedicated cookie-locale options type to configure cookie name/lang via the consolidated options.
  • Documentation
    • Fixed typos and updated JSDoc/examples to reflect the new options-based API.
  • Chores
    • Stopped copying a shim file into the Deno build targets.

@coderabbitai
Copy link

coderabbitai bot commented Nov 12, 2025

Walkthrough

This PR refactors locale and language helper functions across multiple framework adapters and HTTP utilities to accept a single options object parameter instead of destructured individual parameters. Functions previously using { name, parser, lang } destructuring now take unified options: XOptions = {} signatures with internal destructuring for defaults. A new CookieLocaleOptions type is introduced; minor documentation corrections are applied.

Changes

Cohort / File(s) Summary
HTTP Utilities (Core)
src/http.ts, deno/http.ts
Introduces CookieLocaleOptions type and refactors getHeaderLanguagesWithGetter, getPathLanguage, getPathLocale, and getQueryLocale to accept unified options objects instead of destructured parameters; internal destructuring applies defaults.
Framework Adapters
src/h3.ts, src/hono.ts, src/web.ts, src/node.ts
Systematically updates all locale/header/path/query/cookie helper functions to accept options: XOptions = {} pattern; functions extract name, lang, parser from options and delegate to updated HTTP utilities.
Deno Framework
deno/web.ts
Mirrors src/web.ts refactoring: all header, cookie, path, and query locale functions updated to accept unified options objects; delegates to corresponding HTTP utility helpers.
Documentation & Build
src/shared.ts, deno/shared.ts
Corrects typo in comment: "conosle.log" → "console.log" in normalizeLanguageName documentation.
Build Configuration
scripts/deno.ts
Removes shim.d.ts from TARGETS array, reducing files copied to deno hosting directory.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Systematic refactoring: Same parameter restructuring pattern applied consistently across 8+ files reduces individual reasoning per file but increases need for pattern verification.
  • Mechanical changes: Default value extraction and options destructuring are straightforward but require confirmation that all call sites forward options correctly.
  • Areas requiring extra attention:
    • Verify that internal getHeaderLanguagesWithGetter, getPathLanguage, and getQueryLocale utilities receive and use options object correctly.
    • Confirm that default values (e.g., ACCEPT_LANGUAGE_HEADER, DEFAULT_LANG_TAG, parseDefaultHeader) are properly applied within function bodies after extraction from options.
    • Check that tryCatchXxx wrapper functions properly propagate the options object to underlying getXxx functions.
    • Validate CookieLocaleOptions type definition and its usage in cookie-related functions.

Poem

🐰 Options consolidated, parameters take flight,
No more scattered args—just options feels right!
From headers to cookies, the pattern holds true,
One object to rule them, simplifying through! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: wrong default options' directly addresses the core issue: a refactoring that moves default value assignments from parameter destructuring into function bodies to fix inconsistent default handling across multiple locale/language APIs.
Docstring Coverage ✅ Passed Docstring coverage is 97.37% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/refacotor

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d44580d and ed83cda.

📒 Files selected for processing (10)
  • deno/http.ts (5 hunks)
  • deno/shared.ts (1 hunks)
  • deno/web.ts (14 hunks)
  • scripts/deno.ts (0 hunks)
  • src/h3.ts (13 hunks)
  • src/hono.ts (13 hunks)
  • src/http.ts (5 hunks)
  • src/node.ts (14 hunks)
  • src/shared.ts (1 hunks)
  • src/web.ts (14 hunks)
💤 Files with no reviewable changes (1)
  • scripts/deno.ts
🧰 Additional context used
🧬 Code graph analysis (7)
src/hono.ts (1)
src/http.ts (9)
  • HeaderOptions (145-154)
  • getHeaderLanguagesWithGetter (175-188)
  • mapToLocaleFromLanguageTag (222-227)
  • parseDefaultHeader (163-165)
  • CookieLocaleOptions (131-140)
  • CookieOptions (121-126)
  • validateLocale (208-212)
  • PathOptions (251-260)
  • QueryOptions (302-311)
src/web.ts (1)
src/http.ts (12)
  • HeaderOptions (145-154)
  • getHeaderLanguagesWithGetter (175-188)
  • mapToLocaleFromLanguageTag (222-227)
  • parseDefaultHeader (163-165)
  • CookieLocaleOptions (131-140)
  • CookieOptions (121-126)
  • validateLocale (208-212)
  • getExistCookies (237-246)
  • getPathLocale (285-287)
  • PathOptions (251-260)
  • getQueryLocale (342-348)
  • QueryOptions (302-311)
src/node.ts (2)
deno/web.ts (7)
  • getHeaderLanguages (52-56)
  • getHeaderLanguage (83-85)
  • getHeaderLocale (167-177)
  • getCookieLocale (225-233)
  • setCookieLocale (282-295)
  • getPathLocale (307-309)
  • getQueryLocale (339-342)
src/http.ts (11)
  • HeaderOptions (145-154)
  • getHeaderLanguagesWithGetter (175-188)
  • parseDefaultHeader (163-165)
  • CookieLocaleOptions (131-140)
  • CookieOptions (121-126)
  • validateLocale (208-212)
  • getExistCookies (237-246)
  • getPathLocale (285-287)
  • PathOptions (251-260)
  • getQueryLocale (342-348)
  • QueryOptions (302-311)
deno/http.ts (3)
src/http.ts (8)
  • CookieLocaleOptions (131-140)
  • getHeaderLanguagesWithGetter (175-188)
  • HeaderOptions (145-154)
  • parseDefaultHeader (163-165)
  • getPathLanguage (270-273)
  • PathOptions (251-260)
  • getPathLocale (285-287)
  • QueryOptions (302-311)
src/constants.ts (2)
  • ACCEPT_LANGUAGE_HEADER (19-19)
  • DEFAULT_LANG_TAG (9-9)
src/shared.ts (1)
  • pathLanguageParser (146-146)
src/h3.ts (2)
src/http.ts (11)
  • HeaderOptions (145-154)
  • getHeaderLanguagesWithGetter (175-188)
  • mapToLocaleFromLanguageTag (222-227)
  • parseDefaultHeader (163-165)
  • CookieLocaleOptions (131-140)
  • CookieOptions (121-126)
  • validateLocale (208-212)
  • getPathLocale (285-287)
  • PathOptions (251-260)
  • getQueryLocale (342-348)
  • QueryOptions (302-311)
src/constants.ts (3)
  • ACCEPT_LANGUAGE_HEADER (19-19)
  • DEFAULT_LANG_TAG (9-9)
  • DEFAULT_COOKIE_NAME (14-14)
deno/web.ts (2)
deno/http.ts (12)
  • HeaderOptions (145-154)
  • getHeaderLanguagesWithGetter (175-188)
  • mapToLocaleFromLanguageTag (222-227)
  • parseDefaultHeader (163-165)
  • CookieLocaleOptions (131-140)
  • CookieOptions (121-126)
  • validateLocale (208-212)
  • getExistCookies (237-246)
  • getPathLocale (285-287)
  • PathOptions (251-260)
  • getQueryLocale (342-348)
  • QueryOptions (302-311)
deno/constants.ts (3)
  • ACCEPT_LANGUAGE_HEADER (19-19)
  • DEFAULT_LANG_TAG (9-9)
  • DEFAULT_COOKIE_NAME (14-14)
src/http.ts (3)
deno/http.ts (7)
  • getHeaderLanguagesWithGetter (175-188)
  • HeaderOptions (145-154)
  • parseDefaultHeader (163-165)
  • getPathLanguage (270-273)
  • PathOptions (251-260)
  • getPathLocale (285-287)
  • QueryOptions (302-311)
src/constants.ts (2)
  • ACCEPT_LANGUAGE_HEADER (19-19)
  • DEFAULT_LANG_TAG (9-9)
deno/shared.ts (1)
  • pathLanguageParser (146-146)
🔇 Additional comments (5)
src/shared.ts (1)

95-95: Doc example typo fix looks good.

Thanks for aligning the example with the actual API usage.

deno/shared.ts (1)

95-95: Doc example updated correctly.

Mirroring the console log fix here keeps the docs consistent between Node and Deno targets.

deno/http.ts (1)

175-187: Options refactor preserves header semantics.

Deferring default resolution into the body keeps getHeaderLanguagesWithGetter behavior intact while letting callers pass a shared options object—nice cleanup.

src/http.ts (1)

270-287: Path locale helper still defaults correctly.

Pulling defaults from the options object without changing return flow keeps getPathLanguage/getPathLocale behavior stable for existing consumers.

src/node.ts (1)

289-302: Cookie locale defaults remain intact.

Extracting name up front while forwarding the original options keeps the fallback cookie name and serializer behavior consistent—looks good.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kazupon kazupon added the improvement Includes backwards-compatible fixes label Nov 12, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 12, 2025

Open in StackBlitz

npm i https://pkg.pr.new/intlify/utils/@intlify/utils@65

commit: ed83cda

@kazupon
Copy link
Member Author

kazupon commented Nov 12, 2025

@coderabbitai please review this PR

@coderabbitai
Copy link

coderabbitai bot commented Nov 12, 2025

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Get the PR diff and details
gh pr view 65 --json title,body,files,additions,deletions,changedFiles

# Get the actual diff
gh pr diff 65

Length of output: 90260


@kazupon I'll review this PR for you.

Review Summary

This is a well-structured refactoring PR that addresses default options handling across the locale/language retrieval APIs. The changes are consistent, improve code quality, and fix potential issues with default parameter objects.

Key Changes

Default Options Refactoring

The PR consistently refactors all functions to extract default value assignments from parameter declarations into the function body:

Before:

export function getHeaderLanguages(
  request: Request,
  { name = ACCEPT_LANGUAGE_HEADER, parser = parseDefaultHeader }: HeaderOptions = {}
): string[] {

After:

export function getHeaderLanguages(request: Request, options: HeaderOptions = {}): string[] {
  const { name = ACCEPT_LANGUAGE_HEADER, parser = parseDefaultHeader } = options

Benefits:

  • Resolves ESLint unicorn/no-object-as-default-parameter violations
  • Avoids potential issues with object literal defaults
  • More explicit and maintainable code
  • Consistent pattern across the entire codebase

New Type Addition

The CookieLocaleOptions type appropriately separates cookie locale concerns from cookie serialization options:

export type CookieLocaleOptions = {
  lang?: string
  name?: string
}

This is properly used in getCookieLocale and tryCookieLocale functions, while setCookieLocale still uses the fuller CookieOptions type.

setCookieLocale Fix

The problematic default object pattern is fixed:

Before:

options: CookieOptions = { name: DEFAULT_COOKIE_NAME } // eslint-disable-line...

After:

options: CookieOptions = {}
// ...
const { name = DEFAULT_COOKIE_NAME } = options

This properly applies the default while avoiding the linting issue.

Documentation Updates

JSDoc comments are updated to reference the new parameter structure, maintaining documentation quality.

Minor Fixes

  • Typo fix: conosle.logconsole.log in shared.ts
  • Removed unused @ts-ignore comment

Verification

The refactoring is:

  • Consistent - Applied uniformly across all 10 files
  • Non-breaking - API surface remains identical
  • Complete - All affected functions updated
  • Correct - Default values preserved accurately

Recommendation

LGTM! 🎉 This PR successfully fixes the default options handling issue while improving code consistency and maintainability. The changes are safe to merge.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@kazupon kazupon merged commit 6c7f334 into main Nov 12, 2025
8 of 9 checks passed
@kazupon kazupon deleted the fix/refacotor branch November 12, 2025 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Includes backwards-compatible fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants