All files TextUtil.ts

100% Statements 5/5
100% Branches 4/4
100% Functions 1/1
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27                              11x   8x   8x 8x   3x        
/**
 * this util module is about to verify, fix strings like phone, QR code and so on
 * @module angle-util/textUtil
 */
export default {
  /**
   * 修正电话号码格式
   * @author youngbeen
   * @param {number|string} phone - 待修正的手机号
   * @return {string} 修正后的号码
   * @example
   * let phone = '12345ab384eb(2'
   * textUtil.fixPhoneStr(phone)     // '123453842'
   */
  fixPhoneStr (phone: number | string): string {
    if (phone || phone === 0) {
      // change phone into string type at first
      phone = phone.toString()
      // remove all invalid characters in phone
      phone = phone.replace(/[^0-9,]/g, '')
      return phone
    } else {
      return ''
    }
  }
}