Skip to content

Commit

Permalink
Unicode: add 0xfe0f codepoint as a zero-width
Browse files Browse the repository at this point in the history
  • Loading branch information
cronvel committed Aug 3, 2022
1 parent a386f15 commit 5264f09
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

v0.17.3
-------

Unicode: add 0xfe0f codepoint as a zero-width


v0.17.2
-------

Expand Down
13 changes: 11 additions & 2 deletions browser/string-kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3911,6 +3911,13 @@ unicode.codePointWidth = code => {
return 2 ;
}

if (
unicode.isEmojiModifierCodePoint( code ) ||
unicode.isZeroWidthDiacriticCodePoint( code )
) {
return 0 ;
}

return 1 ;
} ;

Expand Down Expand Up @@ -3970,9 +3977,11 @@ unicode.isEmojiCodePoint = code =>
( 0x1f300 <= code && code <= 0x1f3fa ) ||
( 0x1f400 <= code && code <= 0x1faff ) ;

// Emoji modifier (Fitzpatrick): https://en.wikipedia.org/wiki/Miscellaneous_Symbols_and_Pictographs#Emoji_modifiers
// Emoji modifier
unicode.isEmojiModifier = char => unicode.isEmojiModifierCodePoint( char.codePointAt( 0 ) ) ;
unicode.isEmojiModifierCodePoint = code => 0x1f3fb <= code && code <= 0x1f3ff ;
unicode.isEmojiModifierCodePoint = code =>
( 0x1f3fb <= code && code <= 0x1f3ff ) || // (Fitzpatrick): https://en.wikipedia.org/wiki/Miscellaneous_Symbols_and_Pictographs#Emoji_modifiers
code === 0xfe0f ; // VARIATION SELECTOR-16 [VS16] {emoji variation selector}


},{"./unicode-emoji-width-ranges.json":15}],17:[function(require,module,exports){
Expand Down
2 changes: 1 addition & 1 deletion browser/string-kit.min.js

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions lib/unicode.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,13 @@ unicode.codePointWidth = code => {
return 2 ;
}

if (
unicode.isEmojiModifierCodePoint( code ) ||
unicode.isZeroWidthDiacriticCodePoint( code )
) {
return 0 ;
}

return 1 ;
} ;

Expand Down Expand Up @@ -331,7 +338,9 @@ unicode.isEmojiCodePoint = code =>
( 0x1f300 <= code && code <= 0x1f3fa ) ||
( 0x1f400 <= code && code <= 0x1faff ) ;

// Emoji modifier (Fitzpatrick): https://en.wikipedia.org/wiki/Miscellaneous_Symbols_and_Pictographs#Emoji_modifiers
// Emoji modifier
unicode.isEmojiModifier = char => unicode.isEmojiModifierCodePoint( char.codePointAt( 0 ) ) ;
unicode.isEmojiModifierCodePoint = code => 0x1f3fb <= code && code <= 0x1f3ff ;
unicode.isEmojiModifierCodePoint = code =>
( 0x1f3fb <= code && code <= 0x1f3ff ) || // (Fitzpatrick): https://en.wikipedia.org/wiki/Miscellaneous_Symbols_and_Pictographs#Emoji_modifiers
code === 0xfe0f ; // VARIATION SELECTOR-16 [VS16] {emoji variation selector}

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "string-kit",
"version": "0.17.2",
"version": "0.17.3",
"engines": {
"node": ">=14.15.0"
},
Expand Down
4 changes: 4 additions & 0 deletions test/unicode-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ describe( "Unicode" , () => {
expect( string.unicode.width( 'aé@à' ) ).to.be( 4 ) ;
expect( string.unicode.width( 'aé@à' ) ).to.be( 5 ) ;
expect( string.unicode.width( 'aé汉字à' ) ).to.be( 7 ) ;

expect( string.unicode.width( '😀️' ) ).to.be( 2 ) ;
expect( string.unicode.width( '♥' ) ).to.be( 1 ) ;
expect( string.unicode.width( '♥️' ) ).to.be( 1 ) ;
} ) ;

it( ".charWidth() should the width of a single character" , () => {
Expand Down

0 comments on commit 5264f09

Please sign in to comment.