File tree Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change 1212- [ core] ref: Move SDKInformation integration into core prepareEvent method
1313- [ core] ref: Move debug initialization as the first step
1414- [ node] fix: Make handlers types compatibile with Express
15+ - [ utils] fix: Dont break when non-string is passed to truncate
1516
1617## 4.0.4
1718
Original file line number Diff line number Diff line change 1+ import { isString } from './is' ;
2+
13/**
24 * Encodes given object into url-friendly format
35 *
68 * @returns string Encoded
79 */
810
9- export function truncate ( str : string , max : number ) : string {
10- if ( max === 0 ) {
11+ export function truncate ( str : string , max : number = 0 ) : string {
12+ if ( max === 0 || ! isString ( str ) ) {
1113 return str ;
1214 }
1315 return str . length <= max ? str : `${ str . substr ( 0 , max ) } \u2026` ;
Original file line number Diff line number Diff line change @@ -7,4 +7,19 @@ describe('truncate()', () => {
77 expect ( truncate ( 'lol' , 3 ) ) . toEqual ( 'lol' ) ;
88 expect ( truncate ( new Array ( 1000 ) . join ( 'f' ) , 0 ) ) . toEqual ( new Array ( 1000 ) . join ( 'f' ) ) ;
99 } ) ;
10+
11+ test ( 'it instantly returns input when non-string is passed' , ( ) => {
12+ // @ts -ignore
13+ expect ( truncate ( 2 ) ) . toEqual ( 2 ) ;
14+ // @ts -ignore
15+ expect ( truncate ( undefined , 123 ) ) . toEqual ( undefined ) ;
16+ // @ts -ignore
17+ expect ( truncate ( null ) ) . toEqual ( null ) ;
18+ const obj = { } ;
19+ // @ts -ignore
20+ expect ( truncate ( obj , '42' ) ) . toEqual ( obj ) ;
21+ const arr : any [ ] = [ ] ;
22+ // @ts -ignore
23+ expect ( truncate ( arr ) ) . toEqual ( arr ) ;
24+ } ) ;
1025} ) ;
You can’t perform that action at this time.
0 commit comments