@player-ui/common-types-plugin 0.15.1 → 0.15.2-next.0
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/CommonTypesPlugin.native.js +2 -2
- package/dist/CommonTypesPlugin.native.js.map +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +0 -785
- package/dist/index.mjs.map +1 -1
- package/dist/xlr/DataTypes.BooleanType.json +72 -0
- package/dist/xlr/DataTypes.CollectionType.json +39 -0
- package/dist/xlr/DataTypes.DateType.json +55 -0
- package/dist/xlr/DataTypes.IntegerNNType.json +75 -0
- package/dist/xlr/DataTypes.IntegerPosType.json +75 -0
- package/dist/xlr/DataTypes.IntegerType.json +55 -0
- package/dist/xlr/DataTypes.PhoneType.json +55 -0
- package/dist/xlr/DataTypes.StringType.json +62 -0
- package/dist/xlr/Formatters.commaNumber.json +28 -0
- package/dist/xlr/Formatters.currency.json +44 -0
- package/dist/xlr/Formatters.date.json +28 -0
- package/dist/xlr/Formatters.integer.json +14 -0
- package/dist/xlr/Formatters.phone.json +11 -0
- package/dist/xlr/Validators.collection.json +6 -0
- package/dist/xlr/Validators.email.json +6 -0
- package/dist/xlr/Validators.expression.json +23 -0
- package/dist/xlr/Validators.integer.json +6 -0
- package/dist/xlr/Validators.length.json +49 -0
- package/dist/xlr/Validators.max.json +22 -0
- package/dist/xlr/Validators.min.json +22 -0
- package/dist/xlr/Validators.oneOf.json +25 -0
- package/dist/xlr/Validators.phone.json +6 -0
- package/dist/xlr/Validators.readonly.json +6 -0
- package/dist/xlr/Validators.regex.json +22 -0
- package/dist/xlr/Validators.required.json +32 -0
- package/dist/xlr/Validators.string.json +6 -0
- package/dist/xlr/Validators.zip.json +6 -0
- package/dist/xlr/manifest.js +42 -0
- package/dist/xlr/manifest.json +51 -0
- package/package.json +6 -4
- package/src/index.ts +44 -2
- package/src/validators/index.ts +3 -3
- package/types/index.d.ts +24 -1
package/dist/index.legacy-esm.js
CHANGED
|
@@ -1,785 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __export = (target, all) => {
|
|
3
|
-
for (var name in all)
|
|
4
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/common-types/core/src/index.ts
|
|
8
|
-
import { TypesProviderPlugin } from "@player-ui/types-provider-plugin";
|
|
9
|
-
|
|
10
|
-
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/common-types/core/src/validators/index.ts
|
|
11
|
-
var validators_exports = {};
|
|
12
|
-
__export(validators_exports, {
|
|
13
|
-
collection: () => collection,
|
|
14
|
-
email: () => email,
|
|
15
|
-
expression: () => expression,
|
|
16
|
-
integer: () => integer,
|
|
17
|
-
length: () => length,
|
|
18
|
-
max: () => max,
|
|
19
|
-
min: () => min,
|
|
20
|
-
oneOf: () => oneOf,
|
|
21
|
-
phone: () => phone,
|
|
22
|
-
readonly: () => readonly,
|
|
23
|
-
regex: () => regex,
|
|
24
|
-
required: () => required,
|
|
25
|
-
string: () => string,
|
|
26
|
-
zip: () => zip
|
|
27
|
-
});
|
|
28
|
-
import { resolveDataRefs } from "@player-ui/player";
|
|
29
|
-
var EMAIL_REGEX = (
|
|
30
|
-
// eslint-disable-next-line no-control-regex
|
|
31
|
-
/^((([a-z]|\d|[!#$%&'*+\-/=?^_`{|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#$%&'*+-/=?^_`{|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i
|
|
32
|
-
);
|
|
33
|
-
var PHONE_REGEX = /^\+?[1]?[- ]?\(?\d{3}[)\- ]?\s?\d{3}[ -]?\d{4}$/;
|
|
34
|
-
var ZIP_REGEX = /^\d{5}(-\d{4})?$/;
|
|
35
|
-
function skipNullish(validationFn) {
|
|
36
|
-
return (context, value, options) => {
|
|
37
|
-
if (value === null || value === void 0) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
return validationFn(context, value, options);
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
var string = skipNullish((context, value) => {
|
|
44
|
-
if (typeof value !== "string") {
|
|
45
|
-
const message = context.constants.getConstants(
|
|
46
|
-
"validation.string",
|
|
47
|
-
"constants",
|
|
48
|
-
"Value must be a string"
|
|
49
|
-
);
|
|
50
|
-
return {
|
|
51
|
-
message,
|
|
52
|
-
parameters: {
|
|
53
|
-
type: typeof value
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
var readonly = (context) => {
|
|
59
|
-
const message = context.constants.getConstants(
|
|
60
|
-
"validation.readonly",
|
|
61
|
-
"constants",
|
|
62
|
-
"Value cannot be modified"
|
|
63
|
-
);
|
|
64
|
-
return { message };
|
|
65
|
-
};
|
|
66
|
-
var collection = skipNullish((context, value) => {
|
|
67
|
-
if (!Array.isArray(value)) {
|
|
68
|
-
const message = context.constants.getConstants(
|
|
69
|
-
"validation.collection",
|
|
70
|
-
"constants",
|
|
71
|
-
"Cannot set collection to non-array"
|
|
72
|
-
);
|
|
73
|
-
return { message };
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
var integer = skipNullish((context, value) => {
|
|
77
|
-
if (value && (typeof value !== "number" || Math.floor(value) !== value || Number(value) > Number.MAX_SAFE_INTEGER || Number(value) < Number.MIN_SAFE_INTEGER)) {
|
|
78
|
-
const message = context.constants.getConstants(
|
|
79
|
-
"validation.integer",
|
|
80
|
-
"constants",
|
|
81
|
-
"Value must be an integer"
|
|
82
|
-
);
|
|
83
|
-
return {
|
|
84
|
-
message,
|
|
85
|
-
parameters: {
|
|
86
|
-
type: typeof value,
|
|
87
|
-
flooredValue: Math.floor(value)
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
var oneOf = skipNullish((context, value, options) => {
|
|
93
|
-
if (options?.options === void 0 || options.options?.includes(value)) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
const message = context.constants.getConstants(
|
|
97
|
-
"validation.oneOf",
|
|
98
|
-
"constants",
|
|
99
|
-
"Invalid entry"
|
|
100
|
-
);
|
|
101
|
-
return { message };
|
|
102
|
-
});
|
|
103
|
-
var expression = (context, value, options) => {
|
|
104
|
-
if (options?.exp === void 0) {
|
|
105
|
-
context.logger.warn("No expression defined for validation");
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
const result = context.evaluate(options.exp);
|
|
109
|
-
if (!result) {
|
|
110
|
-
const message = context.constants.getConstants(
|
|
111
|
-
"validation.expression",
|
|
112
|
-
"constants",
|
|
113
|
-
"Expression evaluation failed"
|
|
114
|
-
);
|
|
115
|
-
return { message };
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
var required = (context, value, options) => {
|
|
119
|
-
if (options?.if && !context.evaluate(options.if) || options?.ifNot && context.evaluate(options.ifNot)) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
if (value === void 0 || value === null || value === "") {
|
|
123
|
-
const message = context.constants.getConstants(
|
|
124
|
-
"validation.required",
|
|
125
|
-
"constants",
|
|
126
|
-
"A value is required"
|
|
127
|
-
);
|
|
128
|
-
return { message, severity: "error" };
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
var regex = skipNullish((context, value, options) => {
|
|
132
|
-
if (value === void 0 || value === null || value === "" || typeof options?.regex !== "string") {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
const resolvedRegex = resolveDataRefs(options.regex, context);
|
|
136
|
-
const patternMatch = resolvedRegex.match(/^\/(.*)\/(\w)*$/);
|
|
137
|
-
const regexp = patternMatch ? new RegExp(patternMatch[1], patternMatch[2]) : new RegExp(resolvedRegex);
|
|
138
|
-
if (!regexp.test(value)) {
|
|
139
|
-
const message = context.constants.getConstants(
|
|
140
|
-
"validation.regex",
|
|
141
|
-
"constants",
|
|
142
|
-
"Invalid entry"
|
|
143
|
-
);
|
|
144
|
-
return { message };
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
var length = skipNullish((context, value, options) => {
|
|
148
|
-
if (typeof options !== "object") {
|
|
149
|
-
context.logger.warn("Missing comparison in length validation");
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
let valLength;
|
|
153
|
-
let itemName = "items";
|
|
154
|
-
if (typeof value === "string") {
|
|
155
|
-
valLength = value.length;
|
|
156
|
-
itemName = "characters";
|
|
157
|
-
} else if (typeof value === "object" && value !== null) {
|
|
158
|
-
valLength = Object.keys(value).length;
|
|
159
|
-
}
|
|
160
|
-
if (valLength === void 0) {
|
|
161
|
-
context.logger.warn(
|
|
162
|
-
`Unable to determine a length for value of type: ${value}`
|
|
163
|
-
);
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
if ("exact" in options) {
|
|
167
|
-
if (valLength !== options.exact) {
|
|
168
|
-
return {
|
|
169
|
-
message: `Must be exactly ${options.exact} ${itemName} long`,
|
|
170
|
-
parameters: {
|
|
171
|
-
validationLength: valLength
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
if (options.min !== void 0 && valLength < options.min) {
|
|
178
|
-
const message = context.constants.getConstants(
|
|
179
|
-
"validation.length.minimum",
|
|
180
|
-
"constants",
|
|
181
|
-
`At least ${options.min} ${itemName} needed`
|
|
182
|
-
);
|
|
183
|
-
return {
|
|
184
|
-
message,
|
|
185
|
-
parameters: {
|
|
186
|
-
validationLength: valLength
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
if (options.max !== void 0 && valLength > options.max) {
|
|
191
|
-
const message = context.constants.getConstants(
|
|
192
|
-
"validation.length.maximum",
|
|
193
|
-
"constants",
|
|
194
|
-
`Up to ${options.max} ${itemName} allowed`
|
|
195
|
-
);
|
|
196
|
-
return {
|
|
197
|
-
message,
|
|
198
|
-
parameters: {
|
|
199
|
-
validationLength: valLength
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
var min = skipNullish((context, value, options) => {
|
|
205
|
-
if (typeof value !== "number" || options?.value === void 0) {
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
if (value < options.value) {
|
|
209
|
-
const message = context.constants.getConstants(
|
|
210
|
-
"validation.min",
|
|
211
|
-
"constants",
|
|
212
|
-
`Must be at least ${options.value}`
|
|
213
|
-
);
|
|
214
|
-
return { message };
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
var max = skipNullish((context, value, options) => {
|
|
218
|
-
if (typeof value !== "number" || options?.value === void 0) {
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
if (value > options.value) {
|
|
222
|
-
const message = context.constants.getConstants(
|
|
223
|
-
"validation.max",
|
|
224
|
-
"constants",
|
|
225
|
-
`Cannot exceed ${options.value}`
|
|
226
|
-
);
|
|
227
|
-
return { message };
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
var stringRegexValidator = (test, messagePath, invalidMessage) => {
|
|
231
|
-
return skipNullish((context, value) => {
|
|
232
|
-
if (typeof value === "string" && value === "") {
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
if (typeof value !== "string" || !test.test(value)) {
|
|
236
|
-
const message = context.constants.getConstants(
|
|
237
|
-
messagePath,
|
|
238
|
-
"constants",
|
|
239
|
-
invalidMessage
|
|
240
|
-
);
|
|
241
|
-
return { message };
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
};
|
|
245
|
-
var email = stringRegexValidator(
|
|
246
|
-
EMAIL_REGEX,
|
|
247
|
-
"validation.email",
|
|
248
|
-
"Improper email format"
|
|
249
|
-
);
|
|
250
|
-
var phone = stringRegexValidator(
|
|
251
|
-
PHONE_REGEX,
|
|
252
|
-
"validation.phone",
|
|
253
|
-
"Invalid phone number"
|
|
254
|
-
);
|
|
255
|
-
var zip = stringRegexValidator(
|
|
256
|
-
ZIP_REGEX,
|
|
257
|
-
"validation.regex",
|
|
258
|
-
"Invalid zip code"
|
|
259
|
-
);
|
|
260
|
-
|
|
261
|
-
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/common-types/core/src/data-types/types.ts
|
|
262
|
-
var types_exports = {};
|
|
263
|
-
__export(types_exports, {
|
|
264
|
-
BooleanType: () => BooleanType,
|
|
265
|
-
CollectionType: () => CollectionType,
|
|
266
|
-
DateType: () => DateType,
|
|
267
|
-
IntegerNNType: () => IntegerNNType,
|
|
268
|
-
IntegerPosType: () => IntegerPosType,
|
|
269
|
-
IntegerType: () => IntegerType,
|
|
270
|
-
PhoneType: () => PhoneType,
|
|
271
|
-
StringType: () => StringType
|
|
272
|
-
});
|
|
273
|
-
var BooleanType = {
|
|
274
|
-
type: "BooleanType",
|
|
275
|
-
default: false,
|
|
276
|
-
validation: [
|
|
277
|
-
{
|
|
278
|
-
type: "oneOf",
|
|
279
|
-
message: "Value must be true or false",
|
|
280
|
-
options: [true, false]
|
|
281
|
-
}
|
|
282
|
-
]
|
|
283
|
-
};
|
|
284
|
-
var IntegerType = {
|
|
285
|
-
type: "IntegerType",
|
|
286
|
-
validation: [
|
|
287
|
-
{
|
|
288
|
-
type: "integer"
|
|
289
|
-
}
|
|
290
|
-
],
|
|
291
|
-
format: {
|
|
292
|
-
type: "integer"
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
var IntegerPosType = {
|
|
296
|
-
type: "IntegerPosType",
|
|
297
|
-
validation: [
|
|
298
|
-
{
|
|
299
|
-
type: "integer"
|
|
300
|
-
},
|
|
301
|
-
{
|
|
302
|
-
type: "min",
|
|
303
|
-
value: 1
|
|
304
|
-
}
|
|
305
|
-
],
|
|
306
|
-
format: {
|
|
307
|
-
type: "integer"
|
|
308
|
-
}
|
|
309
|
-
};
|
|
310
|
-
var IntegerNNType = {
|
|
311
|
-
type: "IntegerNNType",
|
|
312
|
-
validation: [
|
|
313
|
-
{
|
|
314
|
-
type: "integer"
|
|
315
|
-
},
|
|
316
|
-
{
|
|
317
|
-
type: "min",
|
|
318
|
-
value: 0
|
|
319
|
-
}
|
|
320
|
-
],
|
|
321
|
-
format: {
|
|
322
|
-
type: "integer"
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
var StringType = {
|
|
326
|
-
type: "StringType",
|
|
327
|
-
default: "",
|
|
328
|
-
validation: [
|
|
329
|
-
{
|
|
330
|
-
type: "string"
|
|
331
|
-
}
|
|
332
|
-
],
|
|
333
|
-
format: {
|
|
334
|
-
type: "string"
|
|
335
|
-
}
|
|
336
|
-
};
|
|
337
|
-
var CollectionType = {
|
|
338
|
-
type: "CollectionType",
|
|
339
|
-
validation: [
|
|
340
|
-
{
|
|
341
|
-
type: "collection"
|
|
342
|
-
}
|
|
343
|
-
]
|
|
344
|
-
};
|
|
345
|
-
var DateType = {
|
|
346
|
-
type: "DateType",
|
|
347
|
-
validation: [
|
|
348
|
-
{
|
|
349
|
-
type: "string"
|
|
350
|
-
}
|
|
351
|
-
],
|
|
352
|
-
format: {
|
|
353
|
-
type: "date"
|
|
354
|
-
}
|
|
355
|
-
};
|
|
356
|
-
var PhoneType = {
|
|
357
|
-
type: "PhoneType",
|
|
358
|
-
validation: [
|
|
359
|
-
{
|
|
360
|
-
type: "phone"
|
|
361
|
-
}
|
|
362
|
-
],
|
|
363
|
-
format: {
|
|
364
|
-
type: "phone"
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/common-types/core/src/formats/index.ts
|
|
369
|
-
var formats_exports = {};
|
|
370
|
-
__export(formats_exports, {
|
|
371
|
-
commaNumber: () => commaNumber,
|
|
372
|
-
currency: () => currency,
|
|
373
|
-
date: () => date,
|
|
374
|
-
integer: () => integer2,
|
|
375
|
-
phone: () => phone2
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/common-types/core/src/formats/utils.ts
|
|
379
|
-
var PLACEHOLDER = "#";
|
|
380
|
-
var removeFormatCharactersFromMaskedString = (value, mask, reserved = [PLACEHOLDER]) => {
|
|
381
|
-
const reservedMatchesLength = mask.split("").filter((val) => reserved.includes(val)).length;
|
|
382
|
-
let replacements = 0;
|
|
383
|
-
return value.split("").reduce((newString, nextChar, nextIndex) => {
|
|
384
|
-
const maskedVal = mask[nextIndex];
|
|
385
|
-
if (maskedVal === void 0) {
|
|
386
|
-
return newString;
|
|
387
|
-
}
|
|
388
|
-
if (reservedMatchesLength === replacements) {
|
|
389
|
-
return newString;
|
|
390
|
-
}
|
|
391
|
-
if (reserved.includes(maskedVal)) {
|
|
392
|
-
replacements++;
|
|
393
|
-
return newString + nextChar;
|
|
394
|
-
}
|
|
395
|
-
if (maskedVal !== nextChar) {
|
|
396
|
-
replacements++;
|
|
397
|
-
return newString + nextChar;
|
|
398
|
-
}
|
|
399
|
-
return newString;
|
|
400
|
-
}, "");
|
|
401
|
-
};
|
|
402
|
-
var formatAsEnum = (value, acceptedValues, options) => {
|
|
403
|
-
const autoCompletionsByOverlapCount = acceptedValues.reduce((validCompletions, validValue) => {
|
|
404
|
-
let overlap = 0;
|
|
405
|
-
for (let charIndex = 0; charIndex < Math.min(validValue.length, value.length); charIndex++) {
|
|
406
|
-
const validChar = options?.ignoreCase ? validValue[charIndex].toLowerCase() : validValue[charIndex];
|
|
407
|
-
const actualChar = options?.ignoreCase ? value[charIndex].toLowerCase() : value[charIndex];
|
|
408
|
-
if (validChar !== actualChar) {
|
|
409
|
-
break;
|
|
410
|
-
}
|
|
411
|
-
overlap += 1;
|
|
412
|
-
}
|
|
413
|
-
if (overlap === 0) {
|
|
414
|
-
return validCompletions;
|
|
415
|
-
}
|
|
416
|
-
validCompletions.push({
|
|
417
|
-
count: overlap,
|
|
418
|
-
target: validValue
|
|
419
|
-
});
|
|
420
|
-
return validCompletions;
|
|
421
|
-
}, []).sort((e) => e.count);
|
|
422
|
-
if (autoCompletionsByOverlapCount.length === 0) {
|
|
423
|
-
return void 0;
|
|
424
|
-
}
|
|
425
|
-
if (autoCompletionsByOverlapCount.length === 1 && options?.autocomplete) {
|
|
426
|
-
return autoCompletionsByOverlapCount[0].target;
|
|
427
|
-
}
|
|
428
|
-
return autoCompletionsByOverlapCount[0].target.substr(
|
|
429
|
-
0,
|
|
430
|
-
autoCompletionsByOverlapCount[0].count
|
|
431
|
-
);
|
|
432
|
-
};
|
|
433
|
-
var formatAsMasked = (value, valueCharMaskMatch, mask) => {
|
|
434
|
-
const valStr = String(value);
|
|
435
|
-
let withMask = mask;
|
|
436
|
-
if (valStr.trim() === "") {
|
|
437
|
-
return "";
|
|
438
|
-
}
|
|
439
|
-
valStr.replace(valueCharMaskMatch, (match) => {
|
|
440
|
-
withMask = withMask.replace(PLACEHOLDER, match);
|
|
441
|
-
return match;
|
|
442
|
-
});
|
|
443
|
-
return withMask.split(PLACEHOLDER)[0];
|
|
444
|
-
};
|
|
445
|
-
var createMaskedNumericFormatter = (name, mask) => {
|
|
446
|
-
return {
|
|
447
|
-
name,
|
|
448
|
-
format: (value, options) => {
|
|
449
|
-
if (typeof value !== "string") {
|
|
450
|
-
return value;
|
|
451
|
-
}
|
|
452
|
-
if (options?.exceptions && options.exceptions.length > 0) {
|
|
453
|
-
const formattedUsingExceptions = formatAsEnum(
|
|
454
|
-
value,
|
|
455
|
-
options.exceptions,
|
|
456
|
-
{
|
|
457
|
-
autocomplete: true,
|
|
458
|
-
ignoreCase: true
|
|
459
|
-
}
|
|
460
|
-
);
|
|
461
|
-
if (formattedUsingExceptions !== void 0) {
|
|
462
|
-
return formattedUsingExceptions;
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
return formatAsMasked(value, /\d/g, mask);
|
|
466
|
-
},
|
|
467
|
-
deformat: (value, options) => {
|
|
468
|
-
if (typeof value !== "string") {
|
|
469
|
-
return value;
|
|
470
|
-
}
|
|
471
|
-
if (options?.exceptions && options.exceptions.length > 0) {
|
|
472
|
-
const usingExceptions = formatAsEnum(value, options.exceptions, {
|
|
473
|
-
autocomplete: false,
|
|
474
|
-
ignoreCase: false
|
|
475
|
-
});
|
|
476
|
-
if (usingExceptions !== void 0) {
|
|
477
|
-
return usingExceptions;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
return formatAsMasked(value, /\d/g, mask.replace(/[^#]/g, ""));
|
|
481
|
-
}
|
|
482
|
-
};
|
|
483
|
-
};
|
|
484
|
-
|
|
485
|
-
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/common-types/core/src/formats/index.ts
|
|
486
|
-
var LENGTH_OF_MAX_INT = String(Number.MAX_SAFE_INTEGER).split("").length;
|
|
487
|
-
var integer2 = {
|
|
488
|
-
name: "integer",
|
|
489
|
-
/** Converts any integer to a string */
|
|
490
|
-
format: (value) => {
|
|
491
|
-
if (value === "-") {
|
|
492
|
-
return value;
|
|
493
|
-
}
|
|
494
|
-
const formatted = integer2.deformat?.(value) ?? value;
|
|
495
|
-
if (typeof formatted === "number") {
|
|
496
|
-
return String(formatted);
|
|
497
|
-
}
|
|
498
|
-
return "";
|
|
499
|
-
},
|
|
500
|
-
/** Converts any string or number to an integer */
|
|
501
|
-
deformat: (value) => {
|
|
502
|
-
if (typeof value === "number") {
|
|
503
|
-
return Math.floor(value) + 0;
|
|
504
|
-
}
|
|
505
|
-
if (typeof value !== "string") {
|
|
506
|
-
return;
|
|
507
|
-
}
|
|
508
|
-
const isNeg = value.replace(/[^0-9.-]/g, "").charAt(0) === "-";
|
|
509
|
-
let digits = value.replace(/[^0-9.]/g, "");
|
|
510
|
-
const decimalPlace = digits.indexOf(".");
|
|
511
|
-
if (decimalPlace > -1) {
|
|
512
|
-
digits = digits.substring(0, decimalPlace);
|
|
513
|
-
}
|
|
514
|
-
if (digits.length === 0) {
|
|
515
|
-
return;
|
|
516
|
-
}
|
|
517
|
-
digits = digits.substr(0, LENGTH_OF_MAX_INT);
|
|
518
|
-
const num = Number(`${isNeg ? "-" : ""}${digits}`);
|
|
519
|
-
return Math.floor(num) + 0;
|
|
520
|
-
}
|
|
521
|
-
};
|
|
522
|
-
var commaNumber = {
|
|
523
|
-
name: "commaNumber",
|
|
524
|
-
/** Go from number to number w/ commas */
|
|
525
|
-
format: (_value, options) => {
|
|
526
|
-
if (_value === void 0 || _value === "") {
|
|
527
|
-
return _value;
|
|
528
|
-
}
|
|
529
|
-
if (typeof _value !== "string" && typeof _value !== "number") {
|
|
530
|
-
return "";
|
|
531
|
-
}
|
|
532
|
-
const value = String(_value);
|
|
533
|
-
const isNeg = value.replace(/[^0-9.-]/g, "").charAt(0) === "-";
|
|
534
|
-
let digitAndDecimal = value.replace(/[^0-9.]/g, "");
|
|
535
|
-
digitAndDecimal = digitAndDecimal.replace(/^(0*)((0.)?\d)/g, "$2");
|
|
536
|
-
const firstDecimal = digitAndDecimal.indexOf(".");
|
|
537
|
-
const digitsOnly = digitAndDecimal.replace(/[^0-9]/g, "");
|
|
538
|
-
let preDecDigits = digitsOnly;
|
|
539
|
-
let postDecDigits = "";
|
|
540
|
-
if (firstDecimal >= 0) {
|
|
541
|
-
preDecDigits = digitsOnly.substring(0, firstDecimal).substr(0, LENGTH_OF_MAX_INT);
|
|
542
|
-
postDecDigits = digitsOnly.substring(firstDecimal);
|
|
543
|
-
} else {
|
|
544
|
-
preDecDigits = preDecDigits.substr(0, LENGTH_OF_MAX_INT);
|
|
545
|
-
}
|
|
546
|
-
if (options?.precision !== void 0) {
|
|
547
|
-
postDecDigits = postDecDigits.substring(0, options.precision).padEnd(options.precision, "0");
|
|
548
|
-
}
|
|
549
|
-
preDecDigits = preDecDigits.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
550
|
-
if (preDecDigits === "" && firstDecimal === 0) {
|
|
551
|
-
preDecDigits = "0";
|
|
552
|
-
}
|
|
553
|
-
let retVal = preDecDigits;
|
|
554
|
-
if (isNeg) {
|
|
555
|
-
retVal = `-${retVal}`;
|
|
556
|
-
}
|
|
557
|
-
if ((firstDecimal >= 0 || options?.precision !== void 0) && postDecDigits !== "") {
|
|
558
|
-
retVal += `.${postDecDigits}`;
|
|
559
|
-
}
|
|
560
|
-
return retVal;
|
|
561
|
-
},
|
|
562
|
-
/** Go from string with comma's to numbers */
|
|
563
|
-
deformat: (value) => {
|
|
564
|
-
if (typeof value !== "string") {
|
|
565
|
-
return value;
|
|
566
|
-
}
|
|
567
|
-
const strValue = value.replace(/,/g, "");
|
|
568
|
-
if (strValue === "") {
|
|
569
|
-
return void 0;
|
|
570
|
-
}
|
|
571
|
-
const number = Number(strValue);
|
|
572
|
-
return isNaN(number) || number > Number.MAX_SAFE_INTEGER || number < Number.MIN_SAFE_INTEGER ? void 0 : number;
|
|
573
|
-
}
|
|
574
|
-
};
|
|
575
|
-
var date = {
|
|
576
|
-
name: "date",
|
|
577
|
-
format: (_value, options) => {
|
|
578
|
-
let value = typeof _value === "number" ? String(_value) : _value;
|
|
579
|
-
if (_value === void 0) {
|
|
580
|
-
return void 0;
|
|
581
|
-
}
|
|
582
|
-
if (typeof value !== "string" || value === "") {
|
|
583
|
-
return "";
|
|
584
|
-
}
|
|
585
|
-
if (value.match(/^\d{4}[-]\d{1,2}[-]\d{1,2}$/)) {
|
|
586
|
-
const tempVal = value.split("-");
|
|
587
|
-
value = `${tempVal[1]}/${tempVal[2]}/${tempVal[0]}`;
|
|
588
|
-
}
|
|
589
|
-
const dateFormat = options?.mask?.toUpperCase() ?? "MM/DD/YYYY";
|
|
590
|
-
const delimiter = dateFormat.replace(/[^/.-]/g, "").charAt(0);
|
|
591
|
-
const formatParts = dateFormat.split(delimiter);
|
|
592
|
-
const valueParts = value.split(delimiter);
|
|
593
|
-
const processedValueParts = [];
|
|
594
|
-
let lastMatchIsFull = true;
|
|
595
|
-
for (let index = 0; index < valueParts.length; index++) {
|
|
596
|
-
let part = valueParts[index];
|
|
597
|
-
if (lastMatchIsFull && index < formatParts.length) {
|
|
598
|
-
part = part.replace(/[^0-9]/g, "");
|
|
599
|
-
const isLastExpectedField = formatParts.length - 1 === index;
|
|
600
|
-
const hasDelimiterAfter = valueParts.length - 1 > index;
|
|
601
|
-
const curFormat = formatParts[index];
|
|
602
|
-
if (curFormat === "YYYY") {
|
|
603
|
-
if (part.length > 4) {
|
|
604
|
-
valueParts[index + 1] = [
|
|
605
|
-
"*",
|
|
606
|
-
part.substring(4),
|
|
607
|
-
valueParts[index + 1]
|
|
608
|
-
].join("");
|
|
609
|
-
part = part.substring(0, 4);
|
|
610
|
-
}
|
|
611
|
-
if (part.length === 4) {
|
|
612
|
-
lastMatchIsFull = true;
|
|
613
|
-
processedValueParts.push(part);
|
|
614
|
-
}
|
|
615
|
-
if (part.length === 3) {
|
|
616
|
-
if (isLastExpectedField || !hasDelimiterAfter) {
|
|
617
|
-
lastMatchIsFull = false;
|
|
618
|
-
processedValueParts.push(part);
|
|
619
|
-
} else {
|
|
620
|
-
valueParts[index + 1] = `*${part.substring(2)}${valueParts[index + 1]}`;
|
|
621
|
-
part = part.substring(0, 2);
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
if (part.length === 2) {
|
|
625
|
-
let autocomplete;
|
|
626
|
-
if (part.length === 2 && (hasDelimiterAfter || isLastExpectedField && part !== "19" && part !== "20")) {
|
|
627
|
-
autocomplete = `20${part}`;
|
|
628
|
-
if (part > ((/* @__PURE__ */ new Date()).getFullYear() + 5).toString().substring(2)) {
|
|
629
|
-
autocomplete = `19${part}`;
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
if (autocomplete) {
|
|
633
|
-
lastMatchIsFull = true;
|
|
634
|
-
processedValueParts.push(autocomplete);
|
|
635
|
-
} else {
|
|
636
|
-
lastMatchIsFull = false;
|
|
637
|
-
processedValueParts.push(part);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
if (part.length === 1 || part.length === 0) {
|
|
641
|
-
lastMatchIsFull = false;
|
|
642
|
-
processedValueParts.push(part);
|
|
643
|
-
}
|
|
644
|
-
} else if (curFormat === "YY") {
|
|
645
|
-
if (part.length > 2) {
|
|
646
|
-
valueParts[index + 1] = [
|
|
647
|
-
"*",
|
|
648
|
-
part.substring(2),
|
|
649
|
-
valueParts[index + 1]
|
|
650
|
-
].join("");
|
|
651
|
-
part = part.substring(0, 2);
|
|
652
|
-
}
|
|
653
|
-
if (part.length === 2) {
|
|
654
|
-
lastMatchIsFull = true;
|
|
655
|
-
processedValueParts.push(part);
|
|
656
|
-
}
|
|
657
|
-
if (part.length === 1 || part.length === 0) {
|
|
658
|
-
lastMatchIsFull = false;
|
|
659
|
-
processedValueParts.push(part);
|
|
660
|
-
}
|
|
661
|
-
} else {
|
|
662
|
-
if (part.length > 2) {
|
|
663
|
-
valueParts[index + 1] = [
|
|
664
|
-
"*",
|
|
665
|
-
part.substring(2),
|
|
666
|
-
valueParts[index + 1]
|
|
667
|
-
].join("");
|
|
668
|
-
part = part.substring(0, 2);
|
|
669
|
-
}
|
|
670
|
-
if (part.length === 2) {
|
|
671
|
-
if (part === "00" && !hasDelimiterAfter) {
|
|
672
|
-
lastMatchIsFull = false;
|
|
673
|
-
processedValueParts.push("0");
|
|
674
|
-
} else {
|
|
675
|
-
lastMatchIsFull = true;
|
|
676
|
-
processedValueParts.push(part);
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
if (part.length === 1) {
|
|
680
|
-
if (hasDelimiterAfter) {
|
|
681
|
-
lastMatchIsFull = true;
|
|
682
|
-
processedValueParts.push(`0${part}`);
|
|
683
|
-
} else {
|
|
684
|
-
lastMatchIsFull = false;
|
|
685
|
-
processedValueParts.push(part);
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
if (part.length === 0) {
|
|
689
|
-
lastMatchIsFull = false;
|
|
690
|
-
processedValueParts.push(part);
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
return processedValueParts.join(delimiter);
|
|
696
|
-
}
|
|
697
|
-
};
|
|
698
|
-
var currency = {
|
|
699
|
-
name: "currency",
|
|
700
|
-
format: (_value, options) => {
|
|
701
|
-
const value = typeof _value === "number" ? String(_value) : _value;
|
|
702
|
-
const {
|
|
703
|
-
currencySymbol = "",
|
|
704
|
-
useParensForNeg = false,
|
|
705
|
-
precision = 2
|
|
706
|
-
} = options ?? {};
|
|
707
|
-
if (value === void 0 || value === "") {
|
|
708
|
-
return value;
|
|
709
|
-
}
|
|
710
|
-
if (typeof value !== "string") {
|
|
711
|
-
return value;
|
|
712
|
-
}
|
|
713
|
-
const sign = /^\s*-/.test(value) ? -1 : 1;
|
|
714
|
-
const dotIndex = value.indexOf(".");
|
|
715
|
-
let preDecimal;
|
|
716
|
-
let postDecimal;
|
|
717
|
-
if (dotIndex >= 0) {
|
|
718
|
-
preDecimal = value.substr(0, dotIndex).replace(/\D+/g, "");
|
|
719
|
-
postDecimal = value.substr(dotIndex + 1).replace(/\D+/g, "");
|
|
720
|
-
} else {
|
|
721
|
-
preDecimal = value.replace(/\D+/g, "");
|
|
722
|
-
postDecimal = "0";
|
|
723
|
-
}
|
|
724
|
-
const numericalValue = sign * Number(`${preDecimal}.${postDecimal}`);
|
|
725
|
-
const fixedString = numericalValue.toFixed(precision);
|
|
726
|
-
const prettyString = fixedString.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
727
|
-
if (prettyString.charAt(0) === "-") {
|
|
728
|
-
if (useParensForNeg) {
|
|
729
|
-
return `(${currencySymbol}${prettyString.substring(1)})`;
|
|
730
|
-
}
|
|
731
|
-
return `-${currencySymbol}${prettyString.substring(1)}`;
|
|
732
|
-
}
|
|
733
|
-
return currencySymbol + prettyString;
|
|
734
|
-
},
|
|
735
|
-
deformat: (value, options) => {
|
|
736
|
-
if (typeof value === "number") {
|
|
737
|
-
return value;
|
|
738
|
-
}
|
|
739
|
-
if (typeof value !== "string") {
|
|
740
|
-
return void 0;
|
|
741
|
-
}
|
|
742
|
-
let deformatted = value;
|
|
743
|
-
if (options?.currencySymbol) {
|
|
744
|
-
deformatted = value.replace(options.currencySymbol, "");
|
|
745
|
-
}
|
|
746
|
-
return commaNumber.deformat?.(deformatted);
|
|
747
|
-
}
|
|
748
|
-
};
|
|
749
|
-
var basePhoneFormatter = createMaskedNumericFormatter(
|
|
750
|
-
"phone",
|
|
751
|
-
"(###) ###-####"
|
|
752
|
-
);
|
|
753
|
-
var phone2 = {
|
|
754
|
-
...basePhoneFormatter,
|
|
755
|
-
deformat: (value) => basePhoneFormatter.deformat?.(value),
|
|
756
|
-
format: (value) => basePhoneFormatter.format?.(value === "(" ? "" : value) ?? value
|
|
757
|
-
};
|
|
758
|
-
|
|
759
|
-
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/common-types/core/src/index.ts
|
|
760
|
-
var CommonTypesPlugin = class {
|
|
761
|
-
constructor() {
|
|
762
|
-
this.name = "CommonTypes";
|
|
763
|
-
}
|
|
764
|
-
apply(player) {
|
|
765
|
-
player.registerPlugin(
|
|
766
|
-
new TypesProviderPlugin({
|
|
767
|
-
types: Object.values(types_exports),
|
|
768
|
-
formats: Object.values(formats_exports),
|
|
769
|
-
validators: Object.entries(validators_exports)
|
|
770
|
-
})
|
|
771
|
-
);
|
|
772
|
-
}
|
|
773
|
-
};
|
|
774
|
-
export {
|
|
775
|
-
CommonTypesPlugin,
|
|
776
|
-
PLACEHOLDER,
|
|
777
|
-
createMaskedNumericFormatter,
|
|
778
|
-
types_exports as dataTypes,
|
|
779
|
-
formatAsEnum,
|
|
780
|
-
formatAsMasked,
|
|
781
|
-
formats_exports as formats,
|
|
782
|
-
removeFormatCharactersFromMaskedString,
|
|
783
|
-
validators_exports as validators
|
|
784
|
-
};
|
|
785
|
-
//# sourceMappingURL=index.mjs.map
|