@terascope/core-utils 2.0.0-dev.7
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/LICENSE +21 -0
- package/README.md +17 -0
- package/dist/src/arrays.d.ts +59 -0
- package/dist/src/arrays.d.ts.map +1 -0
- package/dist/src/arrays.js +180 -0
- package/dist/src/arrays.js.map +1 -0
- package/dist/src/big-lru-map.d.ts +14 -0
- package/dist/src/big-lru-map.d.ts.map +1 -0
- package/dist/src/big-lru-map.js +20 -0
- package/dist/src/big-lru-map.js.map +1 -0
- package/dist/src/big-map.d.ts +28 -0
- package/dist/src/big-map.d.ts.map +1 -0
- package/dist/src/big-map.js +148 -0
- package/dist/src/big-map.js.map +1 -0
- package/dist/src/big-set.d.ts +20 -0
- package/dist/src/big-set.d.ts.map +1 -0
- package/dist/src/big-set.js +109 -0
- package/dist/src/big-set.js.map +1 -0
- package/dist/src/booleans.d.ts +44 -0
- package/dist/src/booleans.d.ts.map +1 -0
- package/dist/src/booleans.js +81 -0
- package/dist/src/booleans.js.map +1 -0
- package/dist/src/buffers.d.ts +9 -0
- package/dist/src/buffers.d.ts.map +1 -0
- package/dist/src/buffers.js +22 -0
- package/dist/src/buffers.js.map +1 -0
- package/dist/src/collector.d.ts +48 -0
- package/dist/src/collector.d.ts.map +1 -0
- package/dist/src/collector.js +74 -0
- package/dist/src/collector.js.map +1 -0
- package/dist/src/dates.d.ts +180 -0
- package/dist/src/dates.d.ts.map +1 -0
- package/dist/src/dates.js +744 -0
- package/dist/src/dates.js.map +1 -0
- package/dist/src/decorators.d.ts +7 -0
- package/dist/src/decorators.d.ts.map +1 -0
- package/dist/src/decorators.js +21 -0
- package/dist/src/decorators.js.map +1 -0
- package/dist/src/deps.d.ts +25 -0
- package/dist/src/deps.d.ts.map +1 -0
- package/dist/src/deps.js +96 -0
- package/dist/src/deps.js.map +1 -0
- package/dist/src/empty.d.ts +11 -0
- package/dist/src/empty.d.ts.map +1 -0
- package/dist/src/empty.js +32 -0
- package/dist/src/empty.js.map +1 -0
- package/dist/src/entities/data-entity.d.ts +153 -0
- package/dist/src/entities/data-entity.d.ts.map +1 -0
- package/dist/src/entities/data-entity.js +354 -0
- package/dist/src/entities/data-entity.js.map +1 -0
- package/dist/src/entities/index.d.ts +3 -0
- package/dist/src/entities/index.d.ts.map +1 -0
- package/dist/src/entities/index.js +3 -0
- package/dist/src/entities/index.js.map +1 -0
- package/dist/src/entities/interfaces.d.ts +52 -0
- package/dist/src/entities/interfaces.d.ts.map +1 -0
- package/dist/src/entities/interfaces.js +13 -0
- package/dist/src/entities/interfaces.js.map +1 -0
- package/dist/src/entities/utils.d.ts +9 -0
- package/dist/src/entities/utils.d.ts.map +1 -0
- package/dist/src/entities/utils.js +44 -0
- package/dist/src/entities/utils.js.map +1 -0
- package/dist/src/env.d.ts +6 -0
- package/dist/src/env.d.ts.map +1 -0
- package/dist/src/env.js +15 -0
- package/dist/src/env.js.map +1 -0
- package/dist/src/equality.d.ts +72 -0
- package/dist/src/equality.d.ts.map +1 -0
- package/dist/src/equality.js +128 -0
- package/dist/src/equality.js.map +1 -0
- package/dist/src/errors.d.ts +140 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +372 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/event-loop.d.ts +33 -0
- package/dist/src/event-loop.d.ts.map +1 -0
- package/dist/src/event-loop.js +74 -0
- package/dist/src/event-loop.js.map +1 -0
- package/dist/src/fp.d.ts +15 -0
- package/dist/src/fp.d.ts.map +1 -0
- package/dist/src/fp.js +25 -0
- package/dist/src/fp.js.map +1 -0
- package/dist/src/functions.d.ts +19 -0
- package/dist/src/functions.d.ts.map +1 -0
- package/dist/src/functions.js +58 -0
- package/dist/src/functions.js.map +1 -0
- package/dist/src/index.d.ts +32 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +32 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/iterators.d.ts +9 -0
- package/dist/src/iterators.d.ts.map +1 -0
- package/dist/src/iterators.js +13 -0
- package/dist/src/iterators.js.map +1 -0
- package/dist/src/json.d.ts +8 -0
- package/dist/src/json.d.ts.map +1 -0
- package/dist/src/json.js +46 -0
- package/dist/src/json.js.map +1 -0
- package/dist/src/logger.d.ts +18 -0
- package/dist/src/logger.d.ts.map +1 -0
- package/dist/src/logger.js +87 -0
- package/dist/src/logger.js.map +1 -0
- package/dist/src/numbers.d.ts +86 -0
- package/dist/src/numbers.d.ts.map +1 -0
- package/dist/src/numbers.js +354 -0
- package/dist/src/numbers.js.map +1 -0
- package/dist/src/objects.d.ts +66 -0
- package/dist/src/objects.d.ts.map +1 -0
- package/dist/src/objects.js +170 -0
- package/dist/src/objects.js.map +1 -0
- package/dist/src/phone-number.d.ts +4 -0
- package/dist/src/phone-number.d.ts.map +1 -0
- package/dist/src/phone-number.js +31 -0
- package/dist/src/phone-number.js.map +1 -0
- package/dist/src/promises.d.ts +102 -0
- package/dist/src/promises.d.ts.map +1 -0
- package/dist/src/promises.js +289 -0
- package/dist/src/promises.js.map +1 -0
- package/dist/src/queue/index.d.ts +27 -0
- package/dist/src/queue/index.d.ts.map +1 -0
- package/dist/src/queue/index.js +170 -0
- package/dist/src/queue/index.js.map +1 -0
- package/dist/src/queue/node.d.ts +7 -0
- package/dist/src/queue/node.d.ts.map +1 -0
- package/dist/src/queue/node.js +17 -0
- package/dist/src/queue/node.js.map +1 -0
- package/dist/src/regex.d.ts +19 -0
- package/dist/src/regex.d.ts.map +1 -0
- package/dist/src/regex.js +138 -0
- package/dist/src/regex.js.map +1 -0
- package/dist/src/status-codes.d.ts +67 -0
- package/dist/src/status-codes.d.ts.map +1 -0
- package/dist/src/status-codes.js +66 -0
- package/dist/src/status-codes.js.map +1 -0
- package/dist/src/strings.d.ts +279 -0
- package/dist/src/strings.d.ts.map +1 -0
- package/dist/src/strings.js +578 -0
- package/dist/src/strings.js.map +1 -0
- package/dist/src/vector.d.ts +2 -0
- package/dist/src/vector.d.ts.map +1 -0
- package/dist/src/vector.js +16 -0
- package/dist/src/vector.js.map +1 -0
- package/package.json +65 -0
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { FieldType } from '@terascope/types';
|
|
2
|
+
import { isArrayLike } from './arrays.js';
|
|
3
|
+
import { getTypeOf } from './deps.js';
|
|
4
|
+
import { isKey } from './objects.js';
|
|
5
|
+
let supportsBigInt = true;
|
|
6
|
+
try {
|
|
7
|
+
if (typeof globalThis.BigInt === 'undefined') {
|
|
8
|
+
supportsBigInt = false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
catch (err) {
|
|
12
|
+
supportsBigInt = false;
|
|
13
|
+
}
|
|
14
|
+
/** A native implementation of lodash random */
|
|
15
|
+
export function random(min, max) {
|
|
16
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
17
|
+
}
|
|
18
|
+
/** Check if an input is a number */
|
|
19
|
+
export function isNumber(input) {
|
|
20
|
+
return typeof input === 'number' && !Number.isNaN(input);
|
|
21
|
+
}
|
|
22
|
+
/** Convert any input to a number, return Number.NaN if unable to convert input */
|
|
23
|
+
export function toNumber(input) {
|
|
24
|
+
if (typeof input === 'number')
|
|
25
|
+
return input;
|
|
26
|
+
return Number(input);
|
|
27
|
+
}
|
|
28
|
+
/** Will throw if converted number is NaN */
|
|
29
|
+
export function toNumberOrThrow(input) {
|
|
30
|
+
const num = toNumber(input);
|
|
31
|
+
if (!isNumber(num)) {
|
|
32
|
+
throw new Error(`Could not convert ${input} to a number`);
|
|
33
|
+
}
|
|
34
|
+
return num;
|
|
35
|
+
}
|
|
36
|
+
/** Check if value is a bigint */
|
|
37
|
+
export function isBigInt(input) {
|
|
38
|
+
return typeof input === 'bigint';
|
|
39
|
+
}
|
|
40
|
+
/** Convert any input to a bigint */
|
|
41
|
+
export function toBigInt(input) {
|
|
42
|
+
if (!supportsBigInt) {
|
|
43
|
+
throw new Error('BigInt isn\'t supported in this environment');
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
return toBigIntOrThrow(input);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const _maxBigInt = supportsBigInt
|
|
53
|
+
? BigInt(Number.MAX_SAFE_INTEGER)
|
|
54
|
+
: Number.MAX_SAFE_INTEGER;
|
|
55
|
+
/** Convert any input to a bigint */
|
|
56
|
+
export function toBigIntOrThrow(input) {
|
|
57
|
+
if (typeof input === 'object') {
|
|
58
|
+
throw new TypeError(`Expected ${input} (${getTypeOf(input)}) to be parsable to a float`);
|
|
59
|
+
}
|
|
60
|
+
if (isBigInt(input))
|
|
61
|
+
return input;
|
|
62
|
+
if (!supportsBigInt) {
|
|
63
|
+
throw new Error('BigInt isn\'t supported in this environment');
|
|
64
|
+
}
|
|
65
|
+
if (typeof input === 'number' && input < Number.MAX_SAFE_INTEGER) {
|
|
66
|
+
return BigInt(Math.trunc(input));
|
|
67
|
+
}
|
|
68
|
+
if (!isNumberLike(input)) {
|
|
69
|
+
throw new TypeError(`Expected ${input} (${getTypeOf(input)}) to be parsable to a BigInt`);
|
|
70
|
+
}
|
|
71
|
+
let big;
|
|
72
|
+
if (typeof input === 'string' && input.includes('.')) {
|
|
73
|
+
big = BigInt(Number.parseInt(input, 10));
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
big = BigInt(input);
|
|
77
|
+
}
|
|
78
|
+
// for some reason the number
|
|
79
|
+
// is incorrect when given a number
|
|
80
|
+
// greater than the max safe integer
|
|
81
|
+
if (big > _maxBigInt) {
|
|
82
|
+
return big + BigInt(1);
|
|
83
|
+
}
|
|
84
|
+
return big;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Convert a BigInt to either a number or a string
|
|
88
|
+
*/
|
|
89
|
+
export function bigIntToJSON(int) {
|
|
90
|
+
if (typeof int === 'number')
|
|
91
|
+
return int;
|
|
92
|
+
if (int <= _maxBigInt) {
|
|
93
|
+
return Number.parseInt(int.toString(10), 10);
|
|
94
|
+
}
|
|
95
|
+
// for some reason bigints ending being +1
|
|
96
|
+
return (int - BigInt(1)).toString(10);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* A stricter check for verifying a number string
|
|
100
|
+
* @todo this needs to be smarter
|
|
101
|
+
*/
|
|
102
|
+
export function isNumberLike(input) {
|
|
103
|
+
if (typeof input === 'number')
|
|
104
|
+
return true;
|
|
105
|
+
if (typeof input === 'object')
|
|
106
|
+
return false;
|
|
107
|
+
if (typeof input === 'boolean')
|
|
108
|
+
return false;
|
|
109
|
+
// https://regexr.com/5cljt
|
|
110
|
+
return /^\s*[+-]{0,1}[\d,]+(\.[\d]+){0,1}\s*$/.test(String(input));
|
|
111
|
+
}
|
|
112
|
+
/** A simplified implementation of lodash isInteger */
|
|
113
|
+
export function isInteger(val) {
|
|
114
|
+
if (typeof val !== 'number')
|
|
115
|
+
return false;
|
|
116
|
+
return Number.isSafeInteger(val);
|
|
117
|
+
}
|
|
118
|
+
/** Convert an input to a integer, return false if unable to convert input */
|
|
119
|
+
export function toInteger(input) {
|
|
120
|
+
try {
|
|
121
|
+
return toIntegerOrThrow(input);
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/** Convert an input to a integer or throw */
|
|
128
|
+
export function toIntegerOrThrow(input) {
|
|
129
|
+
if (typeof input === 'object') {
|
|
130
|
+
throw new TypeError(`Expected ${input} (${getTypeOf(input)}) to be parsable to a integer`);
|
|
131
|
+
}
|
|
132
|
+
if (isBigInt(input)) {
|
|
133
|
+
const val = bigIntToJSON(input);
|
|
134
|
+
if (typeof val === 'string') {
|
|
135
|
+
throw new TypeError(`Expected ${val} (${getTypeOf(input)}) to be parsable to a integer`);
|
|
136
|
+
}
|
|
137
|
+
return val;
|
|
138
|
+
}
|
|
139
|
+
if (isInteger(input) || isFloat(input))
|
|
140
|
+
return Math.trunc(input);
|
|
141
|
+
if (!isNumberLike(input)) {
|
|
142
|
+
throw new TypeError(`Expected ${input} (${getTypeOf(input)}) to be parsable to a integer`);
|
|
143
|
+
}
|
|
144
|
+
const val = Number.parseInt(input, 10);
|
|
145
|
+
if (isInteger(val))
|
|
146
|
+
return val;
|
|
147
|
+
throw new TypeError(`Expected ${val} (${getTypeOf(input)}) to be parsable to a integer`);
|
|
148
|
+
}
|
|
149
|
+
/** Verify the input is float */
|
|
150
|
+
export function isFloat(val) {
|
|
151
|
+
if (!isNumber(val))
|
|
152
|
+
return false;
|
|
153
|
+
if (val === Number.POSITIVE_INFINITY)
|
|
154
|
+
return true;
|
|
155
|
+
if (val === Number.NEGATIVE_INFINITY)
|
|
156
|
+
return true;
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
/** Convert an input to a float, return false if unable to convert input */
|
|
160
|
+
export function toFloat(input) {
|
|
161
|
+
try {
|
|
162
|
+
return toFloatOrThrow(input);
|
|
163
|
+
}
|
|
164
|
+
catch (err) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/** Convert an input to a float or throw */
|
|
169
|
+
export function toFloatOrThrow(input) {
|
|
170
|
+
if (typeof input === 'object') {
|
|
171
|
+
throw new TypeError(`Expected ${input} (${getTypeOf(input)}) to be parsable to a float`);
|
|
172
|
+
}
|
|
173
|
+
if (isFloat(input))
|
|
174
|
+
return input;
|
|
175
|
+
if (isBigInt(input)) {
|
|
176
|
+
const val = bigIntToJSON(input);
|
|
177
|
+
if (typeof val === 'string') {
|
|
178
|
+
throw new TypeError(`Expected ${val} (${getTypeOf(input)}) to be parsable to a float`);
|
|
179
|
+
}
|
|
180
|
+
return val;
|
|
181
|
+
}
|
|
182
|
+
if (!isNumberLike(input)) {
|
|
183
|
+
throw new TypeError(`Expected ${input} (${getTypeOf(input)}) to be parsable to a float`);
|
|
184
|
+
}
|
|
185
|
+
const val = Number.parseFloat(input);
|
|
186
|
+
if (isFloat(val))
|
|
187
|
+
return val;
|
|
188
|
+
throw new TypeError(`Expected ${val} (${getTypeOf(input)}) to be parsable to a float`);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Like parseList, except it returns numbers
|
|
192
|
+
*/
|
|
193
|
+
export function parseNumberList(input) {
|
|
194
|
+
let items;
|
|
195
|
+
if (typeof input === 'string') {
|
|
196
|
+
items = input.split(',');
|
|
197
|
+
}
|
|
198
|
+
else if (Array.isArray(input)) {
|
|
199
|
+
items = input;
|
|
200
|
+
}
|
|
201
|
+
else if (isArrayLike(input)) {
|
|
202
|
+
items = Array.from(input);
|
|
203
|
+
}
|
|
204
|
+
else if (isNumber(input)) {
|
|
205
|
+
return [input];
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
return [];
|
|
209
|
+
}
|
|
210
|
+
return items
|
|
211
|
+
// filter out any empty string
|
|
212
|
+
.filter(isConvertibleToNumber)
|
|
213
|
+
.map(toNumber)
|
|
214
|
+
.filter(isNumber);
|
|
215
|
+
}
|
|
216
|
+
function isConvertibleToNumber(item) {
|
|
217
|
+
if (item == null)
|
|
218
|
+
return false;
|
|
219
|
+
if (typeof item === 'string' && !item.trim().length)
|
|
220
|
+
return false;
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Returns true if number is between min or max value provided
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* inNumberRange(42, { min: 0, max: 100}); // true
|
|
228
|
+
* inNumberRange(-42, { min:0 , max: 100 }); // false
|
|
229
|
+
* inNumberRange(42, { min: 0, max: 42 }); // false
|
|
230
|
+
* inNumberRange(42, { min: 0, max: 42, inclusive: true }) // true
|
|
231
|
+
*/
|
|
232
|
+
export function inNumberRange(input, args) {
|
|
233
|
+
if (!isNumber(input) && !isBigInt(input))
|
|
234
|
+
return false;
|
|
235
|
+
const min = args.min == null ? Number.NEGATIVE_INFINITY : args.min;
|
|
236
|
+
const max = args.max == null ? Number.POSITIVE_INFINITY : args.max;
|
|
237
|
+
if (args.inclusive) {
|
|
238
|
+
return (input >= min && input <= max);
|
|
239
|
+
}
|
|
240
|
+
return (input > min && input < max);
|
|
241
|
+
}
|
|
242
|
+
export function inNumberRangeFP(args) {
|
|
243
|
+
return function _inNumberRangeFP(input) {
|
|
244
|
+
return inNumberRange(input, args);
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Returns a truncated number to nth decimal places.
|
|
249
|
+
*
|
|
250
|
+
* @param fractionDigits The number of decimal points to round to.
|
|
251
|
+
* @param truncate If this is true the number will not be rounded
|
|
252
|
+
*/
|
|
253
|
+
export function setPrecision(input, fractionDigits, truncate = false) {
|
|
254
|
+
if (Number.isNaN(input)
|
|
255
|
+
|| input === Number.POSITIVE_INFINITY
|
|
256
|
+
|| input === Number.NEGATIVE_INFINITY) {
|
|
257
|
+
return input;
|
|
258
|
+
}
|
|
259
|
+
const num = toFloatOrThrow(input);
|
|
260
|
+
if (!truncate) {
|
|
261
|
+
return parseFloat(num.toFixed(fractionDigits));
|
|
262
|
+
}
|
|
263
|
+
return parseFloat(setPrecisionFromString(num.toString(), fractionDigits));
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* A functional programming version of setPrecision
|
|
267
|
+
*
|
|
268
|
+
* @param fractionDigits The number of decimal points to round to.
|
|
269
|
+
* @param truncate If this is true the number will not be rounded
|
|
270
|
+
*/
|
|
271
|
+
export function setPrecisionFP(fractionDigits, truncate = false) {
|
|
272
|
+
return function _setPrecision(input) {
|
|
273
|
+
return setPrecision(input, fractionDigits, truncate);
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* this will always truncate (not round)
|
|
278
|
+
*/
|
|
279
|
+
function setPrecisionFromString(input, fractionDigits) {
|
|
280
|
+
const [int, points] = input.toString().split('.');
|
|
281
|
+
if (!points)
|
|
282
|
+
return int || '0';
|
|
283
|
+
const remainingPoints = points.slice(0, fractionDigits);
|
|
284
|
+
if (!remainingPoints)
|
|
285
|
+
return int || '0';
|
|
286
|
+
return `${int || '0'}.${remainingPoints}`;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Convert a fahrenheit value to celsius, this will return a precision of
|
|
290
|
+
* 2 decimal points
|
|
291
|
+
*/
|
|
292
|
+
export function toCelsius(input) {
|
|
293
|
+
const num = toFloatOrThrow(input);
|
|
294
|
+
const cNum = (num - 32) * (5 / 9);
|
|
295
|
+
return parseFloat(cNum.toFixed(2));
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Convert a celsius value to fahrenheit, this will return a precision of
|
|
299
|
+
* 2 decimal points
|
|
300
|
+
*/
|
|
301
|
+
export function toFahrenheit(input) {
|
|
302
|
+
const num = toFloatOrThrow(input);
|
|
303
|
+
const fNum = ((9 / 5) * num) + 32;
|
|
304
|
+
return parseFloat(fNum.toFixed(2));
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* A number in javascript is a double-precision 64-bit
|
|
308
|
+
* binary format IEEE 754 value, much bigger than a regular
|
|
309
|
+
* classical int value, any higher than that should be a bigint
|
|
310
|
+
*/
|
|
311
|
+
const INT_SIZES = {
|
|
312
|
+
[FieldType.Byte]: { min: -128, max: 127 },
|
|
313
|
+
[FieldType.Short]: { min: -32_768, max: 32_767 },
|
|
314
|
+
[FieldType.Integer]: { min: Number.MIN_SAFE_INTEGER, max: Number.MAX_SAFE_INTEGER },
|
|
315
|
+
};
|
|
316
|
+
function _validateNumberFieldType(input, type) {
|
|
317
|
+
const int = toIntegerOrThrow(input);
|
|
318
|
+
if (isKey(INT_SIZES, type)) {
|
|
319
|
+
const { max, min } = INT_SIZES[type];
|
|
320
|
+
if (int >= max) {
|
|
321
|
+
throw new TypeError(`Invalid byte, value of ${int} is greater than maximum size of ${max}`);
|
|
322
|
+
}
|
|
323
|
+
if (int <= min) {
|
|
324
|
+
throw new TypeError(`Invalid byte, value of ${int} is less than minimum size of ${min}`);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return int;
|
|
328
|
+
}
|
|
329
|
+
export function validateByteNumber(input) {
|
|
330
|
+
return _validateNumberFieldType(input, FieldType.Byte);
|
|
331
|
+
}
|
|
332
|
+
export function validateShortNumber(input) {
|
|
333
|
+
return _validateNumberFieldType(input, FieldType.Short);
|
|
334
|
+
}
|
|
335
|
+
export function validateIntegerNumber(input) {
|
|
336
|
+
return _validateNumberFieldType(input, FieldType.Integer);
|
|
337
|
+
}
|
|
338
|
+
export function validateNumberType(type) {
|
|
339
|
+
return function _validateNumberType(input) {
|
|
340
|
+
return _validateNumberFieldType(input, type);
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
export function isValidateNumberType(type) {
|
|
344
|
+
const fn = validateNumberType(type);
|
|
345
|
+
return function _isValidateNumberType(input) {
|
|
346
|
+
try {
|
|
347
|
+
return fn(input) != null;
|
|
348
|
+
}
|
|
349
|
+
catch (_err) {
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
//# sourceMappingURL=numbers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numbers.js","sourceRoot":"","sources":["../../src/numbers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAErC,IAAI,cAAc,GAAG,IAAI,CAAC;AAC1B,IAAI,CAAC;IACD,IAAI,OAAO,UAAU,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;QAC3C,cAAc,GAAG,KAAK,CAAC;IAC3B,CAAC;AACL,CAAC;AAAC,OAAO,GAAG,EAAE,CAAC;IACX,cAAc,GAAG,KAAK,CAAC;AAC3B,CAAC;AAED,+C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,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAEpC,OAAO,SAAS,qBAAqB,CAAC,KAAc;QAChD,IAAI,CAAC;YACD,OAAO,EAAE,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;QAC7B,CAAC;QAAC,OAAO,IAAI,EAAE,CAAC;YACZ,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { WithoutNil, FilteredResult } from '@terascope/types';
|
|
2
|
+
/**
|
|
3
|
+
* Similar to is-plain-object but works better when you cloneDeep a DataEntity
|
|
4
|
+
*/
|
|
5
|
+
export declare function isSimpleObject(input: unknown): input is Record<string, unknown>;
|
|
6
|
+
/**
|
|
7
|
+
* Get the first value in an object
|
|
8
|
+
*/
|
|
9
|
+
export declare function getFirstValue<T>(input: {
|
|
10
|
+
[key: string]: T;
|
|
11
|
+
}): T | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Get the first key in an object
|
|
14
|
+
*/
|
|
15
|
+
export declare function getFirstKey<T extends object>(input: T): (keyof T) | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Verify that k is a key of object O
|
|
18
|
+
*/
|
|
19
|
+
export declare function isKey<T extends object>(O: T, k: PropertyKey): k is keyof T;
|
|
20
|
+
/**
|
|
21
|
+
* Verify if the input is a object like type
|
|
22
|
+
*/
|
|
23
|
+
export declare function isObjectEntity(input: unknown): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* A clone deep using `JSON.parse(JSON.stringify(input))`
|
|
26
|
+
*/
|
|
27
|
+
export declare function fastCloneDeep<T>(input: T): T;
|
|
28
|
+
/** Perform a shallow clone of an object to another, in the fastest way possible */
|
|
29
|
+
export declare function fastAssign<T extends object, U extends object>(target: T, source: U): T & U;
|
|
30
|
+
/** Sort keys on an object */
|
|
31
|
+
export declare function sortKeys<T extends Record<string, unknown>>(input: T, options?: {
|
|
32
|
+
deep?: boolean;
|
|
33
|
+
}): T;
|
|
34
|
+
/** Map the values of an object */
|
|
35
|
+
export declare function mapValues<T extends object, R = T>(input: T, fn: (value: T[keyof T], key: (keyof T)) => any): R;
|
|
36
|
+
/** Map the keys of an object */
|
|
37
|
+
export declare function mapKeys<T extends object, R = T>(input: T, fn: (value: T[keyof T], key: (keyof T)) => any): R;
|
|
38
|
+
/** Build a new object without null or undefined values (shallow) */
|
|
39
|
+
export declare function withoutNil<T>(input: T): WithoutNil<T>;
|
|
40
|
+
/**
|
|
41
|
+
* Filters the keys of an object, by list of included key and excluded
|
|
42
|
+
*/
|
|
43
|
+
export declare function filterObject<T extends object, I extends (keyof T), E extends (keyof T)>(data: T, by?: {
|
|
44
|
+
includes?: I[];
|
|
45
|
+
excludes?: E[];
|
|
46
|
+
}): FilteredResult<T, I, E>;
|
|
47
|
+
/**
|
|
48
|
+
* A type safe get function (will always return the correct type)
|
|
49
|
+
*
|
|
50
|
+
* **IMPORTANT** This does not behave like lodash.get,
|
|
51
|
+
* it does not deal with dot notation (nested fields)
|
|
52
|
+
* and it will use the default when dealing with OR statements
|
|
53
|
+
*/
|
|
54
|
+
export declare function getField<V>(input: undefined, field: string, defaultVal?: V): V;
|
|
55
|
+
export declare function getField<T, P extends keyof T>(input: T, field: P): T[P];
|
|
56
|
+
export declare function getField<T, P extends keyof T>(input: T | undefined, field: P): T[P];
|
|
57
|
+
export declare function getField<T, P extends keyof T>(input: T | undefined, field: P, defaultVal: never[]): T[P];
|
|
58
|
+
export declare function getField<T, P extends keyof T, V>(input: T | undefined, field: P, defaultVal: V): T[P] | V;
|
|
59
|
+
export declare function getField<T, P extends keyof T, V extends T[P]>(input: T | undefined, field: P, defaultVal: V): T[P];
|
|
60
|
+
/**
|
|
61
|
+
* Check if a object has property (and not included in the prototype)
|
|
62
|
+
* Different from has since it doesn't deal with dot notation values.
|
|
63
|
+
*/
|
|
64
|
+
export declare function hasOwn(obj: any, prop: string | symbol | number): boolean;
|
|
65
|
+
export declare function lookup(input: unknown):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AC,CAAC,CAAC,CAAC,CAAC;AACR,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EACzC,KAAK,EAAE,CAAC,GAAG,SAAS,EACpB,KAAK,EAAE,CAAC,GACT,CAAC,CAAC,CAAC,CAAC,CAAC;AACR,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EACzC,KAAK,EAAE,CAAC,GAAG,SAAS,EACpB,KAAK,EAAE,CAAC,EACR,UAAU,EAAE,KAAK,EAAE,GACpB,CAAC,CAAC,CAAC,CAAC,CAAC;AACR,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,CAAC,EAC5C,KAAK,EAAE,CAAC,GAAG,SAAS,EACpB,KAAK,EAAE,CAAC,EACR,UAAU,EAAE,CAAC,GACd,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AACZ,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EACzD,KAAK,EAAE,CAAC,GAAG,SAAS,EACpB,KAAK,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,GACxB,CAAC,CAAC,CAAC,CAAC,CAAC;AAcR;;;EAGE;AAEF,wBAAgB,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAExE;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,GAAG,CAuB5D"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { isDataEntity } from './entities/utils.js';
|
|
2
|
+
import { isBooleanLike } from './booleans.js';
|
|
3
|
+
import { get, isPlainObject, getTypeOf } from './deps.js';
|
|
4
|
+
import { isArrayLike, isArray } from './arrays.js';
|
|
5
|
+
import { isBuffer } from './buffers.js';
|
|
6
|
+
import { isString, trim, isPrimitiveValue } from './strings.js';
|
|
7
|
+
import { toNumber } from './numbers.js';
|
|
8
|
+
/**
|
|
9
|
+
* Similar to is-plain-object but works better when you cloneDeep a DataEntity
|
|
10
|
+
*/
|
|
11
|
+
export function isSimpleObject(input) {
|
|
12
|
+
if (input == null)
|
|
13
|
+
return false;
|
|
14
|
+
if (isBuffer(input))
|
|
15
|
+
return false;
|
|
16
|
+
if (isArrayLike(input))
|
|
17
|
+
return false;
|
|
18
|
+
if (input instanceof Set)
|
|
19
|
+
return false;
|
|
20
|
+
if (input instanceof Map)
|
|
21
|
+
return false;
|
|
22
|
+
return typeof input === 'object';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get the first value in an object
|
|
26
|
+
*/
|
|
27
|
+
export function getFirstValue(input) {
|
|
28
|
+
return Object.values(input)[0];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get the first key in an object
|
|
32
|
+
*/
|
|
33
|
+
export function getFirstKey(input) {
|
|
34
|
+
return Object.keys(input)[0];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Verify that k is a key of object O
|
|
38
|
+
*/
|
|
39
|
+
export function isKey(O, k) {
|
|
40
|
+
return k in O;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Verify if the input is a object like type
|
|
44
|
+
*/
|
|
45
|
+
export function isObjectEntity(input) {
|
|
46
|
+
return isDataEntity(input) || isSimpleObject(input);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A clone deep using `JSON.parse(JSON.stringify(input))`
|
|
50
|
+
*/
|
|
51
|
+
export function fastCloneDeep(input) {
|
|
52
|
+
return JSON.parse(JSON.stringify(input));
|
|
53
|
+
}
|
|
54
|
+
/** Perform a shallow clone of an object to another, in the fastest way possible */
|
|
55
|
+
export function fastAssign(target, source) {
|
|
56
|
+
if (!isObjectEntity(source)) {
|
|
57
|
+
return target;
|
|
58
|
+
}
|
|
59
|
+
for (const [key, val] of Object.entries(source)) {
|
|
60
|
+
target[key] = val;
|
|
61
|
+
}
|
|
62
|
+
return target;
|
|
63
|
+
}
|
|
64
|
+
/** Sort keys on an object */
|
|
65
|
+
export function sortKeys(input, options = {}) {
|
|
66
|
+
const result = {};
|
|
67
|
+
for (const _key of Object.keys(input).sort()) {
|
|
68
|
+
const key = _key;
|
|
69
|
+
const val = input[key];
|
|
70
|
+
if (options.deep && isPlainObject(val)) {
|
|
71
|
+
result[key] = sortKeys(val, options);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
result[key] = val;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
/** Map the values of an object */
|
|
80
|
+
export function mapValues(input, fn) {
|
|
81
|
+
const result = {};
|
|
82
|
+
for (const [key, val] of Object.entries(input)) {
|
|
83
|
+
result[key] = fn(val, key);
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
/** Map the keys of an object */
|
|
88
|
+
export function mapKeys(input, fn) {
|
|
89
|
+
const result = {};
|
|
90
|
+
for (const [key, val] of Object.entries(input)) {
|
|
91
|
+
result[fn(val, key)] = val;
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
/** Build a new object without null or undefined values (shallow) */
|
|
96
|
+
export function withoutNil(input) {
|
|
97
|
+
const result = {};
|
|
98
|
+
for (const _key of Object.keys(input).sort()) {
|
|
99
|
+
const key = _key;
|
|
100
|
+
if (input[key] != null) {
|
|
101
|
+
result[key] = input[key];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Filters the keys of an object, by list of included key and excluded
|
|
108
|
+
*/
|
|
109
|
+
export function filterObject(data, by) {
|
|
110
|
+
const { includes = [], excludes = [] } = by || {};
|
|
111
|
+
const result = {};
|
|
112
|
+
Object.keys(data)
|
|
113
|
+
.filter((key) => {
|
|
114
|
+
const included = includes.length ? includes.includes(key) : true;
|
|
115
|
+
const excluded = excludes.length ? excludes.includes(key) : false;
|
|
116
|
+
return included && !excluded;
|
|
117
|
+
})
|
|
118
|
+
.sort()
|
|
119
|
+
.forEach((key) => {
|
|
120
|
+
if (isKey(data, key)) {
|
|
121
|
+
result[key] = data[key];
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
export function getField(input, field, defaultVal) {
|
|
127
|
+
const result = get(input, field);
|
|
128
|
+
if (isBooleanLike(defaultVal)) {
|
|
129
|
+
if (result == null)
|
|
130
|
+
return defaultVal;
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
return result || defaultVal;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Check if a object has property (and not included in the prototype)
|
|
137
|
+
* Different from has since it doesn't deal with dot notation values.
|
|
138
|
+
*/
|
|
139
|
+
export function hasOwn(obj, prop) {
|
|
140
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
141
|
+
}
|
|
142
|
+
export function lookup(input) {
|
|
143
|
+
// lookup entity can be a string, object or array
|
|
144
|
+
if (!isObjectEntity(input) && !isString(input) && !isArray(input)) {
|
|
145
|
+
throw Error(`input must be an Object Entity, String, received ${getTypeOf(input)}`);
|
|
146
|
+
}
|
|
147
|
+
return function _lookup(key) {
|
|
148
|
+
if (key == null)
|
|
149
|
+
return null;
|
|
150
|
+
// This may be too restrictive at some point
|
|
151
|
+
if (!isPrimitiveValue(key)) {
|
|
152
|
+
throw Error(`lookup key must be not be an object, received ${getTypeOf(key)}`);
|
|
153
|
+
}
|
|
154
|
+
if (isString(input)) {
|
|
155
|
+
return _lookupStringToObject(input)[key];
|
|
156
|
+
}
|
|
157
|
+
if (isArray(input))
|
|
158
|
+
return input[toNumber(key)];
|
|
159
|
+
const lookupObj = input;
|
|
160
|
+
return lookupObj[key];
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function _lookupStringToObject(stringInput) {
|
|
164
|
+
return stringInput.split('\n').reduce((asObj, line) => {
|
|
165
|
+
const [k, v] = trim(line).split(':', 2);
|
|
166
|
+
asObj[trim(k)] = trim(v);
|
|
167
|
+
return asObj;
|
|
168
|
+
}, {});
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=objects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objects.js","sourceRoot":"","sources":["../../src/objects.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC;;EAEE;AACF,MAAM,UAAU,cAAc,CAAC,KAAc;IACzC,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,KAAK,CAAC;IAChC,IAAI,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAClC,IAAI,WAAW,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACrC,IAAI,KAAK,YAAY,GAAG;QAAE,OAAO,KAAK,CAAC;IACvC,IAAI,KAAK,YAAY,GAAG;QAAE,OAAO,KAAK,CAAC;IACvC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACrC,CAAC;AAED;;EAEE;AACF,MAAM,UAAU,aAAa,CAAI,KAA2B;IACxD,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,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,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QAExC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAEzB,OAAO,KAAK,CAAC;IACjB,CAAC,EAAE,EAAE,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phone-number.d.ts","sourceRoot":"","sources":["../../src/phone-number.ts"],"names":[],"mappings":"AAIA,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAO/D;AAYD,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAQhE;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAKzD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { parsePhoneNumber as _parsePhoneNumber } from 'awesome-phonenumber';
|
|
2
|
+
import { toString, isString } from './strings.js';
|
|
3
|
+
import { isNumber, inNumberRange } from './numbers.js';
|
|
4
|
+
export function parsePhoneNumber(input) {
|
|
5
|
+
const preppedInput = _prepPhoneNumber(toString(input).trim());
|
|
6
|
+
const fullNumber = _parsePhoneNumber(preppedInput).number?.e164;
|
|
7
|
+
if (fullNumber)
|
|
8
|
+
return String(fullNumber).slice(1);
|
|
9
|
+
throw Error('Could not determine the incoming phone number');
|
|
10
|
+
}
|
|
11
|
+
function _prepPhoneNumber(input) {
|
|
12
|
+
let testNumber = input;
|
|
13
|
+
if (testNumber.charAt(0) === '0')
|
|
14
|
+
testNumber = testNumber.slice(1);
|
|
15
|
+
if (testNumber.charAt(0) !== '+')
|
|
16
|
+
testNumber = `+${testNumber}`;
|
|
17
|
+
return testNumber;
|
|
18
|
+
}
|
|
19
|
+
export function isISDN(input, country) {
|
|
20
|
+
if (isString(input) || isNumber(input)) {
|
|
21
|
+
const isdn = country ? _parsePhoneNumber(toString(input), { regionCode: country }) : _parsePhoneNumber(`+${input}`);
|
|
22
|
+
return isdn.valid;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
export function isPhoneNumberLike(input) {
|
|
27
|
+
const testValue = toString(input).trim()
|
|
28
|
+
.replace(/\D/g, '');
|
|
29
|
+
return inNumberRange(testValue.length, { min: 7, max: 20, inclusive: true });
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=phone-number.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phone-number.js","sourceRoot":"","sources":["../../src/phone-number.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAEvD,MAAM,UAAU,gBAAgB,CAAC,KAAsB;IACnD,MAAM,YAAY,GAAG,gBAAgB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAE9D,MAAM,UAAU,GAAG,iBAAiB,CAAC,YAAY,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC;IAChE,IAAI,UAAU;QAAE,OAAO,MAAM,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAEnD,MAAM,KAAK,CAAC,+CAA+C,CAAC,CAAC;AACjE,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAa;IACnC,IAAI,UAAU,GAAG,KAAK,CAAC;IAEvB,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG;QAAE,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAEnE,IAAI,UAAU,CAAC,MAAM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