-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
Add leading underscore option #43
Changes from 1 commit
64d6bbc
0c20cd6
9348c29
ee0cf26
ea9be90
e071769
35b8da5
ed03eeb
85209f8
781c37e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -126,6 +126,7 @@ test('supports Armenian', t => { | |||||
}); | ||||||
|
||||||
test('leading underscore', t => { | ||||||
t.is(slugify('_foo bar', {leadingUnderscore: true}), '_foo-bar'); | ||||||
t.is(slugify('_foo_bar', {leadingUnderscore: true}), '_foo-bar'); | ||||||
t.is(slugify('_foo bar', {preserveLeadingUnderscore: true}), '_foo-bar'); | ||||||
t.is(slugify('_foo_bar', {preserveLeadingUnderscore: true}), '_foo-bar'); | ||||||
t.is(slugify('__foo__bar', {preserveLeadingUnderscore: true}), '_-foo-bar'); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should result in:
Suggested change
Would also be good to add a test for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was testin and after the string = string.replace(patternSlug, separator); in all these examples it became _\-foo\-bar. So, I thought in just slicing the separator (\-) after it. Something like: if(string.slice(1,2) == separator){
string = string.slice(0, 1) + string.slice(2, string.length);
} it works, but what do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you're unnecessarily complicating the implementation. You could just do: const shouldPrependUnderscore = options.preserveLeadingUnderscore && string.startsWith('_'); at the start and then prepend a underscore at the end if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually thought that way firstly, but i thought would be better to just modify the current regex and got confused afterall There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just committed the changes, sindre. |
||||||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be better written as: