1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.PhoneMatcher = void 0;
|
4 | var tslib_1 = require("tslib");
|
5 | var matcher_1 = require("./matcher");
|
6 | var phone_match_1 = require("../match/phone-match");
|
7 | var regex_lib_1 = require("../regex-lib");
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | var mostPhoneNumbers = /(?:(?:(?:(\+)?\d{1,3}[-\040.]?)?\(?\d{3}\)?[-\040.]?\d{3}[-\040.]?\d{4})|(?:(\+)(?:9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)[-\040.]?(?:\d[-\040.]?){6,12}\d+))([,;]+[0-9]+#?)*/;
|
16 |
|
17 | var japanesePhoneRe = /(0([1-9]{1}-?[1-9]\d{3}|[1-9]{2}-?\d{3}|[1-9]{2}\d{1}-?\d{2}|[1-9]{2}\d{2}-?\d{1})-?\d{4}|0[789]0-?\d{4}-?\d{4}|050-?\d{4}-?\d{4})/;
|
18 |
|
19 | var phoneMatcherRegex = new RegExp(mostPhoneNumbers.source + "|" + japanesePhoneRe.source, 'g');
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | var PhoneMatcher = (function (_super) {
|
30 | tslib_1.__extends(PhoneMatcher, _super);
|
31 | function PhoneMatcher() {
|
32 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
33 | |
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | _this.matcherRegex = phoneMatcherRegex;
|
52 | return _this;
|
53 | }
|
54 | |
55 |
|
56 |
|
57 | PhoneMatcher.prototype.parseMatches = function (text) {
|
58 | var matcherRegex = this.matcherRegex, tagBuilder = this.tagBuilder, matches = [], match;
|
59 | while ((match = matcherRegex.exec(text)) !== null) {
|
60 |
|
61 | var matchedText = match[0], cleanNumber = matchedText.replace(/[^0-9,;#]/g, ''),
|
62 | plusSign = !!(match[1] || match[2]),
|
63 | before = match.index == 0 ? '' : text.substr(match.index - 1, 1), after = text.substr(match.index + matchedText.length, 1), contextClear = !before.match(/\d/) && !after.match(/\d/);
|
64 | if (this.testMatch(match[3]) && this.testMatch(matchedText) && contextClear) {
|
65 | matches.push(new phone_match_1.PhoneMatch({
|
66 | tagBuilder: tagBuilder,
|
67 | matchedText: matchedText,
|
68 | offset: match.index,
|
69 | number: cleanNumber,
|
70 | plusSign: plusSign
|
71 | }));
|
72 | }
|
73 | }
|
74 | return matches;
|
75 | };
|
76 | PhoneMatcher.prototype.testMatch = function (text) {
|
77 | return regex_lib_1.nonDigitRe.test(text);
|
78 | };
|
79 | return PhoneMatcher;
|
80 | }(matcher_1.Matcher));
|
81 | exports.PhoneMatcher = PhoneMatcher;
|
82 |
|
83 |
|