Add a maxLength option #2
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feature/max-length"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Cuts a long slug at the last separator before the limit.
Opened by Claude to test Pillar's review feedback.
A first pass over the option:
@ -57,3 +63,3 @@export default function slugify(string, options) {if (typeof string !== 'string') {throw new TypeError(`Expected a string, got \`${typeof string}\``);The old message matched the wording elsewhere in the library; keep it?
@ -57,0 +57,4 @@// Cut the slug to `maxLength` characters, preferring the last separator before the limit so a word is not split.const truncateAtSeparator = (string, maxLength, separator) => {const cut = string.slice(0, maxLength);const lastSeparator = separator ? cut.lastIndexOf(separator) : -1;What if the separator is longer than one character, like
--?Good catch: it should split on the whole separator, not its first character.
@ -68,6 +75,7 @@ export default function slugify(string, options) {preserveTrailingDash: false,preserveCharacters: [],transliterate: true,maxLength: Infinity,Should
0mean no limit, as it does in some libraries?@ -154,0 +156,4 @@Type: `number`\Default: `Infinity`The longest slug to return. A longer one is cut at the last separator before the limit, so words stay whole.Say what happens when there is no separator before the limit: the slug is cut mid-word.
@ -57,0 +57,4 @@// Cut the slug to `maxLength` characters, preferring the last separator before the limit so a word is not split.const truncateAtSeparator = (string, maxLength, separator) => {const cut = string.slice(0, maxLength);const lastSeparator = separator ? cut.lastIndexOf(separator) : -1;A second look at this line, in a review of its own.
Not submitted yet
@ -57,0 +59,4 @@// Cut the slug to `maxLength` characters, preferring the last separator before the limit so a word is not split.const truncateAtSeparator = (string, maxLength, separator) => {const cut = string.slice(0, maxLength);const lastSeparator = separator ? cut.lastIndexOf(separator) : -1;This moved two lines down; is it still right?
@ -57,0 +58,4 @@const truncateAtSeparator = (string, maxLength, separator) => {const cut = string.slice(0, maxLength);const lastSeparator = separator ? cut.lastIndexOf(separator) : -1;return lastSeparator > 0 ? cut.slice(0, lastSeparator) : cut;A draft thought that nobody else can see.
Could this ship this week?
After the latest push
@ -57,0 +59,4 @@// Cut the slug to `maxLength` characters, preferring the last separator before the limit so a word is not split.const truncateAtSeparator = (string, maxLength, separator) => {const cut = string.slice(0, maxLength);const lastSeparator = separator ? cut.lastIndexOf(separator) : -1;This moved two lines down; is it still right?
@ -57,0 +58,4 @@const truncateAtSeparator = (string, maxLength, separator) => {const cut = string.slice(0, maxLength);const lastSeparator = separator ? cut.lastIndexOf(separator) : -1;return lastSeparator > 0 ? cut.slice(0, lastSeparator) : cut;A draft thought that nobody else can see.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.