-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
URL: Remove all of Lodash from the package #41687
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a7ede97
url: Introduce remove-accents dependency
tyxla 16afd37
url: Use removeAccents instead of lodash in cleanForSlug
tyxla 3f496c6
url: Remove _.every() from tests
tyxla 8b6e39a
url: Remove unnecessary extra trim
tyxla f6a8d56
Handle multiple leading or trailing dashes
tyxla f2f238a
Add a test to cover multiple leading and trailing dashes
tyxla 8832905
Add comments in cleanForSlug for comprehensibility
tyxla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { every } from 'lodash'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
|
@@ -44,35 +39,37 @@ describe( 'isURL', () => { | |
} ); | ||
|
||
describe( 'isEmail', () => { | ||
it( 'returns true when given things that look like an email', () => { | ||
const emails = [ | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
]; | ||
|
||
expect( every( emails, isEmail ) ).toBe( true ); | ||
} ); | ||
|
||
it( "returns false when given things that don't look like an email", () => { | ||
const emails = [ | ||
'Abc.wordpress.org', | ||
'A@b@[email protected]', | ||
'a"b(c)d,e:f;g<h>i[jk][email protected]', | ||
'just"not"[email protected]', | ||
'this is"[email protected]', | ||
'this still"not\\[email protected]', | ||
'1234567890123456789012345678901234567890123456789012345678901234+x@wordpress.org', | ||
]; | ||
|
||
expect( every( emails, isEmail ) ).toBe( false ); | ||
} ); | ||
it.each( [ | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'1234567890123456789012345678901234567890123456789012345678901234+x@wordpress.org', | ||
] )( | ||
'returns true when given things that look like an email: %s', | ||
( email ) => { | ||
expect( isEmail( email ) ).toBe( true ); | ||
} | ||
); | ||
|
||
it.each( [ | ||
'Abc.wordpress.org', | ||
'A@b@[email protected]', | ||
'a"b(c)d,e:f;g<h>i[jk][email protected]', | ||
'just"not"[email protected]', | ||
'this is"[email protected]', | ||
'this still"not\\[email protected]', | ||
] )( | ||
"returns false when given things that don't look like an email: %s", | ||
( email ) => { | ||
expect( isEmail( email ) ).toBe( false ); | ||
} | ||
); | ||
} ); | ||
|
||
describe( 'getProtocol', () => { | ||
|
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.
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.
Would this work too, @tyxla ?
Found it on StackOverflow – perhaps we could do without the
remove-accents
dependency entirely? I saw it was based on a characters map so perhapsstr.normalize
would give us an even better coverage for free?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.
Thanks for asking @adamziel, it's actually a great question!
I'd be happy to go with that, it's always ideal to not rely on another package. The thing is, that solution works for most of the characters, but from what I've seen, it doesn't cover them all, or at least, doesn't cover as many as the package I've used covers.
Try this in your browser console - I've built it from the character map of the package:
and you'll get:
where while the result is satisfactory, you will notice that there are quite a few that actually remain unchanged.
For the library above, we also used the corresponding WP function originally when compiling the character map, so this also gets us closer to a parity with the WordPress backend - a nice side benefit IMHO.
What do you think?
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.
Nice test!
Alright, let's go with the package 👍