dinero.js 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3968 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
+ typeof define === 'function' && define.amd ? define(factory) :
4
+ (global = global || self, global.Dinero = factory());
5
+ }(this, (function () { 'use strict';
6
+
7
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
8
+
9
+ function createCommonjsModule(fn, module) {
10
+ return module = { exports: {} }, fn(module, module.exports), module.exports;
11
+ }
12
+
13
+ var check = function (it) {
14
+ return it && it.Math == Math && it;
15
+ };
16
+
17
+ // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
18
+ var global_1 =
19
+ // eslint-disable-next-line no-undef
20
+ check(typeof globalThis == 'object' && globalThis) ||
21
+ check(typeof window == 'object' && window) ||
22
+ check(typeof self == 'object' && self) ||
23
+ check(typeof commonjsGlobal == 'object' && commonjsGlobal) ||
24
+ // eslint-disable-next-line no-new-func
25
+ Function('return this')();
26
+
27
+ var fails = function (exec) {
28
+ try {
29
+ return !!exec();
30
+ } catch (error) {
31
+ return true;
32
+ }
33
+ };
34
+
35
+ // Thank's IE8 for his funny defineProperty
36
+ var descriptors = !fails(function () {
37
+ return Object.defineProperty({}, 1, { get: function () { return 7; } })[1] != 7;
38
+ });
39
+
40
+ var nativePropertyIsEnumerable = {}.propertyIsEnumerable;
41
+ var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
42
+
43
+ // Nashorn ~ JDK8 bug
44
+ var NASHORN_BUG = getOwnPropertyDescriptor && !nativePropertyIsEnumerable.call({ 1: 2 }, 1);
45
+
46
+ // `Object.prototype.propertyIsEnumerable` method implementation
47
+ // https://tc39.github.io/ecma262/#sec-object.prototype.propertyisenumerable
48
+ var f = NASHORN_BUG ? function propertyIsEnumerable(V) {
49
+ var descriptor = getOwnPropertyDescriptor(this, V);
50
+ return !!descriptor && descriptor.enumerable;
51
+ } : nativePropertyIsEnumerable;
52
+
53
+ var objectPropertyIsEnumerable = {
54
+ f: f
55
+ };
56
+
57
+ var createPropertyDescriptor = function (bitmap, value) {
58
+ return {
59
+ enumerable: !(bitmap & 1),
60
+ configurable: !(bitmap & 2),
61
+ writable: !(bitmap & 4),
62
+ value: value
63
+ };
64
+ };
65
+
66
+ var toString = {}.toString;
67
+
68
+ var classofRaw = function (it) {
69
+ return toString.call(it).slice(8, -1);
70
+ };
71
+
72
+ var split = ''.split;
73
+
74
+ // fallback for non-array-like ES3 and non-enumerable old V8 strings
75
+ var indexedObject = fails(function () {
76
+ // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346
77
+ // eslint-disable-next-line no-prototype-builtins
78
+ return !Object('z').propertyIsEnumerable(0);
79
+ }) ? function (it) {
80
+ return classofRaw(it) == 'String' ? split.call(it, '') : Object(it);
81
+ } : Object;
82
+
83
+ // `RequireObjectCoercible` abstract operation
84
+ // https://tc39.github.io/ecma262/#sec-requireobjectcoercible
85
+ var requireObjectCoercible = function (it) {
86
+ if (it == undefined) throw TypeError("Can't call method on " + it);
87
+ return it;
88
+ };
89
+
90
+ // toObject with fallback for non-array-like ES3 strings
91
+
92
+
93
+
94
+ var toIndexedObject = function (it) {
95
+ return indexedObject(requireObjectCoercible(it));
96
+ };
97
+
98
+ var isObject = function (it) {
99
+ return typeof it === 'object' ? it !== null : typeof it === 'function';
100
+ };
101
+
102
+ // `ToPrimitive` abstract operation
103
+ // https://tc39.github.io/ecma262/#sec-toprimitive
104
+ // instead of the ES6 spec version, we didn't implement @@toPrimitive case
105
+ // and the second argument - flag - preferred type is a string
106
+ var toPrimitive = function (input, PREFERRED_STRING) {
107
+ if (!isObject(input)) return input;
108
+ var fn, val;
109
+ if (PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val;
110
+ if (typeof (fn = input.valueOf) == 'function' && !isObject(val = fn.call(input))) return val;
111
+ if (!PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val;
112
+ throw TypeError("Can't convert object to primitive value");
113
+ };
114
+
115
+ var hasOwnProperty = {}.hasOwnProperty;
116
+
117
+ var has = function (it, key) {
118
+ return hasOwnProperty.call(it, key);
119
+ };
120
+
121
+ var document$1 = global_1.document;
122
+ // typeof document.createElement is 'object' in old IE
123
+ var EXISTS = isObject(document$1) && isObject(document$1.createElement);
124
+
125
+ var documentCreateElement = function (it) {
126
+ return EXISTS ? document$1.createElement(it) : {};
127
+ };
128
+
129
+ // Thank's IE8 for his funny defineProperty
130
+ var ie8DomDefine = !descriptors && !fails(function () {
131
+ return Object.defineProperty(documentCreateElement('div'), 'a', {
132
+ get: function () { return 7; }
133
+ }).a != 7;
134
+ });
135
+
136
+ var nativeGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
137
+
138
+ // `Object.getOwnPropertyDescriptor` method
139
+ // https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptor
140
+ var f$1 = descriptors ? nativeGetOwnPropertyDescriptor : function getOwnPropertyDescriptor(O, P) {
141
+ O = toIndexedObject(O);
142
+ P = toPrimitive(P, true);
143
+ if (ie8DomDefine) try {
144
+ return nativeGetOwnPropertyDescriptor(O, P);
145
+ } catch (error) { /* empty */ }
146
+ if (has(O, P)) return createPropertyDescriptor(!objectPropertyIsEnumerable.f.call(O, P), O[P]);
147
+ };
148
+
149
+ var objectGetOwnPropertyDescriptor = {
150
+ f: f$1
151
+ };
152
+
153
+ var anObject = function (it) {
154
+ if (!isObject(it)) {
155
+ throw TypeError(String(it) + ' is not an object');
156
+ } return it;
157
+ };
158
+
159
+ var nativeDefineProperty = Object.defineProperty;
160
+
161
+ // `Object.defineProperty` method
162
+ // https://tc39.github.io/ecma262/#sec-object.defineproperty
163
+ var f$2 = descriptors ? nativeDefineProperty : function defineProperty(O, P, Attributes) {
164
+ anObject(O);
165
+ P = toPrimitive(P, true);
166
+ anObject(Attributes);
167
+ if (ie8DomDefine) try {
168
+ return nativeDefineProperty(O, P, Attributes);
169
+ } catch (error) { /* empty */ }
170
+ if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported');
171
+ if ('value' in Attributes) O[P] = Attributes.value;
172
+ return O;
173
+ };
174
+
175
+ var objectDefineProperty = {
176
+ f: f$2
177
+ };
178
+
179
+ var createNonEnumerableProperty = descriptors ? function (object, key, value) {
180
+ return objectDefineProperty.f(object, key, createPropertyDescriptor(1, value));
181
+ } : function (object, key, value) {
182
+ object[key] = value;
183
+ return object;
184
+ };
185
+
186
+ var setGlobal = function (key, value) {
187
+ try {
188
+ createNonEnumerableProperty(global_1, key, value);
189
+ } catch (error) {
190
+ global_1[key] = value;
191
+ } return value;
192
+ };
193
+
194
+ var SHARED = '__core-js_shared__';
195
+ var store = global_1[SHARED] || setGlobal(SHARED, {});
196
+
197
+ var sharedStore = store;
198
+
199
+ var functionToString = Function.toString;
200
+
201
+ // this helper broken in `3.4.1-3.4.4`, so we can't use `shared` helper
202
+ if (typeof sharedStore.inspectSource != 'function') {
203
+ sharedStore.inspectSource = function (it) {
204
+ return functionToString.call(it);
205
+ };
206
+ }
207
+
208
+ var inspectSource = sharedStore.inspectSource;
209
+
210
+ var WeakMap = global_1.WeakMap;
211
+
212
+ var nativeWeakMap = typeof WeakMap === 'function' && /native code/.test(inspectSource(WeakMap));
213
+
214
+ var shared = createCommonjsModule(function (module) {
215
+ (module.exports = function (key, value) {
216
+ return sharedStore[key] || (sharedStore[key] = value !== undefined ? value : {});
217
+ })('versions', []).push({
218
+ version: '3.6.5',
219
+ mode: 'global',
220
+ copyright: '© 2020 Denis Pushkarev (zloirock.ru)'
221
+ });
222
+ });
223
+
224
+ var id = 0;
225
+ var postfix = Math.random();
226
+
227
+ var uid = function (key) {
228
+ return 'Symbol(' + String(key === undefined ? '' : key) + ')_' + (++id + postfix).toString(36);
229
+ };
230
+
231
+ var keys = shared('keys');
232
+
233
+ var sharedKey = function (key) {
234
+ return keys[key] || (keys[key] = uid(key));
235
+ };
236
+
237
+ var hiddenKeys = {};
238
+
239
+ var WeakMap$1 = global_1.WeakMap;
240
+ var set, get, has$1;
241
+
242
+ var enforce = function (it) {
243
+ return has$1(it) ? get(it) : set(it, {});
244
+ };
245
+
246
+ var getterFor = function (TYPE) {
247
+ return function (it) {
248
+ var state;
249
+ if (!isObject(it) || (state = get(it)).type !== TYPE) {
250
+ throw TypeError('Incompatible receiver, ' + TYPE + ' required');
251
+ } return state;
252
+ };
253
+ };
254
+
255
+ if (nativeWeakMap) {
256
+ var store$1 = new WeakMap$1();
257
+ var wmget = store$1.get;
258
+ var wmhas = store$1.has;
259
+ var wmset = store$1.set;
260
+ set = function (it, metadata) {
261
+ wmset.call(store$1, it, metadata);
262
+ return metadata;
263
+ };
264
+ get = function (it) {
265
+ return wmget.call(store$1, it) || {};
266
+ };
267
+ has$1 = function (it) {
268
+ return wmhas.call(store$1, it);
269
+ };
270
+ } else {
271
+ var STATE = sharedKey('state');
272
+ hiddenKeys[STATE] = true;
273
+ set = function (it, metadata) {
274
+ createNonEnumerableProperty(it, STATE, metadata);
275
+ return metadata;
276
+ };
277
+ get = function (it) {
278
+ return has(it, STATE) ? it[STATE] : {};
279
+ };
280
+ has$1 = function (it) {
281
+ return has(it, STATE);
282
+ };
283
+ }
284
+
285
+ var internalState = {
286
+ set: set,
287
+ get: get,
288
+ has: has$1,
289
+ enforce: enforce,
290
+ getterFor: getterFor
291
+ };
292
+
293
+ var redefine = createCommonjsModule(function (module) {
294
+ var getInternalState = internalState.get;
295
+ var enforceInternalState = internalState.enforce;
296
+ var TEMPLATE = String(String).split('String');
297
+
298
+ (module.exports = function (O, key, value, options) {
299
+ var unsafe = options ? !!options.unsafe : false;
300
+ var simple = options ? !!options.enumerable : false;
301
+ var noTargetGet = options ? !!options.noTargetGet : false;
302
+ if (typeof value == 'function') {
303
+ if (typeof key == 'string' && !has(value, 'name')) createNonEnumerableProperty(value, 'name', key);
304
+ enforceInternalState(value).source = TEMPLATE.join(typeof key == 'string' ? key : '');
305
+ }
306
+ if (O === global_1) {
307
+ if (simple) O[key] = value;
308
+ else setGlobal(key, value);
309
+ return;
310
+ } else if (!unsafe) {
311
+ delete O[key];
312
+ } else if (!noTargetGet && O[key]) {
313
+ simple = true;
314
+ }
315
+ if (simple) O[key] = value;
316
+ else createNonEnumerableProperty(O, key, value);
317
+ // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
318
+ })(Function.prototype, 'toString', function toString() {
319
+ return typeof this == 'function' && getInternalState(this).source || inspectSource(this);
320
+ });
321
+ });
322
+
323
+ var path = global_1;
324
+
325
+ var aFunction = function (variable) {
326
+ return typeof variable == 'function' ? variable : undefined;
327
+ };
328
+
329
+ var getBuiltIn = function (namespace, method) {
330
+ return arguments.length < 2 ? aFunction(path[namespace]) || aFunction(global_1[namespace])
331
+ : path[namespace] && path[namespace][method] || global_1[namespace] && global_1[namespace][method];
332
+ };
333
+
334
+ var ceil = Math.ceil;
335
+ var floor = Math.floor;
336
+
337
+ // `ToInteger` abstract operation
338
+ // https://tc39.github.io/ecma262/#sec-tointeger
339
+ var toInteger = function (argument) {
340
+ return isNaN(argument = +argument) ? 0 : (argument > 0 ? floor : ceil)(argument);
341
+ };
342
+
343
+ var min = Math.min;
344
+
345
+ // `ToLength` abstract operation
346
+ // https://tc39.github.io/ecma262/#sec-tolength
347
+ var toLength = function (argument) {
348
+ return argument > 0 ? min(toInteger(argument), 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991
349
+ };
350
+
351
+ var max = Math.max;
352
+ var min$1 = Math.min;
353
+
354
+ // Helper for a popular repeating case of the spec:
355
+ // Let integer be ? ToInteger(index).
356
+ // If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length).
357
+ var toAbsoluteIndex = function (index, length) {
358
+ var integer = toInteger(index);
359
+ return integer < 0 ? max(integer + length, 0) : min$1(integer, length);
360
+ };
361
+
362
+ // `Array.prototype.{ indexOf, includes }` methods implementation
363
+ var createMethod = function (IS_INCLUDES) {
364
+ return function ($this, el, fromIndex) {
365
+ var O = toIndexedObject($this);
366
+ var length = toLength(O.length);
367
+ var index = toAbsoluteIndex(fromIndex, length);
368
+ var value;
369
+ // Array#includes uses SameValueZero equality algorithm
370
+ // eslint-disable-next-line no-self-compare
371
+ if (IS_INCLUDES && el != el) while (length > index) {
372
+ value = O[index++];
373
+ // eslint-disable-next-line no-self-compare
374
+ if (value != value) return true;
375
+ // Array#indexOf ignores holes, Array#includes - not
376
+ } else for (;length > index; index++) {
377
+ if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0;
378
+ } return !IS_INCLUDES && -1;
379
+ };
380
+ };
381
+
382
+ var arrayIncludes = {
383
+ // `Array.prototype.includes` method
384
+ // https://tc39.github.io/ecma262/#sec-array.prototype.includes
385
+ includes: createMethod(true),
386
+ // `Array.prototype.indexOf` method
387
+ // https://tc39.github.io/ecma262/#sec-array.prototype.indexof
388
+ indexOf: createMethod(false)
389
+ };
390
+
391
+ var indexOf = arrayIncludes.indexOf;
392
+
393
+
394
+ var objectKeysInternal = function (object, names) {
395
+ var O = toIndexedObject(object);
396
+ var i = 0;
397
+ var result = [];
398
+ var key;
399
+ for (key in O) !has(hiddenKeys, key) && has(O, key) && result.push(key);
400
+ // Don't enum bug & hidden keys
401
+ while (names.length > i) if (has(O, key = names[i++])) {
402
+ ~indexOf(result, key) || result.push(key);
403
+ }
404
+ return result;
405
+ };
406
+
407
+ // IE8- don't enum bug keys
408
+ var enumBugKeys = [
409
+ 'constructor',
410
+ 'hasOwnProperty',
411
+ 'isPrototypeOf',
412
+ 'propertyIsEnumerable',
413
+ 'toLocaleString',
414
+ 'toString',
415
+ 'valueOf'
416
+ ];
417
+
418
+ var hiddenKeys$1 = enumBugKeys.concat('length', 'prototype');
419
+
420
+ // `Object.getOwnPropertyNames` method
421
+ // https://tc39.github.io/ecma262/#sec-object.getownpropertynames
422
+ var f$3 = Object.getOwnPropertyNames || function getOwnPropertyNames(O) {
423
+ return objectKeysInternal(O, hiddenKeys$1);
424
+ };
425
+
426
+ var objectGetOwnPropertyNames = {
427
+ f: f$3
428
+ };
429
+
430
+ var f$4 = Object.getOwnPropertySymbols;
431
+
432
+ var objectGetOwnPropertySymbols = {
433
+ f: f$4
434
+ };
435
+
436
+ // all object keys, includes non-enumerable and symbols
437
+ var ownKeys = getBuiltIn('Reflect', 'ownKeys') || function ownKeys(it) {
438
+ var keys = objectGetOwnPropertyNames.f(anObject(it));
439
+ var getOwnPropertySymbols = objectGetOwnPropertySymbols.f;
440
+ return getOwnPropertySymbols ? keys.concat(getOwnPropertySymbols(it)) : keys;
441
+ };
442
+
443
+ var copyConstructorProperties = function (target, source) {
444
+ var keys = ownKeys(source);
445
+ var defineProperty = objectDefineProperty.f;
446
+ var getOwnPropertyDescriptor = objectGetOwnPropertyDescriptor.f;
447
+ for (var i = 0; i < keys.length; i++) {
448
+ var key = keys[i];
449
+ if (!has(target, key)) defineProperty(target, key, getOwnPropertyDescriptor(source, key));
450
+ }
451
+ };
452
+
453
+ var replacement = /#|\.prototype\./;
454
+
455
+ var isForced = function (feature, detection) {
456
+ var value = data[normalize(feature)];
457
+ return value == POLYFILL ? true
458
+ : value == NATIVE ? false
459
+ : typeof detection == 'function' ? fails(detection)
460
+ : !!detection;
461
+ };
462
+
463
+ var normalize = isForced.normalize = function (string) {
464
+ return String(string).replace(replacement, '.').toLowerCase();
465
+ };
466
+
467
+ var data = isForced.data = {};
468
+ var NATIVE = isForced.NATIVE = 'N';
469
+ var POLYFILL = isForced.POLYFILL = 'P';
470
+
471
+ var isForced_1 = isForced;
472
+
473
+ var getOwnPropertyDescriptor$1 = objectGetOwnPropertyDescriptor.f;
474
+
475
+
476
+
477
+
478
+
479
+
480
+ /*
481
+ options.target - name of the target object
482
+ options.global - target is the global object
483
+ options.stat - export as static methods of target
484
+ options.proto - export as prototype methods of target
485
+ options.real - real prototype method for the `pure` version
486
+ options.forced - export even if the native feature is available
487
+ options.bind - bind methods to the target, required for the `pure` version
488
+ options.wrap - wrap constructors to preventing global pollution, required for the `pure` version
489
+ options.unsafe - use the simple assignment of property instead of delete + defineProperty
490
+ options.sham - add a flag to not completely full polyfills
491
+ options.enumerable - export as enumerable property
492
+ options.noTargetGet - prevent calling a getter on target
493
+ */
494
+ var _export = function (options, source) {
495
+ var TARGET = options.target;
496
+ var GLOBAL = options.global;
497
+ var STATIC = options.stat;
498
+ var FORCED, target, key, targetProperty, sourceProperty, descriptor;
499
+ if (GLOBAL) {
500
+ target = global_1;
501
+ } else if (STATIC) {
502
+ target = global_1[TARGET] || setGlobal(TARGET, {});
503
+ } else {
504
+ target = (global_1[TARGET] || {}).prototype;
505
+ }
506
+ if (target) for (key in source) {
507
+ sourceProperty = source[key];
508
+ if (options.noTargetGet) {
509
+ descriptor = getOwnPropertyDescriptor$1(target, key);
510
+ targetProperty = descriptor && descriptor.value;
511
+ } else targetProperty = target[key];
512
+ FORCED = isForced_1(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced);
513
+ // contained in target
514
+ if (!FORCED && targetProperty !== undefined) {
515
+ if (typeof sourceProperty === typeof targetProperty) continue;
516
+ copyConstructorProperties(sourceProperty, targetProperty);
517
+ }
518
+ // add a flag to not completely full polyfills
519
+ if (options.sham || (targetProperty && targetProperty.sham)) {
520
+ createNonEnumerableProperty(sourceProperty, 'sham', true);
521
+ }
522
+ // extend global
523
+ redefine(target, key, sourceProperty, options);
524
+ }
525
+ };
526
+
527
+ var aFunction$1 = function (it) {
528
+ if (typeof it != 'function') {
529
+ throw TypeError(String(it) + ' is not a function');
530
+ } return it;
531
+ };
532
+
533
+ // optional / simple context binding
534
+ var functionBindContext = function (fn, that, length) {
535
+ aFunction$1(fn);
536
+ if (that === undefined) return fn;
537
+ switch (length) {
538
+ case 0: return function () {
539
+ return fn.call(that);
540
+ };
541
+ case 1: return function (a) {
542
+ return fn.call(that, a);
543
+ };
544
+ case 2: return function (a, b) {
545
+ return fn.call(that, a, b);
546
+ };
547
+ case 3: return function (a, b, c) {
548
+ return fn.call(that, a, b, c);
549
+ };
550
+ }
551
+ return function (/* ...args */) {
552
+ return fn.apply(that, arguments);
553
+ };
554
+ };
555
+
556
+ // `ToObject` abstract operation
557
+ // https://tc39.github.io/ecma262/#sec-toobject
558
+ var toObject = function (argument) {
559
+ return Object(requireObjectCoercible(argument));
560
+ };
561
+
562
+ // `IsArray` abstract operation
563
+ // https://tc39.github.io/ecma262/#sec-isarray
564
+ var isArray = Array.isArray || function isArray(arg) {
565
+ return classofRaw(arg) == 'Array';
566
+ };
567
+
568
+ var nativeSymbol = !!Object.getOwnPropertySymbols && !fails(function () {
569
+ // Chrome 38 Symbol has incorrect toString conversion
570
+ // eslint-disable-next-line no-undef
571
+ return !String(Symbol());
572
+ });
573
+
574
+ var useSymbolAsUid = nativeSymbol
575
+ // eslint-disable-next-line no-undef
576
+ && !Symbol.sham
577
+ // eslint-disable-next-line no-undef
578
+ && typeof Symbol.iterator == 'symbol';
579
+
580
+ var WellKnownSymbolsStore = shared('wks');
581
+ var Symbol$1 = global_1.Symbol;
582
+ var createWellKnownSymbol = useSymbolAsUid ? Symbol$1 : Symbol$1 && Symbol$1.withoutSetter || uid;
583
+
584
+ var wellKnownSymbol = function (name) {
585
+ if (!has(WellKnownSymbolsStore, name)) {
586
+ if (nativeSymbol && has(Symbol$1, name)) WellKnownSymbolsStore[name] = Symbol$1[name];
587
+ else WellKnownSymbolsStore[name] = createWellKnownSymbol('Symbol.' + name);
588
+ } return WellKnownSymbolsStore[name];
589
+ };
590
+
591
+ var SPECIES = wellKnownSymbol('species');
592
+
593
+ // `ArraySpeciesCreate` abstract operation
594
+ // https://tc39.github.io/ecma262/#sec-arrayspeciescreate
595
+ var arraySpeciesCreate = function (originalArray, length) {
596
+ var C;
597
+ if (isArray(originalArray)) {
598
+ C = originalArray.constructor;
599
+ // cross-realm fallback
600
+ if (typeof C == 'function' && (C === Array || isArray(C.prototype))) C = undefined;
601
+ else if (isObject(C)) {
602
+ C = C[SPECIES];
603
+ if (C === null) C = undefined;
604
+ }
605
+ } return new (C === undefined ? Array : C)(length === 0 ? 0 : length);
606
+ };
607
+
608
+ var push = [].push;
609
+
610
+ // `Array.prototype.{ forEach, map, filter, some, every, find, findIndex }` methods implementation
611
+ var createMethod$1 = function (TYPE) {
612
+ var IS_MAP = TYPE == 1;
613
+ var IS_FILTER = TYPE == 2;
614
+ var IS_SOME = TYPE == 3;
615
+ var IS_EVERY = TYPE == 4;
616
+ var IS_FIND_INDEX = TYPE == 6;
617
+ var NO_HOLES = TYPE == 5 || IS_FIND_INDEX;
618
+ return function ($this, callbackfn, that, specificCreate) {
619
+ var O = toObject($this);
620
+ var self = indexedObject(O);
621
+ var boundFunction = functionBindContext(callbackfn, that, 3);
622
+ var length = toLength(self.length);
623
+ var index = 0;
624
+ var create = specificCreate || arraySpeciesCreate;
625
+ var target = IS_MAP ? create($this, length) : IS_FILTER ? create($this, 0) : undefined;
626
+ var value, result;
627
+ for (;length > index; index++) if (NO_HOLES || index in self) {
628
+ value = self[index];
629
+ result = boundFunction(value, index, O);
630
+ if (TYPE) {
631
+ if (IS_MAP) target[index] = result; // map
632
+ else if (result) switch (TYPE) {
633
+ case 3: return true; // some
634
+ case 5: return value; // find
635
+ case 6: return index; // findIndex
636
+ case 2: push.call(target, value); // filter
637
+ } else if (IS_EVERY) return false; // every
638
+ }
639
+ }
640
+ return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : target;
641
+ };
642
+ };
643
+
644
+ var arrayIteration = {
645
+ // `Array.prototype.forEach` method
646
+ // https://tc39.github.io/ecma262/#sec-array.prototype.foreach
647
+ forEach: createMethod$1(0),
648
+ // `Array.prototype.map` method
649
+ // https://tc39.github.io/ecma262/#sec-array.prototype.map
650
+ map: createMethod$1(1),
651
+ // `Array.prototype.filter` method
652
+ // https://tc39.github.io/ecma262/#sec-array.prototype.filter
653
+ filter: createMethod$1(2),
654
+ // `Array.prototype.some` method
655
+ // https://tc39.github.io/ecma262/#sec-array.prototype.some
656
+ some: createMethod$1(3),
657
+ // `Array.prototype.every` method
658
+ // https://tc39.github.io/ecma262/#sec-array.prototype.every
659
+ every: createMethod$1(4),
660
+ // `Array.prototype.find` method
661
+ // https://tc39.github.io/ecma262/#sec-array.prototype.find
662
+ find: createMethod$1(5),
663
+ // `Array.prototype.findIndex` method
664
+ // https://tc39.github.io/ecma262/#sec-array.prototype.findIndex
665
+ findIndex: createMethod$1(6)
666
+ };
667
+
668
+ var arrayMethodIsStrict = function (METHOD_NAME, argument) {
669
+ var method = [][METHOD_NAME];
670
+ return !!method && fails(function () {
671
+ // eslint-disable-next-line no-useless-call,no-throw-literal
672
+ method.call(null, argument || function () { throw 1; }, 1);
673
+ });
674
+ };
675
+
676
+ var defineProperty = Object.defineProperty;
677
+ var cache = {};
678
+
679
+ var thrower = function (it) { throw it; };
680
+
681
+ var arrayMethodUsesToLength = function (METHOD_NAME, options) {
682
+ if (has(cache, METHOD_NAME)) return cache[METHOD_NAME];
683
+ if (!options) options = {};
684
+ var method = [][METHOD_NAME];
685
+ var ACCESSORS = has(options, 'ACCESSORS') ? options.ACCESSORS : false;
686
+ var argument0 = has(options, 0) ? options[0] : thrower;
687
+ var argument1 = has(options, 1) ? options[1] : undefined;
688
+
689
+ return cache[METHOD_NAME] = !!method && !fails(function () {
690
+ if (ACCESSORS && !descriptors) return true;
691
+ var O = { length: -1 };
692
+
693
+ if (ACCESSORS) defineProperty(O, 1, { enumerable: true, get: thrower });
694
+ else O[1] = 1;
695
+
696
+ method.call(O, argument0, argument1);
697
+ });
698
+ };
699
+
700
+ var $every = arrayIteration.every;
701
+
702
+
703
+
704
+ var STRICT_METHOD = arrayMethodIsStrict('every');
705
+ var USES_TO_LENGTH = arrayMethodUsesToLength('every');
706
+
707
+ // `Array.prototype.every` method
708
+ // https://tc39.github.io/ecma262/#sec-array.prototype.every
709
+ _export({ target: 'Array', proto: true, forced: !STRICT_METHOD || !USES_TO_LENGTH }, {
710
+ every: function every(callbackfn /* , thisArg */) {
711
+ return $every(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
712
+ }
713
+ });
714
+
715
+ var call = Function.call;
716
+
717
+ var entryUnbind = function (CONSTRUCTOR, METHOD, length) {
718
+ return functionBindContext(call, global_1[CONSTRUCTOR].prototype[METHOD], length);
719
+ };
720
+
721
+ var every = entryUnbind('Array', 'every');
722
+
723
+ // `Object.keys` method
724
+ // https://tc39.github.io/ecma262/#sec-object.keys
725
+ var objectKeys = Object.keys || function keys(O) {
726
+ return objectKeysInternal(O, enumBugKeys);
727
+ };
728
+
729
+ // `Object.defineProperties` method
730
+ // https://tc39.github.io/ecma262/#sec-object.defineproperties
731
+ var objectDefineProperties = descriptors ? Object.defineProperties : function defineProperties(O, Properties) {
732
+ anObject(O);
733
+ var keys = objectKeys(Properties);
734
+ var length = keys.length;
735
+ var index = 0;
736
+ var key;
737
+ while (length > index) objectDefineProperty.f(O, key = keys[index++], Properties[key]);
738
+ return O;
739
+ };
740
+
741
+ var html = getBuiltIn('document', 'documentElement');
742
+
743
+ var GT = '>';
744
+ var LT = '<';
745
+ var PROTOTYPE = 'prototype';
746
+ var SCRIPT = 'script';
747
+ var IE_PROTO = sharedKey('IE_PROTO');
748
+
749
+ var EmptyConstructor = function () { /* empty */ };
750
+
751
+ var scriptTag = function (content) {
752
+ return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT;
753
+ };
754
+
755
+ // Create object with fake `null` prototype: use ActiveX Object with cleared prototype
756
+ var NullProtoObjectViaActiveX = function (activeXDocument) {
757
+ activeXDocument.write(scriptTag(''));
758
+ activeXDocument.close();
759
+ var temp = activeXDocument.parentWindow.Object;
760
+ activeXDocument = null; // avoid memory leak
761
+ return temp;
762
+ };
763
+
764
+ // Create object with fake `null` prototype: use iframe Object with cleared prototype
765
+ var NullProtoObjectViaIFrame = function () {
766
+ // Thrash, waste and sodomy: IE GC bug
767
+ var iframe = documentCreateElement('iframe');
768
+ var JS = 'java' + SCRIPT + ':';
769
+ var iframeDocument;
770
+ iframe.style.display = 'none';
771
+ html.appendChild(iframe);
772
+ // https://github.com/zloirock/core-js/issues/475
773
+ iframe.src = String(JS);
774
+ iframeDocument = iframe.contentWindow.document;
775
+ iframeDocument.open();
776
+ iframeDocument.write(scriptTag('document.F=Object'));
777
+ iframeDocument.close();
778
+ return iframeDocument.F;
779
+ };
780
+
781
+ // Check for document.domain and active x support
782
+ // No need to use active x approach when document.domain is not set
783
+ // see https://github.com/es-shims/es5-shim/issues/150
784
+ // variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346
785
+ // avoid IE GC bug
786
+ var activeXDocument;
787
+ var NullProtoObject = function () {
788
+ try {
789
+ /* global ActiveXObject */
790
+ activeXDocument = document.domain && new ActiveXObject('htmlfile');
791
+ } catch (error) { /* ignore */ }
792
+ NullProtoObject = activeXDocument ? NullProtoObjectViaActiveX(activeXDocument) : NullProtoObjectViaIFrame();
793
+ var length = enumBugKeys.length;
794
+ while (length--) delete NullProtoObject[PROTOTYPE][enumBugKeys[length]];
795
+ return NullProtoObject();
796
+ };
797
+
798
+ hiddenKeys[IE_PROTO] = true;
799
+
800
+ // `Object.create` method
801
+ // https://tc39.github.io/ecma262/#sec-object.create
802
+ var objectCreate = Object.create || function create(O, Properties) {
803
+ var result;
804
+ if (O !== null) {
805
+ EmptyConstructor[PROTOTYPE] = anObject(O);
806
+ result = new EmptyConstructor();
807
+ EmptyConstructor[PROTOTYPE] = null;
808
+ // add "__proto__" for Object.getPrototypeOf polyfill
809
+ result[IE_PROTO] = O;
810
+ } else result = NullProtoObject();
811
+ return Properties === undefined ? result : objectDefineProperties(result, Properties);
812
+ };
813
+
814
+ var UNSCOPABLES = wellKnownSymbol('unscopables');
815
+ var ArrayPrototype = Array.prototype;
816
+
817
+ // Array.prototype[@@unscopables]
818
+ // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables
819
+ if (ArrayPrototype[UNSCOPABLES] == undefined) {
820
+ objectDefineProperty.f(ArrayPrototype, UNSCOPABLES, {
821
+ configurable: true,
822
+ value: objectCreate(null)
823
+ });
824
+ }
825
+
826
+ // add a key to Array.prototype[@@unscopables]
827
+ var addToUnscopables = function (key) {
828
+ ArrayPrototype[UNSCOPABLES][key] = true;
829
+ };
830
+
831
+ var $findIndex = arrayIteration.findIndex;
832
+
833
+
834
+
835
+ var FIND_INDEX = 'findIndex';
836
+ var SKIPS_HOLES = true;
837
+
838
+ var USES_TO_LENGTH$1 = arrayMethodUsesToLength(FIND_INDEX);
839
+
840
+ // Shouldn't skip holes
841
+ if (FIND_INDEX in []) Array(1)[FIND_INDEX](function () { SKIPS_HOLES = false; });
842
+
843
+ // `Array.prototype.findIndex` method
844
+ // https://tc39.github.io/ecma262/#sec-array.prototype.findindex
845
+ _export({ target: 'Array', proto: true, forced: SKIPS_HOLES || !USES_TO_LENGTH$1 }, {
846
+ findIndex: function findIndex(callbackfn /* , that = undefined */) {
847
+ return $findIndex(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
848
+ }
849
+ });
850
+
851
+ // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables
852
+ addToUnscopables(FIND_INDEX);
853
+
854
+ var findIndex = entryUnbind('Array', 'findIndex');
855
+
856
+ var $find = arrayIteration.find;
857
+
858
+
859
+
860
+ var FIND = 'find';
861
+ var SKIPS_HOLES$1 = true;
862
+
863
+ var USES_TO_LENGTH$2 = arrayMethodUsesToLength(FIND);
864
+
865
+ // Shouldn't skip holes
866
+ if (FIND in []) Array(1)[FIND](function () { SKIPS_HOLES$1 = false; });
867
+
868
+ // `Array.prototype.find` method
869
+ // https://tc39.github.io/ecma262/#sec-array.prototype.find
870
+ _export({ target: 'Array', proto: true, forced: SKIPS_HOLES$1 || !USES_TO_LENGTH$2 }, {
871
+ find: function find(callbackfn /* , that = undefined */) {
872
+ return $find(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
873
+ }
874
+ });
875
+
876
+ // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables
877
+ addToUnscopables(FIND);
878
+
879
+ var find = entryUnbind('Array', 'find');
880
+
881
+ var iterators = {};
882
+
883
+ var correctPrototypeGetter = !fails(function () {
884
+ function F() { /* empty */ }
885
+ F.prototype.constructor = null;
886
+ return Object.getPrototypeOf(new F()) !== F.prototype;
887
+ });
888
+
889
+ var IE_PROTO$1 = sharedKey('IE_PROTO');
890
+ var ObjectPrototype = Object.prototype;
891
+
892
+ // `Object.getPrototypeOf` method
893
+ // https://tc39.github.io/ecma262/#sec-object.getprototypeof
894
+ var objectGetPrototypeOf = correctPrototypeGetter ? Object.getPrototypeOf : function (O) {
895
+ O = toObject(O);
896
+ if (has(O, IE_PROTO$1)) return O[IE_PROTO$1];
897
+ if (typeof O.constructor == 'function' && O instanceof O.constructor) {
898
+ return O.constructor.prototype;
899
+ } return O instanceof Object ? ObjectPrototype : null;
900
+ };
901
+
902
+ var ITERATOR = wellKnownSymbol('iterator');
903
+ var BUGGY_SAFARI_ITERATORS = false;
904
+
905
+ var returnThis = function () { return this; };
906
+
907
+ // `%IteratorPrototype%` object
908
+ // https://tc39.github.io/ecma262/#sec-%iteratorprototype%-object
909
+ var IteratorPrototype, PrototypeOfArrayIteratorPrototype, arrayIterator;
910
+
911
+ if ([].keys) {
912
+ arrayIterator = [].keys();
913
+ // Safari 8 has buggy iterators w/o `next`
914
+ if (!('next' in arrayIterator)) BUGGY_SAFARI_ITERATORS = true;
915
+ else {
916
+ PrototypeOfArrayIteratorPrototype = objectGetPrototypeOf(objectGetPrototypeOf(arrayIterator));
917
+ if (PrototypeOfArrayIteratorPrototype !== Object.prototype) IteratorPrototype = PrototypeOfArrayIteratorPrototype;
918
+ }
919
+ }
920
+
921
+ if (IteratorPrototype == undefined) IteratorPrototype = {};
922
+
923
+ // 25.1.2.1.1 %IteratorPrototype%[@@iterator]()
924
+ if ( !has(IteratorPrototype, ITERATOR)) {
925
+ createNonEnumerableProperty(IteratorPrototype, ITERATOR, returnThis);
926
+ }
927
+
928
+ var iteratorsCore = {
929
+ IteratorPrototype: IteratorPrototype,
930
+ BUGGY_SAFARI_ITERATORS: BUGGY_SAFARI_ITERATORS
931
+ };
932
+
933
+ var defineProperty$1 = objectDefineProperty.f;
934
+
935
+
936
+
937
+ var TO_STRING_TAG = wellKnownSymbol('toStringTag');
938
+
939
+ var setToStringTag = function (it, TAG, STATIC) {
940
+ if (it && !has(it = STATIC ? it : it.prototype, TO_STRING_TAG)) {
941
+ defineProperty$1(it, TO_STRING_TAG, { configurable: true, value: TAG });
942
+ }
943
+ };
944
+
945
+ var IteratorPrototype$1 = iteratorsCore.IteratorPrototype;
946
+
947
+
948
+
949
+
950
+
951
+ var returnThis$1 = function () { return this; };
952
+
953
+ var createIteratorConstructor = function (IteratorConstructor, NAME, next) {
954
+ var TO_STRING_TAG = NAME + ' Iterator';
955
+ IteratorConstructor.prototype = objectCreate(IteratorPrototype$1, { next: createPropertyDescriptor(1, next) });
956
+ setToStringTag(IteratorConstructor, TO_STRING_TAG, false);
957
+ iterators[TO_STRING_TAG] = returnThis$1;
958
+ return IteratorConstructor;
959
+ };
960
+
961
+ var aPossiblePrototype = function (it) {
962
+ if (!isObject(it) && it !== null) {
963
+ throw TypeError("Can't set " + String(it) + ' as a prototype');
964
+ } return it;
965
+ };
966
+
967
+ // `Object.setPrototypeOf` method
968
+ // https://tc39.github.io/ecma262/#sec-object.setprototypeof
969
+ // Works with __proto__ only. Old v8 can't work with null proto objects.
970
+ /* eslint-disable no-proto */
971
+ var objectSetPrototypeOf = Object.setPrototypeOf || ('__proto__' in {} ? function () {
972
+ var CORRECT_SETTER = false;
973
+ var test = {};
974
+ var setter;
975
+ try {
976
+ setter = Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set;
977
+ setter.call(test, []);
978
+ CORRECT_SETTER = test instanceof Array;
979
+ } catch (error) { /* empty */ }
980
+ return function setPrototypeOf(O, proto) {
981
+ anObject(O);
982
+ aPossiblePrototype(proto);
983
+ if (CORRECT_SETTER) setter.call(O, proto);
984
+ else O.__proto__ = proto;
985
+ return O;
986
+ };
987
+ }() : undefined);
988
+
989
+ var IteratorPrototype$2 = iteratorsCore.IteratorPrototype;
990
+ var BUGGY_SAFARI_ITERATORS$1 = iteratorsCore.BUGGY_SAFARI_ITERATORS;
991
+ var ITERATOR$1 = wellKnownSymbol('iterator');
992
+ var KEYS = 'keys';
993
+ var VALUES = 'values';
994
+ var ENTRIES = 'entries';
995
+
996
+ var returnThis$2 = function () { return this; };
997
+
998
+ var defineIterator = function (Iterable, NAME, IteratorConstructor, next, DEFAULT, IS_SET, FORCED) {
999
+ createIteratorConstructor(IteratorConstructor, NAME, next);
1000
+
1001
+ var getIterationMethod = function (KIND) {
1002
+ if (KIND === DEFAULT && defaultIterator) return defaultIterator;
1003
+ if (!BUGGY_SAFARI_ITERATORS$1 && KIND in IterablePrototype) return IterablePrototype[KIND];
1004
+ switch (KIND) {
1005
+ case KEYS: return function keys() { return new IteratorConstructor(this, KIND); };
1006
+ case VALUES: return function values() { return new IteratorConstructor(this, KIND); };
1007
+ case ENTRIES: return function entries() { return new IteratorConstructor(this, KIND); };
1008
+ } return function () { return new IteratorConstructor(this); };
1009
+ };
1010
+
1011
+ var TO_STRING_TAG = NAME + ' Iterator';
1012
+ var INCORRECT_VALUES_NAME = false;
1013
+ var IterablePrototype = Iterable.prototype;
1014
+ var nativeIterator = IterablePrototype[ITERATOR$1]
1015
+ || IterablePrototype['@@iterator']
1016
+ || DEFAULT && IterablePrototype[DEFAULT];
1017
+ var defaultIterator = !BUGGY_SAFARI_ITERATORS$1 && nativeIterator || getIterationMethod(DEFAULT);
1018
+ var anyNativeIterator = NAME == 'Array' ? IterablePrototype.entries || nativeIterator : nativeIterator;
1019
+ var CurrentIteratorPrototype, methods, KEY;
1020
+
1021
+ // fix native
1022
+ if (anyNativeIterator) {
1023
+ CurrentIteratorPrototype = objectGetPrototypeOf(anyNativeIterator.call(new Iterable()));
1024
+ if (IteratorPrototype$2 !== Object.prototype && CurrentIteratorPrototype.next) {
1025
+ if ( objectGetPrototypeOf(CurrentIteratorPrototype) !== IteratorPrototype$2) {
1026
+ if (objectSetPrototypeOf) {
1027
+ objectSetPrototypeOf(CurrentIteratorPrototype, IteratorPrototype$2);
1028
+ } else if (typeof CurrentIteratorPrototype[ITERATOR$1] != 'function') {
1029
+ createNonEnumerableProperty(CurrentIteratorPrototype, ITERATOR$1, returnThis$2);
1030
+ }
1031
+ }
1032
+ // Set @@toStringTag to native iterators
1033
+ setToStringTag(CurrentIteratorPrototype, TO_STRING_TAG, true);
1034
+ }
1035
+ }
1036
+
1037
+ // fix Array#{values, @@iterator}.name in V8 / FF
1038
+ if (DEFAULT == VALUES && nativeIterator && nativeIterator.name !== VALUES) {
1039
+ INCORRECT_VALUES_NAME = true;
1040
+ defaultIterator = function values() { return nativeIterator.call(this); };
1041
+ }
1042
+
1043
+ // define iterator
1044
+ if ( IterablePrototype[ITERATOR$1] !== defaultIterator) {
1045
+ createNonEnumerableProperty(IterablePrototype, ITERATOR$1, defaultIterator);
1046
+ }
1047
+ iterators[NAME] = defaultIterator;
1048
+
1049
+ // export additional methods
1050
+ if (DEFAULT) {
1051
+ methods = {
1052
+ values: getIterationMethod(VALUES),
1053
+ keys: IS_SET ? defaultIterator : getIterationMethod(KEYS),
1054
+ entries: getIterationMethod(ENTRIES)
1055
+ };
1056
+ if (FORCED) for (KEY in methods) {
1057
+ if (BUGGY_SAFARI_ITERATORS$1 || INCORRECT_VALUES_NAME || !(KEY in IterablePrototype)) {
1058
+ redefine(IterablePrototype, KEY, methods[KEY]);
1059
+ }
1060
+ } else _export({ target: NAME, proto: true, forced: BUGGY_SAFARI_ITERATORS$1 || INCORRECT_VALUES_NAME }, methods);
1061
+ }
1062
+
1063
+ return methods;
1064
+ };
1065
+
1066
+ var ARRAY_ITERATOR = 'Array Iterator';
1067
+ var setInternalState = internalState.set;
1068
+ var getInternalState = internalState.getterFor(ARRAY_ITERATOR);
1069
+
1070
+ // `Array.prototype.entries` method
1071
+ // https://tc39.github.io/ecma262/#sec-array.prototype.entries
1072
+ // `Array.prototype.keys` method
1073
+ // https://tc39.github.io/ecma262/#sec-array.prototype.keys
1074
+ // `Array.prototype.values` method
1075
+ // https://tc39.github.io/ecma262/#sec-array.prototype.values
1076
+ // `Array.prototype[@@iterator]` method
1077
+ // https://tc39.github.io/ecma262/#sec-array.prototype-@@iterator
1078
+ // `CreateArrayIterator` internal method
1079
+ // https://tc39.github.io/ecma262/#sec-createarrayiterator
1080
+ var es_array_iterator = defineIterator(Array, 'Array', function (iterated, kind) {
1081
+ setInternalState(this, {
1082
+ type: ARRAY_ITERATOR,
1083
+ target: toIndexedObject(iterated), // target
1084
+ index: 0, // next index
1085
+ kind: kind // kind
1086
+ });
1087
+ // `%ArrayIteratorPrototype%.next` method
1088
+ // https://tc39.github.io/ecma262/#sec-%arrayiteratorprototype%.next
1089
+ }, function () {
1090
+ var state = getInternalState(this);
1091
+ var target = state.target;
1092
+ var kind = state.kind;
1093
+ var index = state.index++;
1094
+ if (!target || index >= target.length) {
1095
+ state.target = undefined;
1096
+ return { value: undefined, done: true };
1097
+ }
1098
+ if (kind == 'keys') return { value: index, done: false };
1099
+ if (kind == 'values') return { value: target[index], done: false };
1100
+ return { value: [index, target[index]], done: false };
1101
+ }, 'values');
1102
+
1103
+ // argumentsList[@@iterator] is %ArrayProto_values%
1104
+ // https://tc39.github.io/ecma262/#sec-createunmappedargumentsobject
1105
+ // https://tc39.github.io/ecma262/#sec-createmappedargumentsobject
1106
+ iterators.Arguments = iterators.Array;
1107
+
1108
+ // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables
1109
+ addToUnscopables('keys');
1110
+ addToUnscopables('values');
1111
+ addToUnscopables('entries');
1112
+
1113
+ var keys$1 = entryUnbind('Array', 'keys');
1114
+
1115
+ var $some = arrayIteration.some;
1116
+
1117
+
1118
+
1119
+ var STRICT_METHOD$1 = arrayMethodIsStrict('some');
1120
+ var USES_TO_LENGTH$3 = arrayMethodUsesToLength('some');
1121
+
1122
+ // `Array.prototype.some` method
1123
+ // https://tc39.github.io/ecma262/#sec-array.prototype.some
1124
+ _export({ target: 'Array', proto: true, forced: !STRICT_METHOD$1 || !USES_TO_LENGTH$3 }, {
1125
+ some: function some(callbackfn /* , thisArg */) {
1126
+ return $some(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
1127
+ }
1128
+ });
1129
+
1130
+ var some = entryUnbind('Array', 'some');
1131
+
1132
+ var nativeAssign = Object.assign;
1133
+ var defineProperty$2 = Object.defineProperty;
1134
+
1135
+ // `Object.assign` method
1136
+ // https://tc39.github.io/ecma262/#sec-object.assign
1137
+ var objectAssign = !nativeAssign || fails(function () {
1138
+ // should have correct order of operations (Edge bug)
1139
+ if (descriptors && nativeAssign({ b: 1 }, nativeAssign(defineProperty$2({}, 'a', {
1140
+ enumerable: true,
1141
+ get: function () {
1142
+ defineProperty$2(this, 'b', {
1143
+ value: 3,
1144
+ enumerable: false
1145
+ });
1146
+ }
1147
+ }), { b: 2 })).b !== 1) return true;
1148
+ // should work with symbols and should have deterministic property order (V8 bug)
1149
+ var A = {};
1150
+ var B = {};
1151
+ // eslint-disable-next-line no-undef
1152
+ var symbol = Symbol();
1153
+ var alphabet = 'abcdefghijklmnopqrst';
1154
+ A[symbol] = 7;
1155
+ alphabet.split('').forEach(function (chr) { B[chr] = chr; });
1156
+ return nativeAssign({}, A)[symbol] != 7 || objectKeys(nativeAssign({}, B)).join('') != alphabet;
1157
+ }) ? function assign(target, source) { // eslint-disable-line no-unused-vars
1158
+ var T = toObject(target);
1159
+ var argumentsLength = arguments.length;
1160
+ var index = 1;
1161
+ var getOwnPropertySymbols = objectGetOwnPropertySymbols.f;
1162
+ var propertyIsEnumerable = objectPropertyIsEnumerable.f;
1163
+ while (argumentsLength > index) {
1164
+ var S = indexedObject(arguments[index++]);
1165
+ var keys = getOwnPropertySymbols ? objectKeys(S).concat(getOwnPropertySymbols(S)) : objectKeys(S);
1166
+ var length = keys.length;
1167
+ var j = 0;
1168
+ var key;
1169
+ while (length > j) {
1170
+ key = keys[j++];
1171
+ if (!descriptors || propertyIsEnumerable.call(S, key)) T[key] = S[key];
1172
+ }
1173
+ } return T;
1174
+ } : nativeAssign;
1175
+
1176
+ // `Object.assign` method
1177
+ // https://tc39.github.io/ecma262/#sec-object.assign
1178
+ _export({ target: 'Object', stat: true, forced: Object.assign !== objectAssign }, {
1179
+ assign: objectAssign
1180
+ });
1181
+
1182
+ var assign = path.Object.assign;
1183
+
1184
+ var propertyIsEnumerable = objectPropertyIsEnumerable.f;
1185
+
1186
+ // `Object.{ entries, values }` methods implementation
1187
+ var createMethod$2 = function (TO_ENTRIES) {
1188
+ return function (it) {
1189
+ var O = toIndexedObject(it);
1190
+ var keys = objectKeys(O);
1191
+ var length = keys.length;
1192
+ var i = 0;
1193
+ var result = [];
1194
+ var key;
1195
+ while (length > i) {
1196
+ key = keys[i++];
1197
+ if (!descriptors || propertyIsEnumerable.call(O, key)) {
1198
+ result.push(TO_ENTRIES ? [key, O[key]] : O[key]);
1199
+ }
1200
+ }
1201
+ return result;
1202
+ };
1203
+ };
1204
+
1205
+ var objectToArray = {
1206
+ // `Object.entries` method
1207
+ // https://tc39.github.io/ecma262/#sec-object.entries
1208
+ entries: createMethod$2(true),
1209
+ // `Object.values` method
1210
+ // https://tc39.github.io/ecma262/#sec-object.values
1211
+ values: createMethod$2(false)
1212
+ };
1213
+
1214
+ var $entries = objectToArray.entries;
1215
+
1216
+ // `Object.entries` method
1217
+ // https://tc39.github.io/ecma262/#sec-object.entries
1218
+ _export({ target: 'Object', stat: true }, {
1219
+ entries: function entries(O) {
1220
+ return $entries(O);
1221
+ }
1222
+ });
1223
+
1224
+ var entries = path.Object.entries;
1225
+
1226
+ var floor$1 = Math.floor;
1227
+
1228
+ // `Number.isInteger` method implementation
1229
+ // https://tc39.github.io/ecma262/#sec-number.isinteger
1230
+ var isInteger = function isInteger(it) {
1231
+ return !isObject(it) && isFinite(it) && floor$1(it) === it;
1232
+ };
1233
+
1234
+ // `Number.isInteger` method
1235
+ // https://tc39.github.io/ecma262/#sec-number.isinteger
1236
+ _export({ target: 'Number', stat: true }, {
1237
+ isInteger: isInteger
1238
+ });
1239
+
1240
+ var isInteger$1 = path.Number.isInteger;
1241
+
1242
+ // `Math.sign` method implementation
1243
+ // https://tc39.github.io/ecma262/#sec-math.sign
1244
+ var mathSign = Math.sign || function sign(x) {
1245
+ // eslint-disable-next-line no-self-compare
1246
+ return (x = +x) == 0 || x != x ? x : x < 0 ? -1 : 1;
1247
+ };
1248
+
1249
+ // `Math.sign` method
1250
+ // https://tc39.github.io/ecma262/#sec-math.sign
1251
+ _export({ target: 'Math', stat: true }, {
1252
+ sign: mathSign
1253
+ });
1254
+
1255
+ var sign = path.Math.sign;
1256
+
1257
+ var TO_STRING_TAG$1 = wellKnownSymbol('toStringTag');
1258
+ var test = {};
1259
+
1260
+ test[TO_STRING_TAG$1] = 'z';
1261
+
1262
+ var toStringTagSupport = String(test) === '[object z]';
1263
+
1264
+ var TO_STRING_TAG$2 = wellKnownSymbol('toStringTag');
1265
+ // ES3 wrong here
1266
+ var CORRECT_ARGUMENTS = classofRaw(function () { return arguments; }()) == 'Arguments';
1267
+
1268
+ // fallback for IE11 Script Access Denied error
1269
+ var tryGet = function (it, key) {
1270
+ try {
1271
+ return it[key];
1272
+ } catch (error) { /* empty */ }
1273
+ };
1274
+
1275
+ // getting tag from ES6+ `Object.prototype.toString`
1276
+ var classof = toStringTagSupport ? classofRaw : function (it) {
1277
+ var O, tag, result;
1278
+ return it === undefined ? 'Undefined' : it === null ? 'Null'
1279
+ // @@toStringTag case
1280
+ : typeof (tag = tryGet(O = Object(it), TO_STRING_TAG$2)) == 'string' ? tag
1281
+ // builtinTag case
1282
+ : CORRECT_ARGUMENTS ? classofRaw(O)
1283
+ // ES3 arguments fallback
1284
+ : (result = classofRaw(O)) == 'Object' && typeof O.callee == 'function' ? 'Arguments' : result;
1285
+ };
1286
+
1287
+ // `Object.prototype.toString` method implementation
1288
+ // https://tc39.github.io/ecma262/#sec-object.prototype.tostring
1289
+ var objectToString = toStringTagSupport ? {}.toString : function toString() {
1290
+ return '[object ' + classof(this) + ']';
1291
+ };
1292
+
1293
+ // `Object.prototype.toString` method
1294
+ // https://tc39.github.io/ecma262/#sec-object.prototype.tostring
1295
+ if (!toStringTagSupport) {
1296
+ redefine(Object.prototype, 'toString', objectToString, { unsafe: true });
1297
+ }
1298
+
1299
+ // `String.prototype.{ codePointAt, at }` methods implementation
1300
+ var createMethod$3 = function (CONVERT_TO_STRING) {
1301
+ return function ($this, pos) {
1302
+ var S = String(requireObjectCoercible($this));
1303
+ var position = toInteger(pos);
1304
+ var size = S.length;
1305
+ var first, second;
1306
+ if (position < 0 || position >= size) return CONVERT_TO_STRING ? '' : undefined;
1307
+ first = S.charCodeAt(position);
1308
+ return first < 0xD800 || first > 0xDBFF || position + 1 === size
1309
+ || (second = S.charCodeAt(position + 1)) < 0xDC00 || second > 0xDFFF
1310
+ ? CONVERT_TO_STRING ? S.charAt(position) : first
1311
+ : CONVERT_TO_STRING ? S.slice(position, position + 2) : (first - 0xD800 << 10) + (second - 0xDC00) + 0x10000;
1312
+ };
1313
+ };
1314
+
1315
+ var stringMultibyte = {
1316
+ // `String.prototype.codePointAt` method
1317
+ // https://tc39.github.io/ecma262/#sec-string.prototype.codepointat
1318
+ codeAt: createMethod$3(false),
1319
+ // `String.prototype.at` method
1320
+ // https://github.com/mathiasbynens/String.prototype.at
1321
+ charAt: createMethod$3(true)
1322
+ };
1323
+
1324
+ var charAt = stringMultibyte.charAt;
1325
+
1326
+
1327
+
1328
+ var STRING_ITERATOR = 'String Iterator';
1329
+ var setInternalState$1 = internalState.set;
1330
+ var getInternalState$1 = internalState.getterFor(STRING_ITERATOR);
1331
+
1332
+ // `String.prototype[@@iterator]` method
1333
+ // https://tc39.github.io/ecma262/#sec-string.prototype-@@iterator
1334
+ defineIterator(String, 'String', function (iterated) {
1335
+ setInternalState$1(this, {
1336
+ type: STRING_ITERATOR,
1337
+ string: String(iterated),
1338
+ index: 0
1339
+ });
1340
+ // `%StringIteratorPrototype%.next` method
1341
+ // https://tc39.github.io/ecma262/#sec-%stringiteratorprototype%.next
1342
+ }, function next() {
1343
+ var state = getInternalState$1(this);
1344
+ var string = state.string;
1345
+ var index = state.index;
1346
+ var point;
1347
+ if (index >= string.length) return { value: undefined, done: true };
1348
+ point = charAt(string, index);
1349
+ state.index += point.length;
1350
+ return { value: point, done: false };
1351
+ });
1352
+
1353
+ // iterable DOM collections
1354
+ // flag - `iterable` interface - 'entries', 'keys', 'values', 'forEach' methods
1355
+ var domIterables = {
1356
+ CSSRuleList: 0,
1357
+ CSSStyleDeclaration: 0,
1358
+ CSSValueList: 0,
1359
+ ClientRectList: 0,
1360
+ DOMRectList: 0,
1361
+ DOMStringList: 0,
1362
+ DOMTokenList: 1,
1363
+ DataTransferItemList: 0,
1364
+ FileList: 0,
1365
+ HTMLAllCollection: 0,
1366
+ HTMLCollection: 0,
1367
+ HTMLFormElement: 0,
1368
+ HTMLSelectElement: 0,
1369
+ MediaList: 0,
1370
+ MimeTypeArray: 0,
1371
+ NamedNodeMap: 0,
1372
+ NodeList: 1,
1373
+ PaintRequestList: 0,
1374
+ Plugin: 0,
1375
+ PluginArray: 0,
1376
+ SVGLengthList: 0,
1377
+ SVGNumberList: 0,
1378
+ SVGPathSegList: 0,
1379
+ SVGPointList: 0,
1380
+ SVGStringList: 0,
1381
+ SVGTransformList: 0,
1382
+ SourceBufferList: 0,
1383
+ StyleSheetList: 0,
1384
+ TextTrackCueList: 0,
1385
+ TextTrackList: 0,
1386
+ TouchList: 0
1387
+ };
1388
+
1389
+ var ITERATOR$2 = wellKnownSymbol('iterator');
1390
+ var TO_STRING_TAG$3 = wellKnownSymbol('toStringTag');
1391
+ var ArrayValues = es_array_iterator.values;
1392
+
1393
+ for (var COLLECTION_NAME in domIterables) {
1394
+ var Collection = global_1[COLLECTION_NAME];
1395
+ var CollectionPrototype = Collection && Collection.prototype;
1396
+ if (CollectionPrototype) {
1397
+ // some Chrome versions have non-configurable methods on DOMTokenList
1398
+ if (CollectionPrototype[ITERATOR$2] !== ArrayValues) try {
1399
+ createNonEnumerableProperty(CollectionPrototype, ITERATOR$2, ArrayValues);
1400
+ } catch (error) {
1401
+ CollectionPrototype[ITERATOR$2] = ArrayValues;
1402
+ }
1403
+ if (!CollectionPrototype[TO_STRING_TAG$3]) {
1404
+ createNonEnumerableProperty(CollectionPrototype, TO_STRING_TAG$3, COLLECTION_NAME);
1405
+ }
1406
+ if (domIterables[COLLECTION_NAME]) for (var METHOD_NAME in es_array_iterator) {
1407
+ // some Chrome versions have non-configurable methods on DOMTokenList
1408
+ if (CollectionPrototype[METHOD_NAME] !== es_array_iterator[METHOD_NAME]) try {
1409
+ createNonEnumerableProperty(CollectionPrototype, METHOD_NAME, es_array_iterator[METHOD_NAME]);
1410
+ } catch (error) {
1411
+ CollectionPrototype[METHOD_NAME] = es_array_iterator[METHOD_NAME];
1412
+ }
1413
+ }
1414
+ }
1415
+ }
1416
+
1417
+ var nativePromiseConstructor = global_1.Promise;
1418
+
1419
+ var redefineAll = function (target, src, options) {
1420
+ for (var key in src) redefine(target, key, src[key], options);
1421
+ return target;
1422
+ };
1423
+
1424
+ var SPECIES$1 = wellKnownSymbol('species');
1425
+
1426
+ var setSpecies = function (CONSTRUCTOR_NAME) {
1427
+ var Constructor = getBuiltIn(CONSTRUCTOR_NAME);
1428
+ var defineProperty = objectDefineProperty.f;
1429
+
1430
+ if (descriptors && Constructor && !Constructor[SPECIES$1]) {
1431
+ defineProperty(Constructor, SPECIES$1, {
1432
+ configurable: true,
1433
+ get: function () { return this; }
1434
+ });
1435
+ }
1436
+ };
1437
+
1438
+ var anInstance = function (it, Constructor, name) {
1439
+ if (!(it instanceof Constructor)) {
1440
+ throw TypeError('Incorrect ' + (name ? name + ' ' : '') + 'invocation');
1441
+ } return it;
1442
+ };
1443
+
1444
+ var ITERATOR$3 = wellKnownSymbol('iterator');
1445
+ var ArrayPrototype$1 = Array.prototype;
1446
+
1447
+ // check on default Array iterator
1448
+ var isArrayIteratorMethod = function (it) {
1449
+ return it !== undefined && (iterators.Array === it || ArrayPrototype$1[ITERATOR$3] === it);
1450
+ };
1451
+
1452
+ var ITERATOR$4 = wellKnownSymbol('iterator');
1453
+
1454
+ var getIteratorMethod = function (it) {
1455
+ if (it != undefined) return it[ITERATOR$4]
1456
+ || it['@@iterator']
1457
+ || iterators[classof(it)];
1458
+ };
1459
+
1460
+ // call something on iterator step with safe closing on error
1461
+ var callWithSafeIterationClosing = function (iterator, fn, value, ENTRIES) {
1462
+ try {
1463
+ return ENTRIES ? fn(anObject(value)[0], value[1]) : fn(value);
1464
+ // 7.4.6 IteratorClose(iterator, completion)
1465
+ } catch (error) {
1466
+ var returnMethod = iterator['return'];
1467
+ if (returnMethod !== undefined) anObject(returnMethod.call(iterator));
1468
+ throw error;
1469
+ }
1470
+ };
1471
+
1472
+ var iterate_1 = createCommonjsModule(function (module) {
1473
+ var Result = function (stopped, result) {
1474
+ this.stopped = stopped;
1475
+ this.result = result;
1476
+ };
1477
+
1478
+ var iterate = module.exports = function (iterable, fn, that, AS_ENTRIES, IS_ITERATOR) {
1479
+ var boundFunction = functionBindContext(fn, that, AS_ENTRIES ? 2 : 1);
1480
+ var iterator, iterFn, index, length, result, next, step;
1481
+
1482
+ if (IS_ITERATOR) {
1483
+ iterator = iterable;
1484
+ } else {
1485
+ iterFn = getIteratorMethod(iterable);
1486
+ if (typeof iterFn != 'function') throw TypeError('Target is not iterable');
1487
+ // optimisation for array iterators
1488
+ if (isArrayIteratorMethod(iterFn)) {
1489
+ for (index = 0, length = toLength(iterable.length); length > index; index++) {
1490
+ result = AS_ENTRIES
1491
+ ? boundFunction(anObject(step = iterable[index])[0], step[1])
1492
+ : boundFunction(iterable[index]);
1493
+ if (result && result instanceof Result) return result;
1494
+ } return new Result(false);
1495
+ }
1496
+ iterator = iterFn.call(iterable);
1497
+ }
1498
+
1499
+ next = iterator.next;
1500
+ while (!(step = next.call(iterator)).done) {
1501
+ result = callWithSafeIterationClosing(iterator, boundFunction, step.value, AS_ENTRIES);
1502
+ if (typeof result == 'object' && result && result instanceof Result) return result;
1503
+ } return new Result(false);
1504
+ };
1505
+
1506
+ iterate.stop = function (result) {
1507
+ return new Result(true, result);
1508
+ };
1509
+ });
1510
+
1511
+ var ITERATOR$5 = wellKnownSymbol('iterator');
1512
+ var SAFE_CLOSING = false;
1513
+
1514
+ try {
1515
+ var called = 0;
1516
+ var iteratorWithReturn = {
1517
+ next: function () {
1518
+ return { done: !!called++ };
1519
+ },
1520
+ 'return': function () {
1521
+ SAFE_CLOSING = true;
1522
+ }
1523
+ };
1524
+ iteratorWithReturn[ITERATOR$5] = function () {
1525
+ return this;
1526
+ };
1527
+ // eslint-disable-next-line no-throw-literal
1528
+ Array.from(iteratorWithReturn, function () { throw 2; });
1529
+ } catch (error) { /* empty */ }
1530
+
1531
+ var checkCorrectnessOfIteration = function (exec, SKIP_CLOSING) {
1532
+ if (!SKIP_CLOSING && !SAFE_CLOSING) return false;
1533
+ var ITERATION_SUPPORT = false;
1534
+ try {
1535
+ var object = {};
1536
+ object[ITERATOR$5] = function () {
1537
+ return {
1538
+ next: function () {
1539
+ return { done: ITERATION_SUPPORT = true };
1540
+ }
1541
+ };
1542
+ };
1543
+ exec(object);
1544
+ } catch (error) { /* empty */ }
1545
+ return ITERATION_SUPPORT;
1546
+ };
1547
+
1548
+ var SPECIES$2 = wellKnownSymbol('species');
1549
+
1550
+ // `SpeciesConstructor` abstract operation
1551
+ // https://tc39.github.io/ecma262/#sec-speciesconstructor
1552
+ var speciesConstructor = function (O, defaultConstructor) {
1553
+ var C = anObject(O).constructor;
1554
+ var S;
1555
+ return C === undefined || (S = anObject(C)[SPECIES$2]) == undefined ? defaultConstructor : aFunction$1(S);
1556
+ };
1557
+
1558
+ var engineUserAgent = getBuiltIn('navigator', 'userAgent') || '';
1559
+
1560
+ var engineIsIos = /(iphone|ipod|ipad).*applewebkit/i.test(engineUserAgent);
1561
+
1562
+ var location = global_1.location;
1563
+ var set$1 = global_1.setImmediate;
1564
+ var clear = global_1.clearImmediate;
1565
+ var process = global_1.process;
1566
+ var MessageChannel = global_1.MessageChannel;
1567
+ var Dispatch = global_1.Dispatch;
1568
+ var counter = 0;
1569
+ var queue = {};
1570
+ var ONREADYSTATECHANGE = 'onreadystatechange';
1571
+ var defer, channel, port;
1572
+
1573
+ var run = function (id) {
1574
+ // eslint-disable-next-line no-prototype-builtins
1575
+ if (queue.hasOwnProperty(id)) {
1576
+ var fn = queue[id];
1577
+ delete queue[id];
1578
+ fn();
1579
+ }
1580
+ };
1581
+
1582
+ var runner = function (id) {
1583
+ return function () {
1584
+ run(id);
1585
+ };
1586
+ };
1587
+
1588
+ var listener = function (event) {
1589
+ run(event.data);
1590
+ };
1591
+
1592
+ var post = function (id) {
1593
+ // old engines have not location.origin
1594
+ global_1.postMessage(id + '', location.protocol + '//' + location.host);
1595
+ };
1596
+
1597
+ // Node.js 0.9+ & IE10+ has setImmediate, otherwise:
1598
+ if (!set$1 || !clear) {
1599
+ set$1 = function setImmediate(fn) {
1600
+ var args = [];
1601
+ var i = 1;
1602
+ while (arguments.length > i) args.push(arguments[i++]);
1603
+ queue[++counter] = function () {
1604
+ // eslint-disable-next-line no-new-func
1605
+ (typeof fn == 'function' ? fn : Function(fn)).apply(undefined, args);
1606
+ };
1607
+ defer(counter);
1608
+ return counter;
1609
+ };
1610
+ clear = function clearImmediate(id) {
1611
+ delete queue[id];
1612
+ };
1613
+ // Node.js 0.8-
1614
+ if (classofRaw(process) == 'process') {
1615
+ defer = function (id) {
1616
+ process.nextTick(runner(id));
1617
+ };
1618
+ // Sphere (JS game engine) Dispatch API
1619
+ } else if (Dispatch && Dispatch.now) {
1620
+ defer = function (id) {
1621
+ Dispatch.now(runner(id));
1622
+ };
1623
+ // Browsers with MessageChannel, includes WebWorkers
1624
+ // except iOS - https://github.com/zloirock/core-js/issues/624
1625
+ } else if (MessageChannel && !engineIsIos) {
1626
+ channel = new MessageChannel();
1627
+ port = channel.port2;
1628
+ channel.port1.onmessage = listener;
1629
+ defer = functionBindContext(port.postMessage, port, 1);
1630
+ // Browsers with postMessage, skip WebWorkers
1631
+ // IE8 has postMessage, but it's sync & typeof its postMessage is 'object'
1632
+ } else if (
1633
+ global_1.addEventListener &&
1634
+ typeof postMessage == 'function' &&
1635
+ !global_1.importScripts &&
1636
+ !fails(post) &&
1637
+ location.protocol !== 'file:'
1638
+ ) {
1639
+ defer = post;
1640
+ global_1.addEventListener('message', listener, false);
1641
+ // IE8-
1642
+ } else if (ONREADYSTATECHANGE in documentCreateElement('script')) {
1643
+ defer = function (id) {
1644
+ html.appendChild(documentCreateElement('script'))[ONREADYSTATECHANGE] = function () {
1645
+ html.removeChild(this);
1646
+ run(id);
1647
+ };
1648
+ };
1649
+ // Rest old browsers
1650
+ } else {
1651
+ defer = function (id) {
1652
+ setTimeout(runner(id), 0);
1653
+ };
1654
+ }
1655
+ }
1656
+
1657
+ var task = {
1658
+ set: set$1,
1659
+ clear: clear
1660
+ };
1661
+
1662
+ var getOwnPropertyDescriptor$2 = objectGetOwnPropertyDescriptor.f;
1663
+
1664
+ var macrotask = task.set;
1665
+
1666
+
1667
+ var MutationObserver = global_1.MutationObserver || global_1.WebKitMutationObserver;
1668
+ var process$1 = global_1.process;
1669
+ var Promise$1 = global_1.Promise;
1670
+ var IS_NODE = classofRaw(process$1) == 'process';
1671
+ // Node.js 11 shows ExperimentalWarning on getting `queueMicrotask`
1672
+ var queueMicrotaskDescriptor = getOwnPropertyDescriptor$2(global_1, 'queueMicrotask');
1673
+ var queueMicrotask = queueMicrotaskDescriptor && queueMicrotaskDescriptor.value;
1674
+
1675
+ var flush, head, last, notify, toggle, node, promise, then;
1676
+
1677
+ // modern engines have queueMicrotask method
1678
+ if (!queueMicrotask) {
1679
+ flush = function () {
1680
+ var parent, fn;
1681
+ if (IS_NODE && (parent = process$1.domain)) parent.exit();
1682
+ while (head) {
1683
+ fn = head.fn;
1684
+ head = head.next;
1685
+ try {
1686
+ fn();
1687
+ } catch (error) {
1688
+ if (head) notify();
1689
+ else last = undefined;
1690
+ throw error;
1691
+ }
1692
+ } last = undefined;
1693
+ if (parent) parent.enter();
1694
+ };
1695
+
1696
+ // Node.js
1697
+ if (IS_NODE) {
1698
+ notify = function () {
1699
+ process$1.nextTick(flush);
1700
+ };
1701
+ // browsers with MutationObserver, except iOS - https://github.com/zloirock/core-js/issues/339
1702
+ } else if (MutationObserver && !engineIsIos) {
1703
+ toggle = true;
1704
+ node = document.createTextNode('');
1705
+ new MutationObserver(flush).observe(node, { characterData: true });
1706
+ notify = function () {
1707
+ node.data = toggle = !toggle;
1708
+ };
1709
+ // environments with maybe non-completely correct, but existent Promise
1710
+ } else if (Promise$1 && Promise$1.resolve) {
1711
+ // Promise.resolve without an argument throws an error in LG WebOS 2
1712
+ promise = Promise$1.resolve(undefined);
1713
+ then = promise.then;
1714
+ notify = function () {
1715
+ then.call(promise, flush);
1716
+ };
1717
+ // for other environments - macrotask based on:
1718
+ // - setImmediate
1719
+ // - MessageChannel
1720
+ // - window.postMessag
1721
+ // - onreadystatechange
1722
+ // - setTimeout
1723
+ } else {
1724
+ notify = function () {
1725
+ // strange IE + webpack dev server bug - use .call(global)
1726
+ macrotask.call(global_1, flush);
1727
+ };
1728
+ }
1729
+ }
1730
+
1731
+ var microtask = queueMicrotask || function (fn) {
1732
+ var task = { fn: fn, next: undefined };
1733
+ if (last) last.next = task;
1734
+ if (!head) {
1735
+ head = task;
1736
+ notify();
1737
+ } last = task;
1738
+ };
1739
+
1740
+ var PromiseCapability = function (C) {
1741
+ var resolve, reject;
1742
+ this.promise = new C(function ($$resolve, $$reject) {
1743
+ if (resolve !== undefined || reject !== undefined) throw TypeError('Bad Promise constructor');
1744
+ resolve = $$resolve;
1745
+ reject = $$reject;
1746
+ });
1747
+ this.resolve = aFunction$1(resolve);
1748
+ this.reject = aFunction$1(reject);
1749
+ };
1750
+
1751
+ // 25.4.1.5 NewPromiseCapability(C)
1752
+ var f$5 = function (C) {
1753
+ return new PromiseCapability(C);
1754
+ };
1755
+
1756
+ var newPromiseCapability = {
1757
+ f: f$5
1758
+ };
1759
+
1760
+ var promiseResolve = function (C, x) {
1761
+ anObject(C);
1762
+ if (isObject(x) && x.constructor === C) return x;
1763
+ var promiseCapability = newPromiseCapability.f(C);
1764
+ var resolve = promiseCapability.resolve;
1765
+ resolve(x);
1766
+ return promiseCapability.promise;
1767
+ };
1768
+
1769
+ var hostReportErrors = function (a, b) {
1770
+ var console = global_1.console;
1771
+ if (console && console.error) {
1772
+ arguments.length === 1 ? console.error(a) : console.error(a, b);
1773
+ }
1774
+ };
1775
+
1776
+ var perform = function (exec) {
1777
+ try {
1778
+ return { error: false, value: exec() };
1779
+ } catch (error) {
1780
+ return { error: true, value: error };
1781
+ }
1782
+ };
1783
+
1784
+ var process$2 = global_1.process;
1785
+ var versions = process$2 && process$2.versions;
1786
+ var v8 = versions && versions.v8;
1787
+ var match, version;
1788
+
1789
+ if (v8) {
1790
+ match = v8.split('.');
1791
+ version = match[0] + match[1];
1792
+ } else if (engineUserAgent) {
1793
+ match = engineUserAgent.match(/Edge\/(\d+)/);
1794
+ if (!match || match[1] >= 74) {
1795
+ match = engineUserAgent.match(/Chrome\/(\d+)/);
1796
+ if (match) version = match[1];
1797
+ }
1798
+ }
1799
+
1800
+ var engineV8Version = version && +version;
1801
+
1802
+ var task$1 = task.set;
1803
+
1804
+
1805
+
1806
+
1807
+
1808
+
1809
+
1810
+
1811
+
1812
+
1813
+ var SPECIES$3 = wellKnownSymbol('species');
1814
+ var PROMISE = 'Promise';
1815
+ var getInternalState$2 = internalState.get;
1816
+ var setInternalState$2 = internalState.set;
1817
+ var getInternalPromiseState = internalState.getterFor(PROMISE);
1818
+ var PromiseConstructor = nativePromiseConstructor;
1819
+ var TypeError$1 = global_1.TypeError;
1820
+ var document$2 = global_1.document;
1821
+ var process$3 = global_1.process;
1822
+ var $fetch = getBuiltIn('fetch');
1823
+ var newPromiseCapability$1 = newPromiseCapability.f;
1824
+ var newGenericPromiseCapability = newPromiseCapability$1;
1825
+ var IS_NODE$1 = classofRaw(process$3) == 'process';
1826
+ var DISPATCH_EVENT = !!(document$2 && document$2.createEvent && global_1.dispatchEvent);
1827
+ var UNHANDLED_REJECTION = 'unhandledrejection';
1828
+ var REJECTION_HANDLED = 'rejectionhandled';
1829
+ var PENDING = 0;
1830
+ var FULFILLED = 1;
1831
+ var REJECTED = 2;
1832
+ var HANDLED = 1;
1833
+ var UNHANDLED = 2;
1834
+ var Internal, OwnPromiseCapability, PromiseWrapper, nativeThen;
1835
+
1836
+ var FORCED = isForced_1(PROMISE, function () {
1837
+ var GLOBAL_CORE_JS_PROMISE = inspectSource(PromiseConstructor) !== String(PromiseConstructor);
1838
+ if (!GLOBAL_CORE_JS_PROMISE) {
1839
+ // V8 6.6 (Node 10 and Chrome 66) have a bug with resolving custom thenables
1840
+ // https://bugs.chromium.org/p/chromium/issues/detail?id=830565
1841
+ // We can't detect it synchronously, so just check versions
1842
+ if (engineV8Version === 66) return true;
1843
+ // Unhandled rejections tracking support, NodeJS Promise without it fails @@species test
1844
+ if (!IS_NODE$1 && typeof PromiseRejectionEvent != 'function') return true;
1845
+ }
1846
+ // We can't use @@species feature detection in V8 since it causes
1847
+ // deoptimization and performance degradation
1848
+ // https://github.com/zloirock/core-js/issues/679
1849
+ if (engineV8Version >= 51 && /native code/.test(PromiseConstructor)) return false;
1850
+ // Detect correctness of subclassing with @@species support
1851
+ var promise = PromiseConstructor.resolve(1);
1852
+ var FakePromise = function (exec) {
1853
+ exec(function () { /* empty */ }, function () { /* empty */ });
1854
+ };
1855
+ var constructor = promise.constructor = {};
1856
+ constructor[SPECIES$3] = FakePromise;
1857
+ return !(promise.then(function () { /* empty */ }) instanceof FakePromise);
1858
+ });
1859
+
1860
+ var INCORRECT_ITERATION = FORCED || !checkCorrectnessOfIteration(function (iterable) {
1861
+ PromiseConstructor.all(iterable)['catch'](function () { /* empty */ });
1862
+ });
1863
+
1864
+ // helpers
1865
+ var isThenable = function (it) {
1866
+ var then;
1867
+ return isObject(it) && typeof (then = it.then) == 'function' ? then : false;
1868
+ };
1869
+
1870
+ var notify$1 = function (promise, state, isReject) {
1871
+ if (state.notified) return;
1872
+ state.notified = true;
1873
+ var chain = state.reactions;
1874
+ microtask(function () {
1875
+ var value = state.value;
1876
+ var ok = state.state == FULFILLED;
1877
+ var index = 0;
1878
+ // variable length - can't use forEach
1879
+ while (chain.length > index) {
1880
+ var reaction = chain[index++];
1881
+ var handler = ok ? reaction.ok : reaction.fail;
1882
+ var resolve = reaction.resolve;
1883
+ var reject = reaction.reject;
1884
+ var domain = reaction.domain;
1885
+ var result, then, exited;
1886
+ try {
1887
+ if (handler) {
1888
+ if (!ok) {
1889
+ if (state.rejection === UNHANDLED) onHandleUnhandled(promise, state);
1890
+ state.rejection = HANDLED;
1891
+ }
1892
+ if (handler === true) result = value;
1893
+ else {
1894
+ if (domain) domain.enter();
1895
+ result = handler(value); // can throw
1896
+ if (domain) {
1897
+ domain.exit();
1898
+ exited = true;
1899
+ }
1900
+ }
1901
+ if (result === reaction.promise) {
1902
+ reject(TypeError$1('Promise-chain cycle'));
1903
+ } else if (then = isThenable(result)) {
1904
+ then.call(result, resolve, reject);
1905
+ } else resolve(result);
1906
+ } else reject(value);
1907
+ } catch (error) {
1908
+ if (domain && !exited) domain.exit();
1909
+ reject(error);
1910
+ }
1911
+ }
1912
+ state.reactions = [];
1913
+ state.notified = false;
1914
+ if (isReject && !state.rejection) onUnhandled(promise, state);
1915
+ });
1916
+ };
1917
+
1918
+ var dispatchEvent = function (name, promise, reason) {
1919
+ var event, handler;
1920
+ if (DISPATCH_EVENT) {
1921
+ event = document$2.createEvent('Event');
1922
+ event.promise = promise;
1923
+ event.reason = reason;
1924
+ event.initEvent(name, false, true);
1925
+ global_1.dispatchEvent(event);
1926
+ } else event = { promise: promise, reason: reason };
1927
+ if (handler = global_1['on' + name]) handler(event);
1928
+ else if (name === UNHANDLED_REJECTION) hostReportErrors('Unhandled promise rejection', reason);
1929
+ };
1930
+
1931
+ var onUnhandled = function (promise, state) {
1932
+ task$1.call(global_1, function () {
1933
+ var value = state.value;
1934
+ var IS_UNHANDLED = isUnhandled(state);
1935
+ var result;
1936
+ if (IS_UNHANDLED) {
1937
+ result = perform(function () {
1938
+ if (IS_NODE$1) {
1939
+ process$3.emit('unhandledRejection', value, promise);
1940
+ } else dispatchEvent(UNHANDLED_REJECTION, promise, value);
1941
+ });
1942
+ // Browsers should not trigger `rejectionHandled` event if it was handled here, NodeJS - should
1943
+ state.rejection = IS_NODE$1 || isUnhandled(state) ? UNHANDLED : HANDLED;
1944
+ if (result.error) throw result.value;
1945
+ }
1946
+ });
1947
+ };
1948
+
1949
+ var isUnhandled = function (state) {
1950
+ return state.rejection !== HANDLED && !state.parent;
1951
+ };
1952
+
1953
+ var onHandleUnhandled = function (promise, state) {
1954
+ task$1.call(global_1, function () {
1955
+ if (IS_NODE$1) {
1956
+ process$3.emit('rejectionHandled', promise);
1957
+ } else dispatchEvent(REJECTION_HANDLED, promise, state.value);
1958
+ });
1959
+ };
1960
+
1961
+ var bind = function (fn, promise, state, unwrap) {
1962
+ return function (value) {
1963
+ fn(promise, state, value, unwrap);
1964
+ };
1965
+ };
1966
+
1967
+ var internalReject = function (promise, state, value, unwrap) {
1968
+ if (state.done) return;
1969
+ state.done = true;
1970
+ if (unwrap) state = unwrap;
1971
+ state.value = value;
1972
+ state.state = REJECTED;
1973
+ notify$1(promise, state, true);
1974
+ };
1975
+
1976
+ var internalResolve = function (promise, state, value, unwrap) {
1977
+ if (state.done) return;
1978
+ state.done = true;
1979
+ if (unwrap) state = unwrap;
1980
+ try {
1981
+ if (promise === value) throw TypeError$1("Promise can't be resolved itself");
1982
+ var then = isThenable(value);
1983
+ if (then) {
1984
+ microtask(function () {
1985
+ var wrapper = { done: false };
1986
+ try {
1987
+ then.call(value,
1988
+ bind(internalResolve, promise, wrapper, state),
1989
+ bind(internalReject, promise, wrapper, state)
1990
+ );
1991
+ } catch (error) {
1992
+ internalReject(promise, wrapper, error, state);
1993
+ }
1994
+ });
1995
+ } else {
1996
+ state.value = value;
1997
+ state.state = FULFILLED;
1998
+ notify$1(promise, state, false);
1999
+ }
2000
+ } catch (error) {
2001
+ internalReject(promise, { done: false }, error, state);
2002
+ }
2003
+ };
2004
+
2005
+ // constructor polyfill
2006
+ if (FORCED) {
2007
+ // 25.4.3.1 Promise(executor)
2008
+ PromiseConstructor = function Promise(executor) {
2009
+ anInstance(this, PromiseConstructor, PROMISE);
2010
+ aFunction$1(executor);
2011
+ Internal.call(this);
2012
+ var state = getInternalState$2(this);
2013
+ try {
2014
+ executor(bind(internalResolve, this, state), bind(internalReject, this, state));
2015
+ } catch (error) {
2016
+ internalReject(this, state, error);
2017
+ }
2018
+ };
2019
+ // eslint-disable-next-line no-unused-vars
2020
+ Internal = function Promise(executor) {
2021
+ setInternalState$2(this, {
2022
+ type: PROMISE,
2023
+ done: false,
2024
+ notified: false,
2025
+ parent: false,
2026
+ reactions: [],
2027
+ rejection: false,
2028
+ state: PENDING,
2029
+ value: undefined
2030
+ });
2031
+ };
2032
+ Internal.prototype = redefineAll(PromiseConstructor.prototype, {
2033
+ // `Promise.prototype.then` method
2034
+ // https://tc39.github.io/ecma262/#sec-promise.prototype.then
2035
+ then: function then(onFulfilled, onRejected) {
2036
+ var state = getInternalPromiseState(this);
2037
+ var reaction = newPromiseCapability$1(speciesConstructor(this, PromiseConstructor));
2038
+ reaction.ok = typeof onFulfilled == 'function' ? onFulfilled : true;
2039
+ reaction.fail = typeof onRejected == 'function' && onRejected;
2040
+ reaction.domain = IS_NODE$1 ? process$3.domain : undefined;
2041
+ state.parent = true;
2042
+ state.reactions.push(reaction);
2043
+ if (state.state != PENDING) notify$1(this, state, false);
2044
+ return reaction.promise;
2045
+ },
2046
+ // `Promise.prototype.catch` method
2047
+ // https://tc39.github.io/ecma262/#sec-promise.prototype.catch
2048
+ 'catch': function (onRejected) {
2049
+ return this.then(undefined, onRejected);
2050
+ }
2051
+ });
2052
+ OwnPromiseCapability = function () {
2053
+ var promise = new Internal();
2054
+ var state = getInternalState$2(promise);
2055
+ this.promise = promise;
2056
+ this.resolve = bind(internalResolve, promise, state);
2057
+ this.reject = bind(internalReject, promise, state);
2058
+ };
2059
+ newPromiseCapability.f = newPromiseCapability$1 = function (C) {
2060
+ return C === PromiseConstructor || C === PromiseWrapper
2061
+ ? new OwnPromiseCapability(C)
2062
+ : newGenericPromiseCapability(C);
2063
+ };
2064
+
2065
+ if ( typeof nativePromiseConstructor == 'function') {
2066
+ nativeThen = nativePromiseConstructor.prototype.then;
2067
+
2068
+ // wrap native Promise#then for native async functions
2069
+ redefine(nativePromiseConstructor.prototype, 'then', function then(onFulfilled, onRejected) {
2070
+ var that = this;
2071
+ return new PromiseConstructor(function (resolve, reject) {
2072
+ nativeThen.call(that, resolve, reject);
2073
+ }).then(onFulfilled, onRejected);
2074
+ // https://github.com/zloirock/core-js/issues/640
2075
+ }, { unsafe: true });
2076
+
2077
+ // wrap fetch result
2078
+ if (typeof $fetch == 'function') _export({ global: true, enumerable: true, forced: true }, {
2079
+ // eslint-disable-next-line no-unused-vars
2080
+ fetch: function fetch(input /* , init */) {
2081
+ return promiseResolve(PromiseConstructor, $fetch.apply(global_1, arguments));
2082
+ }
2083
+ });
2084
+ }
2085
+ }
2086
+
2087
+ _export({ global: true, wrap: true, forced: FORCED }, {
2088
+ Promise: PromiseConstructor
2089
+ });
2090
+
2091
+ setToStringTag(PromiseConstructor, PROMISE, false);
2092
+ setSpecies(PROMISE);
2093
+
2094
+ PromiseWrapper = getBuiltIn(PROMISE);
2095
+
2096
+ // statics
2097
+ _export({ target: PROMISE, stat: true, forced: FORCED }, {
2098
+ // `Promise.reject` method
2099
+ // https://tc39.github.io/ecma262/#sec-promise.reject
2100
+ reject: function reject(r) {
2101
+ var capability = newPromiseCapability$1(this);
2102
+ capability.reject.call(undefined, r);
2103
+ return capability.promise;
2104
+ }
2105
+ });
2106
+
2107
+ _export({ target: PROMISE, stat: true, forced: FORCED }, {
2108
+ // `Promise.resolve` method
2109
+ // https://tc39.github.io/ecma262/#sec-promise.resolve
2110
+ resolve: function resolve(x) {
2111
+ return promiseResolve( this, x);
2112
+ }
2113
+ });
2114
+
2115
+ _export({ target: PROMISE, stat: true, forced: INCORRECT_ITERATION }, {
2116
+ // `Promise.all` method
2117
+ // https://tc39.github.io/ecma262/#sec-promise.all
2118
+ all: function all(iterable) {
2119
+ var C = this;
2120
+ var capability = newPromiseCapability$1(C);
2121
+ var resolve = capability.resolve;
2122
+ var reject = capability.reject;
2123
+ var result = perform(function () {
2124
+ var $promiseResolve = aFunction$1(C.resolve);
2125
+ var values = [];
2126
+ var counter = 0;
2127
+ var remaining = 1;
2128
+ iterate_1(iterable, function (promise) {
2129
+ var index = counter++;
2130
+ var alreadyCalled = false;
2131
+ values.push(undefined);
2132
+ remaining++;
2133
+ $promiseResolve.call(C, promise).then(function (value) {
2134
+ if (alreadyCalled) return;
2135
+ alreadyCalled = true;
2136
+ values[index] = value;
2137
+ --remaining || resolve(values);
2138
+ }, reject);
2139
+ });
2140
+ --remaining || resolve(values);
2141
+ });
2142
+ if (result.error) reject(result.value);
2143
+ return capability.promise;
2144
+ },
2145
+ // `Promise.race` method
2146
+ // https://tc39.github.io/ecma262/#sec-promise.race
2147
+ race: function race(iterable) {
2148
+ var C = this;
2149
+ var capability = newPromiseCapability$1(C);
2150
+ var reject = capability.reject;
2151
+ var result = perform(function () {
2152
+ var $promiseResolve = aFunction$1(C.resolve);
2153
+ iterate_1(iterable, function (promise) {
2154
+ $promiseResolve.call(C, promise).then(capability.resolve, reject);
2155
+ });
2156
+ });
2157
+ if (result.error) reject(result.value);
2158
+ return capability.promise;
2159
+ }
2160
+ });
2161
+
2162
+ // `Promise.allSettled` method
2163
+ // https://github.com/tc39/proposal-promise-allSettled
2164
+ _export({ target: 'Promise', stat: true }, {
2165
+ allSettled: function allSettled(iterable) {
2166
+ var C = this;
2167
+ var capability = newPromiseCapability.f(C);
2168
+ var resolve = capability.resolve;
2169
+ var reject = capability.reject;
2170
+ var result = perform(function () {
2171
+ var promiseResolve = aFunction$1(C.resolve);
2172
+ var values = [];
2173
+ var counter = 0;
2174
+ var remaining = 1;
2175
+ iterate_1(iterable, function (promise) {
2176
+ var index = counter++;
2177
+ var alreadyCalled = false;
2178
+ values.push(undefined);
2179
+ remaining++;
2180
+ promiseResolve.call(C, promise).then(function (value) {
2181
+ if (alreadyCalled) return;
2182
+ alreadyCalled = true;
2183
+ values[index] = { status: 'fulfilled', value: value };
2184
+ --remaining || resolve(values);
2185
+ }, function (e) {
2186
+ if (alreadyCalled) return;
2187
+ alreadyCalled = true;
2188
+ values[index] = { status: 'rejected', reason: e };
2189
+ --remaining || resolve(values);
2190
+ });
2191
+ });
2192
+ --remaining || resolve(values);
2193
+ });
2194
+ if (result.error) reject(result.value);
2195
+ return capability.promise;
2196
+ }
2197
+ });
2198
+
2199
+ // Safari bug https://bugs.webkit.org/show_bug.cgi?id=200829
2200
+ var NON_GENERIC = !!nativePromiseConstructor && fails(function () {
2201
+ nativePromiseConstructor.prototype['finally'].call({ then: function () { /* empty */ } }, function () { /* empty */ });
2202
+ });
2203
+
2204
+ // `Promise.prototype.finally` method
2205
+ // https://tc39.github.io/ecma262/#sec-promise.prototype.finally
2206
+ _export({ target: 'Promise', proto: true, real: true, forced: NON_GENERIC }, {
2207
+ 'finally': function (onFinally) {
2208
+ var C = speciesConstructor(this, getBuiltIn('Promise'));
2209
+ var isFunction = typeof onFinally == 'function';
2210
+ return this.then(
2211
+ isFunction ? function (x) {
2212
+ return promiseResolve(C, onFinally()).then(function () { return x; });
2213
+ } : onFinally,
2214
+ isFunction ? function (e) {
2215
+ return promiseResolve(C, onFinally()).then(function () { throw e; });
2216
+ } : onFinally
2217
+ );
2218
+ }
2219
+ });
2220
+
2221
+ // patch native Promise.prototype for native async functions
2222
+ if ( typeof nativePromiseConstructor == 'function' && !nativePromiseConstructor.prototype['finally']) {
2223
+ redefine(nativePromiseConstructor.prototype, 'finally', getBuiltIn('Promise').prototype['finally']);
2224
+ }
2225
+
2226
+ var promise$1 = path.Promise;
2227
+
2228
+ var setInternalState$3 = internalState.set;
2229
+ var getInternalAggregateErrorState = internalState.getterFor('AggregateError');
2230
+
2231
+ var $AggregateError = function AggregateError(errors, message) {
2232
+ var that = this;
2233
+ if (!(that instanceof $AggregateError)) return new $AggregateError(errors, message);
2234
+ if (objectSetPrototypeOf) {
2235
+ that = objectSetPrototypeOf(new Error(message), objectGetPrototypeOf(that));
2236
+ }
2237
+ var errorsArray = [];
2238
+ iterate_1(errors, errorsArray.push, errorsArray);
2239
+ if (descriptors) setInternalState$3(that, { errors: errorsArray, type: 'AggregateError' });
2240
+ else that.errors = errorsArray;
2241
+ if (message !== undefined) createNonEnumerableProperty(that, 'message', String(message));
2242
+ return that;
2243
+ };
2244
+
2245
+ $AggregateError.prototype = objectCreate(Error.prototype, {
2246
+ constructor: createPropertyDescriptor(5, $AggregateError),
2247
+ message: createPropertyDescriptor(5, ''),
2248
+ name: createPropertyDescriptor(5, 'AggregateError')
2249
+ });
2250
+
2251
+ if (descriptors) objectDefineProperty.f($AggregateError.prototype, 'errors', {
2252
+ get: function () {
2253
+ return getInternalAggregateErrorState(this).errors;
2254
+ },
2255
+ configurable: true
2256
+ });
2257
+
2258
+ _export({ global: true }, {
2259
+ AggregateError: $AggregateError
2260
+ });
2261
+
2262
+ // `Promise.try` method
2263
+ // https://github.com/tc39/proposal-promise-try
2264
+ _export({ target: 'Promise', stat: true }, {
2265
+ 'try': function (callbackfn) {
2266
+ var promiseCapability = newPromiseCapability.f(this);
2267
+ var result = perform(callbackfn);
2268
+ (result.error ? promiseCapability.reject : promiseCapability.resolve)(result.value);
2269
+ return promiseCapability.promise;
2270
+ }
2271
+ });
2272
+
2273
+ var PROMISE_ANY_ERROR = 'No one promise resolved';
2274
+
2275
+ // `Promise.any` method
2276
+ // https://github.com/tc39/proposal-promise-any
2277
+ _export({ target: 'Promise', stat: true }, {
2278
+ any: function any(iterable) {
2279
+ var C = this;
2280
+ var capability = newPromiseCapability.f(C);
2281
+ var resolve = capability.resolve;
2282
+ var reject = capability.reject;
2283
+ var result = perform(function () {
2284
+ var promiseResolve = aFunction$1(C.resolve);
2285
+ var errors = [];
2286
+ var counter = 0;
2287
+ var remaining = 1;
2288
+ var alreadyResolved = false;
2289
+ iterate_1(iterable, function (promise) {
2290
+ var index = counter++;
2291
+ var alreadyRejected = false;
2292
+ errors.push(undefined);
2293
+ remaining++;
2294
+ promiseResolve.call(C, promise).then(function (value) {
2295
+ if (alreadyRejected || alreadyResolved) return;
2296
+ alreadyResolved = true;
2297
+ resolve(value);
2298
+ }, function (e) {
2299
+ if (alreadyRejected || alreadyResolved) return;
2300
+ alreadyRejected = true;
2301
+ errors[index] = e;
2302
+ --remaining || reject(new (getBuiltIn('AggregateError'))(errors, PROMISE_ANY_ERROR));
2303
+ });
2304
+ });
2305
+ --remaining || reject(new (getBuiltIn('AggregateError'))(errors, PROMISE_ANY_ERROR));
2306
+ });
2307
+ if (result.error) reject(result.value);
2308
+ return capability.promise;
2309
+ }
2310
+ });
2311
+
2312
+ /**
2313
+ * Default values for all Dinero objects.
2314
+ *
2315
+ * You can override default values for all subsequent Dinero objects by changing them directly on the global `Dinero` object.
2316
+ * Existing instances won't be affected.
2317
+ *
2318
+ * @property {Number} defaultAmount - The default amount for new Dinero objects (see {@link module:Dinero Dinero} for format).
2319
+ * @property {String} defaultCurrency - The default currency for new Dinero objects (see {@link module:Dinero Dinero} for format).
2320
+ * @property {Number} defaultPrecision - The default precision for new Dinero objects (see {@link module:Dinero Dinero} for format).
2321
+ *
2322
+ * @example
2323
+ * // Will set currency to 'EUR' for all Dinero objects.
2324
+ * Dinero.defaultCurrency = 'EUR'
2325
+ *
2326
+ * @type {Object}
2327
+ */
2328
+ var Defaults = {
2329
+ defaultAmount: 0,
2330
+ defaultCurrency: 'USD',
2331
+ defaultPrecision: 2
2332
+ };
2333
+ /**
2334
+ * Global settings for all Dinero objects.
2335
+ *
2336
+ * You can override global values for all subsequent Dinero objects by changing them directly on the global `Dinero` object.
2337
+ * Existing instances won't be affected.
2338
+ *
2339
+ * @property {String} globalLocale - The global locale for new Dinero objects (see {@link module:Dinero~setLocale setLocale} for format).
2340
+ * @property {String} globalFormat - The global format for new Dinero objects (see {@link module:Dinero~toFormat toFormat} for format).
2341
+ * @property {String} globalRoundingMode - The global rounding mode for new Dinero objects (see {@link module:Dinero~multiply multiply} or {@link module:Dinero~divide divide} for format).
2342
+ * @property {String} globalFormatRoundingMode - The global rounding mode to format new Dinero objects (see {@link module:Dinero~toFormat toFormat} or {@link module:Dinero~toRoundedUnit toRoundedUnit} for format).
2343
+ * @property {(String|Promise)} globalExchangeRatesApi.endpoint - The global exchange rate API endpoint for new Dinero objects, or the global promise that resolves to the exchanges rates (see {@link module:Dinero~convert convert} for format).
2344
+ * @property {String} globalExchangeRatesApi.propertyPath - The global exchange rate API property path for new Dinero objects (see {@link module:Dinero~convert convert} for format).
2345
+ * @property {Object} globalExchangeRatesApi.headers - The global exchange rate API headers for new Dinero objects (see {@link module:Dinero~convert convert} for format).
2346
+ *
2347
+ * @example
2348
+ * // Will set locale to 'fr-FR' for all Dinero objects.
2349
+ * Dinero.globalLocale = 'fr-FR'
2350
+ * @example
2351
+ * // Will set global exchange rate API parameters for all Dinero objects.
2352
+ * Dinero.globalExchangeRatesApi = {
2353
+ * endpoint: 'https://yourexchangerates.api/latest?base={{from}}',
2354
+ * propertyPath: 'data.rates.{{to}}',
2355
+ * headers: {
2356
+ * 'user-key': 'xxxxxxxxx'
2357
+ * }
2358
+ * }
2359
+ *
2360
+ * @type {Object}
2361
+ */
2362
+
2363
+ var Globals = {
2364
+ globalLocale: 'en-US',
2365
+ globalFormat: '$0,0.00',
2366
+ globalRoundingMode: 'HALF_EVEN',
2367
+ globalFormatRoundingMode: 'HALF_AWAY_FROM_ZERO',
2368
+ globalExchangeRatesApi: {
2369
+ endpoint: undefined,
2370
+ headers: undefined,
2371
+ propertyPath: undefined
2372
+ }
2373
+ };
2374
+
2375
+ function _typeof(obj) {
2376
+ "@babel/helpers - typeof";
2377
+
2378
+ if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
2379
+ _typeof = function (obj) {
2380
+ return typeof obj;
2381
+ };
2382
+ } else {
2383
+ _typeof = function (obj) {
2384
+ return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
2385
+ };
2386
+ }
2387
+
2388
+ return _typeof(obj);
2389
+ }
2390
+
2391
+ function _toArray(arr) {
2392
+ return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest();
2393
+ }
2394
+
2395
+ function _arrayWithHoles(arr) {
2396
+ if (Array.isArray(arr)) return arr;
2397
+ }
2398
+
2399
+ function _iterableToArray(iter) {
2400
+ if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
2401
+ }
2402
+
2403
+ function _unsupportedIterableToArray(o, minLen) {
2404
+ if (!o) return;
2405
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
2406
+ var n = Object.prototype.toString.call(o).slice(8, -1);
2407
+ if (n === "Object" && o.constructor) n = o.constructor.name;
2408
+ if (n === "Map" || n === "Set") return Array.from(o);
2409
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
2410
+ }
2411
+
2412
+ function _arrayLikeToArray(arr, len) {
2413
+ if (len == null || len > arr.length) len = arr.length;
2414
+
2415
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
2416
+
2417
+ return arr2;
2418
+ }
2419
+
2420
+ function _nonIterableRest() {
2421
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
2422
+ }
2423
+
2424
+ /**
2425
+ * Static methods for Dinero.
2426
+ * @ignore
2427
+ *
2428
+ * @type {Object}
2429
+ */
2430
+ var Static = {
2431
+ /**
2432
+ * Returns an array of Dinero objects, normalized to the same precision (the highest).
2433
+ *
2434
+ * @memberof module:Dinero
2435
+ * @method
2436
+ *
2437
+ * @param {Dinero[]} objects - An array of Dinero objects
2438
+ *
2439
+ * @example
2440
+ * // returns an array of Dinero objects
2441
+ * // both with a precision of 3
2442
+ * // and an amount of 1000
2443
+ * Dinero.normalizePrecision([
2444
+ * Dinero({ amount: 100, precision: 2 }),
2445
+ * Dinero({ amount: 1000, precision: 3 })
2446
+ * ])
2447
+ *
2448
+ * @return {Dinero[]}
2449
+ */
2450
+ normalizePrecision: function normalizePrecision(objects) {
2451
+ var highestPrecision = objects.reduce(function (a, b) {
2452
+ return Math.max(a.getPrecision(), b.getPrecision());
2453
+ });
2454
+ return objects.map(function (object) {
2455
+ return object.getPrecision() !== highestPrecision ? object.convertPrecision(highestPrecision) : object;
2456
+ });
2457
+ },
2458
+
2459
+ /**
2460
+ * Returns the smallest Dinero object from an array of Dinero objects
2461
+ *
2462
+ * @memberof module:Dinero
2463
+ * @method
2464
+ *
2465
+ * @param {Dinero[]} objects - An array of Dinero objects
2466
+ *
2467
+ * @example
2468
+ * // returns the smallest Dinero object with amount of 500 from an array of Dinero objects with different precisions
2469
+ * Dinero.minimum([
2470
+ * Dinero({ amount: 500, precision: 3 }),
2471
+ * Dinero({ amount: 100, precision: 2 })
2472
+ * ])
2473
+ * @example
2474
+ * // returns the smallest Dinero object with amount of 50 from an array of Dinero objects
2475
+ * Dinero.minimum([
2476
+ * Dinero({ amount: 50 }),
2477
+ * Dinero({ amount: 100 })
2478
+ * ])
2479
+ *
2480
+ * @return {Dinero[]}
2481
+ */
2482
+ minimum: function minimum(objects) {
2483
+ var _objects = _toArray(objects),
2484
+ firstObject = _objects[0],
2485
+ tailObjects = _objects.slice(1);
2486
+
2487
+ var currentMinimum = firstObject;
2488
+ tailObjects.forEach(function (obj) {
2489
+ currentMinimum = currentMinimum.lessThan(obj) ? currentMinimum : obj;
2490
+ });
2491
+ return currentMinimum;
2492
+ },
2493
+
2494
+ /**
2495
+ * Returns the biggest Dinero object from an array of Dinero objects
2496
+ *
2497
+ * @memberof module:Dinero
2498
+ * @method
2499
+ *
2500
+ * @param {Dinero[]} objects - An array of Dinero objects
2501
+ *
2502
+ * @example
2503
+ * // returns the biggest Dinero object with amount of 20, from an array of Dinero objects with different precisions
2504
+ * Dinero.maximum([
2505
+ * Dinero({ amount: 20, precision: 2 }),
2506
+ * Dinero({ amount: 150, precision: 3 })
2507
+ * ])
2508
+ * @example
2509
+ * // returns the biggest Dinero object with amount of 100, from an array of Dinero objects
2510
+ * Dinero.maximum([
2511
+ * Dinero({ amount: 100 }),
2512
+ * Dinero({ amount: 50 })
2513
+ * ])
2514
+ *
2515
+ * @return {Dinero[]}
2516
+ */
2517
+ maximum: function maximum(objects) {
2518
+ var _objects2 = _toArray(objects),
2519
+ firstObject = _objects2[0],
2520
+ tailObjects = _objects2.slice(1);
2521
+
2522
+ var currentMaximum = firstObject;
2523
+ tailObjects.forEach(function (obj) {
2524
+ currentMaximum = currentMaximum.greaterThan(obj) ? currentMaximum : obj;
2525
+ });
2526
+ return currentMaximum;
2527
+ }
2528
+ };
2529
+
2530
+ /**
2531
+ * Returns whether a value is numeric.
2532
+ * @ignore
2533
+ *
2534
+ * @param {} value - The value to test.
2535
+ *
2536
+ * @return {Boolean}
2537
+ */
2538
+ function isNumeric(value) {
2539
+ return !isNaN(parseInt(value)) && isFinite(value);
2540
+ }
2541
+ /**
2542
+ * Returns whether a value is a percentage.
2543
+ * @ignore
2544
+ *
2545
+ * @param {} percentage - The percentage to test.
2546
+ *
2547
+ * @return {Boolean}
2548
+ */
2549
+
2550
+ function isPercentage(percentage) {
2551
+ return isNumeric(percentage) && percentage <= 100 && percentage >= 0;
2552
+ }
2553
+ /**
2554
+ * Returns whether an array of ratios is valid.
2555
+ * @ignore
2556
+ *
2557
+ * @param {} ratios - The ratios to test.
2558
+ *
2559
+ * @return {Boolean}
2560
+ */
2561
+
2562
+ function areValidRatios(ratios) {
2563
+ return ratios.length > 0 && ratios.every(function (ratio) {
2564
+ return ratio >= 0;
2565
+ }) && ratios.some(function (ratio) {
2566
+ return ratio > 0;
2567
+ });
2568
+ }
2569
+ /**
2570
+ * Returns whether a value is even.
2571
+ * @ignore
2572
+ *
2573
+ * @param {Number} value - The value to test.
2574
+ *
2575
+ * @return {Boolean}
2576
+ */
2577
+
2578
+ function isEven(value) {
2579
+ return value % 2 === 0;
2580
+ }
2581
+ /**
2582
+ * Returns whether a value is a float.
2583
+ * @ignore
2584
+ *
2585
+ * @param {} value - The value to test.
2586
+ *
2587
+ * @return {Boolean}
2588
+ */
2589
+
2590
+ function isFloat(value) {
2591
+ return isNumeric(value) && !Number.isInteger(value);
2592
+ }
2593
+ /**
2594
+ * Returns how many fraction digits a number has.
2595
+ * @ignore
2596
+ *
2597
+ * @param {Number} [number=0] - The number to test.
2598
+ *
2599
+ * @return {Number}
2600
+ */
2601
+
2602
+ function countFractionDigits() {
2603
+ var number = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
2604
+ var stringRepresentation = number.toString();
2605
+
2606
+ if (stringRepresentation.indexOf('e-') > 0) {
2607
+ // It's too small for a normal string representation, e.g. 1e-7 instead of 0.00000001
2608
+ return parseInt(stringRepresentation.split('e-')[1]);
2609
+ } else {
2610
+ var fractionDigits = stringRepresentation.split('.')[1];
2611
+ return fractionDigits ? fractionDigits.length : 0;
2612
+ }
2613
+ }
2614
+ /**
2615
+ * Returns whether a number is half.
2616
+ * @ignore
2617
+ *
2618
+ * @param {Number} number - The number to test.
2619
+ *
2620
+ * @return {Number}
2621
+ */
2622
+
2623
+ function isHalf(number) {
2624
+ return Math.abs(number) % 1 === 0.5;
2625
+ }
2626
+ /**
2627
+ * Fetches a JSON resource.
2628
+ * @ignore
2629
+ *
2630
+ * @param {String} url - The resource to fetch.
2631
+ * @param {Object} [options.headers] - The headers to pass.
2632
+ *
2633
+ * @throws {Error} If `request.status` is lesser than 200 or greater or equal to 400.
2634
+ * @throws {Error} If network fails.
2635
+ *
2636
+ * @return {JSON}
2637
+ */
2638
+
2639
+ function getJSON(url) {
2640
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2641
+ return new Promise(function (resolve, reject) {
2642
+ var request = Object.assign(new XMLHttpRequest(), {
2643
+ onreadystatechange: function onreadystatechange() {
2644
+ if (request.readyState === 4) {
2645
+ if (request.status >= 200 && request.status < 400) resolve(JSON.parse(request.responseText));else reject(new Error(request.statusText));
2646
+ }
2647
+ },
2648
+ onerror: function onerror() {
2649
+ reject(new Error('Network error'));
2650
+ }
2651
+ });
2652
+ request.open('GET', url, true);
2653
+ setXHRHeaders(request, options.headers);
2654
+ request.send();
2655
+ });
2656
+ }
2657
+ /**
2658
+ * Returns an XHR object with attached headers.
2659
+ * @ignore
2660
+ *
2661
+ * @param {XMLHttpRequest} xhr - The XHR request to set headers to.
2662
+ * @param {Object} headers - The headers to set.
2663
+ *
2664
+ * @return {XMLHttpRequest}
2665
+ */
2666
+
2667
+ function setXHRHeaders(xhr) {
2668
+ var headers = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2669
+
2670
+ for (var header in headers) {
2671
+ xhr.setRequestHeader(header, headers[header]);
2672
+ }
2673
+
2674
+ return xhr;
2675
+ }
2676
+ /**
2677
+ * Returns whether a value is undefined.
2678
+ * @ignore
2679
+ *
2680
+ * @param {} value - The value to test.
2681
+ *
2682
+ * @return {Boolean}
2683
+ */
2684
+
2685
+ function isUndefined(value) {
2686
+ return typeof value === 'undefined';
2687
+ }
2688
+ /**
2689
+ * Returns an object flattened to one level deep.
2690
+ * @ignore
2691
+ *
2692
+ * @param {Object} object - The object to flatten.
2693
+ * @param {String} separator - The separator to use between flattened nodes.
2694
+ *
2695
+ * @return {Object}
2696
+ */
2697
+
2698
+ function flattenObject(object) {
2699
+ var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '.';
2700
+ var finalObject = {};
2701
+ Object.entries(object).forEach(function (item) {
2702
+ if (_typeof(item[1]) === 'object') {
2703
+ var flatObject = flattenObject(item[1]);
2704
+ Object.entries(flatObject).forEach(function (node) {
2705
+ finalObject[item[0] + separator + node[0]] = node[1];
2706
+ });
2707
+ } else {
2708
+ finalObject[item[0]] = item[1];
2709
+ }
2710
+ });
2711
+ return finalObject;
2712
+ }
2713
+ /**
2714
+ * Returns whether a value is thenable.
2715
+ * @ignore
2716
+ *
2717
+ * @param {} value - The value to test.
2718
+ *
2719
+ * @return {Boolean}
2720
+ */
2721
+
2722
+ function isThenable$1(value) {
2723
+ return Boolean(value) && (_typeof(value) === 'object' || typeof value === 'function') && typeof value.then === 'function';
2724
+ }
2725
+
2726
+ function Calculator() {
2727
+ var floatMultiply = function floatMultiply(a, b) {
2728
+ var getFactor = function getFactor(number) {
2729
+ return Math.pow(10, countFractionDigits(number));
2730
+ };
2731
+
2732
+ var factor = Math.max(getFactor(a), getFactor(b));
2733
+ return Math.round(a * factor) * Math.round(b * factor) / (factor * factor);
2734
+ };
2735
+
2736
+ var roundingModes = {
2737
+ HALF_ODD: function HALF_ODD(number) {
2738
+ var rounded = Math.round(number);
2739
+ return isHalf(number) ? isEven(rounded) ? rounded - 1 : rounded : rounded;
2740
+ },
2741
+ HALF_EVEN: function HALF_EVEN(number) {
2742
+ var rounded = Math.round(number);
2743
+ return isHalf(number) ? isEven(rounded) ? rounded : rounded - 1 : rounded;
2744
+ },
2745
+ HALF_UP: function HALF_UP(number) {
2746
+ return Math.round(number);
2747
+ },
2748
+ HALF_DOWN: function HALF_DOWN(number) {
2749
+ return isHalf(number) ? Math.floor(number) : Math.round(number);
2750
+ },
2751
+ HALF_TOWARDS_ZERO: function HALF_TOWARDS_ZERO(number) {
2752
+ return isHalf(number) ? Math.sign(number) * Math.floor(Math.abs(number)) : Math.round(number);
2753
+ },
2754
+ HALF_AWAY_FROM_ZERO: function HALF_AWAY_FROM_ZERO(number) {
2755
+ return isHalf(number) ? Math.sign(number) * Math.ceil(Math.abs(number)) : Math.round(number);
2756
+ },
2757
+ DOWN: function DOWN(number) {
2758
+ return Math.floor(number);
2759
+ }
2760
+ };
2761
+ return {
2762
+ /**
2763
+ * Returns the sum of two numbers.
2764
+ * @ignore
2765
+ *
2766
+ * @param {Number} a - The first number to add.
2767
+ * @param {Number} b - The second number to add.
2768
+ *
2769
+ * @return {Number}
2770
+ */
2771
+ add: function add(a, b) {
2772
+ return a + b;
2773
+ },
2774
+
2775
+ /**
2776
+ * Returns the difference of two numbers.
2777
+ * @ignore
2778
+ *
2779
+ * @param {Number} a - The first number to subtract.
2780
+ * @param {Number} b - The second number to subtract.
2781
+ *
2782
+ * @return {Number}
2783
+ */
2784
+ subtract: function subtract(a, b) {
2785
+ return a - b;
2786
+ },
2787
+
2788
+ /**
2789
+ * Returns the product of two numbers.
2790
+ * @ignore
2791
+ *
2792
+ * @param {Number} a - The first number to multiply.
2793
+ * @param {Number} b - The second number to multiply.
2794
+ *
2795
+ * @return {Number}
2796
+ */
2797
+ multiply: function multiply(a, b) {
2798
+ return isFloat(a) || isFloat(b) ? floatMultiply(a, b) : a * b;
2799
+ },
2800
+
2801
+ /**
2802
+ * Returns the quotient of two numbers.
2803
+ * @ignore
2804
+ *
2805
+ * @param {Number} a - The first number to divide.
2806
+ * @param {Number} b - The second number to divide.
2807
+ *
2808
+ * @return {Number}
2809
+ */
2810
+ divide: function divide(a, b) {
2811
+ return a / b;
2812
+ },
2813
+
2814
+ /**
2815
+ * Returns the remainder of two numbers.
2816
+ * @ignore
2817
+ *
2818
+ * @param {Number} a - The first number to divide.
2819
+ * @param {Number} b - The second number to divide.
2820
+ *
2821
+ * @return {Number}
2822
+ */
2823
+ modulo: function modulo(a, b) {
2824
+ return a % b;
2825
+ },
2826
+
2827
+ /**
2828
+ * Returns a rounded number based off a specific rounding mode.
2829
+ * @ignore
2830
+ *
2831
+ * @param {Number} number - The number to round.
2832
+ * @param {String} [roundingMode='HALF_EVEN'] - The rounding mode to use.
2833
+ *
2834
+ * @returns {Number}
2835
+ */
2836
+ round: function round(number) {
2837
+ var roundingMode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'HALF_EVEN';
2838
+ return roundingModes[roundingMode](number);
2839
+ }
2840
+ };
2841
+ }
2842
+
2843
+ var calculator = Calculator();
2844
+ function Format(format) {
2845
+ var matches = /^(?:(\$|USD)?0(?:(,)0)?(\.)?(0+)?|0(?:(,)0)?(\.)?(0+)?\s?(dollar)?)$/gm.exec(format);
2846
+ return {
2847
+ /**
2848
+ * Returns the matches.
2849
+ * @ignore
2850
+ *
2851
+ * @return {Array}
2852
+ */
2853
+ getMatches: function getMatches() {
2854
+ return matches !== null ? matches.slice(1).filter(function (match) {
2855
+ return !isUndefined(match);
2856
+ }) : [];
2857
+ },
2858
+
2859
+ /**
2860
+ * Returns the amount of fraction digits to display.
2861
+ * @ignore
2862
+ *
2863
+ * @return {Number}
2864
+ */
2865
+ getMinimumFractionDigits: function getMinimumFractionDigits() {
2866
+ var decimalPosition = function decimalPosition(match) {
2867
+ return match === '.';
2868
+ };
2869
+
2870
+ return !isUndefined(this.getMatches().find(decimalPosition)) ? this.getMatches()[calculator.add(this.getMatches().findIndex(decimalPosition), 1)].split('').length : 0;
2871
+ },
2872
+
2873
+ /**
2874
+ * Returns the currency display mode.
2875
+ * @ignore
2876
+ *
2877
+ * @return {String}
2878
+ */
2879
+ getCurrencyDisplay: function getCurrencyDisplay() {
2880
+ var modes = {
2881
+ USD: 'code',
2882
+ dollar: 'name',
2883
+ $: 'symbol'
2884
+ };
2885
+ return modes[this.getMatches().find(function (match) {
2886
+ return match === 'USD' || match === 'dollar' || match === '$';
2887
+ })];
2888
+ },
2889
+
2890
+ /**
2891
+ * Returns the formatting style.
2892
+ * @ignore
2893
+ *
2894
+ * @return {String}
2895
+ */
2896
+ getStyle: function getStyle() {
2897
+ return !isUndefined(this.getCurrencyDisplay(this.getMatches())) ? 'currency' : 'decimal';
2898
+ },
2899
+
2900
+ /**
2901
+ * Returns whether grouping should be used or not.
2902
+ * @ignore
2903
+ *
2904
+ * @return {Boolean}
2905
+ */
2906
+ getUseGrouping: function getUseGrouping() {
2907
+ return !isUndefined(this.getMatches().find(function (match) {
2908
+ return match === ',';
2909
+ }));
2910
+ }
2911
+ };
2912
+ }
2913
+
2914
+ function CurrencyConverter(options) {
2915
+ /* istanbul ignore next */
2916
+ var mergeTags = function mergeTags() {
2917
+ var string = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
2918
+ var tags = arguments.length > 1 ? arguments[1] : undefined;
2919
+
2920
+ for (var tag in tags) {
2921
+ string = string.replace("{{".concat(tag, "}}"), tags[tag]);
2922
+ }
2923
+
2924
+ return string;
2925
+ };
2926
+ /* istanbul ignore next */
2927
+
2928
+
2929
+ var getRatesFromRestApi = function getRatesFromRestApi(from, to) {
2930
+ return getJSON(mergeTags(options.endpoint, {
2931
+ from: from,
2932
+ to: to
2933
+ }), {
2934
+ headers: options.headers
2935
+ });
2936
+ };
2937
+
2938
+ return {
2939
+ /**
2940
+ * Returns the exchange rate.
2941
+ * @ignore
2942
+ *
2943
+ * @param {String} from - The base currency.
2944
+ * @param {String} to - The destination currency.
2945
+ *
2946
+ * @return {Promise}
2947
+ */
2948
+ getExchangeRate: function getExchangeRate(from, to) {
2949
+ return (isThenable$1(options.endpoint) ? options.endpoint : getRatesFromRestApi(from, to)).then(function (data) {
2950
+ return flattenObject(data)[mergeTags(options.propertyPath, {
2951
+ from: from,
2952
+ to: to
2953
+ })];
2954
+ });
2955
+ }
2956
+ };
2957
+ }
2958
+
2959
+ /**
2960
+ * Performs an assertion.
2961
+ * @ignore
2962
+ *
2963
+ * @param {Boolean} condition - The expression to assert.
2964
+ * @param {String} errorMessage - The message to throw if the assertion fails
2965
+ * @param {ErrorConstructor} [ErrorType=Error] - The error to throw if the assertion fails.
2966
+ *
2967
+ * @throws {Error} If `condition` returns `false`.
2968
+ */
2969
+
2970
+ function assert(condition, errorMessage) {
2971
+ var ErrorType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Error;
2972
+ if (!condition) throw new ErrorType(errorMessage);
2973
+ }
2974
+ /**
2975
+ * Asserts a value is a percentage.
2976
+ * @ignore
2977
+ *
2978
+ * @param {} percentage - The percentage to test.
2979
+ *
2980
+ * @throws {RangeError} If `percentage` is out of range.
2981
+ */
2982
+
2983
+ function assertPercentage(percentage) {
2984
+ assert(isPercentage(percentage), 'You must provide a numeric value between 0 and 100.', RangeError);
2985
+ }
2986
+ /**
2987
+ * Asserts an array of ratios is valid.
2988
+ * @ignore
2989
+ *
2990
+ * @param {} ratios - The ratios to test.
2991
+ *
2992
+ * @throws {TypeError} If `ratios` are invalid.
2993
+ */
2994
+
2995
+ function assertValidRatios(ratios) {
2996
+ assert(areValidRatios(ratios), 'You must provide a non-empty array of numeric values greater than 0.', TypeError);
2997
+ }
2998
+ /**
2999
+ * Asserts a value is an integer.
3000
+ * @ignore
3001
+ *
3002
+ * @param {} number - The value to test.
3003
+ *
3004
+ * @throws {TypeError}
3005
+ */
3006
+
3007
+ function assertInteger(number) {
3008
+ assert(Number.isInteger(number), 'You must provide an integer.', TypeError);
3009
+ }
3010
+
3011
+ var calculator$1 = Calculator();
3012
+ /**
3013
+ * A Dinero object is an immutable data structure representing a specific monetary value.
3014
+ * It comes with methods for creating, parsing, manipulating, testing, transforming and formatting them.
3015
+ *
3016
+ * A Dinero object has:
3017
+ *
3018
+ * * An `amount`, expressed in minor currency units, as an integer.
3019
+ * * A `currency`, expressed as an {@link https://en.wikipedia.org/wiki/ISO_4217#Active_codes ISO 4217 currency code}.
3020
+ * * A `precision`, expressed as an integer, to represent the number of decimal places in the `amount`.
3021
+ * This is helpful when you want to represent fractional minor currency units (e.g.: $10.4545).
3022
+ * You can also use it to represent a currency with a different [exponent](https://en.wikipedia.org/wiki/ISO_4217#Treatment_of_minor_currency_units_.28the_.22exponent.22.29) than `2` (e.g.: Iraqi dinar with 1000 fils in 1 dinar (exponent of `3`), Japanese yen with no sub-units (exponent of `0`)).
3023
+ * * An optional `locale` property that affects how output strings are formatted.
3024
+ *
3025
+ * Here's an overview of the public API:
3026
+ *
3027
+ * * **Access:** {@link module:Dinero~getAmount getAmount}, {@link module:Dinero~getCurrency getCurrency}, {@link module:Dinero~getLocale getLocale} and {@link module:Dinero~getPrecision getPrecision}.
3028
+ * * **Manipulation:** {@link module:Dinero~add add}, {@link module:Dinero~subtract subtract}, {@link module:Dinero~multiply multiply}, {@link module:Dinero~divide divide}, {@link module:Dinero~percentage percentage}, {@link module:Dinero~allocate allocate} and {@link module:Dinero~convert convert}.
3029
+ * * **Testing:** {@link module:Dinero~equalsTo equalsTo}, {@link module:Dinero~lessThan lessThan}, {@link module:Dinero~lessThanOrEqual lessThanOrEqual}, {@link module:Dinero~greaterThan greaterThan}, {@link module:Dinero~greaterThanOrEqual greaterThanOrEqual}, {@link module:Dinero~isZero isZero}, {@link module:Dinero~isPositive isPositive}, {@link module:Dinero~isNegative isNegative}, {@link module:Dinero~hasSubUnits hasSubUnits}, {@link module:Dinero~hasSameCurrency hasSameCurrency} and {@link module:Dinero~hasSameAmount hasSameAmount}.
3030
+ * * **Configuration:** {@link module:Dinero~setLocale setLocale}.
3031
+ * * **Conversion & formatting:** {@link module:Dinero~toFormat toFormat}, {@link module:Dinero~toUnit toUnit}, {@link module:Dinero~toRoundedUnit toRoundedUnit}, {@link module:Dinero~toObject toObject}, {@link module:Dinero~toJSON toJSON}, {@link module:Dinero~convertPrecision convertPrecision} and {@link module:Dinero.normalizePrecision normalizePrecision}.
3032
+ *
3033
+ * Dinero.js uses `number`s under the hood, so it's constrained by the [double-precision floating-point format](https://en.wikipedia.org/wiki/Double-precision_floating-point_format). Using values over [`Number.MAX_SAFE_INTEGER`](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Number/MAX_SAFE_INTEGER) or below [`Number.MIN_SAFE_INTEGER`](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Number/MIN_SAFE_INTEGER) will yield unpredictable results.
3034
+ * Same goes with performing calculations: once the internal `amount` value exceeds those limits, precision is no longer guaranteed.
3035
+ *
3036
+ * @module Dinero
3037
+ * @param {Number} [options.amount=0] - The amount in minor currency units (as an integer).
3038
+ * @param {String} [options.currency='USD'] - An ISO 4217 currency code.
3039
+ * @param {String} [options.precision=2] - The number of decimal places to represent.
3040
+ *
3041
+ * @throws {TypeError} If `amount` or `precision` is invalid. Integers over [`Number.MAX_SAFE_INTEGER`](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Number/MAX_SAFE_INTEGER) or below [`Number.MIN_SAFE_INTEGER`](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Number/MIN_SAFE_INTEGER) are considered valid, even though they can lead to imprecise amounts.
3042
+ *
3043
+ * @return {Object}
3044
+ */
3045
+
3046
+ var Dinero = function Dinero(options) {
3047
+ var _Object$assign = Object.assign({}, {
3048
+ amount: Dinero.defaultAmount,
3049
+ currency: Dinero.defaultCurrency,
3050
+ precision: Dinero.defaultPrecision
3051
+ }, options),
3052
+ amount = _Object$assign.amount,
3053
+ currency = _Object$assign.currency,
3054
+ precision = _Object$assign.precision;
3055
+
3056
+ assertInteger(amount);
3057
+ assertInteger(precision);
3058
+ var globalLocale = Dinero.globalLocale,
3059
+ globalFormat = Dinero.globalFormat,
3060
+ globalRoundingMode = Dinero.globalRoundingMode,
3061
+ globalFormatRoundingMode = Dinero.globalFormatRoundingMode;
3062
+ var globalExchangeRatesApi = Object.assign({}, Dinero.globalExchangeRatesApi);
3063
+ /**
3064
+ * Uses ES5 function notation so `this` can be passed through call, apply and bind
3065
+ * @ignore
3066
+ */
3067
+
3068
+ var create = function create(options) {
3069
+ var obj = Object.assign({}, Object.assign({}, {
3070
+ amount: amount,
3071
+ currency: currency,
3072
+ precision: precision
3073
+ }, options), Object.assign({}, {
3074
+ locale: this.locale
3075
+ }, options));
3076
+ return Object.assign(Dinero({
3077
+ amount: obj.amount,
3078
+ currency: obj.currency,
3079
+ precision: obj.precision
3080
+ }), {
3081
+ locale: obj.locale
3082
+ });
3083
+ };
3084
+ /**
3085
+ * Uses ES5 function notation so `this` can be passed through call, apply and bind
3086
+ * @ignore
3087
+ */
3088
+
3089
+
3090
+ var assertSameCurrency = function assertSameCurrency(comparator) {
3091
+ assert(this.hasSameCurrency(comparator), 'You must provide a Dinero instance with the same currency.', TypeError);
3092
+ };
3093
+
3094
+ return {
3095
+ /**
3096
+ * Returns the amount.
3097
+ *
3098
+ * @example
3099
+ * // returns 500
3100
+ * Dinero({ amount: 500 }).getAmount()
3101
+ *
3102
+ * @return {Number}
3103
+ */
3104
+ getAmount: function getAmount() {
3105
+ return amount;
3106
+ },
3107
+
3108
+ /**
3109
+ * Returns the currency.
3110
+ *
3111
+ * @example
3112
+ * // returns 'EUR'
3113
+ * Dinero({ currency: 'EUR' }).getCurrency()
3114
+ *
3115
+ * @return {String}
3116
+ */
3117
+ getCurrency: function getCurrency() {
3118
+ return currency;
3119
+ },
3120
+
3121
+ /**
3122
+ * Returns the locale.
3123
+ *
3124
+ * @example
3125
+ * // returns 'fr-FR'
3126
+ * Dinero().setLocale('fr-FR').getLocale()
3127
+ *
3128
+ * @return {String}
3129
+ */
3130
+ getLocale: function getLocale() {
3131
+ return this.locale || globalLocale;
3132
+ },
3133
+
3134
+ /**
3135
+ * Returns a new Dinero object with an embedded locale.
3136
+ *
3137
+ * @param {String} newLocale - The new locale as an {@link http://tools.ietf.org/html/rfc5646 BCP 47 language tag}.
3138
+ *
3139
+ * @example
3140
+ * // Returns a Dinero object with locale 'ja-JP'
3141
+ * Dinero().setLocale('ja-JP')
3142
+ *
3143
+ * @return {Dinero}
3144
+ */
3145
+ setLocale: function setLocale(newLocale) {
3146
+ return create.call(this, {
3147
+ locale: newLocale
3148
+ });
3149
+ },
3150
+
3151
+ /**
3152
+ * Returns the precision.
3153
+ *
3154
+ * @example
3155
+ * // returns 3
3156
+ * Dinero({ precision: 3 }).getPrecision()
3157
+ *
3158
+ * @return {Number}
3159
+ */
3160
+ getPrecision: function getPrecision() {
3161
+ return precision;
3162
+ },
3163
+
3164
+ /**
3165
+ * Returns a new Dinero object with a new precision and a converted amount.
3166
+ *
3167
+ * By default, fractional minor currency units are rounded using the **half to even** rule ([banker's rounding](http://wiki.c2.com/?BankersRounding)).
3168
+ * This can be necessary when you need to convert objects to a smaller precision.
3169
+ *
3170
+ * Rounding *can* lead to accuracy issues as you chain many times. Consider a minimal amount of subsequent conversions for safer results.
3171
+ * You can also specify a different `roundingMode` to better fit your needs.
3172
+ *
3173
+ * @param {Number} newPrecision - The new precision.
3174
+ * @param {String} [roundingMode='HALF_EVEN'] - The rounding mode to use: `'HALF_ODD'`, `'HALF_EVEN'`, `'HALF_UP'`, `'HALF_DOWN'`, `'HALF_TOWARDS_ZERO'`, `'HALF_AWAY_FROM_ZERO'` or `'DOWN'`.
3175
+ *
3176
+ * @example
3177
+ * // Returns a Dinero object with precision 3 and amount 1000
3178
+ * Dinero({ amount: 100, precision: 2 }).convertPrecision(3)
3179
+ *
3180
+ * @throws {TypeError} If `newPrecision` is invalid.
3181
+ *
3182
+ * @return {Dinero}
3183
+ */
3184
+ convertPrecision: function convertPrecision(newPrecision) {
3185
+ var roundingMode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : globalFormatRoundingMode;
3186
+ assertInteger(newPrecision);
3187
+ var precision = this.getPrecision();
3188
+ var isNewPrecisionLarger = newPrecision > precision;
3189
+ var operation = isNewPrecisionLarger ? calculator$1.multiply : calculator$1.divide;
3190
+ var terms = isNewPrecisionLarger ? [newPrecision, precision] : [precision, newPrecision];
3191
+ var factor = Math.pow(10, calculator$1.subtract.apply(calculator$1, terms));
3192
+ return create.call(this, {
3193
+ amount: calculator$1.round(operation(this.getAmount(), factor), roundingMode),
3194
+ precision: newPrecision
3195
+ });
3196
+ },
3197
+
3198
+ /**
3199
+ * Returns a new Dinero object that represents the sum of this and an other Dinero object.
3200
+ *
3201
+ * If Dinero objects have a different `precision`, they will be first converted to the highest.
3202
+ *
3203
+ * @param {Dinero} addend - The Dinero object to add.
3204
+ *
3205
+ * @example
3206
+ * // returns a Dinero object with amount 600
3207
+ * Dinero({ amount: 400 }).add(Dinero({ amount: 200 }))
3208
+ * @example
3209
+ * // returns a Dinero object with amount 144545 and precision 4
3210
+ * Dinero({ amount: 400 }).add(Dinero({ amount: 104545, precision: 4 }))
3211
+ *
3212
+ * @throws {TypeError} If `addend` has a different currency.
3213
+ *
3214
+ * @return {Dinero}
3215
+ */
3216
+ add: function add(addend) {
3217
+ assertSameCurrency.call(this, addend);
3218
+ var addends = Dinero.normalizePrecision([this, addend]);
3219
+ return create.call(this, {
3220
+ amount: calculator$1.add(addends[0].getAmount(), addends[1].getAmount()),
3221
+ precision: addends[0].getPrecision()
3222
+ });
3223
+ },
3224
+
3225
+ /**
3226
+ * Returns a new Dinero object that represents the difference of this and an other Dinero object.
3227
+ *
3228
+ * If Dinero objects have a different `precision`, they will be first converted to the highest.
3229
+ *
3230
+ * @param {Dinero} subtrahend - The Dinero object to subtract.
3231
+ *
3232
+ * @example
3233
+ * // returns a Dinero object with amount 200
3234
+ * Dinero({ amount: 400 }).subtract(Dinero({ amount: 200 }))
3235
+ * @example
3236
+ * // returns a Dinero object with amount 64545 and precision 4
3237
+ * Dinero({ amount: 104545, precision: 4 }).subtract(Dinero({ amount: 400 }))
3238
+ *
3239
+ * @throws {TypeError} If `subtrahend` has a different currency.
3240
+ *
3241
+ * @return {Dinero}
3242
+ */
3243
+ subtract: function subtract(subtrahend) {
3244
+ assertSameCurrency.call(this, subtrahend);
3245
+ var subtrahends = Dinero.normalizePrecision([this, subtrahend]);
3246
+ return create.call(this, {
3247
+ amount: calculator$1.subtract(subtrahends[0].getAmount(), subtrahends[1].getAmount()),
3248
+ precision: subtrahends[0].getPrecision()
3249
+ });
3250
+ },
3251
+
3252
+ /**
3253
+ * Returns a new Dinero object that represents the multiplied value by the given factor.
3254
+ *
3255
+ * By default, fractional minor currency units are rounded using the **half to even** rule ([banker's rounding](http://wiki.c2.com/?BankersRounding)).
3256
+ *
3257
+ * Rounding *can* lead to accuracy issues as you chain many times. Consider a minimal amount of subsequent calculations for safer results.
3258
+ * You can also specify a different `roundingMode` to better fit your needs.
3259
+ *
3260
+ * @param {Number} multiplier - The factor to multiply by.
3261
+ * @param {String} [roundingMode='HALF_EVEN'] - The rounding mode to use: `'HALF_ODD'`, `'HALF_EVEN'`, `'HALF_UP'`, `'HALF_DOWN'`, `'HALF_TOWARDS_ZERO'`, `'HALF_AWAY_FROM_ZERO'` or `'DOWN'`.
3262
+ *
3263
+ * @example
3264
+ * // returns a Dinero object with amount 1600
3265
+ * Dinero({ amount: 400 }).multiply(4)
3266
+ * @example
3267
+ * // returns a Dinero object with amount 800
3268
+ * Dinero({ amount: 400 }).multiply(2.001)
3269
+ * @example
3270
+ * // returns a Dinero object with amount 801
3271
+ * Dinero({ amount: 400 }).multiply(2.00125, 'HALF_UP')
3272
+ *
3273
+ * @return {Dinero}
3274
+ */
3275
+ multiply: function multiply(multiplier) {
3276
+ var roundingMode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : globalRoundingMode;
3277
+ return create.call(this, {
3278
+ amount: calculator$1.round(calculator$1.multiply(this.getAmount(), multiplier), roundingMode)
3279
+ });
3280
+ },
3281
+
3282
+ /**
3283
+ * Returns a new Dinero object that represents the divided value by the given factor.
3284
+ *
3285
+ * By default, fractional minor currency units are rounded using the **half to even** rule ([banker's rounding](http://wiki.c2.com/?BankersRounding)).
3286
+ *
3287
+ * Rounding *can* lead to accuracy issues as you chain many times. Consider a minimal amount of subsequent calculations for safer results.
3288
+ * You can also specify a different `roundingMode` to better fit your needs.
3289
+ *
3290
+ * As rounding is applied, precision may be lost in the process. If you want to accurately split a Dinero object, use {@link module:Dinero~allocate allocate} instead.
3291
+ *
3292
+ * @param {Number} divisor - The factor to divide by.
3293
+ * @param {String} [roundingMode='HALF_EVEN'] - The rounding mode to use: `'HALF_ODD'`, `'HALF_EVEN'`, `'HALF_UP'`, `'HALF_DOWN'`, `'HALF_TOWARDS_ZERO'`, `'HALF_AWAY_FROM_ZERO'` or `'DOWN'`.
3294
+ *
3295
+ * @example
3296
+ * // returns a Dinero object with amount 100
3297
+ * Dinero({ amount: 400 }).divide(4)
3298
+ * @example
3299
+ * // returns a Dinero object with amount 52
3300
+ * Dinero({ amount: 105 }).divide(2)
3301
+ * @example
3302
+ * // returns a Dinero object with amount 53
3303
+ * Dinero({ amount: 105 }).divide(2, 'HALF_UP')
3304
+ *
3305
+ * @return {Dinero}
3306
+ */
3307
+ divide: function divide(divisor) {
3308
+ var roundingMode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : globalRoundingMode;
3309
+ return create.call(this, {
3310
+ amount: calculator$1.round(calculator$1.divide(this.getAmount(), divisor), roundingMode)
3311
+ });
3312
+ },
3313
+
3314
+ /**
3315
+ * Returns a new Dinero object that represents a percentage of this.
3316
+ *
3317
+ * As rounding is applied, precision may be lost in the process. If you want to accurately split a Dinero object, use {@link module:Dinero~allocate allocate} instead.
3318
+ *
3319
+ * @param {Number} percentage - The percentage to extract (between 0 and 100).
3320
+ * @param {String} [roundingMode='HALF_EVEN'] - The rounding mode to use: `'HALF_ODD'`, `'HALF_EVEN'`, `'HALF_UP'`, `'HALF_DOWN'`, `'HALF_TOWARDS_ZERO'`, `'HALF_AWAY_FROM_ZERO'` or `'DOWN'`.
3321
+ *
3322
+ * @example
3323
+ * // returns a Dinero object with amount 5000
3324
+ * Dinero({ amount: 10000 }).percentage(50)
3325
+ * @example
3326
+ * // returns a Dinero object with amount 29
3327
+ * Dinero({ amount: 57 }).percentage(50, "HALF_ODD")
3328
+ *
3329
+ * @throws {RangeError} If `percentage` is out of range.
3330
+ *
3331
+ * @return {Dinero}
3332
+ */
3333
+ percentage: function percentage(_percentage) {
3334
+ var roundingMode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : globalRoundingMode;
3335
+ assertPercentage(_percentage);
3336
+ return this.multiply(calculator$1.divide(_percentage, 100), roundingMode);
3337
+ },
3338
+
3339
+ /**
3340
+ * Allocates the amount of a Dinero object according to a list of ratios.
3341
+ *
3342
+ * Sometimes you need to split monetary values but percentages can't cut it without adding or losing pennies.
3343
+ * A good example is invoicing: let's say you need to bill $1,000.03 and you want a 50% downpayment.
3344
+ * If you use {@link module:Dinero~percentage percentage}, you'll get an accurate Dinero object but the amount won't be billable: you can't split a penny.
3345
+ * If you round it, you'll bill a penny extra.
3346
+ * With {@link module:Dinero~allocate allocate}, you can split a monetary amount then distribute the remainder as evenly as possible.
3347
+ *
3348
+ * You can use percentage style or ratio style for `ratios`: `[25, 75]` and `[1, 3]` will do the same thing.
3349
+ *
3350
+ * Since v1.8.0, you can use zero ratios (such as [0, 50, 50]). If there's a remainder to distribute, zero ratios are skipped and return a Dinero object with amount zero.
3351
+ *
3352
+ * @param {Number[]} ratios - The ratios to allocate the money to.
3353
+ *
3354
+ * @example
3355
+ * // returns an array of two Dinero objects
3356
+ * // the first one with an amount of 502
3357
+ * // the second one with an amount of 501
3358
+ * Dinero({ amount: 1003 }).allocate([50, 50])
3359
+ * @example
3360
+ * // returns an array of two Dinero objects
3361
+ * // the first one with an amount of 25
3362
+ * // the second one with an amount of 75
3363
+ * Dinero({ amount: 100 }).allocate([1, 3])
3364
+ * @example
3365
+ * // since version 1.8.0
3366
+ * // returns an array of three Dinero objects
3367
+ * // the first one with an amount of 0
3368
+ * // the second one with an amount of 502
3369
+ * // the third one with an amount of 501
3370
+ * Dinero({ amount: 1003 }).allocate([0, 50, 50])
3371
+ *
3372
+ * @throws {TypeError} If ratios are invalid.
3373
+ *
3374
+ * @return {Dinero[]}
3375
+ */
3376
+ allocate: function allocate(ratios) {
3377
+ var _this = this;
3378
+
3379
+ assertValidRatios(ratios);
3380
+ var total = ratios.reduce(function (a, b) {
3381
+ return calculator$1.add(a, b);
3382
+ });
3383
+ var remainder = this.getAmount();
3384
+ var shares = ratios.map(function (ratio) {
3385
+ var share = Math.floor(calculator$1.divide(calculator$1.multiply(_this.getAmount(), ratio), total));
3386
+ remainder = calculator$1.subtract(remainder, share);
3387
+ return create.call(_this, {
3388
+ amount: share
3389
+ });
3390
+ });
3391
+ var i = 0;
3392
+
3393
+ while (remainder > 0) {
3394
+ if (ratios[i] > 0) {
3395
+ shares[i] = shares[i].add(create.call(this, {
3396
+ amount: 1
3397
+ }));
3398
+ remainder = calculator$1.subtract(remainder, 1);
3399
+ }
3400
+
3401
+ i += 1;
3402
+ }
3403
+
3404
+ return shares;
3405
+ },
3406
+
3407
+ /**
3408
+ * Returns a Promise containing a new Dinero object converted to another currency.
3409
+ *
3410
+ * You have two options to provide the exchange rates:
3411
+ *
3412
+ * 1. **Use an exchange rate REST API, and let Dinero handle the fetching and conversion.**
3413
+ * This is a simple option if you have access to an exchange rate REST API and want Dinero to do the rest.
3414
+ * 2. **Fetch the exchange rates on your own and provide them directly.**
3415
+ * This is useful if you're fetching your rates from somewhere else (a file, a database), use a different protocol or query language than REST (SOAP, GraphQL) or want to fetch rates once and cache them instead of making new requests every time.
3416
+ *
3417
+ * **If you want to use a REST API**, you must provide a third-party endpoint yourself. Dinero doesn't come bundled with an exchange rates endpoint.
3418
+ *
3419
+ * Here are some exchange rate APIs you can use:
3420
+ *
3421
+ * * [Fixer](https://fixer.io)
3422
+ * * [Open Exchange Rates](https://openexchangerates.org)
3423
+ * * [Coinbase](https://api.coinbase.com/v2/exchange-rates)
3424
+ * * More [foreign](https://github.com/toddmotto/public-apis#currency-exchange) and [crypto](https://github.com/toddmotto/public-apis#cryptocurrency) exchange rate APIs.
3425
+ *
3426
+ * **If you want to fetch your own rates and provide them directly**, you need to pass a promise that resolves to the exchanges rates.
3427
+ *
3428
+ * In both cases, you need to specify at least:
3429
+ *
3430
+ * * a **destination currency**: the currency in which you want to convert your Dinero object. You can specify it with `currency`.
3431
+ * * an **endpoint**: the API URL to query exchange rates, with parameters, or a promise that resolves to the exchange rates. You can specify it with `options.endpoint`.
3432
+ * * a **property path**: the path to access the wanted rate in your API's JSON response (or the custom promise's payload). For example, with a response of:
3433
+ * ```json
3434
+ * {
3435
+ * "data": {
3436
+ * "base": "USD",
3437
+ * "destination": "EUR",
3438
+ * "rate": "0.827728919"
3439
+ * }
3440
+ * }
3441
+ * ```
3442
+ * Then the property path is `'data.rate'`. You can specify it with `options.propertyPath`.
3443
+ *
3444
+ * The base currency (the one of your Dinero object) and the destination currency can be used as "merge tags" with the mustache syntax, respectively `{{from}}` and `{{to}}`.
3445
+ * You can use these tags to refer to these values in `options.endpoint` and `options.propertyPath`.
3446
+ *
3447
+ * For example, if you need to specify the base currency as a query parameter, you can do the following:
3448
+ *
3449
+ * ```js
3450
+ * {
3451
+ * endpoint: 'https://yourexchangerates.api/latest?base={{from}}'
3452
+ * }
3453
+ * ```
3454
+ *
3455
+ * @param {String} currency - The destination currency, expressed as an {@link https://en.wikipedia.org/wiki/ISO_4217#Active_codes ISO 4217 currency code}.
3456
+ * @param {(String|Promise)} options.endpoint - The API endpoint to retrieve exchange rates. You can substitute this with a promise that resolves to the exchanges rates if you already have them.
3457
+ * @param {String} [options.propertyPath='rates.{{to}}'] - The property path to the rate.
3458
+ * @param {Object} [options.headers] - The HTTP headers to provide, if needed.
3459
+ * @param {String} [options.roundingMode='HALF_EVEN'] - The rounding mode to use: `'HALF_ODD'`, `'HALF_EVEN'`, `'HALF_UP'`, `'HALF_DOWN'`, `'HALF_TOWARDS_ZERO'`, `'HALF_AWAY_FROM_ZERO'` or `'DOWN'`.
3460
+ *
3461
+ * @example
3462
+ * // your global API parameters
3463
+ * Dinero.globalExchangeRatesApi = { ... }
3464
+ *
3465
+ * // returns a Promise containing a Dinero object with the destination currency
3466
+ * // and the initial amount converted to the new currency.
3467
+ * Dinero({ amount: 500 }).convert('EUR')
3468
+ * @example
3469
+ * // returns a Promise containing a Dinero object,
3470
+ * // with specific API parameters and rounding mode for this specific instance.
3471
+ * Dinero({ amount: 500 })
3472
+ * .convert('XBT', {
3473
+ * endpoint: 'https://yourexchangerates.api/latest?base={{from}}',
3474
+ * propertyPath: 'data.rates.{{to}}',
3475
+ * headers: {
3476
+ * 'user-key': 'xxxxxxxxx'
3477
+ * },
3478
+ * roundingMode: 'HALF_UP'
3479
+ * })
3480
+ * @example
3481
+ * // usage with exchange rates provided as a custom promise
3482
+ * // using the default `propertyPath` format (so it doesn't have to be specified)
3483
+ * const rates = {
3484
+ * rates: {
3485
+ * EUR: 0.81162
3486
+ * }
3487
+ * }
3488
+ *
3489
+ * Dinero({ amount: 500 })
3490
+ * .convert('EUR', {
3491
+ * endpoint: new Promise(resolve => resolve(rates))
3492
+ * })
3493
+ * @example
3494
+ * // usage with Promise.prototype.then and Promise.prototype.catch
3495
+ * Dinero({ amount: 500 })
3496
+ * .convert('EUR')
3497
+ * .then(dinero => {
3498
+ * dinero.getCurrency() // returns 'EUR'
3499
+ * })
3500
+ * .catch(err => {
3501
+ * // handle errors
3502
+ * })
3503
+ * @example
3504
+ * // usage with async/await
3505
+ * (async () => {
3506
+ * const price = await Dinero({ amount: 500 }).convert('EUR')
3507
+ * price.getCurrency() // returns 'EUR'
3508
+ * })()
3509
+ *
3510
+ * @return {Promise}
3511
+ */
3512
+ convert: function convert(currency) {
3513
+ var _this2 = this;
3514
+
3515
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
3516
+ _ref$endpoint = _ref.endpoint,
3517
+ endpoint = _ref$endpoint === void 0 ? globalExchangeRatesApi.endpoint : _ref$endpoint,
3518
+ _ref$propertyPath = _ref.propertyPath,
3519
+ propertyPath = _ref$propertyPath === void 0 ? globalExchangeRatesApi.propertyPath || 'rates.{{to}}' : _ref$propertyPath,
3520
+ _ref$headers = _ref.headers,
3521
+ headers = _ref$headers === void 0 ? globalExchangeRatesApi.headers : _ref$headers,
3522
+ _ref$roundingMode = _ref.roundingMode,
3523
+ roundingMode = _ref$roundingMode === void 0 ? globalRoundingMode : _ref$roundingMode;
3524
+
3525
+ var options = Object.assign({}, {
3526
+ endpoint: endpoint,
3527
+ propertyPath: propertyPath,
3528
+ headers: headers,
3529
+ roundingMode: roundingMode
3530
+ });
3531
+ return CurrencyConverter(options).getExchangeRate(this.getCurrency(), currency).then(function (rate) {
3532
+ assert(!isUndefined(rate), "No rate was found for the destination currency \"".concat(currency, "\"."), TypeError);
3533
+ return create.call(_this2, {
3534
+ amount: calculator$1.round(calculator$1.multiply(_this2.getAmount(), parseFloat(rate)), options.roundingMode),
3535
+ currency: currency
3536
+ });
3537
+ });
3538
+ },
3539
+
3540
+ /**
3541
+ * Checks whether the value represented by this object equals to the other.
3542
+ *
3543
+ * @param {Dinero} comparator - The Dinero object to compare to.
3544
+ *
3545
+ * @example
3546
+ * // returns true
3547
+ * Dinero({ amount: 500, currency: 'EUR' }).equalsTo(Dinero({ amount: 500, currency: 'EUR' }))
3548
+ * @example
3549
+ * // returns false
3550
+ * Dinero({ amount: 500, currency: 'EUR' }).equalsTo(Dinero({ amount: 800, currency: 'EUR' }))
3551
+ * @example
3552
+ * // returns false
3553
+ * Dinero({ amount: 500, currency: 'USD' }).equalsTo(Dinero({ amount: 500, currency: 'EUR' }))
3554
+ * @example
3555
+ * // returns false
3556
+ * Dinero({ amount: 500, currency: 'USD' }).equalsTo(Dinero({ amount: 800, currency: 'EUR' }))
3557
+ * @example
3558
+ * // returns true
3559
+ * Dinero({ amount: 1000, currency: 'EUR', precision: 2 }).equalsTo(Dinero({ amount: 10000, currency: 'EUR', precision: 3 }))
3560
+ * @example
3561
+ * // returns false
3562
+ * Dinero({ amount: 10000, currency: 'EUR', precision: 2 }).equalsTo(Dinero({ amount: 10000, currency: 'EUR', precision: 3 }))
3563
+ *
3564
+ * @return {Boolean}
3565
+ */
3566
+ equalsTo: function equalsTo(comparator) {
3567
+ return this.hasSameAmount(comparator) && this.hasSameCurrency(comparator);
3568
+ },
3569
+
3570
+ /**
3571
+ * Checks whether the value represented by this object is less than the other.
3572
+ *
3573
+ * @param {Dinero} comparator - The Dinero object to compare to.
3574
+ *
3575
+ * @example
3576
+ * // returns true
3577
+ * Dinero({ amount: 500 }).lessThan(Dinero({ amount: 800 }))
3578
+ * @example
3579
+ * // returns false
3580
+ * Dinero({ amount: 800 }).lessThan(Dinero({ amount: 500 }))
3581
+ * @example
3582
+ * // returns true
3583
+ * Dinero({ amount: 5000, precision: 3 }).lessThan(Dinero({ amount: 800 }))
3584
+ * @example
3585
+ * // returns false
3586
+ * Dinero({ amount: 800 }).lessThan(Dinero({ amount: 5000, precision: 3 }))
3587
+ *
3588
+ * @throws {TypeError} If `comparator` has a different currency.
3589
+ *
3590
+ * @return {Boolean}
3591
+ */
3592
+ lessThan: function lessThan(comparator) {
3593
+ assertSameCurrency.call(this, comparator);
3594
+ var comparators = Dinero.normalizePrecision([this, comparator]);
3595
+ return comparators[0].getAmount() < comparators[1].getAmount();
3596
+ },
3597
+
3598
+ /**
3599
+ * Checks whether the value represented by this object is less than or equal to the other.
3600
+ *
3601
+ * @param {Dinero} comparator - The Dinero object to compare to.
3602
+ *
3603
+ * @example
3604
+ * // returns true
3605
+ * Dinero({ amount: 500 }).lessThanOrEqual(Dinero({ amount: 800 }))
3606
+ * @example
3607
+ * // returns true
3608
+ * Dinero({ amount: 500 }).lessThanOrEqual(Dinero({ amount: 500 }))
3609
+ * @example
3610
+ * // returns false
3611
+ * Dinero({ amount: 500 }).lessThanOrEqual(Dinero({ amount: 300 }))
3612
+ * @example
3613
+ * // returns true
3614
+ * Dinero({ amount: 5000, precision: 3 }).lessThanOrEqual(Dinero({ amount: 800 }))
3615
+ * @example
3616
+ * // returns true
3617
+ * Dinero({ amount: 5000, precision: 3 }).lessThanOrEqual(Dinero({ amount: 500 }))
3618
+ * @example
3619
+ * // returns false
3620
+ * Dinero({ amount: 800 }).lessThanOrEqual(Dinero({ amount: 5000, precision: 3 }))
3621
+ *
3622
+ * @throws {TypeError} If `comparator` has a different currency.
3623
+ *
3624
+ * @return {Boolean}
3625
+ */
3626
+ lessThanOrEqual: function lessThanOrEqual(comparator) {
3627
+ assertSameCurrency.call(this, comparator);
3628
+ var comparators = Dinero.normalizePrecision([this, comparator]);
3629
+ return comparators[0].getAmount() <= comparators[1].getAmount();
3630
+ },
3631
+
3632
+ /**
3633
+ * Checks whether the value represented by this object is greater than the other.
3634
+ *
3635
+ * @param {Dinero} comparator - The Dinero object to compare to.
3636
+ *
3637
+ * @example
3638
+ * // returns false
3639
+ * Dinero({ amount: 500 }).greaterThan(Dinero({ amount: 800 }))
3640
+ * @example
3641
+ * // returns true
3642
+ * Dinero({ amount: 800 }).greaterThan(Dinero({ amount: 500 }))
3643
+ * @example
3644
+ * // returns true
3645
+ * Dinero({ amount: 800 }).greaterThan(Dinero({ amount: 5000, precision: 3 }))
3646
+ * @example
3647
+ * // returns false
3648
+ * Dinero({ amount: 5000, precision: 3 }).greaterThan(Dinero({ amount: 800 }))
3649
+ *
3650
+ * @throws {TypeError} If `comparator` has a different currency.
3651
+ *
3652
+ * @return {Boolean}
3653
+ */
3654
+ greaterThan: function greaterThan(comparator) {
3655
+ assertSameCurrency.call(this, comparator);
3656
+ var comparators = Dinero.normalizePrecision([this, comparator]);
3657
+ return comparators[0].getAmount() > comparators[1].getAmount();
3658
+ },
3659
+
3660
+ /**
3661
+ * Checks whether the value represented by this object is greater than or equal to the other.
3662
+ *
3663
+ * @param {Dinero} comparator - The Dinero object to compare to.
3664
+ *
3665
+ * @example
3666
+ * // returns true
3667
+ * Dinero({ amount: 500 }).greaterThanOrEqual(Dinero({ amount: 300 }))
3668
+ * @example
3669
+ * // returns true
3670
+ * Dinero({ amount: 500 }).greaterThanOrEqual(Dinero({ amount: 500 }))
3671
+ * @example
3672
+ * // returns false
3673
+ * Dinero({ amount: 500 }).greaterThanOrEqual(Dinero({ amount: 800 }))
3674
+ * @example
3675
+ * // returns true
3676
+ * Dinero({ amount: 800 }).greaterThanOrEqual(Dinero({ amount: 5000, precision: 3 }))
3677
+ * @example
3678
+ * // returns true
3679
+ * Dinero({ amount: 500 }).greaterThanOrEqual(Dinero({ amount: 5000, precision: 3 }))
3680
+ * @example
3681
+ * // returns false
3682
+ * Dinero({ amount: 5000, precision: 3 }).greaterThanOrEqual(Dinero({ amount: 800 }))
3683
+ *
3684
+ * @throws {TypeError} If `comparator` has a different currency.
3685
+ *
3686
+ * @return {Boolean}
3687
+ */
3688
+ greaterThanOrEqual: function greaterThanOrEqual(comparator) {
3689
+ assertSameCurrency.call(this, comparator);
3690
+ var comparators = Dinero.normalizePrecision([this, comparator]);
3691
+ return comparators[0].getAmount() >= comparators[1].getAmount();
3692
+ },
3693
+
3694
+ /**
3695
+ * Checks if the value represented by this object is zero.
3696
+ *
3697
+ * @example
3698
+ * // returns true
3699
+ * Dinero({ amount: 0 }).isZero()
3700
+ * @example
3701
+ * // returns false
3702
+ * Dinero({ amount: 100 }).isZero()
3703
+ *
3704
+ * @return {Boolean}
3705
+ */
3706
+ isZero: function isZero() {
3707
+ return this.getAmount() === 0;
3708
+ },
3709
+
3710
+ /**
3711
+ * Checks if the value represented by this object is positive.
3712
+ *
3713
+ * @example
3714
+ * // returns false
3715
+ * Dinero({ amount: -10 }).isPositive()
3716
+ * @example
3717
+ * // returns true
3718
+ * Dinero({ amount: 10 }).isPositive()
3719
+ * @example
3720
+ * // returns true
3721
+ * Dinero({ amount: 0 }).isPositive()
3722
+ *
3723
+ * @return {Boolean}
3724
+ */
3725
+ isPositive: function isPositive() {
3726
+ return this.getAmount() >= 0;
3727
+ },
3728
+
3729
+ /**
3730
+ * Checks if the value represented by this object is negative.
3731
+ *
3732
+ * @example
3733
+ * // returns true
3734
+ * Dinero({ amount: -10 }).isNegative()
3735
+ * @example
3736
+ * // returns false
3737
+ * Dinero({ amount: 10 }).isNegative()
3738
+ * @example
3739
+ * // returns false
3740
+ * Dinero({ amount: 0 }).isNegative()
3741
+ *
3742
+ * @return {Boolean}
3743
+ */
3744
+ isNegative: function isNegative() {
3745
+ return this.getAmount() < 0;
3746
+ },
3747
+
3748
+ /**
3749
+ * Checks if this has minor currency units.
3750
+ * Deprecates {@link module:Dinero~hasCents hasCents}.
3751
+ *
3752
+ * @example
3753
+ * // returns false
3754
+ * Dinero({ amount: 1100 }).hasSubUnits()
3755
+ * @example
3756
+ * // returns true
3757
+ * Dinero({ amount: 1150 }).hasSubUnits()
3758
+ *
3759
+ * @return {Boolean}
3760
+ */
3761
+ hasSubUnits: function hasSubUnits() {
3762
+ return calculator$1.modulo(this.getAmount(), Math.pow(10, precision)) !== 0;
3763
+ },
3764
+
3765
+ /**
3766
+ * Checks if this has minor currency units.
3767
+ *
3768
+ * @deprecated since version 1.4.0, will be removed in 2.0.0
3769
+ * Use {@link module:Dinero~hasSubUnits hasSubUnits} instead.
3770
+ *
3771
+ * @example
3772
+ * // returns false
3773
+ * Dinero({ amount: 1100 }).hasCents()
3774
+ * @example
3775
+ * // returns true
3776
+ * Dinero({ amount: 1150 }).hasCents()
3777
+ *
3778
+ * @return {Boolean}
3779
+ */
3780
+ hasCents: function hasCents() {
3781
+ return calculator$1.modulo(this.getAmount(), Math.pow(10, precision)) !== 0;
3782
+ },
3783
+
3784
+ /**
3785
+ * Checks whether the currency represented by this object equals to the other.
3786
+ *
3787
+ * @param {Dinero} comparator - The Dinero object to compare to.
3788
+ *
3789
+ * @example
3790
+ * // returns true
3791
+ * Dinero({ amount: 2000, currency: 'EUR' }).hasSameCurrency(Dinero({ amount: 1000, currency: 'EUR' }))
3792
+ * @example
3793
+ * // returns false
3794
+ * Dinero({ amount: 1000, currency: 'EUR' }).hasSameCurrency(Dinero({ amount: 1000, currency: 'USD' }))
3795
+ *
3796
+ * @return {Boolean}
3797
+ */
3798
+ hasSameCurrency: function hasSameCurrency(comparator) {
3799
+ return this.getCurrency() === comparator.getCurrency();
3800
+ },
3801
+
3802
+ /**
3803
+ * Checks whether the amount represented by this object equals to the other.
3804
+ *
3805
+ * @param {Dinero} comparator - The Dinero object to compare to.
3806
+ *
3807
+ * @example
3808
+ * // returns true
3809
+ * Dinero({ amount: 1000, currency: 'EUR' }).hasSameAmount(Dinero({ amount: 1000 }))
3810
+ * @example
3811
+ * // returns false
3812
+ * Dinero({ amount: 2000, currency: 'EUR' }).hasSameAmount(Dinero({ amount: 1000, currency: 'EUR' }))
3813
+ * @example
3814
+ * // returns true
3815
+ * Dinero({ amount: 1000, currency: 'EUR', precision: 2 }).hasSameAmount(Dinero({ amount: 10000, precision: 3 }))
3816
+ * @example
3817
+ * // returns false
3818
+ * Dinero({ amount: 10000, currency: 'EUR', precision: 2 }).hasSameAmount(Dinero({ amount: 10000, precision: 3 }))
3819
+ *
3820
+ * @return {Boolean}
3821
+ */
3822
+ hasSameAmount: function hasSameAmount(comparator) {
3823
+ var comparators = Dinero.normalizePrecision([this, comparator]);
3824
+ return comparators[0].getAmount() === comparators[1].getAmount();
3825
+ },
3826
+
3827
+ /**
3828
+ * Returns this object formatted as a string.
3829
+ *
3830
+ * The format is a mask which defines how the output string will be formatted.
3831
+ * It defines whether to display a currency, in what format, how many fraction digits to display and whether to use grouping separators.
3832
+ * The output is formatted according to the applying locale.
3833
+ *
3834
+ * Object | Format | String
3835
+ * :--------------------------- | :---------------- | :---
3836
+ * `Dinero({ amount: 500050 })` | `'$0,0.00'` | $5,000.50
3837
+ * `Dinero({ amount: 500050 })` | `'$0,0'` | $5,001
3838
+ * `Dinero({ amount: 500050 })` | `'$0'` | $5001
3839
+ * `Dinero({ amount: 500050 })` | `'$0.0'` | $5000.5
3840
+ * `Dinero({ amount: 500050 })` | `'USD0,0.0'` | USD5,000.5
3841
+ * `Dinero({ amount: 500050 })` | `'0,0.0 dollar'` | 5,000.5 dollars
3842
+ *
3843
+ * Don't try to substitute the `$` sign or the `USD` code with your target currency, nor adapt the format string to the exact format you want.
3844
+ * The format is a mask which defines a pattern and returns a valid, localized currency string.
3845
+ * If you want to display the object in a custom way, either use {@link module:Dinero~getAmount getAmount}, {@link module:Dinero~toUnit toUnit} or {@link module:Dinero~toRoundedUnit toRoundedUnit} and manipulate the output string as you wish.
3846
+ *
3847
+ * {@link module:Dinero~toFormat toFormat} wraps around `Number.prototype.toLocaleString`. For that reason, **format will vary depending on how it's implemented in the end user's environment**.
3848
+ *
3849
+ * You can also use `toLocaleString` directly:
3850
+ * `Dinero().toRoundedUnit(digits, roundingMode).toLocaleString(locale, options)`.
3851
+ *
3852
+ * By default, amounts are rounded using the **half away from zero** rule ([commercial rounding](https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero)).
3853
+ * You can also specify a different `roundingMode` to better fit your needs.
3854
+ *
3855
+ * @param {String} [format='$0,0.00'] - The format mask to format to.
3856
+ * @param {String} [roundingMode='HALF_AWAY_FROM_ZERO'] - The rounding mode to use: `'HALF_ODD'`, `'HALF_EVEN'`, `'HALF_UP'`, `'HALF_DOWN'`, `'HALF_TOWARDS_ZERO'`, `'HALF_AWAY_FROM_ZERO'` or `'DOWN'`.
3857
+ *
3858
+ * @example
3859
+ * // returns $2,000
3860
+ * Dinero({ amount: 200000 }).toFormat('$0,0')
3861
+ * @example
3862
+ * // returns €50.5
3863
+ * Dinero({ amount: 5050, currency: 'EUR' }).toFormat('$0,0.0')
3864
+ * @example
3865
+ * // returns 100 euros
3866
+ * Dinero({ amount: 10000, currency: 'EUR' }).setLocale('fr-FR').toFormat('0,0 dollar')
3867
+ * @example
3868
+ * // returns 2000
3869
+ * Dinero({ amount: 200000, currency: 'EUR' }).toFormat()
3870
+ * @example
3871
+ * // returns $10
3872
+ * Dinero({ amount: 1050 }).toFormat('$0', 'HALF_EVEN')
3873
+ *
3874
+ * @return {String}
3875
+ */
3876
+ toFormat: function toFormat() {
3877
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : globalFormat;
3878
+ var roundingMode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : globalFormatRoundingMode;
3879
+ var formatter = Format(format);
3880
+ return this.toRoundedUnit(formatter.getMinimumFractionDigits(), roundingMode).toLocaleString(this.getLocale(), {
3881
+ currencyDisplay: formatter.getCurrencyDisplay(),
3882
+ useGrouping: formatter.getUseGrouping(),
3883
+ minimumFractionDigits: formatter.getMinimumFractionDigits(),
3884
+ style: formatter.getStyle(),
3885
+ currency: this.getCurrency()
3886
+ });
3887
+ },
3888
+
3889
+ /**
3890
+ * Returns the amount represented by this object in units.
3891
+ *
3892
+ * @example
3893
+ * // returns 10.5
3894
+ * Dinero({ amount: 1050 }).toUnit()
3895
+ * @example
3896
+ * // returns 10.545
3897
+ * Dinero({ amount: 10545, precision: 3 }).toUnit()
3898
+ *
3899
+ * @return {Number}
3900
+ */
3901
+ toUnit: function toUnit() {
3902
+ return calculator$1.divide(this.getAmount(), Math.pow(10, precision));
3903
+ },
3904
+
3905
+ /**
3906
+ * Returns the amount represented by this object in rounded units.
3907
+ *
3908
+ * By default, the method uses the **half away from zero** rule ([commercial rounding](https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero)).
3909
+ * You can also specify a different `roundingMode` to better fit your needs.
3910
+ *
3911
+ * @example
3912
+ * // returns 10.6
3913
+ * Dinero({ amount: 1055 }).toRoundedUnit(1)
3914
+ * @example
3915
+ * // returns 10
3916
+ * Dinero({ amount: 1050 }).toRoundedUnit(0, 'HALF_EVEN')
3917
+ *
3918
+ * @param {Number} digits - The number of fraction digits to round to.
3919
+ * @param {String} [roundingMode='HALF_AWAY_FROM_ZERO'] - The rounding mode to use: `'HALF_ODD'`, `'HALF_EVEN'`, `'HALF_UP'`, `'HALF_DOWN'`, `'HALF_TOWARDS_ZERO'`, `'HALF_AWAY_FROM_ZERO'` or `'DOWN'`.
3920
+ *
3921
+ * @return {Number}
3922
+ */
3923
+ toRoundedUnit: function toRoundedUnit(digits) {
3924
+ var roundingMode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : globalFormatRoundingMode;
3925
+ var factor = Math.pow(10, digits);
3926
+ return calculator$1.divide(calculator$1.round(calculator$1.multiply(this.toUnit(), factor), roundingMode), factor);
3927
+ },
3928
+
3929
+ /**
3930
+ * Returns the object's data as an object literal.
3931
+ *
3932
+ * @example
3933
+ * // returns { amount: 500, currency: 'EUR', precision: 2 }
3934
+ * Dinero({ amount: 500, currency: 'EUR', precision: 2 }).toObject()
3935
+ *
3936
+ * @return {Object}
3937
+ */
3938
+ toObject: function toObject() {
3939
+ return {
3940
+ amount: amount,
3941
+ currency: currency,
3942
+ precision: precision
3943
+ };
3944
+ },
3945
+
3946
+ /**
3947
+ * Returns the object's data as an object literal.
3948
+ *
3949
+ * Alias of {@link module:Dinero~toObject toObject}.
3950
+ * It is defined so that calling `JSON.stringify` on a Dinero object will automatically extract the relevant data.
3951
+ *
3952
+ * @example
3953
+ * // returns '{"amount":500,"currency":"EUR","precision":2}'
3954
+ * JSON.stringify(Dinero({ amount: 500, currency: 'EUR', precision: 2 }))
3955
+ *
3956
+ * @return {Object}
3957
+ */
3958
+ toJSON: function toJSON() {
3959
+ return this.toObject();
3960
+ }
3961
+ };
3962
+ };
3963
+
3964
+ var Dinero$1 = Object.assign(Dinero, Defaults, Globals, Static);
3965
+
3966
+ return Dinero$1;
3967
+
3968
+ })));