@waku/core 0.0.26-678635e.0 → 0.0.26
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/CHANGELOG.md +30 -0
- package/bundle/base_protocol-pDODy0G6.js +260 -0
- package/bundle/{base_protocol-4bcf7514.js → browser-mTOOnVZp.js} +751 -381
- package/bundle/index-cmONXM-V.js +595 -0
- package/bundle/index.js +637 -1879
- package/bundle/lib/base_protocol.js +3 -3
- package/bundle/lib/message/version_0.js +3 -3
- package/bundle/lib/predefined_bootstrap_nodes.js +1 -1
- package/bundle/{version_0-2f1176e3.js → version_0-LQTFNC7k.js} +118 -11
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/base_protocol.d.ts +3 -2
- package/dist/lib/base_protocol.js +12 -6
- package/dist/lib/base_protocol.js.map +1 -1
- package/dist/lib/connection_manager.d.ts +8 -4
- package/dist/lib/connection_manager.js +34 -12
- package/dist/lib/connection_manager.js.map +1 -1
- package/dist/lib/filter/index.js +8 -5
- package/dist/lib/filter/index.js.map +1 -1
- package/dist/lib/filterPeers.js.map +1 -1
- package/dist/lib/keep_alive_manager.d.ts +1 -0
- package/dist/lib/keep_alive_manager.js +6 -3
- package/dist/lib/keep_alive_manager.js.map +1 -1
- package/dist/lib/light_push/index.js +1 -2
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/message/version_0.d.ts +7 -7
- package/dist/lib/message/version_0.js +5 -6
- package/dist/lib/message/version_0.js.map +1 -1
- package/dist/lib/metadata/index.d.ts +3 -0
- package/dist/lib/metadata/index.js +67 -0
- package/dist/lib/metadata/index.js.map +1 -0
- package/dist/lib/predefined_bootstrap_nodes.js.map +1 -1
- package/dist/lib/store/history_rpc.js.map +1 -1
- package/dist/lib/store/index.js +10 -11
- package/dist/lib/store/index.js.map +1 -1
- package/dist/lib/stream_manager.js.map +1 -1
- package/dist/lib/wait_for_remote_peer.js.map +1 -1
- package/dist/lib/waku.d.ts +4 -3
- package/dist/lib/waku.js +15 -6
- package/dist/lib/waku.js.map +1 -1
- package/package.json +127 -1
- package/src/index.ts +3 -1
- package/src/lib/base_protocol.ts +29 -7
- package/src/lib/connection_manager.ts +44 -13
- package/src/lib/filter/index.ts +18 -11
- package/src/lib/keep_alive_manager.ts +9 -3
- package/src/lib/light_push/index.ts +3 -4
- package/src/lib/message/version_0.ts +18 -10
- package/src/lib/metadata/index.ts +110 -0
- package/src/lib/store/index.ts +12 -13
- package/src/lib/waku.ts +19 -5
- package/bundle/browser-90197c87.js +0 -754
- package/bundle/index-27b91e3b.js +0 -31
- package/dist/lib/constants.d.ts +0 -4
- package/dist/lib/constants.js +0 -5
- package/dist/lib/constants.js.map +0 -1
- package/src/lib/constants.ts +0 -4
@@ -1,5 +1,3 @@
|
|
1
|
-
import { L as Logger } from './index-27b91e3b.js';
|
2
|
-
|
3
1
|
// base-x encoding / decoding
|
4
2
|
// Copyright (c) 2018 base-x contributors
|
5
3
|
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
@@ -162,13 +160,13 @@ const coerce = o => {
|
|
162
160
|
* @param {string} str
|
163
161
|
* @returns {Uint8Array}
|
164
162
|
*/
|
165
|
-
const fromString
|
163
|
+
const fromString = str => (new TextEncoder()).encode(str);
|
166
164
|
|
167
165
|
/**
|
168
166
|
* @param {Uint8Array} b
|
169
167
|
* @returns {string}
|
170
168
|
*/
|
171
|
-
const toString
|
169
|
+
const toString = b => (new TextDecoder()).decode(b);
|
172
170
|
|
173
171
|
/**
|
174
172
|
* Class represents both BaseEncoder and MultibaseEncoder meaning it
|
@@ -776,8 +774,8 @@ var base8$1 = /*#__PURE__*/Object.freeze({
|
|
776
774
|
const identity = from({
|
777
775
|
prefix: '\x00',
|
778
776
|
name: 'identity',
|
779
|
-
encode: (buf) => toString
|
780
|
-
decode: (str) => fromString
|
777
|
+
encode: (buf) => toString(buf),
|
778
|
+
decode: (str) => fromString(str)
|
781
779
|
});
|
782
780
|
|
783
781
|
var identityBase = /*#__PURE__*/Object.freeze({
|
@@ -795,127 +793,6 @@ var identityBase = /*#__PURE__*/Object.freeze({
|
|
795
793
|
new TextEncoder();
|
796
794
|
new TextDecoder();
|
797
795
|
|
798
|
-
// @ts-check
|
799
|
-
|
800
|
-
|
801
|
-
const bases = { ...identityBase, ...base2$1, ...base8$1, ...base10$1, ...base16$1, ...base32$1, ...base36$1, ...base58, ...base64$1, ...base256emoji$1 };
|
802
|
-
|
803
|
-
/**
|
804
|
-
* To guarantee Uint8Array semantics, convert nodejs Buffers
|
805
|
-
* into vanilla Uint8Arrays
|
806
|
-
*/
|
807
|
-
function asUint8Array(buf) {
|
808
|
-
if (globalThis.Buffer != null) {
|
809
|
-
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
810
|
-
}
|
811
|
-
return buf;
|
812
|
-
}
|
813
|
-
|
814
|
-
/**
|
815
|
-
* Returns a `Uint8Array` of the requested size. Referenced memory will
|
816
|
-
* be initialized to 0.
|
817
|
-
*/
|
818
|
-
function alloc(size = 0) {
|
819
|
-
if (globalThis.Buffer?.alloc != null) {
|
820
|
-
return asUint8Array(globalThis.Buffer.alloc(size));
|
821
|
-
}
|
822
|
-
return new Uint8Array(size);
|
823
|
-
}
|
824
|
-
/**
|
825
|
-
* Where possible returns a Uint8Array of the requested size that references
|
826
|
-
* uninitialized memory. Only use if you are certain you will immediately
|
827
|
-
* overwrite every value in the returned `Uint8Array`.
|
828
|
-
*/
|
829
|
-
function allocUnsafe(size = 0) {
|
830
|
-
if (globalThis.Buffer?.allocUnsafe != null) {
|
831
|
-
return asUint8Array(globalThis.Buffer.allocUnsafe(size));
|
832
|
-
}
|
833
|
-
return new Uint8Array(size);
|
834
|
-
}
|
835
|
-
|
836
|
-
function createCodec(name, prefix, encode, decode) {
|
837
|
-
return {
|
838
|
-
name,
|
839
|
-
prefix,
|
840
|
-
encoder: {
|
841
|
-
name,
|
842
|
-
prefix,
|
843
|
-
encode
|
844
|
-
},
|
845
|
-
decoder: {
|
846
|
-
decode
|
847
|
-
}
|
848
|
-
};
|
849
|
-
}
|
850
|
-
const string = createCodec('utf8', 'u', (buf) => {
|
851
|
-
const decoder = new TextDecoder('utf8');
|
852
|
-
return 'u' + decoder.decode(buf);
|
853
|
-
}, (str) => {
|
854
|
-
const encoder = new TextEncoder();
|
855
|
-
return encoder.encode(str.substring(1));
|
856
|
-
});
|
857
|
-
const ascii = createCodec('ascii', 'a', (buf) => {
|
858
|
-
let string = 'a';
|
859
|
-
for (let i = 0; i < buf.length; i++) {
|
860
|
-
string += String.fromCharCode(buf[i]);
|
861
|
-
}
|
862
|
-
return string;
|
863
|
-
}, (str) => {
|
864
|
-
str = str.substring(1);
|
865
|
-
const buf = allocUnsafe(str.length);
|
866
|
-
for (let i = 0; i < str.length; i++) {
|
867
|
-
buf[i] = str.charCodeAt(i);
|
868
|
-
}
|
869
|
-
return buf;
|
870
|
-
});
|
871
|
-
const BASES = {
|
872
|
-
utf8: string,
|
873
|
-
'utf-8': string,
|
874
|
-
hex: bases.base16,
|
875
|
-
latin1: ascii,
|
876
|
-
ascii,
|
877
|
-
binary: ascii,
|
878
|
-
...bases
|
879
|
-
};
|
880
|
-
|
881
|
-
/**
|
882
|
-
* Turns a `Uint8Array` into a string.
|
883
|
-
*
|
884
|
-
* Supports `utf8`, `utf-8` and any encoding supported by the multibase module.
|
885
|
-
*
|
886
|
-
* Also `ascii` which is similar to node's 'binary' encoding.
|
887
|
-
*/
|
888
|
-
function toString(array, encoding = 'utf8') {
|
889
|
-
const base = BASES[encoding];
|
890
|
-
if (base == null) {
|
891
|
-
throw new Error(`Unsupported encoding "${encoding}"`);
|
892
|
-
}
|
893
|
-
if ((encoding === 'utf8' || encoding === 'utf-8') && globalThis.Buffer != null && globalThis.Buffer.from != null) {
|
894
|
-
return globalThis.Buffer.from(array.buffer, array.byteOffset, array.byteLength).toString('utf8');
|
895
|
-
}
|
896
|
-
// strip multibase prefix
|
897
|
-
return base.encoder.encode(array).substring(1);
|
898
|
-
}
|
899
|
-
|
900
|
-
/**
|
901
|
-
* Create a `Uint8Array` from the passed string
|
902
|
-
*
|
903
|
-
* Supports `utf8`, `utf-8`, `hex`, and any encoding supported by the multiformats module.
|
904
|
-
*
|
905
|
-
* Also `ascii` which is similar to node's 'binary' encoding.
|
906
|
-
*/
|
907
|
-
function fromString(string, encoding = 'utf8') {
|
908
|
-
const base = BASES[encoding];
|
909
|
-
if (base == null) {
|
910
|
-
throw new Error(`Unsupported encoding "${encoding}"`);
|
911
|
-
}
|
912
|
-
if ((encoding === 'utf8' || encoding === 'utf-8') && globalThis.Buffer != null && globalThis.Buffer.from != null) {
|
913
|
-
return asUint8Array(globalThis.Buffer.from(string, 'utf-8'));
|
914
|
-
}
|
915
|
-
// add multibase prefix
|
916
|
-
return base.decoder.decode(`${base.prefix}${string}`); // eslint-disable-line @typescript-eslint/restrict-template-expressions
|
917
|
-
}
|
918
|
-
|
919
796
|
var Protocols;
|
920
797
|
(function (Protocols) {
|
921
798
|
Protocols["Relay"] = "relay";
|
@@ -948,8 +825,8 @@ var SendError;
|
|
948
825
|
*/
|
949
826
|
SendError["SIZE_TOO_BIG"] = "Size is too big";
|
950
827
|
/**
|
951
|
-
* The
|
952
|
-
* Please ensure that the
|
828
|
+
* The PubsubTopic passed to the send function is not configured on the Waku node.
|
829
|
+
* Please ensure that the PubsubTopic is used when initializing the Waku node.
|
953
830
|
*/
|
954
831
|
SendError["TOPIC_NOT_CONFIGURED"] = "Topic not configured";
|
955
832
|
/**
|
@@ -990,269 +867,762 @@ var EPeersByDiscoveryEvents;
|
|
990
867
|
EPeersByDiscoveryEvents["PEER_CONNECT_BOOTSTRAP"] = "peer:connected:bootstrap";
|
991
868
|
EPeersByDiscoveryEvents["PEER_CONNECT_PEER_EXCHANGE"] = "peer:connected:peer-exchange";
|
992
869
|
})(EPeersByDiscoveryEvents || (EPeersByDiscoveryEvents = {}));
|
870
|
+
var EConnectionStateEvents;
|
871
|
+
(function (EConnectionStateEvents) {
|
872
|
+
EConnectionStateEvents["CONNECTION_STATUS"] = "waku:connection";
|
873
|
+
})(EConnectionStateEvents || (EConnectionStateEvents = {}));
|
993
874
|
|
994
|
-
|
995
|
-
* Decode byte array to utf-8 string.
|
996
|
-
*/
|
997
|
-
const bytesToUtf8 = (b) => toString(b, "utf8");
|
998
|
-
/**
|
999
|
-
* Encode utf-8 string to byte array.
|
1000
|
-
*/
|
1001
|
-
const utf8ToBytes = (s) => fromString(s, "utf8");
|
1002
|
-
/**
|
1003
|
-
* Concatenate using Uint8Arrays as `Buffer` has a different behavior with `DataView`
|
1004
|
-
*/
|
1005
|
-
function concat(byteArrays, totalLength) {
|
1006
|
-
const len = totalLength ?? byteArrays.reduce((acc, curr) => acc + curr.length, 0);
|
1007
|
-
const res = new Uint8Array(len);
|
1008
|
-
let offset = 0;
|
1009
|
-
for (const bytes of byteArrays) {
|
1010
|
-
res.set(bytes, offset);
|
1011
|
-
offset += bytes.length;
|
1012
|
-
}
|
1013
|
-
return res;
|
1014
|
-
}
|
875
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
1015
876
|
|
1016
|
-
|
1017
|
-
|
1018
|
-
* Useful for protocols such as store and light push
|
1019
|
-
*/
|
1020
|
-
function selectRandomPeer(peers) {
|
1021
|
-
if (peers.length === 0)
|
1022
|
-
return;
|
1023
|
-
const index = Math.round(Math.random() * (peers.length - 1));
|
1024
|
-
return peers[index];
|
1025
|
-
}
|
1026
|
-
/**
|
1027
|
-
* Returns the peer with the lowest latency.
|
1028
|
-
* @param peerStore - The Libp2p PeerStore
|
1029
|
-
* @param peers - The list of peers to choose from
|
1030
|
-
* @returns The peer with the lowest latency, or undefined if no peer could be reached
|
1031
|
-
*/
|
1032
|
-
async function selectLowestLatencyPeer(peerStore, peers) {
|
1033
|
-
if (peers.length === 0)
|
1034
|
-
return;
|
1035
|
-
const results = await Promise.all(peers.map(async (peer) => {
|
1036
|
-
const pingBytes = (await peerStore.get(peer.id)).metadata.get("ping");
|
1037
|
-
if (!pingBytes)
|
1038
|
-
return { peer, ping: Infinity };
|
1039
|
-
const ping = Number(bytesToUtf8(pingBytes)) ?? Infinity;
|
1040
|
-
return { peer, ping };
|
1041
|
-
}));
|
1042
|
-
const lowestLatencyResult = results.sort((a, b) => a.ping - b.ping)[0];
|
1043
|
-
if (!lowestLatencyResult) {
|
1044
|
-
return undefined;
|
1045
|
-
}
|
1046
|
-
return lowestLatencyResult.ping !== Infinity
|
1047
|
-
? lowestLatencyResult.peer
|
1048
|
-
: undefined;
|
1049
|
-
}
|
1050
|
-
/**
|
1051
|
-
* Returns the list of peers that supports the given protocol.
|
1052
|
-
*/
|
1053
|
-
async function getPeersForProtocol(peerStore, protocols) {
|
1054
|
-
const peers = [];
|
1055
|
-
await peerStore.forEach((peer) => {
|
1056
|
-
for (let i = 0; i < protocols.length; i++) {
|
1057
|
-
if (peer.protocols.includes(protocols[i])) {
|
1058
|
-
peers.push(peer);
|
1059
|
-
break;
|
1060
|
-
}
|
1061
|
-
}
|
1062
|
-
});
|
1063
|
-
return peers;
|
1064
|
-
}
|
1065
|
-
/**
|
1066
|
-
* Returns a peer that supports the given protocol.
|
1067
|
-
* If peerId is provided, the peer with that id is returned.
|
1068
|
-
* Otherwise, the peer with the lowest latency is returned.
|
1069
|
-
* If no peer is found from the above criteria, a random peer is returned.
|
1070
|
-
*/
|
1071
|
-
async function selectPeerForProtocol(peerStore, protocols, peerId) {
|
1072
|
-
let peer;
|
1073
|
-
if (peerId) {
|
1074
|
-
peer = await peerStore.get(peerId);
|
1075
|
-
if (!peer) {
|
1076
|
-
throw new Error(`Failed to retrieve connection details for provided peer in peer store: ${peerId.toString()}`);
|
1077
|
-
}
|
1078
|
-
}
|
1079
|
-
else {
|
1080
|
-
const peers = await getPeersForProtocol(peerStore, protocols);
|
1081
|
-
peer = await selectLowestLatencyPeer(peerStore, peers);
|
1082
|
-
if (!peer) {
|
1083
|
-
peer = selectRandomPeer(peers);
|
1084
|
-
if (!peer)
|
1085
|
-
throw new Error(`Failed to find known peer that registers protocols: ${protocols}`);
|
1086
|
-
}
|
1087
|
-
}
|
1088
|
-
let protocol;
|
1089
|
-
for (const codec of protocols) {
|
1090
|
-
if (peer.protocols.includes(codec)) {
|
1091
|
-
protocol = codec;
|
1092
|
-
// Do not break as we want to keep the last value
|
1093
|
-
}
|
1094
|
-
}
|
1095
|
-
if (!protocol) {
|
1096
|
-
throw new Error(`Peer does not register required protocols (${peer.id.toString()}): ${protocols}`);
|
1097
|
-
}
|
1098
|
-
return { peer, protocol };
|
877
|
+
function getDefaultExportFromCjs (x) {
|
878
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
1099
879
|
}
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
880
|
+
|
881
|
+
function getAugmentedNamespace(n) {
|
882
|
+
if (n.__esModule) return n;
|
883
|
+
var f = n.default;
|
884
|
+
if (typeof f == "function") {
|
885
|
+
var a = function a () {
|
886
|
+
if (this instanceof a) {
|
887
|
+
return Reflect.construct(f, arguments, this.constructor);
|
888
|
+
}
|
889
|
+
return f.apply(this, arguments);
|
890
|
+
};
|
891
|
+
a.prototype = f.prototype;
|
892
|
+
} else a = {};
|
893
|
+
Object.defineProperty(a, '__esModule', {value: true});
|
894
|
+
Object.keys(n).forEach(function (k) {
|
895
|
+
var d = Object.getOwnPropertyDescriptor(n, k);
|
896
|
+
Object.defineProperty(a, k, d.get ? d : {
|
897
|
+
enumerable: true,
|
898
|
+
get: function () {
|
899
|
+
return n[k];
|
900
|
+
}
|
901
|
+
});
|
902
|
+
});
|
903
|
+
return a;
|
1117
904
|
}
|
1118
905
|
|
906
|
+
var browser = {exports: {}};
|
907
|
+
|
1119
908
|
/**
|
1120
|
-
*
|
1121
|
-
*
|
1122
|
-
* @param peers - The list of peers to filter from.
|
1123
|
-
* @param numPeers - The total number of peers to retrieve. If 0, all peers are returned.
|
1124
|
-
* @param maxBootstrapPeers - The maximum number of bootstrap peers to retrieve.
|
1125
|
-
* @returns A Promise that resolves to an array of peers based on the specified criteria.
|
909
|
+
* Helpers.
|
1126
910
|
*/
|
1127
|
-
async function filterPeers(peers, numPeers, maxBootstrapPeers) {
|
1128
|
-
// Collect the bootstrap peers up to the specified maximum
|
1129
|
-
const bootstrapPeers = peers
|
1130
|
-
.filter((peer) => peer.tags.has(Tags.BOOTSTRAP))
|
1131
|
-
.slice(0, maxBootstrapPeers);
|
1132
|
-
// Collect non-bootstrap peers
|
1133
|
-
const nonBootstrapPeers = peers.filter((peer) => !peer.tags.has(Tags.BOOTSTRAP));
|
1134
|
-
// If numPeers is 0, return all peers
|
1135
|
-
if (numPeers === 0) {
|
1136
|
-
return [...bootstrapPeers, ...nonBootstrapPeers];
|
1137
|
-
}
|
1138
|
-
// Initialize the list of selected peers with the bootstrap peers
|
1139
|
-
const selectedPeers = [...bootstrapPeers];
|
1140
|
-
// Fill up to numPeers with remaining random peers if needed
|
1141
|
-
while (selectedPeers.length < numPeers && nonBootstrapPeers.length > 0) {
|
1142
|
-
const randomIndex = Math.floor(Math.random() * nonBootstrapPeers.length);
|
1143
|
-
const randomPeer = nonBootstrapPeers.splice(randomIndex, 1)[0];
|
1144
|
-
selectedPeers.push(randomPeer);
|
1145
|
-
}
|
1146
|
-
return selectedPeers;
|
1147
|
-
}
|
1148
911
|
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
912
|
+
var ms;
|
913
|
+
var hasRequiredMs;
|
914
|
+
|
915
|
+
function requireMs () {
|
916
|
+
if (hasRequiredMs) return ms;
|
917
|
+
hasRequiredMs = 1;
|
918
|
+
var s = 1000;
|
919
|
+
var m = s * 60;
|
920
|
+
var h = m * 60;
|
921
|
+
var d = h * 24;
|
922
|
+
var w = d * 7;
|
923
|
+
var y = d * 365.25;
|
924
|
+
|
925
|
+
/**
|
926
|
+
* Parse or format the given `val`.
|
927
|
+
*
|
928
|
+
* Options:
|
929
|
+
*
|
930
|
+
* - `long` verbose formatting [false]
|
931
|
+
*
|
932
|
+
* @param {String|Number} val
|
933
|
+
* @param {Object} [options]
|
934
|
+
* @throws {Error} throw an error if val is not a non-empty string or a number
|
935
|
+
* @return {String|Number}
|
936
|
+
* @api public
|
937
|
+
*/
|
938
|
+
|
939
|
+
ms = function(val, options) {
|
940
|
+
options = options || {};
|
941
|
+
var type = typeof val;
|
942
|
+
if (type === 'string' && val.length > 0) {
|
943
|
+
return parse(val);
|
944
|
+
} else if (type === 'number' && isFinite(val)) {
|
945
|
+
return options.long ? fmtLong(val) : fmtShort(val);
|
946
|
+
}
|
947
|
+
throw new Error(
|
948
|
+
'val is not a non-empty string or a valid number. val=' +
|
949
|
+
JSON.stringify(val)
|
950
|
+
);
|
951
|
+
};
|
952
|
+
|
953
|
+
/**
|
954
|
+
* Parse the given `str` and return milliseconds.
|
955
|
+
*
|
956
|
+
* @param {String} str
|
957
|
+
* @return {Number}
|
958
|
+
* @api private
|
959
|
+
*/
|
960
|
+
|
961
|
+
function parse(str) {
|
962
|
+
str = String(str);
|
963
|
+
if (str.length > 100) {
|
964
|
+
return;
|
965
|
+
}
|
966
|
+
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
967
|
+
str
|
968
|
+
);
|
969
|
+
if (!match) {
|
970
|
+
return;
|
971
|
+
}
|
972
|
+
var n = parseFloat(match[1]);
|
973
|
+
var type = (match[2] || 'ms').toLowerCase();
|
974
|
+
switch (type) {
|
975
|
+
case 'years':
|
976
|
+
case 'year':
|
977
|
+
case 'yrs':
|
978
|
+
case 'yr':
|
979
|
+
case 'y':
|
980
|
+
return n * y;
|
981
|
+
case 'weeks':
|
982
|
+
case 'week':
|
983
|
+
case 'w':
|
984
|
+
return n * w;
|
985
|
+
case 'days':
|
986
|
+
case 'day':
|
987
|
+
case 'd':
|
988
|
+
return n * d;
|
989
|
+
case 'hours':
|
990
|
+
case 'hour':
|
991
|
+
case 'hrs':
|
992
|
+
case 'hr':
|
993
|
+
case 'h':
|
994
|
+
return n * h;
|
995
|
+
case 'minutes':
|
996
|
+
case 'minute':
|
997
|
+
case 'mins':
|
998
|
+
case 'min':
|
999
|
+
case 'm':
|
1000
|
+
return n * m;
|
1001
|
+
case 'seconds':
|
1002
|
+
case 'second':
|
1003
|
+
case 'secs':
|
1004
|
+
case 'sec':
|
1005
|
+
case 's':
|
1006
|
+
return n * s;
|
1007
|
+
case 'milliseconds':
|
1008
|
+
case 'millisecond':
|
1009
|
+
case 'msecs':
|
1010
|
+
case 'msec':
|
1011
|
+
case 'ms':
|
1012
|
+
return n;
|
1013
|
+
default:
|
1014
|
+
return undefined;
|
1015
|
+
}
|
1016
|
+
}
|
1017
|
+
|
1018
|
+
/**
|
1019
|
+
* Short format for `ms`.
|
1020
|
+
*
|
1021
|
+
* @param {Number} ms
|
1022
|
+
* @return {String}
|
1023
|
+
* @api private
|
1024
|
+
*/
|
1025
|
+
|
1026
|
+
function fmtShort(ms) {
|
1027
|
+
var msAbs = Math.abs(ms);
|
1028
|
+
if (msAbs >= d) {
|
1029
|
+
return Math.round(ms / d) + 'd';
|
1030
|
+
}
|
1031
|
+
if (msAbs >= h) {
|
1032
|
+
return Math.round(ms / h) + 'h';
|
1033
|
+
}
|
1034
|
+
if (msAbs >= m) {
|
1035
|
+
return Math.round(ms / m) + 'm';
|
1036
|
+
}
|
1037
|
+
if (msAbs >= s) {
|
1038
|
+
return Math.round(ms / s) + 's';
|
1039
|
+
}
|
1040
|
+
return ms + 'ms';
|
1041
|
+
}
|
1042
|
+
|
1043
|
+
/**
|
1044
|
+
* Long format for `ms`.
|
1045
|
+
*
|
1046
|
+
* @param {Number} ms
|
1047
|
+
* @return {String}
|
1048
|
+
* @api private
|
1049
|
+
*/
|
1050
|
+
|
1051
|
+
function fmtLong(ms) {
|
1052
|
+
var msAbs = Math.abs(ms);
|
1053
|
+
if (msAbs >= d) {
|
1054
|
+
return plural(ms, msAbs, d, 'day');
|
1055
|
+
}
|
1056
|
+
if (msAbs >= h) {
|
1057
|
+
return plural(ms, msAbs, h, 'hour');
|
1058
|
+
}
|
1059
|
+
if (msAbs >= m) {
|
1060
|
+
return plural(ms, msAbs, m, 'minute');
|
1061
|
+
}
|
1062
|
+
if (msAbs >= s) {
|
1063
|
+
return plural(ms, msAbs, s, 'second');
|
1064
|
+
}
|
1065
|
+
return ms + ' ms';
|
1066
|
+
}
|
1067
|
+
|
1068
|
+
/**
|
1069
|
+
* Pluralization helper.
|
1070
|
+
*/
|
1071
|
+
|
1072
|
+
function plural(ms, msAbs, n, name) {
|
1073
|
+
var isPlural = msAbs >= n * 1.5;
|
1074
|
+
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
1075
|
+
}
|
1076
|
+
return ms;
|
1201
1077
|
}
|
1202
1078
|
|
1203
1079
|
/**
|
1204
|
-
*
|
1205
|
-
*
|
1080
|
+
* This is the common logic for both the Node.js and web browser
|
1081
|
+
* implementations of `debug()`.
|
1206
1082
|
*/
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1083
|
+
|
1084
|
+
function setup(env) {
|
1085
|
+
createDebug.debug = createDebug;
|
1086
|
+
createDebug.default = createDebug;
|
1087
|
+
createDebug.coerce = coerce;
|
1088
|
+
createDebug.disable = disable;
|
1089
|
+
createDebug.enable = enable;
|
1090
|
+
createDebug.enabled = enabled;
|
1091
|
+
createDebug.humanize = requireMs();
|
1092
|
+
createDebug.destroy = destroy;
|
1093
|
+
|
1094
|
+
Object.keys(env).forEach(key => {
|
1095
|
+
createDebug[key] = env[key];
|
1096
|
+
});
|
1097
|
+
|
1098
|
+
/**
|
1099
|
+
* The currently active debug mode names, and names to skip.
|
1100
|
+
*/
|
1101
|
+
|
1102
|
+
createDebug.names = [];
|
1103
|
+
createDebug.skips = [];
|
1104
|
+
|
1105
|
+
/**
|
1106
|
+
* Map of special "%n" handling functions, for the debug "format" argument.
|
1107
|
+
*
|
1108
|
+
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
1109
|
+
*/
|
1110
|
+
createDebug.formatters = {};
|
1111
|
+
|
1112
|
+
/**
|
1113
|
+
* Selects a color for a debug namespace
|
1114
|
+
* @param {String} namespace The namespace string for the debug instance to be colored
|
1115
|
+
* @return {Number|String} An ANSI color code for the given namespace
|
1116
|
+
* @api private
|
1117
|
+
*/
|
1118
|
+
function selectColor(namespace) {
|
1119
|
+
let hash = 0;
|
1120
|
+
|
1121
|
+
for (let i = 0; i < namespace.length; i++) {
|
1122
|
+
hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
|
1123
|
+
hash |= 0; // Convert to 32bit integer
|
1124
|
+
}
|
1125
|
+
|
1126
|
+
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
1127
|
+
}
|
1128
|
+
createDebug.selectColor = selectColor;
|
1129
|
+
|
1130
|
+
/**
|
1131
|
+
* Create a debugger with the given `namespace`.
|
1132
|
+
*
|
1133
|
+
* @param {String} namespace
|
1134
|
+
* @return {Function}
|
1135
|
+
* @api public
|
1136
|
+
*/
|
1137
|
+
function createDebug(namespace) {
|
1138
|
+
let prevTime;
|
1139
|
+
let enableOverride = null;
|
1140
|
+
let namespacesCache;
|
1141
|
+
let enabledCache;
|
1142
|
+
|
1143
|
+
function debug(...args) {
|
1144
|
+
// Disabled?
|
1145
|
+
if (!debug.enabled) {
|
1146
|
+
return;
|
1147
|
+
}
|
1148
|
+
|
1149
|
+
const self = debug;
|
1150
|
+
|
1151
|
+
// Set `diff` timestamp
|
1152
|
+
const curr = Number(new Date());
|
1153
|
+
const ms = curr - (prevTime || curr);
|
1154
|
+
self.diff = ms;
|
1155
|
+
self.prev = prevTime;
|
1156
|
+
self.curr = curr;
|
1157
|
+
prevTime = curr;
|
1158
|
+
|
1159
|
+
args[0] = createDebug.coerce(args[0]);
|
1160
|
+
|
1161
|
+
if (typeof args[0] !== 'string') {
|
1162
|
+
// Anything else let's inspect with %O
|
1163
|
+
args.unshift('%O');
|
1164
|
+
}
|
1165
|
+
|
1166
|
+
// Apply any `formatters` transformations
|
1167
|
+
let index = 0;
|
1168
|
+
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
1169
|
+
// If we encounter an escaped % then don't increase the array index
|
1170
|
+
if (match === '%%') {
|
1171
|
+
return '%';
|
1172
|
+
}
|
1173
|
+
index++;
|
1174
|
+
const formatter = createDebug.formatters[format];
|
1175
|
+
if (typeof formatter === 'function') {
|
1176
|
+
const val = args[index];
|
1177
|
+
match = formatter.call(self, val);
|
1178
|
+
|
1179
|
+
// Now we need to remove `args[index]` since it's inlined in the `format`
|
1180
|
+
args.splice(index, 1);
|
1181
|
+
index--;
|
1182
|
+
}
|
1183
|
+
return match;
|
1184
|
+
});
|
1185
|
+
|
1186
|
+
// Apply env-specific formatting (colors, etc.)
|
1187
|
+
createDebug.formatArgs.call(self, args);
|
1188
|
+
|
1189
|
+
const logFn = self.log || createDebug.log;
|
1190
|
+
logFn.apply(self, args);
|
1191
|
+
}
|
1192
|
+
|
1193
|
+
debug.namespace = namespace;
|
1194
|
+
debug.useColors = createDebug.useColors();
|
1195
|
+
debug.color = createDebug.selectColor(namespace);
|
1196
|
+
debug.extend = extend;
|
1197
|
+
debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
|
1198
|
+
|
1199
|
+
Object.defineProperty(debug, 'enabled', {
|
1200
|
+
enumerable: true,
|
1201
|
+
configurable: false,
|
1202
|
+
get: () => {
|
1203
|
+
if (enableOverride !== null) {
|
1204
|
+
return enableOverride;
|
1205
|
+
}
|
1206
|
+
if (namespacesCache !== createDebug.namespaces) {
|
1207
|
+
namespacesCache = createDebug.namespaces;
|
1208
|
+
enabledCache = createDebug.enabled(namespace);
|
1209
|
+
}
|
1210
|
+
|
1211
|
+
return enabledCache;
|
1212
|
+
},
|
1213
|
+
set: v => {
|
1214
|
+
enableOverride = v;
|
1215
|
+
}
|
1216
|
+
});
|
1217
|
+
|
1218
|
+
// Env-specific initialization logic for debug instances
|
1219
|
+
if (typeof createDebug.init === 'function') {
|
1220
|
+
createDebug.init(debug);
|
1221
|
+
}
|
1222
|
+
|
1223
|
+
return debug;
|
1224
|
+
}
|
1225
|
+
|
1226
|
+
function extend(namespace, delimiter) {
|
1227
|
+
const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
1228
|
+
newDebug.log = this.log;
|
1229
|
+
return newDebug;
|
1230
|
+
}
|
1231
|
+
|
1232
|
+
/**
|
1233
|
+
* Enables a debug mode by namespaces. This can include modes
|
1234
|
+
* separated by a colon and wildcards.
|
1235
|
+
*
|
1236
|
+
* @param {String} namespaces
|
1237
|
+
* @api public
|
1238
|
+
*/
|
1239
|
+
function enable(namespaces) {
|
1240
|
+
createDebug.save(namespaces);
|
1241
|
+
createDebug.namespaces = namespaces;
|
1242
|
+
|
1243
|
+
createDebug.names = [];
|
1244
|
+
createDebug.skips = [];
|
1245
|
+
|
1246
|
+
let i;
|
1247
|
+
const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
1248
|
+
const len = split.length;
|
1249
|
+
|
1250
|
+
for (i = 0; i < len; i++) {
|
1251
|
+
if (!split[i]) {
|
1252
|
+
// ignore empty strings
|
1253
|
+
continue;
|
1254
|
+
}
|
1255
|
+
|
1256
|
+
namespaces = split[i].replace(/\*/g, '.*?');
|
1257
|
+
|
1258
|
+
if (namespaces[0] === '-') {
|
1259
|
+
createDebug.skips.push(new RegExp('^' + namespaces.slice(1) + '$'));
|
1260
|
+
} else {
|
1261
|
+
createDebug.names.push(new RegExp('^' + namespaces + '$'));
|
1262
|
+
}
|
1263
|
+
}
|
1264
|
+
}
|
1265
|
+
|
1266
|
+
/**
|
1267
|
+
* Disable debug output.
|
1268
|
+
*
|
1269
|
+
* @return {String} namespaces
|
1270
|
+
* @api public
|
1271
|
+
*/
|
1272
|
+
function disable() {
|
1273
|
+
const namespaces = [
|
1274
|
+
...createDebug.names.map(toNamespace),
|
1275
|
+
...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
|
1276
|
+
].join(',');
|
1277
|
+
createDebug.enable('');
|
1278
|
+
return namespaces;
|
1279
|
+
}
|
1280
|
+
|
1281
|
+
/**
|
1282
|
+
* Returns true if the given mode name is enabled, false otherwise.
|
1283
|
+
*
|
1284
|
+
* @param {String} name
|
1285
|
+
* @return {Boolean}
|
1286
|
+
* @api public
|
1287
|
+
*/
|
1288
|
+
function enabled(name) {
|
1289
|
+
if (name[name.length - 1] === '*') {
|
1290
|
+
return true;
|
1291
|
+
}
|
1292
|
+
|
1293
|
+
let i;
|
1294
|
+
let len;
|
1295
|
+
|
1296
|
+
for (i = 0, len = createDebug.skips.length; i < len; i++) {
|
1297
|
+
if (createDebug.skips[i].test(name)) {
|
1298
|
+
return false;
|
1299
|
+
}
|
1300
|
+
}
|
1301
|
+
|
1302
|
+
for (i = 0, len = createDebug.names.length; i < len; i++) {
|
1303
|
+
if (createDebug.names[i].test(name)) {
|
1304
|
+
return true;
|
1305
|
+
}
|
1306
|
+
}
|
1307
|
+
|
1308
|
+
return false;
|
1309
|
+
}
|
1310
|
+
|
1311
|
+
/**
|
1312
|
+
* Convert regexp to namespace
|
1313
|
+
*
|
1314
|
+
* @param {RegExp} regxep
|
1315
|
+
* @return {String} namespace
|
1316
|
+
* @api private
|
1317
|
+
*/
|
1318
|
+
function toNamespace(regexp) {
|
1319
|
+
return regexp.toString()
|
1320
|
+
.substring(2, regexp.toString().length - 2)
|
1321
|
+
.replace(/\.\*\?$/, '*');
|
1322
|
+
}
|
1323
|
+
|
1324
|
+
/**
|
1325
|
+
* Coerce `val`.
|
1326
|
+
*
|
1327
|
+
* @param {Mixed} val
|
1328
|
+
* @return {Mixed}
|
1329
|
+
* @api private
|
1330
|
+
*/
|
1331
|
+
function coerce(val) {
|
1332
|
+
if (val instanceof Error) {
|
1333
|
+
return val.stack || val.message;
|
1334
|
+
}
|
1335
|
+
return val;
|
1336
|
+
}
|
1337
|
+
|
1338
|
+
/**
|
1339
|
+
* XXX DO NOT USE. This is a temporary stub function.
|
1340
|
+
* XXX It WILL be removed in the next major release.
|
1341
|
+
*/
|
1342
|
+
function destroy() {
|
1343
|
+
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
1344
|
+
}
|
1345
|
+
|
1346
|
+
createDebug.enable(createDebug.load());
|
1347
|
+
|
1348
|
+
return createDebug;
|
1256
1349
|
}
|
1257
1350
|
|
1258
|
-
|
1351
|
+
var common = setup;
|
1352
|
+
|
1353
|
+
/* eslint-env browser */
|
1354
|
+
|
1355
|
+
(function (module, exports) {
|
1356
|
+
/**
|
1357
|
+
* This is the web browser implementation of `debug()`.
|
1358
|
+
*/
|
1359
|
+
|
1360
|
+
exports.formatArgs = formatArgs;
|
1361
|
+
exports.save = save;
|
1362
|
+
exports.load = load;
|
1363
|
+
exports.useColors = useColors;
|
1364
|
+
exports.storage = localstorage();
|
1365
|
+
exports.destroy = (() => {
|
1366
|
+
let warned = false;
|
1367
|
+
|
1368
|
+
return () => {
|
1369
|
+
if (!warned) {
|
1370
|
+
warned = true;
|
1371
|
+
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
1372
|
+
}
|
1373
|
+
};
|
1374
|
+
})();
|
1375
|
+
|
1376
|
+
/**
|
1377
|
+
* Colors.
|
1378
|
+
*/
|
1379
|
+
|
1380
|
+
exports.colors = [
|
1381
|
+
'#0000CC',
|
1382
|
+
'#0000FF',
|
1383
|
+
'#0033CC',
|
1384
|
+
'#0033FF',
|
1385
|
+
'#0066CC',
|
1386
|
+
'#0066FF',
|
1387
|
+
'#0099CC',
|
1388
|
+
'#0099FF',
|
1389
|
+
'#00CC00',
|
1390
|
+
'#00CC33',
|
1391
|
+
'#00CC66',
|
1392
|
+
'#00CC99',
|
1393
|
+
'#00CCCC',
|
1394
|
+
'#00CCFF',
|
1395
|
+
'#3300CC',
|
1396
|
+
'#3300FF',
|
1397
|
+
'#3333CC',
|
1398
|
+
'#3333FF',
|
1399
|
+
'#3366CC',
|
1400
|
+
'#3366FF',
|
1401
|
+
'#3399CC',
|
1402
|
+
'#3399FF',
|
1403
|
+
'#33CC00',
|
1404
|
+
'#33CC33',
|
1405
|
+
'#33CC66',
|
1406
|
+
'#33CC99',
|
1407
|
+
'#33CCCC',
|
1408
|
+
'#33CCFF',
|
1409
|
+
'#6600CC',
|
1410
|
+
'#6600FF',
|
1411
|
+
'#6633CC',
|
1412
|
+
'#6633FF',
|
1413
|
+
'#66CC00',
|
1414
|
+
'#66CC33',
|
1415
|
+
'#9900CC',
|
1416
|
+
'#9900FF',
|
1417
|
+
'#9933CC',
|
1418
|
+
'#9933FF',
|
1419
|
+
'#99CC00',
|
1420
|
+
'#99CC33',
|
1421
|
+
'#CC0000',
|
1422
|
+
'#CC0033',
|
1423
|
+
'#CC0066',
|
1424
|
+
'#CC0099',
|
1425
|
+
'#CC00CC',
|
1426
|
+
'#CC00FF',
|
1427
|
+
'#CC3300',
|
1428
|
+
'#CC3333',
|
1429
|
+
'#CC3366',
|
1430
|
+
'#CC3399',
|
1431
|
+
'#CC33CC',
|
1432
|
+
'#CC33FF',
|
1433
|
+
'#CC6600',
|
1434
|
+
'#CC6633',
|
1435
|
+
'#CC9900',
|
1436
|
+
'#CC9933',
|
1437
|
+
'#CCCC00',
|
1438
|
+
'#CCCC33',
|
1439
|
+
'#FF0000',
|
1440
|
+
'#FF0033',
|
1441
|
+
'#FF0066',
|
1442
|
+
'#FF0099',
|
1443
|
+
'#FF00CC',
|
1444
|
+
'#FF00FF',
|
1445
|
+
'#FF3300',
|
1446
|
+
'#FF3333',
|
1447
|
+
'#FF3366',
|
1448
|
+
'#FF3399',
|
1449
|
+
'#FF33CC',
|
1450
|
+
'#FF33FF',
|
1451
|
+
'#FF6600',
|
1452
|
+
'#FF6633',
|
1453
|
+
'#FF9900',
|
1454
|
+
'#FF9933',
|
1455
|
+
'#FFCC00',
|
1456
|
+
'#FFCC33'
|
1457
|
+
];
|
1458
|
+
|
1459
|
+
/**
|
1460
|
+
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
1461
|
+
* and the Firebug extension (any Firefox version) are known
|
1462
|
+
* to support "%c" CSS customizations.
|
1463
|
+
*
|
1464
|
+
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
1465
|
+
*/
|
1466
|
+
|
1467
|
+
// eslint-disable-next-line complexity
|
1468
|
+
function useColors() {
|
1469
|
+
// NB: In an Electron preload script, document will be defined but not fully
|
1470
|
+
// initialized. Since we know we're in Chrome, we'll just detect this case
|
1471
|
+
// explicitly
|
1472
|
+
if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
|
1473
|
+
return true;
|
1474
|
+
}
|
1475
|
+
|
1476
|
+
// Internet Explorer and Edge do not support colors.
|
1477
|
+
if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
1478
|
+
return false;
|
1479
|
+
}
|
1480
|
+
|
1481
|
+
// Is webkit? http://stackoverflow.com/a/16459606/376773
|
1482
|
+
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
1483
|
+
return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
|
1484
|
+
// Is firebug? http://stackoverflow.com/a/398120/376773
|
1485
|
+
(typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
|
1486
|
+
// Is firefox >= v31?
|
1487
|
+
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
1488
|
+
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
|
1489
|
+
// Double check webkit in userAgent just in case we are in a worker
|
1490
|
+
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
|
1491
|
+
}
|
1492
|
+
|
1493
|
+
/**
|
1494
|
+
* Colorize log arguments if enabled.
|
1495
|
+
*
|
1496
|
+
* @api public
|
1497
|
+
*/
|
1498
|
+
|
1499
|
+
function formatArgs(args) {
|
1500
|
+
args[0] = (this.useColors ? '%c' : '') +
|
1501
|
+
this.namespace +
|
1502
|
+
(this.useColors ? ' %c' : ' ') +
|
1503
|
+
args[0] +
|
1504
|
+
(this.useColors ? '%c ' : ' ') +
|
1505
|
+
'+' + module.exports.humanize(this.diff);
|
1506
|
+
|
1507
|
+
if (!this.useColors) {
|
1508
|
+
return;
|
1509
|
+
}
|
1510
|
+
|
1511
|
+
const c = 'color: ' + this.color;
|
1512
|
+
args.splice(1, 0, c, 'color: inherit');
|
1513
|
+
|
1514
|
+
// The final "%c" is somewhat tricky, because there could be other
|
1515
|
+
// arguments passed either before or after the %c, so we need to
|
1516
|
+
// figure out the correct index to insert the CSS into
|
1517
|
+
let index = 0;
|
1518
|
+
let lastC = 0;
|
1519
|
+
args[0].replace(/%[a-zA-Z%]/g, match => {
|
1520
|
+
if (match === '%%') {
|
1521
|
+
return;
|
1522
|
+
}
|
1523
|
+
index++;
|
1524
|
+
if (match === '%c') {
|
1525
|
+
// We only are interested in the *last* %c
|
1526
|
+
// (the user may have provided their own)
|
1527
|
+
lastC = index;
|
1528
|
+
}
|
1529
|
+
});
|
1530
|
+
|
1531
|
+
args.splice(lastC, 0, c);
|
1532
|
+
}
|
1533
|
+
|
1534
|
+
/**
|
1535
|
+
* Invokes `console.debug()` when available.
|
1536
|
+
* No-op when `console.debug` is not a "function".
|
1537
|
+
* If `console.debug` is not available, falls back
|
1538
|
+
* to `console.log`.
|
1539
|
+
*
|
1540
|
+
* @api public
|
1541
|
+
*/
|
1542
|
+
exports.log = console.debug || console.log || (() => {});
|
1543
|
+
|
1544
|
+
/**
|
1545
|
+
* Save `namespaces`.
|
1546
|
+
*
|
1547
|
+
* @param {String} namespaces
|
1548
|
+
* @api private
|
1549
|
+
*/
|
1550
|
+
function save(namespaces) {
|
1551
|
+
try {
|
1552
|
+
if (namespaces) {
|
1553
|
+
exports.storage.setItem('debug', namespaces);
|
1554
|
+
} else {
|
1555
|
+
exports.storage.removeItem('debug');
|
1556
|
+
}
|
1557
|
+
} catch (error) {
|
1558
|
+
// Swallow
|
1559
|
+
// XXX (@Qix-) should we be logging these?
|
1560
|
+
}
|
1561
|
+
}
|
1562
|
+
|
1563
|
+
/**
|
1564
|
+
* Load `namespaces`.
|
1565
|
+
*
|
1566
|
+
* @return {String} returns the previously persisted debug modes
|
1567
|
+
* @api private
|
1568
|
+
*/
|
1569
|
+
function load() {
|
1570
|
+
let r;
|
1571
|
+
try {
|
1572
|
+
r = exports.storage.getItem('debug');
|
1573
|
+
} catch (error) {
|
1574
|
+
// Swallow
|
1575
|
+
// XXX (@Qix-) should we be logging these?
|
1576
|
+
}
|
1577
|
+
|
1578
|
+
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
1579
|
+
if (!r && typeof process !== 'undefined' && 'env' in process) {
|
1580
|
+
r = process.env.DEBUG;
|
1581
|
+
}
|
1582
|
+
|
1583
|
+
return r;
|
1584
|
+
}
|
1585
|
+
|
1586
|
+
/**
|
1587
|
+
* Localstorage attempts to return the localstorage.
|
1588
|
+
*
|
1589
|
+
* This is necessary because safari throws
|
1590
|
+
* when a user disables cookies/localstorage
|
1591
|
+
* and you attempt to access it.
|
1592
|
+
*
|
1593
|
+
* @return {LocalStorage}
|
1594
|
+
* @api private
|
1595
|
+
*/
|
1596
|
+
|
1597
|
+
function localstorage() {
|
1598
|
+
try {
|
1599
|
+
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
|
1600
|
+
// The Browser also has localStorage in the global context.
|
1601
|
+
return localStorage;
|
1602
|
+
} catch (error) {
|
1603
|
+
// Swallow
|
1604
|
+
// XXX (@Qix-) should we be logging these?
|
1605
|
+
}
|
1606
|
+
}
|
1607
|
+
|
1608
|
+
module.exports = common(exports);
|
1609
|
+
|
1610
|
+
const {formatters} = module.exports;
|
1611
|
+
|
1612
|
+
/**
|
1613
|
+
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
1614
|
+
*/
|
1615
|
+
|
1616
|
+
formatters.j = function (v) {
|
1617
|
+
try {
|
1618
|
+
return JSON.stringify(v);
|
1619
|
+
} catch (error) {
|
1620
|
+
return '[UnexpectedJSONParseError]: ' + error.message;
|
1621
|
+
}
|
1622
|
+
};
|
1623
|
+
} (browser, browser.exports));
|
1624
|
+
|
1625
|
+
var browserExports = browser.exports;
|
1626
|
+
var debug = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
|
1627
|
+
|
1628
|
+
export { EConnectionStateEvents as E, Protocols as P, SendError as S, Tags as T, base58btc as a, base32 as b, coerce as c, commonjsGlobal as d, equals as e, EPeersByDiscoveryEvents as f, getAugmentedNamespace as g, getDefaultExportFromCjs as h, identityBase as i, base2$1 as j, base8$1 as k, base10$1 as l, base16$1 as m, base32$1 as n, base36$1 as o, base58 as p, base64$1 as q, base256emoji$1 as r, debug as s };
|