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