Skip to content

Commit 1b43593

Browse files
committed
Re-add getPhoneNumber() method to PhoneMatch. This method name is a bit more clear than getNumber()
1 parent c65fcf6 commit 1b43593

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,9 @@ var linkedText = Autolinker.link( input, {
332332
}
333333

334334
case 'phone' :
335-
console.log( "Phone Number: ", match.getNumber() );
335+
console.log( "Phone Number: ", match.getPhoneNumber() );
336336

337-
return '<a href="http://newplace.to.link.phone.numbers.to/">' + match.getNumber() + '</a>';
337+
return '<a href="http://newplace.to.link.phone.numbers.to/">' + match.getPhoneNumber() + '</a>';
338338

339339
case 'mention' :
340340
console.log( "Mention: ", match.getMention() );

src/autolinker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ import { MentionMatcher } from "./matcher/mention-matcher";
9191
* }
9292
*
9393
* case 'phone' :
94-
* var phoneNumber = match.getNumber();
94+
* var phoneNumber = match.getPhoneNumber();
9595
* console.log( phoneNumber );
9696
*
9797
* return '<a href="http://newplace.to.link.phone.numbers.to/">' + phoneNumber + '</a>';

src/match/phone-match.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,31 @@ export class PhoneMatch extends Match {
5858

5959

6060
/**
61-
* Returns the phone number that was matched as a string, without any
62-
* delimiter characters.
61+
* Returns the phone number that was matched as a string, without any
62+
* delimiter characters.
6363
*
6464
* Note: This is a string to allow for prefixed 0's.
6565
*
6666
* @return {String}
6767
*/
68-
getNumber() {
68+
getPhoneNumber() {
6969
return this.number;
7070
}
7171

7272

73+
/**
74+
* Alias of {@link #getPhoneNumber}, returns the phone number that was
75+
* matched as a string, without any delimiter characters.
76+
*
77+
* Note: This is a string to allow for prefixed 0's.
78+
*
79+
* @return {String}
80+
*/
81+
getNumber() {
82+
return this.getPhoneNumber();
83+
}
84+
85+
7386
/**
7487
* Returns the anchor href that should be generated for the match.
7588
*

tests/matcher/phone-matcher.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { PhoneMatcher } from "../../src/matcher/phone-matcher";
22
import { AnchorTagBuilder } from "../../src/anchor-tag-builder";
33
import { MatchChecker } from "../match/match-checker";
4+
import { PhoneMatch } from "../../src";
45

56
describe( "Autolinker.matcher.Phone", function() {
67
let matcher: PhoneMatcher;
@@ -64,4 +65,33 @@ describe( "Autolinker.matcher.Phone", function() {
6465
} );
6566

6667

68+
describe( 'getPhoneNumber()', function() {
69+
70+
it( `should should return the matched phone number without any
71+
formatting`,
72+
() => {
73+
let matches = matcher.parseMatches( 'Talk to (123) 456-7890' );
74+
75+
expect( matches.length ).toBe( 1 );
76+
expect( matches[ 0 ] ).toEqual( jasmine.any( PhoneMatch ) );
77+
expect( ( matches[ 0 ] as PhoneMatch ).getPhoneNumber() ).toBe( '1234567890' );
78+
} );
79+
80+
} );
81+
82+
83+
describe( 'getNumber()', function() {
84+
85+
it( `as an alias of getPhoneNumber(), should return the matched phone
86+
number, without any formatting`,
87+
() => {
88+
let matches = matcher.parseMatches( 'Talk to (123) 456-7890' );
89+
90+
expect( matches.length ).toBe( 1 );
91+
expect( matches[ 0 ] ).toEqual( jasmine.any( PhoneMatch ) );
92+
expect( ( matches[ 0 ] as PhoneMatch ).getNumber() ).toBe( '1234567890' );
93+
} );
94+
95+
} );
96+
6797
} );

0 commit comments

Comments
 (0)