Sha256: 84f4a616483b4aa7f6773a5658903f4f3df95e0846b82d16e54b023008d444ff

Contents?: true

Size: 443 Bytes

Versions: 155

Compression:

Stored size: 443 Bytes

Contents

export default class PhoneNumber {

  constructor(number) {
    this.rawNumber = number;
  }

  number() {
    if(/[a-zA-Z]/.test(this.rawNumber)) {
      return null;
    }

    return this._cleanedNumber();
  }

  _cleanedNumber() {
    let num = this.rawNumber.replace(/\D/g,'');

    if (num.length === 10) {
      return num;
    }

    if (num.length === 11 && num[0] === '1') {
      return num.substr(1);
    }

    return null;
  }
}

Version data entries

155 entries across 155 versions & 1 rubygems

Version Path
trackler-2.1.0.15 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.14 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.13 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.12 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.11 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.10 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.9 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.8 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.7 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.6 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.5 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.4 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.3 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.2 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.1 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.1.0.0 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.0.8.55 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.0.8.54 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.0.8.53 tracks/ecmascript/exercises/phone-number/example.js
trackler-2.0.8.52 tracks/ecmascript/exercises/phone-number/example.js