-
Notifications
You must be signed in to change notification settings - Fork 12
Add feature detection of unicode properties support #292
Conversation
src/featuredetection.js
Outdated
* @protected | ||
* @namespace | ||
*/ | ||
export default { |
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 was wondering whether it should be palced in https://github.com/ckeditor/ckeditor5-utils/blob/cf06347de71b235b564a13016a260af7c191a34d/src/unicode.js - but at the end the linked file is related to unicode handling, while this check is focused on RegExp in context of a given unicode goup handling.
However I'd give it better namespacing, I'm thinking more like: utils.featuredetection.regexp.isXyzSupported()
.
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.
@mlewand to clarify:
import featureDetection from '@ckeditor5-utils/src/utils/featuredetection';
console.log(
'Regex group is supported:',
featureDetection.regex.isUnicodePropertySupported()
);
ps.: Shouldn't it be isUnicodePropertyEscapesSupported()
? 😆
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.
@msamsel please create also a PR in mention repo to use this util instaed own feature detection.
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.
@jodator I was thinking more about:
import regExpFeatureDetection from '@ckeditor5-utils/src/utils/featuredetection/regexp';
console.log(
'RegExp group is supported:',
regExpFeatureDetection.isUnicodePropertySupported()
);
This would allow us to nicely organize stuff in future.
And it's important for us to use RegExp with p consistently, as this is how the type is named in JS.
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.
RegExp with p consistently, a
typo, sorry :P
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.
src/featuredetection.js
Outdated
* @protected | ||
* @namespace | ||
*/ | ||
export default { |
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.
@mlewand to clarify:
import featureDetection from '@ckeditor5-utils/src/utils/featuredetection';
console.log(
'Regex group is supported:',
featureDetection.regex.isUnicodePropertySupported()
);
ps.: Shouldn't it be isUnicodePropertyEscapesSupported()
? 😆
src/featuredetection.js
Outdated
* @protected | ||
* @namespace | ||
*/ | ||
export default { |
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.
@msamsel please create also a PR in mention repo to use this util instaed own feature detection.
src/featuredetection.js
Outdated
export default { | ||
/** | ||
* Indicates whether the current browser supports ES2018 Unicode properties like `\p{P}` or `\p{L}`. | ||
* |
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.
Since I'm always searching for this. Please add a link to:
https://www.unicode.org/reports/tr44/#GC_Values_Table
so we get a link to those categories :)
@jodator usually in the documentation you can find the name "Unicode property" or just "property". The word "escape" seems to be strictly related to the existence of |
ef16b13
to
e916e1d
Compare
Also let's try to keep the names simple if possible 🙂 |
OMG next time I'll use |
Those could be really useful, as it is really hard to notice the sarcasm in the written text, where you expect the feedback ;) |
src/featuredetection/regexp.js
Outdated
// See https://github.com/ckeditor/ckeditor5-mention/issues/44#issuecomment-487002174. | ||
|
||
try { | ||
isSupported = 'ć'.search( new RegExp( '[\\p{L}]', 'u' ) ) === 0; |
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.
Why new RegExp
and not a literal?
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.
@Reinmar I'm investigating this - ESLint is complaining about this.
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.
Yeah, definitely there should be comments as this not clear in such cases :(
Tl;dr; ESLint doesn't recognize it.
Simillar discussion is here:
ckeditor/ckeditor5-word-count#10 (comment)
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 mean that we have to bumpt the ESLint rules used in CKEditor to be able to use /\p{L}/u
AFAICS.
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.
OH we've already published the changes and after updating dependencies it works :) So our ESLint config works with this now 🎉
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.
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.
There's an upcoming fix for that. Right now we cannot use them :(
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.
OK, fair enough. Please leave a comment in the code with an explanation.
src/featuredetection/regexp.js
Outdated
*/ | ||
|
||
/** | ||
* @module utils/featuredetection/regexp |
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.
Does it have to be entire namespace for regexp? Do we expect to have many of those?
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 that moving this to env.js
will be cleaner.
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.
Something like this?
const env = {
isMac: isMac( userAgent ),
// ...
features: {
regexp: {
isUnicodePropertySupported: isUnicodePropertySupported()
}
}
// or just
features: {
isRegExpUnicodePropertySupported: isRegExpUnicodePropertySupported()
}
}
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.
Does it have to be entire namespace for regexp? Do we expect to have many of those?
@Reinmar There are several features that are about to come (not widely supported) into JS RegExp:
- s (a.k.a. dotAll) flag
- named groups
- Unicode property escapes (that's in this PR)
Also ES2018 finally added lookahead/lookbehind, luckily both seems to be implemented by all major browser vendors. 🎉
Note that future ES revisions might also expose more RegExp features to further reduce the gap.
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.
There are several features that are about to come (not widely supported) into JS RegExp: (..)
I wonder how many of them are we going to use and will have to detect.
For me having feature detection inside env.js
seems to be a good solution. The first example is more appealing to me.
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.
@mlewand What would be the problem if we had like 5 regexp-oriented properties in env
?
We can create new namespaces for every new distinctive thing that may become "plural" with time. But many of them don't become plural and majority doesn't exceed 3 options. If you don't see technical problems for keeping that in env
, I'd keep that in env
. They will be easier to find there.
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.
// or just
features: {
isRegExpUnicodePropertySupported: isRegExpUnicodePropertySupported()
}
sounds best to me – it's the most flexible option.
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.
See comments.
@msamsel The one thing remains - move the feature detection to the env as features: {
isRegExpUnicodePropertySupported: isRegExpUnicodePropertySupported()
}
|
@jodator I've moved feature detection to env. |
This looks a little bit inconsistent for me, sorry for bumping late into the established discussion. Shouldn't it be like the following? AFAIK we don't prefix boolean props with features: {
regExpUnicodePropertySupported: isRegExpUnicodePropertySupported()
} |
@ma2ciek dunno, it looks like we do :P Line 26 in 21f1c4e
Line 34 in 21f1c4e
Line 42 in 21f1c4e
from other files: So we actually prefix boolean values with is/has/are :) |
Wow. I was pretty sure we do the opposite. So let's be consistent. PS OTOH I don't like this convention because you end up not knowing if the property has a call signature or not. |
I'm merging this one as other PRs might be closed later on and this will be already used by Mention feature. |
Suggested merge commit message (convention)
Feature: Add feature detection of unicode properties support.
Additional information