Skip to content

Commit 303e116

Browse files
refactor : folders
1 parent 4e9720f commit 303e116

23 files changed

+1059
-1058
lines changed

dist/api/TextAreaApi.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.TextAreaApi = void 0;
4+
const SafeConditionalUrlPatternBuilder_1 = require("../pattern/SafeConditionalUrlPatternBuilder");
5+
const DomainPatterns_1 = require("../pattern/DomainPatterns");
6+
const TextAreaService_1 = require("../service/TextAreaService");
7+
exports.TextAreaApi = {
8+
/**
9+
* @brief
10+
* Distill all urls in texts
11+
* @author Andrew Kang
12+
* @param textStr string required
13+
* @param noProtocolJsn object
14+
* default : {
15+
'ipV4' : false,
16+
'ipV6' : false,
17+
'localhost' : false,
18+
'intranet' : false
19+
}
20+
21+
* @return array
22+
*/
23+
extractAllUrls(textStr, noProtocolJsn = {
24+
ipV4: false,
25+
ipV6: false,
26+
localhost: false,
27+
intranet: false
28+
}) {
29+
SafeConditionalUrlPatternBuilder_1.SafeConditionalUrlPatternBuilder.setUrlPattern(noProtocolJsn);
30+
return TextAreaService_1.TextAreaService.extractAllPureUrls(textStr);
31+
},
32+
/**
33+
* @brief
34+
* Distill all emails from normal text
35+
* @author Andrew Kang
36+
* @param textStr string required
37+
* @param prefixSanitizer boolean (default : true)
38+
* @return array
39+
*/
40+
extractAllEmails(textStr, prefixSanitizer = true) {
41+
return TextAreaService_1.TextAreaService.extractAllPureEmails(textStr, prefixSanitizer);
42+
},
43+
/**
44+
*
45+
* [!!Important] This functions well, but should be refactored every business logic is here.
46+
*
47+
* @brief
48+
* Distill uris with certain names from normal text
49+
* @author Andrew Kang
50+
* @param textStr string required
51+
* @param uris array required
52+
* for example, [['a','b'], ['c','d']]
53+
* If you use {number}, this means 'only number' ex) [['a','{number}'], ['c','d']]
54+
* @param endBoundary boolean (default : false)
55+
* @return array
56+
*/
57+
extractCertainUris(textStr, uris, endBoundary = false) {
58+
if (!(textStr && typeof textStr === 'string')) {
59+
throw new Error('the variable textStr must be a string type and not be null.');
60+
}
61+
let obj = TextAreaService_1.TextAreaService.extractCertainPureUris(textStr, uris, endBoundary);
62+
let obj2 = TextAreaService_1.TextAreaService.extractAllPureUrls(textStr);
63+
//console.log('obj : ' + JSON.stringify(obj));
64+
let obj_final = [];
65+
for (let a = 0; a < obj.length; a++) {
66+
let obj_part = {
67+
uriDetected: undefined,
68+
inWhatUrl: undefined,
69+
};
70+
//let matchedUrlFound = false;
71+
for (let b = 0; b < obj2.length; b++) {
72+
if ((obj[a].index.start > obj2[b].index.start && obj[a].index.start < obj2[b].index.end)
73+
&&
74+
(obj[a].index.end > obj2[b].index.start && obj[a].index.end <= obj2[b].index.end)) {
75+
// Here, the uri detected is inside its url
76+
// false positives like the example '//google.com/abc/def?a=5&b=7' can be detected in 'Service.Text.extractCertainPureUris'
77+
let sanitizedUrl = obj[a]['value']['url'] || "";
78+
let rx = new RegExp('^(\\/\\/[^/]*|\\/[^\\s]+\\.' + DomainPatterns_1.DomainPatterns.allRootDomains + ')', 'gi');
79+
let matches = [];
80+
let match;
81+
while ((match = rx.exec(obj[a].value.url || "")) !== null) {
82+
if (match[1]) {
83+
sanitizedUrl = sanitizedUrl.replace(rx, '');
84+
//console.log(match[1]);
85+
obj[a].value.url = sanitizedUrl;
86+
obj[a].index.start += match[1].length;
87+
obj[a].value.onlyUriWithParams = obj[a].value.url;
88+
obj[a].value.onlyUri = (obj[a].value.url || "").replace(/\?[^/]*$/gi, '');
89+
}
90+
}
91+
obj_part.inWhatUrl = obj2[b];
92+
}
93+
}
94+
obj_part.uriDetected = obj[a];
95+
obj_final.push(obj_part);
96+
}
97+
return obj_final;
98+
},
99+
};

dist/api/UrlAreaApi.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.UrlAreaApi = void 0;
4+
const UrlAreaService_1 = require("../service/UrlAreaService");
5+
exports.UrlAreaApi = {
6+
/**
7+
* @brief
8+
* Assort an url into each type.
9+
* @author Andrew Kang
10+
* @param url string required
11+
* @return array ({'url' : '', 'protocol' : '', 'onlyDomain' : '', 'onlyUriWithParams' : '', 'type' : ''})
12+
*/
13+
parseUrl(url) {
14+
return UrlAreaService_1.UrlAreaService.parseUrl(url);
15+
},
16+
/**
17+
* @brief
18+
* Assort an url into each type.
19+
* @author Andrew Kang
20+
* @param url string required
21+
* @return array ({'url' : '', 'protocol' : '', 'onlyDomain' : '', 'onlyUriWithParams' : '', 'type' : ''})
22+
*/
23+
normalizeUrl(url) {
24+
return UrlAreaService_1.UrlAreaService.normalizeUrl(url);
25+
}
26+
};
Lines changed: 28 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,13 @@
11
"use strict";
2-
var __importDefault = (this && this.__importDefault) || function (mod) {
3-
return (mod && mod.__esModule) ? mod : { "default": mod };
4-
};
52
Object.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

Comments
 (0)