utils-lib-js 1.7.12 → 1.7.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/umd/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('http'), require('https'), require('url')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'http', 'https', 'url'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.UtilsLib = {}, global.http, global.https, global.url));
5
- })(this, (function (exports, http, https, url) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.UtilsLib = {}));
5
+ })(this, (function (exports) { 'use strict';
6
6
 
7
7
  /******************************************************************************
8
8
  Copyright (c) Microsoft Corporation.
@@ -380,979 +380,21 @@
380
380
  })(exports.types || (exports.types = {}));
381
381
  var __static = { types: exports.types };
382
382
 
383
- /**
384
- * @author Toru Nagashima <https://github.com/mysticatea>
385
- * @copyright 2015 Toru Nagashima. All rights reserved.
386
- * See LICENSE file in root directory for full license.
387
- */
388
- /**
389
- * @typedef {object} PrivateData
390
- * @property {EventTarget} eventTarget The event target.
391
- * @property {{type:string}} event The original event object.
392
- * @property {number} eventPhase The current event phase.
393
- * @property {EventTarget|null} currentTarget The current event target.
394
- * @property {boolean} canceled The flag to prevent default.
395
- * @property {boolean} stopped The flag to stop propagation.
396
- * @property {boolean} immediateStopped The flag to stop propagation immediately.
397
- * @property {Function|null} passiveListener The listener if the current listener is passive. Otherwise this is null.
398
- * @property {number} timeStamp The unix time.
399
- * @private
400
- */
401
-
402
- /**
403
- * Private data for event wrappers.
404
- * @type {WeakMap<Event, PrivateData>}
405
- * @private
406
- */
407
- const privateData = new WeakMap();
408
-
409
- /**
410
- * Cache for wrapper classes.
411
- * @type {WeakMap<Object, Function>}
412
- * @private
413
- */
414
- const wrappers = new WeakMap();
415
-
416
- /**
417
- * Get private data.
418
- * @param {Event} event The event object to get private data.
419
- * @returns {PrivateData} The private data of the event.
420
- * @private
421
- */
422
- function pd(event) {
423
- const retv = privateData.get(event);
424
- console.assert(
425
- retv != null,
426
- "'this' is expected an Event object, but got",
427
- event
428
- );
429
- return retv
430
- }
431
-
432
- /**
433
- * https://dom.spec.whatwg.org/#set-the-canceled-flag
434
- * @param data {PrivateData} private data.
435
- */
436
- function setCancelFlag(data) {
437
- if (data.passiveListener != null) {
438
- if (
439
- typeof console !== "undefined" &&
440
- typeof console.error === "function"
441
- ) {
442
- console.error(
443
- "Unable to preventDefault inside passive event listener invocation.",
444
- data.passiveListener
445
- );
446
- }
447
- return
448
- }
449
- if (!data.event.cancelable) {
450
- return
451
- }
452
-
453
- data.canceled = true;
454
- if (typeof data.event.preventDefault === "function") {
455
- data.event.preventDefault();
456
- }
457
- }
458
-
459
- /**
460
- * @see https://dom.spec.whatwg.org/#interface-event
461
- * @private
462
- */
463
- /**
464
- * The event wrapper.
465
- * @constructor
466
- * @param {EventTarget} eventTarget The event target of this dispatching.
467
- * @param {Event|{type:string}} event The original event to wrap.
468
- */
469
- function Event$1(eventTarget, event) {
470
- privateData.set(this, {
471
- eventTarget,
472
- event,
473
- eventPhase: 2,
474
- currentTarget: eventTarget,
475
- canceled: false,
476
- stopped: false,
477
- immediateStopped: false,
478
- passiveListener: null,
479
- timeStamp: event.timeStamp || Date.now(),
480
- });
481
-
482
- // https://heycam.github.io/webidl/#Unforgeable
483
- Object.defineProperty(this, "isTrusted", { value: false, enumerable: true });
484
-
485
- // Define accessors
486
- const keys = Object.keys(event);
487
- for (let i = 0; i < keys.length; ++i) {
488
- const key = keys[i];
489
- if (!(key in this)) {
490
- Object.defineProperty(this, key, defineRedirectDescriptor(key));
491
- }
492
- }
493
- }
494
-
495
- // Should be enumerable, but class methods are not enumerable.
496
- Event$1.prototype = {
497
- /**
498
- * The type of this event.
499
- * @type {string}
500
- */
501
- get type() {
502
- return pd(this).event.type
503
- },
504
-
505
- /**
506
- * The target of this event.
507
- * @type {EventTarget}
508
- */
509
- get target() {
510
- return pd(this).eventTarget
511
- },
512
-
513
- /**
514
- * The target of this event.
515
- * @type {EventTarget}
516
- */
517
- get currentTarget() {
518
- return pd(this).currentTarget
519
- },
520
-
521
- /**
522
- * @returns {EventTarget[]} The composed path of this event.
523
- */
524
- composedPath() {
525
- const currentTarget = pd(this).currentTarget;
526
- if (currentTarget == null) {
527
- return []
528
- }
529
- return [currentTarget]
530
- },
531
-
532
- /**
533
- * Constant of NONE.
534
- * @type {number}
535
- */
536
- get NONE() {
537
- return 0
538
- },
539
-
540
- /**
541
- * Constant of CAPTURING_PHASE.
542
- * @type {number}
543
- */
544
- get CAPTURING_PHASE() {
545
- return 1
546
- },
547
-
548
- /**
549
- * Constant of AT_TARGET.
550
- * @type {number}
551
- */
552
- get AT_TARGET() {
553
- return 2
554
- },
555
-
556
- /**
557
- * Constant of BUBBLING_PHASE.
558
- * @type {number}
559
- */
560
- get BUBBLING_PHASE() {
561
- return 3
562
- },
563
-
564
- /**
565
- * The target of this event.
566
- * @type {number}
567
- */
568
- get eventPhase() {
569
- return pd(this).eventPhase
570
- },
571
-
572
- /**
573
- * Stop event bubbling.
574
- * @returns {void}
575
- */
576
- stopPropagation() {
577
- const data = pd(this);
578
-
579
- data.stopped = true;
580
- if (typeof data.event.stopPropagation === "function") {
581
- data.event.stopPropagation();
582
- }
583
- },
584
-
585
- /**
586
- * Stop event bubbling.
587
- * @returns {void}
588
- */
589
- stopImmediatePropagation() {
590
- const data = pd(this);
591
-
592
- data.stopped = true;
593
- data.immediateStopped = true;
594
- if (typeof data.event.stopImmediatePropagation === "function") {
595
- data.event.stopImmediatePropagation();
596
- }
597
- },
598
-
599
- /**
600
- * The flag to be bubbling.
601
- * @type {boolean}
602
- */
603
- get bubbles() {
604
- return Boolean(pd(this).event.bubbles)
605
- },
606
-
607
- /**
608
- * The flag to be cancelable.
609
- * @type {boolean}
610
- */
611
- get cancelable() {
612
- return Boolean(pd(this).event.cancelable)
613
- },
614
-
615
- /**
616
- * Cancel this event.
617
- * @returns {void}
618
- */
619
- preventDefault() {
620
- setCancelFlag(pd(this));
621
- },
622
-
623
- /**
624
- * The flag to indicate cancellation state.
625
- * @type {boolean}
626
- */
627
- get defaultPrevented() {
628
- return pd(this).canceled
629
- },
630
-
631
- /**
632
- * The flag to be composed.
633
- * @type {boolean}
634
- */
635
- get composed() {
636
- return Boolean(pd(this).event.composed)
637
- },
638
-
639
- /**
640
- * The unix time of this event.
641
- * @type {number}
642
- */
643
- get timeStamp() {
644
- return pd(this).timeStamp
645
- },
646
-
647
- /**
648
- * The target of this event.
649
- * @type {EventTarget}
650
- * @deprecated
651
- */
652
- get srcElement() {
653
- return pd(this).eventTarget
654
- },
655
-
656
- /**
657
- * The flag to stop event bubbling.
658
- * @type {boolean}
659
- * @deprecated
660
- */
661
- get cancelBubble() {
662
- return pd(this).stopped
663
- },
664
- set cancelBubble(value) {
665
- if (!value) {
666
- return
667
- }
668
- const data = pd(this);
669
-
670
- data.stopped = true;
671
- if (typeof data.event.cancelBubble === "boolean") {
672
- data.event.cancelBubble = true;
673
- }
674
- },
675
-
676
- /**
677
- * The flag to indicate cancellation state.
678
- * @type {boolean}
679
- * @deprecated
680
- */
681
- get returnValue() {
682
- return !pd(this).canceled
683
- },
684
- set returnValue(value) {
685
- if (!value) {
686
- setCancelFlag(pd(this));
687
- }
688
- },
689
-
690
- /**
691
- * Initialize this event object. But do nothing under event dispatching.
692
- * @param {string} type The event type.
693
- * @param {boolean} [bubbles=false] The flag to be possible to bubble up.
694
- * @param {boolean} [cancelable=false] The flag to be possible to cancel.
695
- * @deprecated
696
- */
697
- initEvent() {
698
- // Do nothing.
699
- },
700
- };
701
-
702
- // `constructor` is not enumerable.
703
- Object.defineProperty(Event$1.prototype, "constructor", {
704
- value: Event$1,
705
- configurable: true,
706
- writable: true,
707
- });
708
-
709
- // Ensure `event instanceof window.Event` is `true`.
710
- if (typeof window !== "undefined" && typeof window.Event !== "undefined") {
711
- Object.setPrototypeOf(Event$1.prototype, window.Event.prototype);
712
-
713
- // Make association for wrappers.
714
- wrappers.set(window.Event.prototype, Event$1);
715
- }
716
-
717
- /**
718
- * Get the property descriptor to redirect a given property.
719
- * @param {string} key Property name to define property descriptor.
720
- * @returns {PropertyDescriptor} The property descriptor to redirect the property.
721
- * @private
722
- */
723
- function defineRedirectDescriptor(key) {
724
- return {
725
- get() {
726
- return pd(this).event[key]
727
- },
728
- set(value) {
729
- pd(this).event[key] = value;
730
- },
731
- configurable: true,
732
- enumerable: true,
733
- }
734
- }
735
-
736
- /**
737
- * Get the property descriptor to call a given method property.
738
- * @param {string} key Property name to define property descriptor.
739
- * @returns {PropertyDescriptor} The property descriptor to call the method property.
740
- * @private
741
- */
742
- function defineCallDescriptor(key) {
743
- return {
744
- value() {
745
- const event = pd(this).event;
746
- return event[key].apply(event, arguments)
747
- },
748
- configurable: true,
749
- enumerable: true,
750
- }
751
- }
752
-
753
- /**
754
- * Define new wrapper class.
755
- * @param {Function} BaseEvent The base wrapper class.
756
- * @param {Object} proto The prototype of the original event.
757
- * @returns {Function} The defined wrapper class.
758
- * @private
759
- */
760
- function defineWrapper(BaseEvent, proto) {
761
- const keys = Object.keys(proto);
762
- if (keys.length === 0) {
763
- return BaseEvent
764
- }
765
-
766
- /** CustomEvent */
767
- function CustomEvent(eventTarget, event) {
768
- BaseEvent.call(this, eventTarget, event);
769
- }
770
-
771
- CustomEvent.prototype = Object.create(BaseEvent.prototype, {
772
- constructor: { value: CustomEvent, configurable: true, writable: true },
773
- });
774
-
775
- // Define accessors.
776
- for (let i = 0; i < keys.length; ++i) {
777
- const key = keys[i];
778
- if (!(key in BaseEvent.prototype)) {
779
- const descriptor = Object.getOwnPropertyDescriptor(proto, key);
780
- const isFunc = typeof descriptor.value === "function";
781
- Object.defineProperty(
782
- CustomEvent.prototype,
783
- key,
784
- isFunc
785
- ? defineCallDescriptor(key)
786
- : defineRedirectDescriptor(key)
787
- );
788
- }
789
- }
790
-
791
- return CustomEvent
792
- }
793
-
794
- /**
795
- * Get the wrapper class of a given prototype.
796
- * @param {Object} proto The prototype of the original event to get its wrapper.
797
- * @returns {Function} The wrapper class.
798
- * @private
799
- */
800
- function getWrapper(proto) {
801
- if (proto == null || proto === Object.prototype) {
802
- return Event$1
803
- }
804
-
805
- let wrapper = wrappers.get(proto);
806
- if (wrapper == null) {
807
- wrapper = defineWrapper(getWrapper(Object.getPrototypeOf(proto)), proto);
808
- wrappers.set(proto, wrapper);
809
- }
810
- return wrapper
811
- }
812
-
813
- /**
814
- * Wrap a given event to management a dispatching.
815
- * @param {EventTarget} eventTarget The event target of this dispatching.
816
- * @param {Object} event The event to wrap.
817
- * @returns {Event} The wrapper instance.
818
- * @private
819
- */
820
- function wrapEvent(eventTarget, event) {
821
- const Wrapper = getWrapper(Object.getPrototypeOf(event));
822
- return new Wrapper(eventTarget, event)
823
- }
824
-
825
- /**
826
- * Get the immediateStopped flag of a given event.
827
- * @param {Event} event The event to get.
828
- * @returns {boolean} The flag to stop propagation immediately.
829
- * @private
830
- */
831
- function isStopped(event) {
832
- return pd(event).immediateStopped
833
- }
834
-
835
- /**
836
- * Set the current event phase of a given event.
837
- * @param {Event} event The event to set current target.
838
- * @param {number} eventPhase New event phase.
839
- * @returns {void}
840
- * @private
841
- */
842
- function setEventPhase(event, eventPhase) {
843
- pd(event).eventPhase = eventPhase;
844
- }
845
-
846
- /**
847
- * Set the current target of a given event.
848
- * @param {Event} event The event to set current target.
849
- * @param {EventTarget|null} currentTarget New current target.
850
- * @returns {void}
851
- * @private
852
- */
853
- function setCurrentTarget(event, currentTarget) {
854
- pd(event).currentTarget = currentTarget;
855
- }
856
-
857
- /**
858
- * Set a passive listener of a given event.
859
- * @param {Event} event The event to set current target.
860
- * @param {Function|null} passiveListener New passive listener.
861
- * @returns {void}
862
- * @private
863
- */
864
- function setPassiveListener(event, passiveListener) {
865
- pd(event).passiveListener = passiveListener;
866
- }
867
-
868
- /**
869
- * @typedef {object} ListenerNode
870
- * @property {Function} listener
871
- * @property {1|2|3} listenerType
872
- * @property {boolean} passive
873
- * @property {boolean} once
874
- * @property {ListenerNode|null} next
875
- * @private
876
- */
877
-
878
- /**
879
- * @type {WeakMap<object, Map<string, ListenerNode>>}
880
- * @private
881
- */
882
- const listenersMap = new WeakMap();
883
-
884
- // Listener types
885
- const CAPTURE = 1;
886
- const BUBBLE = 2;
887
- const ATTRIBUTE = 3;
888
-
889
- /**
890
- * Check whether a given value is an object or not.
891
- * @param {any} x The value to check.
892
- * @returns {boolean} `true` if the value is an object.
893
- */
894
- function isObject(x) {
895
- return x !== null && typeof x === "object" //eslint-disable-line no-restricted-syntax
896
- }
897
-
898
- /**
899
- * Get listeners.
900
- * @param {EventTarget} eventTarget The event target to get.
901
- * @returns {Map<string, ListenerNode>} The listeners.
902
- * @private
903
- */
904
- function getListeners(eventTarget) {
905
- const listeners = listenersMap.get(eventTarget);
906
- if (listeners == null) {
907
- throw new TypeError(
908
- "'this' is expected an EventTarget object, but got another value."
909
- )
910
- }
911
- return listeners
912
- }
913
-
914
- /**
915
- * Get the property descriptor for the event attribute of a given event.
916
- * @param {string} eventName The event name to get property descriptor.
917
- * @returns {PropertyDescriptor} The property descriptor.
918
- * @private
919
- */
920
- function defineEventAttributeDescriptor(eventName) {
921
- return {
922
- get() {
923
- const listeners = getListeners(this);
924
- let node = listeners.get(eventName);
925
- while (node != null) {
926
- if (node.listenerType === ATTRIBUTE) {
927
- return node.listener
928
- }
929
- node = node.next;
930
- }
931
- return null
932
- },
933
-
934
- set(listener) {
935
- if (typeof listener !== "function" && !isObject(listener)) {
936
- listener = null; // eslint-disable-line no-param-reassign
937
- }
938
- const listeners = getListeners(this);
939
-
940
- // Traverse to the tail while removing old value.
941
- let prev = null;
942
- let node = listeners.get(eventName);
943
- while (node != null) {
944
- if (node.listenerType === ATTRIBUTE) {
945
- // Remove old value.
946
- if (prev !== null) {
947
- prev.next = node.next;
948
- } else if (node.next !== null) {
949
- listeners.set(eventName, node.next);
950
- } else {
951
- listeners.delete(eventName);
952
- }
953
- } else {
954
- prev = node;
955
- }
956
-
957
- node = node.next;
958
- }
959
-
960
- // Add new value.
961
- if (listener !== null) {
962
- const newNode = {
963
- listener,
964
- listenerType: ATTRIBUTE,
965
- passive: false,
966
- once: false,
967
- next: null,
968
- };
969
- if (prev === null) {
970
- listeners.set(eventName, newNode);
971
- } else {
972
- prev.next = newNode;
973
- }
974
- }
975
- },
976
- configurable: true,
977
- enumerable: true,
978
- }
979
- }
980
-
981
- /**
982
- * Define an event attribute (e.g. `eventTarget.onclick`).
983
- * @param {Object} eventTargetPrototype The event target prototype to define an event attrbite.
984
- * @param {string} eventName The event name to define.
985
- * @returns {void}
986
- */
987
- function defineEventAttribute(eventTargetPrototype, eventName) {
988
- Object.defineProperty(
989
- eventTargetPrototype,
990
- `on${eventName}`,
991
- defineEventAttributeDescriptor(eventName)
992
- );
993
- }
994
-
995
- /**
996
- * Define a custom EventTarget with event attributes.
997
- * @param {string[]} eventNames Event names for event attributes.
998
- * @returns {EventTarget} The custom EventTarget.
999
- * @private
1000
- */
1001
- function defineCustomEventTarget(eventNames) {
1002
- /** CustomEventTarget */
1003
- function CustomEventTarget() {
1004
- EventTarget.call(this);
1005
- }
1006
-
1007
- CustomEventTarget.prototype = Object.create(EventTarget.prototype, {
1008
- constructor: {
1009
- value: CustomEventTarget,
1010
- configurable: true,
1011
- writable: true,
1012
- },
1013
- });
1014
-
1015
- for (let i = 0; i < eventNames.length; ++i) {
1016
- defineEventAttribute(CustomEventTarget.prototype, eventNames[i]);
1017
- }
1018
-
1019
- return CustomEventTarget
1020
- }
1021
-
1022
- /**
1023
- * EventTarget.
1024
- *
1025
- * - This is constructor if no arguments.
1026
- * - This is a function which returns a CustomEventTarget constructor if there are arguments.
1027
- *
1028
- * For example:
1029
- *
1030
- * class A extends EventTarget {}
1031
- * class B extends EventTarget("message") {}
1032
- * class C extends EventTarget("message", "error") {}
1033
- * class D extends EventTarget(["message", "error"]) {}
1034
- */
1035
- function EventTarget() {
1036
- /*eslint-disable consistent-return */
1037
- if (this instanceof EventTarget) {
1038
- listenersMap.set(this, new Map());
1039
- return
1040
- }
1041
- if (arguments.length === 1 && Array.isArray(arguments[0])) {
1042
- return defineCustomEventTarget(arguments[0])
1043
- }
1044
- if (arguments.length > 0) {
1045
- const types = new Array(arguments.length);
1046
- for (let i = 0; i < arguments.length; ++i) {
1047
- types[i] = arguments[i];
1048
- }
1049
- return defineCustomEventTarget(types)
1050
- }
1051
- throw new TypeError("Cannot call a class as a function")
1052
- /*eslint-enable consistent-return */
1053
- }
1054
-
1055
- // Should be enumerable, but class methods are not enumerable.
1056
- EventTarget.prototype = {
1057
- /**
1058
- * Add a given listener to this event target.
1059
- * @param {string} eventName The event name to add.
1060
- * @param {Function} listener The listener to add.
1061
- * @param {boolean|{capture?:boolean,passive?:boolean,once?:boolean}} [options] The options for this listener.
1062
- * @returns {void}
1063
- */
1064
- addEventListener(eventName, listener, options) {
1065
- if (listener == null) {
1066
- return
1067
- }
1068
- if (typeof listener !== "function" && !isObject(listener)) {
1069
- throw new TypeError("'listener' should be a function or an object.")
1070
- }
1071
-
1072
- const listeners = getListeners(this);
1073
- const optionsIsObj = isObject(options);
1074
- const capture = optionsIsObj
1075
- ? Boolean(options.capture)
1076
- : Boolean(options);
1077
- const listenerType = capture ? CAPTURE : BUBBLE;
1078
- const newNode = {
1079
- listener,
1080
- listenerType,
1081
- passive: optionsIsObj && Boolean(options.passive),
1082
- once: optionsIsObj && Boolean(options.once),
1083
- next: null,
1084
- };
1085
-
1086
- // Set it as the first node if the first node is null.
1087
- let node = listeners.get(eventName);
1088
- if (node === undefined) {
1089
- listeners.set(eventName, newNode);
1090
- return
1091
- }
1092
-
1093
- // Traverse to the tail while checking duplication..
1094
- let prev = null;
1095
- while (node != null) {
1096
- if (
1097
- node.listener === listener &&
1098
- node.listenerType === listenerType
1099
- ) {
1100
- // Should ignore duplication.
1101
- return
1102
- }
1103
- prev = node;
1104
- node = node.next;
1105
- }
1106
-
1107
- // Add it.
1108
- prev.next = newNode;
1109
- },
1110
-
1111
- /**
1112
- * Remove a given listener from this event target.
1113
- * @param {string} eventName The event name to remove.
1114
- * @param {Function} listener The listener to remove.
1115
- * @param {boolean|{capture?:boolean,passive?:boolean,once?:boolean}} [options] The options for this listener.
1116
- * @returns {void}
1117
- */
1118
- removeEventListener(eventName, listener, options) {
1119
- if (listener == null) {
1120
- return
1121
- }
1122
-
1123
- const listeners = getListeners(this);
1124
- const capture = isObject(options)
1125
- ? Boolean(options.capture)
1126
- : Boolean(options);
1127
- const listenerType = capture ? CAPTURE : BUBBLE;
1128
-
1129
- let prev = null;
1130
- let node = listeners.get(eventName);
1131
- while (node != null) {
1132
- if (
1133
- node.listener === listener &&
1134
- node.listenerType === listenerType
1135
- ) {
1136
- if (prev !== null) {
1137
- prev.next = node.next;
1138
- } else if (node.next !== null) {
1139
- listeners.set(eventName, node.next);
1140
- } else {
1141
- listeners.delete(eventName);
1142
- }
1143
- return
1144
- }
1145
-
1146
- prev = node;
1147
- node = node.next;
1148
- }
1149
- },
1150
-
1151
- /**
1152
- * Dispatch a given event.
1153
- * @param {Event|{type:string}} event The event to dispatch.
1154
- * @returns {boolean} `false` if canceled.
1155
- */
1156
- dispatchEvent(event) {
1157
- if (event == null || typeof event.type !== "string") {
1158
- throw new TypeError('"event.type" should be a string.')
1159
- }
1160
-
1161
- // If listeners aren't registered, terminate.
1162
- const listeners = getListeners(this);
1163
- const eventName = event.type;
1164
- let node = listeners.get(eventName);
1165
- if (node == null) {
1166
- return true
1167
- }
1168
-
1169
- // Since we cannot rewrite several properties, so wrap object.
1170
- const wrappedEvent = wrapEvent(this, event);
1171
-
1172
- // This doesn't process capturing phase and bubbling phase.
1173
- // This isn't participating in a tree.
1174
- let prev = null;
1175
- while (node != null) {
1176
- // Remove this listener if it's once
1177
- if (node.once) {
1178
- if (prev !== null) {
1179
- prev.next = node.next;
1180
- } else if (node.next !== null) {
1181
- listeners.set(eventName, node.next);
1182
- } else {
1183
- listeners.delete(eventName);
1184
- }
1185
- } else {
1186
- prev = node;
1187
- }
1188
-
1189
- // Call this listener
1190
- setPassiveListener(
1191
- wrappedEvent,
1192
- node.passive ? node.listener : null
1193
- );
1194
- if (typeof node.listener === "function") {
1195
- try {
1196
- node.listener.call(this, wrappedEvent);
1197
- } catch (err) {
1198
- if (
1199
- typeof console !== "undefined" &&
1200
- typeof console.error === "function"
1201
- ) {
1202
- console.error(err);
1203
- }
1204
- }
1205
- } else if (
1206
- node.listenerType !== ATTRIBUTE &&
1207
- typeof node.listener.handleEvent === "function"
1208
- ) {
1209
- node.listener.handleEvent(wrappedEvent);
1210
- }
1211
-
1212
- // Break if `event.stopImmediatePropagation` was called.
1213
- if (isStopped(wrappedEvent)) {
1214
- break
1215
- }
1216
-
1217
- node = node.next;
1218
- }
1219
- setPassiveListener(wrappedEvent, null);
1220
- setEventPhase(wrappedEvent, 0);
1221
- setCurrentTarget(wrappedEvent, null);
1222
-
1223
- return !wrappedEvent.defaultPrevented
1224
- },
1225
- };
1226
-
1227
- // `constructor` is not enumerable.
1228
- Object.defineProperty(EventTarget.prototype, "constructor", {
1229
- value: EventTarget,
1230
- configurable: true,
1231
- writable: true,
1232
- });
1233
-
1234
- // Ensure `eventTarget instanceof window.EventTarget` is `true`.
1235
- if (
1236
- typeof window !== "undefined" &&
1237
- typeof window.EventTarget !== "undefined"
1238
- ) {
1239
- Object.setPrototypeOf(EventTarget.prototype, window.EventTarget.prototype);
1240
- }
1241
-
1242
- /**
1243
- * @author Toru Nagashima <https://github.com/mysticatea>
1244
- * See LICENSE file in root directory for full license.
1245
- */
1246
-
1247
- /**
1248
- * The signal class.
1249
- * @see https://dom.spec.whatwg.org/#abortsignal
1250
- */
1251
- class AbortSignal extends EventTarget {
1252
- /**
1253
- * AbortSignal cannot be constructed directly.
1254
- */
1255
- constructor() {
1256
- super();
1257
- throw new TypeError("AbortSignal cannot be constructed directly");
1258
- }
1259
- /**
1260
- * Returns `true` if this `AbortSignal`'s `AbortController` has signaled to abort, and `false` otherwise.
1261
- */
1262
- get aborted() {
1263
- const aborted = abortedFlags.get(this);
1264
- if (typeof aborted !== "boolean") {
1265
- throw new TypeError(`Expected 'this' to be an 'AbortSignal' object, but got ${this === null ? "null" : typeof this}`);
1266
- }
1267
- return aborted;
1268
- }
1269
- }
1270
- defineEventAttribute(AbortSignal.prototype, "abort");
1271
- /**
1272
- * Create an AbortSignal object.
1273
- */
1274
- function createAbortSignal() {
1275
- const signal = Object.create(AbortSignal.prototype);
1276
- EventTarget.call(signal);
1277
- abortedFlags.set(signal, false);
1278
- return signal;
1279
- }
1280
- /**
1281
- * Abort a given signal.
1282
- */
1283
- function abortSignal(signal) {
1284
- if (abortedFlags.get(signal) !== false) {
1285
- return;
1286
- }
1287
- abortedFlags.set(signal, true);
1288
- signal.dispatchEvent({ type: "abort" });
1289
- }
1290
- /**
1291
- * Aborted flag for each instances.
1292
- */
1293
- const abortedFlags = new WeakMap();
1294
- // Properties should be enumerable.
1295
- Object.defineProperties(AbortSignal.prototype, {
1296
- aborted: { enumerable: true },
1297
- });
1298
- // `toString()` should return `"[object AbortSignal]"`
1299
- if (typeof Symbol === "function" && typeof Symbol.toStringTag === "symbol") {
1300
- Object.defineProperty(AbortSignal.prototype, Symbol.toStringTag, {
1301
- configurable: true,
1302
- value: "AbortSignal",
1303
- });
1304
- }
1305
-
1306
- /**
1307
- * The AbortController.
1308
- * @see https://dom.spec.whatwg.org/#abortcontroller
1309
- */
1310
- class AbortController {
1311
- /**
1312
- * Initialize this controller.
1313
- */
1314
- constructor() {
1315
- signals.set(this, createAbortSignal());
1316
- }
1317
- /**
1318
- * Returns the `AbortSignal` object associated with this object.
1319
- */
1320
- get signal() {
1321
- return getSignal(this);
1322
- }
1323
- /**
1324
- * Abort and signal to any observers that the associated activity is to be aborted.
1325
- */
1326
- abort() {
1327
- abortSignal(getSignal(this));
1328
- }
1329
- }
1330
- /**
1331
- * Associated signals.
1332
- */
1333
- const signals = new WeakMap();
1334
- /**
1335
- * Get the associated signal of a given controller.
1336
- */
1337
- function getSignal(controller) {
1338
- const signal = signals.get(controller);
1339
- if (signal == null) {
1340
- throw new TypeError(`Expected 'this' to be an 'AbortController' object, but got ${controller === null ? "null" : typeof controller}`);
1341
- }
1342
- return signal;
1343
- }
1344
- // Properties should be enumerable.
1345
- Object.defineProperties(AbortController.prototype, {
1346
- signal: { enumerable: true },
1347
- abort: { enumerable: true },
1348
- });
1349
- if (typeof Symbol === "function" && typeof Symbol.toStringTag === "symbol") {
1350
- Object.defineProperty(AbortController.prototype, Symbol.toStringTag, {
1351
- configurable: true,
1352
- value: "AbortController",
1353
- });
1354
- }
1355
-
383
+ var httpRequest, httpsRequest, parse, CustomAbortController;
384
+ if (typeof require !== "undefined") {
385
+ CustomAbortController = require("abort-controller");
386
+ httpRequest = require("http").request;
387
+ httpsRequest = require("https").request;
388
+ parse = require("url").parse;
389
+ }
390
+ else if (typeof AbortController !== "undefined") {
391
+ CustomAbortController = AbortController;
392
+ }
393
+ else {
394
+ CustomAbortController = function () {
395
+ throw new Error('AbortController is not defined');
396
+ };
397
+ }
1356
398
  var Interceptors = (function () {
1357
399
  function Interceptors() {
1358
400
  }
@@ -1461,7 +503,7 @@
1461
503
  var _this = _super.call(this, origin) || this;
1462
504
  _this.initDefaultParams = function (url, _a) {
1463
505
  var _b, _c;
1464
- var _d = _a.method, method = _d === void 0 ? "GET" : _d, _e = _a.query, query = _e === void 0 ? {} : _e, _f = _a.headers, headers = _f === void 0 ? {} : _f, _g = _a.body, body = _g === void 0 ? null : _g, _h = _a.timeout, timeout = _h === void 0 ? 30 * 1000 : _h, _j = _a.controller, controller = _j === void 0 ? new AbortController() : _j, _k = _a.type, type = _k === void 0 ? "json" : _k, others = __rest(_a, ["method", "query", "headers", "body", "timeout", "controller", "type"]);
506
+ var _d = _a.method, method = _d === void 0 ? "GET" : _d, _e = _a.query, query = _e === void 0 ? {} : _e, _f = _a.headers, headers = _f === void 0 ? {} : _f, _g = _a.body, body = _g === void 0 ? null : _g, _h = _a.timeout, timeout = _h === void 0 ? 30 * 1000 : _h, _j = _a.controller, controller = _j === void 0 ? new CustomAbortController() : _j, _k = _a.type, type = _k === void 0 ? "json" : _k, others = __rest(_a, ["method", "query", "headers", "body", "timeout", "controller", "type"]);
1465
507
  var __params = __assign$1({ url: url, method: method, query: query, headers: headers, body: method === "GET" ? null : jsonToString(body), timeout: timeout, signal: controller === null || controller === void 0 ? void 0 : controller.signal, controller: controller, type: type, timer: null }, others);
1466
508
  var params = (_c = (_b = _this.reqFn) === null || _b === void 0 ? void 0 : _b.call(_this, __params)) !== null && _c !== void 0 ? _c : __params;
1467
509
  params.url = urlJoin(_this.fixOrigin(url), __params.query);
@@ -1471,9 +513,9 @@
1471
513
  var _temp = _this.initAbort(_this.initDefaultParams(url, opts));
1472
514
  return _temp;
1473
515
  };
1474
- _this.initHttpParams = function (url$1, opts) {
1475
- var _temp = _this.initAbort(_this.initDefaultParams(url$1, opts));
1476
- var options = url.parse(_temp.url, true);
516
+ _this.initHttpParams = function (url, opts) {
517
+ var _temp = _this.initAbort(_this.initDefaultParams(url, opts));
518
+ var options = parse(_temp.url, true);
1477
519
  return __assign$1(__assign$1({}, _temp), options);
1478
520
  };
1479
521
  return _this;
@@ -1503,7 +545,7 @@
1503
545
  var params = _this.initHttpParams(_url, _opts);
1504
546
  var signal = params.signal, url = params.url;
1505
547
  promise.finally(function () { return _this.clearTimer(params); });
1506
- var request = _this.checkIsHttps(url) ? https.request : http.request;
548
+ var request = _this.checkIsHttps(url) ? httpsRequest : httpRequest;
1507
549
  var req = request(params, function (response) {
1508
550
  if ((response === null || response === void 0 ? void 0 : response.statusCode) >= 200 && (response === null || response === void 0 ? void 0 : response.statusCode) < 300) {
1509
551
  var data_1 = "";