11"use strict" ;
2- var __importDefault = ( this && this . __importDefault ) || function ( mod ) {
3- return ( mod && mod . __esModule ) ? mod : { "default" : mod } ;
4- } ;
52Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
6- exports . XmlArea = exports . UrlArea = exports . TextArea = void 0 ;
7- const service_1 = __importDefault ( require ( "./service" ) ) ;
8- const OptionalUrlPatternBuilder_1 = require ( "./pattern/OptionalUrlPatternBuilder" ) ;
9- const DomainPatterns_1 = require ( "./pattern/DomainPatterns" ) ;
10- const CommentPatterns_1 = require ( "./pattern/CommentPatterns" ) ;
11- const EmailPatternBuilder_1 = require ( "./pattern/EmailPatternBuilder" ) ;
12- const BasePatterns_1 = require ( "./pattern/BasePatterns" ) ;
13- /*
14- * All Public
15- * */
16- const TextArea = {
17- /**
18- * @brief
19- * Distill all urls in texts
20- * @author Andrew Kang
21- * @param textStr string required
22- * @param noProtocolJsn object
23- * default : {
24- 'ipV4' : false,
25- 'ipV6' : false,
26- 'localhost' : false,
27- 'intranet' : false
28- }
29-
30- * @return array
31- */
32- extractAllUrls ( textStr , noProtocolJsn = {
33- ipV4 : false ,
34- ipV6 : false ,
35- localhost : false ,
36- intranet : false
37- } ) {
38- OptionalUrlPatternBuilder_1 . OptionalUrlPatternBuilder . setUrlPattern ( noProtocolJsn ) ;
39- return service_1 . default . Text . extractAllPureUrls ( textStr ) ;
40- } ,
41- /**
42- * @brief
43- * Distill all emails from normal text
44- * @author Andrew Kang
45- * @param textStr string required
46- * @param prefixSanitizer boolean (default : true)
47- * @return array
48- */
49- extractAllEmails ( textStr , prefixSanitizer = true ) {
50- return service_1 . default . Text . extractAllPureEmails ( textStr , prefixSanitizer ) ;
51- } ,
52- /**
53- *
54- * [!!Important] This functions well, but should be refactored every business logic is here.
55- *
56- * @brief
57- * Distill uris with certain names from normal text
58- * @author Andrew Kang
59- * @param textStr string required
60- * @param uris array required
61- * for example, [['a','b'], ['c','d']]
62- * If you use {number}, this means 'only number' ex) [['a','{number}'], ['c','d']]
63- * @param endBoundary boolean (default : false)
64- * @return array
65- */
66- extractCertainUris ( textStr , uris , endBoundary = false ) {
67- if ( ! ( textStr && typeof textStr === 'string' ) ) {
68- throw new Error ( 'the variable textStr must be a string type and not be null.' ) ;
69- }
70- let obj = service_1 . default . Text . extractCertainPureUris ( textStr , uris , endBoundary ) ;
71- let obj2 = service_1 . default . Text . extractAllPureUrls ( textStr ) ;
72- //console.log('obj : ' + JSON.stringify(obj));
73- let obj_final = [ ] ;
74- for ( let a = 0 ; a < obj . length ; a ++ ) {
75- let obj_part = {
76- uriDetected : undefined ,
77- inWhatUrl : undefined ,
78- } ;
79- //let matchedUrlFound = false;
80- for ( let b = 0 ; b < obj2 . length ; b ++ ) {
81- if ( ( obj [ a ] . index . start > obj2 [ b ] . index . start && obj [ a ] . index . start < obj2 [ b ] . index . end )
82- &&
83- ( obj [ a ] . index . end > obj2 [ b ] . index . start && obj [ a ] . index . end <= obj2 [ b ] . index . end ) ) {
84- // Here, the uri detected is inside its url
85- // false positives like the example '//google.com/abc/def?a=5&b=7' can be detected in 'Service.Text.extractCertainPureUris'
86- let sanitizedUrl = obj [ a ] [ 'value' ] [ 'url' ] || "" ;
87- let rx = new RegExp ( '^(\\/\\/[^/]*|\\/[^\\s]+\\.' + DomainPatterns_1 . DomainPatterns . allRootDomains + ')' , 'gi' ) ;
88- let matches = [ ] ;
89- let match ;
90- while ( ( match = rx . exec ( obj [ a ] . value . url || "" ) ) !== null ) {
91- if ( match [ 1 ] ) {
92- sanitizedUrl = sanitizedUrl . replace ( rx , '' ) ;
93- //console.log(match[1]);
94- obj [ a ] . value . url = sanitizedUrl ;
95- obj [ a ] . index . start += match [ 1 ] . length ;
96- obj [ a ] . value . onlyUriWithParams = obj [ a ] . value . url ;
97- obj [ a ] . value . onlyUri = ( obj [ a ] . value . url || "" ) . replace ( / \? [ ^ / ] * $ / gi, '' ) ;
98- }
99- }
100- obj_part . inWhatUrl = obj2 [ b ] ;
101- }
102- }
103- obj_part . uriDetected = obj [ a ] ;
104- obj_final . push ( obj_part ) ;
105- }
106- return obj_final ;
107- } ,
108- } ;
109- exports . TextArea = TextArea ;
110- const UrlArea = {
111- /**
112- * @brief
113- * Assort an url into each type.
114- * @author Andrew Kang
115- * @param url string required
116- * @return array ({'url' : '', 'protocol' : '', 'onlyDomain' : '', 'onlyUriWithParams' : '', 'type' : ''})
117- */
118- parseUrl ( url ) {
119- return service_1 . default . Url . parseUrl ( url ) ;
120- } ,
121- /**
122- * @brief
123- * Assort an url into each type.
124- * @author Andrew Kang
125- * @param url string required
126- * @return array ({'url' : '', 'protocol' : '', 'onlyDomain' : '', 'onlyUriWithParams' : '', 'type' : ''})
127- */
128- normalizeUrl ( url ) {
129- return service_1 . default . Url . normalizeUrl ( url ) ;
130- }
131- } ;
132- exports . UrlArea = UrlArea ;
133- const XmlArea = {
3+ exports . XmlAreaApi = void 0 ;
4+ const SafeConditionalUrlPatternBuilder_1 = require ( "../pattern/SafeConditionalUrlPatternBuilder" ) ;
5+ const CommentPatterns_1 = require ( "../pattern/CommentPatterns" ) ;
6+ const EmailPatternBuilder_1 = require ( "../pattern/EmailPatternBuilder" ) ;
7+ const BasePatterns_1 = require ( "../pattern/BasePatterns" ) ;
8+ const XmlAreaService_1 = require ( "../service/XmlAreaService" ) ;
9+ const UrlAreaService_1 = require ( "../service/UrlAreaService" ) ;
10+ exports . XmlAreaApi = {
13411 /**
13512 *
13613 * @brief
@@ -144,8 +21,8 @@ const XmlArea = {
14421 if ( ! ( xmlStr && typeof xmlStr === 'string' ) ) {
14522 throw new Error ( 'the variable xmlStr must be a string type and not be null.' ) ;
14623 }
147- const cmtMatches = service_1 . default . Xml . extractAllPureComments ( xmlStr ) ;
148- let matches = service_1 . default . Xml . extractAllPureElements ( xmlStr ) ;
24+ const cmtMatches = XmlAreaService_1 . XmlAreaService . extractAllPureComments ( xmlStr ) ;
25+ let matches = XmlAreaService_1 . XmlAreaService . extractAllPureElements ( xmlStr ) ;
14926 for ( let a = 0 ; a < matches . length ; a ++ ) {
15027 for ( let i = 0 ; i < cmtMatches . length ; i ++ ) {
15128 if ( cmtMatches [ i ] . startIndex < matches [ a ] . startIndex && matches [ a ] . lastIndex < cmtMatches [ i ] . lastIndex ) {
@@ -170,8 +47,8 @@ const XmlArea = {
17047 if ( ! ( xmlStr && typeof xmlStr === 'string' ) ) {
17148 throw new Error ( 'the variable xmlStr must be a string type and not be null.' ) ;
17249 }
173- let el_matches = service_1 . default . Xml . extractAllPureElements ( xmlStr ) ;
174- let matches = service_1 . default . Xml . extractAllPureComments ( xmlStr ) ;
50+ let el_matches = XmlAreaService_1 . XmlAreaService . extractAllPureElements ( xmlStr ) ;
51+ let matches = XmlAreaService_1 . XmlAreaService . extractAllPureComments ( xmlStr ) ;
17552 el_matches = el_matches . reverse ( ) ;
17653 matches = matches . reverse ( ) ;
17754 matches . forEach ( function ( val , idx ) {
@@ -192,25 +69,25 @@ const XmlArea = {
19269 * @param skipXml boolean (default : false)
19370 * @param noProtocolJsn object
19471 * default : {
195- 'ipV4' : false,
196- 'ipV6' : false,
197- 'localhost' : false,
198- 'intranet' : false
199- }
72+ 'ipV4' : false,
73+ 'ipV6' : false,
74+ 'localhost' : false,
75+ 'intranet' : false
76+ }
20077 * @return array
20178 */
20279 extractAllUrls ( xmlStr , skipXml = false , noProtocolJsn ) {
20380 if ( ! ( xmlStr && typeof xmlStr === 'string' ) ) {
20481 throw new Error ( 'the variable xmlStr must be a string type and not be null.' ) ;
20582 }
206- OptionalUrlPatternBuilder_1 . OptionalUrlPatternBuilder . setUrlPattern ( noProtocolJsn ) ;
83+ SafeConditionalUrlPatternBuilder_1 . SafeConditionalUrlPatternBuilder . setUrlPattern ( noProtocolJsn ) ;
20784 let obj = [ ] ;
20885 if ( ! skipXml ) {
209- let cmtMatches = XmlArea . extractAllComments ( xmlStr ) ;
210- let elMatches = XmlArea . extractAllElements ( xmlStr ) ;
86+ let cmtMatches = exports . XmlAreaApi . extractAllComments ( xmlStr ) ;
87+ let elMatches = exports . XmlAreaApi . extractAllElements ( xmlStr ) ;
21188 /* 1. comment */
21289 for ( let a = 0 ; a < cmtMatches . length ; a ++ ) {
213- let rx = new RegExp ( OptionalUrlPatternBuilder_1 . OptionalUrlPatternBuilder . getUrl , 'gi' ) ;
90+ let rx = new RegExp ( SafeConditionalUrlPatternBuilder_1 . SafeConditionalUrlPatternBuilder . getUrl , 'gi' ) ;
21491 let matches = [ ] ;
21592 let match ;
21693 while ( ( match = rx . exec ( cmtMatches [ a ] . value ) ) !== null ) {
@@ -223,14 +100,14 @@ const XmlArea = {
223100 //mod_val = mod_val.replace(/[\n\r\t\s]/g, '');
224101 //mod_val = mod_val.trim();
225102 obj . push ( {
226- 'value' : service_1 . default . Url . parseUrl ( mod_val ) ,
103+ 'value' : UrlAreaService_1 . UrlAreaService . parseUrl ( mod_val ) ,
227104 'area' : 'comment'
228105 } ) ;
229106 }
230107 }
231108 /* 2. element */
232109 for ( let a = 0 ; a < elMatches . length ; a ++ ) {
233- let rx = new RegExp ( OptionalUrlPatternBuilder_1 . OptionalUrlPatternBuilder . getUrl , 'gi' ) ;
110+ let rx = new RegExp ( SafeConditionalUrlPatternBuilder_1 . SafeConditionalUrlPatternBuilder . getUrl , 'gi' ) ;
234111 let matches = [ ] ;
235112 let match ;
236113 while ( ( match = rx . exec ( elMatches [ a ] . value ) ) !== null ) {
@@ -243,7 +120,7 @@ const XmlArea = {
243120 //mod_val = mod_val.replace(/[\n\r\t\s]/g, '');
244121 //mod_val = mod_val.trim();
245122 obj . push ( {
246- 'value' : service_1 . default . Url . parseUrl ( mod_val ) ,
123+ 'value' : UrlAreaService_1 . UrlAreaService . parseUrl ( mod_val ) ,
247124 'area' : 'element : ' + elMatches [ a ] . elementName
248125 } ) ;
249126 }
@@ -256,7 +133,7 @@ const XmlArea = {
256133 /* check if all comments and elements have been removed properly */
257134 //console.log('xmlStr : ' + xmlStr);
258135 /* 5. normal text area */
259- let rx = new RegExp ( OptionalUrlPatternBuilder_1 . OptionalUrlPatternBuilder . getUrl , 'gi' ) ;
136+ let rx = new RegExp ( SafeConditionalUrlPatternBuilder_1 . SafeConditionalUrlPatternBuilder . getUrl , 'gi' ) ;
260137 let matches = [ ] ;
261138 let match ;
262139 while ( ( match = rx . exec ( xmlStr ) ) !== null ) {
@@ -267,7 +144,7 @@ const XmlArea = {
267144 let mod_val = match [ 0 ] ;
268145 //mod_val = mod_val.replace(/[\n\r\t\s]/g, '');
269146 obj . push ( {
270- 'value' : service_1 . default . Url . parseUrl ( mod_val ) ,
147+ 'value' : UrlAreaService_1 . UrlAreaService . parseUrl ( mod_val ) ,
271148 'area' : 'text'
272149 } ) ;
273150 }
@@ -300,8 +177,8 @@ const XmlArea = {
300177 }
301178 let obj = [ ] ;
302179 if ( ! skipXml ) {
303- let cmt_matches = XmlArea . extractAllComments ( xmlStr ) ;
304- let el_matches = XmlArea . extractAllElements ( xmlStr ) ;
180+ let cmt_matches = exports . XmlAreaApi . extractAllComments ( xmlStr ) ;
181+ let el_matches = exports . XmlAreaApi . extractAllElements ( xmlStr ) ;
305182 /* 1. comment */
306183 for ( let a = 0 ; a < cmt_matches . length ; a ++ ) {
307184 let rx = new RegExp ( EmailPatternBuilder_1 . EmailPatternBuilder . getEmail , 'gi' ) ;
@@ -404,4 +281,3 @@ const XmlArea = {
404281 return obj ;
405282 }
406283} ;
407- exports . XmlArea = XmlArea ;
0 commit comments