@pie-element/math-templated 5.1.0 → 5.2.1-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/configure/CHANGELOG.md +11 -0
- package/configure/package.json +5 -5
- package/controller/CHANGELOG.md +17 -0
- package/controller/lib/index.js +1 -1
- package/controller/lib/index.js.map +1 -1
- package/controller/package.json +3 -3
- package/module/configure.js +1 -0
- package/module/controller.js +4869 -0
- package/module/demo.js +67 -0
- package/module/element.js +1 -0
- package/module/index.html +21 -0
- package/module/manifest.json +22 -0
- package/module/print-demo.js +105 -0
- package/module/print.html +18 -0
- package/module/print.js +1 -0
- package/package.json +7 -7
|
@@ -0,0 +1,4869 @@
|
|
|
1
|
+
import * as mv from '@pie-framework/math-validation';
|
|
2
|
+
|
|
3
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
4
|
+
|
|
5
|
+
/** Used for built-in method references. */
|
|
6
|
+
|
|
7
|
+
var objectProto$8 = Object.prototype;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Checks if `value` is likely a prototype object.
|
|
11
|
+
*
|
|
12
|
+
* @private
|
|
13
|
+
* @param {*} value The value to check.
|
|
14
|
+
* @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
|
|
15
|
+
*/
|
|
16
|
+
function isPrototype$2(value) {
|
|
17
|
+
var Ctor = value && value.constructor,
|
|
18
|
+
proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto$8;
|
|
19
|
+
|
|
20
|
+
return value === proto;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var _isPrototype = isPrototype$2;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Creates a unary function that invokes `func` with its argument transformed.
|
|
27
|
+
*
|
|
28
|
+
* @private
|
|
29
|
+
* @param {Function} func The function to wrap.
|
|
30
|
+
* @param {Function} transform The argument transform.
|
|
31
|
+
* @returns {Function} Returns the new function.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
function overArg$1(func, transform) {
|
|
35
|
+
return function(arg) {
|
|
36
|
+
return func(transform(arg));
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
var _overArg = overArg$1;
|
|
41
|
+
|
|
42
|
+
var overArg = _overArg;
|
|
43
|
+
|
|
44
|
+
/* Built-in method references for those with the same name as other `lodash` methods. */
|
|
45
|
+
var nativeKeys$1 = overArg(Object.keys, Object);
|
|
46
|
+
|
|
47
|
+
var _nativeKeys = nativeKeys$1;
|
|
48
|
+
|
|
49
|
+
var isPrototype$1 = _isPrototype,
|
|
50
|
+
nativeKeys = _nativeKeys;
|
|
51
|
+
|
|
52
|
+
/** Used for built-in method references. */
|
|
53
|
+
var objectProto$7 = Object.prototype;
|
|
54
|
+
|
|
55
|
+
/** Used to check objects for own properties. */
|
|
56
|
+
var hasOwnProperty$6 = objectProto$7.hasOwnProperty;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
|
|
60
|
+
*
|
|
61
|
+
* @private
|
|
62
|
+
* @param {Object} object The object to query.
|
|
63
|
+
* @returns {Array} Returns the array of property names.
|
|
64
|
+
*/
|
|
65
|
+
function baseKeys$1(object) {
|
|
66
|
+
if (!isPrototype$1(object)) {
|
|
67
|
+
return nativeKeys(object);
|
|
68
|
+
}
|
|
69
|
+
var result = [];
|
|
70
|
+
for (var key in Object(object)) {
|
|
71
|
+
if (hasOwnProperty$6.call(object, key) && key != 'constructor') {
|
|
72
|
+
result.push(key);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
var _baseKeys = baseKeys$1;
|
|
79
|
+
|
|
80
|
+
/** Detect free variable `global` from Node.js. */
|
|
81
|
+
|
|
82
|
+
var freeGlobal$1 = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
|
|
83
|
+
|
|
84
|
+
var _freeGlobal = freeGlobal$1;
|
|
85
|
+
|
|
86
|
+
var freeGlobal = _freeGlobal;
|
|
87
|
+
|
|
88
|
+
/** Detect free variable `self`. */
|
|
89
|
+
var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
|
|
90
|
+
|
|
91
|
+
/** Used as a reference to the global object. */
|
|
92
|
+
var root$7 = freeGlobal || freeSelf || Function('return this')();
|
|
93
|
+
|
|
94
|
+
var _root = root$7;
|
|
95
|
+
|
|
96
|
+
var root$6 = _root;
|
|
97
|
+
|
|
98
|
+
/** Built-in value references. */
|
|
99
|
+
var Symbol$4 = root$6.Symbol;
|
|
100
|
+
|
|
101
|
+
var _Symbol = Symbol$4;
|
|
102
|
+
|
|
103
|
+
var Symbol$3 = _Symbol;
|
|
104
|
+
|
|
105
|
+
/** Used for built-in method references. */
|
|
106
|
+
var objectProto$6 = Object.prototype;
|
|
107
|
+
|
|
108
|
+
/** Used to check objects for own properties. */
|
|
109
|
+
var hasOwnProperty$5 = objectProto$6.hasOwnProperty;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Used to resolve the
|
|
113
|
+
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
|
|
114
|
+
* of values.
|
|
115
|
+
*/
|
|
116
|
+
var nativeObjectToString$1 = objectProto$6.toString;
|
|
117
|
+
|
|
118
|
+
/** Built-in value references. */
|
|
119
|
+
var symToStringTag$1 = Symbol$3 ? Symbol$3.toStringTag : undefined;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
|
|
123
|
+
*
|
|
124
|
+
* @private
|
|
125
|
+
* @param {*} value The value to query.
|
|
126
|
+
* @returns {string} Returns the raw `toStringTag`.
|
|
127
|
+
*/
|
|
128
|
+
function getRawTag$1(value) {
|
|
129
|
+
var isOwn = hasOwnProperty$5.call(value, symToStringTag$1),
|
|
130
|
+
tag = value[symToStringTag$1];
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
value[symToStringTag$1] = undefined;
|
|
134
|
+
var unmasked = true;
|
|
135
|
+
} catch (e) {}
|
|
136
|
+
|
|
137
|
+
var result = nativeObjectToString$1.call(value);
|
|
138
|
+
if (unmasked) {
|
|
139
|
+
if (isOwn) {
|
|
140
|
+
value[symToStringTag$1] = tag;
|
|
141
|
+
} else {
|
|
142
|
+
delete value[symToStringTag$1];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
var _getRawTag = getRawTag$1;
|
|
149
|
+
|
|
150
|
+
/** Used for built-in method references. */
|
|
151
|
+
|
|
152
|
+
var objectProto$5 = Object.prototype;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Used to resolve the
|
|
156
|
+
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
|
|
157
|
+
* of values.
|
|
158
|
+
*/
|
|
159
|
+
var nativeObjectToString = objectProto$5.toString;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Converts `value` to a string using `Object.prototype.toString`.
|
|
163
|
+
*
|
|
164
|
+
* @private
|
|
165
|
+
* @param {*} value The value to convert.
|
|
166
|
+
* @returns {string} Returns the converted string.
|
|
167
|
+
*/
|
|
168
|
+
function objectToString$1(value) {
|
|
169
|
+
return nativeObjectToString.call(value);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
var _objectToString = objectToString$1;
|
|
173
|
+
|
|
174
|
+
var Symbol$2 = _Symbol,
|
|
175
|
+
getRawTag = _getRawTag,
|
|
176
|
+
objectToString = _objectToString;
|
|
177
|
+
|
|
178
|
+
/** `Object#toString` result references. */
|
|
179
|
+
var nullTag = '[object Null]',
|
|
180
|
+
undefinedTag = '[object Undefined]';
|
|
181
|
+
|
|
182
|
+
/** Built-in value references. */
|
|
183
|
+
var symToStringTag = Symbol$2 ? Symbol$2.toStringTag : undefined;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* The base implementation of `getTag` without fallbacks for buggy environments.
|
|
187
|
+
*
|
|
188
|
+
* @private
|
|
189
|
+
* @param {*} value The value to query.
|
|
190
|
+
* @returns {string} Returns the `toStringTag`.
|
|
191
|
+
*/
|
|
192
|
+
function baseGetTag$4(value) {
|
|
193
|
+
if (value == null) {
|
|
194
|
+
return value === undefined ? undefinedTag : nullTag;
|
|
195
|
+
}
|
|
196
|
+
return (symToStringTag && symToStringTag in Object(value))
|
|
197
|
+
? getRawTag(value)
|
|
198
|
+
: objectToString(value);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
var _baseGetTag = baseGetTag$4;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Checks if `value` is the
|
|
205
|
+
* [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
|
|
206
|
+
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|
207
|
+
*
|
|
208
|
+
* @static
|
|
209
|
+
* @memberOf _
|
|
210
|
+
* @since 0.1.0
|
|
211
|
+
* @category Lang
|
|
212
|
+
* @param {*} value The value to check.
|
|
213
|
+
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
214
|
+
* @example
|
|
215
|
+
*
|
|
216
|
+
* _.isObject({});
|
|
217
|
+
* // => true
|
|
218
|
+
*
|
|
219
|
+
* _.isObject([1, 2, 3]);
|
|
220
|
+
* // => true
|
|
221
|
+
*
|
|
222
|
+
* _.isObject(_.noop);
|
|
223
|
+
* // => true
|
|
224
|
+
*
|
|
225
|
+
* _.isObject(null);
|
|
226
|
+
* // => false
|
|
227
|
+
*/
|
|
228
|
+
|
|
229
|
+
function isObject$2(value) {
|
|
230
|
+
var type = typeof value;
|
|
231
|
+
return value != null && (type == 'object' || type == 'function');
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
var isObject_1 = isObject$2;
|
|
235
|
+
|
|
236
|
+
var baseGetTag$3 = _baseGetTag,
|
|
237
|
+
isObject$1 = isObject_1;
|
|
238
|
+
|
|
239
|
+
/** `Object#toString` result references. */
|
|
240
|
+
var asyncTag = '[object AsyncFunction]',
|
|
241
|
+
funcTag$1 = '[object Function]',
|
|
242
|
+
genTag = '[object GeneratorFunction]',
|
|
243
|
+
proxyTag = '[object Proxy]';
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Checks if `value` is classified as a `Function` object.
|
|
247
|
+
*
|
|
248
|
+
* @static
|
|
249
|
+
* @memberOf _
|
|
250
|
+
* @since 0.1.0
|
|
251
|
+
* @category Lang
|
|
252
|
+
* @param {*} value The value to check.
|
|
253
|
+
* @returns {boolean} Returns `true` if `value` is a function, else `false`.
|
|
254
|
+
* @example
|
|
255
|
+
*
|
|
256
|
+
* _.isFunction(_);
|
|
257
|
+
* // => true
|
|
258
|
+
*
|
|
259
|
+
* _.isFunction(/abc/);
|
|
260
|
+
* // => false
|
|
261
|
+
*/
|
|
262
|
+
function isFunction$2(value) {
|
|
263
|
+
if (!isObject$1(value)) {
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
// The use of `Object#toString` avoids issues with the `typeof` operator
|
|
267
|
+
// in Safari 9 which returns 'object' for typed arrays and other constructors.
|
|
268
|
+
var tag = baseGetTag$3(value);
|
|
269
|
+
return tag == funcTag$1 || tag == genTag || tag == asyncTag || tag == proxyTag;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
var isFunction_1 = isFunction$2;
|
|
273
|
+
|
|
274
|
+
var root$5 = _root;
|
|
275
|
+
|
|
276
|
+
/** Used to detect overreaching core-js shims. */
|
|
277
|
+
var coreJsData$1 = root$5['__core-js_shared__'];
|
|
278
|
+
|
|
279
|
+
var _coreJsData = coreJsData$1;
|
|
280
|
+
|
|
281
|
+
var coreJsData = _coreJsData;
|
|
282
|
+
|
|
283
|
+
/** Used to detect methods masquerading as native. */
|
|
284
|
+
var maskSrcKey = (function() {
|
|
285
|
+
var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
|
|
286
|
+
return uid ? ('Symbol(src)_1.' + uid) : '';
|
|
287
|
+
}());
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Checks if `func` has its source masked.
|
|
291
|
+
*
|
|
292
|
+
* @private
|
|
293
|
+
* @param {Function} func The function to check.
|
|
294
|
+
* @returns {boolean} Returns `true` if `func` is masked, else `false`.
|
|
295
|
+
*/
|
|
296
|
+
function isMasked$1(func) {
|
|
297
|
+
return !!maskSrcKey && (maskSrcKey in func);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
var _isMasked = isMasked$1;
|
|
301
|
+
|
|
302
|
+
/** Used for built-in method references. */
|
|
303
|
+
|
|
304
|
+
var funcProto$1 = Function.prototype;
|
|
305
|
+
|
|
306
|
+
/** Used to resolve the decompiled source of functions. */
|
|
307
|
+
var funcToString$1 = funcProto$1.toString;
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Converts `func` to its source code.
|
|
311
|
+
*
|
|
312
|
+
* @private
|
|
313
|
+
* @param {Function} func The function to convert.
|
|
314
|
+
* @returns {string} Returns the source code.
|
|
315
|
+
*/
|
|
316
|
+
function toSource$2(func) {
|
|
317
|
+
if (func != null) {
|
|
318
|
+
try {
|
|
319
|
+
return funcToString$1.call(func);
|
|
320
|
+
} catch (e) {}
|
|
321
|
+
try {
|
|
322
|
+
return (func + '');
|
|
323
|
+
} catch (e) {}
|
|
324
|
+
}
|
|
325
|
+
return '';
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
var _toSource = toSource$2;
|
|
329
|
+
|
|
330
|
+
var isFunction$1 = isFunction_1,
|
|
331
|
+
isMasked = _isMasked,
|
|
332
|
+
isObject = isObject_1,
|
|
333
|
+
toSource$1 = _toSource;
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Used to match `RegExp`
|
|
337
|
+
* [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
|
|
338
|
+
*/
|
|
339
|
+
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
|
|
340
|
+
|
|
341
|
+
/** Used to detect host constructors (Safari). */
|
|
342
|
+
var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
|
343
|
+
|
|
344
|
+
/** Used for built-in method references. */
|
|
345
|
+
var funcProto = Function.prototype,
|
|
346
|
+
objectProto$4 = Object.prototype;
|
|
347
|
+
|
|
348
|
+
/** Used to resolve the decompiled source of functions. */
|
|
349
|
+
var funcToString = funcProto.toString;
|
|
350
|
+
|
|
351
|
+
/** Used to check objects for own properties. */
|
|
352
|
+
var hasOwnProperty$4 = objectProto$4.hasOwnProperty;
|
|
353
|
+
|
|
354
|
+
/** Used to detect if a method is native. */
|
|
355
|
+
var reIsNative = RegExp('^' +
|
|
356
|
+
funcToString.call(hasOwnProperty$4).replace(reRegExpChar, '\\$&')
|
|
357
|
+
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* The base implementation of `_.isNative` without bad shim checks.
|
|
362
|
+
*
|
|
363
|
+
* @private
|
|
364
|
+
* @param {*} value The value to check.
|
|
365
|
+
* @returns {boolean} Returns `true` if `value` is a native function,
|
|
366
|
+
* else `false`.
|
|
367
|
+
*/
|
|
368
|
+
function baseIsNative$1(value) {
|
|
369
|
+
if (!isObject(value) || isMasked(value)) {
|
|
370
|
+
return false;
|
|
371
|
+
}
|
|
372
|
+
var pattern = isFunction$1(value) ? reIsNative : reIsHostCtor;
|
|
373
|
+
return pattern.test(toSource$1(value));
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
var _baseIsNative = baseIsNative$1;
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Gets the value at `key` of `object`.
|
|
380
|
+
*
|
|
381
|
+
* @private
|
|
382
|
+
* @param {Object} [object] The object to query.
|
|
383
|
+
* @param {string} key The key of the property to get.
|
|
384
|
+
* @returns {*} Returns the property value.
|
|
385
|
+
*/
|
|
386
|
+
|
|
387
|
+
function getValue$1(object, key) {
|
|
388
|
+
return object == null ? undefined : object[key];
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
var _getValue = getValue$1;
|
|
392
|
+
|
|
393
|
+
var baseIsNative = _baseIsNative,
|
|
394
|
+
getValue = _getValue;
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Gets the native function at `key` of `object`.
|
|
398
|
+
*
|
|
399
|
+
* @private
|
|
400
|
+
* @param {Object} object The object to query.
|
|
401
|
+
* @param {string} key The key of the method to get.
|
|
402
|
+
* @returns {*} Returns the function if it's native, else `undefined`.
|
|
403
|
+
*/
|
|
404
|
+
function getNative$6(object, key) {
|
|
405
|
+
var value = getValue(object, key);
|
|
406
|
+
return baseIsNative(value) ? value : undefined;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
var _getNative = getNative$6;
|
|
410
|
+
|
|
411
|
+
var getNative$5 = _getNative,
|
|
412
|
+
root$4 = _root;
|
|
413
|
+
|
|
414
|
+
/* Built-in method references that are verified to be native. */
|
|
415
|
+
var DataView$1 = getNative$5(root$4, 'DataView');
|
|
416
|
+
|
|
417
|
+
var _DataView = DataView$1;
|
|
418
|
+
|
|
419
|
+
var getNative$4 = _getNative,
|
|
420
|
+
root$3 = _root;
|
|
421
|
+
|
|
422
|
+
/* Built-in method references that are verified to be native. */
|
|
423
|
+
var Map$2 = getNative$4(root$3, 'Map');
|
|
424
|
+
|
|
425
|
+
var _Map = Map$2;
|
|
426
|
+
|
|
427
|
+
var getNative$3 = _getNative,
|
|
428
|
+
root$2 = _root;
|
|
429
|
+
|
|
430
|
+
/* Built-in method references that are verified to be native. */
|
|
431
|
+
var Promise$2 = getNative$3(root$2, 'Promise');
|
|
432
|
+
|
|
433
|
+
var _Promise = Promise$2;
|
|
434
|
+
|
|
435
|
+
var getNative$2 = _getNative,
|
|
436
|
+
root$1 = _root;
|
|
437
|
+
|
|
438
|
+
/* Built-in method references that are verified to be native. */
|
|
439
|
+
var Set$1 = getNative$2(root$1, 'Set');
|
|
440
|
+
|
|
441
|
+
var _Set = Set$1;
|
|
442
|
+
|
|
443
|
+
var getNative$1 = _getNative,
|
|
444
|
+
root = _root;
|
|
445
|
+
|
|
446
|
+
/* Built-in method references that are verified to be native. */
|
|
447
|
+
var WeakMap$1 = getNative$1(root, 'WeakMap');
|
|
448
|
+
|
|
449
|
+
var _WeakMap = WeakMap$1;
|
|
450
|
+
|
|
451
|
+
var DataView = _DataView,
|
|
452
|
+
Map$1 = _Map,
|
|
453
|
+
Promise$1 = _Promise,
|
|
454
|
+
Set = _Set,
|
|
455
|
+
WeakMap = _WeakMap,
|
|
456
|
+
baseGetTag$2 = _baseGetTag,
|
|
457
|
+
toSource = _toSource;
|
|
458
|
+
|
|
459
|
+
/** `Object#toString` result references. */
|
|
460
|
+
var mapTag$2 = '[object Map]',
|
|
461
|
+
objectTag$1 = '[object Object]',
|
|
462
|
+
promiseTag = '[object Promise]',
|
|
463
|
+
setTag$2 = '[object Set]',
|
|
464
|
+
weakMapTag$1 = '[object WeakMap]';
|
|
465
|
+
|
|
466
|
+
var dataViewTag$1 = '[object DataView]';
|
|
467
|
+
|
|
468
|
+
/** Used to detect maps, sets, and weakmaps. */
|
|
469
|
+
var dataViewCtorString = toSource(DataView),
|
|
470
|
+
mapCtorString = toSource(Map$1),
|
|
471
|
+
promiseCtorString = toSource(Promise$1),
|
|
472
|
+
setCtorString = toSource(Set),
|
|
473
|
+
weakMapCtorString = toSource(WeakMap);
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Gets the `toStringTag` of `value`.
|
|
477
|
+
*
|
|
478
|
+
* @private
|
|
479
|
+
* @param {*} value The value to query.
|
|
480
|
+
* @returns {string} Returns the `toStringTag`.
|
|
481
|
+
*/
|
|
482
|
+
var getTag$1 = baseGetTag$2;
|
|
483
|
+
|
|
484
|
+
// Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
|
|
485
|
+
if ((DataView && getTag$1(new DataView(new ArrayBuffer(1))) != dataViewTag$1) ||
|
|
486
|
+
(Map$1 && getTag$1(new Map$1) != mapTag$2) ||
|
|
487
|
+
(Promise$1 && getTag$1(Promise$1.resolve()) != promiseTag) ||
|
|
488
|
+
(Set && getTag$1(new Set) != setTag$2) ||
|
|
489
|
+
(WeakMap && getTag$1(new WeakMap) != weakMapTag$1)) {
|
|
490
|
+
getTag$1 = function(value) {
|
|
491
|
+
var result = baseGetTag$2(value),
|
|
492
|
+
Ctor = result == objectTag$1 ? value.constructor : undefined,
|
|
493
|
+
ctorString = Ctor ? toSource(Ctor) : '';
|
|
494
|
+
|
|
495
|
+
if (ctorString) {
|
|
496
|
+
switch (ctorString) {
|
|
497
|
+
case dataViewCtorString: return dataViewTag$1;
|
|
498
|
+
case mapCtorString: return mapTag$2;
|
|
499
|
+
case promiseCtorString: return promiseTag;
|
|
500
|
+
case setCtorString: return setTag$2;
|
|
501
|
+
case weakMapCtorString: return weakMapTag$1;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
return result;
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
var _getTag = getTag$1;
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Checks if `value` is object-like. A value is object-like if it's not `null`
|
|
512
|
+
* and has a `typeof` result of "object".
|
|
513
|
+
*
|
|
514
|
+
* @static
|
|
515
|
+
* @memberOf _
|
|
516
|
+
* @since 4.0.0
|
|
517
|
+
* @category Lang
|
|
518
|
+
* @param {*} value The value to check.
|
|
519
|
+
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
|
520
|
+
* @example
|
|
521
|
+
*
|
|
522
|
+
* _.isObjectLike({});
|
|
523
|
+
* // => true
|
|
524
|
+
*
|
|
525
|
+
* _.isObjectLike([1, 2, 3]);
|
|
526
|
+
* // => true
|
|
527
|
+
*
|
|
528
|
+
* _.isObjectLike(_.noop);
|
|
529
|
+
* // => false
|
|
530
|
+
*
|
|
531
|
+
* _.isObjectLike(null);
|
|
532
|
+
* // => false
|
|
533
|
+
*/
|
|
534
|
+
|
|
535
|
+
function isObjectLike$3(value) {
|
|
536
|
+
return value != null && typeof value == 'object';
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
var isObjectLike_1 = isObjectLike$3;
|
|
540
|
+
|
|
541
|
+
var baseGetTag$1 = _baseGetTag,
|
|
542
|
+
isObjectLike$2 = isObjectLike_1;
|
|
543
|
+
|
|
544
|
+
/** `Object#toString` result references. */
|
|
545
|
+
var argsTag$1 = '[object Arguments]';
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* The base implementation of `_.isArguments`.
|
|
549
|
+
*
|
|
550
|
+
* @private
|
|
551
|
+
* @param {*} value The value to check.
|
|
552
|
+
* @returns {boolean} Returns `true` if `value` is an `arguments` object,
|
|
553
|
+
*/
|
|
554
|
+
function baseIsArguments$1(value) {
|
|
555
|
+
return isObjectLike$2(value) && baseGetTag$1(value) == argsTag$1;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
var _baseIsArguments = baseIsArguments$1;
|
|
559
|
+
|
|
560
|
+
var baseIsArguments = _baseIsArguments,
|
|
561
|
+
isObjectLike$1 = isObjectLike_1;
|
|
562
|
+
|
|
563
|
+
/** Used for built-in method references. */
|
|
564
|
+
var objectProto$3 = Object.prototype;
|
|
565
|
+
|
|
566
|
+
/** Used to check objects for own properties. */
|
|
567
|
+
var hasOwnProperty$3 = objectProto$3.hasOwnProperty;
|
|
568
|
+
|
|
569
|
+
/** Built-in value references. */
|
|
570
|
+
var propertyIsEnumerable = objectProto$3.propertyIsEnumerable;
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Checks if `value` is likely an `arguments` object.
|
|
574
|
+
*
|
|
575
|
+
* @static
|
|
576
|
+
* @memberOf _
|
|
577
|
+
* @since 0.1.0
|
|
578
|
+
* @category Lang
|
|
579
|
+
* @param {*} value The value to check.
|
|
580
|
+
* @returns {boolean} Returns `true` if `value` is an `arguments` object,
|
|
581
|
+
* else `false`.
|
|
582
|
+
* @example
|
|
583
|
+
*
|
|
584
|
+
* _.isArguments(function() { return arguments; }());
|
|
585
|
+
* // => true
|
|
586
|
+
*
|
|
587
|
+
* _.isArguments([1, 2, 3]);
|
|
588
|
+
* // => false
|
|
589
|
+
*/
|
|
590
|
+
var isArguments$1 = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
|
|
591
|
+
return isObjectLike$1(value) && hasOwnProperty$3.call(value, 'callee') &&
|
|
592
|
+
!propertyIsEnumerable.call(value, 'callee');
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
var isArguments_1 = isArguments$1;
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* Checks if `value` is classified as an `Array` object.
|
|
599
|
+
*
|
|
600
|
+
* @static
|
|
601
|
+
* @memberOf _
|
|
602
|
+
* @since 0.1.0
|
|
603
|
+
* @category Lang
|
|
604
|
+
* @param {*} value The value to check.
|
|
605
|
+
* @returns {boolean} Returns `true` if `value` is an array, else `false`.
|
|
606
|
+
* @example
|
|
607
|
+
*
|
|
608
|
+
* _.isArray([1, 2, 3]);
|
|
609
|
+
* // => true
|
|
610
|
+
*
|
|
611
|
+
* _.isArray(document.body.children);
|
|
612
|
+
* // => false
|
|
613
|
+
*
|
|
614
|
+
* _.isArray('abc');
|
|
615
|
+
* // => false
|
|
616
|
+
*
|
|
617
|
+
* _.isArray(_.noop);
|
|
618
|
+
* // => false
|
|
619
|
+
*/
|
|
620
|
+
|
|
621
|
+
var isArray$1 = Array.isArray;
|
|
622
|
+
|
|
623
|
+
var isArray_1 = isArray$1;
|
|
624
|
+
|
|
625
|
+
/** Used as references for various `Number` constants. */
|
|
626
|
+
|
|
627
|
+
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* Checks if `value` is a valid array-like length.
|
|
631
|
+
*
|
|
632
|
+
* **Note:** This method is loosely based on
|
|
633
|
+
* [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
|
|
634
|
+
*
|
|
635
|
+
* @static
|
|
636
|
+
* @memberOf _
|
|
637
|
+
* @since 4.0.0
|
|
638
|
+
* @category Lang
|
|
639
|
+
* @param {*} value The value to check.
|
|
640
|
+
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
|
641
|
+
* @example
|
|
642
|
+
*
|
|
643
|
+
* _.isLength(3);
|
|
644
|
+
* // => true
|
|
645
|
+
*
|
|
646
|
+
* _.isLength(Number.MIN_VALUE);
|
|
647
|
+
* // => false
|
|
648
|
+
*
|
|
649
|
+
* _.isLength(Infinity);
|
|
650
|
+
* // => false
|
|
651
|
+
*
|
|
652
|
+
* _.isLength('3');
|
|
653
|
+
* // => false
|
|
654
|
+
*/
|
|
655
|
+
function isLength$2(value) {
|
|
656
|
+
return typeof value == 'number' &&
|
|
657
|
+
value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
var isLength_1 = isLength$2;
|
|
661
|
+
|
|
662
|
+
var isFunction = isFunction_1,
|
|
663
|
+
isLength$1 = isLength_1;
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* Checks if `value` is array-like. A value is considered array-like if it's
|
|
667
|
+
* not a function and has a `value.length` that's an integer greater than or
|
|
668
|
+
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
|
|
669
|
+
*
|
|
670
|
+
* @static
|
|
671
|
+
* @memberOf _
|
|
672
|
+
* @since 4.0.0
|
|
673
|
+
* @category Lang
|
|
674
|
+
* @param {*} value The value to check.
|
|
675
|
+
* @returns {boolean} Returns `true` if `value` is array-like, else `false`.
|
|
676
|
+
* @example
|
|
677
|
+
*
|
|
678
|
+
* _.isArrayLike([1, 2, 3]);
|
|
679
|
+
* // => true
|
|
680
|
+
*
|
|
681
|
+
* _.isArrayLike(document.body.children);
|
|
682
|
+
* // => true
|
|
683
|
+
*
|
|
684
|
+
* _.isArrayLike('abc');
|
|
685
|
+
* // => true
|
|
686
|
+
*
|
|
687
|
+
* _.isArrayLike(_.noop);
|
|
688
|
+
* // => false
|
|
689
|
+
*/
|
|
690
|
+
function isArrayLike$1(value) {
|
|
691
|
+
return value != null && isLength$1(value.length) && !isFunction(value);
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
var isArrayLike_1 = isArrayLike$1;
|
|
695
|
+
|
|
696
|
+
var isBuffer$1 = {exports: {}};
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* This method returns `false`.
|
|
700
|
+
*
|
|
701
|
+
* @static
|
|
702
|
+
* @memberOf _
|
|
703
|
+
* @since 4.13.0
|
|
704
|
+
* @category Util
|
|
705
|
+
* @returns {boolean} Returns `false`.
|
|
706
|
+
* @example
|
|
707
|
+
*
|
|
708
|
+
* _.times(2, _.stubFalse);
|
|
709
|
+
* // => [false, false]
|
|
710
|
+
*/
|
|
711
|
+
|
|
712
|
+
function stubFalse() {
|
|
713
|
+
return false;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
var stubFalse_1 = stubFalse;
|
|
717
|
+
|
|
718
|
+
(function (module, exports) {
|
|
719
|
+
var root = _root,
|
|
720
|
+
stubFalse = stubFalse_1;
|
|
721
|
+
|
|
722
|
+
/** Detect free variable `exports`. */
|
|
723
|
+
var freeExports = exports && !exports.nodeType && exports;
|
|
724
|
+
|
|
725
|
+
/** Detect free variable `module`. */
|
|
726
|
+
var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
|
|
727
|
+
|
|
728
|
+
/** Detect the popular CommonJS extension `module.exports`. */
|
|
729
|
+
var moduleExports = freeModule && freeModule.exports === freeExports;
|
|
730
|
+
|
|
731
|
+
/** Built-in value references. */
|
|
732
|
+
var Buffer = moduleExports ? root.Buffer : undefined;
|
|
733
|
+
|
|
734
|
+
/* Built-in method references for those with the same name as other `lodash` methods. */
|
|
735
|
+
var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined;
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* Checks if `value` is a buffer.
|
|
739
|
+
*
|
|
740
|
+
* @static
|
|
741
|
+
* @memberOf _
|
|
742
|
+
* @since 4.3.0
|
|
743
|
+
* @category Lang
|
|
744
|
+
* @param {*} value The value to check.
|
|
745
|
+
* @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
|
|
746
|
+
* @example
|
|
747
|
+
*
|
|
748
|
+
* _.isBuffer(new Buffer(2));
|
|
749
|
+
* // => true
|
|
750
|
+
*
|
|
751
|
+
* _.isBuffer(new Uint8Array(2));
|
|
752
|
+
* // => false
|
|
753
|
+
*/
|
|
754
|
+
var isBuffer = nativeIsBuffer || stubFalse;
|
|
755
|
+
|
|
756
|
+
module.exports = isBuffer;
|
|
757
|
+
}(isBuffer$1, isBuffer$1.exports));
|
|
758
|
+
|
|
759
|
+
var baseGetTag = _baseGetTag,
|
|
760
|
+
isLength = isLength_1,
|
|
761
|
+
isObjectLike = isObjectLike_1;
|
|
762
|
+
|
|
763
|
+
/** `Object#toString` result references. */
|
|
764
|
+
var argsTag = '[object Arguments]',
|
|
765
|
+
arrayTag = '[object Array]',
|
|
766
|
+
boolTag = '[object Boolean]',
|
|
767
|
+
dateTag = '[object Date]',
|
|
768
|
+
errorTag = '[object Error]',
|
|
769
|
+
funcTag = '[object Function]',
|
|
770
|
+
mapTag$1 = '[object Map]',
|
|
771
|
+
numberTag = '[object Number]',
|
|
772
|
+
objectTag = '[object Object]',
|
|
773
|
+
regexpTag = '[object RegExp]',
|
|
774
|
+
setTag$1 = '[object Set]',
|
|
775
|
+
stringTag = '[object String]',
|
|
776
|
+
weakMapTag = '[object WeakMap]';
|
|
777
|
+
|
|
778
|
+
var arrayBufferTag = '[object ArrayBuffer]',
|
|
779
|
+
dataViewTag = '[object DataView]',
|
|
780
|
+
float32Tag = '[object Float32Array]',
|
|
781
|
+
float64Tag = '[object Float64Array]',
|
|
782
|
+
int8Tag = '[object Int8Array]',
|
|
783
|
+
int16Tag = '[object Int16Array]',
|
|
784
|
+
int32Tag = '[object Int32Array]',
|
|
785
|
+
uint8Tag = '[object Uint8Array]',
|
|
786
|
+
uint8ClampedTag = '[object Uint8ClampedArray]',
|
|
787
|
+
uint16Tag = '[object Uint16Array]',
|
|
788
|
+
uint32Tag = '[object Uint32Array]';
|
|
789
|
+
|
|
790
|
+
/** Used to identify `toStringTag` values of typed arrays. */
|
|
791
|
+
var typedArrayTags = {};
|
|
792
|
+
typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
|
|
793
|
+
typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
|
|
794
|
+
typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
|
|
795
|
+
typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
|
|
796
|
+
typedArrayTags[uint32Tag] = true;
|
|
797
|
+
typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
|
|
798
|
+
typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
|
|
799
|
+
typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
|
|
800
|
+
typedArrayTags[errorTag] = typedArrayTags[funcTag] =
|
|
801
|
+
typedArrayTags[mapTag$1] = typedArrayTags[numberTag] =
|
|
802
|
+
typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
|
|
803
|
+
typedArrayTags[setTag$1] = typedArrayTags[stringTag] =
|
|
804
|
+
typedArrayTags[weakMapTag] = false;
|
|
805
|
+
|
|
806
|
+
/**
|
|
807
|
+
* The base implementation of `_.isTypedArray` without Node.js optimizations.
|
|
808
|
+
*
|
|
809
|
+
* @private
|
|
810
|
+
* @param {*} value The value to check.
|
|
811
|
+
* @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
|
|
812
|
+
*/
|
|
813
|
+
function baseIsTypedArray$1(value) {
|
|
814
|
+
return isObjectLike(value) &&
|
|
815
|
+
isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
var _baseIsTypedArray = baseIsTypedArray$1;
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* The base implementation of `_.unary` without support for storing metadata.
|
|
822
|
+
*
|
|
823
|
+
* @private
|
|
824
|
+
* @param {Function} func The function to cap arguments for.
|
|
825
|
+
* @returns {Function} Returns the new capped function.
|
|
826
|
+
*/
|
|
827
|
+
|
|
828
|
+
function baseUnary$1(func) {
|
|
829
|
+
return function(value) {
|
|
830
|
+
return func(value);
|
|
831
|
+
};
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
var _baseUnary = baseUnary$1;
|
|
835
|
+
|
|
836
|
+
var _nodeUtil = {exports: {}};
|
|
837
|
+
|
|
838
|
+
(function (module, exports) {
|
|
839
|
+
var freeGlobal = _freeGlobal;
|
|
840
|
+
|
|
841
|
+
/** Detect free variable `exports`. */
|
|
842
|
+
var freeExports = exports && !exports.nodeType && exports;
|
|
843
|
+
|
|
844
|
+
/** Detect free variable `module`. */
|
|
845
|
+
var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
|
|
846
|
+
|
|
847
|
+
/** Detect the popular CommonJS extension `module.exports`. */
|
|
848
|
+
var moduleExports = freeModule && freeModule.exports === freeExports;
|
|
849
|
+
|
|
850
|
+
/** Detect free variable `process` from Node.js. */
|
|
851
|
+
var freeProcess = moduleExports && freeGlobal.process;
|
|
852
|
+
|
|
853
|
+
/** Used to access faster Node.js helpers. */
|
|
854
|
+
var nodeUtil = (function() {
|
|
855
|
+
try {
|
|
856
|
+
// Use `util.types` for Node.js 10+.
|
|
857
|
+
var types = freeModule && freeModule.require && freeModule.require('util').types;
|
|
858
|
+
|
|
859
|
+
if (types) {
|
|
860
|
+
return types;
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
// Legacy `process.binding('util')` for Node.js < 10.
|
|
864
|
+
return freeProcess && freeProcess.binding && freeProcess.binding('util');
|
|
865
|
+
} catch (e) {}
|
|
866
|
+
}());
|
|
867
|
+
|
|
868
|
+
module.exports = nodeUtil;
|
|
869
|
+
}(_nodeUtil, _nodeUtil.exports));
|
|
870
|
+
|
|
871
|
+
var baseIsTypedArray = _baseIsTypedArray,
|
|
872
|
+
baseUnary = _baseUnary,
|
|
873
|
+
nodeUtil = _nodeUtil.exports;
|
|
874
|
+
|
|
875
|
+
/* Node.js helper references. */
|
|
876
|
+
var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
|
|
877
|
+
|
|
878
|
+
/**
|
|
879
|
+
* Checks if `value` is classified as a typed array.
|
|
880
|
+
*
|
|
881
|
+
* @static
|
|
882
|
+
* @memberOf _
|
|
883
|
+
* @since 3.0.0
|
|
884
|
+
* @category Lang
|
|
885
|
+
* @param {*} value The value to check.
|
|
886
|
+
* @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
|
|
887
|
+
* @example
|
|
888
|
+
*
|
|
889
|
+
* _.isTypedArray(new Uint8Array);
|
|
890
|
+
* // => true
|
|
891
|
+
*
|
|
892
|
+
* _.isTypedArray([]);
|
|
893
|
+
* // => false
|
|
894
|
+
*/
|
|
895
|
+
var isTypedArray$1 = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
|
|
896
|
+
|
|
897
|
+
var isTypedArray_1 = isTypedArray$1;
|
|
898
|
+
|
|
899
|
+
var baseKeys = _baseKeys,
|
|
900
|
+
getTag = _getTag,
|
|
901
|
+
isArguments = isArguments_1,
|
|
902
|
+
isArray = isArray_1,
|
|
903
|
+
isArrayLike = isArrayLike_1,
|
|
904
|
+
isBuffer = isBuffer$1.exports,
|
|
905
|
+
isPrototype = _isPrototype,
|
|
906
|
+
isTypedArray = isTypedArray_1;
|
|
907
|
+
|
|
908
|
+
/** `Object#toString` result references. */
|
|
909
|
+
var mapTag = '[object Map]',
|
|
910
|
+
setTag = '[object Set]';
|
|
911
|
+
|
|
912
|
+
/** Used for built-in method references. */
|
|
913
|
+
var objectProto$2 = Object.prototype;
|
|
914
|
+
|
|
915
|
+
/** Used to check objects for own properties. */
|
|
916
|
+
var hasOwnProperty$2 = objectProto$2.hasOwnProperty;
|
|
917
|
+
|
|
918
|
+
/**
|
|
919
|
+
* Checks if `value` is an empty object, collection, map, or set.
|
|
920
|
+
*
|
|
921
|
+
* Objects are considered empty if they have no own enumerable string keyed
|
|
922
|
+
* properties.
|
|
923
|
+
*
|
|
924
|
+
* Array-like values such as `arguments` objects, arrays, buffers, strings, or
|
|
925
|
+
* jQuery-like collections are considered empty if they have a `length` of `0`.
|
|
926
|
+
* Similarly, maps and sets are considered empty if they have a `size` of `0`.
|
|
927
|
+
*
|
|
928
|
+
* @static
|
|
929
|
+
* @memberOf _
|
|
930
|
+
* @since 0.1.0
|
|
931
|
+
* @category Lang
|
|
932
|
+
* @param {*} value The value to check.
|
|
933
|
+
* @returns {boolean} Returns `true` if `value` is empty, else `false`.
|
|
934
|
+
* @example
|
|
935
|
+
*
|
|
936
|
+
* _.isEmpty(null);
|
|
937
|
+
* // => true
|
|
938
|
+
*
|
|
939
|
+
* _.isEmpty(true);
|
|
940
|
+
* // => true
|
|
941
|
+
*
|
|
942
|
+
* _.isEmpty(1);
|
|
943
|
+
* // => true
|
|
944
|
+
*
|
|
945
|
+
* _.isEmpty([1, 2, 3]);
|
|
946
|
+
* // => false
|
|
947
|
+
*
|
|
948
|
+
* _.isEmpty({ 'a': 1 });
|
|
949
|
+
* // => false
|
|
950
|
+
*/
|
|
951
|
+
function isEmpty(value) {
|
|
952
|
+
if (value == null) {
|
|
953
|
+
return true;
|
|
954
|
+
}
|
|
955
|
+
if (isArrayLike(value) &&
|
|
956
|
+
(isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
|
|
957
|
+
isBuffer(value) || isTypedArray(value) || isArguments(value))) {
|
|
958
|
+
return !value.length;
|
|
959
|
+
}
|
|
960
|
+
var tag = getTag(value);
|
|
961
|
+
if (tag == mapTag || tag == setTag) {
|
|
962
|
+
return !value.size;
|
|
963
|
+
}
|
|
964
|
+
if (isPrototype(value)) {
|
|
965
|
+
return !baseKeys(value).length;
|
|
966
|
+
}
|
|
967
|
+
for (var key in value) {
|
|
968
|
+
if (hasOwnProperty$2.call(value, key)) {
|
|
969
|
+
return false;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
return true;
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
var isEmpty_1 = isEmpty;
|
|
976
|
+
|
|
977
|
+
function _typeof(obj) {
|
|
978
|
+
"@babel/helpers - typeof";
|
|
979
|
+
|
|
980
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
981
|
+
return typeof obj;
|
|
982
|
+
} : function (obj) {
|
|
983
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
984
|
+
}, _typeof(obj);
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
function _classCallCheck(instance, Constructor) {
|
|
988
|
+
if (!(instance instanceof Constructor)) {
|
|
989
|
+
throw new TypeError("Cannot call a class as a function");
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
function _toPrimitive(input, hint) {
|
|
994
|
+
if (_typeof(input) !== "object" || input === null) return input;
|
|
995
|
+
var prim = input[Symbol.toPrimitive];
|
|
996
|
+
if (prim !== undefined) {
|
|
997
|
+
var res = prim.call(input, hint || "default");
|
|
998
|
+
if (_typeof(res) !== "object") return res;
|
|
999
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
1000
|
+
}
|
|
1001
|
+
return (hint === "string" ? String : Number)(input);
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
function _toPropertyKey(arg) {
|
|
1005
|
+
var key = _toPrimitive(arg, "string");
|
|
1006
|
+
return _typeof(key) === "symbol" ? key : String(key);
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
function _defineProperties(target, props) {
|
|
1010
|
+
for (var i = 0; i < props.length; i++) {
|
|
1011
|
+
var descriptor = props[i];
|
|
1012
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
1013
|
+
descriptor.configurable = true;
|
|
1014
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
1015
|
+
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
1019
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
1020
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
1021
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
1022
|
+
writable: false
|
|
1023
|
+
});
|
|
1024
|
+
return Constructor;
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
function _assertThisInitialized(self) {
|
|
1028
|
+
if (self === void 0) {
|
|
1029
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
1030
|
+
}
|
|
1031
|
+
return self;
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
function _setPrototypeOf(o, p) {
|
|
1035
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
1036
|
+
o.__proto__ = p;
|
|
1037
|
+
return o;
|
|
1038
|
+
};
|
|
1039
|
+
return _setPrototypeOf(o, p);
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
function _inherits(subClass, superClass) {
|
|
1043
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
1044
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
1045
|
+
}
|
|
1046
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
1047
|
+
constructor: {
|
|
1048
|
+
value: subClass,
|
|
1049
|
+
writable: true,
|
|
1050
|
+
configurable: true
|
|
1051
|
+
}
|
|
1052
|
+
});
|
|
1053
|
+
Object.defineProperty(subClass, "prototype", {
|
|
1054
|
+
writable: false
|
|
1055
|
+
});
|
|
1056
|
+
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
function _possibleConstructorReturn(self, call) {
|
|
1060
|
+
if (call && (_typeof(call) === "object" || typeof call === "function")) {
|
|
1061
|
+
return call;
|
|
1062
|
+
} else if (call !== void 0) {
|
|
1063
|
+
throw new TypeError("Derived constructors may only return object or undefined");
|
|
1064
|
+
}
|
|
1065
|
+
return _assertThisInitialized(self);
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
function _getPrototypeOf(o) {
|
|
1069
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
|
|
1070
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
1071
|
+
};
|
|
1072
|
+
return _getPrototypeOf(o);
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
function _defineProperty(obj, key, value) {
|
|
1076
|
+
key = _toPropertyKey(key);
|
|
1077
|
+
if (key in obj) {
|
|
1078
|
+
Object.defineProperty(obj, key, {
|
|
1079
|
+
value: value,
|
|
1080
|
+
enumerable: true,
|
|
1081
|
+
configurable: true,
|
|
1082
|
+
writable: true
|
|
1083
|
+
});
|
|
1084
|
+
} else {
|
|
1085
|
+
obj[key] = value;
|
|
1086
|
+
}
|
|
1087
|
+
return obj;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
function _arrayWithHoles(arr) {
|
|
1091
|
+
if (Array.isArray(arr)) return arr;
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
function _iterableToArray(iter) {
|
|
1095
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
function _arrayLikeToArray(arr, len) {
|
|
1099
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
1100
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
1101
|
+
return arr2;
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
1105
|
+
if (!o) return;
|
|
1106
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
1107
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
1108
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
1109
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
1110
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
function _nonIterableRest() {
|
|
1114
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
function _toArray(arr) {
|
|
1118
|
+
return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest();
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
function ownKeys$6(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
1122
|
+
function _objectSpread$6(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$6(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$6(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
1123
|
+
var consoleLogger = {
|
|
1124
|
+
type: 'logger',
|
|
1125
|
+
log: function log(args) {
|
|
1126
|
+
this.output('log', args);
|
|
1127
|
+
},
|
|
1128
|
+
warn: function warn(args) {
|
|
1129
|
+
this.output('warn', args);
|
|
1130
|
+
},
|
|
1131
|
+
error: function error(args) {
|
|
1132
|
+
this.output('error', args);
|
|
1133
|
+
},
|
|
1134
|
+
output: function output(type, args) {
|
|
1135
|
+
if (console && console[type]) console[type].apply(console, args);
|
|
1136
|
+
}
|
|
1137
|
+
};
|
|
1138
|
+
var Logger = function () {
|
|
1139
|
+
function Logger(concreteLogger) {
|
|
1140
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1141
|
+
_classCallCheck(this, Logger);
|
|
1142
|
+
this.init(concreteLogger, options);
|
|
1143
|
+
}
|
|
1144
|
+
_createClass(Logger, [{
|
|
1145
|
+
key: "init",
|
|
1146
|
+
value: function init(concreteLogger) {
|
|
1147
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1148
|
+
this.prefix = options.prefix || 'i18next:';
|
|
1149
|
+
this.logger = concreteLogger || consoleLogger;
|
|
1150
|
+
this.options = options;
|
|
1151
|
+
this.debug = options.debug;
|
|
1152
|
+
}
|
|
1153
|
+
}, {
|
|
1154
|
+
key: "setDebug",
|
|
1155
|
+
value: function setDebug(bool) {
|
|
1156
|
+
this.debug = bool;
|
|
1157
|
+
}
|
|
1158
|
+
}, {
|
|
1159
|
+
key: "log",
|
|
1160
|
+
value: function log() {
|
|
1161
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1162
|
+
args[_key] = arguments[_key];
|
|
1163
|
+
}
|
|
1164
|
+
return this.forward(args, 'log', '', true);
|
|
1165
|
+
}
|
|
1166
|
+
}, {
|
|
1167
|
+
key: "warn",
|
|
1168
|
+
value: function warn() {
|
|
1169
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
1170
|
+
args[_key2] = arguments[_key2];
|
|
1171
|
+
}
|
|
1172
|
+
return this.forward(args, 'warn', '', true);
|
|
1173
|
+
}
|
|
1174
|
+
}, {
|
|
1175
|
+
key: "error",
|
|
1176
|
+
value: function error() {
|
|
1177
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
1178
|
+
args[_key3] = arguments[_key3];
|
|
1179
|
+
}
|
|
1180
|
+
return this.forward(args, 'error', '');
|
|
1181
|
+
}
|
|
1182
|
+
}, {
|
|
1183
|
+
key: "deprecate",
|
|
1184
|
+
value: function deprecate() {
|
|
1185
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
1186
|
+
args[_key4] = arguments[_key4];
|
|
1187
|
+
}
|
|
1188
|
+
return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true);
|
|
1189
|
+
}
|
|
1190
|
+
}, {
|
|
1191
|
+
key: "forward",
|
|
1192
|
+
value: function forward(args, lvl, prefix, debugOnly) {
|
|
1193
|
+
if (debugOnly && !this.debug) return null;
|
|
1194
|
+
if (typeof args[0] === 'string') args[0] = "".concat(prefix).concat(this.prefix, " ").concat(args[0]);
|
|
1195
|
+
return this.logger[lvl](args);
|
|
1196
|
+
}
|
|
1197
|
+
}, {
|
|
1198
|
+
key: "create",
|
|
1199
|
+
value: function create(moduleName) {
|
|
1200
|
+
return new Logger(this.logger, _objectSpread$6(_objectSpread$6({}, {
|
|
1201
|
+
prefix: "".concat(this.prefix, ":").concat(moduleName, ":")
|
|
1202
|
+
}), this.options));
|
|
1203
|
+
}
|
|
1204
|
+
}, {
|
|
1205
|
+
key: "clone",
|
|
1206
|
+
value: function clone(options) {
|
|
1207
|
+
options = options || this.options;
|
|
1208
|
+
options.prefix = options.prefix || this.prefix;
|
|
1209
|
+
return new Logger(this.logger, options);
|
|
1210
|
+
}
|
|
1211
|
+
}]);
|
|
1212
|
+
return Logger;
|
|
1213
|
+
}();
|
|
1214
|
+
var baseLogger = new Logger();
|
|
1215
|
+
|
|
1216
|
+
var EventEmitter = function () {
|
|
1217
|
+
function EventEmitter() {
|
|
1218
|
+
_classCallCheck(this, EventEmitter);
|
|
1219
|
+
this.observers = {};
|
|
1220
|
+
}
|
|
1221
|
+
_createClass(EventEmitter, [{
|
|
1222
|
+
key: "on",
|
|
1223
|
+
value: function on(events, listener) {
|
|
1224
|
+
var _this = this;
|
|
1225
|
+
events.split(' ').forEach(function (event) {
|
|
1226
|
+
_this.observers[event] = _this.observers[event] || [];
|
|
1227
|
+
_this.observers[event].push(listener);
|
|
1228
|
+
});
|
|
1229
|
+
return this;
|
|
1230
|
+
}
|
|
1231
|
+
}, {
|
|
1232
|
+
key: "off",
|
|
1233
|
+
value: function off(event, listener) {
|
|
1234
|
+
if (!this.observers[event]) return;
|
|
1235
|
+
if (!listener) {
|
|
1236
|
+
delete this.observers[event];
|
|
1237
|
+
return;
|
|
1238
|
+
}
|
|
1239
|
+
this.observers[event] = this.observers[event].filter(function (l) {
|
|
1240
|
+
return l !== listener;
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
1243
|
+
}, {
|
|
1244
|
+
key: "emit",
|
|
1245
|
+
value: function emit(event) {
|
|
1246
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1247
|
+
args[_key - 1] = arguments[_key];
|
|
1248
|
+
}
|
|
1249
|
+
if (this.observers[event]) {
|
|
1250
|
+
var cloned = [].concat(this.observers[event]);
|
|
1251
|
+
cloned.forEach(function (observer) {
|
|
1252
|
+
observer.apply(void 0, args);
|
|
1253
|
+
});
|
|
1254
|
+
}
|
|
1255
|
+
if (this.observers['*']) {
|
|
1256
|
+
var _cloned = [].concat(this.observers['*']);
|
|
1257
|
+
_cloned.forEach(function (observer) {
|
|
1258
|
+
observer.apply(observer, [event].concat(args));
|
|
1259
|
+
});
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
}]);
|
|
1263
|
+
return EventEmitter;
|
|
1264
|
+
}();
|
|
1265
|
+
|
|
1266
|
+
function defer() {
|
|
1267
|
+
var res;
|
|
1268
|
+
var rej;
|
|
1269
|
+
var promise = new Promise(function (resolve, reject) {
|
|
1270
|
+
res = resolve;
|
|
1271
|
+
rej = reject;
|
|
1272
|
+
});
|
|
1273
|
+
promise.resolve = res;
|
|
1274
|
+
promise.reject = rej;
|
|
1275
|
+
return promise;
|
|
1276
|
+
}
|
|
1277
|
+
function makeString(object) {
|
|
1278
|
+
if (object == null) return '';
|
|
1279
|
+
return '' + object;
|
|
1280
|
+
}
|
|
1281
|
+
function copy(a, s, t) {
|
|
1282
|
+
a.forEach(function (m) {
|
|
1283
|
+
if (s[m]) t[m] = s[m];
|
|
1284
|
+
});
|
|
1285
|
+
}
|
|
1286
|
+
function getLastOfPath(object, path, Empty) {
|
|
1287
|
+
function cleanKey(key) {
|
|
1288
|
+
return key && key.indexOf('###') > -1 ? key.replace(/###/g, '.') : key;
|
|
1289
|
+
}
|
|
1290
|
+
function canNotTraverseDeeper() {
|
|
1291
|
+
return !object || typeof object === 'string';
|
|
1292
|
+
}
|
|
1293
|
+
var stack = typeof path !== 'string' ? [].concat(path) : path.split('.');
|
|
1294
|
+
while (stack.length > 1) {
|
|
1295
|
+
if (canNotTraverseDeeper()) return {};
|
|
1296
|
+
var key = cleanKey(stack.shift());
|
|
1297
|
+
if (!object[key] && Empty) object[key] = new Empty();
|
|
1298
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
1299
|
+
object = object[key];
|
|
1300
|
+
} else {
|
|
1301
|
+
object = {};
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
if (canNotTraverseDeeper()) return {};
|
|
1305
|
+
return {
|
|
1306
|
+
obj: object,
|
|
1307
|
+
k: cleanKey(stack.shift())
|
|
1308
|
+
};
|
|
1309
|
+
}
|
|
1310
|
+
function setPath(object, path, newValue) {
|
|
1311
|
+
var _getLastOfPath = getLastOfPath(object, path, Object),
|
|
1312
|
+
obj = _getLastOfPath.obj,
|
|
1313
|
+
k = _getLastOfPath.k;
|
|
1314
|
+
obj[k] = newValue;
|
|
1315
|
+
}
|
|
1316
|
+
function pushPath(object, path, newValue, concat) {
|
|
1317
|
+
var _getLastOfPath2 = getLastOfPath(object, path, Object),
|
|
1318
|
+
obj = _getLastOfPath2.obj,
|
|
1319
|
+
k = _getLastOfPath2.k;
|
|
1320
|
+
obj[k] = obj[k] || [];
|
|
1321
|
+
if (concat) obj[k] = obj[k].concat(newValue);
|
|
1322
|
+
if (!concat) obj[k].push(newValue);
|
|
1323
|
+
}
|
|
1324
|
+
function getPath(object, path) {
|
|
1325
|
+
var _getLastOfPath3 = getLastOfPath(object, path),
|
|
1326
|
+
obj = _getLastOfPath3.obj,
|
|
1327
|
+
k = _getLastOfPath3.k;
|
|
1328
|
+
if (!obj) return undefined;
|
|
1329
|
+
return obj[k];
|
|
1330
|
+
}
|
|
1331
|
+
function getPathWithDefaults(data, defaultData, key) {
|
|
1332
|
+
var value = getPath(data, key);
|
|
1333
|
+
if (value !== undefined) {
|
|
1334
|
+
return value;
|
|
1335
|
+
}
|
|
1336
|
+
return getPath(defaultData, key);
|
|
1337
|
+
}
|
|
1338
|
+
function deepExtend(target, source, overwrite) {
|
|
1339
|
+
for (var prop in source) {
|
|
1340
|
+
if (prop !== '__proto__' && prop !== 'constructor') {
|
|
1341
|
+
if (prop in target) {
|
|
1342
|
+
if (typeof target[prop] === 'string' || target[prop] instanceof String || typeof source[prop] === 'string' || source[prop] instanceof String) {
|
|
1343
|
+
if (overwrite) target[prop] = source[prop];
|
|
1344
|
+
} else {
|
|
1345
|
+
deepExtend(target[prop], source[prop], overwrite);
|
|
1346
|
+
}
|
|
1347
|
+
} else {
|
|
1348
|
+
target[prop] = source[prop];
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
return target;
|
|
1353
|
+
}
|
|
1354
|
+
function regexEscape(str) {
|
|
1355
|
+
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
|
|
1356
|
+
}
|
|
1357
|
+
var _entityMap = {
|
|
1358
|
+
'&': '&',
|
|
1359
|
+
'<': '<',
|
|
1360
|
+
'>': '>',
|
|
1361
|
+
'"': '"',
|
|
1362
|
+
"'": ''',
|
|
1363
|
+
'/': '/'
|
|
1364
|
+
};
|
|
1365
|
+
function escape(data) {
|
|
1366
|
+
if (typeof data === 'string') {
|
|
1367
|
+
return data.replace(/[&<>"'\/]/g, function (s) {
|
|
1368
|
+
return _entityMap[s];
|
|
1369
|
+
});
|
|
1370
|
+
}
|
|
1371
|
+
return data;
|
|
1372
|
+
}
|
|
1373
|
+
var isIE10 = typeof window !== 'undefined' && window.navigator && typeof window.navigator.userAgentData === 'undefined' && window.navigator.userAgent && window.navigator.userAgent.indexOf('MSIE') > -1;
|
|
1374
|
+
var chars = [' ', ',', '?', '!', ';'];
|
|
1375
|
+
function looksLikeObjectPath(key, nsSeparator, keySeparator) {
|
|
1376
|
+
nsSeparator = nsSeparator || '';
|
|
1377
|
+
keySeparator = keySeparator || '';
|
|
1378
|
+
var possibleChars = chars.filter(function (c) {
|
|
1379
|
+
return nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0;
|
|
1380
|
+
});
|
|
1381
|
+
if (possibleChars.length === 0) return true;
|
|
1382
|
+
var r = new RegExp("(".concat(possibleChars.map(function (c) {
|
|
1383
|
+
return c === '?' ? '\\?' : c;
|
|
1384
|
+
}).join('|'), ")"));
|
|
1385
|
+
var matched = !r.test(key);
|
|
1386
|
+
if (!matched) {
|
|
1387
|
+
var ki = key.indexOf(keySeparator);
|
|
1388
|
+
if (ki > 0 && !r.test(key.substring(0, ki))) {
|
|
1389
|
+
matched = true;
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
return matched;
|
|
1393
|
+
}
|
|
1394
|
+
function deepFind(obj, path) {
|
|
1395
|
+
var keySeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.';
|
|
1396
|
+
if (!obj) return undefined;
|
|
1397
|
+
if (obj[path]) return obj[path];
|
|
1398
|
+
var paths = path.split(keySeparator);
|
|
1399
|
+
var current = obj;
|
|
1400
|
+
for (var i = 0; i < paths.length; ++i) {
|
|
1401
|
+
if (!current) return undefined;
|
|
1402
|
+
if (typeof current[paths[i]] === 'string' && i + 1 < paths.length) {
|
|
1403
|
+
return undefined;
|
|
1404
|
+
}
|
|
1405
|
+
if (current[paths[i]] === undefined) {
|
|
1406
|
+
var j = 2;
|
|
1407
|
+
var p = paths.slice(i, i + j).join(keySeparator);
|
|
1408
|
+
var mix = current[p];
|
|
1409
|
+
while (mix === undefined && paths.length > i + j) {
|
|
1410
|
+
j++;
|
|
1411
|
+
p = paths.slice(i, i + j).join(keySeparator);
|
|
1412
|
+
mix = current[p];
|
|
1413
|
+
}
|
|
1414
|
+
if (mix === undefined) return undefined;
|
|
1415
|
+
if (mix === null) return null;
|
|
1416
|
+
if (path.endsWith(p)) {
|
|
1417
|
+
if (typeof mix === 'string') return mix;
|
|
1418
|
+
if (p && typeof mix[p] === 'string') return mix[p];
|
|
1419
|
+
}
|
|
1420
|
+
var joinedPath = paths.slice(i + j).join(keySeparator);
|
|
1421
|
+
if (joinedPath) return deepFind(mix, joinedPath, keySeparator);
|
|
1422
|
+
return undefined;
|
|
1423
|
+
}
|
|
1424
|
+
current = current[paths[i]];
|
|
1425
|
+
}
|
|
1426
|
+
return current;
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
function ownKeys$5(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
1430
|
+
function _objectSpread$5(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$5(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$5(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
1431
|
+
function _createSuper$3(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$3(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
1432
|
+
function _isNativeReflectConstruct$3() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
1433
|
+
var ResourceStore = function (_EventEmitter) {
|
|
1434
|
+
_inherits(ResourceStore, _EventEmitter);
|
|
1435
|
+
var _super = _createSuper$3(ResourceStore);
|
|
1436
|
+
function ResourceStore(data) {
|
|
1437
|
+
var _this;
|
|
1438
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
1439
|
+
ns: ['translation'],
|
|
1440
|
+
defaultNS: 'translation'
|
|
1441
|
+
};
|
|
1442
|
+
_classCallCheck(this, ResourceStore);
|
|
1443
|
+
_this = _super.call(this);
|
|
1444
|
+
if (isIE10) {
|
|
1445
|
+
EventEmitter.call(_assertThisInitialized(_this));
|
|
1446
|
+
}
|
|
1447
|
+
_this.data = data || {};
|
|
1448
|
+
_this.options = options;
|
|
1449
|
+
if (_this.options.keySeparator === undefined) {
|
|
1450
|
+
_this.options.keySeparator = '.';
|
|
1451
|
+
}
|
|
1452
|
+
if (_this.options.ignoreJSONStructure === undefined) {
|
|
1453
|
+
_this.options.ignoreJSONStructure = true;
|
|
1454
|
+
}
|
|
1455
|
+
return _this;
|
|
1456
|
+
}
|
|
1457
|
+
_createClass(ResourceStore, [{
|
|
1458
|
+
key: "addNamespaces",
|
|
1459
|
+
value: function addNamespaces(ns) {
|
|
1460
|
+
if (this.options.ns.indexOf(ns) < 0) {
|
|
1461
|
+
this.options.ns.push(ns);
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
}, {
|
|
1465
|
+
key: "removeNamespaces",
|
|
1466
|
+
value: function removeNamespaces(ns) {
|
|
1467
|
+
var index = this.options.ns.indexOf(ns);
|
|
1468
|
+
if (index > -1) {
|
|
1469
|
+
this.options.ns.splice(index, 1);
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
}, {
|
|
1473
|
+
key: "getResource",
|
|
1474
|
+
value: function getResource(lng, ns, key) {
|
|
1475
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1476
|
+
var keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
1477
|
+
var ignoreJSONStructure = options.ignoreJSONStructure !== undefined ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
|
|
1478
|
+
var path = [lng, ns];
|
|
1479
|
+
if (key && typeof key !== 'string') path = path.concat(key);
|
|
1480
|
+
if (key && typeof key === 'string') path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
1481
|
+
if (lng.indexOf('.') > -1) {
|
|
1482
|
+
path = lng.split('.');
|
|
1483
|
+
}
|
|
1484
|
+
var result = getPath(this.data, path);
|
|
1485
|
+
if (result || !ignoreJSONStructure || typeof key !== 'string') return result;
|
|
1486
|
+
return deepFind(this.data && this.data[lng] && this.data[lng][ns], key, keySeparator);
|
|
1487
|
+
}
|
|
1488
|
+
}, {
|
|
1489
|
+
key: "addResource",
|
|
1490
|
+
value: function addResource(lng, ns, key, value) {
|
|
1491
|
+
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
|
1492
|
+
silent: false
|
|
1493
|
+
};
|
|
1494
|
+
var keySeparator = this.options.keySeparator;
|
|
1495
|
+
if (keySeparator === undefined) keySeparator = '.';
|
|
1496
|
+
var path = [lng, ns];
|
|
1497
|
+
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
1498
|
+
if (lng.indexOf('.') > -1) {
|
|
1499
|
+
path = lng.split('.');
|
|
1500
|
+
value = ns;
|
|
1501
|
+
ns = path[1];
|
|
1502
|
+
}
|
|
1503
|
+
this.addNamespaces(ns);
|
|
1504
|
+
setPath(this.data, path, value);
|
|
1505
|
+
if (!options.silent) this.emit('added', lng, ns, key, value);
|
|
1506
|
+
}
|
|
1507
|
+
}, {
|
|
1508
|
+
key: "addResources",
|
|
1509
|
+
value: function addResources(lng, ns, resources) {
|
|
1510
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
1511
|
+
silent: false
|
|
1512
|
+
};
|
|
1513
|
+
for (var m in resources) {
|
|
1514
|
+
if (typeof resources[m] === 'string' || Object.prototype.toString.apply(resources[m]) === '[object Array]') this.addResource(lng, ns, m, resources[m], {
|
|
1515
|
+
silent: true
|
|
1516
|
+
});
|
|
1517
|
+
}
|
|
1518
|
+
if (!options.silent) this.emit('added', lng, ns, resources);
|
|
1519
|
+
}
|
|
1520
|
+
}, {
|
|
1521
|
+
key: "addResourceBundle",
|
|
1522
|
+
value: function addResourceBundle(lng, ns, resources, deep, overwrite) {
|
|
1523
|
+
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {
|
|
1524
|
+
silent: false
|
|
1525
|
+
};
|
|
1526
|
+
var path = [lng, ns];
|
|
1527
|
+
if (lng.indexOf('.') > -1) {
|
|
1528
|
+
path = lng.split('.');
|
|
1529
|
+
deep = resources;
|
|
1530
|
+
resources = ns;
|
|
1531
|
+
ns = path[1];
|
|
1532
|
+
}
|
|
1533
|
+
this.addNamespaces(ns);
|
|
1534
|
+
var pack = getPath(this.data, path) || {};
|
|
1535
|
+
if (deep) {
|
|
1536
|
+
deepExtend(pack, resources, overwrite);
|
|
1537
|
+
} else {
|
|
1538
|
+
pack = _objectSpread$5(_objectSpread$5({}, pack), resources);
|
|
1539
|
+
}
|
|
1540
|
+
setPath(this.data, path, pack);
|
|
1541
|
+
if (!options.silent) this.emit('added', lng, ns, resources);
|
|
1542
|
+
}
|
|
1543
|
+
}, {
|
|
1544
|
+
key: "removeResourceBundle",
|
|
1545
|
+
value: function removeResourceBundle(lng, ns) {
|
|
1546
|
+
if (this.hasResourceBundle(lng, ns)) {
|
|
1547
|
+
delete this.data[lng][ns];
|
|
1548
|
+
}
|
|
1549
|
+
this.removeNamespaces(ns);
|
|
1550
|
+
this.emit('removed', lng, ns);
|
|
1551
|
+
}
|
|
1552
|
+
}, {
|
|
1553
|
+
key: "hasResourceBundle",
|
|
1554
|
+
value: function hasResourceBundle(lng, ns) {
|
|
1555
|
+
return this.getResource(lng, ns) !== undefined;
|
|
1556
|
+
}
|
|
1557
|
+
}, {
|
|
1558
|
+
key: "getResourceBundle",
|
|
1559
|
+
value: function getResourceBundle(lng, ns) {
|
|
1560
|
+
if (!ns) ns = this.options.defaultNS;
|
|
1561
|
+
if (this.options.compatibilityAPI === 'v1') return _objectSpread$5(_objectSpread$5({}, {}), this.getResource(lng, ns));
|
|
1562
|
+
return this.getResource(lng, ns);
|
|
1563
|
+
}
|
|
1564
|
+
}, {
|
|
1565
|
+
key: "getDataByLanguage",
|
|
1566
|
+
value: function getDataByLanguage(lng) {
|
|
1567
|
+
return this.data[lng];
|
|
1568
|
+
}
|
|
1569
|
+
}, {
|
|
1570
|
+
key: "hasLanguageSomeTranslations",
|
|
1571
|
+
value: function hasLanguageSomeTranslations(lng) {
|
|
1572
|
+
var data = this.getDataByLanguage(lng);
|
|
1573
|
+
var n = data && Object.keys(data) || [];
|
|
1574
|
+
return !!n.find(function (v) {
|
|
1575
|
+
return data[v] && Object.keys(data[v]).length > 0;
|
|
1576
|
+
});
|
|
1577
|
+
}
|
|
1578
|
+
}, {
|
|
1579
|
+
key: "toJSON",
|
|
1580
|
+
value: function toJSON() {
|
|
1581
|
+
return this.data;
|
|
1582
|
+
}
|
|
1583
|
+
}]);
|
|
1584
|
+
return ResourceStore;
|
|
1585
|
+
}(EventEmitter);
|
|
1586
|
+
|
|
1587
|
+
var postProcessor = {
|
|
1588
|
+
processors: {},
|
|
1589
|
+
addPostProcessor: function addPostProcessor(module) {
|
|
1590
|
+
this.processors[module.name] = module;
|
|
1591
|
+
},
|
|
1592
|
+
handle: function handle(processors, value, key, options, translator) {
|
|
1593
|
+
var _this = this;
|
|
1594
|
+
processors.forEach(function (processor) {
|
|
1595
|
+
if (_this.processors[processor]) value = _this.processors[processor].process(value, key, options, translator);
|
|
1596
|
+
});
|
|
1597
|
+
return value;
|
|
1598
|
+
}
|
|
1599
|
+
};
|
|
1600
|
+
|
|
1601
|
+
function ownKeys$4(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
1602
|
+
function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$4(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$4(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
1603
|
+
function _createSuper$2(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$2(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
1604
|
+
function _isNativeReflectConstruct$2() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
1605
|
+
var checkedLoadedFor = {};
|
|
1606
|
+
var Translator = function (_EventEmitter) {
|
|
1607
|
+
_inherits(Translator, _EventEmitter);
|
|
1608
|
+
var _super = _createSuper$2(Translator);
|
|
1609
|
+
function Translator(services) {
|
|
1610
|
+
var _this;
|
|
1611
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1612
|
+
_classCallCheck(this, Translator);
|
|
1613
|
+
_this = _super.call(this);
|
|
1614
|
+
if (isIE10) {
|
|
1615
|
+
EventEmitter.call(_assertThisInitialized(_this));
|
|
1616
|
+
}
|
|
1617
|
+
copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector', 'i18nFormat', 'utils'], services, _assertThisInitialized(_this));
|
|
1618
|
+
_this.options = options;
|
|
1619
|
+
if (_this.options.keySeparator === undefined) {
|
|
1620
|
+
_this.options.keySeparator = '.';
|
|
1621
|
+
}
|
|
1622
|
+
_this.logger = baseLogger.create('translator');
|
|
1623
|
+
return _this;
|
|
1624
|
+
}
|
|
1625
|
+
_createClass(Translator, [{
|
|
1626
|
+
key: "changeLanguage",
|
|
1627
|
+
value: function changeLanguage(lng) {
|
|
1628
|
+
if (lng) this.language = lng;
|
|
1629
|
+
}
|
|
1630
|
+
}, {
|
|
1631
|
+
key: "exists",
|
|
1632
|
+
value: function exists(key) {
|
|
1633
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
1634
|
+
interpolation: {}
|
|
1635
|
+
};
|
|
1636
|
+
if (key === undefined || key === null) {
|
|
1637
|
+
return false;
|
|
1638
|
+
}
|
|
1639
|
+
var resolved = this.resolve(key, options);
|
|
1640
|
+
return resolved && resolved.res !== undefined;
|
|
1641
|
+
}
|
|
1642
|
+
}, {
|
|
1643
|
+
key: "extractFromKey",
|
|
1644
|
+
value: function extractFromKey(key, options) {
|
|
1645
|
+
var nsSeparator = options.nsSeparator !== undefined ? options.nsSeparator : this.options.nsSeparator;
|
|
1646
|
+
if (nsSeparator === undefined) nsSeparator = ':';
|
|
1647
|
+
var keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
1648
|
+
var namespaces = options.ns || this.options.defaultNS || [];
|
|
1649
|
+
var wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
|
|
1650
|
+
var seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
1651
|
+
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
1652
|
+
var m = key.match(this.interpolator.nestingRegexp);
|
|
1653
|
+
if (m && m.length > 0) {
|
|
1654
|
+
return {
|
|
1655
|
+
key: key,
|
|
1656
|
+
namespaces: namespaces
|
|
1657
|
+
};
|
|
1658
|
+
}
|
|
1659
|
+
var parts = key.split(nsSeparator);
|
|
1660
|
+
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
|
|
1661
|
+
key = parts.join(keySeparator);
|
|
1662
|
+
}
|
|
1663
|
+
if (typeof namespaces === 'string') namespaces = [namespaces];
|
|
1664
|
+
return {
|
|
1665
|
+
key: key,
|
|
1666
|
+
namespaces: namespaces
|
|
1667
|
+
};
|
|
1668
|
+
}
|
|
1669
|
+
}, {
|
|
1670
|
+
key: "translate",
|
|
1671
|
+
value: function translate(keys, options, lastKey) {
|
|
1672
|
+
var _this2 = this;
|
|
1673
|
+
if (_typeof(options) !== 'object' && this.options.overloadTranslationOptionHandler) {
|
|
1674
|
+
options = this.options.overloadTranslationOptionHandler(arguments);
|
|
1675
|
+
}
|
|
1676
|
+
if (_typeof(options) === 'object') options = _objectSpread$4({}, options);
|
|
1677
|
+
if (!options) options = {};
|
|
1678
|
+
if (keys === undefined || keys === null) return '';
|
|
1679
|
+
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
1680
|
+
var returnDetails = options.returnDetails !== undefined ? options.returnDetails : this.options.returnDetails;
|
|
1681
|
+
var keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
1682
|
+
var _this$extractFromKey = this.extractFromKey(keys[keys.length - 1], options),
|
|
1683
|
+
key = _this$extractFromKey.key,
|
|
1684
|
+
namespaces = _this$extractFromKey.namespaces;
|
|
1685
|
+
var namespace = namespaces[namespaces.length - 1];
|
|
1686
|
+
var lng = options.lng || this.language;
|
|
1687
|
+
var appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
1688
|
+
if (lng && lng.toLowerCase() === 'cimode') {
|
|
1689
|
+
if (appendNamespaceToCIMode) {
|
|
1690
|
+
var nsSeparator = options.nsSeparator || this.options.nsSeparator;
|
|
1691
|
+
if (returnDetails) {
|
|
1692
|
+
return {
|
|
1693
|
+
res: "".concat(namespace).concat(nsSeparator).concat(key),
|
|
1694
|
+
usedKey: key,
|
|
1695
|
+
exactUsedKey: key,
|
|
1696
|
+
usedLng: lng,
|
|
1697
|
+
usedNS: namespace
|
|
1698
|
+
};
|
|
1699
|
+
}
|
|
1700
|
+
return "".concat(namespace).concat(nsSeparator).concat(key);
|
|
1701
|
+
}
|
|
1702
|
+
if (returnDetails) {
|
|
1703
|
+
return {
|
|
1704
|
+
res: key,
|
|
1705
|
+
usedKey: key,
|
|
1706
|
+
exactUsedKey: key,
|
|
1707
|
+
usedLng: lng,
|
|
1708
|
+
usedNS: namespace
|
|
1709
|
+
};
|
|
1710
|
+
}
|
|
1711
|
+
return key;
|
|
1712
|
+
}
|
|
1713
|
+
var resolved = this.resolve(keys, options);
|
|
1714
|
+
var res = resolved && resolved.res;
|
|
1715
|
+
var resUsedKey = resolved && resolved.usedKey || key;
|
|
1716
|
+
var resExactUsedKey = resolved && resolved.exactUsedKey || key;
|
|
1717
|
+
var resType = Object.prototype.toString.apply(res);
|
|
1718
|
+
var noObject = ['[object Number]', '[object Function]', '[object RegExp]'];
|
|
1719
|
+
var joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays;
|
|
1720
|
+
var handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
|
|
1721
|
+
var handleAsObject = typeof res !== 'string' && typeof res !== 'boolean' && typeof res !== 'number';
|
|
1722
|
+
if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(typeof joinArrays === 'string' && resType === '[object Array]')) {
|
|
1723
|
+
if (!options.returnObjects && !this.options.returnObjects) {
|
|
1724
|
+
if (!this.options.returnedObjectHandler) {
|
|
1725
|
+
this.logger.warn('accessing an object - but returnObjects options is not enabled!');
|
|
1726
|
+
}
|
|
1727
|
+
var r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, _objectSpread$4(_objectSpread$4({}, options), {}, {
|
|
1728
|
+
ns: namespaces
|
|
1729
|
+
})) : "key '".concat(key, " (").concat(this.language, ")' returned an object instead of string.");
|
|
1730
|
+
if (returnDetails) {
|
|
1731
|
+
resolved.res = r;
|
|
1732
|
+
return resolved;
|
|
1733
|
+
}
|
|
1734
|
+
return r;
|
|
1735
|
+
}
|
|
1736
|
+
if (keySeparator) {
|
|
1737
|
+
var resTypeIsArray = resType === '[object Array]';
|
|
1738
|
+
var copy = resTypeIsArray ? [] : {};
|
|
1739
|
+
var newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
|
|
1740
|
+
for (var m in res) {
|
|
1741
|
+
if (Object.prototype.hasOwnProperty.call(res, m)) {
|
|
1742
|
+
var deepKey = "".concat(newKeyToUse).concat(keySeparator).concat(m);
|
|
1743
|
+
copy[m] = this.translate(deepKey, _objectSpread$4(_objectSpread$4({}, options), {
|
|
1744
|
+
joinArrays: false,
|
|
1745
|
+
ns: namespaces
|
|
1746
|
+
}));
|
|
1747
|
+
if (copy[m] === deepKey) copy[m] = res[m];
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
res = copy;
|
|
1751
|
+
}
|
|
1752
|
+
} else if (handleAsObjectInI18nFormat && typeof joinArrays === 'string' && resType === '[object Array]') {
|
|
1753
|
+
res = res.join(joinArrays);
|
|
1754
|
+
if (res) res = this.extendTranslation(res, keys, options, lastKey);
|
|
1755
|
+
} else {
|
|
1756
|
+
var usedDefault = false;
|
|
1757
|
+
var usedKey = false;
|
|
1758
|
+
var needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
|
|
1759
|
+
var hasDefaultValue = Translator.hasDefaultValue(options);
|
|
1760
|
+
var defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : '';
|
|
1761
|
+
var defaultValue = options["defaultValue".concat(defaultValueSuffix)] || options.defaultValue;
|
|
1762
|
+
if (!this.isValidLookup(res) && hasDefaultValue) {
|
|
1763
|
+
usedDefault = true;
|
|
1764
|
+
res = defaultValue;
|
|
1765
|
+
}
|
|
1766
|
+
if (!this.isValidLookup(res)) {
|
|
1767
|
+
usedKey = true;
|
|
1768
|
+
res = key;
|
|
1769
|
+
}
|
|
1770
|
+
var missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
|
|
1771
|
+
var resForMissing = missingKeyNoValueFallbackToKey && usedKey ? undefined : res;
|
|
1772
|
+
var updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
|
|
1773
|
+
if (usedKey || usedDefault || updateMissing) {
|
|
1774
|
+
this.logger.log(updateMissing ? 'updateKey' : 'missingKey', lng, namespace, key, updateMissing ? defaultValue : res);
|
|
1775
|
+
if (keySeparator) {
|
|
1776
|
+
var fk = this.resolve(key, _objectSpread$4(_objectSpread$4({}, options), {}, {
|
|
1777
|
+
keySeparator: false
|
|
1778
|
+
}));
|
|
1779
|
+
if (fk && fk.res) this.logger.warn('Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.');
|
|
1780
|
+
}
|
|
1781
|
+
var lngs = [];
|
|
1782
|
+
var fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
|
|
1783
|
+
if (this.options.saveMissingTo === 'fallback' && fallbackLngs && fallbackLngs[0]) {
|
|
1784
|
+
for (var i = 0; i < fallbackLngs.length; i++) {
|
|
1785
|
+
lngs.push(fallbackLngs[i]);
|
|
1786
|
+
}
|
|
1787
|
+
} else if (this.options.saveMissingTo === 'all') {
|
|
1788
|
+
lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
|
|
1789
|
+
} else {
|
|
1790
|
+
lngs.push(options.lng || this.language);
|
|
1791
|
+
}
|
|
1792
|
+
var send = function send(l, k, specificDefaultValue) {
|
|
1793
|
+
var defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
|
|
1794
|
+
if (_this2.options.missingKeyHandler) {
|
|
1795
|
+
_this2.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
1796
|
+
} else if (_this2.backendConnector && _this2.backendConnector.saveMissing) {
|
|
1797
|
+
_this2.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
1798
|
+
}
|
|
1799
|
+
_this2.emit('missingKey', l, namespace, k, res);
|
|
1800
|
+
};
|
|
1801
|
+
if (this.options.saveMissing) {
|
|
1802
|
+
if (this.options.saveMissingPlurals && needsPluralHandling) {
|
|
1803
|
+
lngs.forEach(function (language) {
|
|
1804
|
+
_this2.pluralResolver.getSuffixes(language, options).forEach(function (suffix) {
|
|
1805
|
+
send([language], key + suffix, options["defaultValue".concat(suffix)] || defaultValue);
|
|
1806
|
+
});
|
|
1807
|
+
});
|
|
1808
|
+
} else {
|
|
1809
|
+
send(lngs, key, defaultValue);
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
res = this.extendTranslation(res, keys, options, resolved, lastKey);
|
|
1814
|
+
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = "".concat(namespace, ":").concat(key);
|
|
1815
|
+
if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
|
|
1816
|
+
if (this.options.compatibilityAPI !== 'v1') {
|
|
1817
|
+
res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? "".concat(namespace, ":").concat(key) : key, usedDefault ? res : undefined);
|
|
1818
|
+
} else {
|
|
1819
|
+
res = this.options.parseMissingKeyHandler(res);
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
if (returnDetails) {
|
|
1824
|
+
resolved.res = res;
|
|
1825
|
+
return resolved;
|
|
1826
|
+
}
|
|
1827
|
+
return res;
|
|
1828
|
+
}
|
|
1829
|
+
}, {
|
|
1830
|
+
key: "extendTranslation",
|
|
1831
|
+
value: function extendTranslation(res, key, options, resolved, lastKey) {
|
|
1832
|
+
var _this3 = this;
|
|
1833
|
+
if (this.i18nFormat && this.i18nFormat.parse) {
|
|
1834
|
+
res = this.i18nFormat.parse(res, _objectSpread$4(_objectSpread$4({}, this.options.interpolation.defaultVariables), options), resolved.usedLng, resolved.usedNS, resolved.usedKey, {
|
|
1835
|
+
resolved: resolved
|
|
1836
|
+
});
|
|
1837
|
+
} else if (!options.skipInterpolation) {
|
|
1838
|
+
if (options.interpolation) this.interpolator.init(_objectSpread$4(_objectSpread$4({}, options), {
|
|
1839
|
+
interpolation: _objectSpread$4(_objectSpread$4({}, this.options.interpolation), options.interpolation)
|
|
1840
|
+
}));
|
|
1841
|
+
var skipOnVariables = typeof res === 'string' && (options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
|
|
1842
|
+
var nestBef;
|
|
1843
|
+
if (skipOnVariables) {
|
|
1844
|
+
var nb = res.match(this.interpolator.nestingRegexp);
|
|
1845
|
+
nestBef = nb && nb.length;
|
|
1846
|
+
}
|
|
1847
|
+
var data = options.replace && typeof options.replace !== 'string' ? options.replace : options;
|
|
1848
|
+
if (this.options.interpolation.defaultVariables) data = _objectSpread$4(_objectSpread$4({}, this.options.interpolation.defaultVariables), data);
|
|
1849
|
+
res = this.interpolator.interpolate(res, data, options.lng || this.language, options);
|
|
1850
|
+
if (skipOnVariables) {
|
|
1851
|
+
var na = res.match(this.interpolator.nestingRegexp);
|
|
1852
|
+
var nestAft = na && na.length;
|
|
1853
|
+
if (nestBef < nestAft) options.nest = false;
|
|
1854
|
+
}
|
|
1855
|
+
if (!options.lng && this.options.compatibilityAPI !== 'v1' && resolved && resolved.res) options.lng = resolved.usedLng;
|
|
1856
|
+
if (options.nest !== false) res = this.interpolator.nest(res, function () {
|
|
1857
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1858
|
+
args[_key] = arguments[_key];
|
|
1859
|
+
}
|
|
1860
|
+
if (lastKey && lastKey[0] === args[0] && !options.context) {
|
|
1861
|
+
_this3.logger.warn("It seems you are nesting recursively key: ".concat(args[0], " in key: ").concat(key[0]));
|
|
1862
|
+
return null;
|
|
1863
|
+
}
|
|
1864
|
+
return _this3.translate.apply(_this3, args.concat([key]));
|
|
1865
|
+
}, options);
|
|
1866
|
+
if (options.interpolation) this.interpolator.reset();
|
|
1867
|
+
}
|
|
1868
|
+
var postProcess = options.postProcess || this.options.postProcess;
|
|
1869
|
+
var postProcessorNames = typeof postProcess === 'string' ? [postProcess] : postProcess;
|
|
1870
|
+
if (res !== undefined && res !== null && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) {
|
|
1871
|
+
res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? _objectSpread$4({
|
|
1872
|
+
i18nResolved: resolved
|
|
1873
|
+
}, options) : options, this);
|
|
1874
|
+
}
|
|
1875
|
+
return res;
|
|
1876
|
+
}
|
|
1877
|
+
}, {
|
|
1878
|
+
key: "resolve",
|
|
1879
|
+
value: function resolve(keys) {
|
|
1880
|
+
var _this4 = this;
|
|
1881
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1882
|
+
var found;
|
|
1883
|
+
var usedKey;
|
|
1884
|
+
var exactUsedKey;
|
|
1885
|
+
var usedLng;
|
|
1886
|
+
var usedNS;
|
|
1887
|
+
if (typeof keys === 'string') keys = [keys];
|
|
1888
|
+
keys.forEach(function (k) {
|
|
1889
|
+
if (_this4.isValidLookup(found)) return;
|
|
1890
|
+
var extracted = _this4.extractFromKey(k, options);
|
|
1891
|
+
var key = extracted.key;
|
|
1892
|
+
usedKey = key;
|
|
1893
|
+
var namespaces = extracted.namespaces;
|
|
1894
|
+
if (_this4.options.fallbackNS) namespaces = namespaces.concat(_this4.options.fallbackNS);
|
|
1895
|
+
var needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
|
|
1896
|
+
var needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && _this4.pluralResolver.shouldUseIntlApi();
|
|
1897
|
+
var needsContextHandling = options.context !== undefined && (typeof options.context === 'string' || typeof options.context === 'number') && options.context !== '';
|
|
1898
|
+
var codes = options.lngs ? options.lngs : _this4.languageUtils.toResolveHierarchy(options.lng || _this4.language, options.fallbackLng);
|
|
1899
|
+
namespaces.forEach(function (ns) {
|
|
1900
|
+
if (_this4.isValidLookup(found)) return;
|
|
1901
|
+
usedNS = ns;
|
|
1902
|
+
if (!checkedLoadedFor["".concat(codes[0], "-").concat(ns)] && _this4.utils && _this4.utils.hasLoadedNamespace && !_this4.utils.hasLoadedNamespace(usedNS)) {
|
|
1903
|
+
checkedLoadedFor["".concat(codes[0], "-").concat(ns)] = true;
|
|
1904
|
+
_this4.logger.warn("key \"".concat(usedKey, "\" for languages \"").concat(codes.join(', '), "\" won't get resolved as namespace \"").concat(usedNS, "\" was not yet loaded"), 'This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!');
|
|
1905
|
+
}
|
|
1906
|
+
codes.forEach(function (code) {
|
|
1907
|
+
if (_this4.isValidLookup(found)) return;
|
|
1908
|
+
usedLng = code;
|
|
1909
|
+
var finalKeys = [key];
|
|
1910
|
+
if (_this4.i18nFormat && _this4.i18nFormat.addLookupKeys) {
|
|
1911
|
+
_this4.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
|
|
1912
|
+
} else {
|
|
1913
|
+
var pluralSuffix;
|
|
1914
|
+
if (needsPluralHandling) pluralSuffix = _this4.pluralResolver.getSuffix(code, options.count, options);
|
|
1915
|
+
var zeroSuffix = "".concat(_this4.options.pluralSeparator, "zero");
|
|
1916
|
+
if (needsPluralHandling) {
|
|
1917
|
+
finalKeys.push(key + pluralSuffix);
|
|
1918
|
+
if (needsZeroSuffixLookup) {
|
|
1919
|
+
finalKeys.push(key + zeroSuffix);
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
if (needsContextHandling) {
|
|
1923
|
+
var contextKey = "".concat(key).concat(_this4.options.contextSeparator).concat(options.context);
|
|
1924
|
+
finalKeys.push(contextKey);
|
|
1925
|
+
if (needsPluralHandling) {
|
|
1926
|
+
finalKeys.push(contextKey + pluralSuffix);
|
|
1927
|
+
if (needsZeroSuffixLookup) {
|
|
1928
|
+
finalKeys.push(contextKey + zeroSuffix);
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
}
|
|
1933
|
+
var possibleKey;
|
|
1934
|
+
while (possibleKey = finalKeys.pop()) {
|
|
1935
|
+
if (!_this4.isValidLookup(found)) {
|
|
1936
|
+
exactUsedKey = possibleKey;
|
|
1937
|
+
found = _this4.getResource(code, ns, possibleKey, options);
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
});
|
|
1941
|
+
});
|
|
1942
|
+
});
|
|
1943
|
+
return {
|
|
1944
|
+
res: found,
|
|
1945
|
+
usedKey: usedKey,
|
|
1946
|
+
exactUsedKey: exactUsedKey,
|
|
1947
|
+
usedLng: usedLng,
|
|
1948
|
+
usedNS: usedNS
|
|
1949
|
+
};
|
|
1950
|
+
}
|
|
1951
|
+
}, {
|
|
1952
|
+
key: "isValidLookup",
|
|
1953
|
+
value: function isValidLookup(res) {
|
|
1954
|
+
return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === '');
|
|
1955
|
+
}
|
|
1956
|
+
}, {
|
|
1957
|
+
key: "getResource",
|
|
1958
|
+
value: function getResource(code, ns, key) {
|
|
1959
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1960
|
+
if (this.i18nFormat && this.i18nFormat.getResource) return this.i18nFormat.getResource(code, ns, key, options);
|
|
1961
|
+
return this.resourceStore.getResource(code, ns, key, options);
|
|
1962
|
+
}
|
|
1963
|
+
}], [{
|
|
1964
|
+
key: "hasDefaultValue",
|
|
1965
|
+
value: function hasDefaultValue(options) {
|
|
1966
|
+
var prefix = 'defaultValue';
|
|
1967
|
+
for (var option in options) {
|
|
1968
|
+
if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && undefined !== options[option]) {
|
|
1969
|
+
return true;
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
return false;
|
|
1973
|
+
}
|
|
1974
|
+
}]);
|
|
1975
|
+
return Translator;
|
|
1976
|
+
}(EventEmitter);
|
|
1977
|
+
|
|
1978
|
+
function capitalize(string) {
|
|
1979
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
1980
|
+
}
|
|
1981
|
+
var LanguageUtil = function () {
|
|
1982
|
+
function LanguageUtil(options) {
|
|
1983
|
+
_classCallCheck(this, LanguageUtil);
|
|
1984
|
+
this.options = options;
|
|
1985
|
+
this.supportedLngs = this.options.supportedLngs || false;
|
|
1986
|
+
this.logger = baseLogger.create('languageUtils');
|
|
1987
|
+
}
|
|
1988
|
+
_createClass(LanguageUtil, [{
|
|
1989
|
+
key: "getScriptPartFromCode",
|
|
1990
|
+
value: function getScriptPartFromCode(code) {
|
|
1991
|
+
if (!code || code.indexOf('-') < 0) return null;
|
|
1992
|
+
var p = code.split('-');
|
|
1993
|
+
if (p.length === 2) return null;
|
|
1994
|
+
p.pop();
|
|
1995
|
+
if (p[p.length - 1].toLowerCase() === 'x') return null;
|
|
1996
|
+
return this.formatLanguageCode(p.join('-'));
|
|
1997
|
+
}
|
|
1998
|
+
}, {
|
|
1999
|
+
key: "getLanguagePartFromCode",
|
|
2000
|
+
value: function getLanguagePartFromCode(code) {
|
|
2001
|
+
if (!code || code.indexOf('-') < 0) return code;
|
|
2002
|
+
var p = code.split('-');
|
|
2003
|
+
return this.formatLanguageCode(p[0]);
|
|
2004
|
+
}
|
|
2005
|
+
}, {
|
|
2006
|
+
key: "formatLanguageCode",
|
|
2007
|
+
value: function formatLanguageCode(code) {
|
|
2008
|
+
if (typeof code === 'string' && code.indexOf('-') > -1) {
|
|
2009
|
+
var specialCases = ['hans', 'hant', 'latn', 'cyrl', 'cans', 'mong', 'arab'];
|
|
2010
|
+
var p = code.split('-');
|
|
2011
|
+
if (this.options.lowerCaseLng) {
|
|
2012
|
+
p = p.map(function (part) {
|
|
2013
|
+
return part.toLowerCase();
|
|
2014
|
+
});
|
|
2015
|
+
} else if (p.length === 2) {
|
|
2016
|
+
p[0] = p[0].toLowerCase();
|
|
2017
|
+
p[1] = p[1].toUpperCase();
|
|
2018
|
+
if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
|
|
2019
|
+
} else if (p.length === 3) {
|
|
2020
|
+
p[0] = p[0].toLowerCase();
|
|
2021
|
+
if (p[1].length === 2) p[1] = p[1].toUpperCase();
|
|
2022
|
+
if (p[0] !== 'sgn' && p[2].length === 2) p[2] = p[2].toUpperCase();
|
|
2023
|
+
if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
|
|
2024
|
+
if (specialCases.indexOf(p[2].toLowerCase()) > -1) p[2] = capitalize(p[2].toLowerCase());
|
|
2025
|
+
}
|
|
2026
|
+
return p.join('-');
|
|
2027
|
+
}
|
|
2028
|
+
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
|
|
2029
|
+
}
|
|
2030
|
+
}, {
|
|
2031
|
+
key: "isSupportedCode",
|
|
2032
|
+
value: function isSupportedCode(code) {
|
|
2033
|
+
if (this.options.load === 'languageOnly' || this.options.nonExplicitSupportedLngs) {
|
|
2034
|
+
code = this.getLanguagePartFromCode(code);
|
|
2035
|
+
}
|
|
2036
|
+
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
|
|
2037
|
+
}
|
|
2038
|
+
}, {
|
|
2039
|
+
key: "getBestMatchFromCodes",
|
|
2040
|
+
value: function getBestMatchFromCodes(codes) {
|
|
2041
|
+
var _this = this;
|
|
2042
|
+
if (!codes) return null;
|
|
2043
|
+
var found;
|
|
2044
|
+
codes.forEach(function (code) {
|
|
2045
|
+
if (found) return;
|
|
2046
|
+
var cleanedLng = _this.formatLanguageCode(code);
|
|
2047
|
+
if (!_this.options.supportedLngs || _this.isSupportedCode(cleanedLng)) found = cleanedLng;
|
|
2048
|
+
});
|
|
2049
|
+
if (!found && this.options.supportedLngs) {
|
|
2050
|
+
codes.forEach(function (code) {
|
|
2051
|
+
if (found) return;
|
|
2052
|
+
var lngOnly = _this.getLanguagePartFromCode(code);
|
|
2053
|
+
if (_this.isSupportedCode(lngOnly)) return found = lngOnly;
|
|
2054
|
+
found = _this.options.supportedLngs.find(function (supportedLng) {
|
|
2055
|
+
if (supportedLng === lngOnly) return supportedLng;
|
|
2056
|
+
if (supportedLng.indexOf('-') < 0 && lngOnly.indexOf('-') < 0) return;
|
|
2057
|
+
if (supportedLng.indexOf(lngOnly) === 0) return supportedLng;
|
|
2058
|
+
});
|
|
2059
|
+
});
|
|
2060
|
+
}
|
|
2061
|
+
if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
|
|
2062
|
+
return found;
|
|
2063
|
+
}
|
|
2064
|
+
}, {
|
|
2065
|
+
key: "getFallbackCodes",
|
|
2066
|
+
value: function getFallbackCodes(fallbacks, code) {
|
|
2067
|
+
if (!fallbacks) return [];
|
|
2068
|
+
if (typeof fallbacks === 'function') fallbacks = fallbacks(code);
|
|
2069
|
+
if (typeof fallbacks === 'string') fallbacks = [fallbacks];
|
|
2070
|
+
if (Object.prototype.toString.apply(fallbacks) === '[object Array]') return fallbacks;
|
|
2071
|
+
if (!code) return fallbacks["default"] || [];
|
|
2072
|
+
var found = fallbacks[code];
|
|
2073
|
+
if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
|
|
2074
|
+
if (!found) found = fallbacks[this.formatLanguageCode(code)];
|
|
2075
|
+
if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
|
|
2076
|
+
if (!found) found = fallbacks["default"];
|
|
2077
|
+
return found || [];
|
|
2078
|
+
}
|
|
2079
|
+
}, {
|
|
2080
|
+
key: "toResolveHierarchy",
|
|
2081
|
+
value: function toResolveHierarchy(code, fallbackCode) {
|
|
2082
|
+
var _this2 = this;
|
|
2083
|
+
var fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
|
|
2084
|
+
var codes = [];
|
|
2085
|
+
var addCode = function addCode(c) {
|
|
2086
|
+
if (!c) return;
|
|
2087
|
+
if (_this2.isSupportedCode(c)) {
|
|
2088
|
+
codes.push(c);
|
|
2089
|
+
} else {
|
|
2090
|
+
_this2.logger.warn("rejecting language code not found in supportedLngs: ".concat(c));
|
|
2091
|
+
}
|
|
2092
|
+
};
|
|
2093
|
+
if (typeof code === 'string' && code.indexOf('-') > -1) {
|
|
2094
|
+
if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code));
|
|
2095
|
+
if (this.options.load !== 'languageOnly' && this.options.load !== 'currentOnly') addCode(this.getScriptPartFromCode(code));
|
|
2096
|
+
if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code));
|
|
2097
|
+
} else if (typeof code === 'string') {
|
|
2098
|
+
addCode(this.formatLanguageCode(code));
|
|
2099
|
+
}
|
|
2100
|
+
fallbackCodes.forEach(function (fc) {
|
|
2101
|
+
if (codes.indexOf(fc) < 0) addCode(_this2.formatLanguageCode(fc));
|
|
2102
|
+
});
|
|
2103
|
+
return codes;
|
|
2104
|
+
}
|
|
2105
|
+
}]);
|
|
2106
|
+
return LanguageUtil;
|
|
2107
|
+
}();
|
|
2108
|
+
|
|
2109
|
+
var sets = [{
|
|
2110
|
+
lngs: ['ach', 'ak', 'am', 'arn', 'br', 'fil', 'gun', 'ln', 'mfe', 'mg', 'mi', 'oc', 'pt', 'pt-BR', 'tg', 'tl', 'ti', 'tr', 'uz', 'wa'],
|
|
2111
|
+
nr: [1, 2],
|
|
2112
|
+
fc: 1
|
|
2113
|
+
}, {
|
|
2114
|
+
lngs: ['af', 'an', 'ast', 'az', 'bg', 'bn', 'ca', 'da', 'de', 'dev', 'el', 'en', 'eo', 'es', 'et', 'eu', 'fi', 'fo', 'fur', 'fy', 'gl', 'gu', 'ha', 'hi', 'hu', 'hy', 'ia', 'it', 'kk', 'kn', 'ku', 'lb', 'mai', 'ml', 'mn', 'mr', 'nah', 'nap', 'nb', 'ne', 'nl', 'nn', 'no', 'nso', 'pa', 'pap', 'pms', 'ps', 'pt-PT', 'rm', 'sco', 'se', 'si', 'so', 'son', 'sq', 'sv', 'sw', 'ta', 'te', 'tk', 'ur', 'yo'],
|
|
2115
|
+
nr: [1, 2],
|
|
2116
|
+
fc: 2
|
|
2117
|
+
}, {
|
|
2118
|
+
lngs: ['ay', 'bo', 'cgg', 'fa', 'ht', 'id', 'ja', 'jbo', 'ka', 'km', 'ko', 'ky', 'lo', 'ms', 'sah', 'su', 'th', 'tt', 'ug', 'vi', 'wo', 'zh'],
|
|
2119
|
+
nr: [1],
|
|
2120
|
+
fc: 3
|
|
2121
|
+
}, {
|
|
2122
|
+
lngs: ['be', 'bs', 'cnr', 'dz', 'hr', 'ru', 'sr', 'uk'],
|
|
2123
|
+
nr: [1, 2, 5],
|
|
2124
|
+
fc: 4
|
|
2125
|
+
}, {
|
|
2126
|
+
lngs: ['ar'],
|
|
2127
|
+
nr: [0, 1, 2, 3, 11, 100],
|
|
2128
|
+
fc: 5
|
|
2129
|
+
}, {
|
|
2130
|
+
lngs: ['cs', 'sk'],
|
|
2131
|
+
nr: [1, 2, 5],
|
|
2132
|
+
fc: 6
|
|
2133
|
+
}, {
|
|
2134
|
+
lngs: ['csb', 'pl'],
|
|
2135
|
+
nr: [1, 2, 5],
|
|
2136
|
+
fc: 7
|
|
2137
|
+
}, {
|
|
2138
|
+
lngs: ['cy'],
|
|
2139
|
+
nr: [1, 2, 3, 8],
|
|
2140
|
+
fc: 8
|
|
2141
|
+
}, {
|
|
2142
|
+
lngs: ['fr'],
|
|
2143
|
+
nr: [1, 2],
|
|
2144
|
+
fc: 9
|
|
2145
|
+
}, {
|
|
2146
|
+
lngs: ['ga'],
|
|
2147
|
+
nr: [1, 2, 3, 7, 11],
|
|
2148
|
+
fc: 10
|
|
2149
|
+
}, {
|
|
2150
|
+
lngs: ['gd'],
|
|
2151
|
+
nr: [1, 2, 3, 20],
|
|
2152
|
+
fc: 11
|
|
2153
|
+
}, {
|
|
2154
|
+
lngs: ['is'],
|
|
2155
|
+
nr: [1, 2],
|
|
2156
|
+
fc: 12
|
|
2157
|
+
}, {
|
|
2158
|
+
lngs: ['jv'],
|
|
2159
|
+
nr: [0, 1],
|
|
2160
|
+
fc: 13
|
|
2161
|
+
}, {
|
|
2162
|
+
lngs: ['kw'],
|
|
2163
|
+
nr: [1, 2, 3, 4],
|
|
2164
|
+
fc: 14
|
|
2165
|
+
}, {
|
|
2166
|
+
lngs: ['lt'],
|
|
2167
|
+
nr: [1, 2, 10],
|
|
2168
|
+
fc: 15
|
|
2169
|
+
}, {
|
|
2170
|
+
lngs: ['lv'],
|
|
2171
|
+
nr: [1, 2, 0],
|
|
2172
|
+
fc: 16
|
|
2173
|
+
}, {
|
|
2174
|
+
lngs: ['mk'],
|
|
2175
|
+
nr: [1, 2],
|
|
2176
|
+
fc: 17
|
|
2177
|
+
}, {
|
|
2178
|
+
lngs: ['mnk'],
|
|
2179
|
+
nr: [0, 1, 2],
|
|
2180
|
+
fc: 18
|
|
2181
|
+
}, {
|
|
2182
|
+
lngs: ['mt'],
|
|
2183
|
+
nr: [1, 2, 11, 20],
|
|
2184
|
+
fc: 19
|
|
2185
|
+
}, {
|
|
2186
|
+
lngs: ['or'],
|
|
2187
|
+
nr: [2, 1],
|
|
2188
|
+
fc: 2
|
|
2189
|
+
}, {
|
|
2190
|
+
lngs: ['ro'],
|
|
2191
|
+
nr: [1, 2, 20],
|
|
2192
|
+
fc: 20
|
|
2193
|
+
}, {
|
|
2194
|
+
lngs: ['sl'],
|
|
2195
|
+
nr: [5, 1, 2, 3],
|
|
2196
|
+
fc: 21
|
|
2197
|
+
}, {
|
|
2198
|
+
lngs: ['he', 'iw'],
|
|
2199
|
+
nr: [1, 2, 20, 21],
|
|
2200
|
+
fc: 22
|
|
2201
|
+
}];
|
|
2202
|
+
var _rulesPluralsTypes = {
|
|
2203
|
+
1: function _(n) {
|
|
2204
|
+
return Number(n > 1);
|
|
2205
|
+
},
|
|
2206
|
+
2: function _(n) {
|
|
2207
|
+
return Number(n != 1);
|
|
2208
|
+
},
|
|
2209
|
+
3: function _(n) {
|
|
2210
|
+
return 0;
|
|
2211
|
+
},
|
|
2212
|
+
4: function _(n) {
|
|
2213
|
+
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
2214
|
+
},
|
|
2215
|
+
5: function _(n) {
|
|
2216
|
+
return Number(n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5);
|
|
2217
|
+
},
|
|
2218
|
+
6: function _(n) {
|
|
2219
|
+
return Number(n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2);
|
|
2220
|
+
},
|
|
2221
|
+
7: function _(n) {
|
|
2222
|
+
return Number(n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
2223
|
+
},
|
|
2224
|
+
8: function _(n) {
|
|
2225
|
+
return Number(n == 1 ? 0 : n == 2 ? 1 : n != 8 && n != 11 ? 2 : 3);
|
|
2226
|
+
},
|
|
2227
|
+
9: function _(n) {
|
|
2228
|
+
return Number(n >= 2);
|
|
2229
|
+
},
|
|
2230
|
+
10: function _(n) {
|
|
2231
|
+
return Number(n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4);
|
|
2232
|
+
},
|
|
2233
|
+
11: function _(n) {
|
|
2234
|
+
return Number(n == 1 || n == 11 ? 0 : n == 2 || n == 12 ? 1 : n > 2 && n < 20 ? 2 : 3);
|
|
2235
|
+
},
|
|
2236
|
+
12: function _(n) {
|
|
2237
|
+
return Number(n % 10 != 1 || n % 100 == 11);
|
|
2238
|
+
},
|
|
2239
|
+
13: function _(n) {
|
|
2240
|
+
return Number(n !== 0);
|
|
2241
|
+
},
|
|
2242
|
+
14: function _(n) {
|
|
2243
|
+
return Number(n == 1 ? 0 : n == 2 ? 1 : n == 3 ? 2 : 3);
|
|
2244
|
+
},
|
|
2245
|
+
15: function _(n) {
|
|
2246
|
+
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
2247
|
+
},
|
|
2248
|
+
16: function _(n) {
|
|
2249
|
+
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n !== 0 ? 1 : 2);
|
|
2250
|
+
},
|
|
2251
|
+
17: function _(n) {
|
|
2252
|
+
return Number(n == 1 || n % 10 == 1 && n % 100 != 11 ? 0 : 1);
|
|
2253
|
+
},
|
|
2254
|
+
18: function _(n) {
|
|
2255
|
+
return Number(n == 0 ? 0 : n == 1 ? 1 : 2);
|
|
2256
|
+
},
|
|
2257
|
+
19: function _(n) {
|
|
2258
|
+
return Number(n == 1 ? 0 : n == 0 || n % 100 > 1 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3);
|
|
2259
|
+
},
|
|
2260
|
+
20: function _(n) {
|
|
2261
|
+
return Number(n == 1 ? 0 : n == 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2);
|
|
2262
|
+
},
|
|
2263
|
+
21: function _(n) {
|
|
2264
|
+
return Number(n % 100 == 1 ? 1 : n % 100 == 2 ? 2 : n % 100 == 3 || n % 100 == 4 ? 3 : 0);
|
|
2265
|
+
},
|
|
2266
|
+
22: function _(n) {
|
|
2267
|
+
return Number(n == 1 ? 0 : n == 2 ? 1 : (n < 0 || n > 10) && n % 10 == 0 ? 2 : 3);
|
|
2268
|
+
}
|
|
2269
|
+
};
|
|
2270
|
+
var deprecatedJsonVersions = ['v1', 'v2', 'v3'];
|
|
2271
|
+
var suffixesOrder = {
|
|
2272
|
+
zero: 0,
|
|
2273
|
+
one: 1,
|
|
2274
|
+
two: 2,
|
|
2275
|
+
few: 3,
|
|
2276
|
+
many: 4,
|
|
2277
|
+
other: 5
|
|
2278
|
+
};
|
|
2279
|
+
function createRules() {
|
|
2280
|
+
var rules = {};
|
|
2281
|
+
sets.forEach(function (set) {
|
|
2282
|
+
set.lngs.forEach(function (l) {
|
|
2283
|
+
rules[l] = {
|
|
2284
|
+
numbers: set.nr,
|
|
2285
|
+
plurals: _rulesPluralsTypes[set.fc]
|
|
2286
|
+
};
|
|
2287
|
+
});
|
|
2288
|
+
});
|
|
2289
|
+
return rules;
|
|
2290
|
+
}
|
|
2291
|
+
var PluralResolver = function () {
|
|
2292
|
+
function PluralResolver(languageUtils) {
|
|
2293
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2294
|
+
_classCallCheck(this, PluralResolver);
|
|
2295
|
+
this.languageUtils = languageUtils;
|
|
2296
|
+
this.options = options;
|
|
2297
|
+
this.logger = baseLogger.create('pluralResolver');
|
|
2298
|
+
if ((!this.options.compatibilityJSON || this.options.compatibilityJSON === 'v4') && (typeof Intl === 'undefined' || !Intl.PluralRules)) {
|
|
2299
|
+
this.options.compatibilityJSON = 'v3';
|
|
2300
|
+
this.logger.error('Your environment seems not to be Intl API compatible, use an Intl.PluralRules polyfill. Will fallback to the compatibilityJSON v3 format handling.');
|
|
2301
|
+
}
|
|
2302
|
+
this.rules = createRules();
|
|
2303
|
+
}
|
|
2304
|
+
_createClass(PluralResolver, [{
|
|
2305
|
+
key: "addRule",
|
|
2306
|
+
value: function addRule(lng, obj) {
|
|
2307
|
+
this.rules[lng] = obj;
|
|
2308
|
+
}
|
|
2309
|
+
}, {
|
|
2310
|
+
key: "getRule",
|
|
2311
|
+
value: function getRule(code) {
|
|
2312
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2313
|
+
if (this.shouldUseIntlApi()) {
|
|
2314
|
+
try {
|
|
2315
|
+
return new Intl.PluralRules(code, {
|
|
2316
|
+
type: options.ordinal ? 'ordinal' : 'cardinal'
|
|
2317
|
+
});
|
|
2318
|
+
} catch (_unused) {
|
|
2319
|
+
return;
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)];
|
|
2323
|
+
}
|
|
2324
|
+
}, {
|
|
2325
|
+
key: "needsPlural",
|
|
2326
|
+
value: function needsPlural(code) {
|
|
2327
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2328
|
+
var rule = this.getRule(code, options);
|
|
2329
|
+
if (this.shouldUseIntlApi()) {
|
|
2330
|
+
return rule && rule.resolvedOptions().pluralCategories.length > 1;
|
|
2331
|
+
}
|
|
2332
|
+
return rule && rule.numbers.length > 1;
|
|
2333
|
+
}
|
|
2334
|
+
}, {
|
|
2335
|
+
key: "getPluralFormsOfKey",
|
|
2336
|
+
value: function getPluralFormsOfKey(code, key) {
|
|
2337
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
2338
|
+
return this.getSuffixes(code, options).map(function (suffix) {
|
|
2339
|
+
return "".concat(key).concat(suffix);
|
|
2340
|
+
});
|
|
2341
|
+
}
|
|
2342
|
+
}, {
|
|
2343
|
+
key: "getSuffixes",
|
|
2344
|
+
value: function getSuffixes(code) {
|
|
2345
|
+
var _this = this;
|
|
2346
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2347
|
+
var rule = this.getRule(code, options);
|
|
2348
|
+
if (!rule) {
|
|
2349
|
+
return [];
|
|
2350
|
+
}
|
|
2351
|
+
if (this.shouldUseIntlApi()) {
|
|
2352
|
+
return rule.resolvedOptions().pluralCategories.sort(function (pluralCategory1, pluralCategory2) {
|
|
2353
|
+
return suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2];
|
|
2354
|
+
}).map(function (pluralCategory) {
|
|
2355
|
+
return "".concat(_this.options.prepend).concat(pluralCategory);
|
|
2356
|
+
});
|
|
2357
|
+
}
|
|
2358
|
+
return rule.numbers.map(function (number) {
|
|
2359
|
+
return _this.getSuffix(code, number, options);
|
|
2360
|
+
});
|
|
2361
|
+
}
|
|
2362
|
+
}, {
|
|
2363
|
+
key: "getSuffix",
|
|
2364
|
+
value: function getSuffix(code, count) {
|
|
2365
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
2366
|
+
var rule = this.getRule(code, options);
|
|
2367
|
+
if (rule) {
|
|
2368
|
+
if (this.shouldUseIntlApi()) {
|
|
2369
|
+
return "".concat(this.options.prepend).concat(rule.select(count));
|
|
2370
|
+
}
|
|
2371
|
+
return this.getSuffixRetroCompatible(rule, count);
|
|
2372
|
+
}
|
|
2373
|
+
this.logger.warn("no plural rule found for: ".concat(code));
|
|
2374
|
+
return '';
|
|
2375
|
+
}
|
|
2376
|
+
}, {
|
|
2377
|
+
key: "getSuffixRetroCompatible",
|
|
2378
|
+
value: function getSuffixRetroCompatible(rule, count) {
|
|
2379
|
+
var _this2 = this;
|
|
2380
|
+
var idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
|
|
2381
|
+
var suffix = rule.numbers[idx];
|
|
2382
|
+
if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
2383
|
+
if (suffix === 2) {
|
|
2384
|
+
suffix = 'plural';
|
|
2385
|
+
} else if (suffix === 1) {
|
|
2386
|
+
suffix = '';
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
var returnSuffix = function returnSuffix() {
|
|
2390
|
+
return _this2.options.prepend && suffix.toString() ? _this2.options.prepend + suffix.toString() : suffix.toString();
|
|
2391
|
+
};
|
|
2392
|
+
if (this.options.compatibilityJSON === 'v1') {
|
|
2393
|
+
if (suffix === 1) return '';
|
|
2394
|
+
if (typeof suffix === 'number') return "_plural_".concat(suffix.toString());
|
|
2395
|
+
return returnSuffix();
|
|
2396
|
+
} else if (this.options.compatibilityJSON === 'v2') {
|
|
2397
|
+
return returnSuffix();
|
|
2398
|
+
} else if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
2399
|
+
return returnSuffix();
|
|
2400
|
+
}
|
|
2401
|
+
return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
|
|
2402
|
+
}
|
|
2403
|
+
}, {
|
|
2404
|
+
key: "shouldUseIntlApi",
|
|
2405
|
+
value: function shouldUseIntlApi() {
|
|
2406
|
+
return !deprecatedJsonVersions.includes(this.options.compatibilityJSON);
|
|
2407
|
+
}
|
|
2408
|
+
}]);
|
|
2409
|
+
return PluralResolver;
|
|
2410
|
+
}();
|
|
2411
|
+
|
|
2412
|
+
function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2413
|
+
function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$3(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
2414
|
+
function deepFindWithDefaults(data, defaultData, key) {
|
|
2415
|
+
var keySeparator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '.';
|
|
2416
|
+
var ignoreJSONStructure = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
2417
|
+
var path = getPathWithDefaults(data, defaultData, key);
|
|
2418
|
+
if (!path && ignoreJSONStructure && typeof key === 'string') {
|
|
2419
|
+
path = deepFind(data, key, keySeparator);
|
|
2420
|
+
if (path === undefined) path = deepFind(defaultData, key, keySeparator);
|
|
2421
|
+
}
|
|
2422
|
+
return path;
|
|
2423
|
+
}
|
|
2424
|
+
var Interpolator = function () {
|
|
2425
|
+
function Interpolator() {
|
|
2426
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2427
|
+
_classCallCheck(this, Interpolator);
|
|
2428
|
+
this.logger = baseLogger.create('interpolator');
|
|
2429
|
+
this.options = options;
|
|
2430
|
+
this.format = options.interpolation && options.interpolation.format || function (value) {
|
|
2431
|
+
return value;
|
|
2432
|
+
};
|
|
2433
|
+
this.init(options);
|
|
2434
|
+
}
|
|
2435
|
+
_createClass(Interpolator, [{
|
|
2436
|
+
key: "init",
|
|
2437
|
+
value: function init() {
|
|
2438
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2439
|
+
if (!options.interpolation) options.interpolation = {
|
|
2440
|
+
escapeValue: true
|
|
2441
|
+
};
|
|
2442
|
+
var iOpts = options.interpolation;
|
|
2443
|
+
this.escape = iOpts.escape !== undefined ? iOpts.escape : escape;
|
|
2444
|
+
this.escapeValue = iOpts.escapeValue !== undefined ? iOpts.escapeValue : true;
|
|
2445
|
+
this.useRawValueToEscape = iOpts.useRawValueToEscape !== undefined ? iOpts.useRawValueToEscape : false;
|
|
2446
|
+
this.prefix = iOpts.prefix ? regexEscape(iOpts.prefix) : iOpts.prefixEscaped || '{{';
|
|
2447
|
+
this.suffix = iOpts.suffix ? regexEscape(iOpts.suffix) : iOpts.suffixEscaped || '}}';
|
|
2448
|
+
this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';
|
|
2449
|
+
this.unescapePrefix = iOpts.unescapeSuffix ? '' : iOpts.unescapePrefix || '-';
|
|
2450
|
+
this.unescapeSuffix = this.unescapePrefix ? '' : iOpts.unescapeSuffix || '';
|
|
2451
|
+
this.nestingPrefix = iOpts.nestingPrefix ? regexEscape(iOpts.nestingPrefix) : iOpts.nestingPrefixEscaped || regexEscape('$t(');
|
|
2452
|
+
this.nestingSuffix = iOpts.nestingSuffix ? regexEscape(iOpts.nestingSuffix) : iOpts.nestingSuffixEscaped || regexEscape(')');
|
|
2453
|
+
this.nestingOptionsSeparator = iOpts.nestingOptionsSeparator ? iOpts.nestingOptionsSeparator : iOpts.nestingOptionsSeparator || ',';
|
|
2454
|
+
this.maxReplaces = iOpts.maxReplaces ? iOpts.maxReplaces : 1000;
|
|
2455
|
+
this.alwaysFormat = iOpts.alwaysFormat !== undefined ? iOpts.alwaysFormat : false;
|
|
2456
|
+
this.resetRegExp();
|
|
2457
|
+
}
|
|
2458
|
+
}, {
|
|
2459
|
+
key: "reset",
|
|
2460
|
+
value: function reset() {
|
|
2461
|
+
if (this.options) this.init(this.options);
|
|
2462
|
+
}
|
|
2463
|
+
}, {
|
|
2464
|
+
key: "resetRegExp",
|
|
2465
|
+
value: function resetRegExp() {
|
|
2466
|
+
var regexpStr = "".concat(this.prefix, "(.+?)").concat(this.suffix);
|
|
2467
|
+
this.regexp = new RegExp(regexpStr, 'g');
|
|
2468
|
+
var regexpUnescapeStr = "".concat(this.prefix).concat(this.unescapePrefix, "(.+?)").concat(this.unescapeSuffix).concat(this.suffix);
|
|
2469
|
+
this.regexpUnescape = new RegExp(regexpUnescapeStr, 'g');
|
|
2470
|
+
var nestingRegexpStr = "".concat(this.nestingPrefix, "(.+?)").concat(this.nestingSuffix);
|
|
2471
|
+
this.nestingRegexp = new RegExp(nestingRegexpStr, 'g');
|
|
2472
|
+
}
|
|
2473
|
+
}, {
|
|
2474
|
+
key: "interpolate",
|
|
2475
|
+
value: function interpolate(str, data, lng, options) {
|
|
2476
|
+
var _this = this;
|
|
2477
|
+
var match;
|
|
2478
|
+
var value;
|
|
2479
|
+
var replaces;
|
|
2480
|
+
var defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
|
|
2481
|
+
function regexSafe(val) {
|
|
2482
|
+
return val.replace(/\$/g, '$$$$');
|
|
2483
|
+
}
|
|
2484
|
+
var handleFormat = function handleFormat(key) {
|
|
2485
|
+
if (key.indexOf(_this.formatSeparator) < 0) {
|
|
2486
|
+
var path = deepFindWithDefaults(data, defaultData, key, _this.options.keySeparator, _this.options.ignoreJSONStructure);
|
|
2487
|
+
return _this.alwaysFormat ? _this.format(path, undefined, lng, _objectSpread$3(_objectSpread$3(_objectSpread$3({}, options), data), {}, {
|
|
2488
|
+
interpolationkey: key
|
|
2489
|
+
})) : path;
|
|
2490
|
+
}
|
|
2491
|
+
var p = key.split(_this.formatSeparator);
|
|
2492
|
+
var k = p.shift().trim();
|
|
2493
|
+
var f = p.join(_this.formatSeparator).trim();
|
|
2494
|
+
return _this.format(deepFindWithDefaults(data, defaultData, k, _this.options.keySeparator, _this.options.ignoreJSONStructure), f, lng, _objectSpread$3(_objectSpread$3(_objectSpread$3({}, options), data), {}, {
|
|
2495
|
+
interpolationkey: k
|
|
2496
|
+
}));
|
|
2497
|
+
};
|
|
2498
|
+
this.resetRegExp();
|
|
2499
|
+
var missingInterpolationHandler = options && options.missingInterpolationHandler || this.options.missingInterpolationHandler;
|
|
2500
|
+
var skipOnVariables = options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
|
|
2501
|
+
var todos = [{
|
|
2502
|
+
regex: this.regexpUnescape,
|
|
2503
|
+
safeValue: function safeValue(val) {
|
|
2504
|
+
return regexSafe(val);
|
|
2505
|
+
}
|
|
2506
|
+
}, {
|
|
2507
|
+
regex: this.regexp,
|
|
2508
|
+
safeValue: function safeValue(val) {
|
|
2509
|
+
return _this.escapeValue ? regexSafe(_this.escape(val)) : regexSafe(val);
|
|
2510
|
+
}
|
|
2511
|
+
}];
|
|
2512
|
+
todos.forEach(function (todo) {
|
|
2513
|
+
replaces = 0;
|
|
2514
|
+
while (match = todo.regex.exec(str)) {
|
|
2515
|
+
var matchedVar = match[1].trim();
|
|
2516
|
+
value = handleFormat(matchedVar);
|
|
2517
|
+
if (value === undefined) {
|
|
2518
|
+
if (typeof missingInterpolationHandler === 'function') {
|
|
2519
|
+
var temp = missingInterpolationHandler(str, match, options);
|
|
2520
|
+
value = typeof temp === 'string' ? temp : '';
|
|
2521
|
+
} else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
|
|
2522
|
+
value = '';
|
|
2523
|
+
} else if (skipOnVariables) {
|
|
2524
|
+
value = match[0];
|
|
2525
|
+
continue;
|
|
2526
|
+
} else {
|
|
2527
|
+
_this.logger.warn("missed to pass in variable ".concat(matchedVar, " for interpolating ").concat(str));
|
|
2528
|
+
value = '';
|
|
2529
|
+
}
|
|
2530
|
+
} else if (typeof value !== 'string' && !_this.useRawValueToEscape) {
|
|
2531
|
+
value = makeString(value);
|
|
2532
|
+
}
|
|
2533
|
+
var safeValue = todo.safeValue(value);
|
|
2534
|
+
str = str.replace(match[0], safeValue);
|
|
2535
|
+
if (skipOnVariables) {
|
|
2536
|
+
todo.regex.lastIndex += value.length;
|
|
2537
|
+
todo.regex.lastIndex -= match[0].length;
|
|
2538
|
+
} else {
|
|
2539
|
+
todo.regex.lastIndex = 0;
|
|
2540
|
+
}
|
|
2541
|
+
replaces++;
|
|
2542
|
+
if (replaces >= _this.maxReplaces) {
|
|
2543
|
+
break;
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
});
|
|
2547
|
+
return str;
|
|
2548
|
+
}
|
|
2549
|
+
}, {
|
|
2550
|
+
key: "nest",
|
|
2551
|
+
value: function nest(str, fc) {
|
|
2552
|
+
var _this2 = this;
|
|
2553
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
2554
|
+
var match;
|
|
2555
|
+
var value;
|
|
2556
|
+
var clonedOptions;
|
|
2557
|
+
function handleHasOptions(key, inheritedOptions) {
|
|
2558
|
+
var sep = this.nestingOptionsSeparator;
|
|
2559
|
+
if (key.indexOf(sep) < 0) return key;
|
|
2560
|
+
var c = key.split(new RegExp("".concat(sep, "[ ]*{")));
|
|
2561
|
+
var optionsString = "{".concat(c[1]);
|
|
2562
|
+
key = c[0];
|
|
2563
|
+
optionsString = this.interpolate(optionsString, clonedOptions);
|
|
2564
|
+
var matchedSingleQuotes = optionsString.match(/'/g);
|
|
2565
|
+
var matchedDoubleQuotes = optionsString.match(/"/g);
|
|
2566
|
+
if (matchedSingleQuotes && matchedSingleQuotes.length % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
|
|
2567
|
+
optionsString = optionsString.replace(/'/g, '"');
|
|
2568
|
+
}
|
|
2569
|
+
try {
|
|
2570
|
+
clonedOptions = JSON.parse(optionsString);
|
|
2571
|
+
if (inheritedOptions) clonedOptions = _objectSpread$3(_objectSpread$3({}, inheritedOptions), clonedOptions);
|
|
2572
|
+
} catch (e) {
|
|
2573
|
+
this.logger.warn("failed parsing options string in nesting for key ".concat(key), e);
|
|
2574
|
+
return "".concat(key).concat(sep).concat(optionsString);
|
|
2575
|
+
}
|
|
2576
|
+
delete clonedOptions.defaultValue;
|
|
2577
|
+
return key;
|
|
2578
|
+
}
|
|
2579
|
+
while (match = this.nestingRegexp.exec(str)) {
|
|
2580
|
+
var formatters = [];
|
|
2581
|
+
clonedOptions = _objectSpread$3({}, options);
|
|
2582
|
+
clonedOptions = clonedOptions.replace && typeof clonedOptions.replace !== 'string' ? clonedOptions.replace : clonedOptions;
|
|
2583
|
+
clonedOptions.applyPostProcessor = false;
|
|
2584
|
+
delete clonedOptions.defaultValue;
|
|
2585
|
+
var doReduce = false;
|
|
2586
|
+
if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
|
|
2587
|
+
var r = match[1].split(this.formatSeparator).map(function (elem) {
|
|
2588
|
+
return elem.trim();
|
|
2589
|
+
});
|
|
2590
|
+
match[1] = r.shift();
|
|
2591
|
+
formatters = r;
|
|
2592
|
+
doReduce = true;
|
|
2593
|
+
}
|
|
2594
|
+
value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
|
|
2595
|
+
if (value && match[0] === str && typeof value !== 'string') return value;
|
|
2596
|
+
if (typeof value !== 'string') value = makeString(value);
|
|
2597
|
+
if (!value) {
|
|
2598
|
+
this.logger.warn("missed to resolve ".concat(match[1], " for nesting ").concat(str));
|
|
2599
|
+
value = '';
|
|
2600
|
+
}
|
|
2601
|
+
if (doReduce) {
|
|
2602
|
+
value = formatters.reduce(function (v, f) {
|
|
2603
|
+
return _this2.format(v, f, options.lng, _objectSpread$3(_objectSpread$3({}, options), {}, {
|
|
2604
|
+
interpolationkey: match[1].trim()
|
|
2605
|
+
}));
|
|
2606
|
+
}, value.trim());
|
|
2607
|
+
}
|
|
2608
|
+
str = str.replace(match[0], value);
|
|
2609
|
+
this.regexp.lastIndex = 0;
|
|
2610
|
+
}
|
|
2611
|
+
return str;
|
|
2612
|
+
}
|
|
2613
|
+
}]);
|
|
2614
|
+
return Interpolator;
|
|
2615
|
+
}();
|
|
2616
|
+
|
|
2617
|
+
function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2618
|
+
function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$2(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
2619
|
+
function parseFormatStr(formatStr) {
|
|
2620
|
+
var formatName = formatStr.toLowerCase().trim();
|
|
2621
|
+
var formatOptions = {};
|
|
2622
|
+
if (formatStr.indexOf('(') > -1) {
|
|
2623
|
+
var p = formatStr.split('(');
|
|
2624
|
+
formatName = p[0].toLowerCase().trim();
|
|
2625
|
+
var optStr = p[1].substring(0, p[1].length - 1);
|
|
2626
|
+
if (formatName === 'currency' && optStr.indexOf(':') < 0) {
|
|
2627
|
+
if (!formatOptions.currency) formatOptions.currency = optStr.trim();
|
|
2628
|
+
} else if (formatName === 'relativetime' && optStr.indexOf(':') < 0) {
|
|
2629
|
+
if (!formatOptions.range) formatOptions.range = optStr.trim();
|
|
2630
|
+
} else {
|
|
2631
|
+
var opts = optStr.split(';');
|
|
2632
|
+
opts.forEach(function (opt) {
|
|
2633
|
+
if (!opt) return;
|
|
2634
|
+
var _opt$split = opt.split(':'),
|
|
2635
|
+
_opt$split2 = _toArray(_opt$split),
|
|
2636
|
+
key = _opt$split2[0],
|
|
2637
|
+
rest = _opt$split2.slice(1);
|
|
2638
|
+
var val = rest.join(':').trim().replace(/^'+|'+$/g, '');
|
|
2639
|
+
if (!formatOptions[key.trim()]) formatOptions[key.trim()] = val;
|
|
2640
|
+
if (val === 'false') formatOptions[key.trim()] = false;
|
|
2641
|
+
if (val === 'true') formatOptions[key.trim()] = true;
|
|
2642
|
+
if (!isNaN(val)) formatOptions[key.trim()] = parseInt(val, 10);
|
|
2643
|
+
});
|
|
2644
|
+
}
|
|
2645
|
+
}
|
|
2646
|
+
return {
|
|
2647
|
+
formatName: formatName,
|
|
2648
|
+
formatOptions: formatOptions
|
|
2649
|
+
};
|
|
2650
|
+
}
|
|
2651
|
+
function createCachedFormatter(fn) {
|
|
2652
|
+
var cache = {};
|
|
2653
|
+
return function invokeFormatter(val, lng, options) {
|
|
2654
|
+
var key = lng + JSON.stringify(options);
|
|
2655
|
+
var formatter = cache[key];
|
|
2656
|
+
if (!formatter) {
|
|
2657
|
+
formatter = fn(lng, options);
|
|
2658
|
+
cache[key] = formatter;
|
|
2659
|
+
}
|
|
2660
|
+
return formatter(val);
|
|
2661
|
+
};
|
|
2662
|
+
}
|
|
2663
|
+
var Formatter = function () {
|
|
2664
|
+
function Formatter() {
|
|
2665
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2666
|
+
_classCallCheck(this, Formatter);
|
|
2667
|
+
this.logger = baseLogger.create('formatter');
|
|
2668
|
+
this.options = options;
|
|
2669
|
+
this.formats = {
|
|
2670
|
+
number: createCachedFormatter(function (lng, opt) {
|
|
2671
|
+
var formatter = new Intl.NumberFormat(lng, _objectSpread$2({}, opt));
|
|
2672
|
+
return function (val) {
|
|
2673
|
+
return formatter.format(val);
|
|
2674
|
+
};
|
|
2675
|
+
}),
|
|
2676
|
+
currency: createCachedFormatter(function (lng, opt) {
|
|
2677
|
+
var formatter = new Intl.NumberFormat(lng, _objectSpread$2(_objectSpread$2({}, opt), {}, {
|
|
2678
|
+
style: 'currency'
|
|
2679
|
+
}));
|
|
2680
|
+
return function (val) {
|
|
2681
|
+
return formatter.format(val);
|
|
2682
|
+
};
|
|
2683
|
+
}),
|
|
2684
|
+
datetime: createCachedFormatter(function (lng, opt) {
|
|
2685
|
+
var formatter = new Intl.DateTimeFormat(lng, _objectSpread$2({}, opt));
|
|
2686
|
+
return function (val) {
|
|
2687
|
+
return formatter.format(val);
|
|
2688
|
+
};
|
|
2689
|
+
}),
|
|
2690
|
+
relativetime: createCachedFormatter(function (lng, opt) {
|
|
2691
|
+
var formatter = new Intl.RelativeTimeFormat(lng, _objectSpread$2({}, opt));
|
|
2692
|
+
return function (val) {
|
|
2693
|
+
return formatter.format(val, opt.range || 'day');
|
|
2694
|
+
};
|
|
2695
|
+
}),
|
|
2696
|
+
list: createCachedFormatter(function (lng, opt) {
|
|
2697
|
+
var formatter = new Intl.ListFormat(lng, _objectSpread$2({}, opt));
|
|
2698
|
+
return function (val) {
|
|
2699
|
+
return formatter.format(val);
|
|
2700
|
+
};
|
|
2701
|
+
})
|
|
2702
|
+
};
|
|
2703
|
+
this.init(options);
|
|
2704
|
+
}
|
|
2705
|
+
_createClass(Formatter, [{
|
|
2706
|
+
key: "init",
|
|
2707
|
+
value: function init(services) {
|
|
2708
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
2709
|
+
interpolation: {}
|
|
2710
|
+
};
|
|
2711
|
+
var iOpts = options.interpolation;
|
|
2712
|
+
this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';
|
|
2713
|
+
}
|
|
2714
|
+
}, {
|
|
2715
|
+
key: "add",
|
|
2716
|
+
value: function add(name, fc) {
|
|
2717
|
+
this.formats[name.toLowerCase().trim()] = fc;
|
|
2718
|
+
}
|
|
2719
|
+
}, {
|
|
2720
|
+
key: "addCached",
|
|
2721
|
+
value: function addCached(name, fc) {
|
|
2722
|
+
this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
|
|
2723
|
+
}
|
|
2724
|
+
}, {
|
|
2725
|
+
key: "format",
|
|
2726
|
+
value: function format(value, _format, lng) {
|
|
2727
|
+
var _this = this;
|
|
2728
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
2729
|
+
var formats = _format.split(this.formatSeparator);
|
|
2730
|
+
var result = formats.reduce(function (mem, f) {
|
|
2731
|
+
var _parseFormatStr = parseFormatStr(f),
|
|
2732
|
+
formatName = _parseFormatStr.formatName,
|
|
2733
|
+
formatOptions = _parseFormatStr.formatOptions;
|
|
2734
|
+
if (_this.formats[formatName]) {
|
|
2735
|
+
var formatted = mem;
|
|
2736
|
+
try {
|
|
2737
|
+
var valOptions = options && options.formatParams && options.formatParams[options.interpolationkey] || {};
|
|
2738
|
+
var l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
|
|
2739
|
+
formatted = _this.formats[formatName](mem, l, _objectSpread$2(_objectSpread$2(_objectSpread$2({}, formatOptions), options), valOptions));
|
|
2740
|
+
} catch (error) {
|
|
2741
|
+
_this.logger.warn(error);
|
|
2742
|
+
}
|
|
2743
|
+
return formatted;
|
|
2744
|
+
} else {
|
|
2745
|
+
_this.logger.warn("there was no format function for ".concat(formatName));
|
|
2746
|
+
}
|
|
2747
|
+
return mem;
|
|
2748
|
+
}, value);
|
|
2749
|
+
return result;
|
|
2750
|
+
}
|
|
2751
|
+
}]);
|
|
2752
|
+
return Formatter;
|
|
2753
|
+
}();
|
|
2754
|
+
|
|
2755
|
+
function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2756
|
+
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
2757
|
+
function _createSuper$1(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$1(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
2758
|
+
function _isNativeReflectConstruct$1() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
2759
|
+
function removePending(q, name) {
|
|
2760
|
+
if (q.pending[name] !== undefined) {
|
|
2761
|
+
delete q.pending[name];
|
|
2762
|
+
q.pendingCount--;
|
|
2763
|
+
}
|
|
2764
|
+
}
|
|
2765
|
+
var Connector = function (_EventEmitter) {
|
|
2766
|
+
_inherits(Connector, _EventEmitter);
|
|
2767
|
+
var _super = _createSuper$1(Connector);
|
|
2768
|
+
function Connector(backend, store, services) {
|
|
2769
|
+
var _this;
|
|
2770
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
2771
|
+
_classCallCheck(this, Connector);
|
|
2772
|
+
_this = _super.call(this);
|
|
2773
|
+
if (isIE10) {
|
|
2774
|
+
EventEmitter.call(_assertThisInitialized(_this));
|
|
2775
|
+
}
|
|
2776
|
+
_this.backend = backend;
|
|
2777
|
+
_this.store = store;
|
|
2778
|
+
_this.services = services;
|
|
2779
|
+
_this.languageUtils = services.languageUtils;
|
|
2780
|
+
_this.options = options;
|
|
2781
|
+
_this.logger = baseLogger.create('backendConnector');
|
|
2782
|
+
_this.waitingReads = [];
|
|
2783
|
+
_this.maxParallelReads = options.maxParallelReads || 10;
|
|
2784
|
+
_this.readingCalls = 0;
|
|
2785
|
+
_this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
|
|
2786
|
+
_this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
|
|
2787
|
+
_this.state = {};
|
|
2788
|
+
_this.queue = [];
|
|
2789
|
+
if (_this.backend && _this.backend.init) {
|
|
2790
|
+
_this.backend.init(services, options.backend, options);
|
|
2791
|
+
}
|
|
2792
|
+
return _this;
|
|
2793
|
+
}
|
|
2794
|
+
_createClass(Connector, [{
|
|
2795
|
+
key: "queueLoad",
|
|
2796
|
+
value: function queueLoad(languages, namespaces, options, callback) {
|
|
2797
|
+
var _this2 = this;
|
|
2798
|
+
var toLoad = {};
|
|
2799
|
+
var pending = {};
|
|
2800
|
+
var toLoadLanguages = {};
|
|
2801
|
+
var toLoadNamespaces = {};
|
|
2802
|
+
languages.forEach(function (lng) {
|
|
2803
|
+
var hasAllNamespaces = true;
|
|
2804
|
+
namespaces.forEach(function (ns) {
|
|
2805
|
+
var name = "".concat(lng, "|").concat(ns);
|
|
2806
|
+
if (!options.reload && _this2.store.hasResourceBundle(lng, ns)) {
|
|
2807
|
+
_this2.state[name] = 2;
|
|
2808
|
+
} else if (_this2.state[name] < 0) ; else if (_this2.state[name] === 1) {
|
|
2809
|
+
if (pending[name] === undefined) pending[name] = true;
|
|
2810
|
+
} else {
|
|
2811
|
+
_this2.state[name] = 1;
|
|
2812
|
+
hasAllNamespaces = false;
|
|
2813
|
+
if (pending[name] === undefined) pending[name] = true;
|
|
2814
|
+
if (toLoad[name] === undefined) toLoad[name] = true;
|
|
2815
|
+
if (toLoadNamespaces[ns] === undefined) toLoadNamespaces[ns] = true;
|
|
2816
|
+
}
|
|
2817
|
+
});
|
|
2818
|
+
if (!hasAllNamespaces) toLoadLanguages[lng] = true;
|
|
2819
|
+
});
|
|
2820
|
+
if (Object.keys(toLoad).length || Object.keys(pending).length) {
|
|
2821
|
+
this.queue.push({
|
|
2822
|
+
pending: pending,
|
|
2823
|
+
pendingCount: Object.keys(pending).length,
|
|
2824
|
+
loaded: {},
|
|
2825
|
+
errors: [],
|
|
2826
|
+
callback: callback
|
|
2827
|
+
});
|
|
2828
|
+
}
|
|
2829
|
+
return {
|
|
2830
|
+
toLoad: Object.keys(toLoad),
|
|
2831
|
+
pending: Object.keys(pending),
|
|
2832
|
+
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
2833
|
+
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
2834
|
+
};
|
|
2835
|
+
}
|
|
2836
|
+
}, {
|
|
2837
|
+
key: "loaded",
|
|
2838
|
+
value: function loaded(name, err, data) {
|
|
2839
|
+
var s = name.split('|');
|
|
2840
|
+
var lng = s[0];
|
|
2841
|
+
var ns = s[1];
|
|
2842
|
+
if (err) this.emit('failedLoading', lng, ns, err);
|
|
2843
|
+
if (data) {
|
|
2844
|
+
this.store.addResourceBundle(lng, ns, data);
|
|
2845
|
+
}
|
|
2846
|
+
this.state[name] = err ? -1 : 2;
|
|
2847
|
+
var loaded = {};
|
|
2848
|
+
this.queue.forEach(function (q) {
|
|
2849
|
+
pushPath(q.loaded, [lng], ns);
|
|
2850
|
+
removePending(q, name);
|
|
2851
|
+
if (err) q.errors.push(err);
|
|
2852
|
+
if (q.pendingCount === 0 && !q.done) {
|
|
2853
|
+
Object.keys(q.loaded).forEach(function (l) {
|
|
2854
|
+
if (!loaded[l]) loaded[l] = {};
|
|
2855
|
+
var loadedKeys = q.loaded[l];
|
|
2856
|
+
if (loadedKeys.length) {
|
|
2857
|
+
loadedKeys.forEach(function (n) {
|
|
2858
|
+
if (loaded[l][n] === undefined) loaded[l][n] = true;
|
|
2859
|
+
});
|
|
2860
|
+
}
|
|
2861
|
+
});
|
|
2862
|
+
q.done = true;
|
|
2863
|
+
if (q.errors.length) {
|
|
2864
|
+
q.callback(q.errors);
|
|
2865
|
+
} else {
|
|
2866
|
+
q.callback();
|
|
2867
|
+
}
|
|
2868
|
+
}
|
|
2869
|
+
});
|
|
2870
|
+
this.emit('loaded', loaded);
|
|
2871
|
+
this.queue = this.queue.filter(function (q) {
|
|
2872
|
+
return !q.done;
|
|
2873
|
+
});
|
|
2874
|
+
}
|
|
2875
|
+
}, {
|
|
2876
|
+
key: "read",
|
|
2877
|
+
value: function read(lng, ns, fcName) {
|
|
2878
|
+
var _this3 = this;
|
|
2879
|
+
var tried = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
2880
|
+
var wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.retryTimeout;
|
|
2881
|
+
var callback = arguments.length > 5 ? arguments[5] : undefined;
|
|
2882
|
+
if (!lng.length) return callback(null, {});
|
|
2883
|
+
if (this.readingCalls >= this.maxParallelReads) {
|
|
2884
|
+
this.waitingReads.push({
|
|
2885
|
+
lng: lng,
|
|
2886
|
+
ns: ns,
|
|
2887
|
+
fcName: fcName,
|
|
2888
|
+
tried: tried,
|
|
2889
|
+
wait: wait,
|
|
2890
|
+
callback: callback
|
|
2891
|
+
});
|
|
2892
|
+
return;
|
|
2893
|
+
}
|
|
2894
|
+
this.readingCalls++;
|
|
2895
|
+
var resolver = function resolver(err, data) {
|
|
2896
|
+
_this3.readingCalls--;
|
|
2897
|
+
if (_this3.waitingReads.length > 0) {
|
|
2898
|
+
var next = _this3.waitingReads.shift();
|
|
2899
|
+
_this3.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
|
|
2900
|
+
}
|
|
2901
|
+
if (err && data && tried < _this3.maxRetries) {
|
|
2902
|
+
setTimeout(function () {
|
|
2903
|
+
_this3.read.call(_this3, lng, ns, fcName, tried + 1, wait * 2, callback);
|
|
2904
|
+
}, wait);
|
|
2905
|
+
return;
|
|
2906
|
+
}
|
|
2907
|
+
callback(err, data);
|
|
2908
|
+
};
|
|
2909
|
+
var fc = this.backend[fcName].bind(this.backend);
|
|
2910
|
+
if (fc.length === 2) {
|
|
2911
|
+
try {
|
|
2912
|
+
var r = fc(lng, ns);
|
|
2913
|
+
if (r && typeof r.then === 'function') {
|
|
2914
|
+
r.then(function (data) {
|
|
2915
|
+
return resolver(null, data);
|
|
2916
|
+
})["catch"](resolver);
|
|
2917
|
+
} else {
|
|
2918
|
+
resolver(null, r);
|
|
2919
|
+
}
|
|
2920
|
+
} catch (err) {
|
|
2921
|
+
resolver(err);
|
|
2922
|
+
}
|
|
2923
|
+
return;
|
|
2924
|
+
}
|
|
2925
|
+
return fc(lng, ns, resolver);
|
|
2926
|
+
}
|
|
2927
|
+
}, {
|
|
2928
|
+
key: "prepareLoading",
|
|
2929
|
+
value: function prepareLoading(languages, namespaces) {
|
|
2930
|
+
var _this4 = this;
|
|
2931
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
2932
|
+
var callback = arguments.length > 3 ? arguments[3] : undefined;
|
|
2933
|
+
if (!this.backend) {
|
|
2934
|
+
this.logger.warn('No backend was added via i18next.use. Will not load resources.');
|
|
2935
|
+
return callback && callback();
|
|
2936
|
+
}
|
|
2937
|
+
if (typeof languages === 'string') languages = this.languageUtils.toResolveHierarchy(languages);
|
|
2938
|
+
if (typeof namespaces === 'string') namespaces = [namespaces];
|
|
2939
|
+
var toLoad = this.queueLoad(languages, namespaces, options, callback);
|
|
2940
|
+
if (!toLoad.toLoad.length) {
|
|
2941
|
+
if (!toLoad.pending.length) callback();
|
|
2942
|
+
return null;
|
|
2943
|
+
}
|
|
2944
|
+
toLoad.toLoad.forEach(function (name) {
|
|
2945
|
+
_this4.loadOne(name);
|
|
2946
|
+
});
|
|
2947
|
+
}
|
|
2948
|
+
}, {
|
|
2949
|
+
key: "load",
|
|
2950
|
+
value: function load(languages, namespaces, callback) {
|
|
2951
|
+
this.prepareLoading(languages, namespaces, {}, callback);
|
|
2952
|
+
}
|
|
2953
|
+
}, {
|
|
2954
|
+
key: "reload",
|
|
2955
|
+
value: function reload(languages, namespaces, callback) {
|
|
2956
|
+
this.prepareLoading(languages, namespaces, {
|
|
2957
|
+
reload: true
|
|
2958
|
+
}, callback);
|
|
2959
|
+
}
|
|
2960
|
+
}, {
|
|
2961
|
+
key: "loadOne",
|
|
2962
|
+
value: function loadOne(name) {
|
|
2963
|
+
var _this5 = this;
|
|
2964
|
+
var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
2965
|
+
var s = name.split('|');
|
|
2966
|
+
var lng = s[0];
|
|
2967
|
+
var ns = s[1];
|
|
2968
|
+
this.read(lng, ns, 'read', undefined, undefined, function (err, data) {
|
|
2969
|
+
if (err) _this5.logger.warn("".concat(prefix, "loading namespace ").concat(ns, " for language ").concat(lng, " failed"), err);
|
|
2970
|
+
if (!err && data) _this5.logger.log("".concat(prefix, "loaded namespace ").concat(ns, " for language ").concat(lng), data);
|
|
2971
|
+
_this5.loaded(name, err, data);
|
|
2972
|
+
});
|
|
2973
|
+
}
|
|
2974
|
+
}, {
|
|
2975
|
+
key: "saveMissing",
|
|
2976
|
+
value: function saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
|
|
2977
|
+
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
2978
|
+
var clb = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : function () {};
|
|
2979
|
+
if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) {
|
|
2980
|
+
this.logger.warn("did not save key \"".concat(key, "\" as the namespace \"").concat(namespace, "\" was not yet loaded"), 'This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!');
|
|
2981
|
+
return;
|
|
2982
|
+
}
|
|
2983
|
+
if (key === undefined || key === null || key === '') return;
|
|
2984
|
+
if (this.backend && this.backend.create) {
|
|
2985
|
+
var opts = _objectSpread$1(_objectSpread$1({}, options), {}, {
|
|
2986
|
+
isUpdate: isUpdate
|
|
2987
|
+
});
|
|
2988
|
+
var fc = this.backend.create.bind(this.backend);
|
|
2989
|
+
if (fc.length < 6) {
|
|
2990
|
+
try {
|
|
2991
|
+
var r;
|
|
2992
|
+
if (fc.length === 5) {
|
|
2993
|
+
r = fc(languages, namespace, key, fallbackValue, opts);
|
|
2994
|
+
} else {
|
|
2995
|
+
r = fc(languages, namespace, key, fallbackValue);
|
|
2996
|
+
}
|
|
2997
|
+
if (r && typeof r.then === 'function') {
|
|
2998
|
+
r.then(function (data) {
|
|
2999
|
+
return clb(null, data);
|
|
3000
|
+
})["catch"](clb);
|
|
3001
|
+
} else {
|
|
3002
|
+
clb(null, r);
|
|
3003
|
+
}
|
|
3004
|
+
} catch (err) {
|
|
3005
|
+
clb(err);
|
|
3006
|
+
}
|
|
3007
|
+
} else {
|
|
3008
|
+
fc(languages, namespace, key, fallbackValue, clb, opts);
|
|
3009
|
+
}
|
|
3010
|
+
}
|
|
3011
|
+
if (!languages || !languages[0]) return;
|
|
3012
|
+
this.store.addResource(languages[0], namespace, key, fallbackValue);
|
|
3013
|
+
}
|
|
3014
|
+
}]);
|
|
3015
|
+
return Connector;
|
|
3016
|
+
}(EventEmitter);
|
|
3017
|
+
|
|
3018
|
+
function get() {
|
|
3019
|
+
return {
|
|
3020
|
+
debug: false,
|
|
3021
|
+
initImmediate: true,
|
|
3022
|
+
ns: ['translation'],
|
|
3023
|
+
defaultNS: ['translation'],
|
|
3024
|
+
fallbackLng: ['dev'],
|
|
3025
|
+
fallbackNS: false,
|
|
3026
|
+
supportedLngs: false,
|
|
3027
|
+
nonExplicitSupportedLngs: false,
|
|
3028
|
+
load: 'all',
|
|
3029
|
+
preload: false,
|
|
3030
|
+
simplifyPluralSuffix: true,
|
|
3031
|
+
keySeparator: '.',
|
|
3032
|
+
nsSeparator: ':',
|
|
3033
|
+
pluralSeparator: '_',
|
|
3034
|
+
contextSeparator: '_',
|
|
3035
|
+
partialBundledLanguages: false,
|
|
3036
|
+
saveMissing: false,
|
|
3037
|
+
updateMissing: false,
|
|
3038
|
+
saveMissingTo: 'fallback',
|
|
3039
|
+
saveMissingPlurals: true,
|
|
3040
|
+
missingKeyHandler: false,
|
|
3041
|
+
missingInterpolationHandler: false,
|
|
3042
|
+
postProcess: false,
|
|
3043
|
+
postProcessPassResolved: false,
|
|
3044
|
+
returnNull: true,
|
|
3045
|
+
returnEmptyString: true,
|
|
3046
|
+
returnObjects: false,
|
|
3047
|
+
joinArrays: false,
|
|
3048
|
+
returnedObjectHandler: false,
|
|
3049
|
+
parseMissingKeyHandler: false,
|
|
3050
|
+
appendNamespaceToMissingKey: false,
|
|
3051
|
+
appendNamespaceToCIMode: false,
|
|
3052
|
+
overloadTranslationOptionHandler: function handle(args) {
|
|
3053
|
+
var ret = {};
|
|
3054
|
+
if (_typeof(args[1]) === 'object') ret = args[1];
|
|
3055
|
+
if (typeof args[1] === 'string') ret.defaultValue = args[1];
|
|
3056
|
+
if (typeof args[2] === 'string') ret.tDescription = args[2];
|
|
3057
|
+
if (_typeof(args[2]) === 'object' || _typeof(args[3]) === 'object') {
|
|
3058
|
+
var options = args[3] || args[2];
|
|
3059
|
+
Object.keys(options).forEach(function (key) {
|
|
3060
|
+
ret[key] = options[key];
|
|
3061
|
+
});
|
|
3062
|
+
}
|
|
3063
|
+
return ret;
|
|
3064
|
+
},
|
|
3065
|
+
interpolation: {
|
|
3066
|
+
escapeValue: true,
|
|
3067
|
+
format: function format(value, _format, lng, options) {
|
|
3068
|
+
return value;
|
|
3069
|
+
},
|
|
3070
|
+
prefix: '{{',
|
|
3071
|
+
suffix: '}}',
|
|
3072
|
+
formatSeparator: ',',
|
|
3073
|
+
unescapePrefix: '-',
|
|
3074
|
+
nestingPrefix: '$t(',
|
|
3075
|
+
nestingSuffix: ')',
|
|
3076
|
+
nestingOptionsSeparator: ',',
|
|
3077
|
+
maxReplaces: 1000,
|
|
3078
|
+
skipOnVariables: true
|
|
3079
|
+
}
|
|
3080
|
+
};
|
|
3081
|
+
}
|
|
3082
|
+
function transformOptions(options) {
|
|
3083
|
+
if (typeof options.ns === 'string') options.ns = [options.ns];
|
|
3084
|
+
if (typeof options.fallbackLng === 'string') options.fallbackLng = [options.fallbackLng];
|
|
3085
|
+
if (typeof options.fallbackNS === 'string') options.fallbackNS = [options.fallbackNS];
|
|
3086
|
+
if (options.supportedLngs && options.supportedLngs.indexOf('cimode') < 0) {
|
|
3087
|
+
options.supportedLngs = options.supportedLngs.concat(['cimode']);
|
|
3088
|
+
}
|
|
3089
|
+
return options;
|
|
3090
|
+
}
|
|
3091
|
+
|
|
3092
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3093
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
3094
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
3095
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
3096
|
+
function noop() {}
|
|
3097
|
+
function bindMemberFunctions(inst) {
|
|
3098
|
+
var mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
|
|
3099
|
+
mems.forEach(function (mem) {
|
|
3100
|
+
if (typeof inst[mem] === 'function') {
|
|
3101
|
+
inst[mem] = inst[mem].bind(inst);
|
|
3102
|
+
}
|
|
3103
|
+
});
|
|
3104
|
+
}
|
|
3105
|
+
var I18n = function (_EventEmitter) {
|
|
3106
|
+
_inherits(I18n, _EventEmitter);
|
|
3107
|
+
var _super = _createSuper(I18n);
|
|
3108
|
+
function I18n() {
|
|
3109
|
+
var _this;
|
|
3110
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
3111
|
+
var callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
3112
|
+
_classCallCheck(this, I18n);
|
|
3113
|
+
_this = _super.call(this);
|
|
3114
|
+
if (isIE10) {
|
|
3115
|
+
EventEmitter.call(_assertThisInitialized(_this));
|
|
3116
|
+
}
|
|
3117
|
+
_this.options = transformOptions(options);
|
|
3118
|
+
_this.services = {};
|
|
3119
|
+
_this.logger = baseLogger;
|
|
3120
|
+
_this.modules = {
|
|
3121
|
+
external: []
|
|
3122
|
+
};
|
|
3123
|
+
bindMemberFunctions(_assertThisInitialized(_this));
|
|
3124
|
+
if (callback && !_this.isInitialized && !options.isClone) {
|
|
3125
|
+
if (!_this.options.initImmediate) {
|
|
3126
|
+
_this.init(options, callback);
|
|
3127
|
+
return _possibleConstructorReturn(_this, _assertThisInitialized(_this));
|
|
3128
|
+
}
|
|
3129
|
+
setTimeout(function () {
|
|
3130
|
+
_this.init(options, callback);
|
|
3131
|
+
}, 0);
|
|
3132
|
+
}
|
|
3133
|
+
return _this;
|
|
3134
|
+
}
|
|
3135
|
+
_createClass(I18n, [{
|
|
3136
|
+
key: "init",
|
|
3137
|
+
value: function init() {
|
|
3138
|
+
var _this2 = this;
|
|
3139
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
3140
|
+
var callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
3141
|
+
if (typeof options === 'function') {
|
|
3142
|
+
callback = options;
|
|
3143
|
+
options = {};
|
|
3144
|
+
}
|
|
3145
|
+
if (!options.defaultNS && options.defaultNS !== false && options.ns) {
|
|
3146
|
+
if (typeof options.ns === 'string') {
|
|
3147
|
+
options.defaultNS = options.ns;
|
|
3148
|
+
} else if (options.ns.indexOf('translation') < 0) {
|
|
3149
|
+
options.defaultNS = options.ns[0];
|
|
3150
|
+
}
|
|
3151
|
+
}
|
|
3152
|
+
var defOpts = get();
|
|
3153
|
+
this.options = _objectSpread(_objectSpread(_objectSpread({}, defOpts), this.options), transformOptions(options));
|
|
3154
|
+
if (this.options.compatibilityAPI !== 'v1') {
|
|
3155
|
+
this.options.interpolation = _objectSpread(_objectSpread({}, defOpts.interpolation), this.options.interpolation);
|
|
3156
|
+
}
|
|
3157
|
+
if (options.keySeparator !== undefined) {
|
|
3158
|
+
this.options.userDefinedKeySeparator = options.keySeparator;
|
|
3159
|
+
}
|
|
3160
|
+
if (options.nsSeparator !== undefined) {
|
|
3161
|
+
this.options.userDefinedNsSeparator = options.nsSeparator;
|
|
3162
|
+
}
|
|
3163
|
+
function createClassOnDemand(ClassOrObject) {
|
|
3164
|
+
if (!ClassOrObject) return null;
|
|
3165
|
+
if (typeof ClassOrObject === 'function') return new ClassOrObject();
|
|
3166
|
+
return ClassOrObject;
|
|
3167
|
+
}
|
|
3168
|
+
if (!this.options.isClone) {
|
|
3169
|
+
if (this.modules.logger) {
|
|
3170
|
+
baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
|
|
3171
|
+
} else {
|
|
3172
|
+
baseLogger.init(null, this.options);
|
|
3173
|
+
}
|
|
3174
|
+
var formatter;
|
|
3175
|
+
if (this.modules.formatter) {
|
|
3176
|
+
formatter = this.modules.formatter;
|
|
3177
|
+
} else if (typeof Intl !== 'undefined') {
|
|
3178
|
+
formatter = Formatter;
|
|
3179
|
+
}
|
|
3180
|
+
var lu = new LanguageUtil(this.options);
|
|
3181
|
+
this.store = new ResourceStore(this.options.resources, this.options);
|
|
3182
|
+
var s = this.services;
|
|
3183
|
+
s.logger = baseLogger;
|
|
3184
|
+
s.resourceStore = this.store;
|
|
3185
|
+
s.languageUtils = lu;
|
|
3186
|
+
s.pluralResolver = new PluralResolver(lu, {
|
|
3187
|
+
prepend: this.options.pluralSeparator,
|
|
3188
|
+
compatibilityJSON: this.options.compatibilityJSON,
|
|
3189
|
+
simplifyPluralSuffix: this.options.simplifyPluralSuffix
|
|
3190
|
+
});
|
|
3191
|
+
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
|
|
3192
|
+
s.formatter = createClassOnDemand(formatter);
|
|
3193
|
+
s.formatter.init(s, this.options);
|
|
3194
|
+
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
3195
|
+
}
|
|
3196
|
+
s.interpolator = new Interpolator(this.options);
|
|
3197
|
+
s.utils = {
|
|
3198
|
+
hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
|
|
3199
|
+
};
|
|
3200
|
+
s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
|
|
3201
|
+
s.backendConnector.on('*', function (event) {
|
|
3202
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
3203
|
+
args[_key - 1] = arguments[_key];
|
|
3204
|
+
}
|
|
3205
|
+
_this2.emit.apply(_this2, [event].concat(args));
|
|
3206
|
+
});
|
|
3207
|
+
if (this.modules.languageDetector) {
|
|
3208
|
+
s.languageDetector = createClassOnDemand(this.modules.languageDetector);
|
|
3209
|
+
if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
|
|
3210
|
+
}
|
|
3211
|
+
if (this.modules.i18nFormat) {
|
|
3212
|
+
s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
|
|
3213
|
+
if (s.i18nFormat.init) s.i18nFormat.init(this);
|
|
3214
|
+
}
|
|
3215
|
+
this.translator = new Translator(this.services, this.options);
|
|
3216
|
+
this.translator.on('*', function (event) {
|
|
3217
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
3218
|
+
args[_key2 - 1] = arguments[_key2];
|
|
3219
|
+
}
|
|
3220
|
+
_this2.emit.apply(_this2, [event].concat(args));
|
|
3221
|
+
});
|
|
3222
|
+
this.modules.external.forEach(function (m) {
|
|
3223
|
+
if (m.init) m.init(_this2);
|
|
3224
|
+
});
|
|
3225
|
+
}
|
|
3226
|
+
this.format = this.options.interpolation.format;
|
|
3227
|
+
if (!callback) callback = noop;
|
|
3228
|
+
if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
|
|
3229
|
+
var codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
3230
|
+
if (codes.length > 0 && codes[0] !== 'dev') this.options.lng = codes[0];
|
|
3231
|
+
}
|
|
3232
|
+
if (!this.services.languageDetector && !this.options.lng) {
|
|
3233
|
+
this.logger.warn('init: no languageDetector is used and no lng is defined');
|
|
3234
|
+
}
|
|
3235
|
+
var storeApi = ['getResource', 'hasResourceBundle', 'getResourceBundle', 'getDataByLanguage'];
|
|
3236
|
+
storeApi.forEach(function (fcName) {
|
|
3237
|
+
_this2[fcName] = function () {
|
|
3238
|
+
var _this2$store;
|
|
3239
|
+
return (_this2$store = _this2.store)[fcName].apply(_this2$store, arguments);
|
|
3240
|
+
};
|
|
3241
|
+
});
|
|
3242
|
+
var storeApiChained = ['addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle'];
|
|
3243
|
+
storeApiChained.forEach(function (fcName) {
|
|
3244
|
+
_this2[fcName] = function () {
|
|
3245
|
+
var _this2$store2;
|
|
3246
|
+
(_this2$store2 = _this2.store)[fcName].apply(_this2$store2, arguments);
|
|
3247
|
+
return _this2;
|
|
3248
|
+
};
|
|
3249
|
+
});
|
|
3250
|
+
var deferred = defer();
|
|
3251
|
+
var load = function load() {
|
|
3252
|
+
var finish = function finish(err, t) {
|
|
3253
|
+
if (_this2.isInitialized && !_this2.initializedStoreOnce) _this2.logger.warn('init: i18next is already initialized. You should call init just once!');
|
|
3254
|
+
_this2.isInitialized = true;
|
|
3255
|
+
if (!_this2.options.isClone) _this2.logger.log('initialized', _this2.options);
|
|
3256
|
+
_this2.emit('initialized', _this2.options);
|
|
3257
|
+
deferred.resolve(t);
|
|
3258
|
+
callback(err, t);
|
|
3259
|
+
};
|
|
3260
|
+
if (_this2.languages && _this2.options.compatibilityAPI !== 'v1' && !_this2.isInitialized) return finish(null, _this2.t.bind(_this2));
|
|
3261
|
+
_this2.changeLanguage(_this2.options.lng, finish);
|
|
3262
|
+
};
|
|
3263
|
+
if (this.options.resources || !this.options.initImmediate) {
|
|
3264
|
+
load();
|
|
3265
|
+
} else {
|
|
3266
|
+
setTimeout(load, 0);
|
|
3267
|
+
}
|
|
3268
|
+
return deferred;
|
|
3269
|
+
}
|
|
3270
|
+
}, {
|
|
3271
|
+
key: "loadResources",
|
|
3272
|
+
value: function loadResources(language) {
|
|
3273
|
+
var _this3 = this;
|
|
3274
|
+
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
|
|
3275
|
+
var usedCallback = callback;
|
|
3276
|
+
var usedLng = typeof language === 'string' ? language : this.language;
|
|
3277
|
+
if (typeof language === 'function') usedCallback = language;
|
|
3278
|
+
if (!this.options.resources || this.options.partialBundledLanguages) {
|
|
3279
|
+
if (usedLng && usedLng.toLowerCase() === 'cimode') return usedCallback();
|
|
3280
|
+
var toLoad = [];
|
|
3281
|
+
var append = function append(lng) {
|
|
3282
|
+
if (!lng) return;
|
|
3283
|
+
var lngs = _this3.services.languageUtils.toResolveHierarchy(lng);
|
|
3284
|
+
lngs.forEach(function (l) {
|
|
3285
|
+
if (toLoad.indexOf(l) < 0) toLoad.push(l);
|
|
3286
|
+
});
|
|
3287
|
+
};
|
|
3288
|
+
if (!usedLng) {
|
|
3289
|
+
var fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
3290
|
+
fallbacks.forEach(function (l) {
|
|
3291
|
+
return append(l);
|
|
3292
|
+
});
|
|
3293
|
+
} else {
|
|
3294
|
+
append(usedLng);
|
|
3295
|
+
}
|
|
3296
|
+
if (this.options.preload) {
|
|
3297
|
+
this.options.preload.forEach(function (l) {
|
|
3298
|
+
return append(l);
|
|
3299
|
+
});
|
|
3300
|
+
}
|
|
3301
|
+
this.services.backendConnector.load(toLoad, this.options.ns, function (e) {
|
|
3302
|
+
if (!e && !_this3.resolvedLanguage && _this3.language) _this3.setResolvedLanguage(_this3.language);
|
|
3303
|
+
usedCallback(e);
|
|
3304
|
+
});
|
|
3305
|
+
} else {
|
|
3306
|
+
usedCallback(null);
|
|
3307
|
+
}
|
|
3308
|
+
}
|
|
3309
|
+
}, {
|
|
3310
|
+
key: "reloadResources",
|
|
3311
|
+
value: function reloadResources(lngs, ns, callback) {
|
|
3312
|
+
var deferred = defer();
|
|
3313
|
+
if (!lngs) lngs = this.languages;
|
|
3314
|
+
if (!ns) ns = this.options.ns;
|
|
3315
|
+
if (!callback) callback = noop;
|
|
3316
|
+
this.services.backendConnector.reload(lngs, ns, function (err) {
|
|
3317
|
+
deferred.resolve();
|
|
3318
|
+
callback(err);
|
|
3319
|
+
});
|
|
3320
|
+
return deferred;
|
|
3321
|
+
}
|
|
3322
|
+
}, {
|
|
3323
|
+
key: "use",
|
|
3324
|
+
value: function use(module) {
|
|
3325
|
+
if (!module) throw new Error('You are passing an undefined module! Please check the object you are passing to i18next.use()');
|
|
3326
|
+
if (!module.type) throw new Error('You are passing a wrong module! Please check the object you are passing to i18next.use()');
|
|
3327
|
+
if (module.type === 'backend') {
|
|
3328
|
+
this.modules.backend = module;
|
|
3329
|
+
}
|
|
3330
|
+
if (module.type === 'logger' || module.log && module.warn && module.error) {
|
|
3331
|
+
this.modules.logger = module;
|
|
3332
|
+
}
|
|
3333
|
+
if (module.type === 'languageDetector') {
|
|
3334
|
+
this.modules.languageDetector = module;
|
|
3335
|
+
}
|
|
3336
|
+
if (module.type === 'i18nFormat') {
|
|
3337
|
+
this.modules.i18nFormat = module;
|
|
3338
|
+
}
|
|
3339
|
+
if (module.type === 'postProcessor') {
|
|
3340
|
+
postProcessor.addPostProcessor(module);
|
|
3341
|
+
}
|
|
3342
|
+
if (module.type === 'formatter') {
|
|
3343
|
+
this.modules.formatter = module;
|
|
3344
|
+
}
|
|
3345
|
+
if (module.type === '3rdParty') {
|
|
3346
|
+
this.modules.external.push(module);
|
|
3347
|
+
}
|
|
3348
|
+
return this;
|
|
3349
|
+
}
|
|
3350
|
+
}, {
|
|
3351
|
+
key: "setResolvedLanguage",
|
|
3352
|
+
value: function setResolvedLanguage(l) {
|
|
3353
|
+
if (!l || !this.languages) return;
|
|
3354
|
+
if (['cimode', 'dev'].indexOf(l) > -1) return;
|
|
3355
|
+
for (var li = 0; li < this.languages.length; li++) {
|
|
3356
|
+
var lngInLngs = this.languages[li];
|
|
3357
|
+
if (['cimode', 'dev'].indexOf(lngInLngs) > -1) continue;
|
|
3358
|
+
if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
|
|
3359
|
+
this.resolvedLanguage = lngInLngs;
|
|
3360
|
+
break;
|
|
3361
|
+
}
|
|
3362
|
+
}
|
|
3363
|
+
}
|
|
3364
|
+
}, {
|
|
3365
|
+
key: "changeLanguage",
|
|
3366
|
+
value: function changeLanguage(lng, callback) {
|
|
3367
|
+
var _this4 = this;
|
|
3368
|
+
this.isLanguageChangingTo = lng;
|
|
3369
|
+
var deferred = defer();
|
|
3370
|
+
this.emit('languageChanging', lng);
|
|
3371
|
+
var setLngProps = function setLngProps(l) {
|
|
3372
|
+
_this4.language = l;
|
|
3373
|
+
_this4.languages = _this4.services.languageUtils.toResolveHierarchy(l);
|
|
3374
|
+
_this4.resolvedLanguage = undefined;
|
|
3375
|
+
_this4.setResolvedLanguage(l);
|
|
3376
|
+
};
|
|
3377
|
+
var done = function done(err, l) {
|
|
3378
|
+
if (l) {
|
|
3379
|
+
setLngProps(l);
|
|
3380
|
+
_this4.translator.changeLanguage(l);
|
|
3381
|
+
_this4.isLanguageChangingTo = undefined;
|
|
3382
|
+
_this4.emit('languageChanged', l);
|
|
3383
|
+
_this4.logger.log('languageChanged', l);
|
|
3384
|
+
} else {
|
|
3385
|
+
_this4.isLanguageChangingTo = undefined;
|
|
3386
|
+
}
|
|
3387
|
+
deferred.resolve(function () {
|
|
3388
|
+
return _this4.t.apply(_this4, arguments);
|
|
3389
|
+
});
|
|
3390
|
+
if (callback) callback(err, function () {
|
|
3391
|
+
return _this4.t.apply(_this4, arguments);
|
|
3392
|
+
});
|
|
3393
|
+
};
|
|
3394
|
+
var setLng = function setLng(lngs) {
|
|
3395
|
+
if (!lng && !lngs && _this4.services.languageDetector) lngs = [];
|
|
3396
|
+
var l = typeof lngs === 'string' ? lngs : _this4.services.languageUtils.getBestMatchFromCodes(lngs);
|
|
3397
|
+
if (l) {
|
|
3398
|
+
if (!_this4.language) {
|
|
3399
|
+
setLngProps(l);
|
|
3400
|
+
}
|
|
3401
|
+
if (!_this4.translator.language) _this4.translator.changeLanguage(l);
|
|
3402
|
+
if (_this4.services.languageDetector && _this4.services.languageDetector.cacheUserLanguage) _this4.services.languageDetector.cacheUserLanguage(l);
|
|
3403
|
+
}
|
|
3404
|
+
_this4.loadResources(l, function (err) {
|
|
3405
|
+
done(err, l);
|
|
3406
|
+
});
|
|
3407
|
+
};
|
|
3408
|
+
if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
|
|
3409
|
+
setLng(this.services.languageDetector.detect());
|
|
3410
|
+
} else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
|
|
3411
|
+
if (this.services.languageDetector.detect.length === 0) {
|
|
3412
|
+
this.services.languageDetector.detect().then(setLng);
|
|
3413
|
+
} else {
|
|
3414
|
+
this.services.languageDetector.detect(setLng);
|
|
3415
|
+
}
|
|
3416
|
+
} else {
|
|
3417
|
+
setLng(lng);
|
|
3418
|
+
}
|
|
3419
|
+
return deferred;
|
|
3420
|
+
}
|
|
3421
|
+
}, {
|
|
3422
|
+
key: "getFixedT",
|
|
3423
|
+
value: function getFixedT(lng, ns, keyPrefix) {
|
|
3424
|
+
var _this5 = this;
|
|
3425
|
+
var fixedT = function fixedT(key, opts) {
|
|
3426
|
+
var options;
|
|
3427
|
+
if (_typeof(opts) !== 'object') {
|
|
3428
|
+
for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
3429
|
+
rest[_key3 - 2] = arguments[_key3];
|
|
3430
|
+
}
|
|
3431
|
+
options = _this5.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
3432
|
+
} else {
|
|
3433
|
+
options = _objectSpread({}, opts);
|
|
3434
|
+
}
|
|
3435
|
+
options.lng = options.lng || fixedT.lng;
|
|
3436
|
+
options.lngs = options.lngs || fixedT.lngs;
|
|
3437
|
+
options.ns = options.ns || fixedT.ns;
|
|
3438
|
+
options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
|
|
3439
|
+
var keySeparator = _this5.options.keySeparator || '.';
|
|
3440
|
+
var resultKey;
|
|
3441
|
+
if (options.keyPrefix && Array.isArray(key)) {
|
|
3442
|
+
resultKey = key.map(function (k) {
|
|
3443
|
+
return "".concat(options.keyPrefix).concat(keySeparator).concat(k);
|
|
3444
|
+
});
|
|
3445
|
+
} else {
|
|
3446
|
+
resultKey = options.keyPrefix ? "".concat(options.keyPrefix).concat(keySeparator).concat(key) : key;
|
|
3447
|
+
}
|
|
3448
|
+
return _this5.t(resultKey, options);
|
|
3449
|
+
};
|
|
3450
|
+
if (typeof lng === 'string') {
|
|
3451
|
+
fixedT.lng = lng;
|
|
3452
|
+
} else {
|
|
3453
|
+
fixedT.lngs = lng;
|
|
3454
|
+
}
|
|
3455
|
+
fixedT.ns = ns;
|
|
3456
|
+
fixedT.keyPrefix = keyPrefix;
|
|
3457
|
+
return fixedT;
|
|
3458
|
+
}
|
|
3459
|
+
}, {
|
|
3460
|
+
key: "t",
|
|
3461
|
+
value: function t() {
|
|
3462
|
+
var _this$translator;
|
|
3463
|
+
return this.translator && (_this$translator = this.translator).translate.apply(_this$translator, arguments);
|
|
3464
|
+
}
|
|
3465
|
+
}, {
|
|
3466
|
+
key: "exists",
|
|
3467
|
+
value: function exists() {
|
|
3468
|
+
var _this$translator2;
|
|
3469
|
+
return this.translator && (_this$translator2 = this.translator).exists.apply(_this$translator2, arguments);
|
|
3470
|
+
}
|
|
3471
|
+
}, {
|
|
3472
|
+
key: "setDefaultNamespace",
|
|
3473
|
+
value: function setDefaultNamespace(ns) {
|
|
3474
|
+
this.options.defaultNS = ns;
|
|
3475
|
+
}
|
|
3476
|
+
}, {
|
|
3477
|
+
key: "hasLoadedNamespace",
|
|
3478
|
+
value: function hasLoadedNamespace(ns) {
|
|
3479
|
+
var _this6 = this;
|
|
3480
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
3481
|
+
if (!this.isInitialized) {
|
|
3482
|
+
this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
|
|
3483
|
+
return false;
|
|
3484
|
+
}
|
|
3485
|
+
if (!this.languages || !this.languages.length) {
|
|
3486
|
+
this.logger.warn('hasLoadedNamespace: i18n.languages were undefined or empty', this.languages);
|
|
3487
|
+
return false;
|
|
3488
|
+
}
|
|
3489
|
+
var lng = options.lng || this.resolvedLanguage || this.languages[0];
|
|
3490
|
+
var fallbackLng = this.options ? this.options.fallbackLng : false;
|
|
3491
|
+
var lastLng = this.languages[this.languages.length - 1];
|
|
3492
|
+
if (lng.toLowerCase() === 'cimode') return true;
|
|
3493
|
+
var loadNotPending = function loadNotPending(l, n) {
|
|
3494
|
+
var loadState = _this6.services.backendConnector.state["".concat(l, "|").concat(n)];
|
|
3495
|
+
return loadState === -1 || loadState === 2;
|
|
3496
|
+
};
|
|
3497
|
+
if (options.precheck) {
|
|
3498
|
+
var preResult = options.precheck(this, loadNotPending);
|
|
3499
|
+
if (preResult !== undefined) return preResult;
|
|
3500
|
+
}
|
|
3501
|
+
if (this.hasResourceBundle(lng, ns)) return true;
|
|
3502
|
+
if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
|
|
3503
|
+
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
3504
|
+
return false;
|
|
3505
|
+
}
|
|
3506
|
+
}, {
|
|
3507
|
+
key: "loadNamespaces",
|
|
3508
|
+
value: function loadNamespaces(ns, callback) {
|
|
3509
|
+
var _this7 = this;
|
|
3510
|
+
var deferred = defer();
|
|
3511
|
+
if (!this.options.ns) {
|
|
3512
|
+
if (callback) callback();
|
|
3513
|
+
return Promise.resolve();
|
|
3514
|
+
}
|
|
3515
|
+
if (typeof ns === 'string') ns = [ns];
|
|
3516
|
+
ns.forEach(function (n) {
|
|
3517
|
+
if (_this7.options.ns.indexOf(n) < 0) _this7.options.ns.push(n);
|
|
3518
|
+
});
|
|
3519
|
+
this.loadResources(function (err) {
|
|
3520
|
+
deferred.resolve();
|
|
3521
|
+
if (callback) callback(err);
|
|
3522
|
+
});
|
|
3523
|
+
return deferred;
|
|
3524
|
+
}
|
|
3525
|
+
}, {
|
|
3526
|
+
key: "loadLanguages",
|
|
3527
|
+
value: function loadLanguages(lngs, callback) {
|
|
3528
|
+
var deferred = defer();
|
|
3529
|
+
if (typeof lngs === 'string') lngs = [lngs];
|
|
3530
|
+
var preloaded = this.options.preload || [];
|
|
3531
|
+
var newLngs = lngs.filter(function (lng) {
|
|
3532
|
+
return preloaded.indexOf(lng) < 0;
|
|
3533
|
+
});
|
|
3534
|
+
if (!newLngs.length) {
|
|
3535
|
+
if (callback) callback();
|
|
3536
|
+
return Promise.resolve();
|
|
3537
|
+
}
|
|
3538
|
+
this.options.preload = preloaded.concat(newLngs);
|
|
3539
|
+
this.loadResources(function (err) {
|
|
3540
|
+
deferred.resolve();
|
|
3541
|
+
if (callback) callback(err);
|
|
3542
|
+
});
|
|
3543
|
+
return deferred;
|
|
3544
|
+
}
|
|
3545
|
+
}, {
|
|
3546
|
+
key: "dir",
|
|
3547
|
+
value: function dir(lng) {
|
|
3548
|
+
if (!lng) lng = this.resolvedLanguage || (this.languages && this.languages.length > 0 ? this.languages[0] : this.language);
|
|
3549
|
+
if (!lng) return 'rtl';
|
|
3550
|
+
var rtlLngs = ['ar', 'shu', 'sqr', 'ssh', 'xaa', 'yhd', 'yud', 'aao', 'abh', 'abv', 'acm', 'acq', 'acw', 'acx', 'acy', 'adf', 'ads', 'aeb', 'aec', 'afb', 'ajp', 'apc', 'apd', 'arb', 'arq', 'ars', 'ary', 'arz', 'auz', 'avl', 'ayh', 'ayl', 'ayn', 'ayp', 'bbz', 'pga', 'he', 'iw', 'ps', 'pbt', 'pbu', 'pst', 'prp', 'prd', 'ug', 'ur', 'ydd', 'yds', 'yih', 'ji', 'yi', 'hbo', 'men', 'xmn', 'fa', 'jpr', 'peo', 'pes', 'prs', 'dv', 'sam', 'ckb'];
|
|
3551
|
+
var languageUtils = this.services && this.services.languageUtils || new LanguageUtil(get());
|
|
3552
|
+
return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
|
|
3553
|
+
}
|
|
3554
|
+
}, {
|
|
3555
|
+
key: "cloneInstance",
|
|
3556
|
+
value: function cloneInstance() {
|
|
3557
|
+
var _this8 = this;
|
|
3558
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
3559
|
+
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
|
|
3560
|
+
var mergedOptions = _objectSpread(_objectSpread(_objectSpread({}, this.options), options), {
|
|
3561
|
+
isClone: true
|
|
3562
|
+
});
|
|
3563
|
+
var clone = new I18n(mergedOptions);
|
|
3564
|
+
if (options.debug !== undefined || options.prefix !== undefined) {
|
|
3565
|
+
clone.logger = clone.logger.clone(options);
|
|
3566
|
+
}
|
|
3567
|
+
var membersToCopy = ['store', 'services', 'language'];
|
|
3568
|
+
membersToCopy.forEach(function (m) {
|
|
3569
|
+
clone[m] = _this8[m];
|
|
3570
|
+
});
|
|
3571
|
+
clone.services = _objectSpread({}, this.services);
|
|
3572
|
+
clone.services.utils = {
|
|
3573
|
+
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
3574
|
+
};
|
|
3575
|
+
clone.translator = new Translator(clone.services, clone.options);
|
|
3576
|
+
clone.translator.on('*', function (event) {
|
|
3577
|
+
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
|
3578
|
+
args[_key4 - 1] = arguments[_key4];
|
|
3579
|
+
}
|
|
3580
|
+
clone.emit.apply(clone, [event].concat(args));
|
|
3581
|
+
});
|
|
3582
|
+
clone.init(mergedOptions, callback);
|
|
3583
|
+
clone.translator.options = clone.options;
|
|
3584
|
+
clone.translator.backendConnector.services.utils = {
|
|
3585
|
+
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
3586
|
+
};
|
|
3587
|
+
return clone;
|
|
3588
|
+
}
|
|
3589
|
+
}, {
|
|
3590
|
+
key: "toJSON",
|
|
3591
|
+
value: function toJSON() {
|
|
3592
|
+
return {
|
|
3593
|
+
options: this.options,
|
|
3594
|
+
store: this.store,
|
|
3595
|
+
language: this.language,
|
|
3596
|
+
languages: this.languages,
|
|
3597
|
+
resolvedLanguage: this.resolvedLanguage
|
|
3598
|
+
};
|
|
3599
|
+
}
|
|
3600
|
+
}]);
|
|
3601
|
+
return I18n;
|
|
3602
|
+
}(EventEmitter);
|
|
3603
|
+
_defineProperty(I18n, "createInstance", function () {
|
|
3604
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
3605
|
+
var callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
3606
|
+
return new I18n(options, callback);
|
|
3607
|
+
});
|
|
3608
|
+
var instance = I18n.createInstance();
|
|
3609
|
+
instance.createInstance = I18n.createInstance;
|
|
3610
|
+
|
|
3611
|
+
instance.createInstance;
|
|
3612
|
+
instance.dir;
|
|
3613
|
+
instance.init;
|
|
3614
|
+
instance.loadResources;
|
|
3615
|
+
instance.reloadResources;
|
|
3616
|
+
instance.use;
|
|
3617
|
+
instance.changeLanguage;
|
|
3618
|
+
instance.getFixedT;
|
|
3619
|
+
instance.t;
|
|
3620
|
+
instance.exists;
|
|
3621
|
+
instance.setDefaultNamespace;
|
|
3622
|
+
instance.hasLoadedNamespace;
|
|
3623
|
+
instance.loadNamespaces;
|
|
3624
|
+
instance.loadLanguages;
|
|
3625
|
+
|
|
3626
|
+
function _extends() {
|
|
3627
|
+
_extends = Object.assign || function (target) {
|
|
3628
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
3629
|
+
var source = arguments[i];
|
|
3630
|
+
|
|
3631
|
+
for (var key in source) {
|
|
3632
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
3633
|
+
target[key] = source[key];
|
|
3634
|
+
}
|
|
3635
|
+
}
|
|
3636
|
+
}
|
|
3637
|
+
|
|
3638
|
+
return target;
|
|
3639
|
+
};
|
|
3640
|
+
|
|
3641
|
+
return _extends.apply(this, arguments);
|
|
3642
|
+
}
|
|
3643
|
+
|
|
3644
|
+
var en = {
|
|
3645
|
+
translation: {
|
|
3646
|
+
categorize: {
|
|
3647
|
+
limitMaxChoicesPerCategory: "You've reached the limit of {{maxChoicesPerCategory}} responses per area. To add another response, one must first be removed.",
|
|
3648
|
+
maxChoicesPerCategoryRestriction: 'To change this value to {{maxChoicesPerCategory}}, each category must have {{maxChoicesPerCategory}} or fewer answer choice[s].'
|
|
3649
|
+
},
|
|
3650
|
+
ebsr: {
|
|
3651
|
+
part: 'Part {{index}}'
|
|
3652
|
+
},
|
|
3653
|
+
numberLine: {
|
|
3654
|
+
addElementLimit_one: 'You can only add {{count}} element',
|
|
3655
|
+
addElementLimit_other: 'You can only add {{count}} elements',
|
|
3656
|
+
clearAll: 'Clear all'
|
|
3657
|
+
},
|
|
3658
|
+
imageClozeAssociation: {
|
|
3659
|
+
reachedLimit_one: 'You’ve reached the limit of {{count}} response per area. To add another response, one must first be removed.',
|
|
3660
|
+
reachedLimit_other: 'Full'
|
|
3661
|
+
},
|
|
3662
|
+
drawingResponse: {
|
|
3663
|
+
fillColor: 'Fill color',
|
|
3664
|
+
outlineColor: 'Outline color',
|
|
3665
|
+
noFill: 'No fill',
|
|
3666
|
+
lightblue: 'Light blue',
|
|
3667
|
+
lightyellow: 'Light yellow',
|
|
3668
|
+
red: 'Red',
|
|
3669
|
+
orange: 'Orange',
|
|
3670
|
+
yellow: 'Yellow',
|
|
3671
|
+
violet: 'Violet',
|
|
3672
|
+
blue: 'Blue',
|
|
3673
|
+
green: 'Green',
|
|
3674
|
+
white: 'White',
|
|
3675
|
+
black: 'Black',
|
|
3676
|
+
onDoubleClick: 'Double click to edit this text. Press Enter to submit.'
|
|
3677
|
+
},
|
|
3678
|
+
charting: {
|
|
3679
|
+
addCategory: 'Add category',
|
|
3680
|
+
actions: 'Actions',
|
|
3681
|
+
add: 'Add',
|
|
3682
|
+
delete: 'Delete',
|
|
3683
|
+
newLabel: 'New label',
|
|
3684
|
+
reachedLimit_other: "There can't be more than {{count}} categories.",
|
|
3685
|
+
keyLegend: {
|
|
3686
|
+
incorrectAnswer: 'Student incorrect answer',
|
|
3687
|
+
correctAnswer: 'Student correct answer',
|
|
3688
|
+
correctKeyAnswer: 'Answer key correct'
|
|
3689
|
+
}
|
|
3690
|
+
},
|
|
3691
|
+
graphing: {
|
|
3692
|
+
point: 'Point',
|
|
3693
|
+
circle: 'Circle',
|
|
3694
|
+
line: 'Line',
|
|
3695
|
+
parabola: 'Parabola',
|
|
3696
|
+
absolute: 'Absolute Value',
|
|
3697
|
+
exponential: 'Exponential',
|
|
3698
|
+
polygon: 'Polygon',
|
|
3699
|
+
ray: 'Ray',
|
|
3700
|
+
segment: 'Segment',
|
|
3701
|
+
sine: 'Sine',
|
|
3702
|
+
vector: 'Vector',
|
|
3703
|
+
label: 'Label',
|
|
3704
|
+
redo: 'Redo',
|
|
3705
|
+
reset: 'Reset'
|
|
3706
|
+
},
|
|
3707
|
+
mathInline: {
|
|
3708
|
+
primaryCorrectWithAlternates: 'Note: The answer shown above is the primary correct answer specified by the author for this item, but other answers may also be recognized as correct.'
|
|
3709
|
+
},
|
|
3710
|
+
multipleChoice: {
|
|
3711
|
+
minSelections: 'Select at least {{minSelections}}.',
|
|
3712
|
+
maxSelections_one: 'Only {{maxSelections}} answer is allowed.',
|
|
3713
|
+
maxSelections_other: 'Only {{maxSelections}} answers are allowed.',
|
|
3714
|
+
minmaxSelections_equal: 'Select {{minSelections}}.',
|
|
3715
|
+
minmaxSelections_range: 'Select between {{minSelections}} and {{maxSelections}}.'
|
|
3716
|
+
},
|
|
3717
|
+
selectText: {
|
|
3718
|
+
correctAnswerSelected: 'Correct',
|
|
3719
|
+
correctAnswerNotSelected: 'Correct Answer Not Selected',
|
|
3720
|
+
incorrectSelection: 'Incorrect Selection',
|
|
3721
|
+
key: 'Key'
|
|
3722
|
+
}
|
|
3723
|
+
},
|
|
3724
|
+
common: {
|
|
3725
|
+
undo: 'Undo',
|
|
3726
|
+
clearAll: 'Clear all',
|
|
3727
|
+
correct: 'Correct',
|
|
3728
|
+
incorrect: 'Incorrect',
|
|
3729
|
+
showCorrectAnswer: 'Show correct answer',
|
|
3730
|
+
hideCorrectAnswer: 'Hide correct answer',
|
|
3731
|
+
commonCorrectAnswerWithAlternates: 'Note: The answer shown above is the most common correct answer for this item. One or more additional correct answers are also defined, and will also be recognized as correct.',
|
|
3732
|
+
warning: 'Warning',
|
|
3733
|
+
showNote: 'Show Note',
|
|
3734
|
+
hideNote: 'Hide Note',
|
|
3735
|
+
cancel: 'Cancel'
|
|
3736
|
+
}
|
|
3737
|
+
};
|
|
3738
|
+
|
|
3739
|
+
var es = {
|
|
3740
|
+
translation: {
|
|
3741
|
+
categorize: {
|
|
3742
|
+
limitMaxChoicesPerCategory: 'Has alcanzado el límite de {{maxChoicesPerCategory}} respuestas por área. Para agregar otra respuesta, primero se debe eliminar una respuesta.',
|
|
3743
|
+
maxChoicesPerCategoryRestriction: 'Para cambiar este valor a {{maxChoicesPerCategory}}, cada categoría debe tener {{maxChoicesPerCategory}} o menos opciones de respuesta'
|
|
3744
|
+
},
|
|
3745
|
+
ebsr: {
|
|
3746
|
+
part: 'Parte {{index}}'
|
|
3747
|
+
},
|
|
3748
|
+
numberLine: {
|
|
3749
|
+
addElementLimit_one: 'Solo puedes agregar {{count}} elemento',
|
|
3750
|
+
addElementLimit_other: 'Solo puedes agregar {{count}} elementos',
|
|
3751
|
+
clearAll: 'Borrar todo'
|
|
3752
|
+
},
|
|
3753
|
+
imageClozeAssociation: {
|
|
3754
|
+
reachedLimit_one: 'Has alcanzado el límite de {{count}} respuesta por área. Para agregar otra respuesta, primero se debe eliminar una respuesta.',
|
|
3755
|
+
reachedLimit_other: 'Lleno'
|
|
3756
|
+
},
|
|
3757
|
+
drawingResponse: {
|
|
3758
|
+
fillColor: 'Color de relleno',
|
|
3759
|
+
outlineColor: 'Color del contorno',
|
|
3760
|
+
noFill: 'Sin relleno',
|
|
3761
|
+
lightblue: 'Azul claro',
|
|
3762
|
+
lightyellow: 'Amarillo claro',
|
|
3763
|
+
red: 'Rojo',
|
|
3764
|
+
orange: 'Naranja',
|
|
3765
|
+
yellow: 'Amarillo',
|
|
3766
|
+
violet: 'Violeta',
|
|
3767
|
+
blue: 'Azul',
|
|
3768
|
+
green: 'Verde',
|
|
3769
|
+
white: 'Blanco',
|
|
3770
|
+
black: 'Negro',
|
|
3771
|
+
onDoubleClick: 'Haz doble clic para revisar este texto. Presiona el botón de ingreso para enviar'
|
|
3772
|
+
},
|
|
3773
|
+
charting: {
|
|
3774
|
+
addCategory: 'Añadir categoría',
|
|
3775
|
+
actions: 'Acciones',
|
|
3776
|
+
add: 'Añadir',
|
|
3777
|
+
delete: 'Eliminar',
|
|
3778
|
+
newLabel: 'Nueva etiqueta',
|
|
3779
|
+
reachedLimit_other: 'No puede haber más de {{count}} categorías.',
|
|
3780
|
+
keyLegend: {
|
|
3781
|
+
incorrectAnswer: 'Respuesta incorrecta del estudiante',
|
|
3782
|
+
correctAnswer: 'Respuesta correcta del estudiante',
|
|
3783
|
+
correctKeyAnswer: 'Clave de respuesta correcta'
|
|
3784
|
+
}
|
|
3785
|
+
},
|
|
3786
|
+
graphing: {
|
|
3787
|
+
point: 'Punto',
|
|
3788
|
+
circle: 'Circulo',
|
|
3789
|
+
line: 'Línea',
|
|
3790
|
+
parabola: 'Parábola',
|
|
3791
|
+
absolute: 'Valor absoluto',
|
|
3792
|
+
exponential: 'Exponencial',
|
|
3793
|
+
polygon: 'Polígono',
|
|
3794
|
+
ray: 'Semirrecta',
|
|
3795
|
+
segment: 'Segmento ',
|
|
3796
|
+
sine: 'Seno',
|
|
3797
|
+
vector: 'Vector',
|
|
3798
|
+
label: 'Etiqueta',
|
|
3799
|
+
redo: 'Rehacer',
|
|
3800
|
+
reset: 'Reiniciar'
|
|
3801
|
+
},
|
|
3802
|
+
mathInline: {
|
|
3803
|
+
primaryCorrectWithAlternates: 'Nota: La respuesta que se muestra arriba es la respuesta correcta principal especificada por el autor para esta pregunta, pero también se pueden reconocer otras respuestas como correctas.'
|
|
3804
|
+
},
|
|
3805
|
+
multipleChoice: {
|
|
3806
|
+
minSelections: 'Seleccione al menos {{minSelections}}.',
|
|
3807
|
+
maxSelections_one: 'Sólo se permite {{maxSelections}} respuesta.',
|
|
3808
|
+
maxSelections_other: 'Sólo se permiten {{maxSelections}} respuestas.',
|
|
3809
|
+
minmaxSelections_equal: 'Seleccione {{minSelections}}.',
|
|
3810
|
+
minmaxSelections_range: 'Seleccione entre {{minSelections}} y {{maxSelections}}.'
|
|
3811
|
+
},
|
|
3812
|
+
selectText: {
|
|
3813
|
+
correctAnswerSelected: 'Respuesta Correcta',
|
|
3814
|
+
correctAnswerNotSelected: 'Respuesta Correcta No Seleccionada',
|
|
3815
|
+
incorrectSelection: 'Selección Incorrecta',
|
|
3816
|
+
key: 'Clave'
|
|
3817
|
+
}
|
|
3818
|
+
},
|
|
3819
|
+
common: {
|
|
3820
|
+
undo: 'Deshacer',
|
|
3821
|
+
clearAll: 'Borrar todo',
|
|
3822
|
+
correct: 'Correct',
|
|
3823
|
+
incorrect: 'Incorrect',
|
|
3824
|
+
showCorrectAnswer: 'Mostrar respuesta correcta',
|
|
3825
|
+
hideCorrectAnswer: 'Ocultar respuesta correcta',
|
|
3826
|
+
commonCorrectAnswerWithAlternates: 'Nota: La respuesta que se muestra arriba es la respuesta correcta más común para esta pregunta. También se definen una o más respuestas correctas adicionales, y también se reconocerán como correctas.',
|
|
3827
|
+
warning: 'Advertencia',
|
|
3828
|
+
showNote: 'Mostrar Nota',
|
|
3829
|
+
hideNote: 'Ocultar Nota',
|
|
3830
|
+
cancel: 'Cancelar'
|
|
3831
|
+
}
|
|
3832
|
+
};
|
|
3833
|
+
|
|
3834
|
+
instance.init({
|
|
3835
|
+
fallbackLng: 'en',
|
|
3836
|
+
lng: 'en',
|
|
3837
|
+
debug: true,
|
|
3838
|
+
resources: {
|
|
3839
|
+
en: en,
|
|
3840
|
+
es: es
|
|
3841
|
+
}
|
|
3842
|
+
});
|
|
3843
|
+
var index = {
|
|
3844
|
+
translator: _extends({}, instance, {
|
|
3845
|
+
t: (key, options) => {
|
|
3846
|
+
const {
|
|
3847
|
+
lng
|
|
3848
|
+
} = options;
|
|
3849
|
+
|
|
3850
|
+
switch (lng) {
|
|
3851
|
+
// these keys don't work with plurals, don't know why, so I added a workaround to convert them to the correct lng
|
|
3852
|
+
case 'en_US':
|
|
3853
|
+
case 'en-US':
|
|
3854
|
+
options.lng = 'en';
|
|
3855
|
+
break;
|
|
3856
|
+
|
|
3857
|
+
case 'es_ES':
|
|
3858
|
+
case 'es-ES':
|
|
3859
|
+
case 'es_MX':
|
|
3860
|
+
case 'es-MX':
|
|
3861
|
+
options.lng = 'es';
|
|
3862
|
+
break;
|
|
3863
|
+
}
|
|
3864
|
+
|
|
3865
|
+
return instance.t(key, _extends({
|
|
3866
|
+
lng
|
|
3867
|
+
}, options));
|
|
3868
|
+
}
|
|
3869
|
+
}),
|
|
3870
|
+
languageOptions: [{
|
|
3871
|
+
value: 'en_US',
|
|
3872
|
+
label: 'English (US)'
|
|
3873
|
+
}, {
|
|
3874
|
+
value: 'es_ES',
|
|
3875
|
+
label: 'Spanish'
|
|
3876
|
+
}]
|
|
3877
|
+
};
|
|
3878
|
+
|
|
3879
|
+
// Should be exactly the same as configure/defaults.js
|
|
3880
|
+
var defaults = {
|
|
3881
|
+
model: {
|
|
3882
|
+
allowTrailingZerosDefault: false,
|
|
3883
|
+
equationEditor: '8',
|
|
3884
|
+
ignoreOrderDefault: false,
|
|
3885
|
+
markup: '',
|
|
3886
|
+
playerSpellCheckEnabled: true,
|
|
3887
|
+
prompt: '',
|
|
3888
|
+
promptEnabled: true,
|
|
3889
|
+
rationale: '',
|
|
3890
|
+
rationaleEnabled: true,
|
|
3891
|
+
responses: {},
|
|
3892
|
+
spellCheckEnabled: true,
|
|
3893
|
+
teacherInstructions: '',
|
|
3894
|
+
teacherInstructionsEnabled: true,
|
|
3895
|
+
toolbarEditorPosition: 'bottom',
|
|
3896
|
+
validationDefault: 'literal',
|
|
3897
|
+
},
|
|
3898
|
+
configuration: {},
|
|
3899
|
+
};
|
|
3900
|
+
|
|
3901
|
+
var getNative = _getNative;
|
|
3902
|
+
|
|
3903
|
+
/* Built-in method references that are verified to be native. */
|
|
3904
|
+
var nativeCreate$4 = getNative(Object, 'create');
|
|
3905
|
+
|
|
3906
|
+
var _nativeCreate = nativeCreate$4;
|
|
3907
|
+
|
|
3908
|
+
var nativeCreate$3 = _nativeCreate;
|
|
3909
|
+
|
|
3910
|
+
/**
|
|
3911
|
+
* Removes all key-value entries from the hash.
|
|
3912
|
+
*
|
|
3913
|
+
* @private
|
|
3914
|
+
* @name clear
|
|
3915
|
+
* @memberOf Hash
|
|
3916
|
+
*/
|
|
3917
|
+
function hashClear$1() {
|
|
3918
|
+
this.__data__ = nativeCreate$3 ? nativeCreate$3(null) : {};
|
|
3919
|
+
this.size = 0;
|
|
3920
|
+
}
|
|
3921
|
+
|
|
3922
|
+
var _hashClear = hashClear$1;
|
|
3923
|
+
|
|
3924
|
+
/**
|
|
3925
|
+
* Removes `key` and its value from the hash.
|
|
3926
|
+
*
|
|
3927
|
+
* @private
|
|
3928
|
+
* @name delete
|
|
3929
|
+
* @memberOf Hash
|
|
3930
|
+
* @param {Object} hash The hash to modify.
|
|
3931
|
+
* @param {string} key The key of the value to remove.
|
|
3932
|
+
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|
3933
|
+
*/
|
|
3934
|
+
|
|
3935
|
+
function hashDelete$1(key) {
|
|
3936
|
+
var result = this.has(key) && delete this.__data__[key];
|
|
3937
|
+
this.size -= result ? 1 : 0;
|
|
3938
|
+
return result;
|
|
3939
|
+
}
|
|
3940
|
+
|
|
3941
|
+
var _hashDelete = hashDelete$1;
|
|
3942
|
+
|
|
3943
|
+
var nativeCreate$2 = _nativeCreate;
|
|
3944
|
+
|
|
3945
|
+
/** Used to stand-in for `undefined` hash values. */
|
|
3946
|
+
var HASH_UNDEFINED$1 = '__lodash_hash_undefined__';
|
|
3947
|
+
|
|
3948
|
+
/** Used for built-in method references. */
|
|
3949
|
+
var objectProto$1 = Object.prototype;
|
|
3950
|
+
|
|
3951
|
+
/** Used to check objects for own properties. */
|
|
3952
|
+
var hasOwnProperty$1 = objectProto$1.hasOwnProperty;
|
|
3953
|
+
|
|
3954
|
+
/**
|
|
3955
|
+
* Gets the hash value for `key`.
|
|
3956
|
+
*
|
|
3957
|
+
* @private
|
|
3958
|
+
* @name get
|
|
3959
|
+
* @memberOf Hash
|
|
3960
|
+
* @param {string} key The key of the value to get.
|
|
3961
|
+
* @returns {*} Returns the entry value.
|
|
3962
|
+
*/
|
|
3963
|
+
function hashGet$1(key) {
|
|
3964
|
+
var data = this.__data__;
|
|
3965
|
+
if (nativeCreate$2) {
|
|
3966
|
+
var result = data[key];
|
|
3967
|
+
return result === HASH_UNDEFINED$1 ? undefined : result;
|
|
3968
|
+
}
|
|
3969
|
+
return hasOwnProperty$1.call(data, key) ? data[key] : undefined;
|
|
3970
|
+
}
|
|
3971
|
+
|
|
3972
|
+
var _hashGet = hashGet$1;
|
|
3973
|
+
|
|
3974
|
+
var nativeCreate$1 = _nativeCreate;
|
|
3975
|
+
|
|
3976
|
+
/** Used for built-in method references. */
|
|
3977
|
+
var objectProto = Object.prototype;
|
|
3978
|
+
|
|
3979
|
+
/** Used to check objects for own properties. */
|
|
3980
|
+
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
3981
|
+
|
|
3982
|
+
/**
|
|
3983
|
+
* Checks if a hash value for `key` exists.
|
|
3984
|
+
*
|
|
3985
|
+
* @private
|
|
3986
|
+
* @name has
|
|
3987
|
+
* @memberOf Hash
|
|
3988
|
+
* @param {string} key The key of the entry to check.
|
|
3989
|
+
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|
3990
|
+
*/
|
|
3991
|
+
function hashHas$1(key) {
|
|
3992
|
+
var data = this.__data__;
|
|
3993
|
+
return nativeCreate$1 ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
|
|
3994
|
+
}
|
|
3995
|
+
|
|
3996
|
+
var _hashHas = hashHas$1;
|
|
3997
|
+
|
|
3998
|
+
var nativeCreate = _nativeCreate;
|
|
3999
|
+
|
|
4000
|
+
/** Used to stand-in for `undefined` hash values. */
|
|
4001
|
+
var HASH_UNDEFINED = '__lodash_hash_undefined__';
|
|
4002
|
+
|
|
4003
|
+
/**
|
|
4004
|
+
* Sets the hash `key` to `value`.
|
|
4005
|
+
*
|
|
4006
|
+
* @private
|
|
4007
|
+
* @name set
|
|
4008
|
+
* @memberOf Hash
|
|
4009
|
+
* @param {string} key The key of the value to set.
|
|
4010
|
+
* @param {*} value The value to set.
|
|
4011
|
+
* @returns {Object} Returns the hash instance.
|
|
4012
|
+
*/
|
|
4013
|
+
function hashSet$1(key, value) {
|
|
4014
|
+
var data = this.__data__;
|
|
4015
|
+
this.size += this.has(key) ? 0 : 1;
|
|
4016
|
+
data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
|
|
4017
|
+
return this;
|
|
4018
|
+
}
|
|
4019
|
+
|
|
4020
|
+
var _hashSet = hashSet$1;
|
|
4021
|
+
|
|
4022
|
+
var hashClear = _hashClear,
|
|
4023
|
+
hashDelete = _hashDelete,
|
|
4024
|
+
hashGet = _hashGet,
|
|
4025
|
+
hashHas = _hashHas,
|
|
4026
|
+
hashSet = _hashSet;
|
|
4027
|
+
|
|
4028
|
+
/**
|
|
4029
|
+
* Creates a hash object.
|
|
4030
|
+
*
|
|
4031
|
+
* @private
|
|
4032
|
+
* @constructor
|
|
4033
|
+
* @param {Array} [entries] The key-value pairs to cache.
|
|
4034
|
+
*/
|
|
4035
|
+
function Hash$1(entries) {
|
|
4036
|
+
var index = -1,
|
|
4037
|
+
length = entries == null ? 0 : entries.length;
|
|
4038
|
+
|
|
4039
|
+
this.clear();
|
|
4040
|
+
while (++index < length) {
|
|
4041
|
+
var entry = entries[index];
|
|
4042
|
+
this.set(entry[0], entry[1]);
|
|
4043
|
+
}
|
|
4044
|
+
}
|
|
4045
|
+
|
|
4046
|
+
// Add methods to `Hash`.
|
|
4047
|
+
Hash$1.prototype.clear = hashClear;
|
|
4048
|
+
Hash$1.prototype['delete'] = hashDelete;
|
|
4049
|
+
Hash$1.prototype.get = hashGet;
|
|
4050
|
+
Hash$1.prototype.has = hashHas;
|
|
4051
|
+
Hash$1.prototype.set = hashSet;
|
|
4052
|
+
|
|
4053
|
+
var _Hash = Hash$1;
|
|
4054
|
+
|
|
4055
|
+
/**
|
|
4056
|
+
* Removes all key-value entries from the list cache.
|
|
4057
|
+
*
|
|
4058
|
+
* @private
|
|
4059
|
+
* @name clear
|
|
4060
|
+
* @memberOf ListCache
|
|
4061
|
+
*/
|
|
4062
|
+
|
|
4063
|
+
function listCacheClear$1() {
|
|
4064
|
+
this.__data__ = [];
|
|
4065
|
+
this.size = 0;
|
|
4066
|
+
}
|
|
4067
|
+
|
|
4068
|
+
var _listCacheClear = listCacheClear$1;
|
|
4069
|
+
|
|
4070
|
+
/**
|
|
4071
|
+
* Performs a
|
|
4072
|
+
* [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
|
4073
|
+
* comparison between two values to determine if they are equivalent.
|
|
4074
|
+
*
|
|
4075
|
+
* @static
|
|
4076
|
+
* @memberOf _
|
|
4077
|
+
* @since 4.0.0
|
|
4078
|
+
* @category Lang
|
|
4079
|
+
* @param {*} value The value to compare.
|
|
4080
|
+
* @param {*} other The other value to compare.
|
|
4081
|
+
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
|
4082
|
+
* @example
|
|
4083
|
+
*
|
|
4084
|
+
* var object = { 'a': 1 };
|
|
4085
|
+
* var other = { 'a': 1 };
|
|
4086
|
+
*
|
|
4087
|
+
* _.eq(object, object);
|
|
4088
|
+
* // => true
|
|
4089
|
+
*
|
|
4090
|
+
* _.eq(object, other);
|
|
4091
|
+
* // => false
|
|
4092
|
+
*
|
|
4093
|
+
* _.eq('a', 'a');
|
|
4094
|
+
* // => true
|
|
4095
|
+
*
|
|
4096
|
+
* _.eq('a', Object('a'));
|
|
4097
|
+
* // => false
|
|
4098
|
+
*
|
|
4099
|
+
* _.eq(NaN, NaN);
|
|
4100
|
+
* // => true
|
|
4101
|
+
*/
|
|
4102
|
+
|
|
4103
|
+
function eq$1(value, other) {
|
|
4104
|
+
return value === other || (value !== value && other !== other);
|
|
4105
|
+
}
|
|
4106
|
+
|
|
4107
|
+
var eq_1 = eq$1;
|
|
4108
|
+
|
|
4109
|
+
var eq = eq_1;
|
|
4110
|
+
|
|
4111
|
+
/**
|
|
4112
|
+
* Gets the index at which the `key` is found in `array` of key-value pairs.
|
|
4113
|
+
*
|
|
4114
|
+
* @private
|
|
4115
|
+
* @param {Array} array The array to inspect.
|
|
4116
|
+
* @param {*} key The key to search for.
|
|
4117
|
+
* @returns {number} Returns the index of the matched value, else `-1`.
|
|
4118
|
+
*/
|
|
4119
|
+
function assocIndexOf$4(array, key) {
|
|
4120
|
+
var length = array.length;
|
|
4121
|
+
while (length--) {
|
|
4122
|
+
if (eq(array[length][0], key)) {
|
|
4123
|
+
return length;
|
|
4124
|
+
}
|
|
4125
|
+
}
|
|
4126
|
+
return -1;
|
|
4127
|
+
}
|
|
4128
|
+
|
|
4129
|
+
var _assocIndexOf = assocIndexOf$4;
|
|
4130
|
+
|
|
4131
|
+
var assocIndexOf$3 = _assocIndexOf;
|
|
4132
|
+
|
|
4133
|
+
/** Used for built-in method references. */
|
|
4134
|
+
var arrayProto = Array.prototype;
|
|
4135
|
+
|
|
4136
|
+
/** Built-in value references. */
|
|
4137
|
+
var splice = arrayProto.splice;
|
|
4138
|
+
|
|
4139
|
+
/**
|
|
4140
|
+
* Removes `key` and its value from the list cache.
|
|
4141
|
+
*
|
|
4142
|
+
* @private
|
|
4143
|
+
* @name delete
|
|
4144
|
+
* @memberOf ListCache
|
|
4145
|
+
* @param {string} key The key of the value to remove.
|
|
4146
|
+
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|
4147
|
+
*/
|
|
4148
|
+
function listCacheDelete$1(key) {
|
|
4149
|
+
var data = this.__data__,
|
|
4150
|
+
index = assocIndexOf$3(data, key);
|
|
4151
|
+
|
|
4152
|
+
if (index < 0) {
|
|
4153
|
+
return false;
|
|
4154
|
+
}
|
|
4155
|
+
var lastIndex = data.length - 1;
|
|
4156
|
+
if (index == lastIndex) {
|
|
4157
|
+
data.pop();
|
|
4158
|
+
} else {
|
|
4159
|
+
splice.call(data, index, 1);
|
|
4160
|
+
}
|
|
4161
|
+
--this.size;
|
|
4162
|
+
return true;
|
|
4163
|
+
}
|
|
4164
|
+
|
|
4165
|
+
var _listCacheDelete = listCacheDelete$1;
|
|
4166
|
+
|
|
4167
|
+
var assocIndexOf$2 = _assocIndexOf;
|
|
4168
|
+
|
|
4169
|
+
/**
|
|
4170
|
+
* Gets the list cache value for `key`.
|
|
4171
|
+
*
|
|
4172
|
+
* @private
|
|
4173
|
+
* @name get
|
|
4174
|
+
* @memberOf ListCache
|
|
4175
|
+
* @param {string} key The key of the value to get.
|
|
4176
|
+
* @returns {*} Returns the entry value.
|
|
4177
|
+
*/
|
|
4178
|
+
function listCacheGet$1(key) {
|
|
4179
|
+
var data = this.__data__,
|
|
4180
|
+
index = assocIndexOf$2(data, key);
|
|
4181
|
+
|
|
4182
|
+
return index < 0 ? undefined : data[index][1];
|
|
4183
|
+
}
|
|
4184
|
+
|
|
4185
|
+
var _listCacheGet = listCacheGet$1;
|
|
4186
|
+
|
|
4187
|
+
var assocIndexOf$1 = _assocIndexOf;
|
|
4188
|
+
|
|
4189
|
+
/**
|
|
4190
|
+
* Checks if a list cache value for `key` exists.
|
|
4191
|
+
*
|
|
4192
|
+
* @private
|
|
4193
|
+
* @name has
|
|
4194
|
+
* @memberOf ListCache
|
|
4195
|
+
* @param {string} key The key of the entry to check.
|
|
4196
|
+
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|
4197
|
+
*/
|
|
4198
|
+
function listCacheHas$1(key) {
|
|
4199
|
+
return assocIndexOf$1(this.__data__, key) > -1;
|
|
4200
|
+
}
|
|
4201
|
+
|
|
4202
|
+
var _listCacheHas = listCacheHas$1;
|
|
4203
|
+
|
|
4204
|
+
var assocIndexOf = _assocIndexOf;
|
|
4205
|
+
|
|
4206
|
+
/**
|
|
4207
|
+
* Sets the list cache `key` to `value`.
|
|
4208
|
+
*
|
|
4209
|
+
* @private
|
|
4210
|
+
* @name set
|
|
4211
|
+
* @memberOf ListCache
|
|
4212
|
+
* @param {string} key The key of the value to set.
|
|
4213
|
+
* @param {*} value The value to set.
|
|
4214
|
+
* @returns {Object} Returns the list cache instance.
|
|
4215
|
+
*/
|
|
4216
|
+
function listCacheSet$1(key, value) {
|
|
4217
|
+
var data = this.__data__,
|
|
4218
|
+
index = assocIndexOf(data, key);
|
|
4219
|
+
|
|
4220
|
+
if (index < 0) {
|
|
4221
|
+
++this.size;
|
|
4222
|
+
data.push([key, value]);
|
|
4223
|
+
} else {
|
|
4224
|
+
data[index][1] = value;
|
|
4225
|
+
}
|
|
4226
|
+
return this;
|
|
4227
|
+
}
|
|
4228
|
+
|
|
4229
|
+
var _listCacheSet = listCacheSet$1;
|
|
4230
|
+
|
|
4231
|
+
var listCacheClear = _listCacheClear,
|
|
4232
|
+
listCacheDelete = _listCacheDelete,
|
|
4233
|
+
listCacheGet = _listCacheGet,
|
|
4234
|
+
listCacheHas = _listCacheHas,
|
|
4235
|
+
listCacheSet = _listCacheSet;
|
|
4236
|
+
|
|
4237
|
+
/**
|
|
4238
|
+
* Creates an list cache object.
|
|
4239
|
+
*
|
|
4240
|
+
* @private
|
|
4241
|
+
* @constructor
|
|
4242
|
+
* @param {Array} [entries] The key-value pairs to cache.
|
|
4243
|
+
*/
|
|
4244
|
+
function ListCache$1(entries) {
|
|
4245
|
+
var index = -1,
|
|
4246
|
+
length = entries == null ? 0 : entries.length;
|
|
4247
|
+
|
|
4248
|
+
this.clear();
|
|
4249
|
+
while (++index < length) {
|
|
4250
|
+
var entry = entries[index];
|
|
4251
|
+
this.set(entry[0], entry[1]);
|
|
4252
|
+
}
|
|
4253
|
+
}
|
|
4254
|
+
|
|
4255
|
+
// Add methods to `ListCache`.
|
|
4256
|
+
ListCache$1.prototype.clear = listCacheClear;
|
|
4257
|
+
ListCache$1.prototype['delete'] = listCacheDelete;
|
|
4258
|
+
ListCache$1.prototype.get = listCacheGet;
|
|
4259
|
+
ListCache$1.prototype.has = listCacheHas;
|
|
4260
|
+
ListCache$1.prototype.set = listCacheSet;
|
|
4261
|
+
|
|
4262
|
+
var _ListCache = ListCache$1;
|
|
4263
|
+
|
|
4264
|
+
var Hash = _Hash,
|
|
4265
|
+
ListCache = _ListCache,
|
|
4266
|
+
Map = _Map;
|
|
4267
|
+
|
|
4268
|
+
/**
|
|
4269
|
+
* Removes all key-value entries from the map.
|
|
4270
|
+
*
|
|
4271
|
+
* @private
|
|
4272
|
+
* @name clear
|
|
4273
|
+
* @memberOf MapCache
|
|
4274
|
+
*/
|
|
4275
|
+
function mapCacheClear$1() {
|
|
4276
|
+
this.size = 0;
|
|
4277
|
+
this.__data__ = {
|
|
4278
|
+
'hash': new Hash,
|
|
4279
|
+
'map': new (Map || ListCache),
|
|
4280
|
+
'string': new Hash
|
|
4281
|
+
};
|
|
4282
|
+
}
|
|
4283
|
+
|
|
4284
|
+
var _mapCacheClear = mapCacheClear$1;
|
|
4285
|
+
|
|
4286
|
+
/**
|
|
4287
|
+
* Checks if `value` is suitable for use as unique object key.
|
|
4288
|
+
*
|
|
4289
|
+
* @private
|
|
4290
|
+
* @param {*} value The value to check.
|
|
4291
|
+
* @returns {boolean} Returns `true` if `value` is suitable, else `false`.
|
|
4292
|
+
*/
|
|
4293
|
+
|
|
4294
|
+
function isKeyable$1(value) {
|
|
4295
|
+
var type = typeof value;
|
|
4296
|
+
return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
|
|
4297
|
+
? (value !== '__proto__')
|
|
4298
|
+
: (value === null);
|
|
4299
|
+
}
|
|
4300
|
+
|
|
4301
|
+
var _isKeyable = isKeyable$1;
|
|
4302
|
+
|
|
4303
|
+
var isKeyable = _isKeyable;
|
|
4304
|
+
|
|
4305
|
+
/**
|
|
4306
|
+
* Gets the data for `map`.
|
|
4307
|
+
*
|
|
4308
|
+
* @private
|
|
4309
|
+
* @param {Object} map The map to query.
|
|
4310
|
+
* @param {string} key The reference key.
|
|
4311
|
+
* @returns {*} Returns the map data.
|
|
4312
|
+
*/
|
|
4313
|
+
function getMapData$4(map, key) {
|
|
4314
|
+
var data = map.__data__;
|
|
4315
|
+
return isKeyable(key)
|
|
4316
|
+
? data[typeof key == 'string' ? 'string' : 'hash']
|
|
4317
|
+
: data.map;
|
|
4318
|
+
}
|
|
4319
|
+
|
|
4320
|
+
var _getMapData = getMapData$4;
|
|
4321
|
+
|
|
4322
|
+
var getMapData$3 = _getMapData;
|
|
4323
|
+
|
|
4324
|
+
/**
|
|
4325
|
+
* Removes `key` and its value from the map.
|
|
4326
|
+
*
|
|
4327
|
+
* @private
|
|
4328
|
+
* @name delete
|
|
4329
|
+
* @memberOf MapCache
|
|
4330
|
+
* @param {string} key The key of the value to remove.
|
|
4331
|
+
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|
4332
|
+
*/
|
|
4333
|
+
function mapCacheDelete$1(key) {
|
|
4334
|
+
var result = getMapData$3(this, key)['delete'](key);
|
|
4335
|
+
this.size -= result ? 1 : 0;
|
|
4336
|
+
return result;
|
|
4337
|
+
}
|
|
4338
|
+
|
|
4339
|
+
var _mapCacheDelete = mapCacheDelete$1;
|
|
4340
|
+
|
|
4341
|
+
var getMapData$2 = _getMapData;
|
|
4342
|
+
|
|
4343
|
+
/**
|
|
4344
|
+
* Gets the map value for `key`.
|
|
4345
|
+
*
|
|
4346
|
+
* @private
|
|
4347
|
+
* @name get
|
|
4348
|
+
* @memberOf MapCache
|
|
4349
|
+
* @param {string} key The key of the value to get.
|
|
4350
|
+
* @returns {*} Returns the entry value.
|
|
4351
|
+
*/
|
|
4352
|
+
function mapCacheGet$1(key) {
|
|
4353
|
+
return getMapData$2(this, key).get(key);
|
|
4354
|
+
}
|
|
4355
|
+
|
|
4356
|
+
var _mapCacheGet = mapCacheGet$1;
|
|
4357
|
+
|
|
4358
|
+
var getMapData$1 = _getMapData;
|
|
4359
|
+
|
|
4360
|
+
/**
|
|
4361
|
+
* Checks if a map value for `key` exists.
|
|
4362
|
+
*
|
|
4363
|
+
* @private
|
|
4364
|
+
* @name has
|
|
4365
|
+
* @memberOf MapCache
|
|
4366
|
+
* @param {string} key The key of the entry to check.
|
|
4367
|
+
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|
4368
|
+
*/
|
|
4369
|
+
function mapCacheHas$1(key) {
|
|
4370
|
+
return getMapData$1(this, key).has(key);
|
|
4371
|
+
}
|
|
4372
|
+
|
|
4373
|
+
var _mapCacheHas = mapCacheHas$1;
|
|
4374
|
+
|
|
4375
|
+
var getMapData = _getMapData;
|
|
4376
|
+
|
|
4377
|
+
/**
|
|
4378
|
+
* Sets the map `key` to `value`.
|
|
4379
|
+
*
|
|
4380
|
+
* @private
|
|
4381
|
+
* @name set
|
|
4382
|
+
* @memberOf MapCache
|
|
4383
|
+
* @param {string} key The key of the value to set.
|
|
4384
|
+
* @param {*} value The value to set.
|
|
4385
|
+
* @returns {Object} Returns the map cache instance.
|
|
4386
|
+
*/
|
|
4387
|
+
function mapCacheSet$1(key, value) {
|
|
4388
|
+
var data = getMapData(this, key),
|
|
4389
|
+
size = data.size;
|
|
4390
|
+
|
|
4391
|
+
data.set(key, value);
|
|
4392
|
+
this.size += data.size == size ? 0 : 1;
|
|
4393
|
+
return this;
|
|
4394
|
+
}
|
|
4395
|
+
|
|
4396
|
+
var _mapCacheSet = mapCacheSet$1;
|
|
4397
|
+
|
|
4398
|
+
var mapCacheClear = _mapCacheClear,
|
|
4399
|
+
mapCacheDelete = _mapCacheDelete,
|
|
4400
|
+
mapCacheGet = _mapCacheGet,
|
|
4401
|
+
mapCacheHas = _mapCacheHas,
|
|
4402
|
+
mapCacheSet = _mapCacheSet;
|
|
4403
|
+
|
|
4404
|
+
/**
|
|
4405
|
+
* Creates a map cache object to store key-value pairs.
|
|
4406
|
+
*
|
|
4407
|
+
* @private
|
|
4408
|
+
* @constructor
|
|
4409
|
+
* @param {Array} [entries] The key-value pairs to cache.
|
|
4410
|
+
*/
|
|
4411
|
+
function MapCache$1(entries) {
|
|
4412
|
+
var index = -1,
|
|
4413
|
+
length = entries == null ? 0 : entries.length;
|
|
4414
|
+
|
|
4415
|
+
this.clear();
|
|
4416
|
+
while (++index < length) {
|
|
4417
|
+
var entry = entries[index];
|
|
4418
|
+
this.set(entry[0], entry[1]);
|
|
4419
|
+
}
|
|
4420
|
+
}
|
|
4421
|
+
|
|
4422
|
+
// Add methods to `MapCache`.
|
|
4423
|
+
MapCache$1.prototype.clear = mapCacheClear;
|
|
4424
|
+
MapCache$1.prototype['delete'] = mapCacheDelete;
|
|
4425
|
+
MapCache$1.prototype.get = mapCacheGet;
|
|
4426
|
+
MapCache$1.prototype.has = mapCacheHas;
|
|
4427
|
+
MapCache$1.prototype.set = mapCacheSet;
|
|
4428
|
+
|
|
4429
|
+
var _MapCache = MapCache$1;
|
|
4430
|
+
|
|
4431
|
+
var MapCache = _MapCache;
|
|
4432
|
+
|
|
4433
|
+
/** Error message constants. */
|
|
4434
|
+
var FUNC_ERROR_TEXT = 'Expected a function';
|
|
4435
|
+
|
|
4436
|
+
/**
|
|
4437
|
+
* Creates a function that memoizes the result of `func`. If `resolver` is
|
|
4438
|
+
* provided, it determines the cache key for storing the result based on the
|
|
4439
|
+
* arguments provided to the memoized function. By default, the first argument
|
|
4440
|
+
* provided to the memoized function is used as the map cache key. The `func`
|
|
4441
|
+
* is invoked with the `this` binding of the memoized function.
|
|
4442
|
+
*
|
|
4443
|
+
* **Note:** The cache is exposed as the `cache` property on the memoized
|
|
4444
|
+
* function. Its creation may be customized by replacing the `_.memoize.Cache`
|
|
4445
|
+
* constructor with one whose instances implement the
|
|
4446
|
+
* [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
|
|
4447
|
+
* method interface of `clear`, `delete`, `get`, `has`, and `set`.
|
|
4448
|
+
*
|
|
4449
|
+
* @static
|
|
4450
|
+
* @memberOf _
|
|
4451
|
+
* @since 0.1.0
|
|
4452
|
+
* @category Function
|
|
4453
|
+
* @param {Function} func The function to have its output memoized.
|
|
4454
|
+
* @param {Function} [resolver] The function to resolve the cache key.
|
|
4455
|
+
* @returns {Function} Returns the new memoized function.
|
|
4456
|
+
* @example
|
|
4457
|
+
*
|
|
4458
|
+
* var object = { 'a': 1, 'b': 2 };
|
|
4459
|
+
* var other = { 'c': 3, 'd': 4 };
|
|
4460
|
+
*
|
|
4461
|
+
* var values = _.memoize(_.values);
|
|
4462
|
+
* values(object);
|
|
4463
|
+
* // => [1, 2]
|
|
4464
|
+
*
|
|
4465
|
+
* values(other);
|
|
4466
|
+
* // => [3, 4]
|
|
4467
|
+
*
|
|
4468
|
+
* object.a = 2;
|
|
4469
|
+
* values(object);
|
|
4470
|
+
* // => [1, 2]
|
|
4471
|
+
*
|
|
4472
|
+
* // Modify the result cache.
|
|
4473
|
+
* values.cache.set(object, ['a', 'b']);
|
|
4474
|
+
* values(object);
|
|
4475
|
+
* // => ['a', 'b']
|
|
4476
|
+
*
|
|
4477
|
+
* // Replace `_.memoize.Cache`.
|
|
4478
|
+
* _.memoize.Cache = WeakMap;
|
|
4479
|
+
*/
|
|
4480
|
+
function memoize$1(func, resolver) {
|
|
4481
|
+
if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
|
|
4482
|
+
throw new TypeError(FUNC_ERROR_TEXT);
|
|
4483
|
+
}
|
|
4484
|
+
var memoized = function() {
|
|
4485
|
+
var args = arguments,
|
|
4486
|
+
key = resolver ? resolver.apply(this, args) : args[0],
|
|
4487
|
+
cache = memoized.cache;
|
|
4488
|
+
|
|
4489
|
+
if (cache.has(key)) {
|
|
4490
|
+
return cache.get(key);
|
|
4491
|
+
}
|
|
4492
|
+
var result = func.apply(this, args);
|
|
4493
|
+
memoized.cache = cache.set(key, result) || cache;
|
|
4494
|
+
return result;
|
|
4495
|
+
};
|
|
4496
|
+
memoized.cache = new (memoize$1.Cache || MapCache);
|
|
4497
|
+
return memoized;
|
|
4498
|
+
}
|
|
4499
|
+
|
|
4500
|
+
// Expose `MapCache`.
|
|
4501
|
+
memoize$1.Cache = MapCache;
|
|
4502
|
+
|
|
4503
|
+
var memoize_1 = memoize$1;
|
|
4504
|
+
|
|
4505
|
+
var memoize = memoize_1;
|
|
4506
|
+
|
|
4507
|
+
/** Used as the maximum memoize cache size. */
|
|
4508
|
+
var MAX_MEMOIZE_SIZE = 500;
|
|
4509
|
+
|
|
4510
|
+
/**
|
|
4511
|
+
* A specialized version of `_.memoize` which clears the memoized function's
|
|
4512
|
+
* cache when it exceeds `MAX_MEMOIZE_SIZE`.
|
|
4513
|
+
*
|
|
4514
|
+
* @private
|
|
4515
|
+
* @param {Function} func The function to have its output memoized.
|
|
4516
|
+
* @returns {Function} Returns the new memoized function.
|
|
4517
|
+
*/
|
|
4518
|
+
function memoizeCapped$1(func) {
|
|
4519
|
+
var result = memoize(func, function(key) {
|
|
4520
|
+
if (cache.size === MAX_MEMOIZE_SIZE) {
|
|
4521
|
+
cache.clear();
|
|
4522
|
+
}
|
|
4523
|
+
return key;
|
|
4524
|
+
});
|
|
4525
|
+
|
|
4526
|
+
var cache = result.cache;
|
|
4527
|
+
return result;
|
|
4528
|
+
}
|
|
4529
|
+
|
|
4530
|
+
var _memoizeCapped = memoizeCapped$1;
|
|
4531
|
+
|
|
4532
|
+
var memoizeCapped = _memoizeCapped;
|
|
4533
|
+
|
|
4534
|
+
/** Used to match property names within property paths. */
|
|
4535
|
+
var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
|
|
4536
|
+
|
|
4537
|
+
/** Used to match backslashes in property paths. */
|
|
4538
|
+
var reEscapeChar = /\\(\\)?/g;
|
|
4539
|
+
|
|
4540
|
+
/**
|
|
4541
|
+
* Converts `string` to a property path array.
|
|
4542
|
+
*
|
|
4543
|
+
* @private
|
|
4544
|
+
* @param {string} string The string to convert.
|
|
4545
|
+
* @returns {Array} Returns the property path array.
|
|
4546
|
+
*/
|
|
4547
|
+
memoizeCapped(function(string) {
|
|
4548
|
+
var result = [];
|
|
4549
|
+
if (string.charCodeAt(0) === 46 /* . */) {
|
|
4550
|
+
result.push('');
|
|
4551
|
+
}
|
|
4552
|
+
string.replace(rePropName, function(match, number, quote, subString) {
|
|
4553
|
+
result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
|
|
4554
|
+
});
|
|
4555
|
+
return result;
|
|
4556
|
+
});
|
|
4557
|
+
|
|
4558
|
+
var Symbol$1 = _Symbol;
|
|
4559
|
+
|
|
4560
|
+
/** Used to convert symbols to primitives and strings. */
|
|
4561
|
+
var symbolProto = Symbol$1 ? Symbol$1.prototype : undefined;
|
|
4562
|
+
symbolProto ? symbolProto.toString : undefined;
|
|
4563
|
+
|
|
4564
|
+
const enabled = (config, env, defaultValue) => {
|
|
4565
|
+
// if model.partialScoring = false
|
|
4566
|
+
// - if env.partialScoring = false || env.partialScoring = true => use dichotomous scoring
|
|
4567
|
+
// else if model.partialScoring = true || undefined
|
|
4568
|
+
// - if env.partialScoring = false, use dichotomous scoring
|
|
4569
|
+
// - else if env.partialScoring = true, use partial scoring
|
|
4570
|
+
config = config || {};
|
|
4571
|
+
env = env || {};
|
|
4572
|
+
|
|
4573
|
+
if (config.partialScoring === false) {
|
|
4574
|
+
return false;
|
|
4575
|
+
}
|
|
4576
|
+
|
|
4577
|
+
if (env.partialScoring === false) {
|
|
4578
|
+
return false;
|
|
4579
|
+
}
|
|
4580
|
+
|
|
4581
|
+
return typeof defaultValue === 'boolean' ? defaultValue : true;
|
|
4582
|
+
};
|
|
4583
|
+
|
|
4584
|
+
var partialScoring = /*#__PURE__*/Object.freeze({
|
|
4585
|
+
__proto__: null,
|
|
4586
|
+
enabled: enabled
|
|
4587
|
+
});
|
|
4588
|
+
|
|
4589
|
+
const lg = n => console[n].bind(console, 'controller-utils:');
|
|
4590
|
+
|
|
4591
|
+
lg('debug');
|
|
4592
|
+
lg('log');
|
|
4593
|
+
lg('warn');
|
|
4594
|
+
lg('error');
|
|
4595
|
+
|
|
4596
|
+
const { translator } = index;
|
|
4597
|
+
|
|
4598
|
+
const getFeedback = (value) => (value ? 'correct' : 'incorrect');
|
|
4599
|
+
const getContent = (html) => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
|
|
4600
|
+
|
|
4601
|
+
const getIsAnswerCorrect = (correctResponse, answerItem) => {
|
|
4602
|
+
let answerCorrect = false;
|
|
4603
|
+
|
|
4604
|
+
const opts = {
|
|
4605
|
+
mode: correctResponse.validation || defaults.validationDefault,
|
|
4606
|
+
...(correctResponse.validation === 'literal' && {
|
|
4607
|
+
literal: {
|
|
4608
|
+
allowTrailingZeros: correctResponse.allowTrailingZeros || false,
|
|
4609
|
+
ignoreOrder: correctResponse.ignoreOrder || false,
|
|
4610
|
+
},
|
|
4611
|
+
}),
|
|
4612
|
+
};
|
|
4613
|
+
|
|
4614
|
+
if (!answerCorrect) {
|
|
4615
|
+
const acceptedValues = [correctResponse.answer, ...Object.values(correctResponse.alternates || {})];
|
|
4616
|
+
|
|
4617
|
+
try {
|
|
4618
|
+
for (const value of acceptedValues) {
|
|
4619
|
+
answerCorrect = mv.latexEqual(answerItem.value, value, opts);
|
|
4620
|
+
if (answerCorrect) break;
|
|
4621
|
+
}
|
|
4622
|
+
} catch (e) {
|
|
4623
|
+
answerCorrect = false;
|
|
4624
|
+
}
|
|
4625
|
+
}
|
|
4626
|
+
|
|
4627
|
+
return answerCorrect;
|
|
4628
|
+
};
|
|
4629
|
+
|
|
4630
|
+
const getResponseCorrectness = (question, sessionResponse) => {
|
|
4631
|
+
const correctResponses = question.responses;
|
|
4632
|
+
|
|
4633
|
+
if (!sessionResponse) {
|
|
4634
|
+
return {
|
|
4635
|
+
correctness: 'unanswered',
|
|
4636
|
+
score: 0,
|
|
4637
|
+
correct: false,
|
|
4638
|
+
};
|
|
4639
|
+
} else {
|
|
4640
|
+
let correctAnswers = 0;
|
|
4641
|
+
let score = 0;
|
|
4642
|
+
const correctResponsesCount = Object.keys(correctResponses || {}).length;
|
|
4643
|
+
|
|
4644
|
+
Object.keys(correctResponses).forEach((responseId) => {
|
|
4645
|
+
const answerItem = sessionResponse['r' + responseId];
|
|
4646
|
+
const correctResponse = correctResponses[responseId] || {};
|
|
4647
|
+
|
|
4648
|
+
const answerCorrect = getIsAnswerCorrect(correctResponse, answerItem);
|
|
4649
|
+
if (answerCorrect) {
|
|
4650
|
+
correctAnswers++;
|
|
4651
|
+
}
|
|
4652
|
+
});
|
|
4653
|
+
|
|
4654
|
+
const fullyCorrect = correctAnswers === correctResponsesCount;
|
|
4655
|
+
|
|
4656
|
+
// partial credit scoring: each correct answer is worth 1 / total answers point
|
|
4657
|
+
// dichotomous scoring: for credit to be awarded, a correct answer must be entered for every response area
|
|
4658
|
+
score = Number((correctAnswers / Object.keys(correctResponses).length).toFixed(2));
|
|
4659
|
+
|
|
4660
|
+
return {
|
|
4661
|
+
correctness: getFeedback(fullyCorrect),
|
|
4662
|
+
score: correctAnswers > 0 ? score : 0,
|
|
4663
|
+
correct: fullyCorrect,
|
|
4664
|
+
};
|
|
4665
|
+
}
|
|
4666
|
+
};
|
|
4667
|
+
|
|
4668
|
+
const getCorrectness = (question, env, session) => {
|
|
4669
|
+
if (env.mode === 'evaluate') {
|
|
4670
|
+
return getResponseCorrectness(question, session && session.answers);
|
|
4671
|
+
}
|
|
4672
|
+
};
|
|
4673
|
+
|
|
4674
|
+
const getPartialScore = (question, session) => {
|
|
4675
|
+
if (!session || isEmpty_1(session)) {
|
|
4676
|
+
return 0;
|
|
4677
|
+
}
|
|
4678
|
+
|
|
4679
|
+
return 1;
|
|
4680
|
+
};
|
|
4681
|
+
|
|
4682
|
+
const outcome = (question, session, env) =>
|
|
4683
|
+
new Promise((resolve) => {
|
|
4684
|
+
if (!session || isEmpty_1(session)) {
|
|
4685
|
+
resolve({ score: 0, empty: true });
|
|
4686
|
+
}
|
|
4687
|
+
const partialScoringEnabled = partialScoring.enabled(question, env);
|
|
4688
|
+
session = normalizeSession(session);
|
|
4689
|
+
|
|
4690
|
+
if (env.mode !== 'evaluate') {
|
|
4691
|
+
resolve({ score: undefined, completed: undefined });
|
|
4692
|
+
} else {
|
|
4693
|
+
const correctness = getCorrectness(question, env, session);
|
|
4694
|
+
const score = correctness.score;
|
|
4695
|
+
|
|
4696
|
+
resolve({ score: partialScoringEnabled ? score : score === 1 ? 1 : 0 });
|
|
4697
|
+
}
|
|
4698
|
+
});
|
|
4699
|
+
|
|
4700
|
+
const createDefaultModel = (model = {}) => {
|
|
4701
|
+
const { validationDefault, allowTrailingZerosDefault, ignoreOrderDefault, responses = {} } = model;
|
|
4702
|
+
|
|
4703
|
+
const updatedResponses = Object.keys(responses).reduce((acc, responseId) => {
|
|
4704
|
+
const correctResponse = responses[responseId];
|
|
4705
|
+
|
|
4706
|
+
acc[responseId] = {
|
|
4707
|
+
...correctResponse,
|
|
4708
|
+
validation: correctResponse.validation || validationDefault,
|
|
4709
|
+
allowTrailingZeros: correctResponse.allowTrailingZeros || allowTrailingZerosDefault,
|
|
4710
|
+
ignoreOrder: correctResponse.ignoreOrder || ignoreOrderDefault,
|
|
4711
|
+
};
|
|
4712
|
+
|
|
4713
|
+
return acc;
|
|
4714
|
+
}, {});
|
|
4715
|
+
|
|
4716
|
+
return {
|
|
4717
|
+
...defaults.model,
|
|
4718
|
+
...model,
|
|
4719
|
+
responses: updatedResponses,
|
|
4720
|
+
};
|
|
4721
|
+
};
|
|
4722
|
+
|
|
4723
|
+
const normalizeSession = (s) => ({ ...s });
|
|
4724
|
+
|
|
4725
|
+
const getTextFromHTML = (html) => (html || '').replace(/<\/?[^>]+(>|$)/g, '');
|
|
4726
|
+
|
|
4727
|
+
const prepareVal = (html) => getTextFromHTML(html).trim();
|
|
4728
|
+
|
|
4729
|
+
const model = (question, session, env) => {
|
|
4730
|
+
return new Promise((resolve) => {
|
|
4731
|
+
session = session || {};
|
|
4732
|
+
const normalizedQuestion = createDefaultModel(question);
|
|
4733
|
+
const correctness = getCorrectness(normalizedQuestion, env, session);
|
|
4734
|
+
const { responses, language } = normalizedQuestion;
|
|
4735
|
+
let { note } = normalizedQuestion;
|
|
4736
|
+
let showNote = false;
|
|
4737
|
+
|
|
4738
|
+
// check if there is at least one alternate response or if the validation for at least one response is not literal
|
|
4739
|
+
Object.keys(responses).forEach((responseId) => {
|
|
4740
|
+
const correctResponse = responses[responseId] || {};
|
|
4741
|
+
if (correctResponse.alternates && Object.keys(correctResponse.alternates).length > 0) {
|
|
4742
|
+
showNote = true;
|
|
4743
|
+
} else if (correctResponse.validation !== 'literal') {
|
|
4744
|
+
showNote = true;
|
|
4745
|
+
}
|
|
4746
|
+
});
|
|
4747
|
+
|
|
4748
|
+
if (!note) {
|
|
4749
|
+
note = translator.t('mathInline.primaryCorrectWithAlternates', { lng: language });
|
|
4750
|
+
}
|
|
4751
|
+
|
|
4752
|
+
const out = {
|
|
4753
|
+
prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,
|
|
4754
|
+
markup: normalizedQuestion.markup,
|
|
4755
|
+
responses: env.mode === 'gather' ? null : normalizedQuestion.responses,
|
|
4756
|
+
language: normalizedQuestion.language,
|
|
4757
|
+
equationEditor: normalizedQuestion.equationEditor,
|
|
4758
|
+
customKeys: normalizedQuestion.customKeys,
|
|
4759
|
+
disabled: env.mode !== 'gather',
|
|
4760
|
+
view: env.mode === 'view',
|
|
4761
|
+
correctness,
|
|
4762
|
+
env,
|
|
4763
|
+
extraCSSRules: normalizedQuestion.extraCSSRules,
|
|
4764
|
+
};
|
|
4765
|
+
|
|
4766
|
+
const { answers = {} } = session || {};
|
|
4767
|
+
let feedback = {};
|
|
4768
|
+
|
|
4769
|
+
if (env.mode === 'evaluate') {
|
|
4770
|
+
Object.keys(responses).forEach((responseId) => {
|
|
4771
|
+
const answerItem = answers['r' + responseId];
|
|
4772
|
+
const correctResponse = responses[responseId];
|
|
4773
|
+
feedback[responseId] = getIsAnswerCorrect(correctResponse, answerItem);
|
|
4774
|
+
});
|
|
4775
|
+
}
|
|
4776
|
+
|
|
4777
|
+
if (env.mode === 'evaluate') {
|
|
4778
|
+
out.correctResponse = {};
|
|
4779
|
+
out.showNote = showNote;
|
|
4780
|
+
out.note = note;
|
|
4781
|
+
out.feedback = feedback;
|
|
4782
|
+
} else {
|
|
4783
|
+
out.responses = {};
|
|
4784
|
+
out.showNote = false;
|
|
4785
|
+
}
|
|
4786
|
+
|
|
4787
|
+
if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
|
|
4788
|
+
out.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;
|
|
4789
|
+
out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled
|
|
4790
|
+
? normalizedQuestion.teacherInstructions
|
|
4791
|
+
: null;
|
|
4792
|
+
} else {
|
|
4793
|
+
out.rationale = null;
|
|
4794
|
+
out.teacherInstructions = null;
|
|
4795
|
+
}
|
|
4796
|
+
resolve(out);
|
|
4797
|
+
});
|
|
4798
|
+
};
|
|
4799
|
+
|
|
4800
|
+
const createCorrectResponseSession = (question, env) =>
|
|
4801
|
+
new Promise((resolve) => {
|
|
4802
|
+
if (env.mode !== 'evaluate' && env.role === 'instructor') {
|
|
4803
|
+
const correctResponse = Object.keys(question.responses).reduce((acc, responseId) => {
|
|
4804
|
+
acc['r' + responseId] = { value: question.responses[responseId].answer };
|
|
4805
|
+
return acc;
|
|
4806
|
+
}, {});
|
|
4807
|
+
|
|
4808
|
+
resolve({ id: '1', answers: correctResponse });
|
|
4809
|
+
} else {
|
|
4810
|
+
resolve(null);
|
|
4811
|
+
}
|
|
4812
|
+
});
|
|
4813
|
+
|
|
4814
|
+
const validate = (model = {}, config = {}) => {
|
|
4815
|
+
const { responses, markup } = model;
|
|
4816
|
+
const { maxResponseAreas } = config;
|
|
4817
|
+
const responsesErrors = {};
|
|
4818
|
+
const errors = {};
|
|
4819
|
+
|
|
4820
|
+
['teacherInstructions', 'prompt', 'rationale'].forEach((field) => {
|
|
4821
|
+
if (config[field]?.required && !getContent(model[field])) {
|
|
4822
|
+
errors[field] = 'This field is required.';
|
|
4823
|
+
}
|
|
4824
|
+
});
|
|
4825
|
+
|
|
4826
|
+
Object.entries(responses || {}).forEach(([key, response], index) => {
|
|
4827
|
+
const { answer } = response;
|
|
4828
|
+
const reversedAlternates = [...Object.entries(response.alternates || {})].reverse();
|
|
4829
|
+
const alternatesErrors = {};
|
|
4830
|
+
const responseError = {};
|
|
4831
|
+
|
|
4832
|
+
if (answer === '') {
|
|
4833
|
+
responseError.answer = 'Content should not be empty.';
|
|
4834
|
+
}
|
|
4835
|
+
|
|
4836
|
+
reversedAlternates.forEach(([key, value], index) => {
|
|
4837
|
+
if (value === '') {
|
|
4838
|
+
alternatesErrors[key] = 'Content should not be empty.';
|
|
4839
|
+
} else {
|
|
4840
|
+
const identicalAnswer =
|
|
4841
|
+
answer === value || reversedAlternates.slice(index + 1).some(([, val]) => val === value);
|
|
4842
|
+
|
|
4843
|
+
if (identicalAnswer) {
|
|
4844
|
+
alternatesErrors[key] = 'Content should be unique.';
|
|
4845
|
+
}
|
|
4846
|
+
}
|
|
4847
|
+
});
|
|
4848
|
+
|
|
4849
|
+
if (!isEmpty_1(responseError) || !isEmpty_1(alternatesErrors)) {
|
|
4850
|
+
responsesErrors[index] = { ...responseError, ...alternatesErrors };
|
|
4851
|
+
}
|
|
4852
|
+
});
|
|
4853
|
+
|
|
4854
|
+
const nbOfResponseAreas = (markup.match(/\{\{(\d+)\}\}/g) || []).length;
|
|
4855
|
+
|
|
4856
|
+
if (nbOfResponseAreas > maxResponseAreas) {
|
|
4857
|
+
errors.responseAreas = `No more than ${maxResponseAreas} response areas should be defined.`;
|
|
4858
|
+
} else if (nbOfResponseAreas < 1) {
|
|
4859
|
+
errors.responseAreas = 'There should be at least 1 response area defined.';
|
|
4860
|
+
}
|
|
4861
|
+
|
|
4862
|
+
if (!isEmpty_1(responsesErrors)) {
|
|
4863
|
+
errors.responses = responsesErrors;
|
|
4864
|
+
}
|
|
4865
|
+
|
|
4866
|
+
return errors;
|
|
4867
|
+
};
|
|
4868
|
+
|
|
4869
|
+
export { createCorrectResponseSession, createDefaultModel, getCorrectness, getPartialScore, model, normalizeSession, outcome, prepareVal, validate };
|