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