File tree Expand file tree Collapse file tree 4 files changed +49
-6
lines changed Expand file tree Collapse file tree 4 files changed +49
-6
lines changed Original file line number Diff line number Diff 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 () );
Original file line number Diff line number Diff 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>';
Original file line number Diff line number Diff 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 *
Original file line number Diff line number Diff line change 11import { PhoneMatcher } from "../../src/matcher/phone-matcher" ;
22import { AnchorTagBuilder } from "../../src/anchor-tag-builder" ;
33import { MatchChecker } from "../match/match-checker" ;
4+ import { PhoneMatch } from "../../src" ;
45
56describe ( "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} ) ;
You can’t perform that action at this time.
0 commit comments