seller-base-service 0.0.1-security → 0.1.12

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.

Potentially problematic release.


This version of seller-base-service might be problematic. Click here for more details.

Files changed (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +59 -3
  3. package/dist/babel-config-for-main-project.js +74 -0
  4. package/dist/collection/index.js +189 -0
  5. package/dist/collection/index.js.map +1 -0
  6. package/dist/common/index.js +206 -0
  7. package/dist/common/index.js.map +1 -0
  8. package/dist/feedback/index.js +249 -0
  9. package/dist/feedback/index.js.map +1 -0
  10. package/dist/index.d.ts +1117 -0
  11. package/dist/index.js +3223 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/notification/index.js +2373 -0
  14. package/dist/notification/index.js.map +1 -0
  15. package/dist/otp/index.js +197 -0
  16. package/dist/otp/index.js.map +1 -0
  17. package/dist/redteam.js +64 -0
  18. package/dist/report/index.js +330 -0
  19. package/dist/report/index.js.map +1 -0
  20. package/dist/sip/index.js +191 -0
  21. package/dist/sip/index.js.map +1 -0
  22. package/dist/upload/index.js +235 -0
  23. package/dist/upload/index.js.map +1 -0
  24. package/package.json +40 -3
  25. package/src/development/index.ts +38 -0
  26. package/src/index.ts +6 -0
  27. package/src/modules/collection/constants.ts +11 -0
  28. package/src/modules/collection/index.ts +9 -0
  29. package/src/modules/collection/service.ts +53 -0
  30. package/src/modules/collection/types.ts +31 -0
  31. package/src/modules/common/index.ts +7 -0
  32. package/src/modules/common/interceptors.ts +16 -0
  33. package/src/modules/common/service.ts +60 -0
  34. package/src/modules/common/types.ts +36 -0
  35. package/src/modules/feedback/index.ts +6 -0
  36. package/src/modules/feedback/service.ts +73 -0
  37. package/src/modules/feedback/types.ts +68 -0
  38. package/src/modules/index.ts +77 -0
  39. package/src/modules/notification/action.ts +215 -0
  40. package/src/modules/notification/constants.ts +420 -0
  41. package/src/modules/notification/index.ts +23 -0
  42. package/src/modules/notification/service.ts +90 -0
  43. package/src/modules/notification/types.ts +155 -0
  44. package/src/modules/otp/constants.ts +39 -0
  45. package/src/modules/otp/index.ts +11 -0
  46. package/src/modules/otp/service.ts +28 -0
  47. package/src/modules/otp/types.ts +13 -0
  48. package/src/modules/report/constants.ts +20 -0
  49. package/src/modules/report/index.ts +19 -0
  50. package/src/modules/report/service.ts +100 -0
  51. package/src/modules/report/types.ts +31 -0
  52. package/src/modules/report/utils.ts +74 -0
  53. package/src/modules/sip/index.ts +2 -0
  54. package/src/modules/sip/service.ts +59 -0
  55. package/src/modules/sip/types.ts +33 -0
  56. package/src/modules/upload/index.ts +8 -0
  57. package/src/modules/upload/service.ts +94 -0
  58. package/src/modules/upload/types.ts +34 -0
@@ -0,0 +1,2373 @@
1
+ module.exports =
2
+ /******/ (function(modules) { // webpackBootstrap
3
+ /******/ // The module cache
4
+ /******/ var installedModules = {};
5
+ /******/
6
+ /******/ // The require function
7
+ /******/ function __webpack_require__(moduleId) {
8
+ /******/
9
+ /******/ // Check if module is in cache
10
+ /******/ if(installedModules[moduleId]) {
11
+ /******/ return installedModules[moduleId].exports;
12
+ /******/ }
13
+ /******/ // Create a new module (and put it into the cache)
14
+ /******/ var module = installedModules[moduleId] = {
15
+ /******/ i: moduleId,
16
+ /******/ l: false,
17
+ /******/ exports: {}
18
+ /******/ };
19
+ /******/
20
+ /******/ // Execute the module function
21
+ /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
22
+ /******/
23
+ /******/ // Flag the module as loaded
24
+ /******/ module.l = true;
25
+ /******/
26
+ /******/ // Return the exports of the module
27
+ /******/ return module.exports;
28
+ /******/ }
29
+ /******/
30
+ /******/
31
+ /******/ // expose the modules object (__webpack_modules__)
32
+ /******/ __webpack_require__.m = modules;
33
+ /******/
34
+ /******/ // expose the module cache
35
+ /******/ __webpack_require__.c = installedModules;
36
+ /******/
37
+ /******/ // define getter function for harmony exports
38
+ /******/ __webpack_require__.d = function(exports, name, getter) {
39
+ /******/ if(!__webpack_require__.o(exports, name)) {
40
+ /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
41
+ /******/ }
42
+ /******/ };
43
+ /******/
44
+ /******/ // define __esModule on exports
45
+ /******/ __webpack_require__.r = function(exports) {
46
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
47
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
48
+ /******/ }
49
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
50
+ /******/ };
51
+ /******/
52
+ /******/ // create a fake namespace object
53
+ /******/ // mode & 1: value is a module id, require it
54
+ /******/ // mode & 2: merge all properties of value into the ns
55
+ /******/ // mode & 4: return value when already ns object
56
+ /******/ // mode & 8|1: behave like require
57
+ /******/ __webpack_require__.t = function(value, mode) {
58
+ /******/ if(mode & 1) value = __webpack_require__(value);
59
+ /******/ if(mode & 8) return value;
60
+ /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
61
+ /******/ var ns = Object.create(null);
62
+ /******/ __webpack_require__.r(ns);
63
+ /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
64
+ /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
65
+ /******/ return ns;
66
+ /******/ };
67
+ /******/
68
+ /******/ // getDefaultExport function for compatibility with non-harmony modules
69
+ /******/ __webpack_require__.n = function(module) {
70
+ /******/ var getter = module && module.__esModule ?
71
+ /******/ function getDefault() { return module['default']; } :
72
+ /******/ function getModuleExports() { return module; };
73
+ /******/ __webpack_require__.d(getter, 'a', getter);
74
+ /******/ return getter;
75
+ /******/ };
76
+ /******/
77
+ /******/ // Object.prototype.hasOwnProperty.call
78
+ /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
79
+ /******/
80
+ /******/ // __webpack_public_path__
81
+ /******/ __webpack_require__.p = "";
82
+ /******/
83
+ /******/
84
+ /******/ // Load entry module and return exports
85
+ /******/ return __webpack_require__(__webpack_require__.s = "KBg6");
86
+ /******/ })
87
+ /************************************************************************/
88
+ /******/ ({
89
+
90
+ /***/ "6Xvj":
91
+ /***/ (function(module, exports) {
92
+
93
+ module.exports = require("seller-base");
94
+
95
+ /***/ }),
96
+
97
+ /***/ "KBg6":
98
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
99
+
100
+ "use strict";
101
+ __webpack_require__.r(__webpack_exports__);
102
+
103
+ // EXTERNAL MODULE: external "seller-base"
104
+ var external_seller_base_ = __webpack_require__("6Xvj");
105
+
106
+ // CONCATENATED MODULE: ./src/modules/notification/service.ts
107
+ var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
108
+ function adopt(value) {
109
+ return value instanceof P ? value : new P(function (resolve) {
110
+ resolve(value);
111
+ });
112
+ }
113
+
114
+ return new (P || (P = Promise))(function (resolve, reject) {
115
+ function fulfilled(value) {
116
+ try {
117
+ step(generator.next(value));
118
+ } catch (e) {
119
+ reject(e);
120
+ }
121
+ }
122
+
123
+ function rejected(value) {
124
+ try {
125
+ step(generator["throw"](value));
126
+ } catch (e) {
127
+ reject(e);
128
+ }
129
+ }
130
+
131
+ function step(result) {
132
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
133
+ }
134
+
135
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
136
+ });
137
+ };
138
+
139
+
140
+
141
+ class service_NotificationService extends external_seller_base_["ServiceModule"] {
142
+ constructor(service) {
143
+ super(service);
144
+ this.name = 'notification';
145
+ service_NotificationService.$instance = this;
146
+ }
147
+ /**
148
+ * 获取notification 列表
149
+ * @see https://api.seller.shopee.io/project/1288/interface/api/39488
150
+ * @param params NotificationRequest
151
+ */
152
+
153
+
154
+ getNotificationList(params, config) {
155
+ return __awaiter(this, void 0, void 0, function* () {
156
+ return this.api.v1Request.get("/notification/list", {
157
+ params: external_seller_base_["Base"].Utility.snakeCaseKeys(params),
158
+ skipError: !!(config && config.skipError)
159
+ });
160
+ });
161
+ }
162
+ /**
163
+ * 标记所有为已读
164
+ * @see https://api.seller.shopee.io/project/1288/interface/api/39984
165
+ * @param data
166
+ */
167
+
168
+
169
+ markAllAsRead(data) {
170
+ return __awaiter(this, void 0, void 0, function* () {
171
+ return this.api.v1Request.post("/notification/mark_all_as_read", data);
172
+ });
173
+ }
174
+ /**
175
+ * 更新notification状态
176
+ * @see https://api.seller.shopee.io/project/1288/interface/api/39504
177
+ * @param data updateList: UpdateNotificationList[]
178
+ */
179
+
180
+
181
+ updateNotificationStatus(data) {
182
+ return __awaiter(this, void 0, void 0, function* () {
183
+ return this.api.v1Request.post("/notification/status", data);
184
+ });
185
+ }
186
+ /**
187
+ * 获取notification未读消息,包括下面folder
188
+ * @see https://api.seller.shopee.io/project/1288/interface/api/39496
189
+ * @param params NotificationCountsRequest
190
+ */
191
+
192
+
193
+ getNotificationCounts(params, config) {
194
+ return this.api.v1Request.get("/notification/count", {
195
+ skipError: config.skipError,
196
+ params
197
+ });
198
+ }
199
+ /**
200
+ * 拉取最新notification未读消息数量
201
+ * @see https://api.seller.shopee.io/project/1288/interface/api/39992
202
+ */
203
+
204
+
205
+ pullNotificationStatus() {
206
+ return this.api.v1Request.get("/notification/poll_status", {
207
+ skipError: true
208
+ });
209
+ }
210
+ /**
211
+ * 获取group信息
212
+ * @see https://api.seller.shopee.io/project/1288/interface/api/40000
213
+ * @param params: NotificationGroupRequest
214
+ */
215
+
216
+
217
+ getNotificationGroup(params) {
218
+ return this.api.v1Request.get("/notification/group", {
219
+ params: external_seller_base_["Base"].Utility.snakeCaseKeys(params)
220
+ });
221
+ }
222
+ /**
223
+ * 获取有权限的folder信息
224
+ * @see https://api.seller.shopee.io/project/1288/interface/api/42018
225
+ */
226
+
227
+
228
+ getFolders(config) {
229
+ return this.api.v1Request.get("/notification/folder", {
230
+ skipError: config.skipError
231
+ });
232
+ }
233
+
234
+ }
235
+ // CONCATENATED MODULE: ./src/modules/notification/types.ts
236
+ var Status;
237
+
238
+ (function (Status) {
239
+ Status[Status["UNREAD"] = 1] = "UNREAD";
240
+ Status[Status["READ"] = 2] = "READ";
241
+ Status[Status["DELETE"] = 3] = "DELETE";
242
+ })(Status || (Status = {}));
243
+ // CONCATENATED MODULE: ./src/modules/notification/constants.ts
244
+ const FoldersConfig = [{
245
+ to: '/portal/notification/',
246
+ folderKey: undefined,
247
+ type: null,
248
+ category: null,
249
+ transifyKey: 'sp_pc_notification_label_all_notification',
250
+ trackKey: 'all_notifications',
251
+ trackImpressionKey: 'all_notifications'
252
+ }, {
253
+ to: '/portal/notification/order-updates/',
254
+ folderKey: 'order-updates',
255
+ type: 1,
256
+ category: [17, 26],
257
+ transifyKey: 'sp_pc_notification_label_order_updates',
258
+ trackKey: 'order_updates',
259
+ trackImpressionKey: 'order_updates'
260
+ }, {
261
+ to: '/portal/notification/rating-updates/',
262
+ folderKey: 'rating-updates',
263
+ type: 2,
264
+ category: 18,
265
+ transifyKey: 'sp_pc_notification_label_rating_updates',
266
+ trackKey: 'rating',
267
+ trackImpressionKey: 'rating'
268
+ }, {
269
+ to: '/portal/notification/return-refund/',
270
+ folderKey: 'return-refund',
271
+ type: 3,
272
+ category: 19,
273
+ transifyKey: 'sp_pc_notification_label_return_and_refund_updates',
274
+ trackKey: 'return_refund',
275
+ trackImpressionKey: 'return_refund'
276
+ }, {
277
+ to: '/portal/notification/listing-updates/',
278
+ folderKey: 'listing-updates',
279
+ type: 4,
280
+ category: [20, 27],
281
+ transifyKey: 'sp_pc_notification_label_listing_updates',
282
+ trackKey: 'listing',
283
+ trackImpressionKey: 'listing'
284
+ }, {
285
+ to: '/portal/notification/sbs-updates/',
286
+ folderKey: 'sbs-updates',
287
+ type: 9,
288
+ category: [15, 16],
289
+ transifyKey: 'sp_pc_notification_label_sbs_updates',
290
+ trackKey: 'sbs_updates',
291
+ trackImpressionKey: 'sbs_updates'
292
+ }, {
293
+ to: '/portal/notification/wallet-updates/',
294
+ folderKey: 'wallet-updates',
295
+ type: 5,
296
+ category: [21, 28],
297
+ transifyKey: 'sp_pc_notification_label_wallet_updates',
298
+ trackKey: 'seller_wallet',
299
+ trackImpressionKey: 'seller_wallet'
300
+ }, {
301
+ to: '/portal/notification/marketing-center/',
302
+ folderKey: 'marketing-center',
303
+ type: 6,
304
+ category: [9, 14, 22],
305
+ transifyKey: 'sp_pc_notification_label_marketing_centre_updates',
306
+ trackKey: 'marketing_center',
307
+ trackImpressionKey: 'marketing_center'
308
+ }, {
309
+ to: '/portal/notification/performance/',
310
+ folderKey: 'performance',
311
+ type: 7,
312
+ category: [23, 29],
313
+ transifyKey: 'sp_pc_notification_label_performance_updates',
314
+ trackKey: 'perfomrance',
315
+ trackImpressionKey: 'perfomrance'
316
+ }, {
317
+ to: '/portal/notification/shopee-updates/',
318
+ folderKey: 'shopee-updates',
319
+ type: 8,
320
+ category: [6, 24, 30, 31],
321
+ transifyKey: 'sp_pc_notification_label_shopee_updates',
322
+ trackKey: 'shopee_updates',
323
+ trackImpressionKey: 'shopee_updates'
324
+ }];
325
+ const ActionTypes = {
326
+ NEW_ORDER: 1,
327
+ OUT_STOCK: 2,
328
+ DUP_LOGIN: 3,
329
+ INVALID_ITEM: 4,
330
+ ORDER_PAID: 5,
331
+ ORDER_COMPLETE: 7,
332
+ CHAT_MSG: 8,
333
+ NEW_ACTIVITY: 11,
334
+ OFFER_STATUS: 12,
335
+ NEW_ITEM: 14,
336
+ ORDER_CANCEL: 15,
337
+ BAN_ITEM: 16,
338
+ ACCOUNT_BAN: 17,
339
+ CHECKOUT_PAID: 18,
340
+ RETURN_UPDATE: 19,
341
+ CHECKOUT_CANCEL: 20,
342
+ CHECKOUT_UPDATE: 21,
343
+ ORDER_UPDATE: 22,
344
+ EMAIL_VERIFIED: 23,
345
+ ORDER_TOSHIP: 24,
346
+ ORDER_TORECEIVE: 25,
347
+ CHECKOUT_TOSHIP: 26,
348
+ USERINFO_UPDATEED: 27,
349
+ NEW_FEED: 28,
350
+ SHOPINFO_UPDATED: 29,
351
+ OUT_STOCK_VARIATION: 30,
352
+ ACCOUNT_FROZEN: 31,
353
+ ACCOUNT_UNFROZEN: 32,
354
+ CHAT_UPDATE: 33,
355
+ CART_UPDATE: 34,
356
+ CHAT_CLEARED: 35,
357
+ ACTION_REQUIRE_REMOVED: 36,
358
+ CHAT_UNREAD: 37,
359
+ // System Message notifications
360
+ ACTION_SYSTEM_MESSAGE: 99,
361
+ SELLER_PAY_CONFIRM: 100,
362
+ BUYER_UNDERPAY: 101,
363
+ BUYER_PAYER_VERI_FAIL: 102,
364
+ BUYER_CHECKOUT_CANCEL_UNDERPAY: 103,
365
+ SELLER_ORDER_CANCEL_NOPAY: 104,
366
+ BUYER_CHECKOUT_CANCEL_PAY_VERI_FAIL: 105,
367
+ BUYER_ORDER_CANCEL_NOPAY: 106,
368
+ BUYER_BEFORE_ESCROW_RELEASE: 107,
369
+ SELLER_ESCROW_EXTEND: 108,
370
+ BUYER_ORDER_CONFIRM_REMINDER: 109,
371
+ BUYER_ORDER_CANCEL_BANK: 110,
372
+ BUYER_ORDER_CANCEL_CARD: 111,
373
+ BUYER_REFUND_BANK: 112,
374
+ BUYER_REFUND_CARD: 113,
375
+ SELLER_RETURN_REQUEST: 114,
376
+ SELLER_BEFORE_RELEASE_REFUND: 115,
377
+ BUYER_DISPUTE: 116,
378
+ NEED_PROOF: 117,
379
+ SELLER_MEDIATION_RESULT: 118,
380
+ BUYER_OVERPAID_BANK: 119,
381
+ BUYER_NONRECEIPT_DISPUTE: 120,
382
+ SELLER_BANK_INFO: 121,
383
+ BUYER_REFUND_CREATED_BANK: 122,
384
+ SELLER_ORDER_CANCEL_BY_BUYER: 123,
385
+ BUYER_ORDER_SHIPPED: 124,
386
+ BUYER_REFUND_CREATED_CARD: 125,
387
+ SELLER_BANK_INFO_REMINDER: 126,
388
+ BUYER_BANK_INFO_REMINDER: 127,
389
+ BUYER_RETURN_APPROVED: 128,
390
+ BUYER_PAY_CONFIRM: 129,
391
+ BUYER_UNDERPAY_REMINDER: 130,
392
+ BUYER_NOPAY_REMINDER: 131,
393
+ SELLER_NEW_ORDER_ESCROW: 132,
394
+ SELLER_NEW_ORDER_OFFLINE: 133,
395
+ BUYER_BANNED_ITEM: 134,
396
+ BUYER_BEFORE_ESCROW_RELEASE_EXTEND: 135,
397
+ ORDER_COMPLETE_BANK: 136,
398
+ ORDER_COMPLETE_NO_BANK: 137,
399
+ SELLER_BANKINFO_REJECTED: 138,
400
+ BUYER_BANKINFO_REJECTED: 139,
401
+ SELLER_NONRECEIPT_RETURN_REQUEST: 140,
402
+ BUYER_NONRECEIPT_RETURN_REQUEST: 141,
403
+ BUYER_MEDIATION_RESULT: 142,
404
+ BUYER_NOTRECEIVE_RETUERN_DISPUTE: 143,
405
+ SELLER_NOTRECEIVE_RETUERN_DISPUTE: 144,
406
+ BUYER_REFUND_CREATED_BT: 145,
407
+ SELLER_ORDER_COMPLETE_OFFLINE: 146,
408
+ PROMO_CODE_GENERATED: 147,
409
+ CUSTOMIZED_ACTION: 148,
410
+ USER_BANKINFO_REJECTED: 149,
411
+ ORDER_CHANGE_OFFLINE_TO_ESCROW: 150,
412
+ CUSTOMIZED_ACTION_PURE: 151,
413
+ CUSTOMIZED_PUSHNOTI_PURE: 152,
414
+ // add for logistics
415
+ SELLER_NEW_ORDER_COD: 153,
416
+ ORDER_CHANGE_OFFLINE_TO_COD: 154,
417
+ BUYER_ORDER_COD_APPROVE: 155,
418
+ SELLER_ORDER_COD_APPROVE: 156,
419
+ BUYER_ORDER_COD_REJECT: 157,
420
+ SELLER_ORDER_COD_REJECT: 158,
421
+ BUYER_REJECT_COD_DELIVERY: 159,
422
+ BUYER_ORDER_CANCEL_COD: 160,
423
+ LOGISTICS_CONFIRMED_DELIVERY_BUYER: 161,
424
+ LOGISTICS_CONFIRMED_DELIVERY_SELLER: 162,
425
+ PICKUP_DEADLINE: 163,
426
+ SELLER_ORDER_CANCEL_PICKUP_FAILED: 164,
427
+ SELLER_REJECT_COD_DELIVERY: 165,
428
+ BUYER_REJECT_NOCOD_DELIVERY: 166,
429
+ SELLER_REJECT_NOCOD_DELIVERY: 167,
430
+ PICKUP_REMINDER: 168,
431
+ PICKUP_24HOURS: 169,
432
+ PICKUP_THEDAY: 170,
433
+ PICKUP_RETRY_BEFOREDEADLINE: 171,
434
+ SHIPOUT_24HOUR: 172,
435
+ SHIPOUT_DEADLINE: 173,
436
+ BUYER_SHIPPINGFEE_REVISED: 174,
437
+ BUYER_PICKUP_SUCCEED: 175,
438
+ BUYER_ORDER_COD_CANCEL_PICKUP_FAILED: 176,
439
+ BUYER_ORDER_NOCOD_CANCEL_PICKUP_FAILED: 177,
440
+ PICKUP_ARRANGED: 178,
441
+ SELLER_ORDER_CANCEL_ARRANGEPICKUP_FAIL: 179,
442
+ BUYER_ORDER_CANCEL_ARRANGEPICKUP_FAIL: 180,
443
+ SELLER_ARRANGEPICKUP_EXT_REMINDER: 181,
444
+ SELLER_ARRANGEPICKUP_DEADLINE_REMINDER: 182,
445
+ SHOP_DESCRIPTION_BANNED: 183,
446
+ SHOP_COVERS_BANNED: 184,
447
+ SELLER_INACTIVE_FIRST: 185,
448
+ SELLER_INACTIVE_SECOND: 186,
449
+ SELLER_PICKUP_COUNTER_CLOSE: 187,
450
+ BUYER_TW711_DELIVERED_COUNTER: 188,
451
+ SELLER_PAY_NOBANK_CONFIRM: 189,
452
+ BUYER_TW711_DELIVERED_REMINDER: 190,
453
+ SELLER_TW_COLLECT_NOBUYER: 191,
454
+ BUYER_FM_DELIVERED_COUNTER: 192,
455
+ SELLER_ORDER_CANCEL_AFTER_ESCROW: 193,
456
+ BUYER_ORDER_CANCEL_AFTER_ESCROW: 194,
457
+ BUYER_INDO_JOBRESUBMIT_WAYBILL: 195,
458
+ SELLER_RESELECT_COUNTER_COMPLETED: 196,
459
+ SELLER_DELIVERY_CODE_EXPIRED: 197,
460
+ BUYER_DELIVERY_DELAYED_VOUCHER: 198,
461
+ BUYER_RETURN_APPROVED_CARD: 199,
462
+ CRM_SELLER_INACTIVE_SEVEN: 401,
463
+ CRM_SELLER_INACTIVE_ELEVEN: 402,
464
+ CRM_SELLER_INACTIVE_FORTEEN: 403,
465
+ CRM_CHAT_REMINDER: 404,
466
+ CRM_OFFER_REMINDER: 405,
467
+ CRM_ORDER_REMINDER: 406,
468
+ CRM_ORDER_COD_REMINDER: 407,
469
+ BUYER_ORDER_CANCEL_NO_BANK: 408,
470
+ BUYER_RETURN_APPROVED_NO_BA: 409,
471
+ BUYER_COD_BANNED: 410,
472
+ BUYER_COD_RELEASED: 411,
473
+ SELLER_TW_TO_SHIP: 412,
474
+ SELLER_TW_TO_DROP: 413,
475
+ BUYER_ORDER_CANCEL_BY_BUYER: 414,
476
+ SMART_GROUP_MESSAGE: 415,
477
+ SELLER_ORDER_COMPLETE_RATING: 416,
478
+ BUYER_ORDER_COMPLETE_RATING: 417,
479
+ SELLER_RATING_3DAY: 418,
480
+ BUYER_RATING_3DAY: 419,
481
+ SELLER_RATING_BUYER_RATED: 420,
482
+ BUYER_RATING_SELLER_RATED: 421,
483
+ SELLER_VIEW_BOTH_RATED: 422,
484
+ SELLER_VIEW_BUYER_RATED: 432,
485
+ SELLER_VIEW_BUYER_CHANGED: 433,
486
+ SELLER_CONFIRM_AUTO_REFUND: 434,
487
+ SELLER_BE_CANCELORDER_REMINDER: 435,
488
+ BUYER_REFUND_PAYOUT_CARD: 436,
489
+ LOGISTICS_DELIVERY_FAILED_BUYER: 437,
490
+ SELLER_RETURN_PICKUPCOUNTER_CLOSE: 438,
491
+ SELLER_BE_AUTO_CANCEL: 439,
492
+ DISPUTE_RATING_SUCC: 440,
493
+ RATING_DISPUTED: 441,
494
+ CRM_BUYER_CART: 442,
495
+ CRM_BUYER_CART_STOCK: 443,
496
+ CRM_BUYER_CART_DISCOUNT: 444,
497
+ SELLER_FIRST_LISTING_TW: 445,
498
+ HM_SELLER_ARRANGE_PICKUP: 446,
499
+ HM_ORDER_AUTO_CANCEL: 447,
500
+ HM_SELLER_REMINDER_TO_SHIP: 448,
501
+ SELLER_ESCROW_RELEASED_ID_DAYS: 449,
502
+ BUYER_PUSH_SELLER_SO_COD: 450,
503
+ BUYER_PUSH_SELLER_SO_NONCOD: 451,
504
+ BUYER_CAN_CANCEL_REMINDER_NONCOD: 452,
505
+ BUYER_CAN_CANCEL_REMINDER_COD: 453,
506
+ SELLER_RETURN_RESELECT_TW_711: 741,
507
+ // trigger email & sms
508
+ BUYER_OFFER_DECLINE: 200,
509
+ BUYER_OFFER_ACCEPT: 201,
510
+ SELLER_OFFER_NEW: 202,
511
+ BUYER_PAY_CONFIRM_CARD: 203,
512
+ BUYER_RETURN_REQUEST: 204,
513
+ BUYER_PAY_CONFIRM_BANK: 206,
514
+ ACCOUNT_DELETE: 207,
515
+ PASSWORD_CHANGED: 208,
516
+ BUYER_PAY_CHOOSE_BANK: 209,
517
+ SELLER_ESCROW_RELEASED: 210,
518
+ SELLER_OFFER_CANCEL: 211,
519
+ SELLER_DISPUTE: 212,
520
+ SELLER_NONRECEIPT_DISPUTE: 213,
521
+ SELLER_ORDER_CANCEL: 214,
522
+ SELLER_CONFIRM_RETURN: 215,
523
+ SELLER_CANCEL_RETURN: 216,
524
+ BUYER_PAY_CONFIRM_OFFLINE: 217,
525
+ SELLER_FIRST_LISTING: 218,
526
+ SELLER_PAY_CONFIRM_OFFLINE: 219,
527
+ WEB_REGISTRATION: 220,
528
+ SELLER_CONTACT_LOGISTICS_TW: 221,
529
+ SELLER_ESCROW_RELEASED_ID: 222,
530
+ ACTIVITY_FOLLOW_YOU: 300,
531
+ ACTIVITY_AT_YOU_IN_COMMENT: 301,
532
+ ACTIVITY_COMMENT_YOUR_ITEM: 302,
533
+ ACTIVITY_CONTACT_REGISTERED: 303,
534
+ ACTIVITY_ITEM_RATED: 304,
535
+ ACTIVITY_CUSTOMIZED_ACTIVITY: 305,
536
+ ACTIVITY_AT_YOU_IN_FEED_CMT: 306,
537
+ ACTIVITY_COMMENT_YOUR_FEED: 307,
538
+ // ACTIVITY_S_VIEW_BOTH_RATED: 308,
539
+ ACTIVITY_B_VIEW_BOTH_RATED: 309,
540
+ // ACTIVITY_S_VIEW_BUYER_RATED: 310,
541
+ ACTIVITY_B_VIEW_SELLER_RATED: 311,
542
+ // ACTIVITY_S_VIEW_BUYER_CHANGED: 312,
543
+ ACTIVITY_B_VIEW_SELLER_CHANGED: 313,
544
+ SELLER_PENALTY_POINT: 551,
545
+ SELLER_PENALTY_TIER: 552,
546
+ SELLER_PENALTY_POINT_REMOVE: 554,
547
+ SELLER_BUYERCANCEL_REQUESTED: 520,
548
+ SELLER_BUYERCANCEL_WITHDRAW: 521,
549
+ SELLER_BUYERCANCEL_ACCEPT: 522,
550
+ SHOP_FLASHSALE_CANCELLED: 1027,
551
+ SHOP_FLASHSALE_PRODUCT_PROMOTED: 1028,
552
+ SHOP_FLASHSALE_PRODUCT_REJECTED: 1029,
553
+ SHOP_FLASHSALE_SHOP_REJECTED: 1030,
554
+ SHOP_FLASHSALE_CANCELLED_SG: 1037,
555
+ SHOP_FLASHSALE_PRODUCT_PROMOTED_SG: 1038,
556
+ SHOP_FLASHSALE_PRODUCT_REJECTED_SG: 1039,
557
+ SHOP_FLASHSALE_SHOP_REJECTED_SG: 1040,
558
+ SHOP_FLASHSALE_CANCELLED_MY: 1041,
559
+ SHOP_FLASHSALE_PRODUCT_PROMOTED_MY: 1042,
560
+ SHOP_FLASHSALE_PRODUCT_REJECTED_MY: 1043,
561
+ SHOP_FLASHSALE_SHOP_REJECTED_MY: 1044,
562
+ BUYER_MEDIATION_RESULT_DRC: 1118,
563
+ SELLER_MEDIATION_RESULT_DRC: 1119
564
+ };
565
+ const ActionRedirectTypes = {
566
+ REDIRECT_NONE: 0,
567
+ REDIRECT_ORDERS_DETAIL: 1,
568
+ REDIRECT_MY_PRODUCTS: 2,
569
+ REDIRECT_MY_INCOME: 3,
570
+ REDIRECT_ORDERS_RETURNREFUND: 4,
571
+ REDIRECT_ORDERS_CANCEL: 5,
572
+ REDIRECT_OUTOF_STOCK: 6,
573
+ // REDIRECT_REFUND_SELLERCANCEL: 7,
574
+ REDIRECT_PURE_REFUND: 8,
575
+ REDIRECT_NEW_WEB_PAGE: 10,
576
+ REDIRECT_UPLOAD_RECEIPT_PAGE: 11,
577
+ REDIRECT_SHOPING_CART: 12,
578
+ REDIRECT_BUNCH_ORDERS_DETAIL: 13,
579
+ // REDIRECT_BUY_PAGE: 14,
580
+ // REDIRECT_CHAT_PAGE: 15,
581
+ REDIRECT_ORDER_CHAT_PAGE: 16,
582
+ // REDIRECT_PRODUCT_OFFER_CHAT_PAGE: 17,
583
+ REDIRECT_RELATED_PRODUCT_PAGE: 18,
584
+ REDIRECT_CREDIT_CARD_PAYMENT_PAGE: 19,
585
+ REDIRECT_MY_WALLET: 20,
586
+ REDIRECT_EDIT_SHOP_PROFILE: 21,
587
+ REDIRECT_APP_PATH: 22,
588
+ REDIRECT_MY_ACCOUNT: 23
589
+ };
590
+ const AppPath = {
591
+ CHAT_LIST: 'chatList',
592
+ MY_ACCOUNT: 'myAccount',
593
+ EDIT_PROFILE: 'editProfile',
594
+ SOCIAL_ACCOUNT: 'socialAccount',
595
+ SETTINGS: 'settings',
596
+ HOME_FEEDS: 'homeFeed',
597
+ HOME: 'home',
598
+ CHAT: 'chat',
599
+ INCOME: 'income',
600
+ SELLER_ASSISTANT: 'sellerAssistant',
601
+ NOTIFICATION: 'notification',
602
+ PENALTY: 'penalty'
603
+ };
604
+ const RedirectTypePreferred = [ActionRedirectTypes.REDIRECT_APP_PATH, ActionRedirectTypes.REDIRECT_BUNCH_ORDERS_DETAIL, ActionRedirectTypes.REDIRECT_PURE_REFUND];
605
+ const ActionCategory = {
606
+ ORDER_UPDATES: [17, 26],
607
+ RATING: 18,
608
+ RETURN_AND_REFUND: 19,
609
+ LISTING_UPDATES: [20, 27],
610
+ SBS_UPDATES: [15, 16],
611
+ SELLER_WALLET: [21, 28],
612
+ MARKETING_CENTER: [9, 14, 22],
613
+ PERFORMANCE: [23, 29],
614
+ SHOPEE_UPDATES: [6, 24, 30, 31]
615
+ };
616
+ const FoldersType = {
617
+ ORDER_UPDATES: 1,
618
+ RATING: 2,
619
+ RETURN_AND_REFUND: 3,
620
+ LISTING_UPDATES: 4,
621
+ SELLER_WALLET: 5,
622
+ MARKETING_CENTER: 6,
623
+ PERFORMANCE: 7,
624
+ SHOPEE_UPDATES: 8,
625
+ SBS_UPDATES: 9
626
+ };
627
+ var NotiEventNames;
628
+
629
+ (function (NotiEventNames) {
630
+ NotiEventNames["MarkAllHeaderNotiAsRead"] = "HeaderMarkAllAsRead";
631
+ NotiEventNames["MarkAllNotiAsRead"] = "NotiMarkAllAsRead";
632
+ NotiEventNames["MarkNotiAsRead"] = "MarkNotiAsRead";
633
+ NotiEventNames["MarkHeaderNotiAsRead"] = "MarkHeaderNotiAsRead";
634
+ NotiEventNames["NotiCountsChange"] = "NotiCountsChange";
635
+ NotiEventNames["HeaderNotiCountsChange"] = "HeaderNotiCountsChange";
636
+ })(NotiEventNames || (NotiEventNames = {}));
637
+ // EXTERNAL MODULE: ./node_modules/big-integer/BigInteger.js
638
+ var BigInteger = __webpack_require__("dAlA");
639
+ var BigInteger_default = /*#__PURE__*/__webpack_require__.n(BigInteger);
640
+
641
+ // CONCATENATED MODULE: ./src/modules/notification/action.ts
642
+
643
+
644
+
645
+ function replaceUrl(url, action) {
646
+ return url.replace('${PC_MALL_ORIGIN}', external_seller_base_["Base"].$instance.environment.pcMallOrigin).replace('${SELLER_ORIGIN}', external_seller_base_["Base"].$instance.environment.sellerOrigin).replace('${MALL_ORIGIN}', external_seller_base_["Base"].$instance.environment.mallOrigin).replace('${CHECKOUT_ID}', "".concat(action.idInfo.checkoutId)).replace('${ITEM_ID}', "".concat(action.idInfo.itemId)).replace('${BUYER_USER_ID}', "".concat(action.idInfo.userid)).replace('${ORDER_ID}', "".concat(action.idInfo.orderId)).replace('${SHOP_ID}', "".concat(action.idInfo.shopid)).replace('${RETURN_ID || REFUND_ID}', "".concat(action.idInfo.returnId || action.idInfo.refundId));
647
+ }
648
+ function clickable(action) {
649
+ if (!!action.pcRedirectUrl) {
650
+ return true;
651
+ }
652
+
653
+ const redirectType = action.actionRedirectType;
654
+
655
+ if (redirectType === ActionRedirectTypes.REDIRECT_NEW_WEB_PAGE) {
656
+ // special case: penalty redirection
657
+ if ([ActionTypes.SELLER_PENALTY_POINT, ActionTypes.SELLER_PENALTY_TIER, ActionTypes.SELLER_PENALTY_POINT_REMOVE].includes(action.actionType)) {
658
+ return clickableByActionType(action);
659
+ } // special case: bridge_cmd redirection
660
+
661
+
662
+ if (action.actionRedirectUrl && !action.actionRedirectUrl.includes('bridge_cmd')) {
663
+ return true;
664
+ }
665
+
666
+ return clickableByActionType(action);
667
+ }
668
+
669
+ if (RedirectTypePreferred.includes(redirectType)) {
670
+ return clickableByRedirectType(action);
671
+ }
672
+
673
+ let ret = clickableByActionType(action);
674
+
675
+ if (ret === false) {
676
+ ret = clickableByRedirectType(action);
677
+ }
678
+
679
+ return ret;
680
+ }
681
+ function clickableByActionType(action) {
682
+ if (action.actionTypeRedirectUrl) {
683
+ return true;
684
+ }
685
+
686
+ if (Object.values(ActionTypes).includes(action.actionType)) {
687
+ return;
688
+ }
689
+
690
+ return false;
691
+ }
692
+ function clickableByRedirectType(action) {
693
+ if (action.actionRedirectType === ActionRedirectTypes.REDIRECT_ORDER_CHAT_PAGE || action.redirectActionTypeRedirectUrl) {
694
+ return true;
695
+ } else if (action.actionRedirectType === ActionRedirectTypes.REDIRECT_APP_PATH) {
696
+ return clickableByAppPath(action);
697
+ }
698
+ }
699
+ function clickableByAppPath(action) {
700
+ if (action.actionAppPath === AppPath.CHAT || action.appPathRedirectUrl) {
701
+ return true;
702
+ }
703
+
704
+ return false;
705
+ }
706
+
707
+ const getRedirectURL = url => {
708
+ const isCB = external_seller_base_["Base"].$instance.environment.isCBSC || external_seller_base_["Base"].$instance.environment.isMainland;
709
+
710
+ if (!isCB) {
711
+ return url;
712
+ }
713
+
714
+ try {
715
+ const urlObject = new URL(url);
716
+ const env = '(test|uat|staging|live-test|test-stable)?\\.?';
717
+
718
+ if (new RegExp("^mall\\.".concat(env, "shopee\\.")).test(urlObject.hostname)) {
719
+ urlObject.hostname = new URL(external_seller_base_["Base"].$instance.environment.mallOrigin).hostname;
720
+ } else if (new RegExp("^".concat(env, "shopee\\.")).test(urlObject.hostname)) {
721
+ urlObject.hostname = new URL(external_seller_base_["Base"].$instance.environment.sellerOrigin).hostname;
722
+ } else if (new RegExp("^(seller|banhang)\\.".concat(env, "shopee\\.")).test(urlObject.hostname)) {
723
+ urlObject.hostname = new URL(external_seller_base_["Base"].$instance.environment.pcMallOrigin).hostname;
724
+ }
725
+
726
+ return urlObject.toString();
727
+ } catch (e) {
728
+ console.error('getRedirectURL', e);
729
+ return url;
730
+ }
731
+ };
732
+
733
+ function redirect(action, chatProxyService) {
734
+ if (!!action.pcRedirectUrl) {
735
+ const url = getRedirectURL(action.pcRedirectUrl);
736
+ window.open(url);
737
+ return;
738
+ }
739
+
740
+ const redirectType = action.actionRedirectType;
741
+
742
+ if (redirectType === ActionRedirectTypes.REDIRECT_NEW_WEB_PAGE) {
743
+ // special case: penalty redirection
744
+ if ([ActionTypes.SELLER_PENALTY_POINT, ActionTypes.SELLER_PENALTY_TIER, ActionTypes.SELLER_PENALTY_POINT_REMOVE].includes(action.actionType)) {
745
+ redirectByActionType(action);
746
+ return;
747
+ } // special case: bridge_cmd redirection
748
+
749
+
750
+ if (action.actionRedirectUrl && !action.actionRedirectUrl.includes('bridge_cmd')) {
751
+ const url = getRedirectURL(action.actionRedirectUrl);
752
+ window.open(url);
753
+ return;
754
+ } else {
755
+ if (action.actionTypeRedirectUrl) {
756
+ window.open(replaceUrl(action.actionTypeRedirectUrl, action));
757
+ }
758
+ }
759
+
760
+ return;
761
+ }
762
+
763
+ if (RedirectTypePreferred.includes(action.actionRedirectType)) {
764
+ return redirectByRedirectType(action, chatProxyService);
765
+ }
766
+
767
+ const ret = redirectByActionType(action);
768
+
769
+ if (ret === false) {
770
+ redirectByRedirectType(action, chatProxyService);
771
+ }
772
+ }
773
+
774
+ function redirectByActionType(action) {
775
+ if (action.actionTypeRedirectUrl) {
776
+ return window.open(replaceUrl(action.actionTypeRedirectUrl, action));
777
+ }
778
+
779
+ if (Object.values(ActionTypes).includes(action.actionType)) {
780
+ return;
781
+ }
782
+
783
+ return false;
784
+ }
785
+
786
+ function redirectByRedirectType(action, chatProxyService) {
787
+ const {
788
+ orderId,
789
+ shopid,
790
+ buyerId
791
+ } = action.idInfo;
792
+
793
+ if (action.actionRedirectType === ActionRedirectTypes.REDIRECT_ORDER_CHAT_PAGE) {
794
+ chatProxyService.startChatWithOrder(shopid, buyerId, orderId);
795
+ } else if (action.actionRedirectType === ActionRedirectTypes.REDIRECT_APP_PATH) {
796
+ redirectByAppPath(action, chatProxyService);
797
+ } else if (action.redirectActionTypeRedirectUrl) {
798
+ window.open(replaceUrl(action.redirectActionTypeRedirectUrl, action));
799
+ }
800
+ }
801
+
802
+ function redirectByAppPath(action, chatProxyService) {
803
+ if (action.actionAppPath === AppPath.CHAT) {
804
+ const {
805
+ shopid,
806
+ userid,
807
+ buyerId,
808
+ orderId
809
+ } = action.idInfo;
810
+ chatProxyService.startChatWithOrder(shopid, userid || buyerId, orderId);
811
+ } else if (action.appPathRedirectUrl) {
812
+ window.open(replaceUrl(action.appPathRedirectUrl, action));
813
+ }
814
+ }
815
+
816
+ function compileAction(action) {
817
+ return {
818
+ id: action.actionId,
819
+ title: action.title,
820
+ content: action.content,
821
+ images: action.images,
822
+ groupId: action.groupId,
823
+ groupCount: action.groupCount,
824
+ status: action.status,
825
+ type: action.type,
826
+ clickable: !!clickable(action),
827
+ idInfo: action.idInfo,
828
+ actionCate: action.actionCate,
829
+ actionType: action.actionType,
830
+ traceId: action.traceId,
831
+ timestamp: action.timestamp,
832
+ actionRedirectType: action.actionRedirectType,
833
+ actionRedirectUrl: action.actionRedirectUrl,
834
+ actionTypeRedirectUrl: action.actionTypeRedirectUrl,
835
+ appPathRedirectUrl: action.appPathRedirectUrl,
836
+ redirectActionTypeRedirectUrl: action.redirectActionTypeRedirectUrl,
837
+ pcRedirectUrl: action.pcRedirectUrl,
838
+ actionAppPath: action.actionAppPath,
839
+
840
+ action(action, chatProxyService) {
841
+ if (!ActionCategory.MARKETING_CENTER.includes(action.actionCate) || action.actionRedirectUrl) {
842
+ return redirect(action, chatProxyService);
843
+ }
844
+ }
845
+
846
+ };
847
+ }
848
+ function getMaxActionId(notificationList) {
849
+ const actionIds = notificationList.map(item => BigInteger_default()(item.id));
850
+ return actionIds.reduce((prev, next) => {
851
+ if (prev.compareTo(next) < 0) {
852
+ return next;
853
+ }
854
+
855
+ return prev;
856
+ });
857
+ }
858
+ // CONCATENATED MODULE: ./src/modules/notification/index.ts
859
+ /* concated harmony reexport NotificationService */__webpack_require__.d(__webpack_exports__, "NotificationService", function() { return service_NotificationService; });
860
+ /* concated harmony reexport CompiledNotification */__webpack_require__.d(__webpack_exports__, "CompiledNotification", function() { return /* Cannot get final name for export "CompiledNotification" in "./src/modules/notification/types.ts" (known exports: Status, known reexports: ) */ undefined; });
861
+ /* concated harmony reexport Notification */__webpack_require__.d(__webpack_exports__, "Notification", function() { return /* Cannot get final name for export "Notification" in "./src/modules/notification/types.ts" (known exports: Status, known reexports: ) */ undefined; });
862
+ /* concated harmony reexport Counts */__webpack_require__.d(__webpack_exports__, "Counts", function() { return /* Cannot get final name for export "Counts" in "./src/modules/notification/types.ts" (known exports: Status, known reexports: ) */ undefined; });
863
+ /* concated harmony reexport Status */__webpack_require__.d(__webpack_exports__, "Status", function() { return Status; });
864
+ /* concated harmony reexport NotificationGroupRequest */__webpack_require__.d(__webpack_exports__, "NotificationGroupRequest", function() { return /* Cannot get final name for export "NotificationGroupRequest" in "./src/modules/notification/types.ts" (known exports: Status, known reexports: ) */ undefined; });
865
+ /* concated harmony reexport UpdateNotificationList */__webpack_require__.d(__webpack_exports__, "UpdateNotificationList", function() { return /* Cannot get final name for export "UpdateNotificationList" in "./src/modules/notification/types.ts" (known exports: Status, known reexports: ) */ undefined; });
866
+ /* concated harmony reexport NotificationRequest */__webpack_require__.d(__webpack_exports__, "NotificationRequest", function() { return /* Cannot get final name for export "NotificationRequest" in "./src/modules/notification/types.ts" (known exports: Status, known reexports: ) */ undefined; });
867
+ /* concated harmony reexport TrackData */__webpack_require__.d(__webpack_exports__, "TrackData", function() { return /* Cannot get final name for export "TrackData" in "./src/modules/notification/types.ts" (known exports: Status, known reexports: ) */ undefined; });
868
+ /* concated harmony reexport FoldersConfig */__webpack_require__.d(__webpack_exports__, "FoldersConfig", function() { return FoldersConfig; });
869
+ /* concated harmony reexport ActionCategory */__webpack_require__.d(__webpack_exports__, "ActionCategory", function() { return ActionCategory; });
870
+ /* concated harmony reexport FoldersType */__webpack_require__.d(__webpack_exports__, "FoldersType", function() { return FoldersType; });
871
+ /* concated harmony reexport NotiEventNames */__webpack_require__.d(__webpack_exports__, "NotiEventNames", function() { return NotiEventNames; });
872
+ /* concated harmony reexport compileAction */__webpack_require__.d(__webpack_exports__, "compileAction", function() { return compileAction; });
873
+ /* concated harmony reexport getMaxActionId */__webpack_require__.d(__webpack_exports__, "getMaxActionId", function() { return getMaxActionId; });
874
+
875
+
876
+
877
+
878
+
879
+ /***/ }),
880
+
881
+ /***/ "dAlA":
882
+ /***/ (function(module, exports, __webpack_require__) {
883
+
884
+ /* WEBPACK VAR INJECTION */(function(module) {var __WEBPACK_AMD_DEFINE_RESULT__;var bigInt = (function (undefined) {
885
+ "use strict";
886
+
887
+ var BASE = 1e7,
888
+ LOG_BASE = 7,
889
+ MAX_INT = 9007199254740992,
890
+ MAX_INT_ARR = smallToArray(MAX_INT),
891
+ DEFAULT_ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz";
892
+
893
+ var supportsNativeBigInt = typeof BigInt === "function";
894
+
895
+ function Integer(v, radix, alphabet, caseSensitive) {
896
+ if (typeof v === "undefined") return Integer[0];
897
+ if (typeof radix !== "undefined") return +radix === 10 && !alphabet ? parseValue(v) : parseBase(v, radix, alphabet, caseSensitive);
898
+ return parseValue(v);
899
+ }
900
+
901
+ function BigInteger(value, sign) {
902
+ this.value = value;
903
+ this.sign = sign;
904
+ this.isSmall = false;
905
+ }
906
+ BigInteger.prototype = Object.create(Integer.prototype);
907
+
908
+ function SmallInteger(value) {
909
+ this.value = value;
910
+ this.sign = value < 0;
911
+ this.isSmall = true;
912
+ }
913
+ SmallInteger.prototype = Object.create(Integer.prototype);
914
+
915
+ function NativeBigInt(value) {
916
+ this.value = value;
917
+ }
918
+ NativeBigInt.prototype = Object.create(Integer.prototype);
919
+
920
+ function isPrecise(n) {
921
+ return -MAX_INT < n && n < MAX_INT;
922
+ }
923
+
924
+ function smallToArray(n) { // For performance reasons doesn't reference BASE, need to change this function if BASE changes
925
+ if (n < 1e7)
926
+ return [n];
927
+ if (n < 1e14)
928
+ return [n % 1e7, Math.floor(n / 1e7)];
929
+ return [n % 1e7, Math.floor(n / 1e7) % 1e7, Math.floor(n / 1e14)];
930
+ }
931
+
932
+ function arrayToSmall(arr) { // If BASE changes this function may need to change
933
+ trim(arr);
934
+ var length = arr.length;
935
+ if (length < 4 && compareAbs(arr, MAX_INT_ARR) < 0) {
936
+ switch (length) {
937
+ case 0: return 0;
938
+ case 1: return arr[0];
939
+ case 2: return arr[0] + arr[1] * BASE;
940
+ default: return arr[0] + (arr[1] + arr[2] * BASE) * BASE;
941
+ }
942
+ }
943
+ return arr;
944
+ }
945
+
946
+ function trim(v) {
947
+ var i = v.length;
948
+ while (v[--i] === 0);
949
+ v.length = i + 1;
950
+ }
951
+
952
+ function createArray(length) { // function shamelessly stolen from Yaffle's library https://github.com/Yaffle/BigInteger
953
+ var x = new Array(length);
954
+ var i = -1;
955
+ while (++i < length) {
956
+ x[i] = 0;
957
+ }
958
+ return x;
959
+ }
960
+
961
+ function truncate(n) {
962
+ if (n > 0) return Math.floor(n);
963
+ return Math.ceil(n);
964
+ }
965
+
966
+ function add(a, b) { // assumes a and b are arrays with a.length >= b.length
967
+ var l_a = a.length,
968
+ l_b = b.length,
969
+ r = new Array(l_a),
970
+ carry = 0,
971
+ base = BASE,
972
+ sum, i;
973
+ for (i = 0; i < l_b; i++) {
974
+ sum = a[i] + b[i] + carry;
975
+ carry = sum >= base ? 1 : 0;
976
+ r[i] = sum - carry * base;
977
+ }
978
+ while (i < l_a) {
979
+ sum = a[i] + carry;
980
+ carry = sum === base ? 1 : 0;
981
+ r[i++] = sum - carry * base;
982
+ }
983
+ if (carry > 0) r.push(carry);
984
+ return r;
985
+ }
986
+
987
+ function addAny(a, b) {
988
+ if (a.length >= b.length) return add(a, b);
989
+ return add(b, a);
990
+ }
991
+
992
+ function addSmall(a, carry) { // assumes a is array, carry is number with 0 <= carry < MAX_INT
993
+ var l = a.length,
994
+ r = new Array(l),
995
+ base = BASE,
996
+ sum, i;
997
+ for (i = 0; i < l; i++) {
998
+ sum = a[i] - base + carry;
999
+ carry = Math.floor(sum / base);
1000
+ r[i] = sum - carry * base;
1001
+ carry += 1;
1002
+ }
1003
+ while (carry > 0) {
1004
+ r[i++] = carry % base;
1005
+ carry = Math.floor(carry / base);
1006
+ }
1007
+ return r;
1008
+ }
1009
+
1010
+ BigInteger.prototype.add = function (v) {
1011
+ var n = parseValue(v);
1012
+ if (this.sign !== n.sign) {
1013
+ return this.subtract(n.negate());
1014
+ }
1015
+ var a = this.value, b = n.value;
1016
+ if (n.isSmall) {
1017
+ return new BigInteger(addSmall(a, Math.abs(b)), this.sign);
1018
+ }
1019
+ return new BigInteger(addAny(a, b), this.sign);
1020
+ };
1021
+ BigInteger.prototype.plus = BigInteger.prototype.add;
1022
+
1023
+ SmallInteger.prototype.add = function (v) {
1024
+ var n = parseValue(v);
1025
+ var a = this.value;
1026
+ if (a < 0 !== n.sign) {
1027
+ return this.subtract(n.negate());
1028
+ }
1029
+ var b = n.value;
1030
+ if (n.isSmall) {
1031
+ if (isPrecise(a + b)) return new SmallInteger(a + b);
1032
+ b = smallToArray(Math.abs(b));
1033
+ }
1034
+ return new BigInteger(addSmall(b, Math.abs(a)), a < 0);
1035
+ };
1036
+ SmallInteger.prototype.plus = SmallInteger.prototype.add;
1037
+
1038
+ NativeBigInt.prototype.add = function (v) {
1039
+ return new NativeBigInt(this.value + parseValue(v).value);
1040
+ }
1041
+ NativeBigInt.prototype.plus = NativeBigInt.prototype.add;
1042
+
1043
+ function subtract(a, b) { // assumes a and b are arrays with a >= b
1044
+ var a_l = a.length,
1045
+ b_l = b.length,
1046
+ r = new Array(a_l),
1047
+ borrow = 0,
1048
+ base = BASE,
1049
+ i, difference;
1050
+ for (i = 0; i < b_l; i++) {
1051
+ difference = a[i] - borrow - b[i];
1052
+ if (difference < 0) {
1053
+ difference += base;
1054
+ borrow = 1;
1055
+ } else borrow = 0;
1056
+ r[i] = difference;
1057
+ }
1058
+ for (i = b_l; i < a_l; i++) {
1059
+ difference = a[i] - borrow;
1060
+ if (difference < 0) difference += base;
1061
+ else {
1062
+ r[i++] = difference;
1063
+ break;
1064
+ }
1065
+ r[i] = difference;
1066
+ }
1067
+ for (; i < a_l; i++) {
1068
+ r[i] = a[i];
1069
+ }
1070
+ trim(r);
1071
+ return r;
1072
+ }
1073
+
1074
+ function subtractAny(a, b, sign) {
1075
+ var value;
1076
+ if (compareAbs(a, b) >= 0) {
1077
+ value = subtract(a, b);
1078
+ } else {
1079
+ value = subtract(b, a);
1080
+ sign = !sign;
1081
+ }
1082
+ value = arrayToSmall(value);
1083
+ if (typeof value === "number") {
1084
+ if (sign) value = -value;
1085
+ return new SmallInteger(value);
1086
+ }
1087
+ return new BigInteger(value, sign);
1088
+ }
1089
+
1090
+ function subtractSmall(a, b, sign) { // assumes a is array, b is number with 0 <= b < MAX_INT
1091
+ var l = a.length,
1092
+ r = new Array(l),
1093
+ carry = -b,
1094
+ base = BASE,
1095
+ i, difference;
1096
+ for (i = 0; i < l; i++) {
1097
+ difference = a[i] + carry;
1098
+ carry = Math.floor(difference / base);
1099
+ difference %= base;
1100
+ r[i] = difference < 0 ? difference + base : difference;
1101
+ }
1102
+ r = arrayToSmall(r);
1103
+ if (typeof r === "number") {
1104
+ if (sign) r = -r;
1105
+ return new SmallInteger(r);
1106
+ } return new BigInteger(r, sign);
1107
+ }
1108
+
1109
+ BigInteger.prototype.subtract = function (v) {
1110
+ var n = parseValue(v);
1111
+ if (this.sign !== n.sign) {
1112
+ return this.add(n.negate());
1113
+ }
1114
+ var a = this.value, b = n.value;
1115
+ if (n.isSmall)
1116
+ return subtractSmall(a, Math.abs(b), this.sign);
1117
+ return subtractAny(a, b, this.sign);
1118
+ };
1119
+ BigInteger.prototype.minus = BigInteger.prototype.subtract;
1120
+
1121
+ SmallInteger.prototype.subtract = function (v) {
1122
+ var n = parseValue(v);
1123
+ var a = this.value;
1124
+ if (a < 0 !== n.sign) {
1125
+ return this.add(n.negate());
1126
+ }
1127
+ var b = n.value;
1128
+ if (n.isSmall) {
1129
+ return new SmallInteger(a - b);
1130
+ }
1131
+ return subtractSmall(b, Math.abs(a), a >= 0);
1132
+ };
1133
+ SmallInteger.prototype.minus = SmallInteger.prototype.subtract;
1134
+
1135
+ NativeBigInt.prototype.subtract = function (v) {
1136
+ return new NativeBigInt(this.value - parseValue(v).value);
1137
+ }
1138
+ NativeBigInt.prototype.minus = NativeBigInt.prototype.subtract;
1139
+
1140
+ BigInteger.prototype.negate = function () {
1141
+ return new BigInteger(this.value, !this.sign);
1142
+ };
1143
+ SmallInteger.prototype.negate = function () {
1144
+ var sign = this.sign;
1145
+ var small = new SmallInteger(-this.value);
1146
+ small.sign = !sign;
1147
+ return small;
1148
+ };
1149
+ NativeBigInt.prototype.negate = function () {
1150
+ return new NativeBigInt(-this.value);
1151
+ }
1152
+
1153
+ BigInteger.prototype.abs = function () {
1154
+ return new BigInteger(this.value, false);
1155
+ };
1156
+ SmallInteger.prototype.abs = function () {
1157
+ return new SmallInteger(Math.abs(this.value));
1158
+ };
1159
+ NativeBigInt.prototype.abs = function () {
1160
+ return new NativeBigInt(this.value >= 0 ? this.value : -this.value);
1161
+ }
1162
+
1163
+
1164
+ function multiplyLong(a, b) {
1165
+ var a_l = a.length,
1166
+ b_l = b.length,
1167
+ l = a_l + b_l,
1168
+ r = createArray(l),
1169
+ base = BASE,
1170
+ product, carry, i, a_i, b_j;
1171
+ for (i = 0; i < a_l; ++i) {
1172
+ a_i = a[i];
1173
+ for (var j = 0; j < b_l; ++j) {
1174
+ b_j = b[j];
1175
+ product = a_i * b_j + r[i + j];
1176
+ carry = Math.floor(product / base);
1177
+ r[i + j] = product - carry * base;
1178
+ r[i + j + 1] += carry;
1179
+ }
1180
+ }
1181
+ trim(r);
1182
+ return r;
1183
+ }
1184
+
1185
+ function multiplySmall(a, b) { // assumes a is array, b is number with |b| < BASE
1186
+ var l = a.length,
1187
+ r = new Array(l),
1188
+ base = BASE,
1189
+ carry = 0,
1190
+ product, i;
1191
+ for (i = 0; i < l; i++) {
1192
+ product = a[i] * b + carry;
1193
+ carry = Math.floor(product / base);
1194
+ r[i] = product - carry * base;
1195
+ }
1196
+ while (carry > 0) {
1197
+ r[i++] = carry % base;
1198
+ carry = Math.floor(carry / base);
1199
+ }
1200
+ return r;
1201
+ }
1202
+
1203
+ function shiftLeft(x, n) {
1204
+ var r = [];
1205
+ while (n-- > 0) r.push(0);
1206
+ return r.concat(x);
1207
+ }
1208
+
1209
+ function multiplyKaratsuba(x, y) {
1210
+ var n = Math.max(x.length, y.length);
1211
+
1212
+ if (n <= 30) return multiplyLong(x, y);
1213
+ n = Math.ceil(n / 2);
1214
+
1215
+ var b = x.slice(n),
1216
+ a = x.slice(0, n),
1217
+ d = y.slice(n),
1218
+ c = y.slice(0, n);
1219
+
1220
+ var ac = multiplyKaratsuba(a, c),
1221
+ bd = multiplyKaratsuba(b, d),
1222
+ abcd = multiplyKaratsuba(addAny(a, b), addAny(c, d));
1223
+
1224
+ var product = addAny(addAny(ac, shiftLeft(subtract(subtract(abcd, ac), bd), n)), shiftLeft(bd, 2 * n));
1225
+ trim(product);
1226
+ return product;
1227
+ }
1228
+
1229
+ // The following function is derived from a surface fit of a graph plotting the performance difference
1230
+ // between long multiplication and karatsuba multiplication versus the lengths of the two arrays.
1231
+ function useKaratsuba(l1, l2) {
1232
+ return -0.012 * l1 - 0.012 * l2 + 0.000015 * l1 * l2 > 0;
1233
+ }
1234
+
1235
+ BigInteger.prototype.multiply = function (v) {
1236
+ var n = parseValue(v),
1237
+ a = this.value, b = n.value,
1238
+ sign = this.sign !== n.sign,
1239
+ abs;
1240
+ if (n.isSmall) {
1241
+ if (b === 0) return Integer[0];
1242
+ if (b === 1) return this;
1243
+ if (b === -1) return this.negate();
1244
+ abs = Math.abs(b);
1245
+ if (abs < BASE) {
1246
+ return new BigInteger(multiplySmall(a, abs), sign);
1247
+ }
1248
+ b = smallToArray(abs);
1249
+ }
1250
+ if (useKaratsuba(a.length, b.length)) // Karatsuba is only faster for certain array sizes
1251
+ return new BigInteger(multiplyKaratsuba(a, b), sign);
1252
+ return new BigInteger(multiplyLong(a, b), sign);
1253
+ };
1254
+
1255
+ BigInteger.prototype.times = BigInteger.prototype.multiply;
1256
+
1257
+ function multiplySmallAndArray(a, b, sign) { // a >= 0
1258
+ if (a < BASE) {
1259
+ return new BigInteger(multiplySmall(b, a), sign);
1260
+ }
1261
+ return new BigInteger(multiplyLong(b, smallToArray(a)), sign);
1262
+ }
1263
+ SmallInteger.prototype._multiplyBySmall = function (a) {
1264
+ if (isPrecise(a.value * this.value)) {
1265
+ return new SmallInteger(a.value * this.value);
1266
+ }
1267
+ return multiplySmallAndArray(Math.abs(a.value), smallToArray(Math.abs(this.value)), this.sign !== a.sign);
1268
+ };
1269
+ BigInteger.prototype._multiplyBySmall = function (a) {
1270
+ if (a.value === 0) return Integer[0];
1271
+ if (a.value === 1) return this;
1272
+ if (a.value === -1) return this.negate();
1273
+ return multiplySmallAndArray(Math.abs(a.value), this.value, this.sign !== a.sign);
1274
+ };
1275
+ SmallInteger.prototype.multiply = function (v) {
1276
+ return parseValue(v)._multiplyBySmall(this);
1277
+ };
1278
+ SmallInteger.prototype.times = SmallInteger.prototype.multiply;
1279
+
1280
+ NativeBigInt.prototype.multiply = function (v) {
1281
+ return new NativeBigInt(this.value * parseValue(v).value);
1282
+ }
1283
+ NativeBigInt.prototype.times = NativeBigInt.prototype.multiply;
1284
+
1285
+ function square(a) {
1286
+ //console.assert(2 * BASE * BASE < MAX_INT);
1287
+ var l = a.length,
1288
+ r = createArray(l + l),
1289
+ base = BASE,
1290
+ product, carry, i, a_i, a_j;
1291
+ for (i = 0; i < l; i++) {
1292
+ a_i = a[i];
1293
+ carry = 0 - a_i * a_i;
1294
+ for (var j = i; j < l; j++) {
1295
+ a_j = a[j];
1296
+ product = 2 * (a_i * a_j) + r[i + j] + carry;
1297
+ carry = Math.floor(product / base);
1298
+ r[i + j] = product - carry * base;
1299
+ }
1300
+ r[i + l] = carry;
1301
+ }
1302
+ trim(r);
1303
+ return r;
1304
+ }
1305
+
1306
+ BigInteger.prototype.square = function () {
1307
+ return new BigInteger(square(this.value), false);
1308
+ };
1309
+
1310
+ SmallInteger.prototype.square = function () {
1311
+ var value = this.value * this.value;
1312
+ if (isPrecise(value)) return new SmallInteger(value);
1313
+ return new BigInteger(square(smallToArray(Math.abs(this.value))), false);
1314
+ };
1315
+
1316
+ NativeBigInt.prototype.square = function (v) {
1317
+ return new NativeBigInt(this.value * this.value);
1318
+ }
1319
+
1320
+ function divMod1(a, b) { // Left over from previous version. Performs faster than divMod2 on smaller input sizes.
1321
+ var a_l = a.length,
1322
+ b_l = b.length,
1323
+ base = BASE,
1324
+ result = createArray(b.length),
1325
+ divisorMostSignificantDigit = b[b_l - 1],
1326
+ // normalization
1327
+ lambda = Math.ceil(base / (2 * divisorMostSignificantDigit)),
1328
+ remainder = multiplySmall(a, lambda),
1329
+ divisor = multiplySmall(b, lambda),
1330
+ quotientDigit, shift, carry, borrow, i, l, q;
1331
+ if (remainder.length <= a_l) remainder.push(0);
1332
+ divisor.push(0);
1333
+ divisorMostSignificantDigit = divisor[b_l - 1];
1334
+ for (shift = a_l - b_l; shift >= 0; shift--) {
1335
+ quotientDigit = base - 1;
1336
+ if (remainder[shift + b_l] !== divisorMostSignificantDigit) {
1337
+ quotientDigit = Math.floor((remainder[shift + b_l] * base + remainder[shift + b_l - 1]) / divisorMostSignificantDigit);
1338
+ }
1339
+ // quotientDigit <= base - 1
1340
+ carry = 0;
1341
+ borrow = 0;
1342
+ l = divisor.length;
1343
+ for (i = 0; i < l; i++) {
1344
+ carry += quotientDigit * divisor[i];
1345
+ q = Math.floor(carry / base);
1346
+ borrow += remainder[shift + i] - (carry - q * base);
1347
+ carry = q;
1348
+ if (borrow < 0) {
1349
+ remainder[shift + i] = borrow + base;
1350
+ borrow = -1;
1351
+ } else {
1352
+ remainder[shift + i] = borrow;
1353
+ borrow = 0;
1354
+ }
1355
+ }
1356
+ while (borrow !== 0) {
1357
+ quotientDigit -= 1;
1358
+ carry = 0;
1359
+ for (i = 0; i < l; i++) {
1360
+ carry += remainder[shift + i] - base + divisor[i];
1361
+ if (carry < 0) {
1362
+ remainder[shift + i] = carry + base;
1363
+ carry = 0;
1364
+ } else {
1365
+ remainder[shift + i] = carry;
1366
+ carry = 1;
1367
+ }
1368
+ }
1369
+ borrow += carry;
1370
+ }
1371
+ result[shift] = quotientDigit;
1372
+ }
1373
+ // denormalization
1374
+ remainder = divModSmall(remainder, lambda)[0];
1375
+ return [arrayToSmall(result), arrayToSmall(remainder)];
1376
+ }
1377
+
1378
+ function divMod2(a, b) { // Implementation idea shamelessly stolen from Silent Matt's library http://silentmatt.com/biginteger/
1379
+ // Performs faster than divMod1 on larger input sizes.
1380
+ var a_l = a.length,
1381
+ b_l = b.length,
1382
+ result = [],
1383
+ part = [],
1384
+ base = BASE,
1385
+ guess, xlen, highx, highy, check;
1386
+ while (a_l) {
1387
+ part.unshift(a[--a_l]);
1388
+ trim(part);
1389
+ if (compareAbs(part, b) < 0) {
1390
+ result.push(0);
1391
+ continue;
1392
+ }
1393
+ xlen = part.length;
1394
+ highx = part[xlen - 1] * base + part[xlen - 2];
1395
+ highy = b[b_l - 1] * base + b[b_l - 2];
1396
+ if (xlen > b_l) {
1397
+ highx = (highx + 1) * base;
1398
+ }
1399
+ guess = Math.ceil(highx / highy);
1400
+ do {
1401
+ check = multiplySmall(b, guess);
1402
+ if (compareAbs(check, part) <= 0) break;
1403
+ guess--;
1404
+ } while (guess);
1405
+ result.push(guess);
1406
+ part = subtract(part, check);
1407
+ }
1408
+ result.reverse();
1409
+ return [arrayToSmall(result), arrayToSmall(part)];
1410
+ }
1411
+
1412
+ function divModSmall(value, lambda) {
1413
+ var length = value.length,
1414
+ quotient = createArray(length),
1415
+ base = BASE,
1416
+ i, q, remainder, divisor;
1417
+ remainder = 0;
1418
+ for (i = length - 1; i >= 0; --i) {
1419
+ divisor = remainder * base + value[i];
1420
+ q = truncate(divisor / lambda);
1421
+ remainder = divisor - q * lambda;
1422
+ quotient[i] = q | 0;
1423
+ }
1424
+ return [quotient, remainder | 0];
1425
+ }
1426
+
1427
+ function divModAny(self, v) {
1428
+ var value, n = parseValue(v);
1429
+ if (supportsNativeBigInt) {
1430
+ return [new NativeBigInt(self.value / n.value), new NativeBigInt(self.value % n.value)];
1431
+ }
1432
+ var a = self.value, b = n.value;
1433
+ var quotient;
1434
+ if (b === 0) throw new Error("Cannot divide by zero");
1435
+ if (self.isSmall) {
1436
+ if (n.isSmall) {
1437
+ return [new SmallInteger(truncate(a / b)), new SmallInteger(a % b)];
1438
+ }
1439
+ return [Integer[0], self];
1440
+ }
1441
+ if (n.isSmall) {
1442
+ if (b === 1) return [self, Integer[0]];
1443
+ if (b == -1) return [self.negate(), Integer[0]];
1444
+ var abs = Math.abs(b);
1445
+ if (abs < BASE) {
1446
+ value = divModSmall(a, abs);
1447
+ quotient = arrayToSmall(value[0]);
1448
+ var remainder = value[1];
1449
+ if (self.sign) remainder = -remainder;
1450
+ if (typeof quotient === "number") {
1451
+ if (self.sign !== n.sign) quotient = -quotient;
1452
+ return [new SmallInteger(quotient), new SmallInteger(remainder)];
1453
+ }
1454
+ return [new BigInteger(quotient, self.sign !== n.sign), new SmallInteger(remainder)];
1455
+ }
1456
+ b = smallToArray(abs);
1457
+ }
1458
+ var comparison = compareAbs(a, b);
1459
+ if (comparison === -1) return [Integer[0], self];
1460
+ if (comparison === 0) return [Integer[self.sign === n.sign ? 1 : -1], Integer[0]];
1461
+
1462
+ // divMod1 is faster on smaller input sizes
1463
+ if (a.length + b.length <= 200)
1464
+ value = divMod1(a, b);
1465
+ else value = divMod2(a, b);
1466
+
1467
+ quotient = value[0];
1468
+ var qSign = self.sign !== n.sign,
1469
+ mod = value[1],
1470
+ mSign = self.sign;
1471
+ if (typeof quotient === "number") {
1472
+ if (qSign) quotient = -quotient;
1473
+ quotient = new SmallInteger(quotient);
1474
+ } else quotient = new BigInteger(quotient, qSign);
1475
+ if (typeof mod === "number") {
1476
+ if (mSign) mod = -mod;
1477
+ mod = new SmallInteger(mod);
1478
+ } else mod = new BigInteger(mod, mSign);
1479
+ return [quotient, mod];
1480
+ }
1481
+
1482
+ BigInteger.prototype.divmod = function (v) {
1483
+ var result = divModAny(this, v);
1484
+ return {
1485
+ quotient: result[0],
1486
+ remainder: result[1]
1487
+ };
1488
+ };
1489
+ NativeBigInt.prototype.divmod = SmallInteger.prototype.divmod = BigInteger.prototype.divmod;
1490
+
1491
+
1492
+ BigInteger.prototype.divide = function (v) {
1493
+ return divModAny(this, v)[0];
1494
+ };
1495
+ NativeBigInt.prototype.over = NativeBigInt.prototype.divide = function (v) {
1496
+ return new NativeBigInt(this.value / parseValue(v).value);
1497
+ };
1498
+ SmallInteger.prototype.over = SmallInteger.prototype.divide = BigInteger.prototype.over = BigInteger.prototype.divide;
1499
+
1500
+ BigInteger.prototype.mod = function (v) {
1501
+ return divModAny(this, v)[1];
1502
+ };
1503
+ NativeBigInt.prototype.mod = NativeBigInt.prototype.remainder = function (v) {
1504
+ return new NativeBigInt(this.value % parseValue(v).value);
1505
+ };
1506
+ SmallInteger.prototype.remainder = SmallInteger.prototype.mod = BigInteger.prototype.remainder = BigInteger.prototype.mod;
1507
+
1508
+ BigInteger.prototype.pow = function (v) {
1509
+ var n = parseValue(v),
1510
+ a = this.value,
1511
+ b = n.value,
1512
+ value, x, y;
1513
+ if (b === 0) return Integer[1];
1514
+ if (a === 0) return Integer[0];
1515
+ if (a === 1) return Integer[1];
1516
+ if (a === -1) return n.isEven() ? Integer[1] : Integer[-1];
1517
+ if (n.sign) {
1518
+ return Integer[0];
1519
+ }
1520
+ if (!n.isSmall) throw new Error("The exponent " + n.toString() + " is too large.");
1521
+ if (this.isSmall) {
1522
+ if (isPrecise(value = Math.pow(a, b)))
1523
+ return new SmallInteger(truncate(value));
1524
+ }
1525
+ x = this;
1526
+ y = Integer[1];
1527
+ while (true) {
1528
+ if (b & 1 === 1) {
1529
+ y = y.times(x);
1530
+ --b;
1531
+ }
1532
+ if (b === 0) break;
1533
+ b /= 2;
1534
+ x = x.square();
1535
+ }
1536
+ return y;
1537
+ };
1538
+ SmallInteger.prototype.pow = BigInteger.prototype.pow;
1539
+
1540
+ NativeBigInt.prototype.pow = function (v) {
1541
+ var n = parseValue(v);
1542
+ var a = this.value, b = n.value;
1543
+ var _0 = BigInt(0), _1 = BigInt(1), _2 = BigInt(2);
1544
+ if (b === _0) return Integer[1];
1545
+ if (a === _0) return Integer[0];
1546
+ if (a === _1) return Integer[1];
1547
+ if (a === BigInt(-1)) return n.isEven() ? Integer[1] : Integer[-1];
1548
+ if (n.isNegative()) return new NativeBigInt(_0);
1549
+ var x = this;
1550
+ var y = Integer[1];
1551
+ while (true) {
1552
+ if ((b & _1) === _1) {
1553
+ y = y.times(x);
1554
+ --b;
1555
+ }
1556
+ if (b === _0) break;
1557
+ b /= _2;
1558
+ x = x.square();
1559
+ }
1560
+ return y;
1561
+ }
1562
+
1563
+ BigInteger.prototype.modPow = function (exp, mod) {
1564
+ exp = parseValue(exp);
1565
+ mod = parseValue(mod);
1566
+ if (mod.isZero()) throw new Error("Cannot take modPow with modulus 0");
1567
+ var r = Integer[1],
1568
+ base = this.mod(mod);
1569
+ if (exp.isNegative()) {
1570
+ exp = exp.multiply(Integer[-1]);
1571
+ base = base.modInv(mod);
1572
+ }
1573
+ while (exp.isPositive()) {
1574
+ if (base.isZero()) return Integer[0];
1575
+ if (exp.isOdd()) r = r.multiply(base).mod(mod);
1576
+ exp = exp.divide(2);
1577
+ base = base.square().mod(mod);
1578
+ }
1579
+ return r;
1580
+ };
1581
+ NativeBigInt.prototype.modPow = SmallInteger.prototype.modPow = BigInteger.prototype.modPow;
1582
+
1583
+ function compareAbs(a, b) {
1584
+ if (a.length !== b.length) {
1585
+ return a.length > b.length ? 1 : -1;
1586
+ }
1587
+ for (var i = a.length - 1; i >= 0; i--) {
1588
+ if (a[i] !== b[i]) return a[i] > b[i] ? 1 : -1;
1589
+ }
1590
+ return 0;
1591
+ }
1592
+
1593
+ BigInteger.prototype.compareAbs = function (v) {
1594
+ var n = parseValue(v),
1595
+ a = this.value,
1596
+ b = n.value;
1597
+ if (n.isSmall) return 1;
1598
+ return compareAbs(a, b);
1599
+ };
1600
+ SmallInteger.prototype.compareAbs = function (v) {
1601
+ var n = parseValue(v),
1602
+ a = Math.abs(this.value),
1603
+ b = n.value;
1604
+ if (n.isSmall) {
1605
+ b = Math.abs(b);
1606
+ return a === b ? 0 : a > b ? 1 : -1;
1607
+ }
1608
+ return -1;
1609
+ };
1610
+ NativeBigInt.prototype.compareAbs = function (v) {
1611
+ var a = this.value;
1612
+ var b = parseValue(v).value;
1613
+ a = a >= 0 ? a : -a;
1614
+ b = b >= 0 ? b : -b;
1615
+ return a === b ? 0 : a > b ? 1 : -1;
1616
+ }
1617
+
1618
+ BigInteger.prototype.compare = function (v) {
1619
+ // See discussion about comparison with Infinity:
1620
+ // https://github.com/peterolson/BigInteger.js/issues/61
1621
+ if (v === Infinity) {
1622
+ return -1;
1623
+ }
1624
+ if (v === -Infinity) {
1625
+ return 1;
1626
+ }
1627
+
1628
+ var n = parseValue(v),
1629
+ a = this.value,
1630
+ b = n.value;
1631
+ if (this.sign !== n.sign) {
1632
+ return n.sign ? 1 : -1;
1633
+ }
1634
+ if (n.isSmall) {
1635
+ return this.sign ? -1 : 1;
1636
+ }
1637
+ return compareAbs(a, b) * (this.sign ? -1 : 1);
1638
+ };
1639
+ BigInteger.prototype.compareTo = BigInteger.prototype.compare;
1640
+
1641
+ SmallInteger.prototype.compare = function (v) {
1642
+ if (v === Infinity) {
1643
+ return -1;
1644
+ }
1645
+ if (v === -Infinity) {
1646
+ return 1;
1647
+ }
1648
+
1649
+ var n = parseValue(v),
1650
+ a = this.value,
1651
+ b = n.value;
1652
+ if (n.isSmall) {
1653
+ return a == b ? 0 : a > b ? 1 : -1;
1654
+ }
1655
+ if (a < 0 !== n.sign) {
1656
+ return a < 0 ? -1 : 1;
1657
+ }
1658
+ return a < 0 ? 1 : -1;
1659
+ };
1660
+ SmallInteger.prototype.compareTo = SmallInteger.prototype.compare;
1661
+
1662
+ NativeBigInt.prototype.compare = function (v) {
1663
+ if (v === Infinity) {
1664
+ return -1;
1665
+ }
1666
+ if (v === -Infinity) {
1667
+ return 1;
1668
+ }
1669
+ var a = this.value;
1670
+ var b = parseValue(v).value;
1671
+ return a === b ? 0 : a > b ? 1 : -1;
1672
+ }
1673
+ NativeBigInt.prototype.compareTo = NativeBigInt.prototype.compare;
1674
+
1675
+ BigInteger.prototype.equals = function (v) {
1676
+ return this.compare(v) === 0;
1677
+ };
1678
+ NativeBigInt.prototype.eq = NativeBigInt.prototype.equals = SmallInteger.prototype.eq = SmallInteger.prototype.equals = BigInteger.prototype.eq = BigInteger.prototype.equals;
1679
+
1680
+ BigInteger.prototype.notEquals = function (v) {
1681
+ return this.compare(v) !== 0;
1682
+ };
1683
+ NativeBigInt.prototype.neq = NativeBigInt.prototype.notEquals = SmallInteger.prototype.neq = SmallInteger.prototype.notEquals = BigInteger.prototype.neq = BigInteger.prototype.notEquals;
1684
+
1685
+ BigInteger.prototype.greater = function (v) {
1686
+ return this.compare(v) > 0;
1687
+ };
1688
+ NativeBigInt.prototype.gt = NativeBigInt.prototype.greater = SmallInteger.prototype.gt = SmallInteger.prototype.greater = BigInteger.prototype.gt = BigInteger.prototype.greater;
1689
+
1690
+ BigInteger.prototype.lesser = function (v) {
1691
+ return this.compare(v) < 0;
1692
+ };
1693
+ NativeBigInt.prototype.lt = NativeBigInt.prototype.lesser = SmallInteger.prototype.lt = SmallInteger.prototype.lesser = BigInteger.prototype.lt = BigInteger.prototype.lesser;
1694
+
1695
+ BigInteger.prototype.greaterOrEquals = function (v) {
1696
+ return this.compare(v) >= 0;
1697
+ };
1698
+ NativeBigInt.prototype.geq = NativeBigInt.prototype.greaterOrEquals = SmallInteger.prototype.geq = SmallInteger.prototype.greaterOrEquals = BigInteger.prototype.geq = BigInteger.prototype.greaterOrEquals;
1699
+
1700
+ BigInteger.prototype.lesserOrEquals = function (v) {
1701
+ return this.compare(v) <= 0;
1702
+ };
1703
+ NativeBigInt.prototype.leq = NativeBigInt.prototype.lesserOrEquals = SmallInteger.prototype.leq = SmallInteger.prototype.lesserOrEquals = BigInteger.prototype.leq = BigInteger.prototype.lesserOrEquals;
1704
+
1705
+ BigInteger.prototype.isEven = function () {
1706
+ return (this.value[0] & 1) === 0;
1707
+ };
1708
+ SmallInteger.prototype.isEven = function () {
1709
+ return (this.value & 1) === 0;
1710
+ };
1711
+ NativeBigInt.prototype.isEven = function () {
1712
+ return (this.value & BigInt(1)) === BigInt(0);
1713
+ }
1714
+
1715
+ BigInteger.prototype.isOdd = function () {
1716
+ return (this.value[0] & 1) === 1;
1717
+ };
1718
+ SmallInteger.prototype.isOdd = function () {
1719
+ return (this.value & 1) === 1;
1720
+ };
1721
+ NativeBigInt.prototype.isOdd = function () {
1722
+ return (this.value & BigInt(1)) === BigInt(1);
1723
+ }
1724
+
1725
+ BigInteger.prototype.isPositive = function () {
1726
+ return !this.sign;
1727
+ };
1728
+ SmallInteger.prototype.isPositive = function () {
1729
+ return this.value > 0;
1730
+ };
1731
+ NativeBigInt.prototype.isPositive = SmallInteger.prototype.isPositive;
1732
+
1733
+ BigInteger.prototype.isNegative = function () {
1734
+ return this.sign;
1735
+ };
1736
+ SmallInteger.prototype.isNegative = function () {
1737
+ return this.value < 0;
1738
+ };
1739
+ NativeBigInt.prototype.isNegative = SmallInteger.prototype.isNegative;
1740
+
1741
+ BigInteger.prototype.isUnit = function () {
1742
+ return false;
1743
+ };
1744
+ SmallInteger.prototype.isUnit = function () {
1745
+ return Math.abs(this.value) === 1;
1746
+ };
1747
+ NativeBigInt.prototype.isUnit = function () {
1748
+ return this.abs().value === BigInt(1);
1749
+ }
1750
+
1751
+ BigInteger.prototype.isZero = function () {
1752
+ return false;
1753
+ };
1754
+ SmallInteger.prototype.isZero = function () {
1755
+ return this.value === 0;
1756
+ };
1757
+ NativeBigInt.prototype.isZero = function () {
1758
+ return this.value === BigInt(0);
1759
+ }
1760
+
1761
+ BigInteger.prototype.isDivisibleBy = function (v) {
1762
+ var n = parseValue(v);
1763
+ if (n.isZero()) return false;
1764
+ if (n.isUnit()) return true;
1765
+ if (n.compareAbs(2) === 0) return this.isEven();
1766
+ return this.mod(n).isZero();
1767
+ };
1768
+ NativeBigInt.prototype.isDivisibleBy = SmallInteger.prototype.isDivisibleBy = BigInteger.prototype.isDivisibleBy;
1769
+
1770
+ function isBasicPrime(v) {
1771
+ var n = v.abs();
1772
+ if (n.isUnit()) return false;
1773
+ if (n.equals(2) || n.equals(3) || n.equals(5)) return true;
1774
+ if (n.isEven() || n.isDivisibleBy(3) || n.isDivisibleBy(5)) return false;
1775
+ if (n.lesser(49)) return true;
1776
+ // we don't know if it's prime: let the other functions figure it out
1777
+ }
1778
+
1779
+ function millerRabinTest(n, a) {
1780
+ var nPrev = n.prev(),
1781
+ b = nPrev,
1782
+ r = 0,
1783
+ d, t, i, x;
1784
+ while (b.isEven()) b = b.divide(2), r++;
1785
+ next: for (i = 0; i < a.length; i++) {
1786
+ if (n.lesser(a[i])) continue;
1787
+ x = bigInt(a[i]).modPow(b, n);
1788
+ if (x.isUnit() || x.equals(nPrev)) continue;
1789
+ for (d = r - 1; d != 0; d--) {
1790
+ x = x.square().mod(n);
1791
+ if (x.isUnit()) return false;
1792
+ if (x.equals(nPrev)) continue next;
1793
+ }
1794
+ return false;
1795
+ }
1796
+ return true;
1797
+ }
1798
+
1799
+ // Set "strict" to true to force GRH-supported lower bound of 2*log(N)^2
1800
+ BigInteger.prototype.isPrime = function (strict) {
1801
+ var isPrime = isBasicPrime(this);
1802
+ if (isPrime !== undefined) return isPrime;
1803
+ var n = this.abs();
1804
+ var bits = n.bitLength();
1805
+ if (bits <= 64)
1806
+ return millerRabinTest(n, [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]);
1807
+ var logN = Math.log(2) * bits.toJSNumber();
1808
+ var t = Math.ceil((strict === true) ? (2 * Math.pow(logN, 2)) : logN);
1809
+ for (var a = [], i = 0; i < t; i++) {
1810
+ a.push(bigInt(i + 2));
1811
+ }
1812
+ return millerRabinTest(n, a);
1813
+ };
1814
+ NativeBigInt.prototype.isPrime = SmallInteger.prototype.isPrime = BigInteger.prototype.isPrime;
1815
+
1816
+ BigInteger.prototype.isProbablePrime = function (iterations, rng) {
1817
+ var isPrime = isBasicPrime(this);
1818
+ if (isPrime !== undefined) return isPrime;
1819
+ var n = this.abs();
1820
+ var t = iterations === undefined ? 5 : iterations;
1821
+ for (var a = [], i = 0; i < t; i++) {
1822
+ a.push(bigInt.randBetween(2, n.minus(2), rng));
1823
+ }
1824
+ return millerRabinTest(n, a);
1825
+ };
1826
+ NativeBigInt.prototype.isProbablePrime = SmallInteger.prototype.isProbablePrime = BigInteger.prototype.isProbablePrime;
1827
+
1828
+ BigInteger.prototype.modInv = function (n) {
1829
+ var t = bigInt.zero, newT = bigInt.one, r = parseValue(n), newR = this.abs(), q, lastT, lastR;
1830
+ while (!newR.isZero()) {
1831
+ q = r.divide(newR);
1832
+ lastT = t;
1833
+ lastR = r;
1834
+ t = newT;
1835
+ r = newR;
1836
+ newT = lastT.subtract(q.multiply(newT));
1837
+ newR = lastR.subtract(q.multiply(newR));
1838
+ }
1839
+ if (!r.isUnit()) throw new Error(this.toString() + " and " + n.toString() + " are not co-prime");
1840
+ if (t.compare(0) === -1) {
1841
+ t = t.add(n);
1842
+ }
1843
+ if (this.isNegative()) {
1844
+ return t.negate();
1845
+ }
1846
+ return t;
1847
+ };
1848
+
1849
+ NativeBigInt.prototype.modInv = SmallInteger.prototype.modInv = BigInteger.prototype.modInv;
1850
+
1851
+ BigInteger.prototype.next = function () {
1852
+ var value = this.value;
1853
+ if (this.sign) {
1854
+ return subtractSmall(value, 1, this.sign);
1855
+ }
1856
+ return new BigInteger(addSmall(value, 1), this.sign);
1857
+ };
1858
+ SmallInteger.prototype.next = function () {
1859
+ var value = this.value;
1860
+ if (value + 1 < MAX_INT) return new SmallInteger(value + 1);
1861
+ return new BigInteger(MAX_INT_ARR, false);
1862
+ };
1863
+ NativeBigInt.prototype.next = function () {
1864
+ return new NativeBigInt(this.value + BigInt(1));
1865
+ }
1866
+
1867
+ BigInteger.prototype.prev = function () {
1868
+ var value = this.value;
1869
+ if (this.sign) {
1870
+ return new BigInteger(addSmall(value, 1), true);
1871
+ }
1872
+ return subtractSmall(value, 1, this.sign);
1873
+ };
1874
+ SmallInteger.prototype.prev = function () {
1875
+ var value = this.value;
1876
+ if (value - 1 > -MAX_INT) return new SmallInteger(value - 1);
1877
+ return new BigInteger(MAX_INT_ARR, true);
1878
+ };
1879
+ NativeBigInt.prototype.prev = function () {
1880
+ return new NativeBigInt(this.value - BigInt(1));
1881
+ }
1882
+
1883
+ var powersOfTwo = [1];
1884
+ while (2 * powersOfTwo[powersOfTwo.length - 1] <= BASE) powersOfTwo.push(2 * powersOfTwo[powersOfTwo.length - 1]);
1885
+ var powers2Length = powersOfTwo.length, highestPower2 = powersOfTwo[powers2Length - 1];
1886
+
1887
+ function shift_isSmall(n) {
1888
+ return Math.abs(n) <= BASE;
1889
+ }
1890
+
1891
+ BigInteger.prototype.shiftLeft = function (v) {
1892
+ var n = parseValue(v).toJSNumber();
1893
+ if (!shift_isSmall(n)) {
1894
+ throw new Error(String(n) + " is too large for shifting.");
1895
+ }
1896
+ if (n < 0) return this.shiftRight(-n);
1897
+ var result = this;
1898
+ if (result.isZero()) return result;
1899
+ while (n >= powers2Length) {
1900
+ result = result.multiply(highestPower2);
1901
+ n -= powers2Length - 1;
1902
+ }
1903
+ return result.multiply(powersOfTwo[n]);
1904
+ };
1905
+ NativeBigInt.prototype.shiftLeft = SmallInteger.prototype.shiftLeft = BigInteger.prototype.shiftLeft;
1906
+
1907
+ BigInteger.prototype.shiftRight = function (v) {
1908
+ var remQuo;
1909
+ var n = parseValue(v).toJSNumber();
1910
+ if (!shift_isSmall(n)) {
1911
+ throw new Error(String(n) + " is too large for shifting.");
1912
+ }
1913
+ if (n < 0) return this.shiftLeft(-n);
1914
+ var result = this;
1915
+ while (n >= powers2Length) {
1916
+ if (result.isZero() || (result.isNegative() && result.isUnit())) return result;
1917
+ remQuo = divModAny(result, highestPower2);
1918
+ result = remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0];
1919
+ n -= powers2Length - 1;
1920
+ }
1921
+ remQuo = divModAny(result, powersOfTwo[n]);
1922
+ return remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0];
1923
+ };
1924
+ NativeBigInt.prototype.shiftRight = SmallInteger.prototype.shiftRight = BigInteger.prototype.shiftRight;
1925
+
1926
+ function bitwise(x, y, fn) {
1927
+ y = parseValue(y);
1928
+ var xSign = x.isNegative(), ySign = y.isNegative();
1929
+ var xRem = xSign ? x.not() : x,
1930
+ yRem = ySign ? y.not() : y;
1931
+ var xDigit = 0, yDigit = 0;
1932
+ var xDivMod = null, yDivMod = null;
1933
+ var result = [];
1934
+ while (!xRem.isZero() || !yRem.isZero()) {
1935
+ xDivMod = divModAny(xRem, highestPower2);
1936
+ xDigit = xDivMod[1].toJSNumber();
1937
+ if (xSign) {
1938
+ xDigit = highestPower2 - 1 - xDigit; // two's complement for negative numbers
1939
+ }
1940
+
1941
+ yDivMod = divModAny(yRem, highestPower2);
1942
+ yDigit = yDivMod[1].toJSNumber();
1943
+ if (ySign) {
1944
+ yDigit = highestPower2 - 1 - yDigit; // two's complement for negative numbers
1945
+ }
1946
+
1947
+ xRem = xDivMod[0];
1948
+ yRem = yDivMod[0];
1949
+ result.push(fn(xDigit, yDigit));
1950
+ }
1951
+ var sum = fn(xSign ? 1 : 0, ySign ? 1 : 0) !== 0 ? bigInt(-1) : bigInt(0);
1952
+ for (var i = result.length - 1; i >= 0; i -= 1) {
1953
+ sum = sum.multiply(highestPower2).add(bigInt(result[i]));
1954
+ }
1955
+ return sum;
1956
+ }
1957
+
1958
+ BigInteger.prototype.not = function () {
1959
+ return this.negate().prev();
1960
+ };
1961
+ NativeBigInt.prototype.not = SmallInteger.prototype.not = BigInteger.prototype.not;
1962
+
1963
+ BigInteger.prototype.and = function (n) {
1964
+ return bitwise(this, n, function (a, b) { return a & b; });
1965
+ };
1966
+ NativeBigInt.prototype.and = SmallInteger.prototype.and = BigInteger.prototype.and;
1967
+
1968
+ BigInteger.prototype.or = function (n) {
1969
+ return bitwise(this, n, function (a, b) { return a | b; });
1970
+ };
1971
+ NativeBigInt.prototype.or = SmallInteger.prototype.or = BigInteger.prototype.or;
1972
+
1973
+ BigInteger.prototype.xor = function (n) {
1974
+ return bitwise(this, n, function (a, b) { return a ^ b; });
1975
+ };
1976
+ NativeBigInt.prototype.xor = SmallInteger.prototype.xor = BigInteger.prototype.xor;
1977
+
1978
+ var LOBMASK_I = 1 << 30, LOBMASK_BI = (BASE & -BASE) * (BASE & -BASE) | LOBMASK_I;
1979
+ function roughLOB(n) { // get lowestOneBit (rough)
1980
+ // SmallInteger: return Min(lowestOneBit(n), 1 << 30)
1981
+ // BigInteger: return Min(lowestOneBit(n), 1 << 14) [BASE=1e7]
1982
+ var v = n.value,
1983
+ x = typeof v === "number" ? v | LOBMASK_I :
1984
+ typeof v === "bigint" ? v | BigInt(LOBMASK_I) :
1985
+ v[0] + v[1] * BASE | LOBMASK_BI;
1986
+ return x & -x;
1987
+ }
1988
+
1989
+ function integerLogarithm(value, base) {
1990
+ if (base.compareTo(value) <= 0) {
1991
+ var tmp = integerLogarithm(value, base.square(base));
1992
+ var p = tmp.p;
1993
+ var e = tmp.e;
1994
+ var t = p.multiply(base);
1995
+ return t.compareTo(value) <= 0 ? { p: t, e: e * 2 + 1 } : { p: p, e: e * 2 };
1996
+ }
1997
+ return { p: bigInt(1), e: 0 };
1998
+ }
1999
+
2000
+ BigInteger.prototype.bitLength = function () {
2001
+ var n = this;
2002
+ if (n.compareTo(bigInt(0)) < 0) {
2003
+ n = n.negate().subtract(bigInt(1));
2004
+ }
2005
+ if (n.compareTo(bigInt(0)) === 0) {
2006
+ return bigInt(0);
2007
+ }
2008
+ return bigInt(integerLogarithm(n, bigInt(2)).e).add(bigInt(1));
2009
+ }
2010
+ NativeBigInt.prototype.bitLength = SmallInteger.prototype.bitLength = BigInteger.prototype.bitLength;
2011
+
2012
+ function max(a, b) {
2013
+ a = parseValue(a);
2014
+ b = parseValue(b);
2015
+ return a.greater(b) ? a : b;
2016
+ }
2017
+ function min(a, b) {
2018
+ a = parseValue(a);
2019
+ b = parseValue(b);
2020
+ return a.lesser(b) ? a : b;
2021
+ }
2022
+ function gcd(a, b) {
2023
+ a = parseValue(a).abs();
2024
+ b = parseValue(b).abs();
2025
+ if (a.equals(b)) return a;
2026
+ if (a.isZero()) return b;
2027
+ if (b.isZero()) return a;
2028
+ var c = Integer[1], d, t;
2029
+ while (a.isEven() && b.isEven()) {
2030
+ d = min(roughLOB(a), roughLOB(b));
2031
+ a = a.divide(d);
2032
+ b = b.divide(d);
2033
+ c = c.multiply(d);
2034
+ }
2035
+ while (a.isEven()) {
2036
+ a = a.divide(roughLOB(a));
2037
+ }
2038
+ do {
2039
+ while (b.isEven()) {
2040
+ b = b.divide(roughLOB(b));
2041
+ }
2042
+ if (a.greater(b)) {
2043
+ t = b; b = a; a = t;
2044
+ }
2045
+ b = b.subtract(a);
2046
+ } while (!b.isZero());
2047
+ return c.isUnit() ? a : a.multiply(c);
2048
+ }
2049
+ function lcm(a, b) {
2050
+ a = parseValue(a).abs();
2051
+ b = parseValue(b).abs();
2052
+ return a.divide(gcd(a, b)).multiply(b);
2053
+ }
2054
+ function randBetween(a, b, rng) {
2055
+ a = parseValue(a);
2056
+ b = parseValue(b);
2057
+ var usedRNG = rng || Math.random;
2058
+ var low = min(a, b), high = max(a, b);
2059
+ var range = high.subtract(low).add(1);
2060
+ if (range.isSmall) return low.add(Math.floor(usedRNG() * range));
2061
+ var digits = toBase(range, BASE).value;
2062
+ var result = [], restricted = true;
2063
+ for (var i = 0; i < digits.length; i++) {
2064
+ var top = restricted ? digits[i] : BASE;
2065
+ var digit = truncate(usedRNG() * top);
2066
+ result.push(digit);
2067
+ if (digit < top) restricted = false;
2068
+ }
2069
+ return low.add(Integer.fromArray(result, BASE, false));
2070
+ }
2071
+
2072
+ var parseBase = function (text, base, alphabet, caseSensitive) {
2073
+ alphabet = alphabet || DEFAULT_ALPHABET;
2074
+ text = String(text);
2075
+ if (!caseSensitive) {
2076
+ text = text.toLowerCase();
2077
+ alphabet = alphabet.toLowerCase();
2078
+ }
2079
+ var length = text.length;
2080
+ var i;
2081
+ var absBase = Math.abs(base);
2082
+ var alphabetValues = {};
2083
+ for (i = 0; i < alphabet.length; i++) {
2084
+ alphabetValues[alphabet[i]] = i;
2085
+ }
2086
+ for (i = 0; i < length; i++) {
2087
+ var c = text[i];
2088
+ if (c === "-") continue;
2089
+ if (c in alphabetValues) {
2090
+ if (alphabetValues[c] >= absBase) {
2091
+ if (c === "1" && absBase === 1) continue;
2092
+ throw new Error(c + " is not a valid digit in base " + base + ".");
2093
+ }
2094
+ }
2095
+ }
2096
+ base = parseValue(base);
2097
+ var digits = [];
2098
+ var isNegative = text[0] === "-";
2099
+ for (i = isNegative ? 1 : 0; i < text.length; i++) {
2100
+ var c = text[i];
2101
+ if (c in alphabetValues) digits.push(parseValue(alphabetValues[c]));
2102
+ else if (c === "<") {
2103
+ var start = i;
2104
+ do { i++; } while (text[i] !== ">" && i < text.length);
2105
+ digits.push(parseValue(text.slice(start + 1, i)));
2106
+ }
2107
+ else throw new Error(c + " is not a valid character");
2108
+ }
2109
+ return parseBaseFromArray(digits, base, isNegative);
2110
+ };
2111
+
2112
+ function parseBaseFromArray(digits, base, isNegative) {
2113
+ var val = Integer[0], pow = Integer[1], i;
2114
+ for (i = digits.length - 1; i >= 0; i--) {
2115
+ val = val.add(digits[i].times(pow));
2116
+ pow = pow.times(base);
2117
+ }
2118
+ return isNegative ? val.negate() : val;
2119
+ }
2120
+
2121
+ function stringify(digit, alphabet) {
2122
+ alphabet = alphabet || DEFAULT_ALPHABET;
2123
+ if (digit < alphabet.length) {
2124
+ return alphabet[digit];
2125
+ }
2126
+ return "<" + digit + ">";
2127
+ }
2128
+
2129
+ function toBase(n, base) {
2130
+ base = bigInt(base);
2131
+ if (base.isZero()) {
2132
+ if (n.isZero()) return { value: [0], isNegative: false };
2133
+ throw new Error("Cannot convert nonzero numbers to base 0.");
2134
+ }
2135
+ if (base.equals(-1)) {
2136
+ if (n.isZero()) return { value: [0], isNegative: false };
2137
+ if (n.isNegative())
2138
+ return {
2139
+ value: [].concat.apply([], Array.apply(null, Array(-n.toJSNumber()))
2140
+ .map(Array.prototype.valueOf, [1, 0])
2141
+ ),
2142
+ isNegative: false
2143
+ };
2144
+
2145
+ var arr = Array.apply(null, Array(n.toJSNumber() - 1))
2146
+ .map(Array.prototype.valueOf, [0, 1]);
2147
+ arr.unshift([1]);
2148
+ return {
2149
+ value: [].concat.apply([], arr),
2150
+ isNegative: false
2151
+ };
2152
+ }
2153
+
2154
+ var neg = false;
2155
+ if (n.isNegative() && base.isPositive()) {
2156
+ neg = true;
2157
+ n = n.abs();
2158
+ }
2159
+ if (base.isUnit()) {
2160
+ if (n.isZero()) return { value: [0], isNegative: false };
2161
+
2162
+ return {
2163
+ value: Array.apply(null, Array(n.toJSNumber()))
2164
+ .map(Number.prototype.valueOf, 1),
2165
+ isNegative: neg
2166
+ };
2167
+ }
2168
+ var out = [];
2169
+ var left = n, divmod;
2170
+ while (left.isNegative() || left.compareAbs(base) >= 0) {
2171
+ divmod = left.divmod(base);
2172
+ left = divmod.quotient;
2173
+ var digit = divmod.remainder;
2174
+ if (digit.isNegative()) {
2175
+ digit = base.minus(digit).abs();
2176
+ left = left.next();
2177
+ }
2178
+ out.push(digit.toJSNumber());
2179
+ }
2180
+ out.push(left.toJSNumber());
2181
+ return { value: out.reverse(), isNegative: neg };
2182
+ }
2183
+
2184
+ function toBaseString(n, base, alphabet) {
2185
+ var arr = toBase(n, base);
2186
+ return (arr.isNegative ? "-" : "") + arr.value.map(function (x) {
2187
+ return stringify(x, alphabet);
2188
+ }).join('');
2189
+ }
2190
+
2191
+ BigInteger.prototype.toArray = function (radix) {
2192
+ return toBase(this, radix);
2193
+ };
2194
+
2195
+ SmallInteger.prototype.toArray = function (radix) {
2196
+ return toBase(this, radix);
2197
+ };
2198
+
2199
+ NativeBigInt.prototype.toArray = function (radix) {
2200
+ return toBase(this, radix);
2201
+ };
2202
+
2203
+ BigInteger.prototype.toString = function (radix, alphabet) {
2204
+ if (radix === undefined) radix = 10;
2205
+ if (radix !== 10) return toBaseString(this, radix, alphabet);
2206
+ var v = this.value, l = v.length, str = String(v[--l]), zeros = "0000000", digit;
2207
+ while (--l >= 0) {
2208
+ digit = String(v[l]);
2209
+ str += zeros.slice(digit.length) + digit;
2210
+ }
2211
+ var sign = this.sign ? "-" : "";
2212
+ return sign + str;
2213
+ };
2214
+
2215
+ SmallInteger.prototype.toString = function (radix, alphabet) {
2216
+ if (radix === undefined) radix = 10;
2217
+ if (radix != 10) return toBaseString(this, radix, alphabet);
2218
+ return String(this.value);
2219
+ };
2220
+
2221
+ NativeBigInt.prototype.toString = SmallInteger.prototype.toString;
2222
+
2223
+ NativeBigInt.prototype.toJSON = BigInteger.prototype.toJSON = SmallInteger.prototype.toJSON = function () { return this.toString(); }
2224
+
2225
+ BigInteger.prototype.valueOf = function () {
2226
+ return parseInt(this.toString(), 10);
2227
+ };
2228
+ BigInteger.prototype.toJSNumber = BigInteger.prototype.valueOf;
2229
+
2230
+ SmallInteger.prototype.valueOf = function () {
2231
+ return this.value;
2232
+ };
2233
+ SmallInteger.prototype.toJSNumber = SmallInteger.prototype.valueOf;
2234
+ NativeBigInt.prototype.valueOf = NativeBigInt.prototype.toJSNumber = function () {
2235
+ return parseInt(this.toString(), 10);
2236
+ }
2237
+
2238
+ function parseStringValue(v) {
2239
+ if (isPrecise(+v)) {
2240
+ var x = +v;
2241
+ if (x === truncate(x))
2242
+ return supportsNativeBigInt ? new NativeBigInt(BigInt(x)) : new SmallInteger(x);
2243
+ throw new Error("Invalid integer: " + v);
2244
+ }
2245
+ var sign = v[0] === "-";
2246
+ if (sign) v = v.slice(1);
2247
+ var split = v.split(/e/i);
2248
+ if (split.length > 2) throw new Error("Invalid integer: " + split.join("e"));
2249
+ if (split.length === 2) {
2250
+ var exp = split[1];
2251
+ if (exp[0] === "+") exp = exp.slice(1);
2252
+ exp = +exp;
2253
+ if (exp !== truncate(exp) || !isPrecise(exp)) throw new Error("Invalid integer: " + exp + " is not a valid exponent.");
2254
+ var text = split[0];
2255
+ var decimalPlace = text.indexOf(".");
2256
+ if (decimalPlace >= 0) {
2257
+ exp -= text.length - decimalPlace - 1;
2258
+ text = text.slice(0, decimalPlace) + text.slice(decimalPlace + 1);
2259
+ }
2260
+ if (exp < 0) throw new Error("Cannot include negative exponent part for integers");
2261
+ text += (new Array(exp + 1)).join("0");
2262
+ v = text;
2263
+ }
2264
+ var isValid = /^([0-9][0-9]*)$/.test(v);
2265
+ if (!isValid) throw new Error("Invalid integer: " + v);
2266
+ if (supportsNativeBigInt) {
2267
+ return new NativeBigInt(BigInt(sign ? "-" + v : v));
2268
+ }
2269
+ var r = [], max = v.length, l = LOG_BASE, min = max - l;
2270
+ while (max > 0) {
2271
+ r.push(+v.slice(min, max));
2272
+ min -= l;
2273
+ if (min < 0) min = 0;
2274
+ max -= l;
2275
+ }
2276
+ trim(r);
2277
+ return new BigInteger(r, sign);
2278
+ }
2279
+
2280
+ function parseNumberValue(v) {
2281
+ if (supportsNativeBigInt) {
2282
+ return new NativeBigInt(BigInt(v));
2283
+ }
2284
+ if (isPrecise(v)) {
2285
+ if (v !== truncate(v)) throw new Error(v + " is not an integer.");
2286
+ return new SmallInteger(v);
2287
+ }
2288
+ return parseStringValue(v.toString());
2289
+ }
2290
+
2291
+ function parseValue(v) {
2292
+ if (typeof v === "number") {
2293
+ return parseNumberValue(v);
2294
+ }
2295
+ if (typeof v === "string") {
2296
+ return parseStringValue(v);
2297
+ }
2298
+ if (typeof v === "bigint") {
2299
+ return new NativeBigInt(v);
2300
+ }
2301
+ return v;
2302
+ }
2303
+ // Pre-define numbers in range [-999,999]
2304
+ for (var i = 0; i < 1000; i++) {
2305
+ Integer[i] = parseValue(i);
2306
+ if (i > 0) Integer[-i] = parseValue(-i);
2307
+ }
2308
+ // Backwards compatibility
2309
+ Integer.one = Integer[1];
2310
+ Integer.zero = Integer[0];
2311
+ Integer.minusOne = Integer[-1];
2312
+ Integer.max = max;
2313
+ Integer.min = min;
2314
+ Integer.gcd = gcd;
2315
+ Integer.lcm = lcm;
2316
+ Integer.isInstance = function (x) { return x instanceof BigInteger || x instanceof SmallInteger || x instanceof NativeBigInt; };
2317
+ Integer.randBetween = randBetween;
2318
+
2319
+ Integer.fromArray = function (digits, base, isNegative) {
2320
+ return parseBaseFromArray(digits.map(parseValue), parseValue(base || 10), isNegative);
2321
+ };
2322
+
2323
+ return Integer;
2324
+ })();
2325
+
2326
+ // Node.js check
2327
+ if ( true && module.hasOwnProperty("exports")) {
2328
+ module.exports = bigInt;
2329
+ }
2330
+
2331
+ //amd check
2332
+ if (true) {
2333
+ !(__WEBPACK_AMD_DEFINE_RESULT__ = (function () {
2334
+ return bigInt;
2335
+ }).call(exports, __webpack_require__, exports, module),
2336
+ __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
2337
+ }
2338
+
2339
+ /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__("uAlt")(module)))
2340
+
2341
+ /***/ }),
2342
+
2343
+ /***/ "uAlt":
2344
+ /***/ (function(module, exports) {
2345
+
2346
+ module.exports = function(module) {
2347
+ if (!module.webpackPolyfill) {
2348
+ module.deprecate = function() {};
2349
+ module.paths = [];
2350
+ // module.parent = undefined by default
2351
+ if (!module.children) module.children = [];
2352
+ Object.defineProperty(module, "loaded", {
2353
+ enumerable: true,
2354
+ get: function() {
2355
+ return module.l;
2356
+ }
2357
+ });
2358
+ Object.defineProperty(module, "id", {
2359
+ enumerable: true,
2360
+ get: function() {
2361
+ return module.i;
2362
+ }
2363
+ });
2364
+ module.webpackPolyfill = 1;
2365
+ }
2366
+ return module;
2367
+ };
2368
+
2369
+
2370
+ /***/ })
2371
+
2372
+ /******/ });
2373
+ //# sourceMappingURL=index.js.map