Repository navigation
Add maxLength option - #78
Open
AmineYagoub wants to merge 1 commit into
Open
AmineYagoub wants to merge 1 commit into
AmineYagoub wants to merge 1 commit into
Conversation
Truncates the finished slug to at most `maxLength` characters, preferring the rightmost separator boundary at or before the limit and hard-cutting unbroken runs; a truncated slug never ends with the separator. Applies to the base slug in `slugifyWithCounter` before the counter suffix. Rejects anything but a positive integer with a TypeError. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Adds a
maxLengthoption for callers feeding slugs into URL segments, filenames, and keys with hard length limits — today they truncate the returned slug by hand, which cuts words in half and leaves dangling separators.Semantics:
slugify('Foo Bar Baz Qux', {maxLength: 9})→'foo-bar'), hard-cutting a single unbroken run (slugify('Internationalization', {maxLength: 8})→'internat') and withseparator: ''.slugifyWithCounterapplies the limit to the base slug before the counter suffix, so deduplication is never silently broken by truncation.TypeErrornaming the option.Includes tests for each semantic (22 → 28 passing) and readme +
index.d.tsdocs in the existing style.Full disclosure: this change was implemented end-to-end by Detent, an autonomous-engineering tool I'm building — every step was gated by this repo's own
xo/avasuite and independently reviewed before commit. I'm sharing it as a hopefully useful contribution; happy to adjust anything, or to close this and open an issue first if that's your preferred flow.🤖 Generated with Claude Code