Skip to content

fix(string/dash): add number boundaries to dash function #428

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

theodrosyimer
Copy link

@theodrosyimer theodrosyimer commented Aug 10, 2025

Fix dash function to align with lodash kebabCase for number boundaries

Fixes #408

What

Enhanced dash function to treat numbers as separate tokens, enabling existing hyphenation at alphanumeric boundaries.

Why

Align with lodash kebabCase behavior where numbers are treated as distinct words.

Before / After

// Before
dash('hello123') // => 'hello123'
dash('hello123world') // => 'hello123world'

// After  
dash('hello123') // => 'hello-123'
dash('hello123world') // => 'hello-123-world'

Implementation

Split digits into separate tokens by adding (\d+) to the regex:

// Before
?.split(/(?=[A-Z])|[\.\-\s_]/)

// After
?.split(/(?=[A-Z])|(\d+)|[\.\-\s_]/)

Breaking Changes

None - existing functionality preserved.

Bundle impact

Status File Size 1 Difference
M src/string/dash.ts 342 +8 (+2%)

Footnotes

  1. Function size includes the import dependencies of the function.

@radashi-bot
Copy link

radashi-bot commented Aug 10, 2025

Benchmark Results

Name Current Baseline Change
dash ▶︎ with valid input 1,040,489.67 ops/sec ±0.37% 1,501,962.22 ops/sec ±0.68% 🔗 🐢 -30.72%

Performance regressions of 30% or more should be investigated, unless they were anticipated. Smaller regressions may be due to normal variability, as we don't use dedicated CI infrastructure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dash has several disadvantages to lodash/kebabCase
2 participants