@ui5/webcomponents-localization 1.22.0-rc.1 → 1.22.0-rc.2

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.
Files changed (127) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/generated/assets/cldr/ar.json +102 -62
  4. package/dist/generated/assets/cldr/ar_EG.json +102 -62
  5. package/dist/generated/assets/cldr/ar_SA.json +102 -62
  6. package/dist/generated/assets/cldr/bg.json +364 -325
  7. package/dist/generated/assets/cldr/ca.json +491 -453
  8. package/dist/generated/assets/cldr/cs.json +431 -324
  9. package/dist/generated/assets/cldr/cy.json +608 -340
  10. package/dist/generated/assets/cldr/da.json +290 -227
  11. package/dist/generated/assets/cldr/de.json +348 -241
  12. package/dist/generated/assets/cldr/de_AT.json +348 -241
  13. package/dist/generated/assets/cldr/de_CH.json +347 -240
  14. package/dist/generated/assets/cldr/el.json +128 -100
  15. package/dist/generated/assets/cldr/el_CY.json +128 -100
  16. package/dist/generated/assets/cldr/en.json +538 -512
  17. package/dist/generated/assets/cldr/en_AU.json +583 -520
  18. package/dist/generated/assets/cldr/en_GB.json +485 -441
  19. package/dist/generated/assets/cldr/en_HK.json +519 -474
  20. package/dist/generated/assets/cldr/en_IE.json +485 -440
  21. package/dist/generated/assets/cldr/en_IN.json +465 -420
  22. package/dist/generated/assets/cldr/en_NZ.json +505 -460
  23. package/dist/generated/assets/cldr/en_PG.json +505 -460
  24. package/dist/generated/assets/cldr/en_SG.json +505 -460
  25. package/dist/generated/assets/cldr/en_ZA.json +485 -440
  26. package/dist/generated/assets/cldr/es.json +709 -456
  27. package/dist/generated/assets/cldr/es_AR.json +687 -434
  28. package/dist/generated/assets/cldr/es_BO.json +721 -468
  29. package/dist/generated/assets/cldr/es_CL.json +567 -422
  30. package/dist/generated/assets/cldr/es_CO.json +485 -339
  31. package/dist/generated/assets/cldr/es_MX.json +734 -481
  32. package/dist/generated/assets/cldr/es_PE.json +409 -372
  33. package/dist/generated/assets/cldr/es_UY.json +433 -396
  34. package/dist/generated/assets/cldr/es_VE.json +453 -416
  35. package/dist/generated/assets/cldr/et.json +340 -307
  36. package/dist/generated/assets/cldr/fa.json +96 -34
  37. package/dist/generated/assets/cldr/fi.json +359 -308
  38. package/dist/generated/assets/cldr/fr.json +347 -321
  39. package/dist/generated/assets/cldr/fr_BE.json +347 -321
  40. package/dist/generated/assets/cldr/fr_CA.json +458 -432
  41. package/dist/generated/assets/cldr/fr_CH.json +290 -264
  42. package/dist/generated/assets/cldr/fr_LU.json +347 -321
  43. package/dist/generated/assets/cldr/he.json +241 -130
  44. package/dist/generated/assets/cldr/hi.json +103 -53
  45. package/dist/generated/assets/cldr/hr.json +467 -410
  46. package/dist/generated/assets/cldr/hu.json +246 -195
  47. package/dist/generated/assets/cldr/id.json +478 -406
  48. package/dist/generated/assets/cldr/it.json +418 -362
  49. package/dist/generated/assets/cldr/it_CH.json +418 -362
  50. package/dist/generated/assets/cldr/ja.json +58 -18
  51. package/dist/generated/assets/cldr/kk.json +562 -398
  52. package/dist/generated/assets/cldr/ko.json +36 -15
  53. package/dist/generated/assets/cldr/lt.json +320 -231
  54. package/dist/generated/assets/cldr/lv.json +184 -120
  55. package/dist/generated/assets/cldr/ms.json +460 -388
  56. package/dist/generated/assets/cldr/nb.json +160 -92
  57. package/dist/generated/assets/cldr/nl.json +621 -373
  58. package/dist/generated/assets/cldr/nl_BE.json +621 -373
  59. package/dist/generated/assets/cldr/pl.json +590 -279
  60. package/dist/generated/assets/cldr/pt.json +696 -334
  61. package/dist/generated/assets/cldr/pt_PT.json +730 -454
  62. package/dist/generated/assets/cldr/ro.json +409 -339
  63. package/dist/generated/assets/cldr/ru.json +317 -279
  64. package/dist/generated/assets/cldr/ru_UA.json +312 -274
  65. package/dist/generated/assets/cldr/sk.json +454 -413
  66. package/dist/generated/assets/cldr/sl.json +118 -80
  67. package/dist/generated/assets/cldr/sr.json +294 -142
  68. package/dist/generated/assets/cldr/sr_Latn.json +972 -824
  69. package/dist/generated/assets/cldr/sv.json +382 -338
  70. package/dist/generated/assets/cldr/th.json +56 -36
  71. package/dist/generated/assets/cldr/tr.json +371 -320
  72. package/dist/generated/assets/cldr/uk.json +340 -290
  73. package/dist/generated/assets/cldr/vi.json +352 -328
  74. package/dist/generated/assets/cldr/zh_CN.json +34 -10
  75. package/dist/generated/assets/cldr/zh_HK.json +33 -9
  76. package/dist/generated/assets/cldr/zh_SG.json +33 -9
  77. package/dist/generated/assets/cldr/zh_TW.json +32 -8
  78. package/dist/sap/base/Event.js +59 -0
  79. package/dist/sap/base/Eventing.js +146 -0
  80. package/dist/sap/base/Log.js +2 -239
  81. package/dist/sap/base/assert.js +28 -1
  82. package/dist/sap/base/config/MemoryConfigurationProvider.js +20 -0
  83. package/dist/sap/base/config.js +17 -0
  84. package/dist/sap/base/i18n/Formatting.js +1130 -0
  85. package/dist/sap/base/i18n/LanguageTag.js +168 -30
  86. package/dist/sap/base/i18n/date/CalendarType.js +36 -1
  87. package/dist/sap/base/i18n/date/CalendarWeekNumbering.js +76 -1
  88. package/dist/sap/base/i18n/date/TimezoneUtils.js +242 -12
  89. package/dist/sap/base/strings/camelize.js +30 -0
  90. package/dist/sap/base/strings/formatMessage.js +88 -15
  91. package/dist/sap/base/util/ObjectPath.js +95 -3
  92. package/dist/sap/base/util/Version.js +157 -0
  93. package/dist/sap/base/util/_merge.js +83 -26
  94. package/dist/sap/base/util/array/uniqueSort.js +37 -15
  95. package/dist/sap/base/util/deepClone.js +102 -0
  96. package/dist/sap/base/util/deepEqual.js +75 -51
  97. package/dist/sap/base/util/extend.js +58 -7
  98. package/dist/sap/base/util/isEmptyObject.js +34 -0
  99. package/dist/sap/base/util/isPlainObject.js +35 -1
  100. package/dist/sap/base/util/now.js +24 -3
  101. package/dist/sap/base/util/resolveReference.js +157 -0
  102. package/dist/sap/base/util/uid.js +27 -0
  103. package/dist/sap/ui/base/DataType.js +657 -0
  104. package/dist/sap/ui/base/Interface.js +47 -1
  105. package/dist/sap/ui/base/Metadata.js +433 -180
  106. package/dist/sap/ui/base/Object.js +284 -48
  107. package/dist/sap/ui/core/CalendarType.js +23 -1
  108. package/dist/sap/ui/core/Locale.js +189 -57
  109. package/dist/sap/ui/core/LocaleData.js +2670 -1380
  110. package/dist/sap/ui/core/Supportability.js +5 -0
  111. package/dist/sap/ui/core/Theming.js +539 -0
  112. package/dist/sap/ui/core/date/Buddhist.js +162 -87
  113. package/dist/sap/ui/core/date/CalendarUtils.js +61 -21
  114. package/dist/sap/ui/core/date/CalendarWeekNumbering.js +29 -1
  115. package/dist/sap/ui/core/date/Gregorian.js +25 -10
  116. package/dist/sap/ui/core/date/Islamic.js +298 -185
  117. package/dist/sap/ui/core/date/Japanese.js +210 -115
  118. package/dist/sap/ui/core/date/Persian.js +324 -195
  119. package/dist/sap/ui/core/date/UI5Date.js +923 -237
  120. package/dist/sap/ui/core/date/UniversalDate.js +1238 -245
  121. package/dist/sap/ui/core/date/_Calendars.js +10 -1
  122. package/dist/sap/ui/core/format/DateFormat.js +3163 -2145
  123. package/dist/sap/ui/core/format/TimezoneUtil.js +23 -1
  124. package/package-scripts.cjs +4 -10
  125. package/package.json +9 -5
  126. package/used-modules.txt +20 -1
  127. package/dist/sap/ui/Device.js +0 -5
@@ -0,0 +1,657 @@
1
+ /*!
2
+ * OpenUI5
3
+ * (c) Copyright 2009-2024 SAP SE or an SAP affiliate company.
4
+ * Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
5
+ */
6
+ /* global Set */
7
+ // Provides class sap.ui.base.DataType
8
+ import ObjectPath from "../../base/util/ObjectPath.js";
9
+ import assert from "../../base/assert.js";
10
+ import Log from "../../base/Log.js";
11
+ import isPlainObject from "../../base/util/isPlainObject.js";
12
+ import resolveReference from "../../base/util/resolveReference.js";
13
+ /**
14
+ * Pseudo-Constructor for class <code>DataType</code>, never to be used.
15
+ *
16
+ * @class Represents the type of properties in a <code>ManagedObject</code> class.
17
+ *
18
+ * Each type provides some metadata like its {@link #getName qualified name} or its
19
+ * {@link #getBaseType base type} in case of a derived type. Array types provide information
20
+ * about the allowed {@link #getComponentType type of components} in an array, enumeration types
21
+ * inform about the set of their allowed {@link #getEnumValues keys and values}.
22
+ *
23
+ * Each type has a method to {@link #isValid check whether a value is valid} for a property
24
+ * of that type.
25
+ *
26
+ * Already defined types can be looked up by calling {@link #.getType DataType.getType}, new
27
+ * types can only be created by calling the factory method {@link #.createType DataType.createType},
28
+ * calling the constructor will throw an error.
29
+ *
30
+ * @author SAP SE
31
+ * @since 0.9.0
32
+ * @alias sap.ui.base.DataType
33
+ * @public
34
+ * @hideconstructor
35
+ * @throws {Error} Constructor must not be called, use {@link #.createType DataType.createType} instead
36
+ */
37
+ var DataType = function () {
38
+ // Avoid construction of a DataType.
39
+ // DataType is only a function to support the "instanceof" operator.
40
+ throw new Error();
41
+ };
42
+
43
+ /**
44
+ * The qualified name of the data type.
45
+ *
46
+ * @returns {string} Name of the data type
47
+ * @public
48
+ */
49
+ DataType.prototype.getName = function () {
50
+ return undefined;
51
+ };
52
+
53
+ /**
54
+ * The base type of this type or undefined if this is a primitive type.
55
+ * @returns {sap.ui.base.DataType|undefined} Base type or <code>undefined</code>
56
+ * @public
57
+ */
58
+ DataType.prototype.getBaseType = function () {
59
+ return undefined;
60
+ };
61
+
62
+ /**
63
+ * Returns the most basic (primitive) type that this type has been derived from.
64
+ *
65
+ * If the type is a primitive type by itself, <code>this</code> is returned.
66
+ *
67
+ * @returns {sap.ui.base.DataType} Primitive type of this type
68
+ * @public
69
+ */
70
+ DataType.prototype.getPrimitiveType = function () {
71
+ /*eslint-disable consistent-this*/
72
+ var oType = this;
73
+ /*eslint-enable consistent-this*/
74
+ while (oType.getBaseType()) {
75
+ oType = oType.getBaseType();
76
+ }
77
+ return oType;
78
+ };
79
+
80
+ /**
81
+ * Returns the component type of this type or <code>undefined</code> if this is not an array type.
82
+ *
83
+ * @returns {sap.ui.base.DataType|undefined} Component type or <code>undefined</code>
84
+ * @public
85
+ */
86
+ DataType.prototype.getComponentType = function () {
87
+ return undefined;
88
+ };
89
+
90
+ /**
91
+ * The default value for this type. Each type must define a default value.
92
+ * @returns {any} Default value of the data type. The type of the returned value
93
+ * must match the JavaScript type of the data type (a string for string types etc.)
94
+ * @public
95
+ */
96
+ DataType.prototype.getDefaultValue = function () {
97
+ return undefined;
98
+ };
99
+
100
+ /**
101
+ * Whether this type is an array type.
102
+ * @returns {boolean} Whether this type is an array type
103
+ * @public
104
+ */
105
+ DataType.prototype.isArrayType = function () {
106
+ return false;
107
+ };
108
+
109
+ /**
110
+ * Whether this type is an enumeration type.
111
+ * @returns {boolean} Whether this type is an enum type
112
+ * @public
113
+ */
114
+ DataType.prototype.isEnumType = function () {
115
+ return false;
116
+ };
117
+
118
+ /**
119
+ * Returns the object with keys and values from which this enum type was created
120
+ * or <code>undefined</code> if this is not an enum type.
121
+ *
122
+ * @returns {Object<string,string>|undefined} Object with enum keys and values or <code>undefined</code>
123
+ * @public
124
+ */
125
+ DataType.prototype.getEnumValues = function () {
126
+ return undefined;
127
+ };
128
+
129
+ /**
130
+ * Parses the given string value and converts it into the specific data type.
131
+ * @param {string} sValue String representation for a value of this type
132
+ * @returns {any} Value in the correct internal format
133
+ * @public
134
+ */
135
+ DataType.prototype.parseValue = function (sValue) {
136
+ return sValue;
137
+ };
138
+
139
+ /**
140
+ * Checks whether the given value is valid for this type.
141
+ *
142
+ * To be implemented by concrete types.
143
+ * @param {any} vValue Value to be checked
144
+ * @returns {boolean} Whether the given value is valid for this data type (without conversion)
145
+ * @public
146
+ * @function
147
+ */
148
+ DataType.prototype.isValid = undefined;
149
+ // Note that <code>isValid</code> must be assigned a falsy value here as it otherwise
150
+ // would be called in addition to any <code>isValid</code> implementation in subtypes.
151
+ // See <code>createType</code> for details.
152
+
153
+ /**
154
+ * Set or unset a normalizer function to be used for values of this data type.
155
+ *
156
+ * When a normalizer function has been set, it will be applied to values of this type
157
+ * whenever {@link #normalize} is called. <code>ManagedObject.prototype.setProperty</code>
158
+ * calls the <code>normalize</code> method before setting a new value to a property
159
+ * (normalization is applied on-write, not on-read).
160
+ *
161
+ * The <code>fnNormalize</code> function has the signature
162
+ * <pre>
163
+ * fnNormalize(value:any) : any
164
+ * </pre>
165
+ * It will be called with a value for this type and should return a normalized
166
+ * value (which also must be valid for the this type). There's no mean to reject a value.
167
+ * The <code>this</code> context of the function will be this type.
168
+ *
169
+ * This method allows applications or application frameworks to plug-in a generic value
170
+ * normalization for a type, e.g. to convert all URLs in some app-specific way before
171
+ * they are applied to controls. It is not intended to break-out of the value range
172
+ * defined by a type.
173
+ *
174
+ * @param {function(any):any} fnNormalizer Function to apply for normalizing
175
+ * @public
176
+ */
177
+ DataType.prototype.setNormalizer = function (fnNormalizer) {
178
+ assert(typeof fnNormalizer === "function", "DataType.setNormalizer: fnNormalizer must be a function");
179
+ this._fnNormalizer = typeof fnNormalizer === "function" ? fnNormalizer : undefined;
180
+ };
181
+
182
+ /**
183
+ * Normalizes the given value using the specified normalizer for this data type.
184
+ *
185
+ * If no normalizer has been set, the original value is returned.
186
+ *
187
+ * @param {any} oValue Value to be normalized
188
+ * @returns {any} Normalized value
189
+ * @public
190
+ */
191
+ DataType.prototype.normalize = function (oValue) {
192
+ return this._fnNormalizer ? this._fnNormalizer(oValue) : oValue;
193
+ };
194
+ function createType(sName, mSettings, oBase) {
195
+ mSettings = mSettings || {};
196
+
197
+ // create a new type object with the base type as prototype
198
+ var oBaseObject = oBase || DataType.prototype;
199
+ var oType = Object.create(oBaseObject);
200
+
201
+ // getter for the name
202
+ oType.getName = function () {
203
+ return sName;
204
+ };
205
+
206
+ // if a default value is specified, create a getter for it
207
+ if (mSettings.hasOwnProperty("defaultValue")) {
208
+ var vDefault = mSettings.defaultValue;
209
+ oType.getDefaultValue = function () {
210
+ return vDefault;
211
+ };
212
+ }
213
+
214
+ // if a validator is specified either chain it with the base type validator
215
+ // or set it if no base validator exists
216
+ if (mSettings.isValid) {
217
+ var fnIsValid = mSettings.isValid;
218
+ oType.isValid = oBaseObject.isValid ? function (vValue) {
219
+ if (!oBaseObject.isValid(vValue)) {
220
+ return false;
221
+ }
222
+ return fnIsValid(vValue);
223
+ } : fnIsValid;
224
+ }
225
+ if (mSettings.parseValue) {
226
+ oType.parseValue = mSettings.parseValue;
227
+ }
228
+
229
+ // return the base type
230
+ oType.getBaseType = function () {
231
+ return oBase;
232
+ };
233
+ return oType;
234
+ }
235
+ var mTypes = {
236
+ "any": createType("any", {
237
+ defaultValue: null,
238
+ isValid: function (vValue) {
239
+ return true;
240
+ }
241
+ }),
242
+ "boolean": createType("boolean", {
243
+ defaultValue: false,
244
+ isValid: function (vValue) {
245
+ return typeof vValue === "boolean";
246
+ },
247
+ parseValue: function (sValue) {
248
+ return sValue == "true";
249
+ }
250
+ }),
251
+ "int": createType("int", {
252
+ defaultValue: 0,
253
+ isValid: function (vValue) {
254
+ return typeof vValue === "number" && (isNaN(vValue) || Math.floor(vValue) == vValue);
255
+ },
256
+ parseValue: function (sValue) {
257
+ return parseInt(sValue);
258
+ }
259
+ }),
260
+ "float": createType("float", {
261
+ defaultValue: 0.0,
262
+ isValid: function (vValue) {
263
+ return typeof vValue === "number";
264
+ },
265
+ parseValue: function (sValue) {
266
+ return parseFloat(sValue);
267
+ }
268
+ }),
269
+ "string": createType("string", {
270
+ defaultValue: "",
271
+ isValid: function (vValue) {
272
+ return typeof vValue === "string" || vValue instanceof String;
273
+ },
274
+ parseValue: function (sValue) {
275
+ return sValue;
276
+ }
277
+ }),
278
+ "object": createType("object", {
279
+ defaultValue: null,
280
+ isValid: function (vValue) {
281
+ return typeof vValue === "object" || typeof vValue === "function";
282
+ },
283
+ parseValue: function (sValue) {
284
+ return sValue ? JSON.parse(sValue) : null;
285
+ }
286
+ }),
287
+ "function": createType("function", {
288
+ defaultValue: null,
289
+ isValid: function (vValue) {
290
+ return vValue == null || typeof vValue === 'function';
291
+ },
292
+ /*
293
+ * Note: the second parameter <code>_oOptions</code> is a hidden feature for internal use only.
294
+ * Its structure is subject to change. No code other than the XMLTemplateProcessor must use it.
295
+ */
296
+ parseValue: function (sValue, _oOptions) {
297
+ if (sValue === "") {
298
+ return undefined;
299
+ }
300
+ if (!/^\.?[A-Z_\$][A-Z0-9_\$]*(\.[A-Z_\$][A-Z0-9_\$]*)*$/i.test(sValue)) {
301
+ throw new Error("Function references must consist of dot separated " + "simple identifiers (A-Z, 0-9, _ or $) only, but was '" + sValue + "'");
302
+ }
303
+ var fnResult,
304
+ oContext = _oOptions && _oOptions.context,
305
+ oLocals = _oOptions && _oOptions.locals;
306
+ fnResult = resolveReference(sValue, Object.assign({
307
+ ".": oContext
308
+ }, oLocals));
309
+ if (fnResult && this.isValid(fnResult)) {
310
+ return fnResult;
311
+ }
312
+ throw new TypeError("The string '" + sValue + "' couldn't be resolved to a function");
313
+ }
314
+ })
315
+ };
316
+
317
+ // The generic "array" type must not be exposed by DataType.getType to avoid direct usage
318
+ // as type of a managed property. It is therefore not stored in the mTypes map
319
+ var arrayType = createType("array", {
320
+ defaultValue: []
321
+ });
322
+ function createArrayType(componentType) {
323
+ assert(componentType instanceof DataType, "DataType.<createArrayType>: componentType must be a DataType");
324
+
325
+ // create a new type object with the base type as prototype
326
+ var oType = Object.create(DataType.prototype);
327
+
328
+ // getter for the name
329
+ oType.getName = function () {
330
+ return componentType.getName() + "[]";
331
+ };
332
+
333
+ // getter for component type
334
+ oType.getComponentType = function () {
335
+ return componentType;
336
+ };
337
+
338
+ // array validator
339
+ oType.isValid = function (aValues) {
340
+ if (aValues === null) {
341
+ return true;
342
+ }
343
+ if (Array.isArray(aValues)) {
344
+ for (var i = 0; i < aValues.length; i++) {
345
+ if (!componentType.isValid(aValues[i])) {
346
+ return false;
347
+ }
348
+ }
349
+ return true;
350
+ }
351
+ return false;
352
+ };
353
+
354
+ // array parser
355
+ oType.parseValue = function (sValue) {
356
+ var aValues = sValue.split(",");
357
+ for (var i = 0; i < aValues.length; i++) {
358
+ aValues[i] = componentType.parseValue(aValues[i]);
359
+ }
360
+ return aValues;
361
+ };
362
+
363
+ // is an array type
364
+ oType.isArrayType = function () {
365
+ return true;
366
+ };
367
+
368
+ // return the base type
369
+ oType.getBaseType = function () {
370
+ return arrayType;
371
+ };
372
+ return oType;
373
+ }
374
+ const mEnumRegistry = Object.create(null);
375
+ function createEnumType(sTypeName, oEnum) {
376
+ var mValues = {},
377
+ sDefaultValue;
378
+ for (var sName in oEnum) {
379
+ var sValue = oEnum[sName];
380
+ // the first entry will become the default value
381
+ if (!sDefaultValue) {
382
+ sDefaultValue = sValue;
383
+ }
384
+ if (typeof sValue !== "string") {
385
+ throw new Error("Value " + sValue + " for enum type " + sTypeName + " is not a string");
386
+ }
387
+ // if there are multiple entries with the same value, the one where name
388
+ // and value are matching is taken
389
+ if (!mValues.hasOwnProperty(sValue) || sName == sValue) {
390
+ mValues[sValue] = sName;
391
+ }
392
+ }
393
+ var oType = Object.create(DataType.prototype);
394
+
395
+ // getter for the name
396
+ oType.getName = function () {
397
+ return sTypeName;
398
+ };
399
+
400
+ // enum validator
401
+ oType.isValid = function (v) {
402
+ return typeof v === "string" && mValues.hasOwnProperty(v);
403
+ };
404
+
405
+ // enum parser
406
+ oType.parseValue = function (sValue) {
407
+ return oEnum[sValue];
408
+ };
409
+
410
+ // default value
411
+ oType.getDefaultValue = function () {
412
+ return sDefaultValue;
413
+ };
414
+
415
+ // return the base type
416
+ oType.getBaseType = function () {
417
+ return mTypes.string;
418
+ };
419
+
420
+ // is an enum type
421
+ oType.isEnumType = function () {
422
+ return true;
423
+ };
424
+
425
+ // enum values are best represented by the existing global object
426
+ oType.getEnumValues = function () {
427
+ return oEnum;
428
+ };
429
+ return oType;
430
+ }
431
+
432
+ /**
433
+ * Looks up the type with the given name and returns it.
434
+ *
435
+ * See {@link topic:ac56d92162ed47ff858fdf1ce26c18c4 Defining Control Properties} for
436
+ * a list of the built-in primitive types and their semantics.
437
+ *
438
+ * The lookup consists of the following steps:
439
+ * <ul>
440
+ * <li>When a type with the given name is already known, it will be returned</li>
441
+ * <li>When the name ends with a pair of brackets (<code>[]</code>), a type with the name
442
+ * in front of the brackets (<code>name.slice(0,-2)</code>) will be looked up and an
443
+ * array type will be created with the looked-up type as its component type. If the
444
+ * component type is <code>undefined</code>, <code>undefined</code> will be returned</li>
445
+ * <li>When a global property exists with the same name as the type and when the value of that
446
+ * property is an instance of <code>DataType</code>, that instance will be returned</li>
447
+ * <li>When a global property exists with the same name as the type and when the value of that
448
+ * property is a plain object (its prototype is <code>Object</code>), then an enum type will
449
+ * be created, based on the keys and values in that object. The <code>parseValue</code> method
450
+ * of the type will accept any of the keys in the plain object and convert them to the
451
+ * corresponding value; <code>isValid</code> will accept any of the values from the plain
452
+ * object's keys. The <code>defaultValue</code> will be the value of the first key found in
453
+ * the plain object</li>
454
+ * <li>When a global property exist with any other, non-falsy value, a warning is logged and the
455
+ * primitive type 'any' is returned</li>
456
+ * <li>If no such global property exist, an error is logged and <code>undefined</code>
457
+ * is returned</li>
458
+ * </ul>
459
+ *
460
+ * <b<Note:</b> UI Libraries and even components can introduce additional types. This method
461
+ * only checks for types that either have been defined already, or that describe arrays of
462
+ * values of an already defined type or types whose name matches the global name of a plain
463
+ * object (containing enum keys and values). This method doesn't try to load modules that
464
+ * might contain type definitions. So before being able to lookup and use a specific type,
465
+ * the module containing its definition has to be loaded. For that reason it is suggested that
466
+ * controls (or <code>ManagedObject</code> classes in general) declare a dependency to all
467
+ * modules (typically <code>some/lib/library.js</code> modules) that contain the type definitions
468
+ * needed by the specific control or class definition.
469
+ *
470
+ * @param {string} sTypeName Qualified name of the type to retrieve
471
+ * @returns {sap.ui.base.DataType|undefined} Type object or <code>undefined</code> when
472
+ * no such type has been defined yet
473
+ * @public
474
+ */
475
+ DataType.getType = function (sTypeName) {
476
+ assert(sTypeName && typeof sTypeName === 'string', "sTypeName must be a non-empty string");
477
+ var oType = mTypes[sTypeName];
478
+ if (!(oType instanceof DataType)) {
479
+ // check for array types
480
+ if (sTypeName.indexOf("[]", sTypeName.length - 2) > 0) {
481
+ var sComponentTypeName = sTypeName.slice(0, -2),
482
+ oComponentType = this.getType(sComponentTypeName);
483
+ oType = oComponentType && createArrayType(oComponentType);
484
+ if (oType) {
485
+ mTypes[sTypeName] = oType;
486
+ }
487
+ } else if (sTypeName !== 'array') {
488
+ // check if we have a valid pre-registered enum
489
+ oType = mEnumRegistry[sTypeName];
490
+
491
+ /**
492
+ * If an enum was not registered beforehand (either explicitly via registerEnum or
493
+ * via a Proxy in the library namespace), we have to look it up in the global object.
494
+ * @deprecated since 1.120
495
+ */
496
+ if (oType == null) {
497
+ oType = ObjectPath.get(sTypeName);
498
+ if (oType != null) {
499
+ Log.error(`The type '${sTypeName}' was accessed via globals. Defining enums via globals is deprecated. Please require the module 'sap/ui/base/DataType' and call the static 'DataType.registerEnum' API.`);
500
+ }
501
+ }
502
+ if (oType instanceof DataType) {
503
+ mTypes[sTypeName] = oType;
504
+ } else if (isPlainObject(oType)) {
505
+ oType = mTypes[sTypeName] = createEnumType(sTypeName, oType);
506
+ delete mEnumRegistry[sTypeName];
507
+ } else if (oType) {
508
+ Log.warning("[FUTURE FATAL] '" + sTypeName + "' is not a valid data type. Falling back to type 'any'.");
509
+ oType = mTypes.any;
510
+ } else {
511
+ Log.error("[FUTURE FATAL] data type '" + sTypeName + "' could not be found.");
512
+ oType = undefined;
513
+ }
514
+ }
515
+ }
516
+ return oType;
517
+ };
518
+
519
+ /**
520
+ * Derives a new type from a given base type.
521
+ *
522
+ * Example:<br>
523
+ * <pre>
524
+ *
525
+ * var fooType = DataType.createType('foo', {
526
+ * isValid : function(vValue) {
527
+ * return /^(foo(bar)?)$/.test(vValue);
528
+ * }
529
+ * }, DataType.getType('string'));
530
+ *
531
+ * fooType.isValid('foo'); // true
532
+ * fooType.isValid('foobar'); // true
533
+ * fooType.isValid('==foobar=='); // false
534
+ *
535
+ * </pre>
536
+ *
537
+ * If <code>mSettings</code> contains an implementation for <code>isValid</code>,
538
+ * then the validity check of the newly created type will first execute the check of the
539
+ * base type and then call the given <code>isValid</code> function.
540
+ *
541
+ * Array types and enumeration types cannot be created with this method. They're created
542
+ * on-the-fly by {@link #.getType DataType.getType} when such a type is looked up.
543
+ *
544
+ * <b>Note:</b> The creation of new primitive types is not supported. When a type is created
545
+ * without a base type, it is automatically derived from the primitive type <code>any</code>.
546
+ *
547
+ * <b>Note:</b> If a type has to be used in classes, then the implementation of
548
+ * <code>isValid</code> must exactly have the structure shown in the example above (single
549
+ * return statement, regular expression literal of the form <code>/^(...)$/</code>, calling
550
+ * <code>/regex/.test()</code> on the given value).
551
+ * Only the inner part of the regular expression literal can be different.
552
+ *
553
+ * @param {string} sName Unique qualified name of the new type
554
+ * @param {object} [mSettings] Settings for the new type
555
+ * @param {any} [mSettings.defaultValue] Default value for the type (inherited if not given)
556
+ * @param {function} [mSettings.isValid] Additional validity check function for values of the
557
+ * type (inherited if not given)
558
+ * @param {function} [mSettings.parseValue] Parse function that converts a locale independent
559
+ * string into a value of the type (inherited if not given)
560
+ * @param {sap.ui.base.DataType|string} [vBase='any'] Base type for the new type
561
+ * @returns {sap.ui.base.DataType} The newly created type object
562
+ * @public
563
+ */
564
+ DataType.createType = function (sName, mSettings, vBase) {
565
+ assert(typeof sName === "string" && sName, "DataType.createType: type name must be a non-empty string");
566
+ assert(vBase == null || vBase instanceof DataType || typeof vBase === "string" && vBase, "DataType.createType: base type must be empty or a DataType or a non-empty string");
567
+ if (/[\[\]]/.test(sName)) {
568
+ Log.error("[FUTURE FATAL] DataType.createType: array types ('something[]') must not be created with createType, " + "they're created on-the-fly by DataType.getType");
569
+ }
570
+ if (typeof vBase === "string") {
571
+ vBase = DataType.getType(vBase);
572
+ }
573
+ vBase = vBase || mTypes.any;
574
+ if (vBase.isArrayType() || vBase.isEnumType()) {
575
+ Log.error("[FUTURE FATAL] DataType.createType: base type must not be an array- or enum-type");
576
+ }
577
+ if (sName === 'array' || mTypes[sName] instanceof DataType) {
578
+ if (sName === 'array' || mTypes[sName].getBaseType() == null) {
579
+ throw new Error("DataType.createType: primitive or hidden type " + sName + " can't be re-defined");
580
+ }
581
+ Log.warning("[FUTURE FATAL] DataTypes.createType: type " + sName + " is redefined. " + "This is an unsupported usage of DataType and might cause issues.");
582
+ }
583
+ var oType = mTypes[sName] = createType(sName, mSettings, vBase);
584
+ return oType;
585
+ };
586
+
587
+ // ---- minimal support for interface types -------------------------------------------------------------------
588
+
589
+ var oInterfaces = new Set();
590
+
591
+ /**
592
+ * Registers the given array of type names as known interface types.
593
+ * Only purpose is to enable the {@link #isInterfaceType} check.
594
+ * @param {string[]} aTypes interface types to be registered
595
+ * @private
596
+ * @ui5-restricted sap.ui.core.Core
597
+ */
598
+ DataType.registerInterfaceTypes = function (aTypes) {
599
+ aTypes.forEach(function (sType) {
600
+ oInterfaces.add(sType);
601
+
602
+ // Defining the interface on global namespace for compatibility reasons.
603
+ // This has never been a public feature and it is strongly discouraged it be relied upon.
604
+ // An interface must always be referenced by a string literal, not via the global namespace.
605
+ ObjectPath.set(sType, sType);
606
+ });
607
+ };
608
+
609
+ /**
610
+ * Registers an enum under the given name.
611
+ * With version 2.0, registering an enum becomes mandatory when said enum is to be used in
612
+ * properties of a {@link sap.ui.base.ManagedObject ManagedObject} subclass.
613
+ *
614
+ * Example:<br>
615
+ * <pre>
616
+ * DataType.registerEnum("my.enums.Sample", {
617
+ * "A": "A",
618
+ * "B": "B",
619
+ * ...
620
+ * });
621
+ * </pre>
622
+ *
623
+ * @param {string} sTypeName the type name in dot syntax, e.g. sap.ui.my.EnumType
624
+ * @param {object} mContent the enum content
625
+ * @public
626
+ * @since 1.120.0
627
+ */
628
+ DataType.registerEnum = function (sTypeName, mContent) {
629
+ mEnumRegistry[sTypeName] = mContent;
630
+ };
631
+
632
+ /**
633
+ * Checks if the given object contains only static content
634
+ * and can be regarded as an enum candidate.
635
+ *
636
+ * @param {object} oObject the enum candidate
637
+ * @returns {boolean} whether the given object can be regarded as an enum candidate
638
+ * @private
639
+ * @ui5-restricted sap.ui.core.Lib
640
+ */
641
+ DataType._isEnumCandidate = function (oObject) {
642
+ return !Object.keys(oObject).some(key => {
643
+ const propertyType = typeof oObject[key];
644
+ return propertyType === "object" || propertyType === "function";
645
+ });
646
+ };
647
+
648
+ /**
649
+ * @param {string} sType name of type to check
650
+ * @returns {boolean} whether the given type is known to be an interface type
651
+ * @private
652
+ * @ui5-restricted sap.ui.base.ManagedObject
653
+ */
654
+ DataType.isInterfaceType = function (sType) {
655
+ return oInterfaces.has(sType);
656
+ };
657
+ export default DataType;