utils-lib-js 1.7.2 → 1.7.4

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