@player-ui/common-types-plugin 0.4.0-next.3 → 0.4.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.
|
@@ -0,0 +1,910 @@
|
|
|
1
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
|
3
|
+
module.exports = factory();
|
|
4
|
+
else if(typeof define === 'function' && define.amd)
|
|
5
|
+
define([], factory);
|
|
6
|
+
else if(typeof exports === 'object')
|
|
7
|
+
exports["CommonTypesPlugin"] = factory();
|
|
8
|
+
else
|
|
9
|
+
root["CommonTypesPlugin"] = factory();
|
|
10
|
+
})(this, function() {
|
|
11
|
+
return /******/ (function(modules) { // webpackBootstrap
|
|
12
|
+
/******/ // The module cache
|
|
13
|
+
/******/ var installedModules = {};
|
|
14
|
+
/******/
|
|
15
|
+
/******/ // The require function
|
|
16
|
+
/******/ function __webpack_require__(moduleId) {
|
|
17
|
+
/******/
|
|
18
|
+
/******/ // Check if module is in cache
|
|
19
|
+
/******/ if(installedModules[moduleId]) {
|
|
20
|
+
/******/ return installedModules[moduleId].exports;
|
|
21
|
+
/******/ }
|
|
22
|
+
/******/ // Create a new module (and put it into the cache)
|
|
23
|
+
/******/ var module = installedModules[moduleId] = {
|
|
24
|
+
/******/ i: moduleId,
|
|
25
|
+
/******/ l: false,
|
|
26
|
+
/******/ exports: {}
|
|
27
|
+
/******/ };
|
|
28
|
+
/******/
|
|
29
|
+
/******/ // Execute the module function
|
|
30
|
+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
|
31
|
+
/******/
|
|
32
|
+
/******/ // Flag the module as loaded
|
|
33
|
+
/******/ module.l = true;
|
|
34
|
+
/******/
|
|
35
|
+
/******/ // Return the exports of the module
|
|
36
|
+
/******/ return module.exports;
|
|
37
|
+
/******/ }
|
|
38
|
+
/******/
|
|
39
|
+
/******/
|
|
40
|
+
/******/ // expose the modules object (__webpack_modules__)
|
|
41
|
+
/******/ __webpack_require__.m = modules;
|
|
42
|
+
/******/
|
|
43
|
+
/******/ // expose the module cache
|
|
44
|
+
/******/ __webpack_require__.c = installedModules;
|
|
45
|
+
/******/
|
|
46
|
+
/******/ // define getter function for harmony exports
|
|
47
|
+
/******/ __webpack_require__.d = function(exports, name, getter) {
|
|
48
|
+
/******/ if(!__webpack_require__.o(exports, name)) {
|
|
49
|
+
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
|
50
|
+
/******/ }
|
|
51
|
+
/******/ };
|
|
52
|
+
/******/
|
|
53
|
+
/******/ // define __esModule on exports
|
|
54
|
+
/******/ __webpack_require__.r = function(exports) {
|
|
55
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
56
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
57
|
+
/******/ }
|
|
58
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
59
|
+
/******/ };
|
|
60
|
+
/******/
|
|
61
|
+
/******/ // create a fake namespace object
|
|
62
|
+
/******/ // mode & 1: value is a module id, require it
|
|
63
|
+
/******/ // mode & 2: merge all properties of value into the ns
|
|
64
|
+
/******/ // mode & 4: return value when already ns object
|
|
65
|
+
/******/ // mode & 8|1: behave like require
|
|
66
|
+
/******/ __webpack_require__.t = function(value, mode) {
|
|
67
|
+
/******/ if(mode & 1) value = __webpack_require__(value);
|
|
68
|
+
/******/ if(mode & 8) return value;
|
|
69
|
+
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
|
70
|
+
/******/ var ns = Object.create(null);
|
|
71
|
+
/******/ __webpack_require__.r(ns);
|
|
72
|
+
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
|
73
|
+
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
|
74
|
+
/******/ return ns;
|
|
75
|
+
/******/ };
|
|
76
|
+
/******/
|
|
77
|
+
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
78
|
+
/******/ __webpack_require__.n = function(module) {
|
|
79
|
+
/******/ var getter = module && module.__esModule ?
|
|
80
|
+
/******/ function getDefault() { return module['default']; } :
|
|
81
|
+
/******/ function getModuleExports() { return module; };
|
|
82
|
+
/******/ __webpack_require__.d(getter, 'a', getter);
|
|
83
|
+
/******/ return getter;
|
|
84
|
+
/******/ };
|
|
85
|
+
/******/
|
|
86
|
+
/******/ // Object.prototype.hasOwnProperty.call
|
|
87
|
+
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
|
88
|
+
/******/
|
|
89
|
+
/******/ // __webpack_public_path__
|
|
90
|
+
/******/ __webpack_require__.p = "";
|
|
91
|
+
/******/
|
|
92
|
+
/******/
|
|
93
|
+
/******/ // Load entry module and return exports
|
|
94
|
+
/******/ return __webpack_require__(__webpack_require__.s = "./bazel-out/k8-fastbuild/bin/plugins/common-types/core/dist/index.esm.js");
|
|
95
|
+
/******/ })
|
|
96
|
+
/************************************************************************/
|
|
97
|
+
/******/ ({
|
|
98
|
+
|
|
99
|
+
/***/ "./bazel-out/k8-fastbuild/bin/plugins/common-types/core/dist/index.esm.js":
|
|
100
|
+
/*!********************************************************************************!*\
|
|
101
|
+
!*** ./bazel-out/k8-fastbuild/bin/plugins/common-types/core/dist/index.esm.js ***!
|
|
102
|
+
\********************************************************************************/
|
|
103
|
+
/*! exports provided: CommonTypesPlugin, PLACEHOLDER, createMaskedNumericFormatter, dataRefs, dataTypes, formatAsEnum, formatAsMasked, formats, removeFormatCharactersFromMaskedString, validators */
|
|
104
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
105
|
+
|
|
106
|
+
"use strict";
|
|
107
|
+
__webpack_require__.r(__webpack_exports__);
|
|
108
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CommonTypesPlugin", function() { return CommonTypesPlugin; });
|
|
109
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "PLACEHOLDER", function() { return PLACEHOLDER; });
|
|
110
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "createMaskedNumericFormatter", function() { return createMaskedNumericFormatter; });
|
|
111
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "dataRefs", function() { return refs; });
|
|
112
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "dataTypes", function() { return dataTypes; });
|
|
113
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "formatAsEnum", function() { return formatAsEnum; });
|
|
114
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "formatAsMasked", function() { return formatAsMasked; });
|
|
115
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "formats", function() { return formats; });
|
|
116
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "removeFormatCharactersFromMaskedString", function() { return removeFormatCharactersFromMaskedString; });
|
|
117
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "validators", function() { return validators; });
|
|
118
|
+
/* harmony import */ var _player_ui_types_provider_plugin__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @player-ui/types-provider-plugin */ "./bazel-out/k8-fastbuild/bin/plugins/types-provider/core/dist/index.esm.js");
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
const EMAIL_REGEX = /^((([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;
|
|
122
|
+
const PHONE_REGEX = /^\+?[1]?[- ]?\(?\d{3}[)\- ]?\s?\d{3}[ -]?\d{4}$/;
|
|
123
|
+
const ZIP_REGEX = /^\d{5}(-\d{4})?$/;
|
|
124
|
+
function skipNullish(validationFn) {
|
|
125
|
+
return (context, value, options) => {
|
|
126
|
+
if (value === null || value === void 0) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
return validationFn(context, value, options);
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
const string = skipNullish((context, value) => {
|
|
133
|
+
if (typeof value !== "string") {
|
|
134
|
+
const message = context.constants.getConstants("validation.string", "constants", "Value must be a string");
|
|
135
|
+
return {
|
|
136
|
+
message,
|
|
137
|
+
parameters: {
|
|
138
|
+
type: typeof value
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
const readonly = (context) => {
|
|
144
|
+
const message = context.constants.getConstants("validation.readonly", "constants", "Value cannot be modified");
|
|
145
|
+
return { message };
|
|
146
|
+
};
|
|
147
|
+
const collection = skipNullish((context, value) => {
|
|
148
|
+
if (!Array.isArray(value)) {
|
|
149
|
+
const message = context.constants.getConstants("validation.collection", "constants", "Cannot set collection to non-array");
|
|
150
|
+
return { message };
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
const integer$1 = skipNullish((context, value) => {
|
|
154
|
+
if (value && (typeof value !== "number" || Math.floor(value) !== value || Number(value) > Number.MAX_SAFE_INTEGER || Number(value) < Number.MIN_SAFE_INTEGER)) {
|
|
155
|
+
const message = context.constants.getConstants("validation.integer", "constants", "Value must be an integer");
|
|
156
|
+
return {
|
|
157
|
+
message,
|
|
158
|
+
parameters: {
|
|
159
|
+
type: typeof value,
|
|
160
|
+
flooredValue: Math.floor(value)
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
const oneOf = skipNullish((context, value, options) => {
|
|
166
|
+
var _a;
|
|
167
|
+
if ((options == null ? void 0 : options.options) === void 0 || ((_a = options.options) == null ? void 0 : _a.includes(value))) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const message = context.constants.getConstants("validation.oneOf", "constants", "Invalid entry");
|
|
171
|
+
return { message };
|
|
172
|
+
});
|
|
173
|
+
const expression = (context, value, options) => {
|
|
174
|
+
if ((options == null ? void 0 : options.exp) === void 0) {
|
|
175
|
+
context.logger.warn("No expression defined for validation");
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
const result = context.evaluate(options.exp);
|
|
179
|
+
if (!result) {
|
|
180
|
+
const message = context.constants.getConstants("validation.expression", "constants", "Expression evaluation failed");
|
|
181
|
+
return { message };
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
const required = (context, value, options) => {
|
|
185
|
+
if ((options == null ? void 0 : options.if) && !context.evaluate(options.if) || (options == null ? void 0 : options.ifNot) && context.evaluate(options.ifNot)) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (value === void 0 || value === null || value === "") {
|
|
189
|
+
const message = context.constants.getConstants("validation.required", "constants", "A value is required");
|
|
190
|
+
return { message, severity: "error" };
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
const regex = skipNullish((context, value, options) => {
|
|
194
|
+
if (value === void 0 || value === null || value === "" || typeof (options == null ? void 0 : options.regex) !== "string") {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const patternMatch = options.regex.match(/^\/(.*)\/(\w)*$/);
|
|
198
|
+
const regexp = patternMatch ? new RegExp(patternMatch[1], patternMatch[2]) : new RegExp(options.regex);
|
|
199
|
+
if (!regexp.test(value)) {
|
|
200
|
+
const message = context.constants.getConstants("validation.regex", "constants", "Invalid entry");
|
|
201
|
+
return { message };
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
const length = skipNullish((context, value, options) => {
|
|
205
|
+
if (typeof options !== "object") {
|
|
206
|
+
context.logger.warn("Missing comparison in length validation");
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
let valLength;
|
|
210
|
+
let itemName = "items";
|
|
211
|
+
if (typeof value === "string") {
|
|
212
|
+
valLength = value.length;
|
|
213
|
+
itemName = "characters";
|
|
214
|
+
} else if (typeof value === "object" && value !== null) {
|
|
215
|
+
valLength = Object.keys(value).length;
|
|
216
|
+
}
|
|
217
|
+
if (valLength === void 0) {
|
|
218
|
+
context.logger.warn(`Unable to determine a length for value of type: ${value}`);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
if ("exact" in options) {
|
|
222
|
+
if (valLength !== options.exact) {
|
|
223
|
+
return {
|
|
224
|
+
message: `Must be exactly ${options.exact} ${itemName} long`,
|
|
225
|
+
parameters: {
|
|
226
|
+
validationLength: valLength
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (options.min !== void 0 && valLength < options.min) {
|
|
233
|
+
const message = context.constants.getConstants("validation.length.minimum", "constants", `At least ${options.min} ${itemName} needed`);
|
|
234
|
+
return {
|
|
235
|
+
message,
|
|
236
|
+
parameters: {
|
|
237
|
+
validationLength: valLength
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
if (options.max !== void 0 && valLength > options.max) {
|
|
242
|
+
const message = context.constants.getConstants("validation.length.maximum", "constants", `Up to ${options.max} ${itemName} allowed`);
|
|
243
|
+
return {
|
|
244
|
+
message,
|
|
245
|
+
parameters: {
|
|
246
|
+
validationLength: valLength
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
const min = skipNullish((context, value, options) => {
|
|
252
|
+
if (typeof value !== "number" || (options == null ? void 0 : options.value) === void 0) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
if (value < options.value) {
|
|
256
|
+
const message = context.constants.getConstants("validation.min", "constants", `Must be at least ${options.value}`);
|
|
257
|
+
return { message };
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
const max = skipNullish((context, value, options) => {
|
|
261
|
+
if (typeof value !== "number" || (options == null ? void 0 : options.value) === void 0) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
if (value > options.value) {
|
|
265
|
+
const message = context.constants.getConstants("validation.max", "constants", `Cannot exceed ${options.value}`);
|
|
266
|
+
return { message };
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
const stringRegexValidator = (test, messagePath, invalidMessage) => {
|
|
270
|
+
return skipNullish((context, value) => {
|
|
271
|
+
if (typeof value === "string" && value === "") {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
if (typeof value !== "string" || !test.test(value)) {
|
|
275
|
+
const message = context.constants.getConstants(messagePath, "constants", invalidMessage);
|
|
276
|
+
return { message };
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
};
|
|
280
|
+
const email = stringRegexValidator(EMAIL_REGEX, "validation.email", "Improper email format");
|
|
281
|
+
const phone$1 = stringRegexValidator(PHONE_REGEX, "validation.phone", "Invalid phone number");
|
|
282
|
+
const zip = stringRegexValidator(ZIP_REGEX, "validation.regex", "Invalid zip code");
|
|
283
|
+
|
|
284
|
+
var validators = /*#__PURE__*/Object.freeze({
|
|
285
|
+
__proto__: null,
|
|
286
|
+
string: string,
|
|
287
|
+
readonly: readonly,
|
|
288
|
+
collection: collection,
|
|
289
|
+
integer: integer$1,
|
|
290
|
+
oneOf: oneOf,
|
|
291
|
+
expression: expression,
|
|
292
|
+
required: required,
|
|
293
|
+
regex: regex,
|
|
294
|
+
length: length,
|
|
295
|
+
min: min,
|
|
296
|
+
max: max,
|
|
297
|
+
email: email,
|
|
298
|
+
phone: phone$1,
|
|
299
|
+
zip: zip
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
const BooleanTypeRef = {
|
|
303
|
+
type: "BooleanType"
|
|
304
|
+
};
|
|
305
|
+
const IntegerTypeRef = {
|
|
306
|
+
type: "IntegerType"
|
|
307
|
+
};
|
|
308
|
+
const IntegerPosTypeRef = {
|
|
309
|
+
type: "IntegerPosType"
|
|
310
|
+
};
|
|
311
|
+
const IntegerNNTypeRef = {
|
|
312
|
+
type: "IntegerNNType"
|
|
313
|
+
};
|
|
314
|
+
const StringTypeRef = {
|
|
315
|
+
type: "StringType"
|
|
316
|
+
};
|
|
317
|
+
const CollectionTypeRef = {
|
|
318
|
+
type: "CollectionType"
|
|
319
|
+
};
|
|
320
|
+
const DateTypeRef = {
|
|
321
|
+
type: "DateType"
|
|
322
|
+
};
|
|
323
|
+
const PhoneTypeRef = {
|
|
324
|
+
type: "PhoneType"
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
var refs = /*#__PURE__*/Object.freeze({
|
|
328
|
+
__proto__: null,
|
|
329
|
+
BooleanTypeRef: BooleanTypeRef,
|
|
330
|
+
IntegerTypeRef: IntegerTypeRef,
|
|
331
|
+
IntegerPosTypeRef: IntegerPosTypeRef,
|
|
332
|
+
IntegerNNTypeRef: IntegerNNTypeRef,
|
|
333
|
+
StringTypeRef: StringTypeRef,
|
|
334
|
+
CollectionTypeRef: CollectionTypeRef,
|
|
335
|
+
DateTypeRef: DateTypeRef,
|
|
336
|
+
PhoneTypeRef: PhoneTypeRef
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
var __defProp$1 = Object.defineProperty;
|
|
340
|
+
var __defProps$1 = Object.defineProperties;
|
|
341
|
+
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
342
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
343
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
344
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
345
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
346
|
+
var __spreadValues$1 = (a, b) => {
|
|
347
|
+
for (var prop in b || (b = {}))
|
|
348
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
349
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
350
|
+
if (__getOwnPropSymbols$1)
|
|
351
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
352
|
+
if (__propIsEnum$1.call(b, prop))
|
|
353
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
354
|
+
}
|
|
355
|
+
return a;
|
|
356
|
+
};
|
|
357
|
+
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
358
|
+
const BooleanType = __spreadProps$1(__spreadValues$1({}, BooleanTypeRef), {
|
|
359
|
+
default: false,
|
|
360
|
+
validation: [
|
|
361
|
+
{
|
|
362
|
+
type: "oneOf",
|
|
363
|
+
message: "Value must be true or false",
|
|
364
|
+
options: [true, false]
|
|
365
|
+
}
|
|
366
|
+
]
|
|
367
|
+
});
|
|
368
|
+
const IntegerType = __spreadProps$1(__spreadValues$1({}, IntegerTypeRef), {
|
|
369
|
+
validation: [
|
|
370
|
+
{
|
|
371
|
+
type: "integer"
|
|
372
|
+
}
|
|
373
|
+
],
|
|
374
|
+
format: {
|
|
375
|
+
type: "integer"
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
const IntegerPosType = __spreadProps$1(__spreadValues$1({}, IntegerPosTypeRef), {
|
|
379
|
+
validation: [
|
|
380
|
+
{
|
|
381
|
+
type: "integer"
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
type: "min",
|
|
385
|
+
value: 1
|
|
386
|
+
}
|
|
387
|
+
],
|
|
388
|
+
format: {
|
|
389
|
+
type: "integer"
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
const IntegerNNType = __spreadProps$1(__spreadValues$1({}, IntegerNNTypeRef), {
|
|
393
|
+
validation: [
|
|
394
|
+
{
|
|
395
|
+
type: "integer"
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
type: "min",
|
|
399
|
+
value: 0
|
|
400
|
+
}
|
|
401
|
+
],
|
|
402
|
+
format: {
|
|
403
|
+
type: "integer"
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
const StringType = __spreadProps$1(__spreadValues$1({}, StringTypeRef), {
|
|
407
|
+
default: "",
|
|
408
|
+
validation: [
|
|
409
|
+
{
|
|
410
|
+
type: "string"
|
|
411
|
+
}
|
|
412
|
+
],
|
|
413
|
+
format: {
|
|
414
|
+
type: "string"
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
const CollectionType = __spreadProps$1(__spreadValues$1({}, CollectionTypeRef), {
|
|
418
|
+
validation: [
|
|
419
|
+
{
|
|
420
|
+
type: "collection"
|
|
421
|
+
}
|
|
422
|
+
]
|
|
423
|
+
});
|
|
424
|
+
const DateType = __spreadProps$1(__spreadValues$1({}, DateTypeRef), {
|
|
425
|
+
validation: [
|
|
426
|
+
{
|
|
427
|
+
type: "string"
|
|
428
|
+
}
|
|
429
|
+
],
|
|
430
|
+
format: {
|
|
431
|
+
type: "date"
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
const PhoneType = __spreadProps$1(__spreadValues$1({}, PhoneTypeRef), {
|
|
435
|
+
validation: [
|
|
436
|
+
{
|
|
437
|
+
type: "phone"
|
|
438
|
+
}
|
|
439
|
+
],
|
|
440
|
+
format: {
|
|
441
|
+
type: "phone"
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
var dataTypes = /*#__PURE__*/Object.freeze({
|
|
446
|
+
__proto__: null,
|
|
447
|
+
BooleanType: BooleanType,
|
|
448
|
+
IntegerType: IntegerType,
|
|
449
|
+
IntegerPosType: IntegerPosType,
|
|
450
|
+
IntegerNNType: IntegerNNType,
|
|
451
|
+
StringType: StringType,
|
|
452
|
+
CollectionType: CollectionType,
|
|
453
|
+
DateType: DateType,
|
|
454
|
+
PhoneType: PhoneType
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
const PLACEHOLDER = "#";
|
|
458
|
+
const removeFormatCharactersFromMaskedString = (value, mask, reserved = [PLACEHOLDER]) => {
|
|
459
|
+
return value.split("").reduce((newString, nextChar, nextIndex) => {
|
|
460
|
+
const maskedVal = mask[nextIndex];
|
|
461
|
+
if (reserved.includes(maskedVal)) {
|
|
462
|
+
return newString + nextChar;
|
|
463
|
+
}
|
|
464
|
+
return newString;
|
|
465
|
+
}, "");
|
|
466
|
+
};
|
|
467
|
+
const formatAsEnum = (value, acceptedValues, options) => {
|
|
468
|
+
const autoCompletionsByOverlapCount = acceptedValues.reduce((validCompletions, validValue) => {
|
|
469
|
+
let overlap = 0;
|
|
470
|
+
for (let charIndex = 0; charIndex < Math.min(validValue.length, value.length); charIndex++) {
|
|
471
|
+
const validChar = (options == null ? void 0 : options.ignoreCase) ? validValue[charIndex].toLowerCase() : validValue[charIndex];
|
|
472
|
+
const actualChar = (options == null ? void 0 : options.ignoreCase) ? value[charIndex].toLowerCase() : value[charIndex];
|
|
473
|
+
if (validChar !== actualChar) {
|
|
474
|
+
break;
|
|
475
|
+
}
|
|
476
|
+
overlap += 1;
|
|
477
|
+
}
|
|
478
|
+
if (overlap === 0) {
|
|
479
|
+
return validCompletions;
|
|
480
|
+
}
|
|
481
|
+
return [
|
|
482
|
+
...validCompletions,
|
|
483
|
+
{
|
|
484
|
+
count: overlap,
|
|
485
|
+
target: validValue
|
|
486
|
+
}
|
|
487
|
+
];
|
|
488
|
+
}, []).sort((e) => e.count);
|
|
489
|
+
if (autoCompletionsByOverlapCount.length === 0) {
|
|
490
|
+
return void 0;
|
|
491
|
+
}
|
|
492
|
+
if (autoCompletionsByOverlapCount.length === 1 && (options == null ? void 0 : options.autocomplete)) {
|
|
493
|
+
return autoCompletionsByOverlapCount[0].target;
|
|
494
|
+
}
|
|
495
|
+
return autoCompletionsByOverlapCount[0].target.substr(0, autoCompletionsByOverlapCount[0].count);
|
|
496
|
+
};
|
|
497
|
+
const formatAsMasked = (value, valueCharMaskMatch, mask) => {
|
|
498
|
+
const valStr = String(value);
|
|
499
|
+
let withMask = mask;
|
|
500
|
+
if (valStr.trim() === "") {
|
|
501
|
+
return "";
|
|
502
|
+
}
|
|
503
|
+
valStr.replace(valueCharMaskMatch, (match) => {
|
|
504
|
+
withMask = withMask.replace(PLACEHOLDER, match);
|
|
505
|
+
return match;
|
|
506
|
+
});
|
|
507
|
+
return withMask.split(PLACEHOLDER)[0];
|
|
508
|
+
};
|
|
509
|
+
const createMaskedNumericFormatter = (name, mask) => {
|
|
510
|
+
return {
|
|
511
|
+
name,
|
|
512
|
+
format: (value, options) => {
|
|
513
|
+
if (typeof value !== "string") {
|
|
514
|
+
return value;
|
|
515
|
+
}
|
|
516
|
+
if ((options == null ? void 0 : options.exceptions) && options.exceptions.length > 0) {
|
|
517
|
+
const formattedUsingExceptions = formatAsEnum(value, options.exceptions, {
|
|
518
|
+
autocomplete: true,
|
|
519
|
+
ignoreCase: true
|
|
520
|
+
});
|
|
521
|
+
if (formattedUsingExceptions !== void 0) {
|
|
522
|
+
return formattedUsingExceptions;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
return formatAsMasked(value, /\d/g, mask);
|
|
526
|
+
},
|
|
527
|
+
deformat: (value, options) => {
|
|
528
|
+
if (typeof value !== "string") {
|
|
529
|
+
return value;
|
|
530
|
+
}
|
|
531
|
+
if ((options == null ? void 0 : options.exceptions) && options.exceptions.length > 0) {
|
|
532
|
+
const usingExceptions = formatAsEnum(value, options.exceptions, {
|
|
533
|
+
autocomplete: false,
|
|
534
|
+
ignoreCase: false
|
|
535
|
+
});
|
|
536
|
+
if (usingExceptions !== void 0) {
|
|
537
|
+
return usingExceptions;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
return removeFormatCharactersFromMaskedString(value, mask);
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
};
|
|
544
|
+
|
|
545
|
+
var __defProp = Object.defineProperty;
|
|
546
|
+
var __defProps = Object.defineProperties;
|
|
547
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
548
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
549
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
550
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
551
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
552
|
+
var __spreadValues = (a, b) => {
|
|
553
|
+
for (var prop in b || (b = {}))
|
|
554
|
+
if (__hasOwnProp.call(b, prop))
|
|
555
|
+
__defNormalProp(a, prop, b[prop]);
|
|
556
|
+
if (__getOwnPropSymbols)
|
|
557
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
558
|
+
if (__propIsEnum.call(b, prop))
|
|
559
|
+
__defNormalProp(a, prop, b[prop]);
|
|
560
|
+
}
|
|
561
|
+
return a;
|
|
562
|
+
};
|
|
563
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
564
|
+
const LENGTH_OF_MAX_INT = String(Number.MAX_SAFE_INTEGER).split("").length;
|
|
565
|
+
const integer = {
|
|
566
|
+
name: "integer",
|
|
567
|
+
format: (value) => {
|
|
568
|
+
var _a, _b;
|
|
569
|
+
if (value === "-") {
|
|
570
|
+
return value;
|
|
571
|
+
}
|
|
572
|
+
const formatted = (_b = (_a = integer.deformat) == null ? void 0 : _a.call(integer, value)) != null ? _b : value;
|
|
573
|
+
if (typeof formatted === "number") {
|
|
574
|
+
return String(formatted);
|
|
575
|
+
}
|
|
576
|
+
return "";
|
|
577
|
+
},
|
|
578
|
+
deformat: (value) => {
|
|
579
|
+
if (typeof value === "number") {
|
|
580
|
+
return Math.floor(value) + 0;
|
|
581
|
+
}
|
|
582
|
+
if (typeof value !== "string") {
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
const isNeg = value.replace(/[^0-9.-]/g, "").charAt(0) === "-";
|
|
586
|
+
let digits = value.replace(/[^0-9.]/g, "");
|
|
587
|
+
const decimalPlace = digits.indexOf(".");
|
|
588
|
+
if (decimalPlace > -1) {
|
|
589
|
+
digits = digits.substring(0, decimalPlace);
|
|
590
|
+
}
|
|
591
|
+
if (digits.length === 0) {
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
digits = digits.substr(0, LENGTH_OF_MAX_INT);
|
|
595
|
+
const num = Number(`${isNeg ? "-" : ""}${digits}`);
|
|
596
|
+
return Math.floor(num) + 0;
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
const commaNumber = {
|
|
600
|
+
name: "commaNumber",
|
|
601
|
+
format: (_value, options) => {
|
|
602
|
+
if (_value === void 0 || _value === "") {
|
|
603
|
+
return _value;
|
|
604
|
+
}
|
|
605
|
+
if (typeof _value !== "string" && typeof _value !== "number") {
|
|
606
|
+
return "";
|
|
607
|
+
}
|
|
608
|
+
const value = String(_value);
|
|
609
|
+
const isNeg = value.replace(/[^0-9.-]/g, "").charAt(0) === "-";
|
|
610
|
+
let digitAndDecimal = value.replace(/[^0-9.]/g, "");
|
|
611
|
+
digitAndDecimal = digitAndDecimal.replace(/^(0*)((0.)?\d)/g, "$2");
|
|
612
|
+
const firstDecimal = digitAndDecimal.indexOf(".");
|
|
613
|
+
const digitsOnly = digitAndDecimal.replace(/[^0-9]/g, "");
|
|
614
|
+
let preDecDigits = digitsOnly;
|
|
615
|
+
let postDecDigits = "";
|
|
616
|
+
if (firstDecimal >= 0) {
|
|
617
|
+
preDecDigits = digitsOnly.substring(0, firstDecimal).substr(0, LENGTH_OF_MAX_INT);
|
|
618
|
+
postDecDigits = digitsOnly.substring(firstDecimal);
|
|
619
|
+
} else {
|
|
620
|
+
preDecDigits = preDecDigits.substr(0, LENGTH_OF_MAX_INT);
|
|
621
|
+
}
|
|
622
|
+
if ((options == null ? void 0 : options.precision) !== void 0) {
|
|
623
|
+
postDecDigits = postDecDigits.substring(0, options.precision).padEnd(options.precision, "0");
|
|
624
|
+
}
|
|
625
|
+
preDecDigits = preDecDigits.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
626
|
+
if (preDecDigits === "" && firstDecimal === 0) {
|
|
627
|
+
preDecDigits = "0";
|
|
628
|
+
}
|
|
629
|
+
let retVal = preDecDigits;
|
|
630
|
+
if (isNeg) {
|
|
631
|
+
retVal = `-${retVal}`;
|
|
632
|
+
}
|
|
633
|
+
if (firstDecimal >= 0 || (options == null ? void 0 : options.precision) !== void 0) {
|
|
634
|
+
retVal += `.${postDecDigits}`;
|
|
635
|
+
}
|
|
636
|
+
return retVal;
|
|
637
|
+
},
|
|
638
|
+
deformat: (value) => {
|
|
639
|
+
if (typeof value !== "string") {
|
|
640
|
+
return value;
|
|
641
|
+
}
|
|
642
|
+
const strValue = value.replace(/,/g, "");
|
|
643
|
+
if (strValue === "") {
|
|
644
|
+
return void 0;
|
|
645
|
+
}
|
|
646
|
+
const number = Number(strValue);
|
|
647
|
+
return isNaN(number) || number > Number.MAX_SAFE_INTEGER || number < Number.MIN_SAFE_INTEGER ? void 0 : number;
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
const date = {
|
|
651
|
+
name: "date",
|
|
652
|
+
format: (_value, options) => {
|
|
653
|
+
var _a, _b;
|
|
654
|
+
let value = typeof _value === "number" ? String(_value) : _value;
|
|
655
|
+
if (_value === void 0) {
|
|
656
|
+
return void 0;
|
|
657
|
+
}
|
|
658
|
+
if (typeof value !== "string" || value === "") {
|
|
659
|
+
return "";
|
|
660
|
+
}
|
|
661
|
+
if (value.match(/^\d{4}[-]\d{1,2}[-]\d{1,2}$/)) {
|
|
662
|
+
const tempVal = value.split("-");
|
|
663
|
+
value = `${tempVal[1]}/${tempVal[2]}/${tempVal[0]}`;
|
|
664
|
+
}
|
|
665
|
+
const dateFormat = (_b = (_a = options == null ? void 0 : options.mask) == null ? void 0 : _a.toUpperCase()) != null ? _b : "MM/DD/YYYY";
|
|
666
|
+
const delimiter = dateFormat.replace(/[^/.-]/g, "").charAt(0);
|
|
667
|
+
const formatParts = dateFormat.split(delimiter);
|
|
668
|
+
const valueParts = value.split(delimiter);
|
|
669
|
+
const processedValueParts = [];
|
|
670
|
+
let lastMatchIsFull = true;
|
|
671
|
+
for (let index = 0; index < valueParts.length; index++) {
|
|
672
|
+
let part = valueParts[index];
|
|
673
|
+
if (lastMatchIsFull && index < formatParts.length) {
|
|
674
|
+
part = part.replace(/[^0-9]/g, "");
|
|
675
|
+
const isLastExpectedField = formatParts.length - 1 === index;
|
|
676
|
+
const hasDelimiterAfter = valueParts.length - 1 > index;
|
|
677
|
+
const curFormat = formatParts[index];
|
|
678
|
+
if (curFormat === "YYYY") {
|
|
679
|
+
if (part.length > 4) {
|
|
680
|
+
valueParts[index + 1] = [
|
|
681
|
+
"*",
|
|
682
|
+
part.substring(4),
|
|
683
|
+
valueParts[index + 1]
|
|
684
|
+
].join("");
|
|
685
|
+
part = part.substring(0, 4);
|
|
686
|
+
}
|
|
687
|
+
if (part.length === 4) {
|
|
688
|
+
lastMatchIsFull = true;
|
|
689
|
+
processedValueParts.push(part);
|
|
690
|
+
}
|
|
691
|
+
if (part.length === 3) {
|
|
692
|
+
if (isLastExpectedField || !hasDelimiterAfter) {
|
|
693
|
+
lastMatchIsFull = false;
|
|
694
|
+
processedValueParts.push(part);
|
|
695
|
+
} else {
|
|
696
|
+
valueParts[index + 1] = `*${part.substring(2)}${valueParts[index + 1]}`;
|
|
697
|
+
part = part.substring(0, 2);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
if (part.length === 2) {
|
|
701
|
+
let autocomplete;
|
|
702
|
+
if (part.length === 2 && (hasDelimiterAfter || isLastExpectedField && part !== "19" && part !== "20")) {
|
|
703
|
+
autocomplete = `20${part}`;
|
|
704
|
+
if (part > (new Date().getFullYear() + 5).toString().substring(2)) {
|
|
705
|
+
autocomplete = `19${part}`;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
if (autocomplete) {
|
|
709
|
+
lastMatchIsFull = true;
|
|
710
|
+
processedValueParts.push(autocomplete);
|
|
711
|
+
} else {
|
|
712
|
+
lastMatchIsFull = false;
|
|
713
|
+
processedValueParts.push(part);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
if (part.length === 1 || part.length === 0) {
|
|
717
|
+
lastMatchIsFull = false;
|
|
718
|
+
processedValueParts.push(part);
|
|
719
|
+
}
|
|
720
|
+
} else if (curFormat === "YY") {
|
|
721
|
+
if (part.length > 2) {
|
|
722
|
+
valueParts[index + 1] = [
|
|
723
|
+
"*",
|
|
724
|
+
part.substring(2),
|
|
725
|
+
valueParts[index + 1]
|
|
726
|
+
].join("");
|
|
727
|
+
part = part.substring(0, 2);
|
|
728
|
+
}
|
|
729
|
+
if (part.length === 2) {
|
|
730
|
+
lastMatchIsFull = true;
|
|
731
|
+
processedValueParts.push(part);
|
|
732
|
+
}
|
|
733
|
+
if (part.length === 1 || part.length === 0) {
|
|
734
|
+
lastMatchIsFull = false;
|
|
735
|
+
processedValueParts.push(part);
|
|
736
|
+
}
|
|
737
|
+
} else {
|
|
738
|
+
if (part.length > 2) {
|
|
739
|
+
valueParts[index + 1] = [
|
|
740
|
+
"*",
|
|
741
|
+
part.substring(2),
|
|
742
|
+
valueParts[index + 1]
|
|
743
|
+
].join("");
|
|
744
|
+
part = part.substring(0, 2);
|
|
745
|
+
}
|
|
746
|
+
if (part.length === 2) {
|
|
747
|
+
if (part === "00" && !hasDelimiterAfter) {
|
|
748
|
+
lastMatchIsFull = false;
|
|
749
|
+
processedValueParts.push("0");
|
|
750
|
+
} else {
|
|
751
|
+
lastMatchIsFull = true;
|
|
752
|
+
processedValueParts.push(part);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
if (part.length === 1) {
|
|
756
|
+
if (hasDelimiterAfter) {
|
|
757
|
+
lastMatchIsFull = true;
|
|
758
|
+
processedValueParts.push(`0${part}`);
|
|
759
|
+
} else {
|
|
760
|
+
lastMatchIsFull = false;
|
|
761
|
+
processedValueParts.push(part);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
if (part.length === 0) {
|
|
765
|
+
lastMatchIsFull = false;
|
|
766
|
+
processedValueParts.push(part);
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
return processedValueParts.join(delimiter);
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
const currency = {
|
|
775
|
+
name: "currency",
|
|
776
|
+
format: (_value, options) => {
|
|
777
|
+
const value = typeof _value === "number" ? String(_value) : _value;
|
|
778
|
+
const {
|
|
779
|
+
currencySymbol = "",
|
|
780
|
+
useParensForNeg = false,
|
|
781
|
+
precision = 2
|
|
782
|
+
} = options != null ? options : {};
|
|
783
|
+
if (value === void 0 || value === "") {
|
|
784
|
+
return value;
|
|
785
|
+
}
|
|
786
|
+
if (typeof value !== "string") {
|
|
787
|
+
return value;
|
|
788
|
+
}
|
|
789
|
+
const sign = /^\s*-/.test(value) ? -1 : 1;
|
|
790
|
+
const dotIndex = value.indexOf(".");
|
|
791
|
+
let preDecimal;
|
|
792
|
+
let postDecimal;
|
|
793
|
+
if (dotIndex >= 0) {
|
|
794
|
+
preDecimal = value.substr(0, dotIndex).replace(/\D+/g, "");
|
|
795
|
+
postDecimal = value.substr(dotIndex + 1).replace(/\D+/g, "");
|
|
796
|
+
} else {
|
|
797
|
+
preDecimal = value.replace(/\D+/g, "");
|
|
798
|
+
postDecimal = "0";
|
|
799
|
+
}
|
|
800
|
+
const numericalValue = sign * Number(`${preDecimal}.${postDecimal}`);
|
|
801
|
+
const fixedString = numericalValue.toFixed(precision);
|
|
802
|
+
const prettyString = fixedString.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
803
|
+
if (prettyString.charAt(0) === "-") {
|
|
804
|
+
if (useParensForNeg) {
|
|
805
|
+
return `(${currencySymbol}${prettyString.substring(1)})`;
|
|
806
|
+
}
|
|
807
|
+
return `-${currencySymbol}${prettyString.substring(1)}`;
|
|
808
|
+
}
|
|
809
|
+
return currencySymbol + prettyString;
|
|
810
|
+
},
|
|
811
|
+
deformat: (value, options) => {
|
|
812
|
+
var _a;
|
|
813
|
+
if (typeof value === "number") {
|
|
814
|
+
return value;
|
|
815
|
+
}
|
|
816
|
+
if (typeof value !== "string") {
|
|
817
|
+
return void 0;
|
|
818
|
+
}
|
|
819
|
+
let deformatted = value;
|
|
820
|
+
if (options == null ? void 0 : options.currencySymbol) {
|
|
821
|
+
deformatted = value.replace(options.currencySymbol, "");
|
|
822
|
+
}
|
|
823
|
+
return (_a = commaNumber.deformat) == null ? void 0 : _a.call(commaNumber, deformatted);
|
|
824
|
+
}
|
|
825
|
+
};
|
|
826
|
+
const basePhoneFormatter = createMaskedNumericFormatter("phone", "(###) ###-####");
|
|
827
|
+
const phone = __spreadProps(__spreadValues({}, basePhoneFormatter), {
|
|
828
|
+
deformat: (value) => {
|
|
829
|
+
var _a;
|
|
830
|
+
return (_a = basePhoneFormatter.deformat) == null ? void 0 : _a.call(basePhoneFormatter, value);
|
|
831
|
+
},
|
|
832
|
+
format: (value) => {
|
|
833
|
+
var _a, _b;
|
|
834
|
+
return (_b = (_a = basePhoneFormatter.format) == null ? void 0 : _a.call(basePhoneFormatter, value === "(" ? "" : value)) != null ? _b : value;
|
|
835
|
+
}
|
|
836
|
+
});
|
|
837
|
+
|
|
838
|
+
var formats = /*#__PURE__*/Object.freeze({
|
|
839
|
+
__proto__: null,
|
|
840
|
+
integer: integer,
|
|
841
|
+
commaNumber: commaNumber,
|
|
842
|
+
date: date,
|
|
843
|
+
currency: currency,
|
|
844
|
+
phone: phone
|
|
845
|
+
});
|
|
846
|
+
|
|
847
|
+
class CommonTypesPlugin {
|
|
848
|
+
constructor() {
|
|
849
|
+
this.name = "CommonTypes";
|
|
850
|
+
}
|
|
851
|
+
apply(player) {
|
|
852
|
+
player.registerPlugin(new _player_ui_types_provider_plugin__WEBPACK_IMPORTED_MODULE_0__["TypesProviderPlugin"]({
|
|
853
|
+
types: Object.values(dataTypes),
|
|
854
|
+
formats: Object.values(formats),
|
|
855
|
+
validators: Object.entries(validators)
|
|
856
|
+
}));
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
//# sourceMappingURL=index.esm.js.map
|
|
862
|
+
|
|
863
|
+
|
|
864
|
+
/***/ }),
|
|
865
|
+
|
|
866
|
+
/***/ "./bazel-out/k8-fastbuild/bin/plugins/types-provider/core/dist/index.esm.js":
|
|
867
|
+
/*!**********************************************************************************!*\
|
|
868
|
+
!*** ./bazel-out/k8-fastbuild/bin/plugins/types-provider/core/dist/index.esm.js ***!
|
|
869
|
+
\**********************************************************************************/
|
|
870
|
+
/*! exports provided: TypesProviderPlugin */
|
|
871
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
872
|
+
|
|
873
|
+
"use strict";
|
|
874
|
+
__webpack_require__.r(__webpack_exports__);
|
|
875
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "TypesProviderPlugin", function() { return TypesProviderPlugin; });
|
|
876
|
+
class TypesProviderPlugin {
|
|
877
|
+
constructor(config) {
|
|
878
|
+
this.name = "TypesProviderPlugin";
|
|
879
|
+
this.config = config;
|
|
880
|
+
}
|
|
881
|
+
apply(player) {
|
|
882
|
+
player.hooks.schema.tap(this.name, (schema) => {
|
|
883
|
+
if (this.config.types) {
|
|
884
|
+
schema.addDataTypes(this.config.types);
|
|
885
|
+
}
|
|
886
|
+
if (this.config.formats) {
|
|
887
|
+
schema.addFormatters(this.config.formats);
|
|
888
|
+
}
|
|
889
|
+
});
|
|
890
|
+
if (this.config.validators) {
|
|
891
|
+
player.hooks.validationController.tap(this.name, (validationController) => {
|
|
892
|
+
validationController.hooks.createValidatorRegistry.tap(this.name, (validationRegistry) => {
|
|
893
|
+
var _a;
|
|
894
|
+
(_a = this.config.validators) == null ? void 0 : _a.forEach(([name, handler]) => {
|
|
895
|
+
validationRegistry.register(name, handler);
|
|
896
|
+
});
|
|
897
|
+
});
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
|
|
904
|
+
//# sourceMappingURL=index.esm.js.map
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
/***/ })
|
|
908
|
+
|
|
909
|
+
/******/ });
|
|
910
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,t){"object"===typeof exports&&"object"===typeof module?module.exports=t():"function"===typeof define&&define.amd?define([],t):"object"===typeof exports?exports.CommonTypesPlugin=t():e.CommonTypesPlugin=t()}(this,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"===typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";n.r(t),n.d(t,"CommonTypesPlugin",(function(){return fe})),n.d(t,"PLACEHOLDER",(function(){return q})),n.d(t,"createMaskedNumericFormatter",(function(){return J})),n.d(t,"dataRefs",(function(){return E})),n.d(t,"dataTypes",(function(){return G})),n.d(t,"formatAsEnum",(function(){return X})),n.d(t,"formatAsMasked",(function(){return H})),n.d(t,"formats",(function(){return ce})),n.d(t,"removeFormatCharactersFromMaskedString",(function(){return U})),n.d(t,"validators",(function(){return F}));class r{constructor(e){this.name="TypesProviderPlugin",this.config=e}apply(e){e.hooks.schema.tap(this.name,(e=>{this.config.types&&e.addDataTypes(this.config.types),this.config.formats&&e.addFormatters(this.config.formats)})),this.config.validators&&e.hooks.validationController.tap(this.name,(e=>{e.hooks.createValidatorRegistry.tap(this.name,(e=>{var t;null==(t=this.config.validators)||t.forEach((([t,n])=>{e.register(t,n)}))}))}))}}function o(e){return(t,n,r)=>{if(null!==n&&void 0!==n)return e(t,n,r)}}const i=o(((e,t)=>{if("string"!==typeof t){return{message:e.constants.getConstants("validation.string","constants","Value must be a string"),parameters:{type:typeof t}}}})),a=o(((e,t)=>{if(!Array.isArray(t)){return{message:e.constants.getConstants("validation.collection","constants","Cannot set collection to non-array")}}})),s=o(((e,t)=>{if(t&&("number"!==typeof t||Math.floor(t)!==t||Number(t)>Number.MAX_SAFE_INTEGER||Number(t)<Number.MIN_SAFE_INTEGER)){return{message:e.constants.getConstants("validation.integer","constants","Value must be an integer"),parameters:{type:typeof t,flooredValue:Math.floor(t)}}}})),u=o(((e,t,n)=>{var r;if(void 0===(null==n?void 0:n.options)||(null==(r=n.options)?void 0:r.includes(t)))return;return{message:e.constants.getConstants("validation.oneOf","constants","Invalid entry")}})),l=o(((e,t,n)=>{if(void 0===t||null===t||""===t||"string"!==typeof(null==n?void 0:n.regex))return;const r=n.regex.match(/^\/(.*)\/(\w)*$/);if(!(r?new RegExp(r[1],r[2]):new RegExp(n.regex)).test(t)){return{message:e.constants.getConstants("validation.regex","constants","Invalid entry")}}})),p=o(((e,t,n)=>{if("object"!==typeof n)return void e.logger.warn("Missing comparison in length validation");let r,o="items";if("string"===typeof t?(r=t.length,o="characters"):"object"===typeof t&&null!==t&&(r=Object.keys(t).length),void 0!==r){if("exact"in n)return r!==n.exact?{message:`Must be exactly ${n.exact} ${o} long`,parameters:{validationLength:r}}:void 0;if(void 0!==n.min&&r<n.min){return{message:e.constants.getConstants("validation.length.minimum","constants",`At least ${n.min} ${o} needed`),parameters:{validationLength:r}}}if(void 0!==n.max&&r>n.max){return{message:e.constants.getConstants("validation.length.maximum","constants",`Up to ${n.max} ${o} allowed`),parameters:{validationLength:r}}}}else e.logger.warn(`Unable to determine a length for value of type: ${t}`)})),c=o(((e,t,n)=>{if("number"===typeof t&&void 0!==(null==n?void 0:n.value)&&t<n.value){return{message:e.constants.getConstants("validation.min","constants",`Must be at least ${n.value}`)}}})),f=o(((e,t,n)=>{if("number"===typeof t&&void 0!==(null==n?void 0:n.value)&&t>n.value){return{message:e.constants.getConstants("validation.max","constants",`Cannot exceed ${n.value}`)}}})),g=(e,t,n)=>o(((r,o)=>{if(("string"!==typeof o||""!==o)&&("string"!==typeof o||!e.test(o))){return{message:r.constants.getConstants(t,"constants",n)}}})),d=g(/^((([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,"validation.email","Improper email format"),m=g(/^\+?[1]?[- ]?\(?\d{3}[)\- ]?\s?\d{3}[ -]?\d{4}$/,"validation.phone","Invalid phone number"),y=g(/^\d{5}(-\d{4})?$/,"validation.regex","Invalid zip code");var F=Object.freeze({__proto__:null,string:i,readonly:e=>({message:e.constants.getConstants("validation.readonly","constants","Value cannot be modified")}),collection:a,integer:s,oneOf:u,expression:(e,t,n)=>{if(void 0===(null==n?void 0:n.exp))return void e.logger.warn("No expression defined for validation");if(!e.evaluate(n.exp)){return{message:e.constants.getConstants("validation.expression","constants","Expression evaluation failed")}}},required:(e,t,n)=>{if(!((null==n?void 0:n.if)&&!e.evaluate(n.if)||(null==n?void 0:n.ifNot)&&e.evaluate(n.ifNot))&&(void 0===t||null===t||""===t)){return{message:e.constants.getConstants("validation.required","constants","A value is required"),severity:"error"}}},regex:l,length:p,min:c,max:f,email:d,phone:m,zip:y});const v={type:"BooleanType"},b={type:"IntegerType"},h={type:"IntegerPosType"},x={type:"IntegerNNType"},D={type:"StringType"},C={type:"CollectionType"},O={type:"DateType"},T={type:"PhoneType"};var E=Object.freeze({__proto__:null,BooleanTypeRef:v,IntegerTypeRef:b,IntegerPosTypeRef:h,IntegerNNTypeRef:x,StringTypeRef:D,CollectionTypeRef:C,DateTypeRef:O,PhoneTypeRef:T}),j=Object.defineProperty,_=Object.defineProperties,$=Object.getOwnPropertyDescriptors,N=Object.getOwnPropertySymbols,A=Object.prototype.hasOwnProperty,P=Object.prototype.propertyIsEnumerable,S=(e,t,n)=>t in e?j(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,I=(e,t)=>{for(var n in t||(t={}))A.call(t,n)&&S(e,n,t[n]);if(N)for(var n of N(t))P.call(t,n)&&S(e,n,t[n]);return e},M=(e,t)=>_(e,$(t));const w=M(I({},v),{default:!1,validation:[{type:"oneOf",message:"Value must be true or false",options:[!0,!1]}]}),R=M(I({},b),{validation:[{type:"integer"}],format:{type:"integer"}}),z=M(I({},h),{validation:[{type:"integer"},{type:"min",value:1}],format:{type:"integer"}}),Y=M(I({},x),{validation:[{type:"integer"},{type:"min",value:0}],format:{type:"integer"}}),k=M(I({},D),{default:"",validation:[{type:"string"}],format:{type:"string"}}),L=M(I({},C),{validation:[{type:"collection"}]}),V=M(I({},O),{validation:[{type:"string"}],format:{type:"date"}}),B=M(I({},T),{validation:[{type:"phone"}],format:{type:"phone"}});var G=Object.freeze({__proto__:null,BooleanType:w,IntegerType:R,IntegerPosType:z,IntegerNNType:Y,StringType:k,CollectionType:L,DateType:V,PhoneType:B});const q="#",U=(e,t,n=[q])=>e.split("").reduce(((e,r,o)=>{const i=t[o];return n.includes(i)?e+r:e}),""),X=(e,t,n)=>{const r=t.reduce(((t,r)=>{let o=0;for(let i=0;i<Math.min(r.length,e.length);i++){if(((null==n?void 0:n.ignoreCase)?r[i].toLowerCase():r[i])!==((null==n?void 0:n.ignoreCase)?e[i].toLowerCase():e[i]))break;o+=1}return 0===o?t:[...t,{count:o,target:r}]}),[]).sort((e=>e.count));if(0!==r.length)return 1===r.length&&(null==n?void 0:n.autocomplete)?r[0].target:r[0].target.substr(0,r[0].count)},H=(e,t,n)=>{const r=String(e);let o=n;return""===r.trim()?"":(r.replace(t,(e=>(o=o.replace(q,e),e))),o.split(q)[0])},J=(e,t)=>({name:e,format:(e,n)=>{if("string"!==typeof e)return e;if((null==n?void 0:n.exceptions)&&n.exceptions.length>0){const t=X(e,n.exceptions,{autocomplete:!0,ignoreCase:!0});if(void 0!==t)return t}return H(e,/\d/g,t)},deformat:(e,n)=>{if("string"!==typeof e)return e;if((null==n?void 0:n.exceptions)&&n.exceptions.length>0){const t=X(e,n.exceptions,{autocomplete:!1,ignoreCase:!1});if(void 0!==t)return t}return U(e,t)}});var K=Object.defineProperty,Q=Object.defineProperties,W=Object.getOwnPropertyDescriptors,Z=Object.getOwnPropertySymbols,ee=Object.prototype.hasOwnProperty,te=Object.prototype.propertyIsEnumerable,ne=(e,t,n)=>t in e?K(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;const re=String(Number.MAX_SAFE_INTEGER).split("").length,oe={name:"integer",format:e=>{var t,n;if("-"===e)return e;const r=null!=(n=null==(t=oe.deformat)?void 0:t.call(oe,e))?n:e;return"number"===typeof r?String(r):""},deformat:e=>{if("number"===typeof e)return Math.floor(e)+0;if("string"!==typeof e)return;const t="-"===e.replace(/[^0-9.-]/g,"").charAt(0);let n=e.replace(/[^0-9.]/g,"");const r=n.indexOf(".");if(r>-1&&(n=n.substring(0,r)),0===n.length)return;n=n.substr(0,re);const o=Number(`${t?"-":""}${n}`);return Math.floor(o)+0}},ie={name:"commaNumber",format:(e,t)=>{if(void 0===e||""===e)return e;if("string"!==typeof e&&"number"!==typeof e)return"";const n=String(e),r="-"===n.replace(/[^0-9.-]/g,"").charAt(0);let o=n.replace(/[^0-9.]/g,"");o=o.replace(/^(0*)((0.)?\d)/g,"$2");const i=o.indexOf("."),a=o.replace(/[^0-9]/g,"");let s=a,u="";i>=0?(s=a.substring(0,i).substr(0,re),u=a.substring(i)):s=s.substr(0,re),void 0!==(null==t?void 0:t.precision)&&(u=u.substring(0,t.precision).padEnd(t.precision,"0")),s=s.replace(/\B(?=(\d{3})+(?!\d))/g,","),""===s&&0===i&&(s="0");let l=s;return r&&(l=`-${l}`),(i>=0||void 0!==(null==t?void 0:t.precision))&&(l+=`.${u}`),l},deformat:e=>{if("string"!==typeof e)return e;const t=e.replace(/,/g,"");if(""===t)return;const n=Number(t);return isNaN(n)||n>Number.MAX_SAFE_INTEGER||n<Number.MIN_SAFE_INTEGER?void 0:n}},ae={name:"date",format:(e,t)=>{var n,r;let o="number"===typeof e?String(e):e;if(void 0===e)return;if("string"!==typeof o||""===o)return"";if(o.match(/^\d{4}[-]\d{1,2}[-]\d{1,2}$/)){const e=o.split("-");o=`${e[1]}/${e[2]}/${e[0]}`}const i=null!=(r=null==(n=null==t?void 0:t.mask)?void 0:n.toUpperCase())?r:"MM/DD/YYYY",a=i.replace(/[^/.-]/g,"").charAt(0),s=i.split(a),u=o.split(a),l=[];let p=!0;for(let c=0;c<u.length;c++){let e=u[c];if(p&&c<s.length){e=e.replace(/[^0-9]/g,"");const t=s.length-1===c,n=u.length-1>c,r=s[c];if("YYYY"===r){if(e.length>4&&(u[c+1]=["*",e.substring(4),u[c+1]].join(""),e=e.substring(0,4)),4===e.length&&(p=!0,l.push(e)),3===e.length&&(t||!n?(p=!1,l.push(e)):(u[c+1]=`*${e.substring(2)}${u[c+1]}`,e=e.substring(0,2))),2===e.length){let r;2===e.length&&(n||t&&"19"!==e&&"20"!==e)&&(r=`20${e}`,e>((new Date).getFullYear()+5).toString().substring(2)&&(r=`19${e}`)),r?(p=!0,l.push(r)):(p=!1,l.push(e))}1!==e.length&&0!==e.length||(p=!1,l.push(e))}else"YY"===r?(e.length>2&&(u[c+1]=["*",e.substring(2),u[c+1]].join(""),e=e.substring(0,2)),2===e.length&&(p=!0,l.push(e)),1!==e.length&&0!==e.length||(p=!1,l.push(e))):(e.length>2&&(u[c+1]=["*",e.substring(2),u[c+1]].join(""),e=e.substring(0,2)),2===e.length&&("00"!==e||n?(p=!0,l.push(e)):(p=!1,l.push("0"))),1===e.length&&(n?(p=!0,l.push(`0${e}`)):(p=!1,l.push(e))),0===e.length&&(p=!1,l.push(e)))}}return l.join(a)}},se={name:"currency",format:(e,t)=>{const n="number"===typeof e?String(e):e,{currencySymbol:r="",useParensForNeg:o=!1,precision:i=2}=null!=t?t:{};if(void 0===n||""===n)return n;if("string"!==typeof n)return n;const a=/^\s*-/.test(n)?-1:1,s=n.indexOf(".");let u,l;s>=0?(u=n.substr(0,s).replace(/\D+/g,""),l=n.substr(s+1).replace(/\D+/g,"")):(u=n.replace(/\D+/g,""),l="0");const p=(a*Number(`${u}.${l}`)).toFixed(i).replace(/\B(?=(\d{3})+(?!\d))/g,",");return"-"===p.charAt(0)?o?`(${r}${p.substring(1)})`:`-${r}${p.substring(1)}`:r+p},deformat:(e,t)=>{var n;if("number"===typeof e)return e;if("string"!==typeof e)return;let r=e;return(null==t?void 0:t.currencySymbol)&&(r=e.replace(t.currencySymbol,"")),null==(n=ie.deformat)?void 0:n.call(ie,r)}},ue=J("phone","(###) ###-####"),le=(pe=((e,t)=>{for(var n in t||(t={}))ee.call(t,n)&&ne(e,n,t[n]);if(Z)for(var n of Z(t))te.call(t,n)&&ne(e,n,t[n]);return e})({},ue),Q(pe,W({deformat:e=>{var t;return null==(t=ue.deformat)?void 0:t.call(ue,e)},format:e=>{var t,n;return null!=(n=null==(t=ue.format)?void 0:t.call(ue,"("===e?"":e))?n:e}})));var pe,ce=Object.freeze({__proto__:null,integer:oe,commaNumber:ie,date:ae,currency:se,phone:le});class fe{constructor(){this.name="CommonTypes"}apply(e){e.registerPlugin(new r({types:Object.values(G),formats:Object.values(ce),validators:Object.entries(F)}))}}}])}));
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@player-ui/common-types-plugin",
|
|
3
|
-
"version": "0.4.0
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
7
7
|
},
|
|
8
8
|
"peerDependencies": {
|
|
9
|
-
"@player-ui/player": "0.4.0
|
|
9
|
+
"@player-ui/player": "0.4.0"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@player-ui/types-provider-plugin": "0.4.0
|
|
12
|
+
"@player-ui/types-provider-plugin": "0.4.0",
|
|
13
13
|
"@babel/runtime": "7.15.4"
|
|
14
14
|
},
|
|
15
15
|
"main": "dist/index.cjs.js",
|