Slugify icon indicating copy to clipboard operation
Slugify copied to clipboard

Option to limit Slug Length

Open ntbm opened this issue 2 years ago • 5 comments

Implements #18

Added Option to Limit Output Slug Length. Default Value is null to not introduce any breaking Changes into the Library.

ntbm avatar Oct 01 '22 07:10 ntbm

Hi @ntbm - thanks for this!

ctolkien avatar Oct 04 '22 07:10 ctolkien

The failing test is an interesting one... normally the lib won't leave trailing -'s but we are specifically asking for a max length....

ctolkien avatar Oct 04 '22 07:10 ctolkien

The failing test is an interesting one... normally the lib won't leave trailing -'s but we are specifically afking for a max length....

That's why I added it. Handling all the specific edgescases will be a nightmare. So I'd vote to just accept that edge case. Question is if it be best to document it 🤔

ntbm avatar Oct 04 '22 15:10 ntbm

Would it make sense to make the limiting a bit “smarter” so that it would not break within words if possible?

For example "this is an example" would slugify to "this-is-an-example". But cutting it at 15 characters would result in "this-is-an-exam" which might not be ideal. Instead, there could be some more sophisticated limiting approach which would result in "this-is-an" instead since example doesn’t fit anymore.

poke avatar Oct 09 '22 16:10 poke

Would it make sense to make the limiting a bit “smarter” so that it would not break within words if possible?

If there is a fast way of doing that? I imagine you need scan back to find the last non - character within the string limit length.

ctolkien avatar Feb 22 '23 11:02 ctolkien