File tree Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ export default function isLength(str, options) {
1414 max = arguments [ 2 ] ;
1515 }
1616
17- const presentationSequences = str . match ( / ( \uFE0F | \uFE0E ) / g) || [ ] ;
17+ const presentationSequences = str . match ( / [ ^ \uFE0F \uFE0E ] [ \uFE0F \uFE0E ] / g) || [ ] ;
1818 const surrogatePairs = str . match ( / [ \uD800 - \uDBFF ] [ \uDC00 - \uDFFF ] / g) || [ ] ;
1919 const len = str . length - presentationSequences . length - surrogatePairs . length ;
2020 const isInsideRange = len >= min && ( typeof max === 'undefined' || len <= max ) ;
Original file line number Diff line number Diff line change 1+ import test from '../testFunctions' ;
2+
3+ describe ( 'isLength' , ( ) => {
4+ it ( 'should return false for a string with length greater than the max' , ( ) => {
5+ test ( {
6+ validator : 'isLength' ,
7+ args : [ { max : 3 } ] ,
8+ invalid : [ 'test' ] ,
9+ } ) ;
10+ } ) ;
11+
12+ it ( 'should return true for a string with length equal to the max' , ( ) => {
13+ test ( {
14+ validator : 'isLength' ,
15+ args : [ { max : 4 } ] ,
16+ valid : [ 'test' ] ,
17+ } ) ;
18+ } ) ;
19+
20+ it ( 'should correctly calculate the length of a string with presentation sequences' , ( ) => {
21+ test ( {
22+ validator : 'isLength' ,
23+ args : [ { max : 4 } ] ,
24+ valid : [ 'test\uFE0F' ] ,
25+ } ) ;
26+
27+ test ( {
28+ validator : 'isLength' ,
29+ args : [ { min : 5 , max : 5 } ] ,
30+ valid : [ 'test\uFE0F\uFE0F' ] ,
31+ } ) ;
32+
33+ test ( {
34+ validator : 'isLength' ,
35+ args : [ { min : 5 , max : 5 } ] ,
36+ valid : [ '\uFE0Ftest' ] ,
37+ } ) ;
38+
39+ test ( {
40+ validator : 'isLength' ,
41+ args : [ { min : 9 , max : 9 } ] ,
42+ valid : [ 'test\uFE0F\uFE0F\uFE0F\uFE0F\uFE0F\uFE0F' ] ,
43+ } ) ;
44+ } ) ;
45+ } ) ;
You can’t perform that action at this time.
0 commit comments