@fkui/logic 5.36.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/LICENSE.md +7 -0
- package/README.md +3 -0
- package/lib/cjs/index.js +5124 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/polyfills.js +3 -0
- package/lib/cjs/polyfills.js.map +1 -0
- package/lib/esm/index.js +5047 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/package.json +3 -0
- package/lib/esm/polyfills.js +2 -0
- package/lib/esm/polyfills.js.map +1 -0
- package/lib/polyfills.js +3 -0
- package/lib/types/index.d.ts +1337 -0
- package/lib/types/polyfills.d.ts +2 -0
- package/lib/types/tsdoc-metadata.json +11 -0
- package/package.json +71 -0
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,5047 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @public
|
|
3
|
+
*/
|
|
4
|
+
const configLogic = {
|
|
5
|
+
production: true,
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Determine if a value is empty.
|
|
10
|
+
*
|
|
11
|
+
* A value is considered empty if it is:
|
|
12
|
+
*
|
|
13
|
+
* - `undefined`
|
|
14
|
+
* - `null`
|
|
15
|
+
* - empty string `""`.
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
18
|
+
* @param value - value to check if it is empty
|
|
19
|
+
*/
|
|
20
|
+
function isEmpty(value) {
|
|
21
|
+
return !value;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Determine if a value is set. If it is undefined or null, this function
|
|
26
|
+
* returns false.
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
* @param value - the value for which to determine if it is set
|
|
30
|
+
*/
|
|
31
|
+
function isSet(value) {
|
|
32
|
+
return value !== undefined && value !== null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
function isString(value) {
|
|
39
|
+
return typeof value === "string" || value instanceof String;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Matches a single whitespace globally.
|
|
44
|
+
*
|
|
45
|
+
* @public
|
|
46
|
+
* @deprecated Use {@link stripWhitespace} instead
|
|
47
|
+
*/
|
|
48
|
+
const WHITESPACE_PATTERN = /\s/g;
|
|
49
|
+
/**
|
|
50
|
+
* @public
|
|
51
|
+
* @deprecated Use {@link formatNumber} instead.
|
|
52
|
+
*/
|
|
53
|
+
const FORMAT_3_DIGITS_GROUPS = /\B(?=(\d{3})+(?!\d))/g;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Implementation of Object.fromEntries() until we run a recent enough version
|
|
57
|
+
* of NodeJS.
|
|
58
|
+
*
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
function fromEntries(iterable) {
|
|
62
|
+
return iterable.reduce((obj, [key, value]) => {
|
|
63
|
+
obj[key] = value;
|
|
64
|
+
return obj;
|
|
65
|
+
}, {});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Recursively strips null from source parameter.
|
|
69
|
+
*
|
|
70
|
+
* - Literals string, numbers etc will be returned as-is.
|
|
71
|
+
* - Literal `null` will return `undefined`
|
|
72
|
+
* - Arrays with `null` be replace element with `undefined`, i.e. the length of
|
|
73
|
+
* the array is not modified.
|
|
74
|
+
* - Object values with `null` will be removed, i.e. `hasOwnProperty(..)` will
|
|
75
|
+
* return `false`.
|
|
76
|
+
*
|
|
77
|
+
* @public
|
|
78
|
+
* @param src - Source value
|
|
79
|
+
* @returns A copy of the source parameter with any null stripped
|
|
80
|
+
*/
|
|
81
|
+
/* eslint-disable @typescript-eslint/no-explicit-any -- technical debt */
|
|
82
|
+
function stripNull(src) {
|
|
83
|
+
/* handle literal null */
|
|
84
|
+
if (src === null) {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
/* handle arrays recursively */
|
|
88
|
+
if (Array.isArray(src)) {
|
|
89
|
+
return src.map(stripNull);
|
|
90
|
+
}
|
|
91
|
+
/* handle pod literals such as string, number, etc */
|
|
92
|
+
if (typeof src !== "object") {
|
|
93
|
+
return src;
|
|
94
|
+
}
|
|
95
|
+
/* unpack object to a [key, value] array */
|
|
96
|
+
const entries = Object.entries(src)
|
|
97
|
+
/* filter out any entries where value is null */
|
|
98
|
+
.filter(([, value]) => value !== null)
|
|
99
|
+
/* recursively replace values from the [key, value] array */
|
|
100
|
+
.map(([key, value]) => {
|
|
101
|
+
return [key, stripNull(value)];
|
|
102
|
+
});
|
|
103
|
+
/* reconstruct a new object from the [key, value] array */
|
|
104
|
+
return fromEntries(entries);
|
|
105
|
+
}
|
|
106
|
+
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Decorates an original error with more information while
|
|
110
|
+
* keeping the original intact.
|
|
111
|
+
*
|
|
112
|
+
* @public
|
|
113
|
+
*/
|
|
114
|
+
class DecoratedError extends Error {
|
|
115
|
+
cause;
|
|
116
|
+
constructor(message, cause) {
|
|
117
|
+
super(message);
|
|
118
|
+
Object.setPrototypeOf(this, DecoratedError.prototype);
|
|
119
|
+
this.stack += `\nCaused by: ${cause.stack}`;
|
|
120
|
+
this.cause = cause;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Get the direct cause of this error, the one that triggered
|
|
124
|
+
* this error.
|
|
125
|
+
*/
|
|
126
|
+
getCause() {
|
|
127
|
+
return this.cause;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get the root cause of this error, the first error that occured.
|
|
131
|
+
*/
|
|
132
|
+
getRootCause() {
|
|
133
|
+
const cause = this.cause;
|
|
134
|
+
if (cause instanceof DecoratedError) {
|
|
135
|
+
return cause.getRootCause();
|
|
136
|
+
}
|
|
137
|
+
return cause;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @public
|
|
143
|
+
* @deprecated Use `FDate` instead.
|
|
144
|
+
*/
|
|
145
|
+
const DATE_REGEXP_WITH_DASH = /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/;
|
|
146
|
+
/**
|
|
147
|
+
* @public
|
|
148
|
+
*/
|
|
149
|
+
function validLimit(limit) {
|
|
150
|
+
if (typeof limit !== "string" || isEmpty(limit)) {
|
|
151
|
+
throw new Error(`limit must be a non-empty string`);
|
|
152
|
+
}
|
|
153
|
+
const limitAsString = limit;
|
|
154
|
+
if (!DATE_REGEXP_WITH_DASH.test(limitAsString)) {
|
|
155
|
+
throw new Error(`limit has invalid format`);
|
|
156
|
+
}
|
|
157
|
+
return limitAsString;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Executes a function when it stops being invoked for n seconds. Usually used together with resize,
|
|
162
|
+
* scroll and keyup/keydown-events to improve application's performance.
|
|
163
|
+
*
|
|
164
|
+
* Example:
|
|
165
|
+
*
|
|
166
|
+
* ```
|
|
167
|
+
* window.addEventListener(
|
|
168
|
+
* 'resize',
|
|
169
|
+
* debounce(computationalHeavyFunction, 1000),
|
|
170
|
+
* );
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* This will call the `computationalHeavyFunction` once if the resize-event hasn't been sent for 1000 ms.
|
|
174
|
+
*
|
|
175
|
+
* Example with immediate-flag:
|
|
176
|
+
*
|
|
177
|
+
* ```
|
|
178
|
+
* window.addEventListener(
|
|
179
|
+
* 'resize',
|
|
180
|
+
* debounce(computationalHeavyFunction, 1000, true),
|
|
181
|
+
* );
|
|
182
|
+
* ```
|
|
183
|
+
*
|
|
184
|
+
* This will call the `computationalHeavyFunction` once BEFORE the resize-event has finished,
|
|
185
|
+
* and thereafter will not be able to be called again until the timeout has finished
|
|
186
|
+
*
|
|
187
|
+
* @public
|
|
188
|
+
* @param func - Function to be debounced.
|
|
189
|
+
* @param delay - Function execution threshold in milliseconds.
|
|
190
|
+
* @param immediate - Whether the function should be called at the beginning of the delay (Before the timeout) instead of the end.
|
|
191
|
+
* Default is false.
|
|
192
|
+
*/
|
|
193
|
+
function debounce(func, delay, immediate = false) {
|
|
194
|
+
let timeout = null;
|
|
195
|
+
return function functionToExecute(...args) {
|
|
196
|
+
const timedOutFunction = () => {
|
|
197
|
+
timeout = null;
|
|
198
|
+
if (!immediate) {
|
|
199
|
+
func.apply(this, args);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
const callNow = immediate && !timeout;
|
|
203
|
+
if (timeout !== null) {
|
|
204
|
+
clearTimeout(timeout);
|
|
205
|
+
}
|
|
206
|
+
timeout = setTimeout(timedOutFunction, delay);
|
|
207
|
+
if (callNow) {
|
|
208
|
+
func.apply(this);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
var commonjsGlobal$1 = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
214
|
+
|
|
215
|
+
function getDefaultExportFromCjs$1 (x) {
|
|
216
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
var lodash_clonedeep = {exports: {}};
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* lodash (Custom Build) <https://lodash.com/>
|
|
223
|
+
* Build: `lodash modularize exports="npm" -o ./`
|
|
224
|
+
* Copyright jQuery Foundation and other contributors <https://jquery.org/>
|
|
225
|
+
* Released under MIT license <https://lodash.com/license>
|
|
226
|
+
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
227
|
+
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
228
|
+
*/
|
|
229
|
+
lodash_clonedeep.exports;
|
|
230
|
+
|
|
231
|
+
(function (module, exports) {
|
|
232
|
+
/** Used as the size to enable large array optimizations. */
|
|
233
|
+
var LARGE_ARRAY_SIZE = 200;
|
|
234
|
+
|
|
235
|
+
/** Used to stand-in for `undefined` hash values. */
|
|
236
|
+
var HASH_UNDEFINED = '__lodash_hash_undefined__';
|
|
237
|
+
|
|
238
|
+
/** Used as references for various `Number` constants. */
|
|
239
|
+
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
240
|
+
|
|
241
|
+
/** `Object#toString` result references. */
|
|
242
|
+
var argsTag = '[object Arguments]',
|
|
243
|
+
arrayTag = '[object Array]',
|
|
244
|
+
boolTag = '[object Boolean]',
|
|
245
|
+
dateTag = '[object Date]',
|
|
246
|
+
errorTag = '[object Error]',
|
|
247
|
+
funcTag = '[object Function]',
|
|
248
|
+
genTag = '[object GeneratorFunction]',
|
|
249
|
+
mapTag = '[object Map]',
|
|
250
|
+
numberTag = '[object Number]',
|
|
251
|
+
objectTag = '[object Object]',
|
|
252
|
+
promiseTag = '[object Promise]',
|
|
253
|
+
regexpTag = '[object RegExp]',
|
|
254
|
+
setTag = '[object Set]',
|
|
255
|
+
stringTag = '[object String]',
|
|
256
|
+
symbolTag = '[object Symbol]',
|
|
257
|
+
weakMapTag = '[object WeakMap]';
|
|
258
|
+
|
|
259
|
+
var arrayBufferTag = '[object ArrayBuffer]',
|
|
260
|
+
dataViewTag = '[object DataView]',
|
|
261
|
+
float32Tag = '[object Float32Array]',
|
|
262
|
+
float64Tag = '[object Float64Array]',
|
|
263
|
+
int8Tag = '[object Int8Array]',
|
|
264
|
+
int16Tag = '[object Int16Array]',
|
|
265
|
+
int32Tag = '[object Int32Array]',
|
|
266
|
+
uint8Tag = '[object Uint8Array]',
|
|
267
|
+
uint8ClampedTag = '[object Uint8ClampedArray]',
|
|
268
|
+
uint16Tag = '[object Uint16Array]',
|
|
269
|
+
uint32Tag = '[object Uint32Array]';
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Used to match `RegExp`
|
|
273
|
+
* [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
|
|
274
|
+
*/
|
|
275
|
+
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
|
|
276
|
+
|
|
277
|
+
/** Used to match `RegExp` flags from their coerced string values. */
|
|
278
|
+
var reFlags = /\w*$/;
|
|
279
|
+
|
|
280
|
+
/** Used to detect host constructors (Safari). */
|
|
281
|
+
var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
|
282
|
+
|
|
283
|
+
/** Used to detect unsigned integer values. */
|
|
284
|
+
var reIsUint = /^(?:0|[1-9]\d*)$/;
|
|
285
|
+
|
|
286
|
+
/** Used to identify `toStringTag` values supported by `_.clone`. */
|
|
287
|
+
var cloneableTags = {};
|
|
288
|
+
cloneableTags[argsTag] = cloneableTags[arrayTag] =
|
|
289
|
+
cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
|
|
290
|
+
cloneableTags[boolTag] = cloneableTags[dateTag] =
|
|
291
|
+
cloneableTags[float32Tag] = cloneableTags[float64Tag] =
|
|
292
|
+
cloneableTags[int8Tag] = cloneableTags[int16Tag] =
|
|
293
|
+
cloneableTags[int32Tag] = cloneableTags[mapTag] =
|
|
294
|
+
cloneableTags[numberTag] = cloneableTags[objectTag] =
|
|
295
|
+
cloneableTags[regexpTag] = cloneableTags[setTag] =
|
|
296
|
+
cloneableTags[stringTag] = cloneableTags[symbolTag] =
|
|
297
|
+
cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
|
|
298
|
+
cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
|
|
299
|
+
cloneableTags[errorTag] = cloneableTags[funcTag] =
|
|
300
|
+
cloneableTags[weakMapTag] = false;
|
|
301
|
+
|
|
302
|
+
/** Detect free variable `global` from Node.js. */
|
|
303
|
+
var freeGlobal = typeof commonjsGlobal$1 == 'object' && commonjsGlobal$1 && commonjsGlobal$1.Object === Object && commonjsGlobal$1;
|
|
304
|
+
|
|
305
|
+
/** Detect free variable `self`. */
|
|
306
|
+
var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
|
|
307
|
+
|
|
308
|
+
/** Used as a reference to the global object. */
|
|
309
|
+
var root = freeGlobal || freeSelf || Function('return this')();
|
|
310
|
+
|
|
311
|
+
/** Detect free variable `exports`. */
|
|
312
|
+
var freeExports = exports && !exports.nodeType && exports;
|
|
313
|
+
|
|
314
|
+
/** Detect free variable `module`. */
|
|
315
|
+
var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
|
|
316
|
+
|
|
317
|
+
/** Detect the popular CommonJS extension `module.exports`. */
|
|
318
|
+
var moduleExports = freeModule && freeModule.exports === freeExports;
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Adds the key-value `pair` to `map`.
|
|
322
|
+
*
|
|
323
|
+
* @private
|
|
324
|
+
* @param {Object} map The map to modify.
|
|
325
|
+
* @param {Array} pair The key-value pair to add.
|
|
326
|
+
* @returns {Object} Returns `map`.
|
|
327
|
+
*/
|
|
328
|
+
function addMapEntry(map, pair) {
|
|
329
|
+
// Don't return `map.set` because it's not chainable in IE 11.
|
|
330
|
+
map.set(pair[0], pair[1]);
|
|
331
|
+
return map;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Adds `value` to `set`.
|
|
336
|
+
*
|
|
337
|
+
* @private
|
|
338
|
+
* @param {Object} set The set to modify.
|
|
339
|
+
* @param {*} value The value to add.
|
|
340
|
+
* @returns {Object} Returns `set`.
|
|
341
|
+
*/
|
|
342
|
+
function addSetEntry(set, value) {
|
|
343
|
+
// Don't return `set.add` because it's not chainable in IE 11.
|
|
344
|
+
set.add(value);
|
|
345
|
+
return set;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* A specialized version of `_.forEach` for arrays without support for
|
|
350
|
+
* iteratee shorthands.
|
|
351
|
+
*
|
|
352
|
+
* @private
|
|
353
|
+
* @param {Array} [array] The array to iterate over.
|
|
354
|
+
* @param {Function} iteratee The function invoked per iteration.
|
|
355
|
+
* @returns {Array} Returns `array`.
|
|
356
|
+
*/
|
|
357
|
+
function arrayEach(array, iteratee) {
|
|
358
|
+
var index = -1,
|
|
359
|
+
length = array ? array.length : 0;
|
|
360
|
+
|
|
361
|
+
while (++index < length) {
|
|
362
|
+
if (iteratee(array[index], index, array) === false) {
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return array;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Appends the elements of `values` to `array`.
|
|
371
|
+
*
|
|
372
|
+
* @private
|
|
373
|
+
* @param {Array} array The array to modify.
|
|
374
|
+
* @param {Array} values The values to append.
|
|
375
|
+
* @returns {Array} Returns `array`.
|
|
376
|
+
*/
|
|
377
|
+
function arrayPush(array, values) {
|
|
378
|
+
var index = -1,
|
|
379
|
+
length = values.length,
|
|
380
|
+
offset = array.length;
|
|
381
|
+
|
|
382
|
+
while (++index < length) {
|
|
383
|
+
array[offset + index] = values[index];
|
|
384
|
+
}
|
|
385
|
+
return array;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* A specialized version of `_.reduce` for arrays without support for
|
|
390
|
+
* iteratee shorthands.
|
|
391
|
+
*
|
|
392
|
+
* @private
|
|
393
|
+
* @param {Array} [array] The array to iterate over.
|
|
394
|
+
* @param {Function} iteratee The function invoked per iteration.
|
|
395
|
+
* @param {*} [accumulator] The initial value.
|
|
396
|
+
* @param {boolean} [initAccum] Specify using the first element of `array` as
|
|
397
|
+
* the initial value.
|
|
398
|
+
* @returns {*} Returns the accumulated value.
|
|
399
|
+
*/
|
|
400
|
+
function arrayReduce(array, iteratee, accumulator, initAccum) {
|
|
401
|
+
var index = -1,
|
|
402
|
+
length = array ? array.length : 0;
|
|
403
|
+
while (++index < length) {
|
|
404
|
+
accumulator = iteratee(accumulator, array[index], index, array);
|
|
405
|
+
}
|
|
406
|
+
return accumulator;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* The base implementation of `_.times` without support for iteratee shorthands
|
|
411
|
+
* or max array length checks.
|
|
412
|
+
*
|
|
413
|
+
* @private
|
|
414
|
+
* @param {number} n The number of times to invoke `iteratee`.
|
|
415
|
+
* @param {Function} iteratee The function invoked per iteration.
|
|
416
|
+
* @returns {Array} Returns the array of results.
|
|
417
|
+
*/
|
|
418
|
+
function baseTimes(n, iteratee) {
|
|
419
|
+
var index = -1,
|
|
420
|
+
result = Array(n);
|
|
421
|
+
|
|
422
|
+
while (++index < n) {
|
|
423
|
+
result[index] = iteratee(index);
|
|
424
|
+
}
|
|
425
|
+
return result;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Gets the value at `key` of `object`.
|
|
430
|
+
*
|
|
431
|
+
* @private
|
|
432
|
+
* @param {Object} [object] The object to query.
|
|
433
|
+
* @param {string} key The key of the property to get.
|
|
434
|
+
* @returns {*} Returns the property value.
|
|
435
|
+
*/
|
|
436
|
+
function getValue(object, key) {
|
|
437
|
+
return object == null ? undefined : object[key];
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Checks if `value` is a host object in IE < 9.
|
|
442
|
+
*
|
|
443
|
+
* @private
|
|
444
|
+
* @param {*} value The value to check.
|
|
445
|
+
* @returns {boolean} Returns `true` if `value` is a host object, else `false`.
|
|
446
|
+
*/
|
|
447
|
+
function isHostObject(value) {
|
|
448
|
+
// Many host objects are `Object` objects that can coerce to strings
|
|
449
|
+
// despite having improperly defined `toString` methods.
|
|
450
|
+
var result = false;
|
|
451
|
+
if (value != null && typeof value.toString != 'function') {
|
|
452
|
+
try {
|
|
453
|
+
result = !!(value + '');
|
|
454
|
+
} catch (e) {}
|
|
455
|
+
}
|
|
456
|
+
return result;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Converts `map` to its key-value pairs.
|
|
461
|
+
*
|
|
462
|
+
* @private
|
|
463
|
+
* @param {Object} map The map to convert.
|
|
464
|
+
* @returns {Array} Returns the key-value pairs.
|
|
465
|
+
*/
|
|
466
|
+
function mapToArray(map) {
|
|
467
|
+
var index = -1,
|
|
468
|
+
result = Array(map.size);
|
|
469
|
+
|
|
470
|
+
map.forEach(function(value, key) {
|
|
471
|
+
result[++index] = [key, value];
|
|
472
|
+
});
|
|
473
|
+
return result;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Creates a unary function that invokes `func` with its argument transformed.
|
|
478
|
+
*
|
|
479
|
+
* @private
|
|
480
|
+
* @param {Function} func The function to wrap.
|
|
481
|
+
* @param {Function} transform The argument transform.
|
|
482
|
+
* @returns {Function} Returns the new function.
|
|
483
|
+
*/
|
|
484
|
+
function overArg(func, transform) {
|
|
485
|
+
return function(arg) {
|
|
486
|
+
return func(transform(arg));
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Converts `set` to an array of its values.
|
|
492
|
+
*
|
|
493
|
+
* @private
|
|
494
|
+
* @param {Object} set The set to convert.
|
|
495
|
+
* @returns {Array} Returns the values.
|
|
496
|
+
*/
|
|
497
|
+
function setToArray(set) {
|
|
498
|
+
var index = -1,
|
|
499
|
+
result = Array(set.size);
|
|
500
|
+
|
|
501
|
+
set.forEach(function(value) {
|
|
502
|
+
result[++index] = value;
|
|
503
|
+
});
|
|
504
|
+
return result;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/** Used for built-in method references. */
|
|
508
|
+
var arrayProto = Array.prototype,
|
|
509
|
+
funcProto = Function.prototype,
|
|
510
|
+
objectProto = Object.prototype;
|
|
511
|
+
|
|
512
|
+
/** Used to detect overreaching core-js shims. */
|
|
513
|
+
var coreJsData = root['__core-js_shared__'];
|
|
514
|
+
|
|
515
|
+
/** Used to detect methods masquerading as native. */
|
|
516
|
+
var maskSrcKey = (function() {
|
|
517
|
+
var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
|
|
518
|
+
return uid ? ('Symbol(src)_1.' + uid) : '';
|
|
519
|
+
}());
|
|
520
|
+
|
|
521
|
+
/** Used to resolve the decompiled source of functions. */
|
|
522
|
+
var funcToString = funcProto.toString;
|
|
523
|
+
|
|
524
|
+
/** Used to check objects for own properties. */
|
|
525
|
+
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Used to resolve the
|
|
529
|
+
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
|
|
530
|
+
* of values.
|
|
531
|
+
*/
|
|
532
|
+
var objectToString = objectProto.toString;
|
|
533
|
+
|
|
534
|
+
/** Used to detect if a method is native. */
|
|
535
|
+
var reIsNative = RegExp('^' +
|
|
536
|
+
funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
|
|
537
|
+
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
|
538
|
+
);
|
|
539
|
+
|
|
540
|
+
/** Built-in value references. */
|
|
541
|
+
var Buffer = moduleExports ? root.Buffer : undefined,
|
|
542
|
+
Symbol = root.Symbol,
|
|
543
|
+
Uint8Array = root.Uint8Array,
|
|
544
|
+
getPrototype = overArg(Object.getPrototypeOf, Object),
|
|
545
|
+
objectCreate = Object.create,
|
|
546
|
+
propertyIsEnumerable = objectProto.propertyIsEnumerable,
|
|
547
|
+
splice = arrayProto.splice;
|
|
548
|
+
|
|
549
|
+
/* Built-in method references for those with the same name as other `lodash` methods. */
|
|
550
|
+
var nativeGetSymbols = Object.getOwnPropertySymbols,
|
|
551
|
+
nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
|
|
552
|
+
nativeKeys = overArg(Object.keys, Object);
|
|
553
|
+
|
|
554
|
+
/* Built-in method references that are verified to be native. */
|
|
555
|
+
var DataView = getNative(root, 'DataView'),
|
|
556
|
+
Map = getNative(root, 'Map'),
|
|
557
|
+
Promise = getNative(root, 'Promise'),
|
|
558
|
+
Set = getNative(root, 'Set'),
|
|
559
|
+
WeakMap = getNative(root, 'WeakMap'),
|
|
560
|
+
nativeCreate = getNative(Object, 'create');
|
|
561
|
+
|
|
562
|
+
/** Used to detect maps, sets, and weakmaps. */
|
|
563
|
+
var dataViewCtorString = toSource(DataView),
|
|
564
|
+
mapCtorString = toSource(Map),
|
|
565
|
+
promiseCtorString = toSource(Promise),
|
|
566
|
+
setCtorString = toSource(Set),
|
|
567
|
+
weakMapCtorString = toSource(WeakMap);
|
|
568
|
+
|
|
569
|
+
/** Used to convert symbols to primitives and strings. */
|
|
570
|
+
var symbolProto = Symbol ? Symbol.prototype : undefined,
|
|
571
|
+
symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Creates a hash object.
|
|
575
|
+
*
|
|
576
|
+
* @private
|
|
577
|
+
* @constructor
|
|
578
|
+
* @param {Array} [entries] The key-value pairs to cache.
|
|
579
|
+
*/
|
|
580
|
+
function Hash(entries) {
|
|
581
|
+
var index = -1,
|
|
582
|
+
length = entries ? entries.length : 0;
|
|
583
|
+
|
|
584
|
+
this.clear();
|
|
585
|
+
while (++index < length) {
|
|
586
|
+
var entry = entries[index];
|
|
587
|
+
this.set(entry[0], entry[1]);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Removes all key-value entries from the hash.
|
|
593
|
+
*
|
|
594
|
+
* @private
|
|
595
|
+
* @name clear
|
|
596
|
+
* @memberOf Hash
|
|
597
|
+
*/
|
|
598
|
+
function hashClear() {
|
|
599
|
+
this.__data__ = nativeCreate ? nativeCreate(null) : {};
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Removes `key` and its value from the hash.
|
|
604
|
+
*
|
|
605
|
+
* @private
|
|
606
|
+
* @name delete
|
|
607
|
+
* @memberOf Hash
|
|
608
|
+
* @param {Object} hash The hash to modify.
|
|
609
|
+
* @param {string} key The key of the value to remove.
|
|
610
|
+
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|
611
|
+
*/
|
|
612
|
+
function hashDelete(key) {
|
|
613
|
+
return this.has(key) && delete this.__data__[key];
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* Gets the hash value for `key`.
|
|
618
|
+
*
|
|
619
|
+
* @private
|
|
620
|
+
* @name get
|
|
621
|
+
* @memberOf Hash
|
|
622
|
+
* @param {string} key The key of the value to get.
|
|
623
|
+
* @returns {*} Returns the entry value.
|
|
624
|
+
*/
|
|
625
|
+
function hashGet(key) {
|
|
626
|
+
var data = this.__data__;
|
|
627
|
+
if (nativeCreate) {
|
|
628
|
+
var result = data[key];
|
|
629
|
+
return result === HASH_UNDEFINED ? undefined : result;
|
|
630
|
+
}
|
|
631
|
+
return hasOwnProperty.call(data, key) ? data[key] : undefined;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* Checks if a hash value for `key` exists.
|
|
636
|
+
*
|
|
637
|
+
* @private
|
|
638
|
+
* @name has
|
|
639
|
+
* @memberOf Hash
|
|
640
|
+
* @param {string} key The key of the entry to check.
|
|
641
|
+
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|
642
|
+
*/
|
|
643
|
+
function hashHas(key) {
|
|
644
|
+
var data = this.__data__;
|
|
645
|
+
return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* Sets the hash `key` to `value`.
|
|
650
|
+
*
|
|
651
|
+
* @private
|
|
652
|
+
* @name set
|
|
653
|
+
* @memberOf Hash
|
|
654
|
+
* @param {string} key The key of the value to set.
|
|
655
|
+
* @param {*} value The value to set.
|
|
656
|
+
* @returns {Object} Returns the hash instance.
|
|
657
|
+
*/
|
|
658
|
+
function hashSet(key, value) {
|
|
659
|
+
var data = this.__data__;
|
|
660
|
+
data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
|
|
661
|
+
return this;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// Add methods to `Hash`.
|
|
665
|
+
Hash.prototype.clear = hashClear;
|
|
666
|
+
Hash.prototype['delete'] = hashDelete;
|
|
667
|
+
Hash.prototype.get = hashGet;
|
|
668
|
+
Hash.prototype.has = hashHas;
|
|
669
|
+
Hash.prototype.set = hashSet;
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* Creates an list cache object.
|
|
673
|
+
*
|
|
674
|
+
* @private
|
|
675
|
+
* @constructor
|
|
676
|
+
* @param {Array} [entries] The key-value pairs to cache.
|
|
677
|
+
*/
|
|
678
|
+
function ListCache(entries) {
|
|
679
|
+
var index = -1,
|
|
680
|
+
length = entries ? entries.length : 0;
|
|
681
|
+
|
|
682
|
+
this.clear();
|
|
683
|
+
while (++index < length) {
|
|
684
|
+
var entry = entries[index];
|
|
685
|
+
this.set(entry[0], entry[1]);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* Removes all key-value entries from the list cache.
|
|
691
|
+
*
|
|
692
|
+
* @private
|
|
693
|
+
* @name clear
|
|
694
|
+
* @memberOf ListCache
|
|
695
|
+
*/
|
|
696
|
+
function listCacheClear() {
|
|
697
|
+
this.__data__ = [];
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
* Removes `key` and its value from the list cache.
|
|
702
|
+
*
|
|
703
|
+
* @private
|
|
704
|
+
* @name delete
|
|
705
|
+
* @memberOf ListCache
|
|
706
|
+
* @param {string} key The key of the value to remove.
|
|
707
|
+
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|
708
|
+
*/
|
|
709
|
+
function listCacheDelete(key) {
|
|
710
|
+
var data = this.__data__,
|
|
711
|
+
index = assocIndexOf(data, key);
|
|
712
|
+
|
|
713
|
+
if (index < 0) {
|
|
714
|
+
return false;
|
|
715
|
+
}
|
|
716
|
+
var lastIndex = data.length - 1;
|
|
717
|
+
if (index == lastIndex) {
|
|
718
|
+
data.pop();
|
|
719
|
+
} else {
|
|
720
|
+
splice.call(data, index, 1);
|
|
721
|
+
}
|
|
722
|
+
return true;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
/**
|
|
726
|
+
* Gets the list cache value for `key`.
|
|
727
|
+
*
|
|
728
|
+
* @private
|
|
729
|
+
* @name get
|
|
730
|
+
* @memberOf ListCache
|
|
731
|
+
* @param {string} key The key of the value to get.
|
|
732
|
+
* @returns {*} Returns the entry value.
|
|
733
|
+
*/
|
|
734
|
+
function listCacheGet(key) {
|
|
735
|
+
var data = this.__data__,
|
|
736
|
+
index = assocIndexOf(data, key);
|
|
737
|
+
|
|
738
|
+
return index < 0 ? undefined : data[index][1];
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/**
|
|
742
|
+
* Checks if a list cache value for `key` exists.
|
|
743
|
+
*
|
|
744
|
+
* @private
|
|
745
|
+
* @name has
|
|
746
|
+
* @memberOf ListCache
|
|
747
|
+
* @param {string} key The key of the entry to check.
|
|
748
|
+
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|
749
|
+
*/
|
|
750
|
+
function listCacheHas(key) {
|
|
751
|
+
return assocIndexOf(this.__data__, key) > -1;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
* Sets the list cache `key` to `value`.
|
|
756
|
+
*
|
|
757
|
+
* @private
|
|
758
|
+
* @name set
|
|
759
|
+
* @memberOf ListCache
|
|
760
|
+
* @param {string} key The key of the value to set.
|
|
761
|
+
* @param {*} value The value to set.
|
|
762
|
+
* @returns {Object} Returns the list cache instance.
|
|
763
|
+
*/
|
|
764
|
+
function listCacheSet(key, value) {
|
|
765
|
+
var data = this.__data__,
|
|
766
|
+
index = assocIndexOf(data, key);
|
|
767
|
+
|
|
768
|
+
if (index < 0) {
|
|
769
|
+
data.push([key, value]);
|
|
770
|
+
} else {
|
|
771
|
+
data[index][1] = value;
|
|
772
|
+
}
|
|
773
|
+
return this;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
// Add methods to `ListCache`.
|
|
777
|
+
ListCache.prototype.clear = listCacheClear;
|
|
778
|
+
ListCache.prototype['delete'] = listCacheDelete;
|
|
779
|
+
ListCache.prototype.get = listCacheGet;
|
|
780
|
+
ListCache.prototype.has = listCacheHas;
|
|
781
|
+
ListCache.prototype.set = listCacheSet;
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* Creates a map cache object to store key-value pairs.
|
|
785
|
+
*
|
|
786
|
+
* @private
|
|
787
|
+
* @constructor
|
|
788
|
+
* @param {Array} [entries] The key-value pairs to cache.
|
|
789
|
+
*/
|
|
790
|
+
function MapCache(entries) {
|
|
791
|
+
var index = -1,
|
|
792
|
+
length = entries ? entries.length : 0;
|
|
793
|
+
|
|
794
|
+
this.clear();
|
|
795
|
+
while (++index < length) {
|
|
796
|
+
var entry = entries[index];
|
|
797
|
+
this.set(entry[0], entry[1]);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* Removes all key-value entries from the map.
|
|
803
|
+
*
|
|
804
|
+
* @private
|
|
805
|
+
* @name clear
|
|
806
|
+
* @memberOf MapCache
|
|
807
|
+
*/
|
|
808
|
+
function mapCacheClear() {
|
|
809
|
+
this.__data__ = {
|
|
810
|
+
'hash': new Hash,
|
|
811
|
+
'map': new (Map || ListCache),
|
|
812
|
+
'string': new Hash
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
/**
|
|
817
|
+
* Removes `key` and its value from the map.
|
|
818
|
+
*
|
|
819
|
+
* @private
|
|
820
|
+
* @name delete
|
|
821
|
+
* @memberOf MapCache
|
|
822
|
+
* @param {string} key The key of the value to remove.
|
|
823
|
+
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|
824
|
+
*/
|
|
825
|
+
function mapCacheDelete(key) {
|
|
826
|
+
return getMapData(this, key)['delete'](key);
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* Gets the map value for `key`.
|
|
831
|
+
*
|
|
832
|
+
* @private
|
|
833
|
+
* @name get
|
|
834
|
+
* @memberOf MapCache
|
|
835
|
+
* @param {string} key The key of the value to get.
|
|
836
|
+
* @returns {*} Returns the entry value.
|
|
837
|
+
*/
|
|
838
|
+
function mapCacheGet(key) {
|
|
839
|
+
return getMapData(this, key).get(key);
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* Checks if a map value for `key` exists.
|
|
844
|
+
*
|
|
845
|
+
* @private
|
|
846
|
+
* @name has
|
|
847
|
+
* @memberOf MapCache
|
|
848
|
+
* @param {string} key The key of the entry to check.
|
|
849
|
+
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|
850
|
+
*/
|
|
851
|
+
function mapCacheHas(key) {
|
|
852
|
+
return getMapData(this, key).has(key);
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
/**
|
|
856
|
+
* Sets the map `key` to `value`.
|
|
857
|
+
*
|
|
858
|
+
* @private
|
|
859
|
+
* @name set
|
|
860
|
+
* @memberOf MapCache
|
|
861
|
+
* @param {string} key The key of the value to set.
|
|
862
|
+
* @param {*} value The value to set.
|
|
863
|
+
* @returns {Object} Returns the map cache instance.
|
|
864
|
+
*/
|
|
865
|
+
function mapCacheSet(key, value) {
|
|
866
|
+
getMapData(this, key).set(key, value);
|
|
867
|
+
return this;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
// Add methods to `MapCache`.
|
|
871
|
+
MapCache.prototype.clear = mapCacheClear;
|
|
872
|
+
MapCache.prototype['delete'] = mapCacheDelete;
|
|
873
|
+
MapCache.prototype.get = mapCacheGet;
|
|
874
|
+
MapCache.prototype.has = mapCacheHas;
|
|
875
|
+
MapCache.prototype.set = mapCacheSet;
|
|
876
|
+
|
|
877
|
+
/**
|
|
878
|
+
* Creates a stack cache object to store key-value pairs.
|
|
879
|
+
*
|
|
880
|
+
* @private
|
|
881
|
+
* @constructor
|
|
882
|
+
* @param {Array} [entries] The key-value pairs to cache.
|
|
883
|
+
*/
|
|
884
|
+
function Stack(entries) {
|
|
885
|
+
this.__data__ = new ListCache(entries);
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
/**
|
|
889
|
+
* Removes all key-value entries from the stack.
|
|
890
|
+
*
|
|
891
|
+
* @private
|
|
892
|
+
* @name clear
|
|
893
|
+
* @memberOf Stack
|
|
894
|
+
*/
|
|
895
|
+
function stackClear() {
|
|
896
|
+
this.__data__ = new ListCache;
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
/**
|
|
900
|
+
* Removes `key` and its value from the stack.
|
|
901
|
+
*
|
|
902
|
+
* @private
|
|
903
|
+
* @name delete
|
|
904
|
+
* @memberOf Stack
|
|
905
|
+
* @param {string} key The key of the value to remove.
|
|
906
|
+
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|
907
|
+
*/
|
|
908
|
+
function stackDelete(key) {
|
|
909
|
+
return this.__data__['delete'](key);
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
/**
|
|
913
|
+
* Gets the stack value for `key`.
|
|
914
|
+
*
|
|
915
|
+
* @private
|
|
916
|
+
* @name get
|
|
917
|
+
* @memberOf Stack
|
|
918
|
+
* @param {string} key The key of the value to get.
|
|
919
|
+
* @returns {*} Returns the entry value.
|
|
920
|
+
*/
|
|
921
|
+
function stackGet(key) {
|
|
922
|
+
return this.__data__.get(key);
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
/**
|
|
926
|
+
* Checks if a stack value for `key` exists.
|
|
927
|
+
*
|
|
928
|
+
* @private
|
|
929
|
+
* @name has
|
|
930
|
+
* @memberOf Stack
|
|
931
|
+
* @param {string} key The key of the entry to check.
|
|
932
|
+
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|
933
|
+
*/
|
|
934
|
+
function stackHas(key) {
|
|
935
|
+
return this.__data__.has(key);
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
/**
|
|
939
|
+
* Sets the stack `key` to `value`.
|
|
940
|
+
*
|
|
941
|
+
* @private
|
|
942
|
+
* @name set
|
|
943
|
+
* @memberOf Stack
|
|
944
|
+
* @param {string} key The key of the value to set.
|
|
945
|
+
* @param {*} value The value to set.
|
|
946
|
+
* @returns {Object} Returns the stack cache instance.
|
|
947
|
+
*/
|
|
948
|
+
function stackSet(key, value) {
|
|
949
|
+
var cache = this.__data__;
|
|
950
|
+
if (cache instanceof ListCache) {
|
|
951
|
+
var pairs = cache.__data__;
|
|
952
|
+
if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
|
|
953
|
+
pairs.push([key, value]);
|
|
954
|
+
return this;
|
|
955
|
+
}
|
|
956
|
+
cache = this.__data__ = new MapCache(pairs);
|
|
957
|
+
}
|
|
958
|
+
cache.set(key, value);
|
|
959
|
+
return this;
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
// Add methods to `Stack`.
|
|
963
|
+
Stack.prototype.clear = stackClear;
|
|
964
|
+
Stack.prototype['delete'] = stackDelete;
|
|
965
|
+
Stack.prototype.get = stackGet;
|
|
966
|
+
Stack.prototype.has = stackHas;
|
|
967
|
+
Stack.prototype.set = stackSet;
|
|
968
|
+
|
|
969
|
+
/**
|
|
970
|
+
* Creates an array of the enumerable property names of the array-like `value`.
|
|
971
|
+
*
|
|
972
|
+
* @private
|
|
973
|
+
* @param {*} value The value to query.
|
|
974
|
+
* @param {boolean} inherited Specify returning inherited property names.
|
|
975
|
+
* @returns {Array} Returns the array of property names.
|
|
976
|
+
*/
|
|
977
|
+
function arrayLikeKeys(value, inherited) {
|
|
978
|
+
// Safari 8.1 makes `arguments.callee` enumerable in strict mode.
|
|
979
|
+
// Safari 9 makes `arguments.length` enumerable in strict mode.
|
|
980
|
+
var result = (isArray(value) || isArguments(value))
|
|
981
|
+
? baseTimes(value.length, String)
|
|
982
|
+
: [];
|
|
983
|
+
|
|
984
|
+
var length = result.length,
|
|
985
|
+
skipIndexes = !!length;
|
|
986
|
+
|
|
987
|
+
for (var key in value) {
|
|
988
|
+
if ((hasOwnProperty.call(value, key)) &&
|
|
989
|
+
!(skipIndexes && (key == 'length' || isIndex(key, length)))) {
|
|
990
|
+
result.push(key);
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
return result;
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
/**
|
|
997
|
+
* Assigns `value` to `key` of `object` if the existing value is not equivalent
|
|
998
|
+
* using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
|
999
|
+
* for equality comparisons.
|
|
1000
|
+
*
|
|
1001
|
+
* @private
|
|
1002
|
+
* @param {Object} object The object to modify.
|
|
1003
|
+
* @param {string} key The key of the property to assign.
|
|
1004
|
+
* @param {*} value The value to assign.
|
|
1005
|
+
*/
|
|
1006
|
+
function assignValue(object, key, value) {
|
|
1007
|
+
var objValue = object[key];
|
|
1008
|
+
if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
|
|
1009
|
+
(value === undefined && !(key in object))) {
|
|
1010
|
+
object[key] = value;
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
/**
|
|
1015
|
+
* Gets the index at which the `key` is found in `array` of key-value pairs.
|
|
1016
|
+
*
|
|
1017
|
+
* @private
|
|
1018
|
+
* @param {Array} array The array to inspect.
|
|
1019
|
+
* @param {*} key The key to search for.
|
|
1020
|
+
* @returns {number} Returns the index of the matched value, else `-1`.
|
|
1021
|
+
*/
|
|
1022
|
+
function assocIndexOf(array, key) {
|
|
1023
|
+
var length = array.length;
|
|
1024
|
+
while (length--) {
|
|
1025
|
+
if (eq(array[length][0], key)) {
|
|
1026
|
+
return length;
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
return -1;
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
/**
|
|
1033
|
+
* The base implementation of `_.assign` without support for multiple sources
|
|
1034
|
+
* or `customizer` functions.
|
|
1035
|
+
*
|
|
1036
|
+
* @private
|
|
1037
|
+
* @param {Object} object The destination object.
|
|
1038
|
+
* @param {Object} source The source object.
|
|
1039
|
+
* @returns {Object} Returns `object`.
|
|
1040
|
+
*/
|
|
1041
|
+
function baseAssign(object, source) {
|
|
1042
|
+
return object && copyObject(source, keys(source), object);
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
/**
|
|
1046
|
+
* The base implementation of `_.clone` and `_.cloneDeep` which tracks
|
|
1047
|
+
* traversed objects.
|
|
1048
|
+
*
|
|
1049
|
+
* @private
|
|
1050
|
+
* @param {*} value The value to clone.
|
|
1051
|
+
* @param {boolean} [isDeep] Specify a deep clone.
|
|
1052
|
+
* @param {boolean} [isFull] Specify a clone including symbols.
|
|
1053
|
+
* @param {Function} [customizer] The function to customize cloning.
|
|
1054
|
+
* @param {string} [key] The key of `value`.
|
|
1055
|
+
* @param {Object} [object] The parent object of `value`.
|
|
1056
|
+
* @param {Object} [stack] Tracks traversed objects and their clone counterparts.
|
|
1057
|
+
* @returns {*} Returns the cloned value.
|
|
1058
|
+
*/
|
|
1059
|
+
function baseClone(value, isDeep, isFull, customizer, key, object, stack) {
|
|
1060
|
+
var result;
|
|
1061
|
+
if (customizer) {
|
|
1062
|
+
result = object ? customizer(value, key, object, stack) : customizer(value);
|
|
1063
|
+
}
|
|
1064
|
+
if (result !== undefined) {
|
|
1065
|
+
return result;
|
|
1066
|
+
}
|
|
1067
|
+
if (!isObject(value)) {
|
|
1068
|
+
return value;
|
|
1069
|
+
}
|
|
1070
|
+
var isArr = isArray(value);
|
|
1071
|
+
if (isArr) {
|
|
1072
|
+
result = initCloneArray(value);
|
|
1073
|
+
if (!isDeep) {
|
|
1074
|
+
return copyArray(value, result);
|
|
1075
|
+
}
|
|
1076
|
+
} else {
|
|
1077
|
+
var tag = getTag(value),
|
|
1078
|
+
isFunc = tag == funcTag || tag == genTag;
|
|
1079
|
+
|
|
1080
|
+
if (isBuffer(value)) {
|
|
1081
|
+
return cloneBuffer(value, isDeep);
|
|
1082
|
+
}
|
|
1083
|
+
if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
|
|
1084
|
+
if (isHostObject(value)) {
|
|
1085
|
+
return object ? value : {};
|
|
1086
|
+
}
|
|
1087
|
+
result = initCloneObject(isFunc ? {} : value);
|
|
1088
|
+
if (!isDeep) {
|
|
1089
|
+
return copySymbols(value, baseAssign(result, value));
|
|
1090
|
+
}
|
|
1091
|
+
} else {
|
|
1092
|
+
if (!cloneableTags[tag]) {
|
|
1093
|
+
return object ? value : {};
|
|
1094
|
+
}
|
|
1095
|
+
result = initCloneByTag(value, tag, baseClone, isDeep);
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
// Check for circular references and return its corresponding clone.
|
|
1099
|
+
stack || (stack = new Stack);
|
|
1100
|
+
var stacked = stack.get(value);
|
|
1101
|
+
if (stacked) {
|
|
1102
|
+
return stacked;
|
|
1103
|
+
}
|
|
1104
|
+
stack.set(value, result);
|
|
1105
|
+
|
|
1106
|
+
if (!isArr) {
|
|
1107
|
+
var props = isFull ? getAllKeys(value) : keys(value);
|
|
1108
|
+
}
|
|
1109
|
+
arrayEach(props || value, function(subValue, key) {
|
|
1110
|
+
if (props) {
|
|
1111
|
+
key = subValue;
|
|
1112
|
+
subValue = value[key];
|
|
1113
|
+
}
|
|
1114
|
+
// Recursively populate clone (susceptible to call stack limits).
|
|
1115
|
+
assignValue(result, key, baseClone(subValue, isDeep, isFull, customizer, key, value, stack));
|
|
1116
|
+
});
|
|
1117
|
+
return result;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
/**
|
|
1121
|
+
* The base implementation of `_.create` without support for assigning
|
|
1122
|
+
* properties to the created object.
|
|
1123
|
+
*
|
|
1124
|
+
* @private
|
|
1125
|
+
* @param {Object} prototype The object to inherit from.
|
|
1126
|
+
* @returns {Object} Returns the new object.
|
|
1127
|
+
*/
|
|
1128
|
+
function baseCreate(proto) {
|
|
1129
|
+
return isObject(proto) ? objectCreate(proto) : {};
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
/**
|
|
1133
|
+
* The base implementation of `getAllKeys` and `getAllKeysIn` which uses
|
|
1134
|
+
* `keysFunc` and `symbolsFunc` to get the enumerable property names and
|
|
1135
|
+
* symbols of `object`.
|
|
1136
|
+
*
|
|
1137
|
+
* @private
|
|
1138
|
+
* @param {Object} object The object to query.
|
|
1139
|
+
* @param {Function} keysFunc The function to get the keys of `object`.
|
|
1140
|
+
* @param {Function} symbolsFunc The function to get the symbols of `object`.
|
|
1141
|
+
* @returns {Array} Returns the array of property names and symbols.
|
|
1142
|
+
*/
|
|
1143
|
+
function baseGetAllKeys(object, keysFunc, symbolsFunc) {
|
|
1144
|
+
var result = keysFunc(object);
|
|
1145
|
+
return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
/**
|
|
1149
|
+
* The base implementation of `getTag`.
|
|
1150
|
+
*
|
|
1151
|
+
* @private
|
|
1152
|
+
* @param {*} value The value to query.
|
|
1153
|
+
* @returns {string} Returns the `toStringTag`.
|
|
1154
|
+
*/
|
|
1155
|
+
function baseGetTag(value) {
|
|
1156
|
+
return objectToString.call(value);
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
/**
|
|
1160
|
+
* The base implementation of `_.isNative` without bad shim checks.
|
|
1161
|
+
*
|
|
1162
|
+
* @private
|
|
1163
|
+
* @param {*} value The value to check.
|
|
1164
|
+
* @returns {boolean} Returns `true` if `value` is a native function,
|
|
1165
|
+
* else `false`.
|
|
1166
|
+
*/
|
|
1167
|
+
function baseIsNative(value) {
|
|
1168
|
+
if (!isObject(value) || isMasked(value)) {
|
|
1169
|
+
return false;
|
|
1170
|
+
}
|
|
1171
|
+
var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
|
|
1172
|
+
return pattern.test(toSource(value));
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
/**
|
|
1176
|
+
* The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
|
|
1177
|
+
*
|
|
1178
|
+
* @private
|
|
1179
|
+
* @param {Object} object The object to query.
|
|
1180
|
+
* @returns {Array} Returns the array of property names.
|
|
1181
|
+
*/
|
|
1182
|
+
function baseKeys(object) {
|
|
1183
|
+
if (!isPrototype(object)) {
|
|
1184
|
+
return nativeKeys(object);
|
|
1185
|
+
}
|
|
1186
|
+
var result = [];
|
|
1187
|
+
for (var key in Object(object)) {
|
|
1188
|
+
if (hasOwnProperty.call(object, key) && key != 'constructor') {
|
|
1189
|
+
result.push(key);
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
return result;
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
/**
|
|
1196
|
+
* Creates a clone of `buffer`.
|
|
1197
|
+
*
|
|
1198
|
+
* @private
|
|
1199
|
+
* @param {Buffer} buffer The buffer to clone.
|
|
1200
|
+
* @param {boolean} [isDeep] Specify a deep clone.
|
|
1201
|
+
* @returns {Buffer} Returns the cloned buffer.
|
|
1202
|
+
*/
|
|
1203
|
+
function cloneBuffer(buffer, isDeep) {
|
|
1204
|
+
if (isDeep) {
|
|
1205
|
+
return buffer.slice();
|
|
1206
|
+
}
|
|
1207
|
+
var result = new buffer.constructor(buffer.length);
|
|
1208
|
+
buffer.copy(result);
|
|
1209
|
+
return result;
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
/**
|
|
1213
|
+
* Creates a clone of `arrayBuffer`.
|
|
1214
|
+
*
|
|
1215
|
+
* @private
|
|
1216
|
+
* @param {ArrayBuffer} arrayBuffer The array buffer to clone.
|
|
1217
|
+
* @returns {ArrayBuffer} Returns the cloned array buffer.
|
|
1218
|
+
*/
|
|
1219
|
+
function cloneArrayBuffer(arrayBuffer) {
|
|
1220
|
+
var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
|
|
1221
|
+
new Uint8Array(result).set(new Uint8Array(arrayBuffer));
|
|
1222
|
+
return result;
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
/**
|
|
1226
|
+
* Creates a clone of `dataView`.
|
|
1227
|
+
*
|
|
1228
|
+
* @private
|
|
1229
|
+
* @param {Object} dataView The data view to clone.
|
|
1230
|
+
* @param {boolean} [isDeep] Specify a deep clone.
|
|
1231
|
+
* @returns {Object} Returns the cloned data view.
|
|
1232
|
+
*/
|
|
1233
|
+
function cloneDataView(dataView, isDeep) {
|
|
1234
|
+
var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
|
|
1235
|
+
return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
/**
|
|
1239
|
+
* Creates a clone of `map`.
|
|
1240
|
+
*
|
|
1241
|
+
* @private
|
|
1242
|
+
* @param {Object} map The map to clone.
|
|
1243
|
+
* @param {Function} cloneFunc The function to clone values.
|
|
1244
|
+
* @param {boolean} [isDeep] Specify a deep clone.
|
|
1245
|
+
* @returns {Object} Returns the cloned map.
|
|
1246
|
+
*/
|
|
1247
|
+
function cloneMap(map, isDeep, cloneFunc) {
|
|
1248
|
+
var array = isDeep ? cloneFunc(mapToArray(map), true) : mapToArray(map);
|
|
1249
|
+
return arrayReduce(array, addMapEntry, new map.constructor);
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
/**
|
|
1253
|
+
* Creates a clone of `regexp`.
|
|
1254
|
+
*
|
|
1255
|
+
* @private
|
|
1256
|
+
* @param {Object} regexp The regexp to clone.
|
|
1257
|
+
* @returns {Object} Returns the cloned regexp.
|
|
1258
|
+
*/
|
|
1259
|
+
function cloneRegExp(regexp) {
|
|
1260
|
+
var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
|
|
1261
|
+
result.lastIndex = regexp.lastIndex;
|
|
1262
|
+
return result;
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
/**
|
|
1266
|
+
* Creates a clone of `set`.
|
|
1267
|
+
*
|
|
1268
|
+
* @private
|
|
1269
|
+
* @param {Object} set The set to clone.
|
|
1270
|
+
* @param {Function} cloneFunc The function to clone values.
|
|
1271
|
+
* @param {boolean} [isDeep] Specify a deep clone.
|
|
1272
|
+
* @returns {Object} Returns the cloned set.
|
|
1273
|
+
*/
|
|
1274
|
+
function cloneSet(set, isDeep, cloneFunc) {
|
|
1275
|
+
var array = isDeep ? cloneFunc(setToArray(set), true) : setToArray(set);
|
|
1276
|
+
return arrayReduce(array, addSetEntry, new set.constructor);
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
/**
|
|
1280
|
+
* Creates a clone of the `symbol` object.
|
|
1281
|
+
*
|
|
1282
|
+
* @private
|
|
1283
|
+
* @param {Object} symbol The symbol object to clone.
|
|
1284
|
+
* @returns {Object} Returns the cloned symbol object.
|
|
1285
|
+
*/
|
|
1286
|
+
function cloneSymbol(symbol) {
|
|
1287
|
+
return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
/**
|
|
1291
|
+
* Creates a clone of `typedArray`.
|
|
1292
|
+
*
|
|
1293
|
+
* @private
|
|
1294
|
+
* @param {Object} typedArray The typed array to clone.
|
|
1295
|
+
* @param {boolean} [isDeep] Specify a deep clone.
|
|
1296
|
+
* @returns {Object} Returns the cloned typed array.
|
|
1297
|
+
*/
|
|
1298
|
+
function cloneTypedArray(typedArray, isDeep) {
|
|
1299
|
+
var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
|
|
1300
|
+
return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
/**
|
|
1304
|
+
* Copies the values of `source` to `array`.
|
|
1305
|
+
*
|
|
1306
|
+
* @private
|
|
1307
|
+
* @param {Array} source The array to copy values from.
|
|
1308
|
+
* @param {Array} [array=[]] The array to copy values to.
|
|
1309
|
+
* @returns {Array} Returns `array`.
|
|
1310
|
+
*/
|
|
1311
|
+
function copyArray(source, array) {
|
|
1312
|
+
var index = -1,
|
|
1313
|
+
length = source.length;
|
|
1314
|
+
|
|
1315
|
+
array || (array = Array(length));
|
|
1316
|
+
while (++index < length) {
|
|
1317
|
+
array[index] = source[index];
|
|
1318
|
+
}
|
|
1319
|
+
return array;
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
/**
|
|
1323
|
+
* Copies properties of `source` to `object`.
|
|
1324
|
+
*
|
|
1325
|
+
* @private
|
|
1326
|
+
* @param {Object} source The object to copy properties from.
|
|
1327
|
+
* @param {Array} props The property identifiers to copy.
|
|
1328
|
+
* @param {Object} [object={}] The object to copy properties to.
|
|
1329
|
+
* @param {Function} [customizer] The function to customize copied values.
|
|
1330
|
+
* @returns {Object} Returns `object`.
|
|
1331
|
+
*/
|
|
1332
|
+
function copyObject(source, props, object, customizer) {
|
|
1333
|
+
object || (object = {});
|
|
1334
|
+
|
|
1335
|
+
var index = -1,
|
|
1336
|
+
length = props.length;
|
|
1337
|
+
|
|
1338
|
+
while (++index < length) {
|
|
1339
|
+
var key = props[index];
|
|
1340
|
+
|
|
1341
|
+
var newValue = undefined;
|
|
1342
|
+
|
|
1343
|
+
assignValue(object, key, newValue === undefined ? source[key] : newValue);
|
|
1344
|
+
}
|
|
1345
|
+
return object;
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
/**
|
|
1349
|
+
* Copies own symbol properties of `source` to `object`.
|
|
1350
|
+
*
|
|
1351
|
+
* @private
|
|
1352
|
+
* @param {Object} source The object to copy symbols from.
|
|
1353
|
+
* @param {Object} [object={}] The object to copy symbols to.
|
|
1354
|
+
* @returns {Object} Returns `object`.
|
|
1355
|
+
*/
|
|
1356
|
+
function copySymbols(source, object) {
|
|
1357
|
+
return copyObject(source, getSymbols(source), object);
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
/**
|
|
1361
|
+
* Creates an array of own enumerable property names and symbols of `object`.
|
|
1362
|
+
*
|
|
1363
|
+
* @private
|
|
1364
|
+
* @param {Object} object The object to query.
|
|
1365
|
+
* @returns {Array} Returns the array of property names and symbols.
|
|
1366
|
+
*/
|
|
1367
|
+
function getAllKeys(object) {
|
|
1368
|
+
return baseGetAllKeys(object, keys, getSymbols);
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
/**
|
|
1372
|
+
* Gets the data for `map`.
|
|
1373
|
+
*
|
|
1374
|
+
* @private
|
|
1375
|
+
* @param {Object} map The map to query.
|
|
1376
|
+
* @param {string} key The reference key.
|
|
1377
|
+
* @returns {*} Returns the map data.
|
|
1378
|
+
*/
|
|
1379
|
+
function getMapData(map, key) {
|
|
1380
|
+
var data = map.__data__;
|
|
1381
|
+
return isKeyable(key)
|
|
1382
|
+
? data[typeof key == 'string' ? 'string' : 'hash']
|
|
1383
|
+
: data.map;
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
/**
|
|
1387
|
+
* Gets the native function at `key` of `object`.
|
|
1388
|
+
*
|
|
1389
|
+
* @private
|
|
1390
|
+
* @param {Object} object The object to query.
|
|
1391
|
+
* @param {string} key The key of the method to get.
|
|
1392
|
+
* @returns {*} Returns the function if it's native, else `undefined`.
|
|
1393
|
+
*/
|
|
1394
|
+
function getNative(object, key) {
|
|
1395
|
+
var value = getValue(object, key);
|
|
1396
|
+
return baseIsNative(value) ? value : undefined;
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
/**
|
|
1400
|
+
* Creates an array of the own enumerable symbol properties of `object`.
|
|
1401
|
+
*
|
|
1402
|
+
* @private
|
|
1403
|
+
* @param {Object} object The object to query.
|
|
1404
|
+
* @returns {Array} Returns the array of symbols.
|
|
1405
|
+
*/
|
|
1406
|
+
var getSymbols = nativeGetSymbols ? overArg(nativeGetSymbols, Object) : stubArray;
|
|
1407
|
+
|
|
1408
|
+
/**
|
|
1409
|
+
* Gets the `toStringTag` of `value`.
|
|
1410
|
+
*
|
|
1411
|
+
* @private
|
|
1412
|
+
* @param {*} value The value to query.
|
|
1413
|
+
* @returns {string} Returns the `toStringTag`.
|
|
1414
|
+
*/
|
|
1415
|
+
var getTag = baseGetTag;
|
|
1416
|
+
|
|
1417
|
+
// Fallback for data views, maps, sets, and weak maps in IE 11,
|
|
1418
|
+
// for data views in Edge < 14, and promises in Node.js.
|
|
1419
|
+
if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
|
|
1420
|
+
(Map && getTag(new Map) != mapTag) ||
|
|
1421
|
+
(Promise && getTag(Promise.resolve()) != promiseTag) ||
|
|
1422
|
+
(Set && getTag(new Set) != setTag) ||
|
|
1423
|
+
(WeakMap && getTag(new WeakMap) != weakMapTag)) {
|
|
1424
|
+
getTag = function(value) {
|
|
1425
|
+
var result = objectToString.call(value),
|
|
1426
|
+
Ctor = result == objectTag ? value.constructor : undefined,
|
|
1427
|
+
ctorString = Ctor ? toSource(Ctor) : undefined;
|
|
1428
|
+
|
|
1429
|
+
if (ctorString) {
|
|
1430
|
+
switch (ctorString) {
|
|
1431
|
+
case dataViewCtorString: return dataViewTag;
|
|
1432
|
+
case mapCtorString: return mapTag;
|
|
1433
|
+
case promiseCtorString: return promiseTag;
|
|
1434
|
+
case setCtorString: return setTag;
|
|
1435
|
+
case weakMapCtorString: return weakMapTag;
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
return result;
|
|
1439
|
+
};
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
/**
|
|
1443
|
+
* Initializes an array clone.
|
|
1444
|
+
*
|
|
1445
|
+
* @private
|
|
1446
|
+
* @param {Array} array The array to clone.
|
|
1447
|
+
* @returns {Array} Returns the initialized clone.
|
|
1448
|
+
*/
|
|
1449
|
+
function initCloneArray(array) {
|
|
1450
|
+
var length = array.length,
|
|
1451
|
+
result = array.constructor(length);
|
|
1452
|
+
|
|
1453
|
+
// Add properties assigned by `RegExp#exec`.
|
|
1454
|
+
if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
|
|
1455
|
+
result.index = array.index;
|
|
1456
|
+
result.input = array.input;
|
|
1457
|
+
}
|
|
1458
|
+
return result;
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
/**
|
|
1462
|
+
* Initializes an object clone.
|
|
1463
|
+
*
|
|
1464
|
+
* @private
|
|
1465
|
+
* @param {Object} object The object to clone.
|
|
1466
|
+
* @returns {Object} Returns the initialized clone.
|
|
1467
|
+
*/
|
|
1468
|
+
function initCloneObject(object) {
|
|
1469
|
+
return (typeof object.constructor == 'function' && !isPrototype(object))
|
|
1470
|
+
? baseCreate(getPrototype(object))
|
|
1471
|
+
: {};
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
/**
|
|
1475
|
+
* Initializes an object clone based on its `toStringTag`.
|
|
1476
|
+
*
|
|
1477
|
+
* **Note:** This function only supports cloning values with tags of
|
|
1478
|
+
* `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
|
|
1479
|
+
*
|
|
1480
|
+
* @private
|
|
1481
|
+
* @param {Object} object The object to clone.
|
|
1482
|
+
* @param {string} tag The `toStringTag` of the object to clone.
|
|
1483
|
+
* @param {Function} cloneFunc The function to clone values.
|
|
1484
|
+
* @param {boolean} [isDeep] Specify a deep clone.
|
|
1485
|
+
* @returns {Object} Returns the initialized clone.
|
|
1486
|
+
*/
|
|
1487
|
+
function initCloneByTag(object, tag, cloneFunc, isDeep) {
|
|
1488
|
+
var Ctor = object.constructor;
|
|
1489
|
+
switch (tag) {
|
|
1490
|
+
case arrayBufferTag:
|
|
1491
|
+
return cloneArrayBuffer(object);
|
|
1492
|
+
|
|
1493
|
+
case boolTag:
|
|
1494
|
+
case dateTag:
|
|
1495
|
+
return new Ctor(+object);
|
|
1496
|
+
|
|
1497
|
+
case dataViewTag:
|
|
1498
|
+
return cloneDataView(object, isDeep);
|
|
1499
|
+
|
|
1500
|
+
case float32Tag: case float64Tag:
|
|
1501
|
+
case int8Tag: case int16Tag: case int32Tag:
|
|
1502
|
+
case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
|
|
1503
|
+
return cloneTypedArray(object, isDeep);
|
|
1504
|
+
|
|
1505
|
+
case mapTag:
|
|
1506
|
+
return cloneMap(object, isDeep, cloneFunc);
|
|
1507
|
+
|
|
1508
|
+
case numberTag:
|
|
1509
|
+
case stringTag:
|
|
1510
|
+
return new Ctor(object);
|
|
1511
|
+
|
|
1512
|
+
case regexpTag:
|
|
1513
|
+
return cloneRegExp(object);
|
|
1514
|
+
|
|
1515
|
+
case setTag:
|
|
1516
|
+
return cloneSet(object, isDeep, cloneFunc);
|
|
1517
|
+
|
|
1518
|
+
case symbolTag:
|
|
1519
|
+
return cloneSymbol(object);
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
/**
|
|
1524
|
+
* Checks if `value` is a valid array-like index.
|
|
1525
|
+
*
|
|
1526
|
+
* @private
|
|
1527
|
+
* @param {*} value The value to check.
|
|
1528
|
+
* @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
|
|
1529
|
+
* @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
|
|
1530
|
+
*/
|
|
1531
|
+
function isIndex(value, length) {
|
|
1532
|
+
length = length == null ? MAX_SAFE_INTEGER : length;
|
|
1533
|
+
return !!length &&
|
|
1534
|
+
(typeof value == 'number' || reIsUint.test(value)) &&
|
|
1535
|
+
(value > -1 && value % 1 == 0 && value < length);
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
/**
|
|
1539
|
+
* Checks if `value` is suitable for use as unique object key.
|
|
1540
|
+
*
|
|
1541
|
+
* @private
|
|
1542
|
+
* @param {*} value The value to check.
|
|
1543
|
+
* @returns {boolean} Returns `true` if `value` is suitable, else `false`.
|
|
1544
|
+
*/
|
|
1545
|
+
function isKeyable(value) {
|
|
1546
|
+
var type = typeof value;
|
|
1547
|
+
return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
|
|
1548
|
+
? (value !== '__proto__')
|
|
1549
|
+
: (value === null);
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
/**
|
|
1553
|
+
* Checks if `func` has its source masked.
|
|
1554
|
+
*
|
|
1555
|
+
* @private
|
|
1556
|
+
* @param {Function} func The function to check.
|
|
1557
|
+
* @returns {boolean} Returns `true` if `func` is masked, else `false`.
|
|
1558
|
+
*/
|
|
1559
|
+
function isMasked(func) {
|
|
1560
|
+
return !!maskSrcKey && (maskSrcKey in func);
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
/**
|
|
1564
|
+
* Checks if `value` is likely a prototype object.
|
|
1565
|
+
*
|
|
1566
|
+
* @private
|
|
1567
|
+
* @param {*} value The value to check.
|
|
1568
|
+
* @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
|
|
1569
|
+
*/
|
|
1570
|
+
function isPrototype(value) {
|
|
1571
|
+
var Ctor = value && value.constructor,
|
|
1572
|
+
proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
|
|
1573
|
+
|
|
1574
|
+
return value === proto;
|
|
1575
|
+
}
|
|
1576
|
+
|
|
1577
|
+
/**
|
|
1578
|
+
* Converts `func` to its source code.
|
|
1579
|
+
*
|
|
1580
|
+
* @private
|
|
1581
|
+
* @param {Function} func The function to process.
|
|
1582
|
+
* @returns {string} Returns the source code.
|
|
1583
|
+
*/
|
|
1584
|
+
function toSource(func) {
|
|
1585
|
+
if (func != null) {
|
|
1586
|
+
try {
|
|
1587
|
+
return funcToString.call(func);
|
|
1588
|
+
} catch (e) {}
|
|
1589
|
+
try {
|
|
1590
|
+
return (func + '');
|
|
1591
|
+
} catch (e) {}
|
|
1592
|
+
}
|
|
1593
|
+
return '';
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
/**
|
|
1597
|
+
* This method is like `_.clone` except that it recursively clones `value`.
|
|
1598
|
+
*
|
|
1599
|
+
* @static
|
|
1600
|
+
* @memberOf _
|
|
1601
|
+
* @since 1.0.0
|
|
1602
|
+
* @category Lang
|
|
1603
|
+
* @param {*} value The value to recursively clone.
|
|
1604
|
+
* @returns {*} Returns the deep cloned value.
|
|
1605
|
+
* @see _.clone
|
|
1606
|
+
* @example
|
|
1607
|
+
*
|
|
1608
|
+
* var objects = [{ 'a': 1 }, { 'b': 2 }];
|
|
1609
|
+
*
|
|
1610
|
+
* var deep = _.cloneDeep(objects);
|
|
1611
|
+
* console.log(deep[0] === objects[0]);
|
|
1612
|
+
* // => false
|
|
1613
|
+
*/
|
|
1614
|
+
function cloneDeep(value) {
|
|
1615
|
+
return baseClone(value, true, true);
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
/**
|
|
1619
|
+
* Performs a
|
|
1620
|
+
* [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
|
1621
|
+
* comparison between two values to determine if they are equivalent.
|
|
1622
|
+
*
|
|
1623
|
+
* @static
|
|
1624
|
+
* @memberOf _
|
|
1625
|
+
* @since 4.0.0
|
|
1626
|
+
* @category Lang
|
|
1627
|
+
* @param {*} value The value to compare.
|
|
1628
|
+
* @param {*} other The other value to compare.
|
|
1629
|
+
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
|
1630
|
+
* @example
|
|
1631
|
+
*
|
|
1632
|
+
* var object = { 'a': 1 };
|
|
1633
|
+
* var other = { 'a': 1 };
|
|
1634
|
+
*
|
|
1635
|
+
* _.eq(object, object);
|
|
1636
|
+
* // => true
|
|
1637
|
+
*
|
|
1638
|
+
* _.eq(object, other);
|
|
1639
|
+
* // => false
|
|
1640
|
+
*
|
|
1641
|
+
* _.eq('a', 'a');
|
|
1642
|
+
* // => true
|
|
1643
|
+
*
|
|
1644
|
+
* _.eq('a', Object('a'));
|
|
1645
|
+
* // => false
|
|
1646
|
+
*
|
|
1647
|
+
* _.eq(NaN, NaN);
|
|
1648
|
+
* // => true
|
|
1649
|
+
*/
|
|
1650
|
+
function eq(value, other) {
|
|
1651
|
+
return value === other || (value !== value && other !== other);
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
/**
|
|
1655
|
+
* Checks if `value` is likely an `arguments` object.
|
|
1656
|
+
*
|
|
1657
|
+
* @static
|
|
1658
|
+
* @memberOf _
|
|
1659
|
+
* @since 0.1.0
|
|
1660
|
+
* @category Lang
|
|
1661
|
+
* @param {*} value The value to check.
|
|
1662
|
+
* @returns {boolean} Returns `true` if `value` is an `arguments` object,
|
|
1663
|
+
* else `false`.
|
|
1664
|
+
* @example
|
|
1665
|
+
*
|
|
1666
|
+
* _.isArguments(function() { return arguments; }());
|
|
1667
|
+
* // => true
|
|
1668
|
+
*
|
|
1669
|
+
* _.isArguments([1, 2, 3]);
|
|
1670
|
+
* // => false
|
|
1671
|
+
*/
|
|
1672
|
+
function isArguments(value) {
|
|
1673
|
+
// Safari 8.1 makes `arguments.callee` enumerable in strict mode.
|
|
1674
|
+
return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
|
|
1675
|
+
(!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
/**
|
|
1679
|
+
* Checks if `value` is classified as an `Array` object.
|
|
1680
|
+
*
|
|
1681
|
+
* @static
|
|
1682
|
+
* @memberOf _
|
|
1683
|
+
* @since 0.1.0
|
|
1684
|
+
* @category Lang
|
|
1685
|
+
* @param {*} value The value to check.
|
|
1686
|
+
* @returns {boolean} Returns `true` if `value` is an array, else `false`.
|
|
1687
|
+
* @example
|
|
1688
|
+
*
|
|
1689
|
+
* _.isArray([1, 2, 3]);
|
|
1690
|
+
* // => true
|
|
1691
|
+
*
|
|
1692
|
+
* _.isArray(document.body.children);
|
|
1693
|
+
* // => false
|
|
1694
|
+
*
|
|
1695
|
+
* _.isArray('abc');
|
|
1696
|
+
* // => false
|
|
1697
|
+
*
|
|
1698
|
+
* _.isArray(_.noop);
|
|
1699
|
+
* // => false
|
|
1700
|
+
*/
|
|
1701
|
+
var isArray = Array.isArray;
|
|
1702
|
+
|
|
1703
|
+
/**
|
|
1704
|
+
* Checks if `value` is array-like. A value is considered array-like if it's
|
|
1705
|
+
* not a function and has a `value.length` that's an integer greater than or
|
|
1706
|
+
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
|
|
1707
|
+
*
|
|
1708
|
+
* @static
|
|
1709
|
+
* @memberOf _
|
|
1710
|
+
* @since 4.0.0
|
|
1711
|
+
* @category Lang
|
|
1712
|
+
* @param {*} value The value to check.
|
|
1713
|
+
* @returns {boolean} Returns `true` if `value` is array-like, else `false`.
|
|
1714
|
+
* @example
|
|
1715
|
+
*
|
|
1716
|
+
* _.isArrayLike([1, 2, 3]);
|
|
1717
|
+
* // => true
|
|
1718
|
+
*
|
|
1719
|
+
* _.isArrayLike(document.body.children);
|
|
1720
|
+
* // => true
|
|
1721
|
+
*
|
|
1722
|
+
* _.isArrayLike('abc');
|
|
1723
|
+
* // => true
|
|
1724
|
+
*
|
|
1725
|
+
* _.isArrayLike(_.noop);
|
|
1726
|
+
* // => false
|
|
1727
|
+
*/
|
|
1728
|
+
function isArrayLike(value) {
|
|
1729
|
+
return value != null && isLength(value.length) && !isFunction(value);
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
/**
|
|
1733
|
+
* This method is like `_.isArrayLike` except that it also checks if `value`
|
|
1734
|
+
* is an object.
|
|
1735
|
+
*
|
|
1736
|
+
* @static
|
|
1737
|
+
* @memberOf _
|
|
1738
|
+
* @since 4.0.0
|
|
1739
|
+
* @category Lang
|
|
1740
|
+
* @param {*} value The value to check.
|
|
1741
|
+
* @returns {boolean} Returns `true` if `value` is an array-like object,
|
|
1742
|
+
* else `false`.
|
|
1743
|
+
* @example
|
|
1744
|
+
*
|
|
1745
|
+
* _.isArrayLikeObject([1, 2, 3]);
|
|
1746
|
+
* // => true
|
|
1747
|
+
*
|
|
1748
|
+
* _.isArrayLikeObject(document.body.children);
|
|
1749
|
+
* // => true
|
|
1750
|
+
*
|
|
1751
|
+
* _.isArrayLikeObject('abc');
|
|
1752
|
+
* // => false
|
|
1753
|
+
*
|
|
1754
|
+
* _.isArrayLikeObject(_.noop);
|
|
1755
|
+
* // => false
|
|
1756
|
+
*/
|
|
1757
|
+
function isArrayLikeObject(value) {
|
|
1758
|
+
return isObjectLike(value) && isArrayLike(value);
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1761
|
+
/**
|
|
1762
|
+
* Checks if `value` is a buffer.
|
|
1763
|
+
*
|
|
1764
|
+
* @static
|
|
1765
|
+
* @memberOf _
|
|
1766
|
+
* @since 4.3.0
|
|
1767
|
+
* @category Lang
|
|
1768
|
+
* @param {*} value The value to check.
|
|
1769
|
+
* @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
|
|
1770
|
+
* @example
|
|
1771
|
+
*
|
|
1772
|
+
* _.isBuffer(new Buffer(2));
|
|
1773
|
+
* // => true
|
|
1774
|
+
*
|
|
1775
|
+
* _.isBuffer(new Uint8Array(2));
|
|
1776
|
+
* // => false
|
|
1777
|
+
*/
|
|
1778
|
+
var isBuffer = nativeIsBuffer || stubFalse;
|
|
1779
|
+
|
|
1780
|
+
/**
|
|
1781
|
+
* Checks if `value` is classified as a `Function` object.
|
|
1782
|
+
*
|
|
1783
|
+
* @static
|
|
1784
|
+
* @memberOf _
|
|
1785
|
+
* @since 0.1.0
|
|
1786
|
+
* @category Lang
|
|
1787
|
+
* @param {*} value The value to check.
|
|
1788
|
+
* @returns {boolean} Returns `true` if `value` is a function, else `false`.
|
|
1789
|
+
* @example
|
|
1790
|
+
*
|
|
1791
|
+
* _.isFunction(_);
|
|
1792
|
+
* // => true
|
|
1793
|
+
*
|
|
1794
|
+
* _.isFunction(/abc/);
|
|
1795
|
+
* // => false
|
|
1796
|
+
*/
|
|
1797
|
+
function isFunction(value) {
|
|
1798
|
+
// The use of `Object#toString` avoids issues with the `typeof` operator
|
|
1799
|
+
// in Safari 8-9 which returns 'object' for typed array and other constructors.
|
|
1800
|
+
var tag = isObject(value) ? objectToString.call(value) : '';
|
|
1801
|
+
return tag == funcTag || tag == genTag;
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
/**
|
|
1805
|
+
* Checks if `value` is a valid array-like length.
|
|
1806
|
+
*
|
|
1807
|
+
* **Note:** This method is loosely based on
|
|
1808
|
+
* [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
|
|
1809
|
+
*
|
|
1810
|
+
* @static
|
|
1811
|
+
* @memberOf _
|
|
1812
|
+
* @since 4.0.0
|
|
1813
|
+
* @category Lang
|
|
1814
|
+
* @param {*} value The value to check.
|
|
1815
|
+
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
|
1816
|
+
* @example
|
|
1817
|
+
*
|
|
1818
|
+
* _.isLength(3);
|
|
1819
|
+
* // => true
|
|
1820
|
+
*
|
|
1821
|
+
* _.isLength(Number.MIN_VALUE);
|
|
1822
|
+
* // => false
|
|
1823
|
+
*
|
|
1824
|
+
* _.isLength(Infinity);
|
|
1825
|
+
* // => false
|
|
1826
|
+
*
|
|
1827
|
+
* _.isLength('3');
|
|
1828
|
+
* // => false
|
|
1829
|
+
*/
|
|
1830
|
+
function isLength(value) {
|
|
1831
|
+
return typeof value == 'number' &&
|
|
1832
|
+
value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
/**
|
|
1836
|
+
* Checks if `value` is the
|
|
1837
|
+
* [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
|
|
1838
|
+
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|
1839
|
+
*
|
|
1840
|
+
* @static
|
|
1841
|
+
* @memberOf _
|
|
1842
|
+
* @since 0.1.0
|
|
1843
|
+
* @category Lang
|
|
1844
|
+
* @param {*} value The value to check.
|
|
1845
|
+
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
1846
|
+
* @example
|
|
1847
|
+
*
|
|
1848
|
+
* _.isObject({});
|
|
1849
|
+
* // => true
|
|
1850
|
+
*
|
|
1851
|
+
* _.isObject([1, 2, 3]);
|
|
1852
|
+
* // => true
|
|
1853
|
+
*
|
|
1854
|
+
* _.isObject(_.noop);
|
|
1855
|
+
* // => true
|
|
1856
|
+
*
|
|
1857
|
+
* _.isObject(null);
|
|
1858
|
+
* // => false
|
|
1859
|
+
*/
|
|
1860
|
+
function isObject(value) {
|
|
1861
|
+
var type = typeof value;
|
|
1862
|
+
return !!value && (type == 'object' || type == 'function');
|
|
1863
|
+
}
|
|
1864
|
+
|
|
1865
|
+
/**
|
|
1866
|
+
* Checks if `value` is object-like. A value is object-like if it's not `null`
|
|
1867
|
+
* and has a `typeof` result of "object".
|
|
1868
|
+
*
|
|
1869
|
+
* @static
|
|
1870
|
+
* @memberOf _
|
|
1871
|
+
* @since 4.0.0
|
|
1872
|
+
* @category Lang
|
|
1873
|
+
* @param {*} value The value to check.
|
|
1874
|
+
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
|
1875
|
+
* @example
|
|
1876
|
+
*
|
|
1877
|
+
* _.isObjectLike({});
|
|
1878
|
+
* // => true
|
|
1879
|
+
*
|
|
1880
|
+
* _.isObjectLike([1, 2, 3]);
|
|
1881
|
+
* // => true
|
|
1882
|
+
*
|
|
1883
|
+
* _.isObjectLike(_.noop);
|
|
1884
|
+
* // => false
|
|
1885
|
+
*
|
|
1886
|
+
* _.isObjectLike(null);
|
|
1887
|
+
* // => false
|
|
1888
|
+
*/
|
|
1889
|
+
function isObjectLike(value) {
|
|
1890
|
+
return !!value && typeof value == 'object';
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1893
|
+
/**
|
|
1894
|
+
* Creates an array of the own enumerable property names of `object`.
|
|
1895
|
+
*
|
|
1896
|
+
* **Note:** Non-object values are coerced to objects. See the
|
|
1897
|
+
* [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
|
|
1898
|
+
* for more details.
|
|
1899
|
+
*
|
|
1900
|
+
* @static
|
|
1901
|
+
* @since 0.1.0
|
|
1902
|
+
* @memberOf _
|
|
1903
|
+
* @category Object
|
|
1904
|
+
* @param {Object} object The object to query.
|
|
1905
|
+
* @returns {Array} Returns the array of property names.
|
|
1906
|
+
* @example
|
|
1907
|
+
*
|
|
1908
|
+
* function Foo() {
|
|
1909
|
+
* this.a = 1;
|
|
1910
|
+
* this.b = 2;
|
|
1911
|
+
* }
|
|
1912
|
+
*
|
|
1913
|
+
* Foo.prototype.c = 3;
|
|
1914
|
+
*
|
|
1915
|
+
* _.keys(new Foo);
|
|
1916
|
+
* // => ['a', 'b'] (iteration order is not guaranteed)
|
|
1917
|
+
*
|
|
1918
|
+
* _.keys('hi');
|
|
1919
|
+
* // => ['0', '1']
|
|
1920
|
+
*/
|
|
1921
|
+
function keys(object) {
|
|
1922
|
+
return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1925
|
+
/**
|
|
1926
|
+
* This method returns a new empty array.
|
|
1927
|
+
*
|
|
1928
|
+
* @static
|
|
1929
|
+
* @memberOf _
|
|
1930
|
+
* @since 4.13.0
|
|
1931
|
+
* @category Util
|
|
1932
|
+
* @returns {Array} Returns the new empty array.
|
|
1933
|
+
* @example
|
|
1934
|
+
*
|
|
1935
|
+
* var arrays = _.times(2, _.stubArray);
|
|
1936
|
+
*
|
|
1937
|
+
* console.log(arrays);
|
|
1938
|
+
* // => [[], []]
|
|
1939
|
+
*
|
|
1940
|
+
* console.log(arrays[0] === arrays[1]);
|
|
1941
|
+
* // => false
|
|
1942
|
+
*/
|
|
1943
|
+
function stubArray() {
|
|
1944
|
+
return [];
|
|
1945
|
+
}
|
|
1946
|
+
|
|
1947
|
+
/**
|
|
1948
|
+
* This method returns `false`.
|
|
1949
|
+
*
|
|
1950
|
+
* @static
|
|
1951
|
+
* @memberOf _
|
|
1952
|
+
* @since 4.13.0
|
|
1953
|
+
* @category Util
|
|
1954
|
+
* @returns {boolean} Returns `false`.
|
|
1955
|
+
* @example
|
|
1956
|
+
*
|
|
1957
|
+
* _.times(2, _.stubFalse);
|
|
1958
|
+
* // => [false, false]
|
|
1959
|
+
*/
|
|
1960
|
+
function stubFalse() {
|
|
1961
|
+
return false;
|
|
1962
|
+
}
|
|
1963
|
+
|
|
1964
|
+
module.exports = cloneDeep;
|
|
1965
|
+
} (lodash_clonedeep, lodash_clonedeep.exports));
|
|
1966
|
+
|
|
1967
|
+
var lodash_clonedeepExports = lodash_clonedeep.exports;
|
|
1968
|
+
var cloneDeep = /*@__PURE__*/getDefaultExportFromCjs$1(lodash_clonedeepExports);
|
|
1969
|
+
|
|
1970
|
+
/**
|
|
1971
|
+
* Perform a deep clone of the given value.
|
|
1972
|
+
*
|
|
1973
|
+
* This function supports cloning:
|
|
1974
|
+
*
|
|
1975
|
+
* - Primitive types such as booleans, numbers and strings
|
|
1976
|
+
* - Arrays and objects
|
|
1977
|
+
* - Classes
|
|
1978
|
+
* - `Date`,
|
|
1979
|
+
* - `Map`,
|
|
1980
|
+
* - `RegExp`
|
|
1981
|
+
* - `Set`
|
|
1982
|
+
* - `Symbol`
|
|
1983
|
+
*
|
|
1984
|
+
* The following values are NOT cloned:
|
|
1985
|
+
*
|
|
1986
|
+
* - `Error` (and subclasses) - Cloned value will reference the same Error instance.
|
|
1987
|
+
* - DOM `Node` (and subclasses) - Cloned value will return the same DOM reference.
|
|
1988
|
+
* - `Function` (and arrow functions) - Cloned value will be an empty object `{}`
|
|
1989
|
+
*
|
|
1990
|
+
* @public
|
|
1991
|
+
* @param value - The value to recursively clone.
|
|
1992
|
+
* @returns Returns the deep cloned value.
|
|
1993
|
+
*/
|
|
1994
|
+
function deepClone(value) {
|
|
1995
|
+
return cloneDeep(value);
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
/**
|
|
1999
|
+
* An error indicating that a mandatory value is not set.
|
|
2000
|
+
*
|
|
2001
|
+
* @public
|
|
2002
|
+
*/
|
|
2003
|
+
class MissingValueError extends Error {
|
|
2004
|
+
constructor(message) {
|
|
2005
|
+
super(message);
|
|
2006
|
+
Object.setPrototypeOf(this, MissingValueError.prototype);
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
/**
|
|
2010
|
+
* Assert that a value is set and throw a {@link MissingValueError} if it is not,
|
|
2011
|
+
* i.e., both null and undefined values will throw an error. This can be nice to
|
|
2012
|
+
* use when transforming data between view model and rest api model.
|
|
2013
|
+
*
|
|
2014
|
+
* @public
|
|
2015
|
+
* @param value - the value asserted to be set.
|
|
2016
|
+
* @param message - an optional exception message to use if the check fails.
|
|
2017
|
+
* @returns the value unambiguously defined.
|
|
2018
|
+
* @throws {@link MissingValueError} if value is not set.
|
|
2019
|
+
*/
|
|
2020
|
+
function ensureSet(value, message = "") {
|
|
2021
|
+
if (!isSet(value)) {
|
|
2022
|
+
throw new MissingValueError(message);
|
|
2023
|
+
}
|
|
2024
|
+
return value;
|
|
2025
|
+
}
|
|
2026
|
+
|
|
2027
|
+
/**
|
|
2028
|
+
* Takes an optionally nested textobject structure and convert to a flat
|
|
2029
|
+
* structure. Nested keys are joined with a dot ".". Deep nesting is supported.
|
|
2030
|
+
*
|
|
2031
|
+
* Given the following:
|
|
2032
|
+
* ```
|
|
2033
|
+
* {
|
|
2034
|
+
* "foo": {
|
|
2035
|
+
* "bar": "text"
|
|
2036
|
+
* }
|
|
2037
|
+
* }
|
|
2038
|
+
* ```
|
|
2039
|
+
*
|
|
2040
|
+
* It would produce the following output:
|
|
2041
|
+
* ```
|
|
2042
|
+
* {
|
|
2043
|
+
* "foo.bar": "text"
|
|
2044
|
+
* }
|
|
2045
|
+
* ```
|
|
2046
|
+
*
|
|
2047
|
+
* If the src object is already flat the output will be the same.
|
|
2048
|
+
*
|
|
2049
|
+
* @public
|
|
2050
|
+
* @param src - Source data
|
|
2051
|
+
* @param destination - Destination to write temporary result to.
|
|
2052
|
+
* @param prefix - If set this is prefixed to all keys.
|
|
2053
|
+
*/
|
|
2054
|
+
function flatten(src, destination, prefix = "") {
|
|
2055
|
+
destination = destination || {};
|
|
2056
|
+
return Object.entries(src).reduce((result, [key, data]) => {
|
|
2057
|
+
const nestedKey = `${prefix}${key}`;
|
|
2058
|
+
if (typeof data === "string") {
|
|
2059
|
+
result[nestedKey] = data;
|
|
2060
|
+
}
|
|
2061
|
+
else {
|
|
2062
|
+
flatten(data, result, `${nestedKey}.`);
|
|
2063
|
+
}
|
|
2064
|
+
return result;
|
|
2065
|
+
}, destination);
|
|
2066
|
+
}
|
|
2067
|
+
|
|
2068
|
+
/**
|
|
2069
|
+
* Takes a date string in any of the supported formats and normalizes it for
|
|
2070
|
+
* usage with `FDate` (ISO-8601).
|
|
2071
|
+
*
|
|
2072
|
+
* Handles:
|
|
2073
|
+
*
|
|
2074
|
+
* - `YYYY-MM-DD`
|
|
2075
|
+
* - `YYYY/MM/DD`
|
|
2076
|
+
* - `YYYYMMDD`
|
|
2077
|
+
*
|
|
2078
|
+
* @internal
|
|
2079
|
+
* @param value - Date string to normalize.
|
|
2080
|
+
* @returns Normalized date string (ISO-8601) or undefined if it doesnt match one of the
|
|
2081
|
+
* supported formats.
|
|
2082
|
+
*/
|
|
2083
|
+
function normalizeDateFormat(value) {
|
|
2084
|
+
const supportedFormats = [
|
|
2085
|
+
/* yyyy-mm-dd */
|
|
2086
|
+
/^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})$/,
|
|
2087
|
+
/* yyyymmdd */
|
|
2088
|
+
/^(?<year>\d{4})(?<month>\d{2})(?<day>\d{2})$/,
|
|
2089
|
+
/* yyyy-mm-dd */
|
|
2090
|
+
/^(?<year>\d{4})\/(?<month>\d{2})\/(?<day>\d{2})$/,
|
|
2091
|
+
];
|
|
2092
|
+
const match = supportedFormats
|
|
2093
|
+
.map((pattern) => value.match(pattern))
|
|
2094
|
+
.find(Boolean);
|
|
2095
|
+
if (!match || !match.groups) {
|
|
2096
|
+
return undefined;
|
|
2097
|
+
}
|
|
2098
|
+
const { year, month, day } = match.groups;
|
|
2099
|
+
return `${year}-${month}-${day}`;
|
|
2100
|
+
}
|
|
2101
|
+
|
|
2102
|
+
/**
|
|
2103
|
+
* Takes a string containing only numbers and checks that the checksum is correct
|
|
2104
|
+
* according to the Luhn Algorithm.
|
|
2105
|
+
*
|
|
2106
|
+
* @public
|
|
2107
|
+
* @param inputString - A string containing only numbers
|
|
2108
|
+
*/
|
|
2109
|
+
function testLuhnChecksum(inputString) {
|
|
2110
|
+
let sum = 0;
|
|
2111
|
+
if (/^[0-9]+$/.test(inputString) === false) {
|
|
2112
|
+
throw new Error("Luhn Checksum test only works on strings containing numbers");
|
|
2113
|
+
}
|
|
2114
|
+
inputString
|
|
2115
|
+
.split("")
|
|
2116
|
+
.reverse()
|
|
2117
|
+
.forEach((numChar, index) => {
|
|
2118
|
+
const digit = parseInt(numChar, 10) * ((index + 1) % 2 === 0 ? 2 : 1);
|
|
2119
|
+
sum += digit >= 10 ? digit - 9 : digit;
|
|
2120
|
+
});
|
|
2121
|
+
return sum % 10 === 0;
|
|
2122
|
+
}
|
|
2123
|
+
|
|
2124
|
+
/**
|
|
2125
|
+
* @public
|
|
2126
|
+
*/
|
|
2127
|
+
function validChecksum(value) {
|
|
2128
|
+
const yymmddxxxx = value.slice(2).replace(/-/g, "");
|
|
2129
|
+
return testLuhnChecksum(yymmddxxxx);
|
|
2130
|
+
}
|
|
2131
|
+
|
|
2132
|
+
const TWELVE_HOURS = 12 * 60 * 60;
|
|
2133
|
+
/**
|
|
2134
|
+
* @public
|
|
2135
|
+
*/
|
|
2136
|
+
function setCookie(options) {
|
|
2137
|
+
const shouldKeepTheExistingCookie = options.keepAnyExistingCookie && findCookie(options.name);
|
|
2138
|
+
if (shouldKeepTheExistingCookie) {
|
|
2139
|
+
return;
|
|
2140
|
+
}
|
|
2141
|
+
let cookieString = `${options.name}=${encodeURIComponent(options.value)}; path=/;`;
|
|
2142
|
+
const timeLimitSeconds = options.timeLimitMillis
|
|
2143
|
+
? Math.round(options.timeLimitMillis / 1000)
|
|
2144
|
+
: options.timeLimitSeconds;
|
|
2145
|
+
const timeout = timeLimitSeconds ?? TWELVE_HOURS;
|
|
2146
|
+
cookieString += `max-age=${timeout};`;
|
|
2147
|
+
document.cookie = cookieString;
|
|
2148
|
+
}
|
|
2149
|
+
/**
|
|
2150
|
+
* @public
|
|
2151
|
+
*/
|
|
2152
|
+
function deleteCookie(name) {
|
|
2153
|
+
document.cookie = `${name}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT;`;
|
|
2154
|
+
}
|
|
2155
|
+
/**
|
|
2156
|
+
* @public
|
|
2157
|
+
*/
|
|
2158
|
+
function findCookie(name) {
|
|
2159
|
+
/* handle when document or cookie does not exist, e.g. when DOM isn't
|
|
2160
|
+
* present */
|
|
2161
|
+
if (!document?.cookie) {
|
|
2162
|
+
return undefined;
|
|
2163
|
+
}
|
|
2164
|
+
const cookieKeyValueStrings = document.cookie.split(";");
|
|
2165
|
+
for (const cookie of cookieKeyValueStrings) {
|
|
2166
|
+
const [foundCookieName, foundCookieValue] = cookie.split("=", 2);
|
|
2167
|
+
if (name === foundCookieName.trim()) {
|
|
2168
|
+
return foundCookieValue
|
|
2169
|
+
? decodeURIComponent(foundCookieValue)
|
|
2170
|
+
: undefined;
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
return undefined;
|
|
2174
|
+
}
|
|
2175
|
+
|
|
2176
|
+
const BANK_ACCOUNT_NUMBER_REGEXP = /^\d{3,16}$/;
|
|
2177
|
+
const BANK_ACCOUNT_NUMBER_TRIM_REGEXP = /[- .,]+/g;
|
|
2178
|
+
/**
|
|
2179
|
+
* @public
|
|
2180
|
+
*/
|
|
2181
|
+
function parseBankAccountNumber(value) {
|
|
2182
|
+
if (isEmpty(value)) {
|
|
2183
|
+
return undefined;
|
|
2184
|
+
}
|
|
2185
|
+
// remove hyphen, blank space, period, comma
|
|
2186
|
+
const trimmedValue = value.replace(BANK_ACCOUNT_NUMBER_TRIM_REGEXP, "");
|
|
2187
|
+
return BANK_ACCOUNT_NUMBER_REGEXP.test(trimmedValue)
|
|
2188
|
+
? trimmedValue
|
|
2189
|
+
: undefined;
|
|
2190
|
+
}
|
|
2191
|
+
|
|
2192
|
+
const BANKGIRO_REGEXP_HYPHEN = /^(\d{3,4})[-]?(\d{4})$/;
|
|
2193
|
+
/**
|
|
2194
|
+
* @public
|
|
2195
|
+
*/
|
|
2196
|
+
function parseBankgiro(value) {
|
|
2197
|
+
if (isEmpty(value)) {
|
|
2198
|
+
return undefined;
|
|
2199
|
+
}
|
|
2200
|
+
const match = value.match(BANKGIRO_REGEXP_HYPHEN);
|
|
2201
|
+
if (!match) {
|
|
2202
|
+
return undefined;
|
|
2203
|
+
}
|
|
2204
|
+
if (!testLuhnChecksum(`${match[1]}${match[2]}`)) {
|
|
2205
|
+
return undefined;
|
|
2206
|
+
}
|
|
2207
|
+
return `${match[1]}-${match[2]}`;
|
|
2208
|
+
}
|
|
2209
|
+
|
|
2210
|
+
const CLEARINGNUMBER_REGEXP = /^\d{4}([-\s]?\d)?$/;
|
|
2211
|
+
/**
|
|
2212
|
+
* @public
|
|
2213
|
+
*/
|
|
2214
|
+
function parseClearingNumber(value) {
|
|
2215
|
+
if (isEmpty(value)) {
|
|
2216
|
+
return undefined;
|
|
2217
|
+
}
|
|
2218
|
+
if (!CLEARINGNUMBER_REGEXP.test(value)) {
|
|
2219
|
+
return undefined;
|
|
2220
|
+
}
|
|
2221
|
+
// add hyphen between number 4 & 5
|
|
2222
|
+
return value.length === 5
|
|
2223
|
+
? `${value.substring(0, 4)}-${value.substring(4, 5)}`
|
|
2224
|
+
: value;
|
|
2225
|
+
}
|
|
2226
|
+
/**
|
|
2227
|
+
* @public
|
|
2228
|
+
*/
|
|
2229
|
+
function formatClearingNumberForBackend(value) {
|
|
2230
|
+
// remove the 5th number
|
|
2231
|
+
return value.substring(0, 4);
|
|
2232
|
+
}
|
|
2233
|
+
|
|
2234
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
2235
|
+
|
|
2236
|
+
function getDefaultExportFromCjs (x) {
|
|
2237
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
2238
|
+
}
|
|
2239
|
+
|
|
2240
|
+
var dayjs_min = {exports: {}};
|
|
2241
|
+
|
|
2242
|
+
(function (module, exports) {
|
|
2243
|
+
!function(t,e){module.exports=e();}(commonjsGlobal,(function(){var t=1e3,e=6e4,n=36e5,r="millisecond",i="second",s="minute",u="hour",a="day",o="week",c="month",f="quarter",h="year",d="date",l="Invalid Date",$=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,y=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,M={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(t){var e=["th","st","nd","rd"],n=t%100;return "["+t+(e[(n-20)%10]||e[n]||e[0])+"]"}},m=function(t,e,n){var r=String(t);return !r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},v={s:m,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),i=n%60;return (e<=0?"+":"-")+m(r,2,"0")+":"+m(i,2,"0")},m:function t(e,n){if(e.date()<n.date())return -t(n,e);var r=12*(n.year()-e.year())+(n.month()-e.month()),i=e.clone().add(r,c),s=n-i<0,u=e.clone().add(r+(s?-1:1),c);return +(-(r+(n-i)/(s?i-u:u-i))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(t){return {M:c,y:h,w:o,d:a,D:d,h:u,m:s,s:i,ms:r,Q:f}[t]||String(t||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},g="en",D={};D[g]=M;var p="$isDayjsObject",S=function(t){return t instanceof _||!(!t||!t[p])},w=function t(e,n,r){var i;if(!e)return g;if("string"==typeof e){var s=e.toLowerCase();D[s]&&(i=s),n&&(D[s]=n,i=s);var u=e.split("-");if(!i&&u.length>1)return t(u[0])}else {var a=e.name;D[a]=e,i=a;}return !r&&i&&(g=i),i||!r&&g},O=function(t,e){if(S(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new _(n)},b=v;b.l=w,b.i=S,b.w=function(t,e){return O(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var _=function(){function M(t){this.$L=w(t.locale,null,!0),this.parse(t),this.$x=this.$x||t.x||{},this[p]=!0;}var m=M.prototype;return m.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(b.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var r=e.match($);if(r){var i=r[2]-1||0,s=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)}}return new Date(e)}(t),this.init();},m.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds();},m.$utils=function(){return b},m.isValid=function(){return !(this.$d.toString()===l)},m.isSame=function(t,e){var n=O(t);return this.startOf(e)<=n&&n<=this.endOf(e)},m.isAfter=function(t,e){return O(t)<this.startOf(e)},m.isBefore=function(t,e){return this.endOf(e)<O(t)},m.$g=function(t,e,n){return b.u(t)?this[e]:this.set(n,t)},m.unix=function(){return Math.floor(this.valueOf()/1e3)},m.valueOf=function(){return this.$d.getTime()},m.startOf=function(t,e){var n=this,r=!!b.u(e)||e,f=b.p(t),l=function(t,e){var i=b.w(n.$u?Date.UTC(n.$y,e,t):new Date(n.$y,e,t),n);return r?i:i.endOf(a)},$=function(t,e){return b.w(n.toDate()[t].apply(n.toDate("s"),(r?[0,0,0,0]:[23,59,59,999]).slice(e)),n)},y=this.$W,M=this.$M,m=this.$D,v="set"+(this.$u?"UTC":"");switch(f){case h:return r?l(1,0):l(31,11);case c:return r?l(1,M):l(0,M+1);case o:var g=this.$locale().weekStart||0,D=(y<g?y+7:y)-g;return l(r?m-D:m+(6-D),M);case a:case d:return $(v+"Hours",0);case u:return $(v+"Minutes",1);case s:return $(v+"Seconds",2);case i:return $(v+"Milliseconds",3);default:return this.clone()}},m.endOf=function(t){return this.startOf(t,!1)},m.$set=function(t,e){var n,o=b.p(t),f="set"+(this.$u?"UTC":""),l=(n={},n[a]=f+"Date",n[d]=f+"Date",n[c]=f+"Month",n[h]=f+"FullYear",n[u]=f+"Hours",n[s]=f+"Minutes",n[i]=f+"Seconds",n[r]=f+"Milliseconds",n)[o],$=o===a?this.$D+(e-this.$W):e;if(o===c||o===h){var y=this.clone().set(d,1);y.$d[l]($),y.init(),this.$d=y.set(d,Math.min(this.$D,y.daysInMonth())).$d;}else l&&this.$d[l]($);return this.init(),this},m.set=function(t,e){return this.clone().$set(t,e)},m.get=function(t){return this[b.p(t)]()},m.add=function(r,f){var d,l=this;r=Number(r);var $=b.p(f),y=function(t){var e=O(l);return b.w(e.date(e.date()+Math.round(t*r)),l)};if($===c)return this.set(c,this.$M+r);if($===h)return this.set(h,this.$y+r);if($===a)return y(1);if($===o)return y(7);var M=(d={},d[s]=e,d[u]=n,d[i]=t,d)[$]||1,m=this.$d.getTime()+r*M;return b.w(m,this)},m.subtract=function(t,e){return this.add(-1*t,e)},m.format=function(t){var e=this,n=this.$locale();if(!this.isValid())return n.invalidDate||l;var r=t||"YYYY-MM-DDTHH:mm:ssZ",i=b.z(this),s=this.$H,u=this.$m,a=this.$M,o=n.weekdays,c=n.months,f=n.meridiem,h=function(t,n,i,s){return t&&(t[n]||t(e,r))||i[n].slice(0,s)},d=function(t){return b.s(s%12||12,t,"0")},$=f||function(t,e,n){var r=t<12?"AM":"PM";return n?r.toLowerCase():r};return r.replace(y,(function(t,r){return r||function(t){switch(t){case"YY":return String(e.$y).slice(-2);case"YYYY":return b.s(e.$y,4,"0");case"M":return a+1;case"MM":return b.s(a+1,2,"0");case"MMM":return h(n.monthsShort,a,c,3);case"MMMM":return h(c,a);case"D":return e.$D;case"DD":return b.s(e.$D,2,"0");case"d":return String(e.$W);case"dd":return h(n.weekdaysMin,e.$W,o,2);case"ddd":return h(n.weekdaysShort,e.$W,o,3);case"dddd":return o[e.$W];case"H":return String(s);case"HH":return b.s(s,2,"0");case"h":return d(1);case"hh":return d(2);case"a":return $(s,u,!0);case"A":return $(s,u,!1);case"m":return String(u);case"mm":return b.s(u,2,"0");case"s":return String(e.$s);case"ss":return b.s(e.$s,2,"0");case"SSS":return b.s(e.$ms,3,"0");case"Z":return i}return null}(t)||i.replace(":","")}))},m.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},m.diff=function(r,d,l){var $,y=this,M=b.p(d),m=O(r),v=(m.utcOffset()-this.utcOffset())*e,g=this-m,D=function(){return b.m(y,m)};switch(M){case h:$=D()/12;break;case c:$=D();break;case f:$=D()/3;break;case o:$=(g-v)/6048e5;break;case a:$=(g-v)/864e5;break;case u:$=g/n;break;case s:$=g/e;break;case i:$=g/t;break;default:$=g;}return l?$:b.a($)},m.daysInMonth=function(){return this.endOf(c).$D},m.$locale=function(){return D[this.$L]},m.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=w(t,e,!0);return r&&(n.$L=r),n},m.clone=function(){return b.w(this.$d,this)},m.toDate=function(){return new Date(this.valueOf())},m.toJSON=function(){return this.isValid()?this.toISOString():null},m.toISOString=function(){return this.$d.toISOString()},m.toString=function(){return this.$d.toUTCString()},M}(),k=_.prototype;return O.prototype=k,[["$ms",r],["$s",i],["$m",s],["$H",u],["$W",a],["$M",c],["$y",h],["$D",d]].forEach((function(t){k[t[1]]=function(e){return this.$g(e,t[0],t[1])};})),O.extend=function(t,e){return t.$i||(t(e,_,O),t.$i=!0),O},O.locale=w,O.isDayjs=S,O.unix=function(t){return O(1e3*t)},O.en=D[g],O.Ls=D,O.p={},O}));
|
|
2244
|
+
} (dayjs_min));
|
|
2245
|
+
|
|
2246
|
+
var dayjs_minExports = dayjs_min.exports;
|
|
2247
|
+
var dayjs = /*@__PURE__*/getDefaultExportFromCjs(dayjs_minExports);
|
|
2248
|
+
|
|
2249
|
+
var sv = {exports: {}};
|
|
2250
|
+
|
|
2251
|
+
(function (module, exports) {
|
|
2252
|
+
!function(e,t){module.exports=t(dayjs_minExports);}(commonjsGlobal,(function(e){function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=t(e),d={name:"sv",weekdays:"söndag_måndag_tisdag_onsdag_torsdag_fredag_lördag".split("_"),weekdaysShort:"sön_mån_tis_ons_tor_fre_lör".split("_"),weekdaysMin:"sö_må_ti_on_to_fr_lö".split("_"),months:"januari_februari_mars_april_maj_juni_juli_augusti_september_oktober_november_december".split("_"),monthsShort:"jan_feb_mar_apr_maj_jun_jul_aug_sep_okt_nov_dec".split("_"),weekStart:1,yearStart:4,ordinal:function(e){var t=e%10;return "["+e+(1===t||2===t?"a":"e")+"]"},formats:{LT:"HH:mm",LTS:"HH:mm:ss",L:"YYYY-MM-DD",LL:"D MMMM YYYY",LLL:"D MMMM YYYY [kl.] HH:mm",LLLL:"dddd D MMMM YYYY [kl.] HH:mm",lll:"D MMM YYYY HH:mm",llll:"ddd D MMM YYYY HH:mm"},relativeTime:{future:"om %s",past:"för %s sedan",s:"några sekunder",m:"en minut",mm:"%d minuter",h:"en timme",hh:"%d timmar",d:"en dag",dd:"%d dagar",M:"en månad",MM:"%d månader",y:"ett år",yy:"%d år"}};return a.default.locale(d,null,!0),d}));
|
|
2253
|
+
} (sv));
|
|
2254
|
+
|
|
2255
|
+
var weekOfYear$1 = {exports: {}};
|
|
2256
|
+
|
|
2257
|
+
(function (module, exports) {
|
|
2258
|
+
!function(e,t){module.exports=t();}(commonjsGlobal,(function(){var e="week",t="year";return function(i,n,r){var f=n.prototype;f.week=function(i){if(void 0===i&&(i=null),null!==i)return this.add(7*(i-this.week()),"day");var n=this.$locale().yearStart||1;if(11===this.month()&&this.date()>25){var f=r(this).startOf(t).add(1,t).date(n),s=r(this).endOf(e);if(f.isBefore(s))return 1}var a=r(this).startOf(t).date(n).startOf(e).subtract(1,"millisecond"),o=this.diff(a,e,!0);return o<0?r(this).startOf("week").week():Math.ceil(o)},f.weeks=function(e){return void 0===e&&(e=null),this.week(e)};}}));
|
|
2259
|
+
} (weekOfYear$1));
|
|
2260
|
+
|
|
2261
|
+
var weekOfYearExports = weekOfYear$1.exports;
|
|
2262
|
+
var weekOfYear = /*@__PURE__*/getDefaultExportFromCjs(weekOfYearExports);
|
|
2263
|
+
|
|
2264
|
+
dayjs.extend(weekOfYear);
|
|
2265
|
+
|
|
2266
|
+
/**
|
|
2267
|
+
* What format to use when formatting dates.
|
|
2268
|
+
*
|
|
2269
|
+
* @public
|
|
2270
|
+
*/
|
|
2271
|
+
var DateFormat;
|
|
2272
|
+
(function (DateFormat) {
|
|
2273
|
+
/**
|
|
2274
|
+
* Format with weekday, day, month, year as a human-readable string.
|
|
2275
|
+
*
|
|
2276
|
+
* "onsdag 4 maj 2022"
|
|
2277
|
+
*/
|
|
2278
|
+
DateFormat["FULL"] = "full";
|
|
2279
|
+
/**
|
|
2280
|
+
* Format with day, month, year as a human-readable string.
|
|
2281
|
+
*
|
|
2282
|
+
* "4 maj 2022"
|
|
2283
|
+
*/
|
|
2284
|
+
DateFormat["LONG"] = "long";
|
|
2285
|
+
/**
|
|
2286
|
+
* Format according to ISO 8601 format.
|
|
2287
|
+
*
|
|
2288
|
+
* "2022-05-04"
|
|
2289
|
+
*/
|
|
2290
|
+
DateFormat["ISO8601"] = "iso-8601";
|
|
2291
|
+
/**
|
|
2292
|
+
* Format YYYYMMDD
|
|
2293
|
+
*
|
|
2294
|
+
* "20220504"
|
|
2295
|
+
*/
|
|
2296
|
+
DateFormat["YYYYMMDD"] = "YYYYMMDD";
|
|
2297
|
+
})(DateFormat || (DateFormat = {}));
|
|
2298
|
+
|
|
2299
|
+
/**
|
|
2300
|
+
* What locale to use when formatting days.
|
|
2301
|
+
*
|
|
2302
|
+
* @public
|
|
2303
|
+
*/
|
|
2304
|
+
var Locale;
|
|
2305
|
+
(function (Locale) {
|
|
2306
|
+
Locale["SWEDISH"] = "sv";
|
|
2307
|
+
Locale["ENGLISH"] = "en";
|
|
2308
|
+
})(Locale || (Locale = {}));
|
|
2309
|
+
function getDefaultLocale() {
|
|
2310
|
+
return Locale.SWEDISH;
|
|
2311
|
+
}
|
|
2312
|
+
let _locale = getDefaultLocale();
|
|
2313
|
+
/**
|
|
2314
|
+
* Get current locale.
|
|
2315
|
+
*
|
|
2316
|
+
* Swedish locale is default.
|
|
2317
|
+
*
|
|
2318
|
+
* @public
|
|
2319
|
+
*/
|
|
2320
|
+
function getLocale() {
|
|
2321
|
+
return _locale;
|
|
2322
|
+
}
|
|
2323
|
+
|
|
2324
|
+
/**
|
|
2325
|
+
* Days in a week.
|
|
2326
|
+
* MONDAY(1) to SUNDAY(7)
|
|
2327
|
+
*
|
|
2328
|
+
* @public
|
|
2329
|
+
*/
|
|
2330
|
+
var Weekday;
|
|
2331
|
+
(function (Weekday) {
|
|
2332
|
+
Weekday[Weekday["MONDAY"] = 1] = "MONDAY";
|
|
2333
|
+
Weekday[Weekday["TUESDAY"] = 2] = "TUESDAY";
|
|
2334
|
+
Weekday[Weekday["WEDNESDAY"] = 3] = "WEDNESDAY";
|
|
2335
|
+
Weekday[Weekday["THURSDAY"] = 4] = "THURSDAY";
|
|
2336
|
+
Weekday[Weekday["FRIDAY"] = 5] = "FRIDAY";
|
|
2337
|
+
Weekday[Weekday["SATURDAY"] = 6] = "SATURDAY";
|
|
2338
|
+
Weekday[Weekday["SUNDAY"] = 7] = "SUNDAY";
|
|
2339
|
+
})(Weekday || (Weekday = {}));
|
|
2340
|
+
|
|
2341
|
+
({
|
|
2342
|
+
[Locale.SWEDISH]: [
|
|
2343
|
+
{
|
|
2344
|
+
weekday: Weekday.MONDAY,
|
|
2345
|
+
name: "måndag",
|
|
2346
|
+
shortName: "mån",
|
|
2347
|
+
},
|
|
2348
|
+
{
|
|
2349
|
+
weekday: Weekday.TUESDAY,
|
|
2350
|
+
name: "tisdag",
|
|
2351
|
+
shortName: "tis",
|
|
2352
|
+
},
|
|
2353
|
+
{
|
|
2354
|
+
weekday: Weekday.WEDNESDAY,
|
|
2355
|
+
name: "onsdag",
|
|
2356
|
+
shortName: "ons",
|
|
2357
|
+
},
|
|
2358
|
+
{
|
|
2359
|
+
weekday: Weekday.THURSDAY,
|
|
2360
|
+
name: "torsdag",
|
|
2361
|
+
shortName: "tor",
|
|
2362
|
+
},
|
|
2363
|
+
{
|
|
2364
|
+
weekday: Weekday.FRIDAY,
|
|
2365
|
+
name: "fredag",
|
|
2366
|
+
shortName: "fre",
|
|
2367
|
+
},
|
|
2368
|
+
{
|
|
2369
|
+
weekday: Weekday.SATURDAY,
|
|
2370
|
+
name: "lördag",
|
|
2371
|
+
shortName: "lör",
|
|
2372
|
+
},
|
|
2373
|
+
{
|
|
2374
|
+
weekday: Weekday.SUNDAY,
|
|
2375
|
+
name: "söndag",
|
|
2376
|
+
shortName: "sön",
|
|
2377
|
+
},
|
|
2378
|
+
],
|
|
2379
|
+
[Locale.ENGLISH]: [
|
|
2380
|
+
{
|
|
2381
|
+
weekday: Weekday.MONDAY,
|
|
2382
|
+
name: "Monday",
|
|
2383
|
+
shortName: "Mon",
|
|
2384
|
+
},
|
|
2385
|
+
{
|
|
2386
|
+
weekday: Weekday.TUESDAY,
|
|
2387
|
+
name: "Tuesday",
|
|
2388
|
+
shortName: "Tue",
|
|
2389
|
+
},
|
|
2390
|
+
{
|
|
2391
|
+
weekday: Weekday.WEDNESDAY,
|
|
2392
|
+
name: "Wednesday",
|
|
2393
|
+
shortName: "Wed",
|
|
2394
|
+
},
|
|
2395
|
+
{
|
|
2396
|
+
weekday: Weekday.THURSDAY,
|
|
2397
|
+
name: "Thursday",
|
|
2398
|
+
shortName: "Thu",
|
|
2399
|
+
},
|
|
2400
|
+
{
|
|
2401
|
+
weekday: Weekday.FRIDAY,
|
|
2402
|
+
name: "Friday",
|
|
2403
|
+
shortName: "Fri",
|
|
2404
|
+
},
|
|
2405
|
+
{
|
|
2406
|
+
weekday: Weekday.SATURDAY,
|
|
2407
|
+
name: "Saturday",
|
|
2408
|
+
shortName: "Sat",
|
|
2409
|
+
},
|
|
2410
|
+
{
|
|
2411
|
+
weekday: Weekday.SUNDAY,
|
|
2412
|
+
name: "Sunday",
|
|
2413
|
+
shortName: "Sun",
|
|
2414
|
+
},
|
|
2415
|
+
],
|
|
2416
|
+
});
|
|
2417
|
+
|
|
2418
|
+
const ISO8601_YYYY_MM_DD = "YYYY-MM-DD";
|
|
2419
|
+
const formatter = {
|
|
2420
|
+
[Locale.SWEDISH]: {
|
|
2421
|
+
[DateFormat.FULL]: "dddd D MMMM YYYY",
|
|
2422
|
+
[DateFormat.LONG]: "D MMMM YYYY",
|
|
2423
|
+
[DateFormat.ISO8601]: ISO8601_YYYY_MM_DD,
|
|
2424
|
+
[DateFormat.YYYYMMDD]: "YYYYMMDD",
|
|
2425
|
+
},
|
|
2426
|
+
[Locale.ENGLISH]: {
|
|
2427
|
+
[DateFormat.FULL]: "dddd, D MMMM YYYY",
|
|
2428
|
+
[DateFormat.LONG]: "D MMMM YYYY",
|
|
2429
|
+
[DateFormat.ISO8601]: ISO8601_YYYY_MM_DD,
|
|
2430
|
+
[DateFormat.YYYYMMDD]: "YYYYMMDD",
|
|
2431
|
+
},
|
|
2432
|
+
};
|
|
2433
|
+
/**
|
|
2434
|
+
* Represents a date (with year, month and day).
|
|
2435
|
+
*
|
|
2436
|
+
* @public
|
|
2437
|
+
*/
|
|
2438
|
+
class FDate {
|
|
2439
|
+
value;
|
|
2440
|
+
constructor(value) {
|
|
2441
|
+
this.value = dayjs(value, ISO8601_YYYY_MM_DD, true);
|
|
2442
|
+
}
|
|
2443
|
+
/**
|
|
2444
|
+
* Create {@link FDate} with an invalid state.
|
|
2445
|
+
*
|
|
2446
|
+
* @internal
|
|
2447
|
+
*/
|
|
2448
|
+
static invalid() {
|
|
2449
|
+
return new FDate("<invalid>");
|
|
2450
|
+
}
|
|
2451
|
+
/**
|
|
2452
|
+
* Create {@link FDate} from current date.
|
|
2453
|
+
*
|
|
2454
|
+
* ```
|
|
2455
|
+
* FDate.now()
|
|
2456
|
+
* ```
|
|
2457
|
+
*
|
|
2458
|
+
* @public
|
|
2459
|
+
*/
|
|
2460
|
+
static now() {
|
|
2461
|
+
return new FDate();
|
|
2462
|
+
}
|
|
2463
|
+
/**
|
|
2464
|
+
* Create {@link FDate} from ISO8601 string.
|
|
2465
|
+
*
|
|
2466
|
+
* ```
|
|
2467
|
+
* FDate.fromIso("2022-04-20")
|
|
2468
|
+
* ```
|
|
2469
|
+
*
|
|
2470
|
+
* @public
|
|
2471
|
+
*/
|
|
2472
|
+
static fromIso(value) {
|
|
2473
|
+
const match = value.match(/^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})$/);
|
|
2474
|
+
if (match && match.groups) {
|
|
2475
|
+
const date = new FDate(value);
|
|
2476
|
+
const { month } = match.groups;
|
|
2477
|
+
/* in dayjs (and native Date) when the day overflows (e.g. 31 feb)
|
|
2478
|
+
* it increases the month, this is not the desired behaviour so we
|
|
2479
|
+
* compare the parsed month with the original month, if they differ
|
|
2480
|
+
* an invalid FDate is returned instead.*/
|
|
2481
|
+
if (date.isValid() && date.month === parseInt(month, 10)) {
|
|
2482
|
+
return date;
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
2485
|
+
return FDate.invalid();
|
|
2486
|
+
}
|
|
2487
|
+
/**
|
|
2488
|
+
* Create {@link FDate} from `Date`.
|
|
2489
|
+
*
|
|
2490
|
+
* ```
|
|
2491
|
+
* FDate.fromDate(new Date())
|
|
2492
|
+
* ```
|
|
2493
|
+
*
|
|
2494
|
+
* @public
|
|
2495
|
+
*/
|
|
2496
|
+
static fromDate(value) {
|
|
2497
|
+
return new FDate(value);
|
|
2498
|
+
}
|
|
2499
|
+
/**
|
|
2500
|
+
* Create {@link FDate} from year, month, day.
|
|
2501
|
+
*
|
|
2502
|
+
* ```
|
|
2503
|
+
* FDate.fromYearMonthDay(2023, 1, 1) // => 2023-01-01
|
|
2504
|
+
* FDate.fromYearMonthDay("2023", "01", "01") // => 2023-01-01
|
|
2505
|
+
* ```
|
|
2506
|
+
*
|
|
2507
|
+
* @public
|
|
2508
|
+
*/
|
|
2509
|
+
static fromYearMonthDay(year, month, day) {
|
|
2510
|
+
const paddedMonth = month.toString().padStart(2, "0");
|
|
2511
|
+
const paddedDay = day.toString().padStart(2, "0");
|
|
2512
|
+
const iso = `${year}-${paddedMonth}-${paddedDay}`;
|
|
2513
|
+
return FDate.fromIso(iso);
|
|
2514
|
+
}
|
|
2515
|
+
/**
|
|
2516
|
+
* Get the year.
|
|
2517
|
+
*
|
|
2518
|
+
* ```
|
|
2519
|
+
* FDate.now().year()// => 2022
|
|
2520
|
+
* ```
|
|
2521
|
+
*
|
|
2522
|
+
* @public
|
|
2523
|
+
*/
|
|
2524
|
+
get year() {
|
|
2525
|
+
return this.value.year();
|
|
2526
|
+
}
|
|
2527
|
+
/**
|
|
2528
|
+
* Get the month.
|
|
2529
|
+
*
|
|
2530
|
+
* Months are one-indexed, so January is month 1.
|
|
2531
|
+
*
|
|
2532
|
+
* ```
|
|
2533
|
+
* FDate.now().month()// => 1-12
|
|
2534
|
+
* ```
|
|
2535
|
+
*
|
|
2536
|
+
* @public
|
|
2537
|
+
*/
|
|
2538
|
+
get month() {
|
|
2539
|
+
return this.value.month() + 1;
|
|
2540
|
+
}
|
|
2541
|
+
/**
|
|
2542
|
+
* Get the week according to the Swedish locale.
|
|
2543
|
+
*
|
|
2544
|
+
* @public
|
|
2545
|
+
*/
|
|
2546
|
+
get week() {
|
|
2547
|
+
return this.value.locale(Locale.SWEDISH).week();
|
|
2548
|
+
}
|
|
2549
|
+
/**
|
|
2550
|
+
* Get the day of the month.
|
|
2551
|
+
*
|
|
2552
|
+
* ```
|
|
2553
|
+
* FDate.now().day// => 1-31
|
|
2554
|
+
* ```
|
|
2555
|
+
*
|
|
2556
|
+
* @public
|
|
2557
|
+
*/
|
|
2558
|
+
get day() {
|
|
2559
|
+
return this.value.date();
|
|
2560
|
+
}
|
|
2561
|
+
/**
|
|
2562
|
+
* Get the name of the month.
|
|
2563
|
+
*
|
|
2564
|
+
* ```
|
|
2565
|
+
* FDate.now().monthName// => January
|
|
2566
|
+
* ```
|
|
2567
|
+
*
|
|
2568
|
+
* @public
|
|
2569
|
+
*/
|
|
2570
|
+
get monthName() {
|
|
2571
|
+
if (this.isValid()) {
|
|
2572
|
+
return this.value.locale(getLocale()).format("MMMM");
|
|
2573
|
+
}
|
|
2574
|
+
else {
|
|
2575
|
+
return "";
|
|
2576
|
+
}
|
|
2577
|
+
}
|
|
2578
|
+
/**
|
|
2579
|
+
* Get the short name of the month.
|
|
2580
|
+
*
|
|
2581
|
+
* ```
|
|
2582
|
+
* FDate.now().monthNameShort// => Jan
|
|
2583
|
+
* ```
|
|
2584
|
+
*
|
|
2585
|
+
* @public
|
|
2586
|
+
*/
|
|
2587
|
+
get monthNameShort() {
|
|
2588
|
+
if (this.isValid()) {
|
|
2589
|
+
return this.value.locale(getLocale()).format("MMM");
|
|
2590
|
+
}
|
|
2591
|
+
else {
|
|
2592
|
+
return "";
|
|
2593
|
+
}
|
|
2594
|
+
}
|
|
2595
|
+
/**
|
|
2596
|
+
* Get the name of the day.
|
|
2597
|
+
*
|
|
2598
|
+
* ```
|
|
2599
|
+
* FDate.now().dayName// => Monday
|
|
2600
|
+
* ```
|
|
2601
|
+
*
|
|
2602
|
+
* @public
|
|
2603
|
+
*/
|
|
2604
|
+
get dayName() {
|
|
2605
|
+
if (this.isValid()) {
|
|
2606
|
+
return this.value.locale(getLocale()).format("dddd");
|
|
2607
|
+
}
|
|
2608
|
+
else {
|
|
2609
|
+
return "";
|
|
2610
|
+
}
|
|
2611
|
+
}
|
|
2612
|
+
/**
|
|
2613
|
+
* Get the short name of the day.
|
|
2614
|
+
*
|
|
2615
|
+
* ```
|
|
2616
|
+
* FDate.now().dayNameShort// => Mon
|
|
2617
|
+
* ```
|
|
2618
|
+
*
|
|
2619
|
+
* @public
|
|
2620
|
+
*/
|
|
2621
|
+
get dayNameShort() {
|
|
2622
|
+
if (this.isValid()) {
|
|
2623
|
+
return this.value.locale(getLocale()).format("ddd");
|
|
2624
|
+
}
|
|
2625
|
+
else {
|
|
2626
|
+
return "";
|
|
2627
|
+
}
|
|
2628
|
+
}
|
|
2629
|
+
/**
|
|
2630
|
+
* Get number of the day in a week.
|
|
2631
|
+
* Returns `Weekday` enum.
|
|
2632
|
+
* If date is invalid, `0` is returned.
|
|
2633
|
+
*
|
|
2634
|
+
* ```
|
|
2635
|
+
* FDate.now().weekDay// => Weekday.MONDAY / 1
|
|
2636
|
+
* ```
|
|
2637
|
+
*
|
|
2638
|
+
* @public
|
|
2639
|
+
*/
|
|
2640
|
+
get weekDay() {
|
|
2641
|
+
if (!this.isValid()) {
|
|
2642
|
+
return 0;
|
|
2643
|
+
}
|
|
2644
|
+
const result = parseInt(this.value.format("d"), 10);
|
|
2645
|
+
if (!result) {
|
|
2646
|
+
return Weekday.SUNDAY;
|
|
2647
|
+
}
|
|
2648
|
+
return result;
|
|
2649
|
+
}
|
|
2650
|
+
/**
|
|
2651
|
+
* This returns a `boolean` indicating whether the FDate object contains a valid date or not.
|
|
2652
|
+
*
|
|
2653
|
+
* ```
|
|
2654
|
+
* FDate().isValid()// => boolean
|
|
2655
|
+
* ```
|
|
2656
|
+
*
|
|
2657
|
+
* @public
|
|
2658
|
+
*/
|
|
2659
|
+
isValid() {
|
|
2660
|
+
return this.value.isValid();
|
|
2661
|
+
}
|
|
2662
|
+
/**
|
|
2663
|
+
* Returns a cloned {@link FDate} object and set it to the start of month.
|
|
2664
|
+
*
|
|
2665
|
+
* @public
|
|
2666
|
+
*/
|
|
2667
|
+
startOfMonth() {
|
|
2668
|
+
return new FDate(this.value.startOf("month"));
|
|
2669
|
+
}
|
|
2670
|
+
/**
|
|
2671
|
+
* Returns a cloned {@link FDate} object and set it to the end of month.
|
|
2672
|
+
*
|
|
2673
|
+
* @public
|
|
2674
|
+
*/
|
|
2675
|
+
endOfMonth() {
|
|
2676
|
+
return new FDate(this.value.endOf("month"));
|
|
2677
|
+
}
|
|
2678
|
+
/**
|
|
2679
|
+
* Returns a new {@link FDate} object with a specified amount of days added.
|
|
2680
|
+
* Specify a negative amount in order to subtract days.
|
|
2681
|
+
*
|
|
2682
|
+
* ```
|
|
2683
|
+
* FDate().addDays(7)// => FDate
|
|
2684
|
+
* ```
|
|
2685
|
+
*
|
|
2686
|
+
* @public
|
|
2687
|
+
*/
|
|
2688
|
+
addDays(value) {
|
|
2689
|
+
return new FDate(this.value.add(value, "day"));
|
|
2690
|
+
}
|
|
2691
|
+
/**
|
|
2692
|
+
* Returns a cloned {@link FDate} object with a specified amount of months added.
|
|
2693
|
+
* Specify a negative amount in order to subtract months.
|
|
2694
|
+
*
|
|
2695
|
+
* ```
|
|
2696
|
+
* FDate().addMonths(7)// => FDate
|
|
2697
|
+
* ```
|
|
2698
|
+
*
|
|
2699
|
+
* @public
|
|
2700
|
+
*/
|
|
2701
|
+
addMonths(value) {
|
|
2702
|
+
return new FDate(this.value.add(value, "month"));
|
|
2703
|
+
}
|
|
2704
|
+
/**
|
|
2705
|
+
* Returns a new {@link FDate} object with a specified amount of years added.
|
|
2706
|
+
* Specify a negative amount in order to subtract years.
|
|
2707
|
+
*
|
|
2708
|
+
* ```
|
|
2709
|
+
* FDate().addYears(7)// => FDate
|
|
2710
|
+
* ```
|
|
2711
|
+
*
|
|
2712
|
+
* @public
|
|
2713
|
+
*/
|
|
2714
|
+
addYears(value) {
|
|
2715
|
+
return new FDate(this.value.add(value, "year"));
|
|
2716
|
+
}
|
|
2717
|
+
next() {
|
|
2718
|
+
return this.addDays(1);
|
|
2719
|
+
}
|
|
2720
|
+
/**
|
|
2721
|
+
* Compares two {@link FDate} objects and returns `true` if they represent the
|
|
2722
|
+
* same date.
|
|
2723
|
+
*
|
|
2724
|
+
* Invalid dates always returns `false`.
|
|
2725
|
+
*
|
|
2726
|
+
* @public
|
|
2727
|
+
* @param rhs - The date to compare with.
|
|
2728
|
+
* @returns `true` if the dates represent the same date.
|
|
2729
|
+
*/
|
|
2730
|
+
equals(rhs) {
|
|
2731
|
+
if (typeof rhs === "string") {
|
|
2732
|
+
rhs = FDate.fromIso(rhs);
|
|
2733
|
+
}
|
|
2734
|
+
return this.value.isSame(rhs.value, "day");
|
|
2735
|
+
}
|
|
2736
|
+
/**
|
|
2737
|
+
* Returns true if this date is before given date.
|
|
2738
|
+
*
|
|
2739
|
+
* If the dates are the same this function returns false.
|
|
2740
|
+
*/
|
|
2741
|
+
isBefore(rhs) {
|
|
2742
|
+
if (typeof rhs === "string") {
|
|
2743
|
+
rhs = FDate.fromIso(rhs);
|
|
2744
|
+
}
|
|
2745
|
+
return this.value.isBefore(rhs.value);
|
|
2746
|
+
}
|
|
2747
|
+
/**
|
|
2748
|
+
* Returns true if this date is after given date.
|
|
2749
|
+
*
|
|
2750
|
+
* If the dates are the same this function returns false.
|
|
2751
|
+
*/
|
|
2752
|
+
isAfter(rhs) {
|
|
2753
|
+
if (typeof rhs === "string") {
|
|
2754
|
+
rhs = FDate.fromIso(rhs);
|
|
2755
|
+
}
|
|
2756
|
+
return this.value.isAfter(rhs.value);
|
|
2757
|
+
}
|
|
2758
|
+
/**
|
|
2759
|
+
* Compares two {@link FDate} objects. Returns and integer indicating whenever
|
|
2760
|
+
* `a` comes before or after or is equal to `b`.
|
|
2761
|
+
*
|
|
2762
|
+
* - `-1` if `a` beomes before `b`.
|
|
2763
|
+
* - `0` if `a` and `b` are the same date.
|
|
2764
|
+
* - `1` if `a` beomes after `b`.
|
|
2765
|
+
*
|
|
2766
|
+
* If either or both date is invalid the result is undefined behaviour and
|
|
2767
|
+
* should not be relied on. Use {@link FDate.isValid} to ensure validity
|
|
2768
|
+
* first, e.g. `myArray.filter(it => it.isValid())` before sorting.
|
|
2769
|
+
*
|
|
2770
|
+
* @public
|
|
2771
|
+
* @param a - First date object to compare.
|
|
2772
|
+
* @param b - Second date object to compare.
|
|
2773
|
+
* @returns `-1`, `0` or `1`
|
|
2774
|
+
*/
|
|
2775
|
+
static compare(a, b) {
|
|
2776
|
+
if (typeof a === "string") {
|
|
2777
|
+
a = FDate.fromIso(a);
|
|
2778
|
+
}
|
|
2779
|
+
if (typeof b === "string") {
|
|
2780
|
+
b = FDate.fromIso(b);
|
|
2781
|
+
}
|
|
2782
|
+
const aInvalid = !a.isValid();
|
|
2783
|
+
const bInvalid = !b.isValid();
|
|
2784
|
+
if (aInvalid || bInvalid) {
|
|
2785
|
+
if (aInvalid && bInvalid) {
|
|
2786
|
+
return 0;
|
|
2787
|
+
}
|
|
2788
|
+
else if (aInvalid) {
|
|
2789
|
+
return 1;
|
|
2790
|
+
}
|
|
2791
|
+
else {
|
|
2792
|
+
return -1;
|
|
2793
|
+
}
|
|
2794
|
+
}
|
|
2795
|
+
if (a.value.isSame(b.value)) {
|
|
2796
|
+
return 0;
|
|
2797
|
+
}
|
|
2798
|
+
else if (a.value.isBefore(b.value)) {
|
|
2799
|
+
return -1;
|
|
2800
|
+
}
|
|
2801
|
+
else {
|
|
2802
|
+
return 1;
|
|
2803
|
+
}
|
|
2804
|
+
}
|
|
2805
|
+
/**
|
|
2806
|
+
* Returns a string representation of the date.
|
|
2807
|
+
*
|
|
2808
|
+
* ```
|
|
2809
|
+
* FDate().toString() // "2022-05-04"
|
|
2810
|
+
* FDate().toString(DateFormat.FULL) // "onsdag 4 maj 2022"
|
|
2811
|
+
* FDate().toString(DateFormat.LONG) // "4 maj 2022"
|
|
2812
|
+
* FDate().toString(DateFormat.ISO8601) // "2022-04-20"
|
|
2813
|
+
* ```
|
|
2814
|
+
*
|
|
2815
|
+
* @public
|
|
2816
|
+
* @param format - Format to use.
|
|
2817
|
+
*/
|
|
2818
|
+
toString(format = DateFormat.ISO8601) {
|
|
2819
|
+
if (this.isValid()) {
|
|
2820
|
+
const template = formatter[getLocale()][format];
|
|
2821
|
+
return this.value.locale(getLocale()).format(template);
|
|
2822
|
+
}
|
|
2823
|
+
else {
|
|
2824
|
+
return "";
|
|
2825
|
+
}
|
|
2826
|
+
}
|
|
2827
|
+
/**
|
|
2828
|
+
* To serialize as an ISO8601 string.
|
|
2829
|
+
*
|
|
2830
|
+
* ```
|
|
2831
|
+
* FDate().toJSON() // "2019-01-25"
|
|
2832
|
+
* ```
|
|
2833
|
+
*
|
|
2834
|
+
* @public
|
|
2835
|
+
*/
|
|
2836
|
+
toJSON() {
|
|
2837
|
+
return this.toString(DateFormat.ISO8601);
|
|
2838
|
+
}
|
|
2839
|
+
}
|
|
2840
|
+
|
|
2841
|
+
/**
|
|
2842
|
+
* @public
|
|
2843
|
+
*/
|
|
2844
|
+
function parseDate(value) {
|
|
2845
|
+
if (isEmpty(value)) {
|
|
2846
|
+
return undefined;
|
|
2847
|
+
}
|
|
2848
|
+
const normalized = normalizeDateFormat(value);
|
|
2849
|
+
if (!normalized) {
|
|
2850
|
+
return undefined;
|
|
2851
|
+
}
|
|
2852
|
+
const date = FDate.fromIso(normalized);
|
|
2853
|
+
if (date.isValid()) {
|
|
2854
|
+
return date.toString();
|
|
2855
|
+
}
|
|
2856
|
+
else {
|
|
2857
|
+
return undefined;
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
|
|
2861
|
+
/**
|
|
2862
|
+
* Strips all whitespace from the text (not only leading and trailing)
|
|
2863
|
+
*
|
|
2864
|
+
* @public
|
|
2865
|
+
* @param text - Text to strip whitespace from.
|
|
2866
|
+
* @returns Text with whitespace stripped.
|
|
2867
|
+
*/
|
|
2868
|
+
function stripWhitespace(text) {
|
|
2869
|
+
return text.replace(/\s+/g, "");
|
|
2870
|
+
}
|
|
2871
|
+
|
|
2872
|
+
const NUMBER_REGEXP$1 = /^([-]?[0-9]+)([,.][0-9]+)?$/;
|
|
2873
|
+
function replaceCommaWithDot(str) {
|
|
2874
|
+
return str.replace(",", ".");
|
|
2875
|
+
}
|
|
2876
|
+
function replaceMinusSignWithDash(str) {
|
|
2877
|
+
return str.replace("−", "-");
|
|
2878
|
+
}
|
|
2879
|
+
function replaceDotWithComma(str) {
|
|
2880
|
+
return str.replace(".", ",");
|
|
2881
|
+
}
|
|
2882
|
+
function formatSwedishNotation(value, decimals) {
|
|
2883
|
+
if (decimals !== undefined) {
|
|
2884
|
+
// round
|
|
2885
|
+
value = Number(value.toFixed(decimals));
|
|
2886
|
+
}
|
|
2887
|
+
// Workaround, replace dot with comma. Node doesn't have swedish locale
|
|
2888
|
+
// installed as default. By having this workaround the applications
|
|
2889
|
+
// doesn't need to install full-icu & cross-env to get correct
|
|
2890
|
+
// formatting in jest tests.
|
|
2891
|
+
return replaceDotWithComma(value.toLocaleString("sv-SE", {
|
|
2892
|
+
minimumFractionDigits: decimals,
|
|
2893
|
+
}));
|
|
2894
|
+
}
|
|
2895
|
+
/**
|
|
2896
|
+
* Format number with thousand separator and use comma as decimal separator.
|
|
2897
|
+
*
|
|
2898
|
+
* @public
|
|
2899
|
+
*/
|
|
2900
|
+
function formatNumber(value, decimals) {
|
|
2901
|
+
if (typeof value === "string") {
|
|
2902
|
+
value = parseNumber(value) ?? "";
|
|
2903
|
+
}
|
|
2904
|
+
if (typeof value !== "number" || isNaN(value)) {
|
|
2905
|
+
return undefined;
|
|
2906
|
+
}
|
|
2907
|
+
return formatSwedishNotation(value, decimals);
|
|
2908
|
+
}
|
|
2909
|
+
/**
|
|
2910
|
+
* @public
|
|
2911
|
+
*/
|
|
2912
|
+
function parseNumber(value) {
|
|
2913
|
+
if (isEmpty(value)) {
|
|
2914
|
+
return undefined;
|
|
2915
|
+
}
|
|
2916
|
+
const stripped = stripWhitespace(value);
|
|
2917
|
+
const numberString = replaceCommaWithDot(replaceMinusSignWithDash(stripped));
|
|
2918
|
+
if (!NUMBER_REGEXP$1.test(numberString)) {
|
|
2919
|
+
return undefined;
|
|
2920
|
+
}
|
|
2921
|
+
const number = Number(numberString);
|
|
2922
|
+
return isNaN(number) ? undefined : number;
|
|
2923
|
+
}
|
|
2924
|
+
|
|
2925
|
+
function getNowDetails(now) {
|
|
2926
|
+
const nowIso = now.toString();
|
|
2927
|
+
return {
|
|
2928
|
+
nowCentury: nowIso.substring(0, 2),
|
|
2929
|
+
nowYear: nowIso.substring(2, 4),
|
|
2930
|
+
nowMonthDay: nowIso.substring(5, 7) + nowIso.substring(8, 10),
|
|
2931
|
+
};
|
|
2932
|
+
}
|
|
2933
|
+
/**
|
|
2934
|
+
* Resolves missing century.
|
|
2935
|
+
*
|
|
2936
|
+
* ```
|
|
2937
|
+
* getCentury("22", "01", "01", true, FDate.now()) // => "19"
|
|
2938
|
+
* ```
|
|
2939
|
+
*
|
|
2940
|
+
* @internal
|
|
2941
|
+
*/
|
|
2942
|
+
function resolveCentury(year, month, day, hasPlus, now) {
|
|
2943
|
+
const { nowCentury, nowYear, nowMonthDay } = getNowDetails(now);
|
|
2944
|
+
let subtractCenturies = 0;
|
|
2945
|
+
if (hasPlus) {
|
|
2946
|
+
subtractCenturies += 1;
|
|
2947
|
+
}
|
|
2948
|
+
if (year > nowYear ||
|
|
2949
|
+
(year === nowYear && !hasPlus && `${month}${day}` > nowMonthDay)) {
|
|
2950
|
+
subtractCenturies += 1;
|
|
2951
|
+
}
|
|
2952
|
+
return (Number(nowCentury) - subtractCenturies).toString();
|
|
2953
|
+
}
|
|
2954
|
+
|
|
2955
|
+
const PERSONNUMMER_REGEXP = /^(?<century>\d{2})?(?<year>\d{2})(?<month>\d{2})(?<day>\d{2})(?<sign>-|\+)?(?<check>\d{4})$/;
|
|
2956
|
+
function getDayWithoutSamordning(day) {
|
|
2957
|
+
return (Number(day) % 60).toString().padStart(2, "0");
|
|
2958
|
+
}
|
|
2959
|
+
function getPersonnummerString(century, year, month, day, check) {
|
|
2960
|
+
return `${century}${year}${month}${day}-${check}`;
|
|
2961
|
+
}
|
|
2962
|
+
/**
|
|
2963
|
+
* Checks if date is valid and within valid period.
|
|
2964
|
+
* The valid period is between 1840-05-06 (first registered personnummer) and today's date.
|
|
2965
|
+
*
|
|
2966
|
+
* @internal
|
|
2967
|
+
*/
|
|
2968
|
+
function isValidDate(date, now) {
|
|
2969
|
+
if (!date.isValid() || date.isBefore("1840-05-06") || date.isAfter(now)) {
|
|
2970
|
+
return false;
|
|
2971
|
+
}
|
|
2972
|
+
return true;
|
|
2973
|
+
}
|
|
2974
|
+
/**
|
|
2975
|
+
* Parses 10- and 12-digit personnummers.
|
|
2976
|
+
*
|
|
2977
|
+
* @public
|
|
2978
|
+
*/
|
|
2979
|
+
function parsePersonnummer(value, now = FDate.now()) {
|
|
2980
|
+
if (!isSet(value)) {
|
|
2981
|
+
return undefined;
|
|
2982
|
+
}
|
|
2983
|
+
const match = stripWhitespace(value).match(PERSONNUMMER_REGEXP);
|
|
2984
|
+
if (!match) {
|
|
2985
|
+
return undefined;
|
|
2986
|
+
}
|
|
2987
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- expected
|
|
2988
|
+
const { year, month, day, sign, check } = match.groups;
|
|
2989
|
+
const dayWithoutSamordning = getDayWithoutSamordning(day);
|
|
2990
|
+
const century = match.groups?.century ??
|
|
2991
|
+
resolveCentury(year, month, dayWithoutSamordning, sign === "+", now);
|
|
2992
|
+
// consider date as valid when samordningsnummer equals "60" (it means birthday is unknown)
|
|
2993
|
+
if (day === "60") {
|
|
2994
|
+
return getPersonnummerString(century, year, month, day, check);
|
|
2995
|
+
}
|
|
2996
|
+
const date = FDate.fromYearMonthDay(century + year, month, dayWithoutSamordning);
|
|
2997
|
+
if (!isValidDate(date, now)) {
|
|
2998
|
+
return undefined;
|
|
2999
|
+
}
|
|
3000
|
+
return getPersonnummerString(century, year, month, day, check);
|
|
3001
|
+
}
|
|
3002
|
+
/**
|
|
3003
|
+
* Parses 10- and 12-digit personnummers with Luhn validation.
|
|
3004
|
+
*
|
|
3005
|
+
* @public
|
|
3006
|
+
*/
|
|
3007
|
+
function parsePersonnummerLuhn(value) {
|
|
3008
|
+
const parsed = parsePersonnummer(value);
|
|
3009
|
+
if (!parsed) {
|
|
3010
|
+
return undefined;
|
|
3011
|
+
}
|
|
3012
|
+
if (!validChecksum(parsed)) {
|
|
3013
|
+
return undefined;
|
|
3014
|
+
}
|
|
3015
|
+
return parsed;
|
|
3016
|
+
}
|
|
3017
|
+
/**
|
|
3018
|
+
* Formats personnummer to a 10-digit string.
|
|
3019
|
+
*
|
|
3020
|
+
* @public
|
|
3021
|
+
*/
|
|
3022
|
+
function formatPersonnummer(value) {
|
|
3023
|
+
if (!isSet(value)) {
|
|
3024
|
+
return undefined;
|
|
3025
|
+
}
|
|
3026
|
+
const currentYear = FDate.now().year;
|
|
3027
|
+
const year = Number(value.substring(0, 4));
|
|
3028
|
+
if (currentYear - year >= 100) {
|
|
3029
|
+
return value.substring(2).replace("-", "+");
|
|
3030
|
+
}
|
|
3031
|
+
return value.substring(2);
|
|
3032
|
+
}
|
|
3033
|
+
|
|
3034
|
+
const PLUSGIRO_REGEXP = /^\d{1,7}[-]?\d{1}$/;
|
|
3035
|
+
function hyphenShouldBeAdded(value) {
|
|
3036
|
+
return value.length >= 2 && value.length <= 8;
|
|
3037
|
+
}
|
|
3038
|
+
/**
|
|
3039
|
+
* @public
|
|
3040
|
+
*/
|
|
3041
|
+
function parsePlusgiro(value) {
|
|
3042
|
+
if (isEmpty(value)) {
|
|
3043
|
+
return undefined;
|
|
3044
|
+
}
|
|
3045
|
+
/**
|
|
3046
|
+
* Add spaces between each pair of digits before the hyphen back-to-front.
|
|
3047
|
+
* If the number of digits is odd then the first pair in the string can be a single digit.
|
|
3048
|
+
* If the number of characters is 9, there will be a space after the first 3 characters.
|
|
3049
|
+
*/
|
|
3050
|
+
value = value.replace(/ /g, "");
|
|
3051
|
+
value = value.replace(/\D/g, "");
|
|
3052
|
+
if (!PLUSGIRO_REGEXP.test(value) ||
|
|
3053
|
+
!testLuhnChecksum(value.replace(/\D/g, ""))) {
|
|
3054
|
+
return undefined;
|
|
3055
|
+
}
|
|
3056
|
+
if (hyphenShouldBeAdded(value)) {
|
|
3057
|
+
value = `${value.substring(0, value.length - 1)}-${value[value.length - 1]}`;
|
|
3058
|
+
}
|
|
3059
|
+
const startOffset = 4;
|
|
3060
|
+
let formattedString = value.substring(value.length - startOffset, value.length);
|
|
3061
|
+
const step = 2;
|
|
3062
|
+
for (let i = value.length - startOffset; i >= (value.length === 9 ? 3 : 1); i -= step) {
|
|
3063
|
+
formattedString = `${value.substring(Math.max(i - step, 0), i)} ${formattedString}`;
|
|
3064
|
+
}
|
|
3065
|
+
if (value.length === 9) {
|
|
3066
|
+
formattedString = value.substring(0, 1) + formattedString;
|
|
3067
|
+
}
|
|
3068
|
+
return formattedString;
|
|
3069
|
+
}
|
|
3070
|
+
|
|
3071
|
+
/**
|
|
3072
|
+
* @internal
|
|
3073
|
+
*/
|
|
3074
|
+
const POSTAL_CODE_REGEXP = /^([1-9]{1}\d{2}) ?(\d{2})$/;
|
|
3075
|
+
/**
|
|
3076
|
+
* @public
|
|
3077
|
+
*/
|
|
3078
|
+
function formatPostalCode(value) {
|
|
3079
|
+
if (isEmpty(value)) {
|
|
3080
|
+
return undefined;
|
|
3081
|
+
}
|
|
3082
|
+
const match = value.match(POSTAL_CODE_REGEXP);
|
|
3083
|
+
if (match === null) {
|
|
3084
|
+
return undefined;
|
|
3085
|
+
}
|
|
3086
|
+
return `${match[1]} ${match[2]}`;
|
|
3087
|
+
}
|
|
3088
|
+
/**
|
|
3089
|
+
* @public
|
|
3090
|
+
*/
|
|
3091
|
+
function parsePostalCode(value) {
|
|
3092
|
+
return formatPostalCode(value);
|
|
3093
|
+
}
|
|
3094
|
+
|
|
3095
|
+
const ORGANISATIONSNUMMER_REGEXP = /^([0-9]{6})-?([0-9]{4})$/;
|
|
3096
|
+
/**
|
|
3097
|
+
* @public
|
|
3098
|
+
*/
|
|
3099
|
+
function parseOrganisationsnummer(value) {
|
|
3100
|
+
if (isEmpty(value)) {
|
|
3101
|
+
return undefined;
|
|
3102
|
+
}
|
|
3103
|
+
const match = value.match(ORGANISATIONSNUMMER_REGEXP);
|
|
3104
|
+
if (!match) {
|
|
3105
|
+
return undefined;
|
|
3106
|
+
}
|
|
3107
|
+
if (!testLuhnChecksum(`${match[1]}${match[2]}`)) {
|
|
3108
|
+
return undefined;
|
|
3109
|
+
}
|
|
3110
|
+
return `${match[1]}-${match[2]}`;
|
|
3111
|
+
}
|
|
3112
|
+
|
|
3113
|
+
/**
|
|
3114
|
+
* @public
|
|
3115
|
+
*/
|
|
3116
|
+
function formatPercent(modelValue, decimals) {
|
|
3117
|
+
return formatNumber(modelValue, decimals);
|
|
3118
|
+
}
|
|
3119
|
+
/**
|
|
3120
|
+
* @public
|
|
3121
|
+
*/
|
|
3122
|
+
function parsePercent(viewValue) {
|
|
3123
|
+
return parseNumber(viewValue);
|
|
3124
|
+
}
|
|
3125
|
+
|
|
3126
|
+
/**
|
|
3127
|
+
* Add a listener to each item in the list of elements
|
|
3128
|
+
*
|
|
3129
|
+
* @public
|
|
3130
|
+
*/
|
|
3131
|
+
function addFocusListener(elements, listener) {
|
|
3132
|
+
for (const element of elements) {
|
|
3133
|
+
element.addEventListener("focus", listener);
|
|
3134
|
+
}
|
|
3135
|
+
}
|
|
3136
|
+
|
|
3137
|
+
/**
|
|
3138
|
+
* Compares the position of the given node against another node in any document.
|
|
3139
|
+
*
|
|
3140
|
+
* Unset elements (e.g. `null`) are undefined behaviour but the current
|
|
3141
|
+
* non-contractural behaviour is to put them at the end of the sorted
|
|
3142
|
+
* array. The caller should ensure those elements are removed before sorting.
|
|
3143
|
+
*
|
|
3144
|
+
* @example
|
|
3145
|
+
* ```ts
|
|
3146
|
+
* const sorted = listOfElements.sort(documentOrderComparator);
|
|
3147
|
+
* ```
|
|
3148
|
+
*
|
|
3149
|
+
* @public
|
|
3150
|
+
*/
|
|
3151
|
+
function documentOrderComparator(a, b) {
|
|
3152
|
+
if (!a) {
|
|
3153
|
+
return 1;
|
|
3154
|
+
}
|
|
3155
|
+
if (!b) {
|
|
3156
|
+
return -1;
|
|
3157
|
+
}
|
|
3158
|
+
const BITMASK = Node.DOCUMENT_POSITION_DISCONNECTED | Node.DOCUMENT_POSITION_PRECEDING;
|
|
3159
|
+
const result = a.compareDocumentPosition(b) & BITMASK;
|
|
3160
|
+
/* After the bitmask result can only have three distinct values:
|
|
3161
|
+
*
|
|
3162
|
+
* Result Comparator Description
|
|
3163
|
+
* ------ ---------- -----------
|
|
3164
|
+
* 0 -1 A follow B
|
|
3165
|
+
* 1 0 Disconnected
|
|
3166
|
+
* 2 1 A preceed B
|
|
3167
|
+
*
|
|
3168
|
+
* Given above table we can compute final comparator value by subtracting 1.
|
|
3169
|
+
*/
|
|
3170
|
+
return result - 1;
|
|
3171
|
+
}
|
|
3172
|
+
|
|
3173
|
+
/**
|
|
3174
|
+
* Check if an element is visible in the dom
|
|
3175
|
+
*
|
|
3176
|
+
* @public
|
|
3177
|
+
*/
|
|
3178
|
+
function isVisible(element) {
|
|
3179
|
+
return Boolean(element.offsetWidth ||
|
|
3180
|
+
element.offsetHeight ||
|
|
3181
|
+
element.getClientRects().length);
|
|
3182
|
+
}
|
|
3183
|
+
|
|
3184
|
+
const FRAMERATE = 60;
|
|
3185
|
+
function easeInEaseOut(a, b, s) {
|
|
3186
|
+
return a + ((b - a) * (1 + Math.cos(Math.PI + s * Math.PI))) / 2;
|
|
3187
|
+
}
|
|
3188
|
+
function elementTop(element) {
|
|
3189
|
+
const rect = element.getBoundingClientRect();
|
|
3190
|
+
const scrollTop = window.pageYOffset;
|
|
3191
|
+
const clientTop = document.documentElement.clientTop;
|
|
3192
|
+
return rect.top + scrollTop - clientTop;
|
|
3193
|
+
}
|
|
3194
|
+
function scrollTo(element, arg = 0) {
|
|
3195
|
+
if (typeof arg === "number") {
|
|
3196
|
+
const offset = arg;
|
|
3197
|
+
const bodyRect = document.body.getBoundingClientRect();
|
|
3198
|
+
const elemRect = element.getBoundingClientRect();
|
|
3199
|
+
const scroll = elemRect.top - bodyRect.top - offset;
|
|
3200
|
+
window.scrollTo({ top: scroll, behavior: "smooth" });
|
|
3201
|
+
return Promise.resolve();
|
|
3202
|
+
}
|
|
3203
|
+
else {
|
|
3204
|
+
return scrollToSlow(element, arg.duration || 500, arg.offset || 0);
|
|
3205
|
+
}
|
|
3206
|
+
}
|
|
3207
|
+
/**
|
|
3208
|
+
* Scroll to element with given duration
|
|
3209
|
+
*
|
|
3210
|
+
* @param element - Element to scroll into view
|
|
3211
|
+
* @param duration - Duration in milliseconds
|
|
3212
|
+
* @param offset - Set vertical offset, default 0px
|
|
3213
|
+
*/
|
|
3214
|
+
function scrollToSlow(element, duration, offset = 0) {
|
|
3215
|
+
const steps = (duration / 1000) * FRAMERATE;
|
|
3216
|
+
const interval = duration / steps;
|
|
3217
|
+
const target = elementTop(element) - offset;
|
|
3218
|
+
const scrollRange = target - window.pageYOffset;
|
|
3219
|
+
function tween(s) {
|
|
3220
|
+
return target - easeInEaseOut(scrollRange, 0, s);
|
|
3221
|
+
}
|
|
3222
|
+
return new Promise((resolve) => {
|
|
3223
|
+
let stepsLeft = steps;
|
|
3224
|
+
const requestAnimationFrame = setInterval(() => {
|
|
3225
|
+
if (stepsLeft-- > 0) {
|
|
3226
|
+
const s = 1 - stepsLeft / steps;
|
|
3227
|
+
const top = tween(s);
|
|
3228
|
+
window.scrollTo({ top, left: 0 });
|
|
3229
|
+
}
|
|
3230
|
+
else {
|
|
3231
|
+
clearInterval(requestAnimationFrame);
|
|
3232
|
+
resolve();
|
|
3233
|
+
}
|
|
3234
|
+
}, interval);
|
|
3235
|
+
});
|
|
3236
|
+
}
|
|
3237
|
+
|
|
3238
|
+
const sym = Symbol("focus-stack");
|
|
3239
|
+
let _stackHandleCounter = 0;
|
|
3240
|
+
const _focusElementStack = [];
|
|
3241
|
+
const TABBABLE_ELEMENT_SELECTOR = [
|
|
3242
|
+
"a[href]",
|
|
3243
|
+
"area[href]",
|
|
3244
|
+
"input",
|
|
3245
|
+
"select",
|
|
3246
|
+
"textarea",
|
|
3247
|
+
"button",
|
|
3248
|
+
"iframe",
|
|
3249
|
+
"object",
|
|
3250
|
+
"embed",
|
|
3251
|
+
"*[contenteditable]",
|
|
3252
|
+
'*[tabindex]:not([tabindex="-1"])',
|
|
3253
|
+
].join(", ");
|
|
3254
|
+
function isHTMLElement(element) {
|
|
3255
|
+
return Boolean(element && element instanceof HTMLElement);
|
|
3256
|
+
}
|
|
3257
|
+
/**
|
|
3258
|
+
* Give focus to a given element.
|
|
3259
|
+
*
|
|
3260
|
+
* For convenience it will ignore `null` and `undefined` as element parameter.
|
|
3261
|
+
*
|
|
3262
|
+
* If in a Vue context, please refer to the `focus` method included in `@fkui/vue`.
|
|
3263
|
+
*
|
|
3264
|
+
* @public
|
|
3265
|
+
* @param element - Element to focus.
|
|
3266
|
+
* @param options - Focus options. If you pass boolean `true` or `false` it sets the `force` option.
|
|
3267
|
+
*/
|
|
3268
|
+
function focus(element, options = {}) {
|
|
3269
|
+
if (typeof options === "boolean") {
|
|
3270
|
+
options = { force: options };
|
|
3271
|
+
}
|
|
3272
|
+
if (isHTMLElement(element)) {
|
|
3273
|
+
if (options.force && !isFocusable(element)) {
|
|
3274
|
+
element.setAttribute("tabindex", "-1");
|
|
3275
|
+
}
|
|
3276
|
+
const { force, scrollToTop, ...params } = options;
|
|
3277
|
+
element.focus(params);
|
|
3278
|
+
if (scrollToTop) {
|
|
3279
|
+
element.focus({ ...params, preventScroll: true });
|
|
3280
|
+
scrollTo(element);
|
|
3281
|
+
}
|
|
3282
|
+
else {
|
|
3283
|
+
element.focus(params);
|
|
3284
|
+
}
|
|
3285
|
+
}
|
|
3286
|
+
}
|
|
3287
|
+
/**
|
|
3288
|
+
* Check if an element is focusable (visible and either interactive or with
|
|
3289
|
+
* tabindex). This includes programatically focusable elements.
|
|
3290
|
+
*
|
|
3291
|
+
* @public
|
|
3292
|
+
* @param element - An `Element` for which to test focusability.
|
|
3293
|
+
* @returns `true` if the element is focusable, otherwise `false`.
|
|
3294
|
+
*/
|
|
3295
|
+
function isFocusable(element) {
|
|
3296
|
+
const visible = element instanceof HTMLElement ? isVisible(element) : false;
|
|
3297
|
+
return (isTabbable(element) || (visible && element.matches('*[tabindex="-1"]')));
|
|
3298
|
+
}
|
|
3299
|
+
/**
|
|
3300
|
+
* Check if an element is disabled.
|
|
3301
|
+
*
|
|
3302
|
+
* @public
|
|
3303
|
+
* @param element - An `Element`to test disabled.
|
|
3304
|
+
* @returns `true`if the element is disabled.
|
|
3305
|
+
*
|
|
3306
|
+
*/
|
|
3307
|
+
function isDisabled(element) {
|
|
3308
|
+
return Boolean(element.disabled);
|
|
3309
|
+
}
|
|
3310
|
+
/**
|
|
3311
|
+
* Check if an element is tabbable (visible and either interactive or
|
|
3312
|
+
* non-negative tabindex). This does not include programatically focusable
|
|
3313
|
+
* elements.
|
|
3314
|
+
*
|
|
3315
|
+
* @public
|
|
3316
|
+
* @param element - An `Element` for which to test focusability.
|
|
3317
|
+
* @returns `true` if the element is focusable, otherwise `false`.
|
|
3318
|
+
*/
|
|
3319
|
+
function isTabbable(element) {
|
|
3320
|
+
const tabindexAttr = element instanceof HTMLElement ? element.tabIndex : 0;
|
|
3321
|
+
const visible = element instanceof HTMLElement ? isVisible(element) : false;
|
|
3322
|
+
return (!isDisabled(element) &&
|
|
3323
|
+
tabindexAttr !== -1 &&
|
|
3324
|
+
visible &&
|
|
3325
|
+
element.matches(TABBABLE_ELEMENT_SELECTOR));
|
|
3326
|
+
}
|
|
3327
|
+
/**
|
|
3328
|
+
* Find all visible and tabbable elements.
|
|
3329
|
+
*
|
|
3330
|
+
* @public
|
|
3331
|
+
* @param root - Element or document to find tabbable elements in.
|
|
3332
|
+
* @returns List of matching elements
|
|
3333
|
+
*/
|
|
3334
|
+
function findTabbableElements(root) {
|
|
3335
|
+
const selector = TABBABLE_ELEMENT_SELECTOR;
|
|
3336
|
+
const nodes = root.querySelectorAll(selector);
|
|
3337
|
+
return Array.from(nodes).filter(isTabbable);
|
|
3338
|
+
}
|
|
3339
|
+
/**
|
|
3340
|
+
* Focus first focusable element among given root element's hierarchy.
|
|
3341
|
+
*
|
|
3342
|
+
* @public
|
|
3343
|
+
* @param rootElement - Root element.
|
|
3344
|
+
*/
|
|
3345
|
+
function focusFirst(rootElement) {
|
|
3346
|
+
const element = findTabbableElements(rootElement).shift();
|
|
3347
|
+
if (element) {
|
|
3348
|
+
focus(element);
|
|
3349
|
+
}
|
|
3350
|
+
}
|
|
3351
|
+
/**
|
|
3352
|
+
* Focus last focusable element among given root element's hierarchy.
|
|
3353
|
+
*
|
|
3354
|
+
* @public
|
|
3355
|
+
* @param rootElement - Root element.
|
|
3356
|
+
*/
|
|
3357
|
+
function focusLast(rootElement) {
|
|
3358
|
+
const element = findTabbableElements(rootElement).pop();
|
|
3359
|
+
if (element) {
|
|
3360
|
+
focus(element);
|
|
3361
|
+
}
|
|
3362
|
+
}
|
|
3363
|
+
/**
|
|
3364
|
+
* Restore focus to a previous element. Use this in combination with {@link saveFocus}
|
|
3365
|
+
*
|
|
3366
|
+
* @public
|
|
3367
|
+
*/
|
|
3368
|
+
function restoreFocus() {
|
|
3369
|
+
try {
|
|
3370
|
+
forcePopFocus();
|
|
3371
|
+
}
|
|
3372
|
+
catch {
|
|
3373
|
+
/* do nothing */
|
|
3374
|
+
}
|
|
3375
|
+
}
|
|
3376
|
+
/**
|
|
3377
|
+
* Save a DOM reference to the active element for later use.
|
|
3378
|
+
*
|
|
3379
|
+
* @public
|
|
3380
|
+
* @param document - Document element
|
|
3381
|
+
*/
|
|
3382
|
+
function saveFocus(document) {
|
|
3383
|
+
if (document.activeElement instanceof HTMLElement) {
|
|
3384
|
+
pushFocus();
|
|
3385
|
+
}
|
|
3386
|
+
}
|
|
3387
|
+
/**
|
|
3388
|
+
* Save current active element focus on the stack and set focus on element
|
|
3389
|
+
*
|
|
3390
|
+
* @public
|
|
3391
|
+
* @param element - The element to set focus on
|
|
3392
|
+
*/
|
|
3393
|
+
function pushFocus(element) {
|
|
3394
|
+
const stackFrame = {
|
|
3395
|
+
id: _stackHandleCounter++,
|
|
3396
|
+
element: document.activeElement,
|
|
3397
|
+
};
|
|
3398
|
+
_focusElementStack.push(stackFrame);
|
|
3399
|
+
focus(element);
|
|
3400
|
+
return { [sym]: stackFrame.id };
|
|
3401
|
+
}
|
|
3402
|
+
/**
|
|
3403
|
+
* Restore the focus on the last element from the stack
|
|
3404
|
+
*
|
|
3405
|
+
* @public
|
|
3406
|
+
* @throws Error when pop is called on an empty focus stack
|
|
3407
|
+
* @throws Error when pop is called without a valid StackHandle
|
|
3408
|
+
*/
|
|
3409
|
+
function popFocus(handle) {
|
|
3410
|
+
if (_focusElementStack.length === 0) {
|
|
3411
|
+
const emptyStackErrorMsg = "Can not call pop on an empty focus stack";
|
|
3412
|
+
if (configLogic.production) {
|
|
3413
|
+
// eslint-disable-next-line no-console -- expected to log
|
|
3414
|
+
console.error(emptyStackErrorMsg);
|
|
3415
|
+
return;
|
|
3416
|
+
}
|
|
3417
|
+
else {
|
|
3418
|
+
throw new Error(emptyStackErrorMsg);
|
|
3419
|
+
}
|
|
3420
|
+
}
|
|
3421
|
+
const top = _focusElementStack.pop();
|
|
3422
|
+
if (top?.id !== handle[sym]) {
|
|
3423
|
+
const outOfOrderErrorMsg = `push/pop called out-of-order. Expected stack handle id: ${top?.id} but got ${handle[sym]}`;
|
|
3424
|
+
if (configLogic.production) {
|
|
3425
|
+
// eslint-disable-next-line no-console -- expected to log
|
|
3426
|
+
console.error(outOfOrderErrorMsg);
|
|
3427
|
+
return;
|
|
3428
|
+
}
|
|
3429
|
+
else {
|
|
3430
|
+
throw new Error(outOfOrderErrorMsg);
|
|
3431
|
+
}
|
|
3432
|
+
}
|
|
3433
|
+
focus(top?.element);
|
|
3434
|
+
}
|
|
3435
|
+
/**
|
|
3436
|
+
* Restore the focus on the last element from the stack
|
|
3437
|
+
* Prefer `popFocus(handle: StackHandle)`
|
|
3438
|
+
*
|
|
3439
|
+
* @internal
|
|
3440
|
+
*/
|
|
3441
|
+
function forcePopFocus() {
|
|
3442
|
+
if (_focusElementStack.length === 0) {
|
|
3443
|
+
throw new Error("Can not call pop on an empty focus stack");
|
|
3444
|
+
}
|
|
3445
|
+
const top = _focusElementStack.pop();
|
|
3446
|
+
focus(top?.element);
|
|
3447
|
+
}
|
|
3448
|
+
|
|
3449
|
+
/**
|
|
3450
|
+
* Handle tab focus between given containers focusable elements
|
|
3451
|
+
*
|
|
3452
|
+
* @public
|
|
3453
|
+
* @param event - tab KeyboardEvent
|
|
3454
|
+
* @param container - containing focusable elements
|
|
3455
|
+
*/
|
|
3456
|
+
function handleTab(event, container) {
|
|
3457
|
+
const elements = findTabbableElements(container);
|
|
3458
|
+
let targetIndex = elements.indexOf(event.target);
|
|
3459
|
+
if (event.shiftKey) {
|
|
3460
|
+
targetIndex--;
|
|
3461
|
+
}
|
|
3462
|
+
else {
|
|
3463
|
+
targetIndex++;
|
|
3464
|
+
}
|
|
3465
|
+
if (targetIndex < 0) {
|
|
3466
|
+
targetIndex = elements.length - 1;
|
|
3467
|
+
}
|
|
3468
|
+
else if (targetIndex >= elements.length) {
|
|
3469
|
+
targetIndex = 0;
|
|
3470
|
+
}
|
|
3471
|
+
focus(elements[targetIndex]);
|
|
3472
|
+
event.preventDefault();
|
|
3473
|
+
}
|
|
3474
|
+
|
|
3475
|
+
/**
|
|
3476
|
+
* Check if element is of type radiobutton or checkbox
|
|
3477
|
+
*
|
|
3478
|
+
* @public
|
|
3479
|
+
*/
|
|
3480
|
+
function isRadiobuttonOrCheckbox(element) {
|
|
3481
|
+
return (element instanceof HTMLInputElement &&
|
|
3482
|
+
(element.type === "radio" || element.type === "checkbox"));
|
|
3483
|
+
}
|
|
3484
|
+
|
|
3485
|
+
/**
|
|
3486
|
+
* Check if element is a form element
|
|
3487
|
+
*
|
|
3488
|
+
* Also see {@link isValidatableHTMLElement} for a similar function but
|
|
3489
|
+
* including HTMLFieldSetElement.
|
|
3490
|
+
*
|
|
3491
|
+
* @public
|
|
3492
|
+
* @param element - Element to test
|
|
3493
|
+
*/
|
|
3494
|
+
function isValidatableFormElement(element) {
|
|
3495
|
+
return (element instanceof HTMLInputElement ||
|
|
3496
|
+
element instanceof HTMLSelectElement ||
|
|
3497
|
+
element instanceof HTMLTextAreaElement);
|
|
3498
|
+
}
|
|
3499
|
+
|
|
3500
|
+
/**
|
|
3501
|
+
* Check if an element is fully visible in the viewport
|
|
3502
|
+
*
|
|
3503
|
+
* @public
|
|
3504
|
+
*/
|
|
3505
|
+
function isVisibleInViewport(element) {
|
|
3506
|
+
const rect = element.getBoundingClientRect();
|
|
3507
|
+
return Boolean(rect.top >= 0 &&
|
|
3508
|
+
rect.left >= 0 &&
|
|
3509
|
+
rect.bottom <=
|
|
3510
|
+
(window.innerHeight || document.documentElement.clientHeight) &&
|
|
3511
|
+
rect.right <=
|
|
3512
|
+
(window.innerWidth || document.documentElement.clientWidth));
|
|
3513
|
+
}
|
|
3514
|
+
|
|
3515
|
+
/**
|
|
3516
|
+
* Remove listener for each item in the list of elements
|
|
3517
|
+
*
|
|
3518
|
+
* @public
|
|
3519
|
+
*/
|
|
3520
|
+
function removeFocusListener(elements, listener) {
|
|
3521
|
+
for (const element of elements) {
|
|
3522
|
+
element.removeEventListener("focus", listener);
|
|
3523
|
+
}
|
|
3524
|
+
}
|
|
3525
|
+
|
|
3526
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
3527
|
+
__proto__: null,
|
|
3528
|
+
addFocusListener: addFocusListener,
|
|
3529
|
+
documentOrderComparator: documentOrderComparator,
|
|
3530
|
+
findTabbableElements: findTabbableElements,
|
|
3531
|
+
focus: focus,
|
|
3532
|
+
focusFirst: focusFirst,
|
|
3533
|
+
focusLast: focusLast,
|
|
3534
|
+
handleTab: handleTab,
|
|
3535
|
+
isFocusable: isFocusable,
|
|
3536
|
+
isRadiobuttonOrCheckbox: isRadiobuttonOrCheckbox,
|
|
3537
|
+
isTabbable: isTabbable,
|
|
3538
|
+
isValidatableFormElement: isValidatableFormElement,
|
|
3539
|
+
isVisible: isVisible,
|
|
3540
|
+
isVisibleInViewport: isVisibleInViewport,
|
|
3541
|
+
popFocus: popFocus,
|
|
3542
|
+
pushFocus: pushFocus,
|
|
3543
|
+
removeFocusListener: removeFocusListener,
|
|
3544
|
+
restoreFocus: restoreFocus,
|
|
3545
|
+
saveFocus: saveFocus,
|
|
3546
|
+
scrollTo: scrollTo
|
|
3547
|
+
});
|
|
3548
|
+
|
|
3549
|
+
class DefaultTranslationProvider {
|
|
3550
|
+
language = "sv";
|
|
3551
|
+
get currentLanguage() {
|
|
3552
|
+
return this.language;
|
|
3553
|
+
}
|
|
3554
|
+
async changeLanguage(language) {
|
|
3555
|
+
this.language = language;
|
|
3556
|
+
}
|
|
3557
|
+
translate(key, defaultValueOrArgs, args) {
|
|
3558
|
+
if (this.language === "cimode") {
|
|
3559
|
+
return key;
|
|
3560
|
+
}
|
|
3561
|
+
if (!isSet(defaultValueOrArgs) ||
|
|
3562
|
+
typeof defaultValueOrArgs !== "string") {
|
|
3563
|
+
throw new Error("Translation failed: No default value specified (key translation is not supported by the default provider)");
|
|
3564
|
+
}
|
|
3565
|
+
return isSet(args)
|
|
3566
|
+
? this.interpolate(defaultValueOrArgs, args)
|
|
3567
|
+
: defaultValueOrArgs;
|
|
3568
|
+
}
|
|
3569
|
+
interpolate(defaultValue, args) {
|
|
3570
|
+
return defaultValue.replace(/{{\s*([^\s]+)\s*}}/g, (match, key) => {
|
|
3571
|
+
return String(args[key]) || match;
|
|
3572
|
+
});
|
|
3573
|
+
}
|
|
3574
|
+
}
|
|
3575
|
+
|
|
3576
|
+
class TranslationServiceImpl {
|
|
3577
|
+
provider = new DefaultTranslationProvider();
|
|
3578
|
+
changeProvider(newProvider) {
|
|
3579
|
+
this.provider = newProvider;
|
|
3580
|
+
}
|
|
3581
|
+
}
|
|
3582
|
+
/**
|
|
3583
|
+
* @public
|
|
3584
|
+
*/
|
|
3585
|
+
const TranslationService = new TranslationServiceImpl();
|
|
3586
|
+
|
|
3587
|
+
/**
|
|
3588
|
+
* Builder to create validation error message map.
|
|
3589
|
+
*
|
|
3590
|
+
* @public
|
|
3591
|
+
*/
|
|
3592
|
+
class ValidationErrorMessageBuilder {
|
|
3593
|
+
/**
|
|
3594
|
+
* Create a new builder.
|
|
3595
|
+
*/
|
|
3596
|
+
static create() {
|
|
3597
|
+
return new ValidationErrorMessageBuilder();
|
|
3598
|
+
}
|
|
3599
|
+
validatorMessageMap;
|
|
3600
|
+
constructor() {
|
|
3601
|
+
this.validatorMessageMap = {};
|
|
3602
|
+
}
|
|
3603
|
+
/**
|
|
3604
|
+
* Map the validator name message towards an error message.
|
|
3605
|
+
*
|
|
3606
|
+
* @param validatorName - the name of the validator
|
|
3607
|
+
* @param message - the error message
|
|
3608
|
+
* @param elementType - limit to a specific element type
|
|
3609
|
+
*/
|
|
3610
|
+
map(validatorName, message, elementType) {
|
|
3611
|
+
let key = validatorName;
|
|
3612
|
+
if (elementType) {
|
|
3613
|
+
key += `.${elementType}`;
|
|
3614
|
+
}
|
|
3615
|
+
this.validatorMessageMap[key] = message;
|
|
3616
|
+
return this;
|
|
3617
|
+
}
|
|
3618
|
+
/**
|
|
3619
|
+
* Validators that coexists on same element can have a combined message,
|
|
3620
|
+
* i.e. if a element have the `required` and the `personnummer` validator
|
|
3621
|
+
* the required error message could be combined with
|
|
3622
|
+
* `mapCombined('required','personnummer', 'You must enter a social security number!');`.
|
|
3623
|
+
*
|
|
3624
|
+
* @param validatorName - the name of the validator
|
|
3625
|
+
* @param dependentValidatorName - the name of the combined validator
|
|
3626
|
+
* @param message - the error message
|
|
3627
|
+
* @param elementType - limit to a specific element type
|
|
3628
|
+
*/
|
|
3629
|
+
mapCombined(validatorName, dependentValidatorName, message, elementType) {
|
|
3630
|
+
return this.map(`${validatorName}.${dependentValidatorName}`, message, elementType);
|
|
3631
|
+
}
|
|
3632
|
+
/**
|
|
3633
|
+
* Build the translation map.
|
|
3634
|
+
*
|
|
3635
|
+
* @returns the created map.
|
|
3636
|
+
*/
|
|
3637
|
+
build() {
|
|
3638
|
+
return this.validatorMessageMap;
|
|
3639
|
+
}
|
|
3640
|
+
}
|
|
3641
|
+
|
|
3642
|
+
/**
|
|
3643
|
+
* @public
|
|
3644
|
+
*/
|
|
3645
|
+
function getErrorMessages() {
|
|
3646
|
+
return ValidationErrorMessageBuilder.create()
|
|
3647
|
+
.map("bankAccountNumber", "Kontonumret är inte rätt ifyllt. Kolla att det stämmer.")
|
|
3648
|
+
.mapCombined("required", "bankAccountNumber", "Fyll i ett kontonummer.")
|
|
3649
|
+
.map("bankgiro", "Skriv bankgironumret med sju eller åtta siffror och bindestreck.")
|
|
3650
|
+
.mapCombined("required", "bankgiro", "Fyll i bankgironumret.")
|
|
3651
|
+
.mapCombined("maxLength", "bankgiro", "Bankgironumret kan inte ha mer än 9 tecken.")
|
|
3652
|
+
.map("clearingNumber", "Clearingnumret är inte rätt ifyllt. Kolla att det stämmer.")
|
|
3653
|
+
.mapCombined("required", "clearingNumber", "Fyll i ett clearingnummer.")
|
|
3654
|
+
.map("currency", "Fyll i ett belopp.")
|
|
3655
|
+
.mapCombined("required", "currency", "Fyll i ett belopp.")
|
|
3656
|
+
.map("date", "Du har skrivit ett felaktigt datum.")
|
|
3657
|
+
.mapCombined("required", "date", "Välj ett datum.")
|
|
3658
|
+
.map("dateFormat", "Skriv datumet med åtta siffror.")
|
|
3659
|
+
.map("decimal", "Fyll i ett värde med rätt antal decimaler.")
|
|
3660
|
+
.map("email", "Mejladressen är inte korrekt ifylld.")
|
|
3661
|
+
.mapCombined("required", "email", "Fyll i en mejladress.")
|
|
3662
|
+
.mapCombined("matches", "email", "Kolla att mejladressen stämmer.")
|
|
3663
|
+
.map("greaterThan", "Fyll i en högre siffra.")
|
|
3664
|
+
.map("integer", "Fyll i siffror utan decimal.")
|
|
3665
|
+
.mapCombined("required", "integer", "Fyll i en siffra.")
|
|
3666
|
+
.map("lessThan", "Du har fyllt i en för hög siffra.")
|
|
3667
|
+
.map("minDate", "Datumet ligger för långt bak i tiden.")
|
|
3668
|
+
.mapCombined("minDate", "date", "Datumet ligger för långt bak i tiden.")
|
|
3669
|
+
.map("maxDate", "Datumet ligger för långt fram i tiden.")
|
|
3670
|
+
.mapCombined("maxDate", "date", "Datumet ligger för långt fram i tiden.")
|
|
3671
|
+
.map("maxValue", "Du har fyllt i en för hög siffra.")
|
|
3672
|
+
.map("minValue", "Fyll i en högre siffra.")
|
|
3673
|
+
.map("number", "Du har fyllt i ett ogiltigt tecken. Fyll i siffror.")
|
|
3674
|
+
.mapCombined("required", "number", "Fyll i en siffra.")
|
|
3675
|
+
.mapCombined("minValue", "number", "Fyll i en högre siffra.")
|
|
3676
|
+
.mapCombined("maxValue", "number", "Du har fyllt i en för hög siffra.")
|
|
3677
|
+
.map("organisationsnummer", "Fyll i organisationsnumret med 10 siffror, till exempel 999999-9999.")
|
|
3678
|
+
.mapCombined("required", "organisationsnummer", "Fyll i organisationsnumret med 10 siffror, till exempel 999999-9999.")
|
|
3679
|
+
.mapCombined("maxLength", "organisationsnummer", "Organisationsnumret kan inte ha mer än 11 tecken.")
|
|
3680
|
+
.map("percent", "Fyll i procent med en siffra.")
|
|
3681
|
+
.mapCombined("integer", "percent", "Fyll i procent utan decimal.")
|
|
3682
|
+
.mapCombined("required", "percent", "Fyll i en siffra.")
|
|
3683
|
+
.mapCombined("minValue", "percent", "Fyll i en högre siffra.")
|
|
3684
|
+
.mapCombined("maxValue", "percent", "Fyll i en lägre siffra.")
|
|
3685
|
+
.map("personnummerFormat", "Skriv personnumret med 10 siffror.")
|
|
3686
|
+
.mapCombined("required", "personnummerFormat", "Skriv personnumret med 10 siffror.")
|
|
3687
|
+
.mapCombined("maxLength", "personnummerFormat", "Skriv personnumret med 10 siffror.")
|
|
3688
|
+
.map("personnummerLuhn", "Kolla att personnumret stämmer.")
|
|
3689
|
+
.map("postalCode", "Fyll i postnumret med fem siffror.")
|
|
3690
|
+
.mapCombined("required", "postalCode", "Fyll i ett postnummer.")
|
|
3691
|
+
.mapCombined("maxLength", "postalCode", "Postnumret kan inte ha mer än 13 tecken.")
|
|
3692
|
+
.map("phoneNumber", "Telefonnumret är inte rätt ifyllt.")
|
|
3693
|
+
.mapCombined("required", "phoneNumber", "Fyll i ett telefonnummer.")
|
|
3694
|
+
.mapCombined("matches", "phoneNumber", "Kolla att telefonnumret stämmer.")
|
|
3695
|
+
.map("plusgiro", "Skriv plusgironumret med siffror och bindestreck.")
|
|
3696
|
+
.mapCombined("required", "plusgiro", "Fyll i plusgironumret.")
|
|
3697
|
+
.mapCombined("maxLength", "plusgiro", "Plusgironumret kan inte ha mer än 11 tecken.")
|
|
3698
|
+
.map("matches", "Fälten stämmer inte överens.")
|
|
3699
|
+
.map("required", "Fyll i text.")
|
|
3700
|
+
.map("required", "Välj minst ett alternativ.", "checkbox")
|
|
3701
|
+
.map("required", "Välj ett av alternativen.", "radio")
|
|
3702
|
+
.map("required", "Välj ett av alternativen.", "select")
|
|
3703
|
+
.map("invalidDates", "Du kan inte välja det här datumet.")
|
|
3704
|
+
.map("invalidWeekdays", "Du kan inte välja det här datumet.")
|
|
3705
|
+
.map("whitelist", 'Fältet innehåller otillåtna tecken. Exempel på ogiltiga tecken är /, % och ".')
|
|
3706
|
+
.build();
|
|
3707
|
+
}
|
|
3708
|
+
|
|
3709
|
+
/**
|
|
3710
|
+
* @internal
|
|
3711
|
+
*/
|
|
3712
|
+
function createFieldsetValidator(element, validationService) {
|
|
3713
|
+
/* eslint-disable-next-line no-new -- technical debt, this should be
|
|
3714
|
+
* refactored as to not rely of side-effects of the constructor */
|
|
3715
|
+
new FieldsetValidationHandler(element, validationService);
|
|
3716
|
+
}
|
|
3717
|
+
class FieldsetValidationHandler {
|
|
3718
|
+
hasDocumentListener = false;
|
|
3719
|
+
documentFocusInRef = undefined;
|
|
3720
|
+
element;
|
|
3721
|
+
validationService;
|
|
3722
|
+
constructor(element, validationService) {
|
|
3723
|
+
Object.assign(this);
|
|
3724
|
+
this.element = element;
|
|
3725
|
+
this.validationService = validationService;
|
|
3726
|
+
element.addEventListener("focusin", (event) => this.onFocusIn(event));
|
|
3727
|
+
// Handle checking of input by using keyboard (space)
|
|
3728
|
+
element.addEventListener("change", this.documentFocusIn.bind(this));
|
|
3729
|
+
Array.from(this.element.querySelectorAll("input[type='checkbox'], input[type='radio']"))
|
|
3730
|
+
.filter((childElement) => childElement.closest("fieldset") === element)
|
|
3731
|
+
.forEach((childElement) => {
|
|
3732
|
+
childElement.setAttribute("required", "");
|
|
3733
|
+
});
|
|
3734
|
+
}
|
|
3735
|
+
hasFocusableTarget(target) {
|
|
3736
|
+
return target
|
|
3737
|
+
? Array.from(this.element.querySelectorAll("input, label")).some((element) => element === target)
|
|
3738
|
+
: false;
|
|
3739
|
+
}
|
|
3740
|
+
onFocusIn(event) {
|
|
3741
|
+
// IE11 (not Chrome / FF) trigger focusin-event on legends and other elements inside the fieldset
|
|
3742
|
+
// So we need to check the event target, if it's focusable.
|
|
3743
|
+
if (this.hasFocusableTarget(event.target) &&
|
|
3744
|
+
!this.hasDocumentListener) {
|
|
3745
|
+
this.documentFocusInRef = this.documentFocusIn.bind(this);
|
|
3746
|
+
document.addEventListener("focusin", this.documentFocusInRef);
|
|
3747
|
+
document.addEventListener("click", this.documentFocusInRef);
|
|
3748
|
+
this.hasDocumentListener = true;
|
|
3749
|
+
}
|
|
3750
|
+
}
|
|
3751
|
+
documentFocusIn(event) {
|
|
3752
|
+
this.validationService.setTouched(this.element);
|
|
3753
|
+
const children = Array.from(this.element.querySelectorAll("input"));
|
|
3754
|
+
for (const childElement of children) {
|
|
3755
|
+
this.validationService.setTouched(childElement);
|
|
3756
|
+
}
|
|
3757
|
+
if (!this.hasFocusableTarget(event.target)) {
|
|
3758
|
+
this.removeEventListeners();
|
|
3759
|
+
}
|
|
3760
|
+
else if (event.target.checked) {
|
|
3761
|
+
this.validateFieldsetAndChildren();
|
|
3762
|
+
}
|
|
3763
|
+
}
|
|
3764
|
+
removeEventListeners() {
|
|
3765
|
+
if (this.hasDocumentListener && this.documentFocusInRef) {
|
|
3766
|
+
document.removeEventListener("focusin", this.documentFocusInRef);
|
|
3767
|
+
document.removeEventListener("click", this.documentFocusInRef);
|
|
3768
|
+
this.hasDocumentListener = false;
|
|
3769
|
+
this.validateFieldsetAndChildren();
|
|
3770
|
+
}
|
|
3771
|
+
}
|
|
3772
|
+
validateFieldsetAndChildren() {
|
|
3773
|
+
const validatableElements = document.querySelectorAll(`fieldset#${this.element.id}, #${this.element.id} input[type='checkbox'], #${this.element.id} input[type='radio']`);
|
|
3774
|
+
validatableElements.forEach((element) => {
|
|
3775
|
+
if (element.id) {
|
|
3776
|
+
this.validationService.validateElement(element.id);
|
|
3777
|
+
}
|
|
3778
|
+
});
|
|
3779
|
+
}
|
|
3780
|
+
}
|
|
3781
|
+
|
|
3782
|
+
/**
|
|
3783
|
+
* Registered validators.
|
|
3784
|
+
*
|
|
3785
|
+
* @internal
|
|
3786
|
+
*/
|
|
3787
|
+
const registry = {};
|
|
3788
|
+
|
|
3789
|
+
/**
|
|
3790
|
+
* Returns validation error message candidates in prioritized order.
|
|
3791
|
+
*
|
|
3792
|
+
* @internal
|
|
3793
|
+
*/
|
|
3794
|
+
function getCandidates(validatorName, validators, elementType) {
|
|
3795
|
+
const candidates = [];
|
|
3796
|
+
const combinedNames = validators.map((it) => `${validatorName}.${it.name}`);
|
|
3797
|
+
if (elementType) {
|
|
3798
|
+
const combinedNamesWithType = combinedNames.map((it) => `${it}.${elementType}`);
|
|
3799
|
+
candidates.push(...combinedNamesWithType);
|
|
3800
|
+
}
|
|
3801
|
+
candidates.push(...combinedNames);
|
|
3802
|
+
if (elementType) {
|
|
3803
|
+
candidates.push(`${validatorName}.${elementType}`);
|
|
3804
|
+
}
|
|
3805
|
+
candidates.push(validatorName);
|
|
3806
|
+
return candidates;
|
|
3807
|
+
}
|
|
3808
|
+
|
|
3809
|
+
/**
|
|
3810
|
+
* Resolves element type for a `ValidatableHTMLElement`.
|
|
3811
|
+
*
|
|
3812
|
+
* Input types other than text, radio, checkbox returns \"text\".
|
|
3813
|
+
* Fieldset returns \"radio\" or \"checkbox\" when it contains radio or checkbox elements.
|
|
3814
|
+
*
|
|
3815
|
+
* @internal
|
|
3816
|
+
*/
|
|
3817
|
+
function getElementType(element) {
|
|
3818
|
+
if (element instanceof HTMLInputElement) {
|
|
3819
|
+
return element.type === "checkbox"
|
|
3820
|
+
? "checkbox"
|
|
3821
|
+
: element.type === "radio"
|
|
3822
|
+
? "radio"
|
|
3823
|
+
: "text";
|
|
3824
|
+
}
|
|
3825
|
+
else if (element instanceof HTMLTextAreaElement) {
|
|
3826
|
+
return "textarea";
|
|
3827
|
+
}
|
|
3828
|
+
else if (element instanceof HTMLSelectElement) {
|
|
3829
|
+
return "select";
|
|
3830
|
+
}
|
|
3831
|
+
else if (element instanceof HTMLFieldSetElement) {
|
|
3832
|
+
return getElementType(element.querySelector("input[type='checkbox'], input[type='radio']"));
|
|
3833
|
+
}
|
|
3834
|
+
}
|
|
3835
|
+
|
|
3836
|
+
/**
|
|
3837
|
+
* Returns true if given element is a validatable element.
|
|
3838
|
+
*
|
|
3839
|
+
* Also see {@link isValidatableFormElement} for a similar function but
|
|
3840
|
+
* excluding HTMLFieldSetElement.
|
|
3841
|
+
*
|
|
3842
|
+
* @public
|
|
3843
|
+
* @param element - Element to test
|
|
3844
|
+
*/
|
|
3845
|
+
function isValidatableHTMLElement(element) {
|
|
3846
|
+
return (element instanceof HTMLInputElement ||
|
|
3847
|
+
element instanceof HTMLTextAreaElement ||
|
|
3848
|
+
element instanceof HTMLSelectElement ||
|
|
3849
|
+
element instanceof HTMLFieldSetElement);
|
|
3850
|
+
}
|
|
3851
|
+
/**
|
|
3852
|
+
* @internal
|
|
3853
|
+
*/
|
|
3854
|
+
function isFieldset(element) {
|
|
3855
|
+
return element instanceof HTMLFieldSetElement;
|
|
3856
|
+
}
|
|
3857
|
+
function hasValidators(element) {
|
|
3858
|
+
return typeof element.dataset.validation === "string";
|
|
3859
|
+
}
|
|
3860
|
+
class ValidationServiceImpl {
|
|
3861
|
+
validationStates = {};
|
|
3862
|
+
elementValidatorsReferences = {};
|
|
3863
|
+
validationErrorMessages = {};
|
|
3864
|
+
constructor() {
|
|
3865
|
+
this.addValidationErrorMessages(getErrorMessages());
|
|
3866
|
+
}
|
|
3867
|
+
getElementsAndValidators() {
|
|
3868
|
+
return this.elementValidatorsReferences;
|
|
3869
|
+
}
|
|
3870
|
+
get isAnyTouched() {
|
|
3871
|
+
return Object.values(this.validationStates).some((item) => item.touched === true);
|
|
3872
|
+
}
|
|
3873
|
+
addValidationErrorMessages(validationErrorMessages) {
|
|
3874
|
+
this.validationErrorMessages = {
|
|
3875
|
+
...this.validationErrorMessages,
|
|
3876
|
+
...validationErrorMessages,
|
|
3877
|
+
};
|
|
3878
|
+
}
|
|
3879
|
+
registerValidator(validator) {
|
|
3880
|
+
const { name } = validator;
|
|
3881
|
+
registry[name] = validator;
|
|
3882
|
+
}
|
|
3883
|
+
hasExistingReference(elementValidatorsReference, element) {
|
|
3884
|
+
return (isSet(elementValidatorsReference) &&
|
|
3885
|
+
elementValidatorsReference.element === element);
|
|
3886
|
+
}
|
|
3887
|
+
shouldApplyNewConfigOnBaseConfig(isBaseConfigs, elementValidatorsReference) {
|
|
3888
|
+
return (!isBaseConfigs &&
|
|
3889
|
+
isSet(elementValidatorsReference.baseValidatorConfigs));
|
|
3890
|
+
}
|
|
3891
|
+
decideEffectiveValidatorReference(element, newValidatorConfigs, isBaseConfigs) {
|
|
3892
|
+
const elementValidatorsReference = this.elementValidatorsReferences[element.id];
|
|
3893
|
+
const hasExistingReference = this.hasExistingReference(elementValidatorsReference, element);
|
|
3894
|
+
let validatorConfigs;
|
|
3895
|
+
if (!hasExistingReference) {
|
|
3896
|
+
validatorConfigs = newValidatorConfigs;
|
|
3897
|
+
}
|
|
3898
|
+
else if (this.shouldApplyNewConfigOnBaseConfig(isBaseConfigs, elementValidatorsReference)) {
|
|
3899
|
+
validatorConfigs = this.mergeValidatorConfigs(elementValidatorsReference.baseValidatorConfigs, newValidatorConfigs);
|
|
3900
|
+
}
|
|
3901
|
+
else if (isBaseConfigs) {
|
|
3902
|
+
validatorConfigs = this.mergeValidatorConfigs(newValidatorConfigs, elementValidatorsReference.validatorConfigs);
|
|
3903
|
+
elementValidatorsReference.baseValidatorConfigs =
|
|
3904
|
+
newValidatorConfigs;
|
|
3905
|
+
}
|
|
3906
|
+
else {
|
|
3907
|
+
validatorConfigs = newValidatorConfigs;
|
|
3908
|
+
}
|
|
3909
|
+
return validatorConfigs;
|
|
3910
|
+
}
|
|
3911
|
+
dispatchValidationConfig(validatorConfigs, element) {
|
|
3912
|
+
const event = new CustomEvent("validation-config-update", {
|
|
3913
|
+
bubbles: false,
|
|
3914
|
+
detail: { config: validatorConfigs },
|
|
3915
|
+
});
|
|
3916
|
+
element.dispatchEvent(event);
|
|
3917
|
+
}
|
|
3918
|
+
removeValidatorsFromElement(element) {
|
|
3919
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete -- Technical debt, a map would have been better.
|
|
3920
|
+
delete this.elementValidatorsReferences[element.id];
|
|
3921
|
+
}
|
|
3922
|
+
addValidatorsToElement(element, newValidatorConfigs, isBaseConfigs = false) {
|
|
3923
|
+
if (!isValidatableHTMLElement(element)) {
|
|
3924
|
+
return;
|
|
3925
|
+
}
|
|
3926
|
+
const validatorConfigs = this.decideEffectiveValidatorReference(element, newValidatorConfigs, isBaseConfigs);
|
|
3927
|
+
this.dispatchValidationConfig(validatorConfigs, element);
|
|
3928
|
+
if (element instanceof HTMLFieldSetElement) {
|
|
3929
|
+
createFieldsetValidator(element, this);
|
|
3930
|
+
}
|
|
3931
|
+
this.setRequiredAttribute(element, validatorConfigs);
|
|
3932
|
+
// Deprecated: SFKUI-4412 personnummerValidator is deprecated. Replace with personnummerFormat and personnummerLuhn
|
|
3933
|
+
// Legacy compability tests cant be found here: @fkui/vue:src\components\FTextField\FTextField.cy.ts
|
|
3934
|
+
if (validatorConfigs["personnummer"] !== undefined) {
|
|
3935
|
+
const oldConfig = validatorConfigs["personnummer"];
|
|
3936
|
+
validatorConfigs["personnummerFormat"] = oldConfig;
|
|
3937
|
+
validatorConfigs["personnummerLuhn"] = oldConfig;
|
|
3938
|
+
delete validatorConfigs.personnummer;
|
|
3939
|
+
}
|
|
3940
|
+
const foundValidators = this.getValidators(validatorConfigs);
|
|
3941
|
+
// set data-validation attribute to indicate that validation is activated on the element
|
|
3942
|
+
if (foundValidators.length > 0) {
|
|
3943
|
+
element.dataset.validation = "";
|
|
3944
|
+
}
|
|
3945
|
+
const useInstantValidation = this.useInstantValidation(foundValidators, validatorConfigs);
|
|
3946
|
+
let elementValidatorsReference = this.elementValidatorsReferences[element.id];
|
|
3947
|
+
if (this.hasExistingReference(elementValidatorsReference, element)) {
|
|
3948
|
+
elementValidatorsReference.validatorConfigs = validatorConfigs;
|
|
3949
|
+
elementValidatorsReference.validators = foundValidators;
|
|
3950
|
+
elementValidatorsReference.instant = useInstantValidation;
|
|
3951
|
+
}
|
|
3952
|
+
else {
|
|
3953
|
+
elementValidatorsReference = {
|
|
3954
|
+
validators: foundValidators,
|
|
3955
|
+
validatorConfigs: validatorConfigs,
|
|
3956
|
+
element,
|
|
3957
|
+
instant: useInstantValidation,
|
|
3958
|
+
baseValidatorConfigs: isBaseConfigs
|
|
3959
|
+
? validatorConfigs
|
|
3960
|
+
: undefined,
|
|
3961
|
+
};
|
|
3962
|
+
this.elementValidatorsReferences[element.id] =
|
|
3963
|
+
elementValidatorsReference;
|
|
3964
|
+
this.createEventListeners(elementValidatorsReference);
|
|
3965
|
+
}
|
|
3966
|
+
}
|
|
3967
|
+
mergeValidatorConfigs(baseConfig, newConfig) {
|
|
3968
|
+
const required = isSet(newConfig.required)
|
|
3969
|
+
? { required: {} }
|
|
3970
|
+
: undefined;
|
|
3971
|
+
return {
|
|
3972
|
+
...required,
|
|
3973
|
+
...baseConfig,
|
|
3974
|
+
...newConfig,
|
|
3975
|
+
};
|
|
3976
|
+
}
|
|
3977
|
+
createEventListeners(elementValidatorsReference) {
|
|
3978
|
+
const element = elementValidatorsReference.element;
|
|
3979
|
+
if (!(element instanceof HTMLFieldSetElement)) {
|
|
3980
|
+
element.addEventListener("input", () => {
|
|
3981
|
+
const validationState = this.getExistingStateOrSetDefault(element);
|
|
3982
|
+
validationState.serverError = undefined;
|
|
3983
|
+
if (elementValidatorsReference.instant) {
|
|
3984
|
+
validationState.touched = true;
|
|
3985
|
+
this.validateAndDispatchEvent("input", {
|
|
3986
|
+
validationState,
|
|
3987
|
+
elementValidatorsReference,
|
|
3988
|
+
});
|
|
3989
|
+
}
|
|
3990
|
+
else {
|
|
3991
|
+
element.dispatchEvent(new CustomEvent("pending-validity", {
|
|
3992
|
+
bubbles: false,
|
|
3993
|
+
}));
|
|
3994
|
+
}
|
|
3995
|
+
});
|
|
3996
|
+
element.addEventListener("change", () => {
|
|
3997
|
+
const validationState = this.getExistingStateOrSetDefault(element);
|
|
3998
|
+
validationState.touched = true;
|
|
3999
|
+
this.validateAndDispatchEvent("change", {
|
|
4000
|
+
validationState,
|
|
4001
|
+
elementValidatorsReference,
|
|
4002
|
+
});
|
|
4003
|
+
});
|
|
4004
|
+
element.addEventListener("blur", () => {
|
|
4005
|
+
const validationState = this.getExistingStateOrSetDefault(element);
|
|
4006
|
+
validationState.touched = true;
|
|
4007
|
+
this.validateAndDispatchEvent("blur", {
|
|
4008
|
+
validationState,
|
|
4009
|
+
elementValidatorsReference,
|
|
4010
|
+
});
|
|
4011
|
+
});
|
|
4012
|
+
}
|
|
4013
|
+
element.addEventListener("validate", () => {
|
|
4014
|
+
const validationState = this.getExistingStateOrSetDefault(element);
|
|
4015
|
+
this.validateAndDispatchEvent("validate", {
|
|
4016
|
+
validationState,
|
|
4017
|
+
elementValidatorsReference,
|
|
4018
|
+
});
|
|
4019
|
+
});
|
|
4020
|
+
}
|
|
4021
|
+
async isValid(src, root = document) {
|
|
4022
|
+
/* nest inner sync function mostly because the code itself is sync
|
|
4023
|
+
* (especially required by Array.every) but we still want the API to be
|
|
4024
|
+
* async to future-proof it */
|
|
4025
|
+
function isValidSync(src) {
|
|
4026
|
+
if (!src) {
|
|
4027
|
+
return false;
|
|
4028
|
+
}
|
|
4029
|
+
else if (Array.isArray(src)) {
|
|
4030
|
+
const array = src;
|
|
4031
|
+
return array.every((it) => isValidSync(it));
|
|
4032
|
+
}
|
|
4033
|
+
else if (typeof src === "string") {
|
|
4034
|
+
return isValidSync(root.querySelector(`#${src}`));
|
|
4035
|
+
}
|
|
4036
|
+
else if (isValidatableFormElement(src)) {
|
|
4037
|
+
return src.validity.valid;
|
|
4038
|
+
}
|
|
4039
|
+
else {
|
|
4040
|
+
return src.querySelectorAll(":invalid").length === 0;
|
|
4041
|
+
}
|
|
4042
|
+
}
|
|
4043
|
+
return isValidSync(src);
|
|
4044
|
+
}
|
|
4045
|
+
async validateElement(src) {
|
|
4046
|
+
if (!src) {
|
|
4047
|
+
return {
|
|
4048
|
+
isValid: true,
|
|
4049
|
+
isTouched: false,
|
|
4050
|
+
isSubmitted: false,
|
|
4051
|
+
error: null,
|
|
4052
|
+
};
|
|
4053
|
+
}
|
|
4054
|
+
if (typeof src === "string") {
|
|
4055
|
+
const element = document.getElementById(src);
|
|
4056
|
+
if (!element) {
|
|
4057
|
+
throw new Error(`Element with id "${src}" not found when calling validateElement(..)`);
|
|
4058
|
+
}
|
|
4059
|
+
src = element;
|
|
4060
|
+
}
|
|
4061
|
+
if (!isValidatableHTMLElement(src)) {
|
|
4062
|
+
const tagName = src.tagName.toLowerCase();
|
|
4063
|
+
const ref = `${tagName}#${src.id}`;
|
|
4064
|
+
throw new Error(`Element "${ref}" is not a validatable element`);
|
|
4065
|
+
}
|
|
4066
|
+
const element = src;
|
|
4067
|
+
/* Handle when element has no registered validators (and thus no event
|
|
4068
|
+
* listeners) by assuming the element is valid */
|
|
4069
|
+
if (!hasValidators(element)) {
|
|
4070
|
+
/* For compatibility (mostly with whitebox unittests) this event is
|
|
4071
|
+
* still delivered. Relying on this event is discouraged and
|
|
4072
|
+
* deprecated */
|
|
4073
|
+
const event = new CustomEvent("validate", {
|
|
4074
|
+
bubbles: false,
|
|
4075
|
+
});
|
|
4076
|
+
element.dispatchEvent(event);
|
|
4077
|
+
return {
|
|
4078
|
+
isValid: true,
|
|
4079
|
+
isTouched: false,
|
|
4080
|
+
isSubmitted: false,
|
|
4081
|
+
error: null,
|
|
4082
|
+
};
|
|
4083
|
+
}
|
|
4084
|
+
return new Promise((resolve, reject) => {
|
|
4085
|
+
/* Add a temporary listener, as long as IE11 is supported we cannot
|
|
4086
|
+
* use "once" so instead we save the listener and remove it manually
|
|
4087
|
+
* later. */
|
|
4088
|
+
const once = (event) => {
|
|
4089
|
+
element.removeEventListener("validity", once);
|
|
4090
|
+
clearTimeout(watchdog);
|
|
4091
|
+
const { touched: isTouched = false, submitted: isSubmitted = false, } = this.getState(element.id);
|
|
4092
|
+
const { isValid, validationMessage } = event.detail;
|
|
4093
|
+
resolve({
|
|
4094
|
+
isValid,
|
|
4095
|
+
isTouched,
|
|
4096
|
+
isSubmitted,
|
|
4097
|
+
error: isValid ? null : validationMessage,
|
|
4098
|
+
});
|
|
4099
|
+
};
|
|
4100
|
+
element.addEventListener("validity", once);
|
|
4101
|
+
/* Add a watchdog timer in case the listener isn't actually there or
|
|
4102
|
+
* if the event is blocked with {@link stopPropagation} or similar. */
|
|
4103
|
+
const watchdog = setTimeout(() => {
|
|
4104
|
+
const tagName = element.tagName.toLowerCase();
|
|
4105
|
+
const ref = `${tagName}#${element.id}`;
|
|
4106
|
+
element.removeEventListener("validity", once);
|
|
4107
|
+
reject(`Element "${ref}" did not respond with validity event after 500ms`);
|
|
4108
|
+
}, 500);
|
|
4109
|
+
/* Dispatch request to validate, this is supposed to be picked up by
|
|
4110
|
+
* the the eventlistener installed while adding validators and in a
|
|
4111
|
+
* happy-case this is 1:1 mapped to receiving the "validity"
|
|
4112
|
+
* event. */
|
|
4113
|
+
const event = new CustomEvent("validate", {
|
|
4114
|
+
bubbles: false,
|
|
4115
|
+
});
|
|
4116
|
+
element.dispatchEvent(event);
|
|
4117
|
+
});
|
|
4118
|
+
}
|
|
4119
|
+
async validateAllElements(root) {
|
|
4120
|
+
const elements = this.getValidatableElements(root);
|
|
4121
|
+
const promises = elements.map((it) => this.validateElement(it));
|
|
4122
|
+
await Promise.all(promises);
|
|
4123
|
+
}
|
|
4124
|
+
setState(element, validationState) {
|
|
4125
|
+
if (!element) {
|
|
4126
|
+
return;
|
|
4127
|
+
}
|
|
4128
|
+
else if (typeof element === "string") {
|
|
4129
|
+
const found = document.getElementById(element);
|
|
4130
|
+
this.setState(found, validationState);
|
|
4131
|
+
}
|
|
4132
|
+
else if (!isValidatableHTMLElement(element)) {
|
|
4133
|
+
const childElements = this.getValidatableElements(element);
|
|
4134
|
+
for (const childElement of childElements) {
|
|
4135
|
+
this.setState(childElement, validationState);
|
|
4136
|
+
}
|
|
4137
|
+
}
|
|
4138
|
+
else {
|
|
4139
|
+
const existingState = this.validationStates[element.id];
|
|
4140
|
+
if (existingState) {
|
|
4141
|
+
this.validationStates[element.id] = {
|
|
4142
|
+
...existingState,
|
|
4143
|
+
...validationState,
|
|
4144
|
+
};
|
|
4145
|
+
}
|
|
4146
|
+
else {
|
|
4147
|
+
this.validationStates[element.id] = validationState;
|
|
4148
|
+
}
|
|
4149
|
+
}
|
|
4150
|
+
}
|
|
4151
|
+
setSubmitted(element) {
|
|
4152
|
+
this.setState(element, {
|
|
4153
|
+
submitted: true,
|
|
4154
|
+
});
|
|
4155
|
+
}
|
|
4156
|
+
setTouched(element) {
|
|
4157
|
+
this.setState(element, {
|
|
4158
|
+
touched: true,
|
|
4159
|
+
});
|
|
4160
|
+
}
|
|
4161
|
+
setError(element, message) {
|
|
4162
|
+
this.setState(element, {
|
|
4163
|
+
serverError: message,
|
|
4164
|
+
});
|
|
4165
|
+
}
|
|
4166
|
+
resetState(element) {
|
|
4167
|
+
this.setState(element, {
|
|
4168
|
+
touched: false,
|
|
4169
|
+
submitted: false,
|
|
4170
|
+
serverError: undefined,
|
|
4171
|
+
});
|
|
4172
|
+
}
|
|
4173
|
+
getValidatableElements(parent) {
|
|
4174
|
+
if (!parent) {
|
|
4175
|
+
return [];
|
|
4176
|
+
}
|
|
4177
|
+
else if (typeof parent === "string") {
|
|
4178
|
+
const element = document.getElementById(parent);
|
|
4179
|
+
return this.getValidatableElements(element);
|
|
4180
|
+
}
|
|
4181
|
+
else {
|
|
4182
|
+
const selector = ["input", "textarea", "select", "fieldset"].join(",");
|
|
4183
|
+
return Array.from(parent.querySelectorAll(selector));
|
|
4184
|
+
}
|
|
4185
|
+
}
|
|
4186
|
+
setRequiredAttribute(element, validatorConfigs) {
|
|
4187
|
+
if (!validatorConfigs.required) {
|
|
4188
|
+
return;
|
|
4189
|
+
}
|
|
4190
|
+
if (validatorConfigs.required.enabled !== false) {
|
|
4191
|
+
element.dataset.required = "";
|
|
4192
|
+
if (isValidatableFormElement(element)) {
|
|
4193
|
+
element.setAttribute("required", "");
|
|
4194
|
+
}
|
|
4195
|
+
}
|
|
4196
|
+
else {
|
|
4197
|
+
delete element.dataset.required;
|
|
4198
|
+
if (isValidatableFormElement(element)) {
|
|
4199
|
+
element.removeAttribute("required");
|
|
4200
|
+
}
|
|
4201
|
+
}
|
|
4202
|
+
}
|
|
4203
|
+
useInstantValidation(foundValidators, validatorConfigs) {
|
|
4204
|
+
return foundValidators.some((validator) => {
|
|
4205
|
+
const config = validatorConfigs[validator.name];
|
|
4206
|
+
const instantConfig = isSet(config) ? config.instant : undefined;
|
|
4207
|
+
return ((validator.instant && instantConfig !== false) ||
|
|
4208
|
+
instantConfig === true);
|
|
4209
|
+
});
|
|
4210
|
+
}
|
|
4211
|
+
getState(id) {
|
|
4212
|
+
return this.validationStates[id];
|
|
4213
|
+
}
|
|
4214
|
+
getExistingStateOrSetDefault(element) {
|
|
4215
|
+
let validationState = this.getState(element.id);
|
|
4216
|
+
if (!validationState) {
|
|
4217
|
+
validationState = { touched: false, submitted: false };
|
|
4218
|
+
this.setState(element, validationState);
|
|
4219
|
+
}
|
|
4220
|
+
return validationState;
|
|
4221
|
+
}
|
|
4222
|
+
getValidators(validatorConfigs) {
|
|
4223
|
+
const validatorNames = Object.keys(validatorConfigs);
|
|
4224
|
+
return validatorNames.map((validatorName) => {
|
|
4225
|
+
const validator = registry[validatorName];
|
|
4226
|
+
if (validator) {
|
|
4227
|
+
return validator;
|
|
4228
|
+
}
|
|
4229
|
+
throw new Error(`Validator '${validatorName}' does not exist or is not registered, see ValidatorService.registerValidator.`);
|
|
4230
|
+
});
|
|
4231
|
+
}
|
|
4232
|
+
getValidatorByName(name) {
|
|
4233
|
+
if (!(name in registry)) {
|
|
4234
|
+
throw new Error(`Validator '${name}' does not exist or is not registered, see ValidatorService.registerValidator.`);
|
|
4235
|
+
}
|
|
4236
|
+
return registry[name];
|
|
4237
|
+
}
|
|
4238
|
+
validateAndDispatchEvent(nativeEvent, params) {
|
|
4239
|
+
const validationResult = this.validateAll(params.elementValidatorsReference.element, params.validationState, params.elementValidatorsReference.validators, params.elementValidatorsReference.validatorConfigs);
|
|
4240
|
+
const validityMode = this.resolveValidityMode(params.elementValidatorsReference.element, params.validationState, validationResult.isValid);
|
|
4241
|
+
this.dispatchValidityEvent(params.elementValidatorsReference.element, {
|
|
4242
|
+
...validationResult,
|
|
4243
|
+
target: params.elementValidatorsReference.element,
|
|
4244
|
+
elementId: params.elementValidatorsReference.element.id,
|
|
4245
|
+
validityMode: validityMode,
|
|
4246
|
+
nativeEvent,
|
|
4247
|
+
});
|
|
4248
|
+
}
|
|
4249
|
+
resolveValidityMode(element, validationState, isValid) {
|
|
4250
|
+
if (validationState.serverError) {
|
|
4251
|
+
return "ERROR";
|
|
4252
|
+
}
|
|
4253
|
+
else if (isValid) {
|
|
4254
|
+
return this.resolveValidityModeWhenValid(element);
|
|
4255
|
+
}
|
|
4256
|
+
else {
|
|
4257
|
+
return this.resolveValidityModeWhenError(element, validationState.touched, validationState.submitted);
|
|
4258
|
+
}
|
|
4259
|
+
}
|
|
4260
|
+
resolveValidityModeWhenValid(element) {
|
|
4261
|
+
return this.hasValue(element) ? "VALID" : "INITIAL";
|
|
4262
|
+
}
|
|
4263
|
+
resolveValidityModeWhenError(element, touched, submitted) {
|
|
4264
|
+
return submitted || this.hasValue(element) ? "ERROR" : "INITIAL";
|
|
4265
|
+
}
|
|
4266
|
+
hasValue(element) {
|
|
4267
|
+
if (element instanceof HTMLFieldSetElement) {
|
|
4268
|
+
return Array.from(element.querySelectorAll("input")).some((fieldsetInputElement) => {
|
|
4269
|
+
return this.hasValue(fieldsetInputElement);
|
|
4270
|
+
});
|
|
4271
|
+
}
|
|
4272
|
+
return Boolean(isRadiobuttonOrCheckbox(element)
|
|
4273
|
+
? element.checked
|
|
4274
|
+
: element.value);
|
|
4275
|
+
}
|
|
4276
|
+
getValue(element) {
|
|
4277
|
+
return element instanceof HTMLFieldSetElement || !element.value
|
|
4278
|
+
? ""
|
|
4279
|
+
: element.value.trim();
|
|
4280
|
+
}
|
|
4281
|
+
validateAll(element, validationState, validators, validatorConfigs) {
|
|
4282
|
+
if (validationState.serverError) {
|
|
4283
|
+
return {
|
|
4284
|
+
isValid: false,
|
|
4285
|
+
validationMessage: validationState.serverError,
|
|
4286
|
+
};
|
|
4287
|
+
}
|
|
4288
|
+
/* if the element is disabled we always consider it to be valid */
|
|
4289
|
+
if (element.disabled) {
|
|
4290
|
+
return {
|
|
4291
|
+
isValid: true,
|
|
4292
|
+
validationMessage: "",
|
|
4293
|
+
};
|
|
4294
|
+
}
|
|
4295
|
+
const value = this.getValue(element);
|
|
4296
|
+
const resultFromValidators = validators.map((validator) => {
|
|
4297
|
+
return {
|
|
4298
|
+
isValid: this.validate(value, element, validator, validatorConfigs),
|
|
4299
|
+
name: validator.name,
|
|
4300
|
+
};
|
|
4301
|
+
});
|
|
4302
|
+
const firstInvalidResult = resultFromValidators.find((result) => !result.isValid);
|
|
4303
|
+
if (firstInvalidResult) {
|
|
4304
|
+
const validationMessage = this.getErrorMessage(firstInvalidResult.name, validators, validatorConfigs, getElementType(element));
|
|
4305
|
+
return { isValid: false, validationMessage };
|
|
4306
|
+
}
|
|
4307
|
+
else {
|
|
4308
|
+
return { isValid: true, validationMessage: "" };
|
|
4309
|
+
}
|
|
4310
|
+
}
|
|
4311
|
+
validate(value, element, validator, validatorConfigs) {
|
|
4312
|
+
const validatorConfig = validatorConfigs[validator.name] || {};
|
|
4313
|
+
const isEnabled = validatorConfig.enabled === undefined ||
|
|
4314
|
+
validatorConfig.enabled === true;
|
|
4315
|
+
/**
|
|
4316
|
+
* Only execute validation method if enabled is undefined or true.
|
|
4317
|
+
*/
|
|
4318
|
+
return isEnabled
|
|
4319
|
+
? validator.validation(value, element, validatorConfig)
|
|
4320
|
+
: true;
|
|
4321
|
+
}
|
|
4322
|
+
getErrorMessage(validatorName, validators, validatorConfigs, elementType) {
|
|
4323
|
+
const validatorConfig = validatorConfigs[validatorName];
|
|
4324
|
+
if (validatorConfig && validatorConfig.errorMessage) {
|
|
4325
|
+
return validatorConfig.errorMessage;
|
|
4326
|
+
}
|
|
4327
|
+
const candidates = getCandidates(validatorName, validators, elementType);
|
|
4328
|
+
const key = candidates.find((candidate) => isSet(this.validationErrorMessages[candidate]));
|
|
4329
|
+
if (key) {
|
|
4330
|
+
return (this.validationErrorMessages[key] ?? validatorName.toUpperCase());
|
|
4331
|
+
}
|
|
4332
|
+
return validatorName.toUpperCase();
|
|
4333
|
+
}
|
|
4334
|
+
getElementsAffectedByValidity(element) {
|
|
4335
|
+
if (element instanceof HTMLFieldSetElement) {
|
|
4336
|
+
return this.getValidatableElements(element).filter((childElement) => childElement.closest("fieldset") === element);
|
|
4337
|
+
}
|
|
4338
|
+
else {
|
|
4339
|
+
return [element];
|
|
4340
|
+
}
|
|
4341
|
+
}
|
|
4342
|
+
dispatchValidityEvent(element, validityEvent) {
|
|
4343
|
+
const affectedElements = this.getElementsAffectedByValidity(element);
|
|
4344
|
+
const validField = validityEvent.validityMode === "ERROR";
|
|
4345
|
+
const event = new CustomEvent("validity", {
|
|
4346
|
+
bubbles: true,
|
|
4347
|
+
detail: validityEvent,
|
|
4348
|
+
});
|
|
4349
|
+
for (const affectedElement of affectedElements) {
|
|
4350
|
+
affectedElement.setCustomValidity(validityEvent.validationMessage);
|
|
4351
|
+
affectedElement.setAttribute("aria-invalid", validField.toString());
|
|
4352
|
+
}
|
|
4353
|
+
element.dispatchEvent(event);
|
|
4354
|
+
}
|
|
4355
|
+
clearAllStates() {
|
|
4356
|
+
this.validationStates = {};
|
|
4357
|
+
}
|
|
4358
|
+
}
|
|
4359
|
+
/**
|
|
4360
|
+
* @public
|
|
4361
|
+
*/
|
|
4362
|
+
const ValidationService = new ValidationServiceImpl();
|
|
4363
|
+
|
|
4364
|
+
const bankAccountNumberValidator = {
|
|
4365
|
+
name: "bankAccountNumber",
|
|
4366
|
+
validation(value) {
|
|
4367
|
+
return isEmpty(value) || isSet(parseBankAccountNumber(value));
|
|
4368
|
+
},
|
|
4369
|
+
};
|
|
4370
|
+
|
|
4371
|
+
const bankgiroValidator = {
|
|
4372
|
+
name: "bankgiro",
|
|
4373
|
+
validation(value) {
|
|
4374
|
+
return isEmpty(value) || isSet(parseBankgiro(value));
|
|
4375
|
+
},
|
|
4376
|
+
};
|
|
4377
|
+
|
|
4378
|
+
const clearingNumberValidator = {
|
|
4379
|
+
name: "clearingNumber",
|
|
4380
|
+
validation(value) {
|
|
4381
|
+
return isEmpty(value) || isSet(parseClearingNumber(value));
|
|
4382
|
+
},
|
|
4383
|
+
};
|
|
4384
|
+
|
|
4385
|
+
const dateValidator = {
|
|
4386
|
+
name: "date",
|
|
4387
|
+
validation(value) {
|
|
4388
|
+
if (isEmpty(value)) {
|
|
4389
|
+
return true;
|
|
4390
|
+
}
|
|
4391
|
+
const normalized = normalizeDateFormat(value);
|
|
4392
|
+
if (!normalized) {
|
|
4393
|
+
return false;
|
|
4394
|
+
}
|
|
4395
|
+
const parsed = FDate.fromIso(normalized);
|
|
4396
|
+
return parsed.isValid();
|
|
4397
|
+
},
|
|
4398
|
+
};
|
|
4399
|
+
const dateFormatValidator = {
|
|
4400
|
+
name: "dateFormat",
|
|
4401
|
+
validation(value) {
|
|
4402
|
+
if (isEmpty(value)) {
|
|
4403
|
+
return true;
|
|
4404
|
+
}
|
|
4405
|
+
const normalized = normalizeDateFormat(value);
|
|
4406
|
+
return Boolean(normalized);
|
|
4407
|
+
},
|
|
4408
|
+
};
|
|
4409
|
+
|
|
4410
|
+
function createNumberRegexp(minDecimals = 0, maxDecimals = 2) {
|
|
4411
|
+
return new RegExp(`^([-\u2212]?[0-9]+)([,.][0-9]{${minDecimals},${maxDecimals}})(?<![,.])$`);
|
|
4412
|
+
}
|
|
4413
|
+
const decimalValidator = {
|
|
4414
|
+
name: "decimal",
|
|
4415
|
+
validation(value, _element, config) {
|
|
4416
|
+
const valueWithoutWhitespace = isSet(value)
|
|
4417
|
+
? stripWhitespace(String(value))
|
|
4418
|
+
: value;
|
|
4419
|
+
const minDecimalsAsNumber = isSet(config.minDecimals)
|
|
4420
|
+
? Number(config.minDecimals)
|
|
4421
|
+
: undefined;
|
|
4422
|
+
const maxDecimalsAsNumber = isSet(config.maxDecimals)
|
|
4423
|
+
? Number(config.maxDecimals)
|
|
4424
|
+
: undefined;
|
|
4425
|
+
/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- technical debt, should actually verfiy value instead */
|
|
4426
|
+
if (config.minDecimals && isNaN(minDecimalsAsNumber)) {
|
|
4427
|
+
throw new Error("config.minDecimals must be a number");
|
|
4428
|
+
}
|
|
4429
|
+
/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- technical debt, should actually verfiy value instead */
|
|
4430
|
+
if (config.maxDecimals && isNaN(maxDecimalsAsNumber)) {
|
|
4431
|
+
throw new Error("config.maxDecimals must be a number");
|
|
4432
|
+
}
|
|
4433
|
+
return (isEmpty(valueWithoutWhitespace) ||
|
|
4434
|
+
createNumberRegexp(minDecimalsAsNumber, maxDecimalsAsNumber).test(valueWithoutWhitespace));
|
|
4435
|
+
},
|
|
4436
|
+
};
|
|
4437
|
+
|
|
4438
|
+
function toArray(value) {
|
|
4439
|
+
if (Array.isArray(value)) {
|
|
4440
|
+
return value;
|
|
4441
|
+
}
|
|
4442
|
+
else {
|
|
4443
|
+
return [value];
|
|
4444
|
+
}
|
|
4445
|
+
}
|
|
4446
|
+
const blacklistValidator = {
|
|
4447
|
+
name: "blacklist",
|
|
4448
|
+
validation(value, _element, config) {
|
|
4449
|
+
if (!config.values) {
|
|
4450
|
+
throw new Error("config.exclude must have values");
|
|
4451
|
+
}
|
|
4452
|
+
const values = toArray(config.values);
|
|
4453
|
+
const found = values.some((it) => String(it) === value);
|
|
4454
|
+
return !found;
|
|
4455
|
+
},
|
|
4456
|
+
};
|
|
4457
|
+
|
|
4458
|
+
const emailValidator = {
|
|
4459
|
+
name: "email",
|
|
4460
|
+
validation(value, _element, config) {
|
|
4461
|
+
const maxLength = config.maxLength || 254;
|
|
4462
|
+
const EMAIL_REGEXP = new RegExp(`^(?=.{1,${maxLength}}$)(?=.{1,64}@)[-!#$%&'*+/0-9=?A-Z^_\`a-z{|}~åäöÅÄÖ]+(\\.[-!#$%&'*+/0-9=?A-Z^_\`a-z{|}~åäöÅÄÖ]+)*@[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(\\.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*$`);
|
|
4463
|
+
return isEmpty(value) || EMAIL_REGEXP.test(value);
|
|
4464
|
+
},
|
|
4465
|
+
};
|
|
4466
|
+
|
|
4467
|
+
const NUMBER_REGEXP = /^([-−]?[0-9]+)?$/;
|
|
4468
|
+
const integerValidator = {
|
|
4469
|
+
name: "integer",
|
|
4470
|
+
validation(value) {
|
|
4471
|
+
const valueWithoutWhitespace = isSet(value)
|
|
4472
|
+
? stripWhitespace(String(value))
|
|
4473
|
+
: value;
|
|
4474
|
+
return (isEmpty(valueWithoutWhitespace) ||
|
|
4475
|
+
NUMBER_REGEXP.test(valueWithoutWhitespace));
|
|
4476
|
+
},
|
|
4477
|
+
};
|
|
4478
|
+
|
|
4479
|
+
/**
|
|
4480
|
+
* @public
|
|
4481
|
+
*/
|
|
4482
|
+
function isInvalidDatesConfig(value) {
|
|
4483
|
+
return Boolean(value.dates);
|
|
4484
|
+
}
|
|
4485
|
+
/**
|
|
4486
|
+
* @public
|
|
4487
|
+
*/
|
|
4488
|
+
const invalidDatesValidator = {
|
|
4489
|
+
name: "invalidDates",
|
|
4490
|
+
validation(value, element, config) {
|
|
4491
|
+
if (isEmpty(value)) {
|
|
4492
|
+
return true;
|
|
4493
|
+
}
|
|
4494
|
+
if (!isInvalidDatesConfig(config)) {
|
|
4495
|
+
throw new Error(`Invalid invalidDates config for ${element.id}`);
|
|
4496
|
+
}
|
|
4497
|
+
return !config.dates.includes(value);
|
|
4498
|
+
},
|
|
4499
|
+
};
|
|
4500
|
+
|
|
4501
|
+
/**
|
|
4502
|
+
* @public
|
|
4503
|
+
*/
|
|
4504
|
+
function isInvalidWeekdaysConfig(value) {
|
|
4505
|
+
return Boolean(value.days);
|
|
4506
|
+
}
|
|
4507
|
+
/**
|
|
4508
|
+
* @public
|
|
4509
|
+
*/
|
|
4510
|
+
const invalidWeekdaysValidator = {
|
|
4511
|
+
name: "invalidWeekdays",
|
|
4512
|
+
validation(value, element, config) {
|
|
4513
|
+
if (isEmpty(value)) {
|
|
4514
|
+
return true;
|
|
4515
|
+
}
|
|
4516
|
+
if (!isInvalidWeekdaysConfig(config)) {
|
|
4517
|
+
throw new Error(`Invalid invalidWeekdays config for ${element.id}`);
|
|
4518
|
+
}
|
|
4519
|
+
const day = FDate.fromIso(value).weekDay;
|
|
4520
|
+
return !config.days.includes(day);
|
|
4521
|
+
},
|
|
4522
|
+
};
|
|
4523
|
+
|
|
4524
|
+
/**
|
|
4525
|
+
* @internal
|
|
4526
|
+
*/
|
|
4527
|
+
function numberValidator$1(value, config, name, compare) {
|
|
4528
|
+
if (value === "") {
|
|
4529
|
+
return true;
|
|
4530
|
+
}
|
|
4531
|
+
const limit = config[name];
|
|
4532
|
+
if (!isSet(limit)) {
|
|
4533
|
+
return false;
|
|
4534
|
+
}
|
|
4535
|
+
const limitAsNumber = parseNumber(String(config[name]));
|
|
4536
|
+
if (limitAsNumber === undefined) {
|
|
4537
|
+
throw new Error(`config.${String(name)} must be a number`);
|
|
4538
|
+
}
|
|
4539
|
+
const valueAsNumber = parseNumber(value);
|
|
4540
|
+
if (valueAsNumber === undefined) {
|
|
4541
|
+
return false;
|
|
4542
|
+
}
|
|
4543
|
+
return compare(valueAsNumber, limitAsNumber);
|
|
4544
|
+
}
|
|
4545
|
+
|
|
4546
|
+
const greaterThanValidator = {
|
|
4547
|
+
name: "greaterThan",
|
|
4548
|
+
validation(value, _element, config) {
|
|
4549
|
+
return numberValidator$1(value, config, "limit", (value, limit) => value > limit);
|
|
4550
|
+
},
|
|
4551
|
+
};
|
|
4552
|
+
|
|
4553
|
+
const lessThanValidator = {
|
|
4554
|
+
name: "lessThan",
|
|
4555
|
+
validation(value, _element, config) {
|
|
4556
|
+
return numberValidator$1(value, config, "limit", (value, limit) => value < limit);
|
|
4557
|
+
},
|
|
4558
|
+
};
|
|
4559
|
+
|
|
4560
|
+
const matchesValidator = {
|
|
4561
|
+
name: "matches",
|
|
4562
|
+
validation(value, _element, config) {
|
|
4563
|
+
if (!isSet(config.id) || !isSet(value)) {
|
|
4564
|
+
return true;
|
|
4565
|
+
}
|
|
4566
|
+
/** TODO This will crash if the element is not found */
|
|
4567
|
+
/** TODO This assumes the id references an `<input>` field */
|
|
4568
|
+
const el = document.getElementById(config.id);
|
|
4569
|
+
return el.value === value;
|
|
4570
|
+
},
|
|
4571
|
+
};
|
|
4572
|
+
|
|
4573
|
+
const maxLengthValidator = {
|
|
4574
|
+
name: "maxLength",
|
|
4575
|
+
validation(value, _element, config) {
|
|
4576
|
+
return config.length ? value.length <= config.length : true;
|
|
4577
|
+
},
|
|
4578
|
+
};
|
|
4579
|
+
|
|
4580
|
+
const maxValueValidator = {
|
|
4581
|
+
name: "maxValue",
|
|
4582
|
+
validation(value, _element, config) {
|
|
4583
|
+
return numberValidator$1(value, config, this.name, (value, limit) => value <= limit);
|
|
4584
|
+
},
|
|
4585
|
+
};
|
|
4586
|
+
|
|
4587
|
+
const minDateValidator = {
|
|
4588
|
+
name: "minDate",
|
|
4589
|
+
validation(value, _element, config) {
|
|
4590
|
+
if (isEmpty(value)) {
|
|
4591
|
+
return true;
|
|
4592
|
+
}
|
|
4593
|
+
const normalizedValue = normalizeDateFormat(value);
|
|
4594
|
+
if (!normalizedValue) {
|
|
4595
|
+
return false;
|
|
4596
|
+
}
|
|
4597
|
+
const parsed = FDate.fromIso(normalizedValue);
|
|
4598
|
+
const limit = FDate.fromIso(validLimit(config.limit));
|
|
4599
|
+
return parsed.equals(limit) || parsed.isAfter(limit);
|
|
4600
|
+
},
|
|
4601
|
+
};
|
|
4602
|
+
|
|
4603
|
+
const maxDateValidator = {
|
|
4604
|
+
name: "maxDate",
|
|
4605
|
+
validation(value, _element, config) {
|
|
4606
|
+
if (isEmpty(value)) {
|
|
4607
|
+
return true;
|
|
4608
|
+
}
|
|
4609
|
+
const normalizedValue = normalizeDateFormat(value);
|
|
4610
|
+
if (!normalizedValue) {
|
|
4611
|
+
return false;
|
|
4612
|
+
}
|
|
4613
|
+
const parsed = FDate.fromIso(normalizedValue);
|
|
4614
|
+
const limit = FDate.fromIso(validLimit(config.limit));
|
|
4615
|
+
return parsed.equals(limit) || parsed.isBefore(limit);
|
|
4616
|
+
},
|
|
4617
|
+
};
|
|
4618
|
+
|
|
4619
|
+
const minLengthValidator = {
|
|
4620
|
+
name: "minLength",
|
|
4621
|
+
validation(value, _element, config) {
|
|
4622
|
+
return config.length && value ? value.length >= config.length : true;
|
|
4623
|
+
},
|
|
4624
|
+
};
|
|
4625
|
+
|
|
4626
|
+
const minValueValidator = {
|
|
4627
|
+
name: "minValue",
|
|
4628
|
+
validation(value, _element, config) {
|
|
4629
|
+
return numberValidator$1(value, config, this.name, (value, limit) => value >= limit);
|
|
4630
|
+
},
|
|
4631
|
+
};
|
|
4632
|
+
|
|
4633
|
+
const numberValidator = {
|
|
4634
|
+
name: "number",
|
|
4635
|
+
validation(value) {
|
|
4636
|
+
return isEmpty(value) || isSet(parseNumber(value));
|
|
4637
|
+
},
|
|
4638
|
+
};
|
|
4639
|
+
|
|
4640
|
+
const currencyValidator = {
|
|
4641
|
+
name: "currency",
|
|
4642
|
+
validation(value) {
|
|
4643
|
+
return isEmpty(value) || isSet(parseNumber(value));
|
|
4644
|
+
},
|
|
4645
|
+
};
|
|
4646
|
+
|
|
4647
|
+
const organisationsnummerValidator = {
|
|
4648
|
+
name: "organisationsnummer",
|
|
4649
|
+
validation(value) {
|
|
4650
|
+
return isEmpty(value) || isSet(parseOrganisationsnummer(value));
|
|
4651
|
+
},
|
|
4652
|
+
};
|
|
4653
|
+
|
|
4654
|
+
const PERCENT_REGEXP = /^([-+]?[0-9]+)([,.][0-9]+)?$/;
|
|
4655
|
+
const percentValidator = {
|
|
4656
|
+
name: "percent",
|
|
4657
|
+
validation(value) {
|
|
4658
|
+
const valueWithoutWhitespace = isSet(value)
|
|
4659
|
+
? stripWhitespace(String(value))
|
|
4660
|
+
: value;
|
|
4661
|
+
return (isEmpty(valueWithoutWhitespace) ||
|
|
4662
|
+
PERCENT_REGEXP.test(valueWithoutWhitespace));
|
|
4663
|
+
},
|
|
4664
|
+
};
|
|
4665
|
+
|
|
4666
|
+
const personnummerFormatValidator = {
|
|
4667
|
+
name: "personnummerFormat",
|
|
4668
|
+
validation(value) {
|
|
4669
|
+
return isEmpty(value) || isSet(parsePersonnummer(value));
|
|
4670
|
+
},
|
|
4671
|
+
};
|
|
4672
|
+
|
|
4673
|
+
const personnummerLuhnValidator = {
|
|
4674
|
+
name: "personnummerLuhn",
|
|
4675
|
+
validation(value) {
|
|
4676
|
+
return isEmpty(value) || isSet(parsePersonnummerLuhn(value));
|
|
4677
|
+
},
|
|
4678
|
+
};
|
|
4679
|
+
|
|
4680
|
+
const PHONE_NUMBER_REGEXP = /^(\+?[-_/() ]*(\d[-_/() ]*?){3,17})$/;
|
|
4681
|
+
const phoneNumberValidator = {
|
|
4682
|
+
name: "phoneNumber",
|
|
4683
|
+
validation(value) {
|
|
4684
|
+
if (isEmpty(value)) {
|
|
4685
|
+
return true;
|
|
4686
|
+
}
|
|
4687
|
+
if (!isString(value) || value.length > 21) {
|
|
4688
|
+
return false;
|
|
4689
|
+
}
|
|
4690
|
+
return PHONE_NUMBER_REGEXP.test(value);
|
|
4691
|
+
},
|
|
4692
|
+
};
|
|
4693
|
+
|
|
4694
|
+
const plusgiroValidator = {
|
|
4695
|
+
name: "plusgiro",
|
|
4696
|
+
validation(value) {
|
|
4697
|
+
return isEmpty(value) || isSet(parsePlusgiro(value));
|
|
4698
|
+
},
|
|
4699
|
+
};
|
|
4700
|
+
|
|
4701
|
+
const postalCodeValidator = {
|
|
4702
|
+
name: "postalCode",
|
|
4703
|
+
validation(value) {
|
|
4704
|
+
return isEmpty(value) || isSet(parsePostalCode(value));
|
|
4705
|
+
},
|
|
4706
|
+
};
|
|
4707
|
+
|
|
4708
|
+
const REQUIRED_REGEXP = /^\S+/;
|
|
4709
|
+
function isRelevantElement(input) {
|
|
4710
|
+
return isRadiobuttonOrCheckbox(input) && !input.disabled;
|
|
4711
|
+
}
|
|
4712
|
+
function validateFieldset(fieldset) {
|
|
4713
|
+
const inputs = Array.from(fieldset.elements).filter(isRelevantElement);
|
|
4714
|
+
return inputs.length > 0 ? inputs.some((input) => input.checked) : true;
|
|
4715
|
+
}
|
|
4716
|
+
function validateChecked(element) {
|
|
4717
|
+
return element.checked;
|
|
4718
|
+
}
|
|
4719
|
+
function validateInput(value) {
|
|
4720
|
+
return REQUIRED_REGEXP.test(value);
|
|
4721
|
+
}
|
|
4722
|
+
const requiredValidator = {
|
|
4723
|
+
name: "required",
|
|
4724
|
+
validation(value, element) {
|
|
4725
|
+
if (element instanceof HTMLFieldSetElement) {
|
|
4726
|
+
return validateFieldset(element);
|
|
4727
|
+
}
|
|
4728
|
+
else if (isRadiobuttonOrCheckbox(element)) {
|
|
4729
|
+
return validateChecked(element);
|
|
4730
|
+
}
|
|
4731
|
+
else {
|
|
4732
|
+
return validateInput(value);
|
|
4733
|
+
}
|
|
4734
|
+
},
|
|
4735
|
+
};
|
|
4736
|
+
|
|
4737
|
+
const WHITELIST_REGEXP = /^[a-zA-Z0-9 .,\-()\r\n?+=!:@*\xC0-\xFF]*$/;
|
|
4738
|
+
const whitelistValidator = {
|
|
4739
|
+
name: "whitelist",
|
|
4740
|
+
instant: true,
|
|
4741
|
+
validation(value) {
|
|
4742
|
+
return isEmpty(value) || WHITELIST_REGEXP.test(value);
|
|
4743
|
+
},
|
|
4744
|
+
};
|
|
4745
|
+
|
|
4746
|
+
ValidationService.registerValidator(bankAccountNumberValidator);
|
|
4747
|
+
ValidationService.registerValidator(bankgiroValidator);
|
|
4748
|
+
ValidationService.registerValidator(clearingNumberValidator);
|
|
4749
|
+
ValidationService.registerValidator(dateFormatValidator);
|
|
4750
|
+
ValidationService.registerValidator(dateValidator);
|
|
4751
|
+
ValidationService.registerValidator(decimalValidator);
|
|
4752
|
+
ValidationService.registerValidator(blacklistValidator);
|
|
4753
|
+
ValidationService.registerValidator(emailValidator);
|
|
4754
|
+
ValidationService.registerValidator(integerValidator);
|
|
4755
|
+
ValidationService.registerValidator(greaterThanValidator);
|
|
4756
|
+
ValidationService.registerValidator(invalidDatesValidator);
|
|
4757
|
+
ValidationService.registerValidator(invalidWeekdaysValidator);
|
|
4758
|
+
ValidationService.registerValidator(lessThanValidator);
|
|
4759
|
+
ValidationService.registerValidator(minLengthValidator);
|
|
4760
|
+
ValidationService.registerValidator(matchesValidator);
|
|
4761
|
+
ValidationService.registerValidator(maxLengthValidator);
|
|
4762
|
+
ValidationService.registerValidator(minValueValidator);
|
|
4763
|
+
ValidationService.registerValidator(maxValueValidator);
|
|
4764
|
+
ValidationService.registerValidator(minDateValidator);
|
|
4765
|
+
ValidationService.registerValidator(maxDateValidator);
|
|
4766
|
+
ValidationService.registerValidator(numberValidator);
|
|
4767
|
+
ValidationService.registerValidator(currencyValidator);
|
|
4768
|
+
ValidationService.registerValidator(organisationsnummerValidator);
|
|
4769
|
+
ValidationService.registerValidator(percentValidator);
|
|
4770
|
+
ValidationService.registerValidator(personnummerFormatValidator);
|
|
4771
|
+
ValidationService.registerValidator(personnummerLuhnValidator);
|
|
4772
|
+
ValidationService.registerValidator(phoneNumberValidator);
|
|
4773
|
+
ValidationService.registerValidator(plusgiroValidator);
|
|
4774
|
+
ValidationService.registerValidator(postalCodeValidator);
|
|
4775
|
+
ValidationService.registerValidator(requiredValidator);
|
|
4776
|
+
ValidationService.registerValidator(whitelistValidator);
|
|
4777
|
+
|
|
4778
|
+
/**
|
|
4779
|
+
* This function does nothing and should not be used.
|
|
4780
|
+
*
|
|
4781
|
+
* @public
|
|
4782
|
+
* @deprecated This function does nothing.
|
|
4783
|
+
*/
|
|
4784
|
+
function applyValidationMessages() {
|
|
4785
|
+
/* do nothing */
|
|
4786
|
+
}
|
|
4787
|
+
|
|
4788
|
+
class ElementIdServiceImpl {
|
|
4789
|
+
elementIdMap = new Map();
|
|
4790
|
+
generateElementId(prefix = "fkui") {
|
|
4791
|
+
const id = this.nextId(prefix);
|
|
4792
|
+
if (document.getElementById(id) === null) {
|
|
4793
|
+
return id;
|
|
4794
|
+
}
|
|
4795
|
+
return this.generateElementId(prefix);
|
|
4796
|
+
}
|
|
4797
|
+
nextId(prefix) {
|
|
4798
|
+
let elementIdWithPadding = String(this.getIdFromMap(prefix));
|
|
4799
|
+
while (elementIdWithPadding.length < 4) {
|
|
4800
|
+
elementIdWithPadding = `0${elementIdWithPadding}`;
|
|
4801
|
+
}
|
|
4802
|
+
return `${prefix}-vue-element-${elementIdWithPadding}`;
|
|
4803
|
+
}
|
|
4804
|
+
getIdFromMap(prefix) {
|
|
4805
|
+
const elementId = this.elementIdMap.get(prefix);
|
|
4806
|
+
if (!elementId) {
|
|
4807
|
+
this.elementIdMap.set(prefix, { count: 1 });
|
|
4808
|
+
return 1;
|
|
4809
|
+
}
|
|
4810
|
+
elementId.count++;
|
|
4811
|
+
return elementId.count;
|
|
4812
|
+
}
|
|
4813
|
+
reset() {
|
|
4814
|
+
this.elementIdMap = new Map();
|
|
4815
|
+
}
|
|
4816
|
+
}
|
|
4817
|
+
/**
|
|
4818
|
+
* @public
|
|
4819
|
+
*/
|
|
4820
|
+
const ElementIdService = new ElementIdServiceImpl();
|
|
4821
|
+
|
|
4822
|
+
/* istanbul ignore next: manually tested */
|
|
4823
|
+
const haveSessionStorage = (() => {
|
|
4824
|
+
const test = "fkui.sessionstorage.test";
|
|
4825
|
+
try {
|
|
4826
|
+
if (window.sessionStorage) {
|
|
4827
|
+
window.sessionStorage.setItem(test, "test");
|
|
4828
|
+
window.sessionStorage.removeItem(test);
|
|
4829
|
+
return true;
|
|
4830
|
+
}
|
|
4831
|
+
else {
|
|
4832
|
+
return false;
|
|
4833
|
+
}
|
|
4834
|
+
}
|
|
4835
|
+
catch {
|
|
4836
|
+
/* Safari on iOS throws security exceptions when accessing
|
|
4837
|
+
* sessionstorage in private browsing. */
|
|
4838
|
+
return false;
|
|
4839
|
+
}
|
|
4840
|
+
})();
|
|
4841
|
+
/**
|
|
4842
|
+
* This feature can be used by creating a new file with something like:
|
|
4843
|
+
*
|
|
4844
|
+
* ```
|
|
4845
|
+
* export const MyCustomPersistenceService = new PersistenceService<MyCustomApplicationModel>();
|
|
4846
|
+
* ```
|
|
4847
|
+
*
|
|
4848
|
+
* There is also a simplified version in {@link SimplePersistenceService}.
|
|
4849
|
+
*
|
|
4850
|
+
* @public
|
|
4851
|
+
*/
|
|
4852
|
+
class PersistenceService {
|
|
4853
|
+
cache;
|
|
4854
|
+
constructor() {
|
|
4855
|
+
this.cache = new Map();
|
|
4856
|
+
}
|
|
4857
|
+
set(key, value) {
|
|
4858
|
+
if (this.isSessionPresent) {
|
|
4859
|
+
window.sessionStorage.setItem(key, JSON.stringify(value));
|
|
4860
|
+
}
|
|
4861
|
+
this.cache.set(key, value);
|
|
4862
|
+
}
|
|
4863
|
+
get(key) {
|
|
4864
|
+
const found = this.find(key);
|
|
4865
|
+
if (typeof found !== "undefined") {
|
|
4866
|
+
return found;
|
|
4867
|
+
}
|
|
4868
|
+
throw Error(`PersistenceService cannot find entry with key "${key}"`);
|
|
4869
|
+
}
|
|
4870
|
+
find(key) {
|
|
4871
|
+
if (this.cache.has(key)) {
|
|
4872
|
+
return this.cache.get(key);
|
|
4873
|
+
}
|
|
4874
|
+
const persisted = this.isSessionPresent
|
|
4875
|
+
? window.sessionStorage.getItem(key)
|
|
4876
|
+
: null;
|
|
4877
|
+
if (persisted) {
|
|
4878
|
+
const value = JSON.parse(persisted);
|
|
4879
|
+
this.cache.set(key, value);
|
|
4880
|
+
}
|
|
4881
|
+
return this.cache.get(key);
|
|
4882
|
+
}
|
|
4883
|
+
remove(key) {
|
|
4884
|
+
if (this.isSessionPresent) {
|
|
4885
|
+
window.sessionStorage.removeItem(key);
|
|
4886
|
+
}
|
|
4887
|
+
this.cache.delete(key);
|
|
4888
|
+
}
|
|
4889
|
+
/**
|
|
4890
|
+
* @internal
|
|
4891
|
+
*/
|
|
4892
|
+
/* istanbul ignore next: for mocking in unittests */
|
|
4893
|
+
get isSessionPresent() {
|
|
4894
|
+
return haveSessionStorage;
|
|
4895
|
+
}
|
|
4896
|
+
}
|
|
4897
|
+
|
|
4898
|
+
/**
|
|
4899
|
+
* This feature can be used by creating a new file with something like:
|
|
4900
|
+
*
|
|
4901
|
+
* ```ts
|
|
4902
|
+
* export const MyAwesomePersistenceService = new SimplePersistenceService<MyAwesomeModel>("my-awesome-key");
|
|
4903
|
+
* ```
|
|
4904
|
+
*
|
|
4905
|
+
* There is also a more advanced version in {@link PersistenceService}.
|
|
4906
|
+
*
|
|
4907
|
+
* @public
|
|
4908
|
+
*/
|
|
4909
|
+
class SimplePersistenceService {
|
|
4910
|
+
persistenceService;
|
|
4911
|
+
key;
|
|
4912
|
+
constructor(key) {
|
|
4913
|
+
this.key = key;
|
|
4914
|
+
this.persistenceService = new PersistenceService();
|
|
4915
|
+
}
|
|
4916
|
+
set(value) {
|
|
4917
|
+
this.persistenceService.set(this.key, value);
|
|
4918
|
+
}
|
|
4919
|
+
get() {
|
|
4920
|
+
return this.persistenceService.get(this.key);
|
|
4921
|
+
}
|
|
4922
|
+
find() {
|
|
4923
|
+
return this.persistenceService.find(this.key);
|
|
4924
|
+
}
|
|
4925
|
+
remove() {
|
|
4926
|
+
this.persistenceService.remove(this.key);
|
|
4927
|
+
}
|
|
4928
|
+
}
|
|
4929
|
+
|
|
4930
|
+
/**
|
|
4931
|
+
* @public
|
|
4932
|
+
*/
|
|
4933
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- technical debt
|
|
4934
|
+
class Reference {
|
|
4935
|
+
ref = {};
|
|
4936
|
+
constructor(ref) {
|
|
4937
|
+
Object.assign(this.ref, ref);
|
|
4938
|
+
}
|
|
4939
|
+
}
|
|
4940
|
+
|
|
4941
|
+
/**
|
|
4942
|
+
* Default delay in milliseconds for {@link waitForScreenReader}
|
|
4943
|
+
*
|
|
4944
|
+
* @public
|
|
4945
|
+
*/
|
|
4946
|
+
const SCREEN_READER_DELAY = 100;
|
|
4947
|
+
/**
|
|
4948
|
+
* Defer execution of passed function to allow screen reader to update.
|
|
4949
|
+
* Used if screen reader has not been updated with changed or added
|
|
4950
|
+
* aria attributes before interaction.
|
|
4951
|
+
*
|
|
4952
|
+
* See issue:
|
|
4953
|
+
* https://github.com/nvaccess/nvda/issues/12738
|
|
4954
|
+
*
|
|
4955
|
+
* @public
|
|
4956
|
+
*/
|
|
4957
|
+
function waitForScreenReader(callback, delay = SCREEN_READER_DELAY) {
|
|
4958
|
+
return new Promise((resolve, reject) => {
|
|
4959
|
+
setTimeout(() => {
|
|
4960
|
+
try {
|
|
4961
|
+
const result = callback();
|
|
4962
|
+
resolve(result);
|
|
4963
|
+
}
|
|
4964
|
+
catch (err) {
|
|
4965
|
+
reject(err);
|
|
4966
|
+
}
|
|
4967
|
+
}, delay);
|
|
4968
|
+
});
|
|
4969
|
+
}
|
|
4970
|
+
|
|
4971
|
+
/**
|
|
4972
|
+
* Delay before {@link alertScreenReader} text is removed.
|
|
4973
|
+
*
|
|
4974
|
+
* @internal
|
|
4975
|
+
*/
|
|
4976
|
+
const REMOVE_TEXT_DELAY = 2000;
|
|
4977
|
+
const defaultOptions = {
|
|
4978
|
+
assertive: false,
|
|
4979
|
+
};
|
|
4980
|
+
let wrapper;
|
|
4981
|
+
/**
|
|
4982
|
+
* Trigger screen reader to read the passed text.
|
|
4983
|
+
*
|
|
4984
|
+
* @public
|
|
4985
|
+
* @param text - text to be read by screen reader.
|
|
4986
|
+
* @param options - options for wrapper element attributes.
|
|
4987
|
+
*/
|
|
4988
|
+
function alertScreenReader(text, options) {
|
|
4989
|
+
const mergedOptions = { ...defaultOptions, ...options };
|
|
4990
|
+
const wrapper = getWrapper();
|
|
4991
|
+
updateProperties(mergedOptions);
|
|
4992
|
+
const msg = document.createElement("p");
|
|
4993
|
+
msg.textContent = text;
|
|
4994
|
+
waitForScreenReader(() => {
|
|
4995
|
+
while (wrapper.firstChild) {
|
|
4996
|
+
wrapper.removeChild(wrapper.firstChild);
|
|
4997
|
+
}
|
|
4998
|
+
wrapper.appendChild(msg);
|
|
4999
|
+
setTimeout(() => {
|
|
5000
|
+
// Remove element if it is still in the DOM.
|
|
5001
|
+
if (msg.parentElement === wrapper) {
|
|
5002
|
+
wrapper.removeChild(msg);
|
|
5003
|
+
}
|
|
5004
|
+
}, REMOVE_TEXT_DELAY);
|
|
5005
|
+
});
|
|
5006
|
+
}
|
|
5007
|
+
/**
|
|
5008
|
+
* Create an element for adding text to be read by a screen reader.
|
|
5009
|
+
*
|
|
5010
|
+
* @internal
|
|
5011
|
+
* @param options - options for wrapper element attributes.
|
|
5012
|
+
*/
|
|
5013
|
+
function createScreenReaderWrapper(options) {
|
|
5014
|
+
if (!getWrapper()) {
|
|
5015
|
+
wrapper = document.createElement("div");
|
|
5016
|
+
wrapper.id = "fkui-alert-screen-reader";
|
|
5017
|
+
wrapper.className = "sr-only";
|
|
5018
|
+
updateProperties(options);
|
|
5019
|
+
document.body.appendChild(wrapper);
|
|
5020
|
+
}
|
|
5021
|
+
}
|
|
5022
|
+
/**
|
|
5023
|
+
* Update properties on wrapper element.
|
|
5024
|
+
*
|
|
5025
|
+
* @internal
|
|
5026
|
+
* @param options - options for wrapper element attributes.
|
|
5027
|
+
*/
|
|
5028
|
+
function updateProperties(options) {
|
|
5029
|
+
const wrapper = getWrapper();
|
|
5030
|
+
const ariaLive = options.assertive ? "assertive" : "polite";
|
|
5031
|
+
wrapper.setAttribute("aria-live", ariaLive);
|
|
5032
|
+
}
|
|
5033
|
+
/**
|
|
5034
|
+
* Retrieve wrapper element.
|
|
5035
|
+
*
|
|
5036
|
+
* @internal
|
|
5037
|
+
*/
|
|
5038
|
+
function getWrapper() {
|
|
5039
|
+
return wrapper;
|
|
5040
|
+
}
|
|
5041
|
+
|
|
5042
|
+
if (typeof document !== "undefined") {
|
|
5043
|
+
createScreenReaderWrapper({ assertive: false });
|
|
5044
|
+
}
|
|
5045
|
+
|
|
5046
|
+
export { DATE_REGEXP_WITH_DASH, DecoratedError, index as DomUtils, ElementIdService, FORMAT_3_DIGITS_GROUPS, MissingValueError, POSTAL_CODE_REGEXP, PersistenceService, Reference, SCREEN_READER_DELAY, SimplePersistenceService, TranslationService, ValidationErrorMessageBuilder, ValidationService, WHITESPACE_PATTERN, addFocusListener, alertScreenReader, applyValidationMessages, configLogic, debounce, deepClone, deleteCookie, documentOrderComparator, ensureSet, findCookie, findTabbableElements, flatten, focus, focusFirst, focusLast, formatClearingNumberForBackend, formatNumber, formatPercent, formatPersonnummer, formatPostalCode, getErrorMessages, handleTab, isEmpty, isFieldset, isFocusable, isInvalidDatesConfig, isInvalidWeekdaysConfig, isRadiobuttonOrCheckbox, isSet, isString, isTabbable, isValidDate, isValidatableFormElement, isValidatableHTMLElement, isVisible, isVisibleInViewport, normalizeDateFormat, parseBankAccountNumber, parseBankgiro, parseClearingNumber, parseDate, parseNumber, parseOrganisationsnummer, parsePercent, parsePersonnummer, parsePersonnummerLuhn, parsePlusgiro, parsePostalCode, popFocus, pushFocus, removeFocusListener, restoreFocus, saveFocus, scrollTo, setCookie, stripNull, stripWhitespace, testLuhnChecksum, validChecksum, validLimit, waitForScreenReader };
|
|
5047
|
+
//# sourceMappingURL=index.js.map
|