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