param expect String . random = function ( expect = 16 ) : string { let str = Math . random ( ) . toString ( 36 ) . substring ( 2 ) ; while ( str . length < expect ) { str += Math . random ( ) . toString ( 36 ) . substring ( 2 ) ; } return str . substring ( 0 , expect ) ; } ; /**
 * 判断字符串是否为空或者空字符串
 */ String . prototype . isNullOrEmpty = function ( ) : boolean { return this === undefined || this === null || typeof this === 'undefined' || this === '' ? true : this . trim ( ) . length === 0 ; } ; /**
 * 使用正则表达式验证当前字符串
 */ String . prototype . test = function ( reg ) : boolean { try { return reg . test ( this . valueOf ( ) ) ; } catch ( error ) { throw error ; } } ; /**
 * 是否是Url
 */ String . prototype . isUrl = function ( ) : boolean { return this . test ( /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/ ) ; } ; param len returns String . prototype . segment = function ( len ) : Array < string > { if ( this . isNullOrEmpty ( ) || len <= 0 ) return [ ] ; let array = [ ] ; let length = this . length ; for ( let i = 0 ; i < length / len ; i ++ ) { if ( ( i + 1 ) * len > length ) array . push ( this . substring ( i * len , length ) ) ; else array . push ( this . substring ( i * len , ( i + 1 ) * len ) ) ; } return array ; } ; param radix String . prototype . toNumber = function ( radix = 10 ) : number { try { return parseInt ( this . valueOf ( ) , radix ) ; } catch ( error ) { throw error ; } } ;