email-forward-parser 1.7.2 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +43 -0
- package/dist/index.js +67 -0
- package/dist/parser.d.ts +85 -0
- package/dist/parser.js +829 -0
- package/dist/utils.d.ts +18 -0
- package/dist/utils.js +98 -0
- package/package.json +36 -12
- package/lib/index.d.ts +0 -46
- package/lib/index.js +0 -74
- package/lib/parser.js +0 -1107
- package/lib/utils.js +0 -148
package/lib/utils.js
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**************************************************************************
|
|
4
|
-
* IMPORTS
|
|
5
|
-
***************************************************************************/
|
|
6
|
-
|
|
7
|
-
var RE2 = require("re2");
|
|
8
|
-
|
|
9
|
-
/**************************************************************************
|
|
10
|
-
* FUNCTIONS
|
|
11
|
-
***************************************************************************/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Executes multiple regular expressions until one succeeds
|
|
15
|
-
* @public
|
|
16
|
-
* @param {object} regexes
|
|
17
|
-
* @param {string} str
|
|
18
|
-
* @param {string} [mode]
|
|
19
|
-
* @param {boolean} [highestPosition]
|
|
20
|
-
* @return {object} The result of the first successfull regular expression
|
|
21
|
-
*/
|
|
22
|
-
var loopRegexes = function(
|
|
23
|
-
regexes, str, mode = "match", highestPosition = true
|
|
24
|
-
) {
|
|
25
|
-
var _match;
|
|
26
|
-
var _minLength = mode === "split" ? 1 : 0;
|
|
27
|
-
var _maxLength = str.length;
|
|
28
|
-
|
|
29
|
-
for (var _i = 0; _i < regexes.length; _i++) {
|
|
30
|
-
var _regex = regexes[_i];
|
|
31
|
-
|
|
32
|
-
if (typeof regexes[_i] === "string") {
|
|
33
|
-
// Build the regex
|
|
34
|
-
_regex = new RE2(regexes[_i]);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
var _currentMatch = (
|
|
38
|
-
_regex[mode](str || "", mode === "replace" ? "" : undefined)
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
if (mode === "replace") {
|
|
42
|
-
_match = _currentMatch;
|
|
43
|
-
|
|
44
|
-
// A successfull replace must return a smaller string than the input
|
|
45
|
-
if (_match.length < _maxLength) {
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
} else if (mode === "split" || mode === "match") {
|
|
49
|
-
// A successfull split must return an array with at least two items
|
|
50
|
-
if ((_currentMatch || []).length > _minLength) {
|
|
51
|
-
if (highestPosition === true) {
|
|
52
|
-
// No previous match?
|
|
53
|
-
if (!_match) {
|
|
54
|
-
// Save match and continue looking for other matches
|
|
55
|
-
_match = _currentMatch;
|
|
56
|
-
} else {
|
|
57
|
-
var _higher;
|
|
58
|
-
|
|
59
|
-
if (mode === "match") {
|
|
60
|
-
_higher = _match.index > _currentMatch.index;
|
|
61
|
-
} else if (mode === "split") {
|
|
62
|
-
_higher = _match[0].length > _currentMatch[0].length;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Match positioned higher than previous one?
|
|
66
|
-
if (_higher) {
|
|
67
|
-
// Replace match and continue looking for other matches
|
|
68
|
-
_match = _currentMatch;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
} else {
|
|
72
|
-
// Save match and stop
|
|
73
|
-
_match = _currentMatch;
|
|
74
|
-
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return (mode === "replace") ? (_match || "") : (_match || []);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Reconciliates match substrings after a "split" operation
|
|
87
|
-
* @public
|
|
88
|
-
* @param {object} match
|
|
89
|
-
* @param {number} min_substrings
|
|
90
|
-
* @param {object} default_substrings
|
|
91
|
-
* @param {function} fn_exlude
|
|
92
|
-
* @return {string} The reconciliated string
|
|
93
|
-
*/
|
|
94
|
-
var reconciliateSplitMatch = function(
|
|
95
|
-
match, min_substrings, default_substrings, fn_exlude = null
|
|
96
|
-
) {
|
|
97
|
-
var _str = "";
|
|
98
|
-
|
|
99
|
-
// Add default substrings
|
|
100
|
-
for (var _i = 0; _i < default_substrings.length; _i++) {
|
|
101
|
-
_str += match[default_substrings[_i]];
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// More substrings than expected?
|
|
105
|
-
if (match.length > min_substrings) {
|
|
106
|
-
// Reconciliate them
|
|
107
|
-
for (var _i = min_substrings; _i < match.length; _i++) {
|
|
108
|
-
var _exclude = false;
|
|
109
|
-
|
|
110
|
-
// Exclude the substring?
|
|
111
|
-
if (typeof fn_exlude === "function") {
|
|
112
|
-
_exclude = fn_exlude(_i);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (_exclude === false) {
|
|
116
|
-
_str += match[_i];
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return _str;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Trims a string
|
|
127
|
-
* @public
|
|
128
|
-
* @param {string} str
|
|
129
|
-
* @return {string} The trimed string
|
|
130
|
-
*/
|
|
131
|
-
var trimString = function(str) {
|
|
132
|
-
return ((str || "").trim() || "");
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
/**************************************************************************
|
|
137
|
-
* EXPORTS
|
|
138
|
-
***************************************************************************/
|
|
139
|
-
|
|
140
|
-
exports.loopRegexes = loopRegexes;
|
|
141
|
-
exports.reconciliateSplitMatch = reconciliateSplitMatch;
|
|
142
|
-
exports.trimString = trimString;
|
|
143
|
-
|
|
144
|
-
exports.default = {
|
|
145
|
-
loopRegexes : loopRegexes,
|
|
146
|
-
reconciliateSplitMatch : reconciliateSplitMatch,
|
|
147
|
-
trimString : trimString
|
|
148
|
-
};
|