investira.sdk 2.4.30 → 2.4.32
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/.rgignore +4 -0
- package/CHANGELOG.md +4 -0
- package/index.js +1 -0
- package/lib/utils/rags.js +230 -0
- package/package.json +4 -4
package/.rgignore
ADDED
package/CHANGELOG.md
CHANGED
package/index.js
CHANGED
|
@@ -9,6 +9,7 @@ module.exports.invests = require('./lib/utils/invests');
|
|
|
9
9
|
module.exports.numbers = require('./lib/utils/numbers');
|
|
10
10
|
module.exports.objects = require('./lib/utils/objects');
|
|
11
11
|
module.exports.strings = require('./lib/utils/strings');
|
|
12
|
+
module.exports.rags = require('./lib/utils/rags');
|
|
12
13
|
module.exports.responses = require('./lib/utils/responses');
|
|
13
14
|
module.exports.validators = require('./lib/utils/validators');
|
|
14
15
|
module.exports.spellChecker = require('./lib/utils/spellChecker');
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
// const { dataHolidays } = require('investira.data');
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
// const moment = require('moment/min/moment-with-locales');
|
|
4
|
+
// const numbers = require('./numbers');
|
|
5
|
+
// const { isEmpty, isNull, isNumber, isDate, isFunction } = require('./validators');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
moment.suppressDeprecationWarnings = true;
|
|
9
|
+
|
|
10
|
+
const rags = {
|
|
11
|
+
/**
|
|
12
|
+
* Extrai aliases sem acentuação para tokens com diacríticos.
|
|
13
|
+
*
|
|
14
|
+
* Mantém apenas tokens cujo texto muda após remover acentos para reduzir ruído.
|
|
15
|
+
*
|
|
16
|
+
* @private
|
|
17
|
+
* @param {string} pText - Texto a processar
|
|
18
|
+
* @returns {string[]} Aliases sem acentuação
|
|
19
|
+
*/
|
|
20
|
+
extractAccentlessAliases: pText => {
|
|
21
|
+
const xAliases = new Set();
|
|
22
|
+
const xTokens = String(pText || '').match(/[A-Za-zÀ-ÖØ-öø-ÿ0-9_/-]+/g) || [];
|
|
23
|
+
|
|
24
|
+
for (const xTokenRaw of xTokens) {
|
|
25
|
+
const xToken = String(xTokenRaw || '').trim();
|
|
26
|
+
if (!xToken || !/[À-ÖØ-öø-ÿ]/.test(xToken)) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const xAccentlessToken = xToken
|
|
31
|
+
.normalize('NFD')
|
|
32
|
+
.replace(/[\u0300-\u036f]/g, '');
|
|
33
|
+
|
|
34
|
+
if (!xAccentlessToken || xAccentlessToken === xToken) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
xAliases.add(xAccentlessToken);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return [...xAliases].slice(0, 120);
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Extrai aliases numéricos com delimitadores de milhares.
|
|
46
|
+
*
|
|
47
|
+
* @private
|
|
48
|
+
* @param {string} pText - Texto a processar
|
|
49
|
+
* @returns {string[]} Aliases numéricos
|
|
50
|
+
*/
|
|
51
|
+
extractNumericAliases: pText => {
|
|
52
|
+
const xAliases = new Set();
|
|
53
|
+
const xMatches = String(pText || '').matchAll(/\b(?:\d{1,3}(?:[.\s]\d{3})+|\d{4,})\b/g);
|
|
54
|
+
|
|
55
|
+
for (const xMatch of xMatches) {
|
|
56
|
+
const xToken = String(xMatch?.[0] || '').trim();
|
|
57
|
+
if (!xToken) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const xDigits = xToken.replace(/[^\d]/g, '');
|
|
62
|
+
if (xDigits.length < 4) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const xDotVariant = pvFormatThousandsWithDelimiter(xDigits, '.');
|
|
67
|
+
|
|
68
|
+
xAliases.add(xDigits);
|
|
69
|
+
if (xDotVariant) {
|
|
70
|
+
xAliases.add(xDotVariant);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return [...xAliases];
|
|
75
|
+
},
|
|
76
|
+
/**
|
|
77
|
+
* Extrai aliases de datas do texto.
|
|
78
|
+
*
|
|
79
|
+
* @private
|
|
80
|
+
* @param {string} pText - Texto a processar
|
|
81
|
+
* @returns {string[]} Aliases de datas encontradas
|
|
82
|
+
*/
|
|
83
|
+
extractDateAliases: pText => {
|
|
84
|
+
const xAliases = new Set();
|
|
85
|
+
const xText = String(pText || '');
|
|
86
|
+
|
|
87
|
+
const xDmyMatches = xText.matchAll(/\b(\d{1,2})[./-](\d{1,2})[./-](\d{2,4})\b/g);
|
|
88
|
+
for (const xMatch of xDmyMatches) {
|
|
89
|
+
const xVariants = pvBuildDateAliasesFromParts({
|
|
90
|
+
day: xMatch?.[1],
|
|
91
|
+
month: xMatch?.[2],
|
|
92
|
+
year: xMatch?.[3]
|
|
93
|
+
});
|
|
94
|
+
xVariants.forEach(rVariant => xAliases.add(rVariant));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const xYmdMatches = xText.matchAll(/\b(\d{4})[./-](\d{1,2})[./-](\d{1,2})\b/g);
|
|
98
|
+
for (const xMatch of xYmdMatches) {
|
|
99
|
+
const xVariants = pvBuildDateAliasesFromParts({
|
|
100
|
+
day: xMatch?.[3],
|
|
101
|
+
month: xMatch?.[2],
|
|
102
|
+
year: xMatch?.[1]
|
|
103
|
+
});
|
|
104
|
+
xVariants.forEach(rVariant => xAliases.add(rVariant));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return [...xAliases];
|
|
108
|
+
},
|
|
109
|
+
/**
|
|
110
|
+
* Extrai aliases canônicos para códigos com separadores.
|
|
111
|
+
*
|
|
112
|
+
* Exemplos:
|
|
113
|
+
* - NTN-B -> NTNB
|
|
114
|
+
* - LCI-2029 -> LCI2029
|
|
115
|
+
* - ABC/12 -> ABC12
|
|
116
|
+
*
|
|
117
|
+
* Não gera aliases com espaços.
|
|
118
|
+
*
|
|
119
|
+
* @private
|
|
120
|
+
* @param {string} pText - Texto a processar
|
|
121
|
+
* @returns {string[]} Aliases de códigos encontrados
|
|
122
|
+
*/
|
|
123
|
+
extractAlphanumericCodeAliases: pText => {
|
|
124
|
+
const xAliases = new Set();
|
|
125
|
+
const xMatches = String(pText || '').matchAll(/\b(?=[A-Za-z0-9./-]*[A-Za-z])[A-Za-z0-9]+(?:[-./][A-Za-z0-9]+)+\b/g);
|
|
126
|
+
|
|
127
|
+
for (const xMatch of xMatches) {
|
|
128
|
+
const xToken = String(xMatch?.[0] || '').trim().toUpperCase();
|
|
129
|
+
if (!xToken) {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const xCanonicalToken = xToken.replace(/[-./]/g, '');
|
|
134
|
+
if (!xCanonicalToken || xCanonicalToken === xToken) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
xAliases.add(xCanonicalToken);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return [...xAliases];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
module.exports = rags;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Formata números com delimitador de milhares.
|
|
150
|
+
*
|
|
151
|
+
* @private
|
|
152
|
+
* @param {string|number} pDigits - Dígitos a formatar
|
|
153
|
+
* @param {string} [pDelimiter='.'] - Delimitador a ser usado
|
|
154
|
+
* @returns {string} Número formatado
|
|
155
|
+
*/
|
|
156
|
+
const pvFormatThousandsWithDelimiter = (pDigits, pDelimiter) => {
|
|
157
|
+
const xRawDigits = String(pDigits || '').replace(/[^\d]/g, '');
|
|
158
|
+
if (xRawDigits.length < 4) {
|
|
159
|
+
return xRawDigits;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const xNormalizedDigits = xRawDigits.replace(/^0+(\d)/, '$1');
|
|
163
|
+
const xDelimiter = typeof pDelimiter === 'string' ? pDelimiter : '.';
|
|
164
|
+
return xNormalizedDigits.replace(/\B(?=(\d{3})+(?!\d))/g, xDelimiter);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Constrói aliases de datas a partir de partes.
|
|
170
|
+
*
|
|
171
|
+
* @private
|
|
172
|
+
* @param {Object} pParts - Partes da data
|
|
173
|
+
* @param {string} pParts.day - Dia
|
|
174
|
+
* @param {string} pParts.month - Mês
|
|
175
|
+
* @param {string} pParts.year - Ano
|
|
176
|
+
* @returns {string[]} Aliases de datas construídos
|
|
177
|
+
*/
|
|
178
|
+
const pvBuildDateAliasesFromParts = ({ day, month, year }) => {
|
|
179
|
+
const xAliases = new Set();
|
|
180
|
+
|
|
181
|
+
const xRawDay = String(day || '').trim();
|
|
182
|
+
const xRawMonth = String(month || '').trim();
|
|
183
|
+
const xRawYear = String(year || '').trim();
|
|
184
|
+
|
|
185
|
+
// Converte para número apenas quando o conteúdo é realmente numérico.
|
|
186
|
+
const xDayNumber = /^\d{1,2}$/.test(xRawDay) ? Number(xRawDay) : null;
|
|
187
|
+
const xMonthNumber = /^\d{1,2}$/.test(xRawMonth) ? Number(xRawMonth) : null;
|
|
188
|
+
const xYearLength = xRawYear.length === 2 ? 2 : xRawYear.length === 4 ? 4 : 0;
|
|
189
|
+
const xYearNumber = xYearLength && /^\d+$/.test(xRawYear) ? Number(xRawYear) : null;
|
|
190
|
+
|
|
191
|
+
const xHasValidDay = Number.isInteger(xDayNumber) && xDayNumber >= 1 && xDayNumber <= 31;
|
|
192
|
+
const xHasValidMonth = Number.isInteger(xMonthNumber) && xMonthNumber >= 1 && xMonthNumber <= 12;
|
|
193
|
+
const xHasValidYear = Number.isInteger(xYearNumber);
|
|
194
|
+
|
|
195
|
+
const xDay = xHasValidDay ? String(xDayNumber).padStart(2, '0') : null;
|
|
196
|
+
const xMonth = xHasValidMonth ? String(xMonthNumber).padStart(2, '0') : null;
|
|
197
|
+
const xYear = xHasValidYear ? String(xYearNumber).padStart(xYearLength, '0') : null;
|
|
198
|
+
let xHasValidDayMonthCombo = false;
|
|
199
|
+
if (xYearLength === 4 && xDay && xMonth && xYear && xHasValidDayMonthCombo) {
|
|
200
|
+
xAliases.add(`${xYear}-${xMonth}-${xDay}`);
|
|
201
|
+
xAliases.add(`${xYear}/${xMonth}/${xDay}`);
|
|
202
|
+
xAliases.add(`${xYear}.${xMonth}.${xDay}`);
|
|
203
|
+
xAliases.add(`${xYear}${xMonth}${xDay}`);
|
|
204
|
+
xAliases.add(`${xDay}-${xMonth}-${xYear}`);
|
|
205
|
+
xAliases.add(`${xDay}/${xMonth}/${xYear}`);
|
|
206
|
+
xAliases.add(`${xDay}.${xMonth}.${xYear}`);
|
|
207
|
+
xAliases.add(`${xDay}${xMonth}${xYear}`);
|
|
208
|
+
} else if (xDay && xMonth) {
|
|
209
|
+
xAliases.add(`${xDay}/${xMonth}`);
|
|
210
|
+
xAliases.add(`${xDay}-${xMonth}`);
|
|
211
|
+
xAliases.add(`${xDay}.${xMonth}`);
|
|
212
|
+
xAliases.add(`${xDay}${xMonth}`);
|
|
213
|
+
} else if (xMonth && xYear) {
|
|
214
|
+
if (xYearLength === 4) {
|
|
215
|
+
xAliases.add(`${xYear}-${xMonth}`);
|
|
216
|
+
xAliases.add(`${xYear}/${xMonth}`);
|
|
217
|
+
xAliases.add(`${xYear}.${xMonth}`);
|
|
218
|
+
xAliases.add(`${xYear}${xMonth}`);
|
|
219
|
+
} else {
|
|
220
|
+
xAliases.add(`${xMonth}/${xYear}`);
|
|
221
|
+
xAliases.add(`${xMonth}-${xYear}`);
|
|
222
|
+
xAliases.add(`${xMonth}.${xYear}`);
|
|
223
|
+
xAliases.add(`${xMonth}${xYear}`);
|
|
224
|
+
}
|
|
225
|
+
} else if (xYear && !xAliases.size) {
|
|
226
|
+
xAliases.add(xYear);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return [...xAliases];
|
|
230
|
+
};
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "investira.sdk",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.32",
|
|
4
4
|
"author": "Investira",
|
|
5
5
|
"description": "Investira SDK",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"type": "commonjs",
|
|
8
8
|
"registry": true,
|
|
9
|
-
"raw": "investira.sdk@2.4.
|
|
9
|
+
"raw": "investira.sdk@2.4.32",
|
|
10
10
|
"escapedName": "investira.sdk",
|
|
11
|
-
"rawSpec": "2.4.
|
|
11
|
+
"rawSpec": "2.4.32",
|
|
12
12
|
"saveSpec": null,
|
|
13
|
-
"fetchSpec": "2.4.
|
|
13
|
+
"fetchSpec": "2.4.32",
|
|
14
14
|
"homepage": "https://investira.com.br/",
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">=11.11.0 <=18.21.0",
|