File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import {
22 getUnicodeNonBmpRegExp ,
33 getSupplementaryPrivateUseRegExp ,
4- getPunctuationRegExp
4+ getPunctuationRegExp ,
5+ getCategoryFormatRegExp
56} from './unicode' ;
67import emojiRegexText from 'emoji-regex' ;
78
@@ -20,19 +21,22 @@ import emojiRegexText from 'emoji-regex';
2021 */
2122function hasUnicode ( str , options ) {
2223 const { emoji, nonBmp, punctuations } = options ;
24+ let value = false ;
25+
2326 if ( emoji ) {
24- return emojiRegexText ( ) . test ( str ) ;
27+ value ||= emojiRegexText ( ) . test ( str ) ;
2528 }
2629 if ( nonBmp ) {
27- return (
30+ value ||=
2831 getUnicodeNonBmpRegExp ( ) . test ( str ) ||
29- getSupplementaryPrivateUseRegExp ( ) . test ( str )
30- ) ;
32+ getSupplementaryPrivateUseRegExp ( ) . test ( str ) ||
33+ getCategoryFormatRegExp ( ) . test ( str ) ;
3134 }
3235 if ( punctuations ) {
33- return getPunctuationRegExp ( ) . test ( str ) ;
36+ value ||= getPunctuationRegExp ( ) . test ( str ) ;
3437 }
35- return false ;
38+
39+ return value ;
3640}
3741
3842export default hasUnicode ;
Original file line number Diff line number Diff line change 11import {
22 getUnicodeNonBmpRegExp ,
33 getSupplementaryPrivateUseRegExp ,
4- getPunctuationRegExp
4+ getPunctuationRegExp ,
5+ getCategoryFormatRegExp
56} from './unicode.js' ;
67import emojiRegexText from 'emoji-regex' ;
78
@@ -25,8 +26,10 @@ function removeUnicode(str, options) {
2526 str = str . replace ( emojiRegexText ( ) , '' ) ;
2627 }
2728 if ( nonBmp ) {
28- str = str . replace ( getUnicodeNonBmpRegExp ( ) , '' ) ;
29- str = str . replace ( getSupplementaryPrivateUseRegExp ( ) , '' ) ;
29+ str = str
30+ . replace ( getUnicodeNonBmpRegExp ( ) , '' )
31+ . replace ( getSupplementaryPrivateUseRegExp ( ) , '' )
32+ . replace ( getCategoryFormatRegExp ( ) , '' ) ;
3033 }
3134 if ( punctuations ) {
3235 str = str . replace ( getPunctuationRegExp ( ) , '' ) ;
Original file line number Diff line number Diff line change @@ -83,3 +83,15 @@ export function getSupplementaryPrivateUseRegExp() {
8383 // ┏━━━━━━┻━━━━━━┓┏━━━━━━┻━━━━━━┓
8484 return / [ \uDB80 - \uDBBF ] [ \uDC00 - \uDFFF ] / g;
8585}
86+
87+ /**
88+ * Get regular expression for unicode format category.
89+ * When we drop IE11 we can instead use unicode character escape `/p{Cf}/gu`
90+ * Reference:
91+ * - https://www.compart.com/en/unicode/category/Cf
92+ *
93+ * @returns {RegExp }
94+ */
95+ export function getCategoryFormatRegExp ( ) {
96+ return / [ \xAD \u0600 - \u0605 \u061C \u06DD \u070F \u08E2 \u180E \u200B - \u200F \u202A - \u202E \u2060 - \u2064 \u2066 - \u206F \uFEFF \uFFF9 - \uFFFB ] | \uD804 [ \uDCBD \uDCCD ] | \uD80D [ \uDC30 - \uDC38 ] | \uD82F [ \uDCA0 - \uDCA3 ] | \uD834 [ \uDD73 - \uDD7A ] | \uDB40 [ \uDC01 \uDC20 - \uDC7F ] / g;
97+ }
You can’t perform that action at this time.
0 commit comments