@metamask/utils 8.4.0 → 8.5.0
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 +14 -1
- package/dist/assert.cjs +127 -0
- package/dist/assert.cjs.map +1 -0
- package/dist/{types/assert.d.ts → assert.d.cts} +3 -3
- package/dist/assert.d.cts.map +1 -0
- package/dist/assert.d.mts +61 -0
- package/dist/assert.d.mts.map +1 -0
- package/dist/assert.mjs +119 -15
- package/dist/assert.mjs.map +1 -1
- package/dist/base64.cjs +34 -0
- package/dist/base64.cjs.map +1 -0
- package/dist/{types/base64.d.ts → base64.d.cts} +3 -3
- package/dist/base64.d.cts.map +1 -0
- package/dist/base64.d.mts +25 -0
- package/dist/base64.d.mts.map +1 -0
- package/dist/base64.mjs +28 -9
- package/dist/base64.mjs.map +1 -1
- package/dist/bytes.cjs +400 -0
- package/dist/{chunk-QEPVHEP7.js.map → bytes.cjs.map} +1 -1
- package/dist/{types/bytes.d.ts → bytes.d.cts} +3 -3
- package/dist/bytes.d.cts.map +1 -0
- package/dist/bytes.d.mts +183 -0
- package/dist/bytes.d.mts.map +1 -0
- package/dist/bytes.mjs +379 -42
- package/dist/bytes.mjs.map +1 -1
- package/dist/caip-types.cjs +151 -0
- package/dist/caip-types.cjs.map +1 -0
- package/dist/{types/caip-types.d.ts → caip-types.d.cts} +12 -12
- package/dist/caip-types.d.cts.map +1 -0
- package/dist/caip-types.d.mts +114 -0
- package/dist/caip-types.d.mts.map +1 -0
- package/dist/caip-types.mjs +139 -43
- package/dist/caip-types.mjs.map +1 -1
- package/dist/checksum.cjs +7 -0
- package/dist/checksum.cjs.map +1 -0
- package/dist/checksum.d.cts +2 -0
- package/dist/checksum.d.cts.map +1 -0
- package/dist/checksum.d.mts +2 -0
- package/dist/checksum.d.mts.map +1 -0
- package/dist/checksum.mjs +3 -11
- package/dist/checksum.mjs.map +1 -1
- package/dist/coercers.cjs +162 -0
- package/dist/coercers.cjs.map +1 -0
- package/dist/{types/coercers.d.ts → coercers.d.cts} +7 -7
- package/dist/coercers.d.cts.map +1 -0
- package/dist/coercers.d.mts +97 -0
- package/dist/coercers.d.mts.map +1 -0
- package/dist/coercers.mjs +154 -17
- package/dist/coercers.mjs.map +1 -1
- package/dist/collections.cjs +109 -0
- package/dist/collections.cjs.map +1 -0
- package/dist/{types/collections.d.ts → collections.d.cts} +1 -1
- package/dist/collections.d.cts.map +1 -0
- package/dist/collections.d.mts +39 -0
- package/dist/collections.d.mts.map +1 -0
- package/dist/collections.mjs +103 -8
- package/dist/collections.mjs.map +1 -1
- package/dist/encryption-types.cjs +3 -0
- package/dist/encryption-types.cjs.map +1 -0
- package/dist/{types/encryption-types.d.ts → encryption-types.d.cts} +2 -2
- package/dist/encryption-types.d.cts.map +1 -0
- package/dist/encryption-types.d.mts +7 -0
- package/dist/encryption-types.d.mts.map +1 -0
- package/dist/encryption-types.mjs +1 -1
- package/dist/encryption-types.mjs.map +1 -1
- package/dist/errors.cjs +111 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/{types/errors.d.ts → errors.d.cts} +1 -1
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.mts +58 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +102 -16
- package/dist/errors.mjs.map +1 -1
- package/dist/fs.cjs +248 -0
- package/dist/fs.cjs.map +1 -0
- package/dist/{types/fs.d.ts → fs.d.cts} +3 -3
- package/dist/fs.d.cts.map +1 -0
- package/dist/fs.d.mts +133 -0
- package/dist/fs.d.mts.map +1 -0
- package/dist/fs.mjs +209 -25
- package/dist/fs.mjs.map +1 -1
- package/dist/hex.cjs +134 -0
- package/dist/hex.cjs.map +1 -0
- package/dist/{types/hex.d.ts → hex.d.cts} +3 -3
- package/dist/hex.d.cts.map +1 -0
- package/dist/hex.d.mts +77 -0
- package/dist/hex.d.mts.map +1 -0
- package/dist/hex.mjs +121 -34
- package/dist/hex.mjs.map +1 -1
- package/dist/index.cjs +37 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +21 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +21 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +20 -296
- package/dist/index.mjs.map +1 -1
- package/dist/json.cjs +413 -0
- package/dist/json.cjs.map +1 -0
- package/dist/{types/json.d.ts → json.d.cts} +21 -22
- package/dist/json.d.cts.map +1 -0
- package/dist/json.d.mts +383 -0
- package/dist/json.d.mts.map +1 -0
- package/dist/json.mjs +389 -74
- package/dist/json.mjs.map +1 -1
- package/dist/keyring.cjs +3 -0
- package/dist/keyring.cjs.map +1 -0
- package/dist/{types/keyring.d.ts → keyring.d.cts} +7 -7
- package/dist/keyring.d.cts.map +1 -0
- package/dist/keyring.d.mts +224 -0
- package/dist/keyring.d.mts.map +1 -0
- package/dist/keyring.mjs +1 -1
- package/dist/keyring.mjs.map +1 -1
- package/dist/logging.cjs +43 -0
- package/dist/logging.cjs.map +1 -0
- package/dist/{types/logging.d.ts → logging.d.cts} +2 -2
- package/dist/logging.d.cts.map +1 -0
- package/dist/logging.d.mts +30 -0
- package/dist/logging.d.mts.map +1 -0
- package/dist/logging.mjs +34 -9
- package/dist/logging.mjs.map +1 -1
- package/dist/misc.cjs +149 -0
- package/dist/misc.cjs.map +1 -0
- package/dist/{types/misc.d.ts → misc.d.cts} +6 -6
- package/dist/misc.d.cts.map +1 -0
- package/dist/misc.d.mts +119 -0
- package/dist/misc.d.mts.map +1 -0
- package/dist/misc.mjs +136 -27
- package/dist/misc.mjs.map +1 -1
- package/dist/node.cjs +19 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.d.cts +3 -0
- package/dist/node.d.cts.map +1 -0
- package/dist/node.d.mts +3 -0
- package/dist/node.d.mts.map +1 -0
- package/dist/node.mjs +2 -316
- package/dist/node.mjs.map +1 -1
- package/dist/number.cjs +102 -0
- package/dist/number.cjs.map +1 -0
- package/dist/{types/number.d.ts → number.d.cts} +1 -1
- package/dist/number.d.cts.map +1 -0
- package/dist/number.d.mts +73 -0
- package/dist/number.d.mts.map +1 -0
- package/dist/number.mjs +93 -16
- package/dist/number.mjs.map +1 -1
- package/dist/opaque.cjs +3 -0
- package/dist/opaque.cjs.map +1 -0
- package/dist/opaque.d.cts +6 -0
- package/dist/opaque.d.cts.map +1 -0
- package/dist/opaque.d.mts +6 -0
- package/dist/opaque.d.mts.map +1 -0
- package/dist/opaque.mjs +1 -1
- package/dist/opaque.mjs.map +1 -1
- package/dist/promise.cjs +40 -0
- package/dist/promise.cjs.map +1 -0
- package/dist/{types/promise.d.ts → promise.d.cts} +2 -2
- package/dist/promise.d.cts.map +1 -0
- package/dist/promise.d.mts +45 -0
- package/dist/promise.d.mts.map +1 -0
- package/dist/promise.mjs +35 -7
- package/dist/promise.mjs.map +1 -1
- package/dist/time.cjs +67 -0
- package/dist/time.cjs.map +1 -0
- package/dist/{types/time.d.ts → time.d.cts} +1 -1
- package/dist/time.d.cts.map +1 -0
- package/dist/time.d.mts +49 -0
- package/dist/time.d.mts.map +1 -0
- package/dist/time.mjs +60 -10
- package/dist/time.mjs.map +1 -1
- package/dist/transaction-types.cjs +3 -0
- package/dist/transaction-types.cjs.map +1 -0
- package/dist/{types/transaction-types.d.ts → transaction-types.d.cts} +11 -11
- package/dist/transaction-types.d.cts.map +1 -0
- package/dist/transaction-types.d.mts +117 -0
- package/dist/transaction-types.d.mts.map +1 -0
- package/dist/transaction-types.mjs +1 -1
- package/dist/transaction-types.mjs.map +1 -1
- package/dist/versions.cjs +95 -0
- package/dist/versions.cjs.map +1 -0
- package/dist/{types/versions.d.ts → versions.d.cts} +5 -5
- package/dist/versions.d.cts.map +1 -0
- package/dist/versions.d.mts +101 -0
- package/dist/versions.d.mts.map +1 -0
- package/dist/versions.mjs +85 -26
- package/dist/versions.mjs.map +1 -1
- package/package.json +26 -17
- package/dist/assert.js +0 -16
- package/dist/assert.js.map +0 -1
- package/dist/base64.js +0 -11
- package/dist/base64.js.map +0 -1
- package/dist/bytes.js +0 -43
- package/dist/bytes.js.map +0 -1
- package/dist/caip-types.js +0 -44
- package/dist/caip-types.js.map +0 -1
- package/dist/checksum.js +0 -12
- package/dist/checksum.js.map +0 -1
- package/dist/chunk-2LBGT4GH.js +0 -15
- package/dist/chunk-2LBGT4GH.js.map +0 -1
- package/dist/chunk-3W5G4CYI.js +0 -25
- package/dist/chunk-3W5G4CYI.js.map +0 -1
- package/dist/chunk-4D6XQBHA.js +0 -69
- package/dist/chunk-4D6XQBHA.js.map +0 -1
- package/dist/chunk-4RMX5YWE.js +0 -34
- package/dist/chunk-4RMX5YWE.js.map +0 -1
- package/dist/chunk-5AVWINSB.js +0 -1
- package/dist/chunk-5AVWINSB.js.map +0 -1
- package/dist/chunk-622IOGVI.mjs +0 -1
- package/dist/chunk-622IOGVI.mjs.map +0 -1
- package/dist/chunk-6C35XQOF.mjs +0 -257
- package/dist/chunk-6C35XQOF.mjs.map +0 -1
- package/dist/chunk-6NZW4WK4.js +0 -35
- package/dist/chunk-6NZW4WK4.js.map +0 -1
- package/dist/chunk-6ZDHSOUV.js +0 -59
- package/dist/chunk-6ZDHSOUV.js.map +0 -1
- package/dist/chunk-74DGVJVE.mjs +0 -59
- package/dist/chunk-74DGVJVE.mjs.map +0 -1
- package/dist/chunk-AY6FDCBT.mjs +0 -1
- package/dist/chunk-AY6FDCBT.mjs.map +0 -1
- package/dist/chunk-C6HGFEYL.js +0 -23
- package/dist/chunk-C6HGFEYL.js.map +0 -1
- package/dist/chunk-DHVKFDHQ.js +0 -95
- package/dist/chunk-DHVKFDHQ.js.map +0 -1
- package/dist/chunk-DYRKZQMK.mjs +0 -122
- package/dist/chunk-DYRKZQMK.mjs.map +0 -1
- package/dist/chunk-E4C7EW4R.js +0 -16
- package/dist/chunk-E4C7EW4R.js.map +0 -1
- package/dist/chunk-EQMZL4XU.js +0 -1
- package/dist/chunk-EQMZL4XU.js.map +0 -1
- package/dist/chunk-GZS3IQBZ.mjs +0 -16
- package/dist/chunk-GZS3IQBZ.mjs.map +0 -1
- package/dist/chunk-H4YFDLB7.mjs +0 -70
- package/dist/chunk-H4YFDLB7.mjs.map +0 -1
- package/dist/chunk-I575FZFH.mjs +0 -1
- package/dist/chunk-I575FZFH.mjs.map +0 -1
- package/dist/chunk-IZC266HS.js +0 -55
- package/dist/chunk-IZC266HS.js.map +0 -1
- package/dist/chunk-JPAL7Q5S.mjs +0 -90
- package/dist/chunk-JPAL7Q5S.mjs.map +0 -1
- package/dist/chunk-LC2CRSWD.js +0 -1
- package/dist/chunk-LC2CRSWD.js.map +0 -1
- package/dist/chunk-NQMRFZHB.mjs +0 -35
- package/dist/chunk-NQMRFZHB.mjs.map +0 -1
- package/dist/chunk-O3EIM33O.mjs +0 -95
- package/dist/chunk-O3EIM33O.mjs.map +0 -1
- package/dist/chunk-OLLG4H35.js +0 -257
- package/dist/chunk-OLLG4H35.js.map +0 -1
- package/dist/chunk-OUZ3LSLX.mjs +0 -94
- package/dist/chunk-OUZ3LSLX.mjs.map +0 -1
- package/dist/chunk-QEPVHEP7.js +0 -273
- package/dist/chunk-QVEKZRZ2.js +0 -70
- package/dist/chunk-QVEKZRZ2.js.map +0 -1
- package/dist/chunk-RIRDOQPX.mjs +0 -15
- package/dist/chunk-RIRDOQPX.mjs.map +0 -1
- package/dist/chunk-RKRGAFXY.js +0 -1
- package/dist/chunk-RKRGAFXY.js.map +0 -1
- package/dist/chunk-RNEXSCNP.js +0 -122
- package/dist/chunk-RNEXSCNP.js.map +0 -1
- package/dist/chunk-ROQSKDP5.mjs +0 -69
- package/dist/chunk-ROQSKDP5.mjs.map +0 -1
- package/dist/chunk-RRYOWRCV.mjs +0 -1
- package/dist/chunk-RRYOWRCV.mjs.map +0 -1
- package/dist/chunk-S3UHBN2Z.mjs +0 -44
- package/dist/chunk-S3UHBN2Z.mjs.map +0 -1
- package/dist/chunk-THNLGEXV.mjs +0 -34
- package/dist/chunk-THNLGEXV.mjs.map +0 -1
- package/dist/chunk-UOTVU7OQ.js +0 -1
- package/dist/chunk-UOTVU7OQ.js.map +0 -1
- package/dist/chunk-VA2DRBDE.mjs +0 -273
- package/dist/chunk-VA2DRBDE.mjs.map +0 -1
- package/dist/chunk-VFXTVNXN.js +0 -44
- package/dist/chunk-VFXTVNXN.js.map +0 -1
- package/dist/chunk-W5XI7ERF.mjs +0 -23
- package/dist/chunk-W5XI7ERF.mjs.map +0 -1
- package/dist/chunk-WA4DHIND.mjs +0 -1
- package/dist/chunk-WA4DHIND.mjs.map +0 -1
- package/dist/chunk-X66SUIEF.mjs +0 -25
- package/dist/chunk-X66SUIEF.mjs.map +0 -1
- package/dist/chunk-XYGUOY6N.mjs +0 -55
- package/dist/chunk-XYGUOY6N.mjs.map +0 -1
- package/dist/chunk-YWAID473.js +0 -94
- package/dist/chunk-YWAID473.js.map +0 -1
- package/dist/chunk-Z2RGWDD7.js +0 -90
- package/dist/chunk-Z2RGWDD7.js.map +0 -1
- package/dist/coercers.js +0 -18
- package/dist/coercers.js.map +0 -1
- package/dist/collections.js +0 -10
- package/dist/collections.js.map +0 -1
- package/dist/encryption-types.js +0 -2
- package/dist/encryption-types.js.map +0 -1
- package/dist/errors.js +0 -17
- package/dist/errors.js.map +0 -1
- package/dist/fs.js +0 -26
- package/dist/fs.js.map +0 -1
- package/dist/hex.js +0 -35
- package/dist/hex.js.map +0 -1
- package/dist/index.js +0 -297
- package/dist/index.js.map +0 -1
- package/dist/json.js +0 -75
- package/dist/json.js.map +0 -1
- package/dist/keyring.js +0 -2
- package/dist/keyring.js.map +0 -1
- package/dist/logging.js +0 -10
- package/dist/logging.js.map +0 -1
- package/dist/misc.js +0 -28
- package/dist/misc.js.map +0 -1
- package/dist/node.js +0 -317
- package/dist/node.js.map +0 -1
- package/dist/number.js +0 -18
- package/dist/number.js.map +0 -1
- package/dist/opaque.js +0 -2
- package/dist/opaque.js.map +0 -1
- package/dist/promise.js +0 -8
- package/dist/promise.js.map +0 -1
- package/dist/time.js +0 -12
- package/dist/time.js.map +0 -1
- package/dist/transaction-types.js +0 -2
- package/dist/transaction-types.js.map +0 -1
- package/dist/types/assert.d.ts.map +0 -1
- package/dist/types/base64.d.ts.map +0 -1
- package/dist/types/bytes.d.ts.map +0 -1
- package/dist/types/caip-types.d.ts.map +0 -1
- package/dist/types/checksum.d.ts +0 -2
- package/dist/types/checksum.d.ts.map +0 -1
- package/dist/types/coercers.d.ts.map +0 -1
- package/dist/types/collections.d.ts.map +0 -1
- package/dist/types/encryption-types.d.ts.map +0 -1
- package/dist/types/errors.d.ts.map +0 -1
- package/dist/types/fs.d.ts.map +0 -1
- package/dist/types/hex.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -21
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/json.d.ts.map +0 -1
- package/dist/types/keyring.d.ts.map +0 -1
- package/dist/types/logging.d.ts.map +0 -1
- package/dist/types/misc.d.ts.map +0 -1
- package/dist/types/node.d.ts +0 -3
- package/dist/types/node.d.ts.map +0 -1
- package/dist/types/number.d.ts.map +0 -1
- package/dist/types/opaque.d.ts +0 -6
- package/dist/types/opaque.d.ts.map +0 -1
- package/dist/types/promise.d.ts.map +0 -1
- package/dist/types/time.d.ts.map +0 -1
- package/dist/types/transaction-types.d.ts.map +0 -1
- package/dist/types/versions.d.ts.map +0 -1
- package/dist/versions.js +0 -27
- package/dist/versions.js.map +0 -1
package/dist/chunk-QEPVHEP7.js
DELETED
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
-
|
|
3
|
-
var _chunk6ZDHSOUVjs = require('./chunk-6ZDHSOUV.js');
|
|
4
|
-
|
|
5
|
-
// src/hex.ts
|
|
6
|
-
var _sha3 = require('@noble/hashes/sha3');
|
|
7
|
-
var _superstruct = require('superstruct');
|
|
8
|
-
|
|
9
|
-
// src/bytes.ts
|
|
10
|
-
var _base = require('@scure/base');
|
|
11
|
-
var HEX_MINIMUM_NUMBER_CHARACTER = 48;
|
|
12
|
-
var HEX_MAXIMUM_NUMBER_CHARACTER = 58;
|
|
13
|
-
var HEX_CHARACTER_OFFSET = 87;
|
|
14
|
-
function getPrecomputedHexValuesBuilder() {
|
|
15
|
-
const lookupTable = [];
|
|
16
|
-
return () => {
|
|
17
|
-
if (lookupTable.length === 0) {
|
|
18
|
-
for (let i = 0; i < 256; i++) {
|
|
19
|
-
lookupTable.push(i.toString(16).padStart(2, "0"));
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return lookupTable;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
var getPrecomputedHexValues = getPrecomputedHexValuesBuilder();
|
|
26
|
-
function isBytes(value) {
|
|
27
|
-
return value instanceof Uint8Array;
|
|
28
|
-
}
|
|
29
|
-
function assertIsBytes(value) {
|
|
30
|
-
_chunk6ZDHSOUVjs.assert.call(void 0, isBytes(value), "Value must be a Uint8Array.");
|
|
31
|
-
}
|
|
32
|
-
function bytesToHex(bytes) {
|
|
33
|
-
assertIsBytes(bytes);
|
|
34
|
-
if (bytes.length === 0) {
|
|
35
|
-
return "0x";
|
|
36
|
-
}
|
|
37
|
-
const lookupTable = getPrecomputedHexValues();
|
|
38
|
-
const hexadecimal = new Array(bytes.length);
|
|
39
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
40
|
-
hexadecimal[i] = lookupTable[bytes[i]];
|
|
41
|
-
}
|
|
42
|
-
return add0x(hexadecimal.join(""));
|
|
43
|
-
}
|
|
44
|
-
function bytesToBigInt(bytes) {
|
|
45
|
-
assertIsBytes(bytes);
|
|
46
|
-
const hexadecimal = bytesToHex(bytes);
|
|
47
|
-
return BigInt(hexadecimal);
|
|
48
|
-
}
|
|
49
|
-
function bytesToSignedBigInt(bytes) {
|
|
50
|
-
assertIsBytes(bytes);
|
|
51
|
-
let value = BigInt(0);
|
|
52
|
-
for (const byte of bytes) {
|
|
53
|
-
value = (value << BigInt(8)) + BigInt(byte);
|
|
54
|
-
}
|
|
55
|
-
return BigInt.asIntN(bytes.length * 8, value);
|
|
56
|
-
}
|
|
57
|
-
function bytesToNumber(bytes) {
|
|
58
|
-
assertIsBytes(bytes);
|
|
59
|
-
const bigint = bytesToBigInt(bytes);
|
|
60
|
-
_chunk6ZDHSOUVjs.assert.call(void 0,
|
|
61
|
-
bigint <= BigInt(Number.MAX_SAFE_INTEGER),
|
|
62
|
-
"Number is not a safe integer. Use `bytesToBigInt` instead."
|
|
63
|
-
);
|
|
64
|
-
return Number(bigint);
|
|
65
|
-
}
|
|
66
|
-
function bytesToString(bytes) {
|
|
67
|
-
assertIsBytes(bytes);
|
|
68
|
-
return new TextDecoder().decode(bytes);
|
|
69
|
-
}
|
|
70
|
-
function bytesToBase64(bytes) {
|
|
71
|
-
assertIsBytes(bytes);
|
|
72
|
-
return _base.base64.encode(bytes);
|
|
73
|
-
}
|
|
74
|
-
function hexToBytes(value) {
|
|
75
|
-
if (_optionalChain([value, 'optionalAccess', _ => _.toLowerCase, 'optionalCall', _2 => _2()]) === "0x") {
|
|
76
|
-
return new Uint8Array();
|
|
77
|
-
}
|
|
78
|
-
assertIsHexString(value);
|
|
79
|
-
const strippedValue = remove0x(value).toLowerCase();
|
|
80
|
-
const normalizedValue = strippedValue.length % 2 === 0 ? strippedValue : `0${strippedValue}`;
|
|
81
|
-
const bytes = new Uint8Array(normalizedValue.length / 2);
|
|
82
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
83
|
-
const c1 = normalizedValue.charCodeAt(i * 2);
|
|
84
|
-
const c2 = normalizedValue.charCodeAt(i * 2 + 1);
|
|
85
|
-
const n1 = c1 - (c1 < HEX_MAXIMUM_NUMBER_CHARACTER ? HEX_MINIMUM_NUMBER_CHARACTER : HEX_CHARACTER_OFFSET);
|
|
86
|
-
const n2 = c2 - (c2 < HEX_MAXIMUM_NUMBER_CHARACTER ? HEX_MINIMUM_NUMBER_CHARACTER : HEX_CHARACTER_OFFSET);
|
|
87
|
-
bytes[i] = n1 * 16 + n2;
|
|
88
|
-
}
|
|
89
|
-
return bytes;
|
|
90
|
-
}
|
|
91
|
-
function bigIntToBytes(value) {
|
|
92
|
-
_chunk6ZDHSOUVjs.assert.call(void 0, typeof value === "bigint", "Value must be a bigint.");
|
|
93
|
-
_chunk6ZDHSOUVjs.assert.call(void 0, value >= BigInt(0), "Value must be a non-negative bigint.");
|
|
94
|
-
const hexadecimal = value.toString(16);
|
|
95
|
-
return hexToBytes(hexadecimal);
|
|
96
|
-
}
|
|
97
|
-
function bigIntFits(value, bytes) {
|
|
98
|
-
_chunk6ZDHSOUVjs.assert.call(void 0, bytes > 0);
|
|
99
|
-
const mask = value >> BigInt(31);
|
|
100
|
-
return !((~value & mask) + (value & ~mask) >> BigInt(bytes * 8 + ~0));
|
|
101
|
-
}
|
|
102
|
-
function signedBigIntToBytes(value, byteLength) {
|
|
103
|
-
_chunk6ZDHSOUVjs.assert.call(void 0, typeof value === "bigint", "Value must be a bigint.");
|
|
104
|
-
_chunk6ZDHSOUVjs.assert.call(void 0, typeof byteLength === "number", "Byte length must be a number.");
|
|
105
|
-
_chunk6ZDHSOUVjs.assert.call(void 0, byteLength > 0, "Byte length must be greater than 0.");
|
|
106
|
-
_chunk6ZDHSOUVjs.assert.call(void 0,
|
|
107
|
-
bigIntFits(value, byteLength),
|
|
108
|
-
"Byte length is too small to represent the given value."
|
|
109
|
-
);
|
|
110
|
-
let numberValue = value;
|
|
111
|
-
const bytes = new Uint8Array(byteLength);
|
|
112
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
113
|
-
bytes[i] = Number(BigInt.asUintN(8, numberValue));
|
|
114
|
-
numberValue >>= BigInt(8);
|
|
115
|
-
}
|
|
116
|
-
return bytes.reverse();
|
|
117
|
-
}
|
|
118
|
-
function numberToBytes(value) {
|
|
119
|
-
_chunk6ZDHSOUVjs.assert.call(void 0, typeof value === "number", "Value must be a number.");
|
|
120
|
-
_chunk6ZDHSOUVjs.assert.call(void 0, value >= 0, "Value must be a non-negative number.");
|
|
121
|
-
_chunk6ZDHSOUVjs.assert.call(void 0,
|
|
122
|
-
Number.isSafeInteger(value),
|
|
123
|
-
"Value is not a safe integer. Use `bigIntToBytes` instead."
|
|
124
|
-
);
|
|
125
|
-
const hexadecimal = value.toString(16);
|
|
126
|
-
return hexToBytes(hexadecimal);
|
|
127
|
-
}
|
|
128
|
-
function stringToBytes(value) {
|
|
129
|
-
_chunk6ZDHSOUVjs.assert.call(void 0, typeof value === "string", "Value must be a string.");
|
|
130
|
-
return new TextEncoder().encode(value);
|
|
131
|
-
}
|
|
132
|
-
function base64ToBytes(value) {
|
|
133
|
-
_chunk6ZDHSOUVjs.assert.call(void 0, typeof value === "string", "Value must be a string.");
|
|
134
|
-
return _base.base64.decode(value);
|
|
135
|
-
}
|
|
136
|
-
function valueToBytes(value) {
|
|
137
|
-
if (typeof value === "bigint") {
|
|
138
|
-
return bigIntToBytes(value);
|
|
139
|
-
}
|
|
140
|
-
if (typeof value === "number") {
|
|
141
|
-
return numberToBytes(value);
|
|
142
|
-
}
|
|
143
|
-
if (typeof value === "string") {
|
|
144
|
-
if (value.startsWith("0x")) {
|
|
145
|
-
return hexToBytes(value);
|
|
146
|
-
}
|
|
147
|
-
return stringToBytes(value);
|
|
148
|
-
}
|
|
149
|
-
if (isBytes(value)) {
|
|
150
|
-
return value;
|
|
151
|
-
}
|
|
152
|
-
throw new TypeError(`Unsupported value type: "${typeof value}".`);
|
|
153
|
-
}
|
|
154
|
-
function concatBytes(values) {
|
|
155
|
-
const normalizedValues = new Array(values.length);
|
|
156
|
-
let byteLength = 0;
|
|
157
|
-
for (let i = 0; i < values.length; i++) {
|
|
158
|
-
const value = valueToBytes(values[i]);
|
|
159
|
-
normalizedValues[i] = value;
|
|
160
|
-
byteLength += value.length;
|
|
161
|
-
}
|
|
162
|
-
const bytes = new Uint8Array(byteLength);
|
|
163
|
-
for (let i = 0, offset = 0; i < normalizedValues.length; i++) {
|
|
164
|
-
bytes.set(normalizedValues[i], offset);
|
|
165
|
-
offset += normalizedValues[i].length;
|
|
166
|
-
}
|
|
167
|
-
return bytes;
|
|
168
|
-
}
|
|
169
|
-
function createDataView(bytes) {
|
|
170
|
-
if (typeof Buffer !== "undefined" && bytes instanceof Buffer) {
|
|
171
|
-
const buffer = bytes.buffer.slice(
|
|
172
|
-
bytes.byteOffset,
|
|
173
|
-
bytes.byteOffset + bytes.byteLength
|
|
174
|
-
);
|
|
175
|
-
return new DataView(buffer);
|
|
176
|
-
}
|
|
177
|
-
return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// src/hex.ts
|
|
181
|
-
var HexStruct = _superstruct.pattern.call(void 0, _superstruct.string.call(void 0, ), /^(?:0x)?[0-9a-f]+$/iu);
|
|
182
|
-
var StrictHexStruct = _superstruct.pattern.call(void 0, _superstruct.string.call(void 0, ), /^0x[0-9a-f]+$/iu);
|
|
183
|
-
var HexAddressStruct = _superstruct.pattern.call(void 0,
|
|
184
|
-
_superstruct.string.call(void 0, ),
|
|
185
|
-
/^0x[0-9a-f]{40}$/u
|
|
186
|
-
);
|
|
187
|
-
var HexChecksumAddressStruct = _superstruct.pattern.call(void 0,
|
|
188
|
-
_superstruct.string.call(void 0, ),
|
|
189
|
-
/^0x[0-9a-fA-F]{40}$/u
|
|
190
|
-
);
|
|
191
|
-
function isHexString(value) {
|
|
192
|
-
return _superstruct.is.call(void 0, value, HexStruct);
|
|
193
|
-
}
|
|
194
|
-
function isStrictHexString(value) {
|
|
195
|
-
return _superstruct.is.call(void 0, value, StrictHexStruct);
|
|
196
|
-
}
|
|
197
|
-
function assertIsHexString(value) {
|
|
198
|
-
_chunk6ZDHSOUVjs.assert.call(void 0, isHexString(value), "Value must be a hexadecimal string.");
|
|
199
|
-
}
|
|
200
|
-
function assertIsStrictHexString(value) {
|
|
201
|
-
_chunk6ZDHSOUVjs.assert.call(void 0,
|
|
202
|
-
isStrictHexString(value),
|
|
203
|
-
'Value must be a hexadecimal string, starting with "0x".'
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
function isValidHexAddress(possibleAddress) {
|
|
207
|
-
return _superstruct.is.call(void 0, possibleAddress, HexAddressStruct) || isValidChecksumAddress(possibleAddress);
|
|
208
|
-
}
|
|
209
|
-
function getChecksumAddress(address) {
|
|
210
|
-
_chunk6ZDHSOUVjs.assert.call(void 0, _superstruct.is.call(void 0, address, HexChecksumAddressStruct), "Invalid hex address.");
|
|
211
|
-
const unPrefixed = remove0x(address.toLowerCase());
|
|
212
|
-
const unPrefixedHash = remove0x(bytesToHex(_sha3.keccak_256.call(void 0, unPrefixed)));
|
|
213
|
-
return `0x${unPrefixed.split("").map((character, nibbleIndex) => {
|
|
214
|
-
const hashCharacter = unPrefixedHash[nibbleIndex];
|
|
215
|
-
_chunk6ZDHSOUVjs.assert.call(void 0, _superstruct.is.call(void 0, hashCharacter, _superstruct.string.call(void 0, )), "Hash shorter than address.");
|
|
216
|
-
return parseInt(hashCharacter, 16) > 7 ? character.toUpperCase() : character;
|
|
217
|
-
}).join("")}`;
|
|
218
|
-
}
|
|
219
|
-
function isValidChecksumAddress(possibleChecksum) {
|
|
220
|
-
if (!_superstruct.is.call(void 0, possibleChecksum, HexChecksumAddressStruct)) {
|
|
221
|
-
return false;
|
|
222
|
-
}
|
|
223
|
-
return getChecksumAddress(possibleChecksum) === possibleChecksum;
|
|
224
|
-
}
|
|
225
|
-
function add0x(hexadecimal) {
|
|
226
|
-
if (hexadecimal.startsWith("0x")) {
|
|
227
|
-
return hexadecimal;
|
|
228
|
-
}
|
|
229
|
-
if (hexadecimal.startsWith("0X")) {
|
|
230
|
-
return `0x${hexadecimal.substring(2)}`;
|
|
231
|
-
}
|
|
232
|
-
return `0x${hexadecimal}`;
|
|
233
|
-
}
|
|
234
|
-
function remove0x(hexadecimal) {
|
|
235
|
-
if (hexadecimal.startsWith("0x") || hexadecimal.startsWith("0X")) {
|
|
236
|
-
return hexadecimal.substring(2);
|
|
237
|
-
}
|
|
238
|
-
return hexadecimal;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
exports.HexStruct = HexStruct; exports.StrictHexStruct = StrictHexStruct; exports.HexAddressStruct = HexAddressStruct; exports.HexChecksumAddressStruct = HexChecksumAddressStruct; exports.isHexString = isHexString; exports.isStrictHexString = isStrictHexString; exports.assertIsHexString = assertIsHexString; exports.assertIsStrictHexString = assertIsStrictHexString; exports.isValidHexAddress = isValidHexAddress; exports.getChecksumAddress = getChecksumAddress; exports.isValidChecksumAddress = isValidChecksumAddress; exports.add0x = add0x; exports.remove0x = remove0x; exports.isBytes = isBytes; exports.assertIsBytes = assertIsBytes; exports.bytesToHex = bytesToHex; exports.bytesToBigInt = bytesToBigInt; exports.bytesToSignedBigInt = bytesToSignedBigInt; exports.bytesToNumber = bytesToNumber; exports.bytesToString = bytesToString; exports.bytesToBase64 = bytesToBase64; exports.hexToBytes = hexToBytes; exports.bigIntToBytes = bigIntToBytes; exports.signedBigIntToBytes = signedBigIntToBytes; exports.numberToBytes = numberToBytes; exports.stringToBytes = stringToBytes; exports.base64ToBytes = base64ToBytes; exports.valueToBytes = valueToBytes; exports.concatBytes = concatBytes; exports.createDataView = createDataView;
|
|
273
|
-
//# sourceMappingURL=chunk-QEPVHEP7.js.map
|
package/dist/chunk-QVEKZRZ2.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/misc.ts
|
|
2
|
-
function isNonEmptyArray(value) {
|
|
3
|
-
return Array.isArray(value) && value.length > 0;
|
|
4
|
-
}
|
|
5
|
-
function isNullOrUndefined(value) {
|
|
6
|
-
return value === null || value === void 0;
|
|
7
|
-
}
|
|
8
|
-
function isObject(value) {
|
|
9
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
10
|
-
}
|
|
11
|
-
var hasProperty = (objectToCheck, name) => Object.hasOwnProperty.call(objectToCheck, name);
|
|
12
|
-
function getKnownPropertyNames(object) {
|
|
13
|
-
return Object.getOwnPropertyNames(object);
|
|
14
|
-
}
|
|
15
|
-
var JsonSize = /* @__PURE__ */ ((JsonSize2) => {
|
|
16
|
-
JsonSize2[JsonSize2["Null"] = 4] = "Null";
|
|
17
|
-
JsonSize2[JsonSize2["Comma"] = 1] = "Comma";
|
|
18
|
-
JsonSize2[JsonSize2["Wrapper"] = 1] = "Wrapper";
|
|
19
|
-
JsonSize2[JsonSize2["True"] = 4] = "True";
|
|
20
|
-
JsonSize2[JsonSize2["False"] = 5] = "False";
|
|
21
|
-
JsonSize2[JsonSize2["Quote"] = 1] = "Quote";
|
|
22
|
-
JsonSize2[JsonSize2["Colon"] = 1] = "Colon";
|
|
23
|
-
JsonSize2[JsonSize2["Date"] = 24] = "Date";
|
|
24
|
-
return JsonSize2;
|
|
25
|
-
})(JsonSize || {});
|
|
26
|
-
var ESCAPE_CHARACTERS_REGEXP = /"|\\|\n|\r|\t/gu;
|
|
27
|
-
function isPlainObject(value) {
|
|
28
|
-
if (typeof value !== "object" || value === null) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
try {
|
|
32
|
-
let proto = value;
|
|
33
|
-
while (Object.getPrototypeOf(proto) !== null) {
|
|
34
|
-
proto = Object.getPrototypeOf(proto);
|
|
35
|
-
}
|
|
36
|
-
return Object.getPrototypeOf(value) === proto;
|
|
37
|
-
} catch (_) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function isASCII(character) {
|
|
42
|
-
return character.charCodeAt(0) <= 127;
|
|
43
|
-
}
|
|
44
|
-
function calculateStringSize(value) {
|
|
45
|
-
const size = value.split("").reduce((total, character) => {
|
|
46
|
-
if (isASCII(character)) {
|
|
47
|
-
return total + 1;
|
|
48
|
-
}
|
|
49
|
-
return total + 2;
|
|
50
|
-
}, 0);
|
|
51
|
-
return size + (_nullishCoalesce(value.match(ESCAPE_CHARACTERS_REGEXP), () => ( []))).length;
|
|
52
|
-
}
|
|
53
|
-
function calculateNumberSize(value) {
|
|
54
|
-
return value.toString().length;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
exports.isNonEmptyArray = isNonEmptyArray; exports.isNullOrUndefined = isNullOrUndefined; exports.isObject = isObject; exports.hasProperty = hasProperty; exports.getKnownPropertyNames = getKnownPropertyNames; exports.JsonSize = JsonSize; exports.ESCAPE_CHARACTERS_REGEXP = ESCAPE_CHARACTERS_REGEXP; exports.isPlainObject = isPlainObject; exports.isASCII = isASCII; exports.calculateStringSize = calculateStringSize; exports.calculateNumberSize = calculateNumberSize;
|
|
70
|
-
//# sourceMappingURL=chunk-QVEKZRZ2.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/misc.ts"],"names":["JsonSize"],"mappings":";AAiDO,SAAS,gBACd,OACiC;AACjC,SAAO,MAAM,QAAQ,KAAK,KAAK,MAAM,SAAS;AAChD;AAQO,SAAS,kBAAkB,OAA2C;AAC3E,SAAO,UAAU,QAAQ,UAAU;AACrC;AASO,SAAS,SAAS,OAAwC;AAC/D,SAAO,QAAQ,KAAK,KAAK,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAcO,IAAM,cAAc,CAKzB,eACA,SAKK,OAAO,eAAe,KAAK,eAAe,IAAI;AAa9C,SAAS,sBACd,QACO;AACP,SAAO,OAAO,oBAAoB,MAAM;AAC1C;AAOO,IAAK,WAAL,kBAAKA,cAAL;AACL,EAAAA,oBAAA,UAAO,KAAP;AACA,EAAAA,oBAAA,WAAQ,KAAR;AACA,EAAAA,oBAAA,aAAU,KAAV;AACA,EAAAA,oBAAA,UAAO,KAAP;AACA,EAAAA,oBAAA,WAAQ,KAAR;AACA,EAAAA,oBAAA,WAAQ,KAAR;AACA,EAAAA,oBAAA,WAAQ,KAAR;AAEA,EAAAA,oBAAA,UAAO,MAAP;AATU,SAAAA;AAAA,GAAA;AAeL,IAAM,2BAA2B;AASjC,SAAS,cAAc,OAAsC;AAClE,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO;AAAA,EACT;AAEA,MAAI;AACF,QAAI,QAAQ;AACZ,WAAO,OAAO,eAAe,KAAK,MAAM,MAAM;AAC5C,cAAQ,OAAO,eAAe,KAAK;AAAA,IACrC;AAEA,WAAO,OAAO,eAAe,KAAK,MAAM;AAAA,EAC1C,SAAS,GAAG;AACV,WAAO;AAAA,EACT;AACF;AAQO,SAAS,QAAQ,WAAmB;AACzC,SAAO,UAAU,WAAW,CAAC,KAAK;AACpC;AAQO,SAAS,oBAAoB,OAAuB;AACzD,QAAM,OAAO,MAAM,MAAM,EAAE,EAAE,OAAO,CAAC,OAAO,cAAc;AACxD,QAAI,QAAQ,SAAS,GAAG;AACtB,aAAO,QAAQ;AAAA,IACjB;AACA,WAAO,QAAQ;AAAA,EACjB,GAAG,CAAC;AAGJ,SAAO,QAAQ,MAAM,MAAM,wBAAwB,KAAK,CAAC,GAAG;AAC9D;AAQO,SAAS,oBAAoB,OAAuB;AACzD,SAAO,MAAM,SAAS,EAAE;AAC1B","sourcesContent":["//\n// Types\n//\n\n/**\n * Makes every specified property of the specified object type mutable.\n *\n * @template ObjectValue - The object whose readonly properties to make mutable.\n * @template TargetKey - The property key(s) to make mutable.\n */\nexport type Mutable<\n ObjectValue extends Record<string, unknown>,\n TargetKey extends keyof ObjectValue,\n> = {\n -readonly [Key in keyof Pick<ObjectValue, TargetKey>]: ObjectValue[Key];\n} & {\n [Key in keyof Omit<ObjectValue, TargetKey>]: ObjectValue[Key];\n};\n\n/**\n * Useful for representing some value that _might_ be present and / or complete.\n *\n * @template Value - The value that might be present or complete.\n */\nexport type PartialOrAbsent<Value> = Partial<Value> | null | undefined;\n\n/**\n * Like {@link Array}, but always non-empty.\n *\n * @template Element - The non-empty array member type.\n */\nexport type NonEmptyArray<Element> = [Element, ...Element[]];\n\n/**\n * A JavaScript object that is not `null`, a function, or an array.\n */\nexport type RuntimeObject = Record<PropertyKey, unknown>;\n\n//\n// Type Guards\n//\n\n/**\n * A {@link NonEmptyArray} type guard.\n *\n * @template Element - The non-empty array member type.\n * @param value - The value to check.\n * @returns Whether the value is a non-empty array.\n */\nexport function isNonEmptyArray<Element>(\n value: Element[],\n): value is NonEmptyArray<Element> {\n return Array.isArray(value) && value.length > 0;\n}\n\n/**\n * Type guard for \"nullishness\".\n *\n * @param value - Any value.\n * @returns `true` if the value is null or undefined, `false` otherwise.\n */\nexport function isNullOrUndefined(value: unknown): value is null | undefined {\n return value === null || value === undefined;\n}\n\n/**\n * A type guard for {@link RuntimeObject}.\n *\n * @param value - The value to check.\n * @returns Whether the specified value has a runtime type of `object` and is\n * neither `null` nor an `Array`.\n */\nexport function isObject(value: unknown): value is RuntimeObject {\n return Boolean(value) && typeof value === 'object' && !Array.isArray(value);\n}\n\n//\n// Other utility functions\n//\n\n/**\n * A type guard for ensuring an object has a property.\n *\n * @param objectToCheck - The object to check.\n * @param name - The property name to check for.\n * @returns Whether the specified object has an own property with the specified\n * name, regardless of whether it is enumerable or not.\n */\nexport const hasProperty = <\n // eslint-disable-next-line @typescript-eslint/ban-types\n ObjectToCheck extends Object,\n Property extends PropertyKey,\n>(\n objectToCheck: ObjectToCheck,\n name: Property,\n): objectToCheck is ObjectToCheck &\n Record<\n Property,\n Property extends keyof ObjectToCheck ? ObjectToCheck[Property] : unknown\n > => Object.hasOwnProperty.call(objectToCheck, name);\n\n/**\n * `Object.getOwnPropertyNames()` is intentionally generic: it returns the\n * immediate property names of an object, but it cannot make guarantees about\n * the contents of that object, so the type of the property names is merely\n * `string[]`. While this is technically accurate, it is also unnecessary if we\n * have an object with a type that we own (such as an enum).\n *\n * @param object - The plain object.\n * @returns The own property names of the object which are assigned a type\n * derived from the object itself.\n */\nexport function getKnownPropertyNames<Key extends PropertyKey>(\n object: Partial<Record<Key, any>>,\n): Key[] {\n return Object.getOwnPropertyNames(object) as Key[];\n}\n\nexport type PlainObject = Record<number | string | symbol, unknown>;\n\n/**\n * Predefined sizes (in Bytes) of specific parts of JSON structure.\n */\nexport enum JsonSize {\n Null = 4,\n Comma = 1,\n Wrapper = 1,\n True = 4,\n False = 5,\n Quote = 1,\n Colon = 1,\n // eslint-disable-next-line @typescript-eslint/no-shadow\n Date = 24,\n}\n\n/**\n * Regular expression with pattern matching for (special) escaped characters.\n */\nexport const ESCAPE_CHARACTERS_REGEXP = /\"|\\\\|\\n|\\r|\\t/gu;\n\n/**\n * Check if the value is plain object.\n *\n * @param value - Value to be checked.\n * @returns True if an object is the plain JavaScript object,\n * false if the object is not plain (e.g. function).\n */\nexport function isPlainObject(value: unknown): value is PlainObject {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n\n try {\n let proto = value;\n while (Object.getPrototypeOf(proto) !== null) {\n proto = Object.getPrototypeOf(proto);\n }\n\n return Object.getPrototypeOf(value) === proto;\n } catch (_) {\n return false;\n }\n}\n\n/**\n * Check if character is ASCII.\n *\n * @param character - Character.\n * @returns True if a character code is ASCII, false if not.\n */\nexport function isASCII(character: string) {\n return character.charCodeAt(0) <= 127;\n}\n\n/**\n * Calculate string size.\n *\n * @param value - String value to calculate size.\n * @returns Number of bytes used to store whole string value.\n */\nexport function calculateStringSize(value: string): number {\n const size = value.split('').reduce((total, character) => {\n if (isASCII(character)) {\n return total + 1;\n }\n return total + 2;\n }, 0);\n\n // Also detect characters that need backslash escape\n return size + (value.match(ESCAPE_CHARACTERS_REGEXP) ?? []).length;\n}\n\n/**\n * Calculate size of a number ofter JSON serialization.\n *\n * @param value - Number value to calculate size.\n * @returns Number of bytes used to store whole number in JSON.\n */\nexport function calculateNumberSize(value: number): number {\n return value.toString().length;\n}\n"]}
|
package/dist/chunk-RIRDOQPX.mjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// src/logging.ts
|
|
2
|
-
import debug from "debug";
|
|
3
|
-
var globalLogger = debug("metamask");
|
|
4
|
-
function createProjectLogger(projectName) {
|
|
5
|
-
return globalLogger.extend(projectName);
|
|
6
|
-
}
|
|
7
|
-
function createModuleLogger(projectLogger, moduleName) {
|
|
8
|
-
return projectLogger.extend(moduleName);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export {
|
|
12
|
-
createProjectLogger,
|
|
13
|
-
createModuleLogger
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=chunk-RIRDOQPX.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/logging.ts"],"sourcesContent":["import type { Debugger } from 'debug';\nimport debug from 'debug';\n\nconst globalLogger = debug('metamask');\n\n/**\n * Creates a logger via the `debug` library whose log messages will be tagged\n * using the name of your project. By default, such messages will be\n * suppressed, but you can reveal them by setting the `DEBUG` environment\n * variable to `metamask:<projectName>`. You can also set this variable to\n * `metamask:*` if you want to see log messages from all MetaMask projects that\n * are also using this function to create their loggers.\n *\n * @param projectName - The name of your project. This should be the name of\n * your NPM package if you're developing one.\n * @returns An instance of `debug`.\n */\nexport function createProjectLogger(projectName: string): Debugger {\n return globalLogger.extend(projectName);\n}\n\n/**\n * Creates a logger via the `debug` library which is derived from the logger for\n * the whole project whose log messages will be tagged using the name of your\n * module. By default, such messages will be suppressed, but you can reveal them\n * by setting the `DEBUG` environment variable to\n * `metamask:<projectName>:<moduleName>`. You can also set this variable to\n * `metamask:<projectName>:*` if you want to see log messages from the project,\n * or `metamask:*` if you want to see log messages from all MetaMask projects.\n *\n * @param projectLogger - The logger created via {@link createProjectLogger}.\n * @param moduleName - The name of your module. You could use the name of the\n * file where you're using this logger or some other name.\n * @returns An instance of `debug`.\n */\nexport function createModuleLogger(\n projectLogger: Debugger,\n moduleName: string,\n): Debugger {\n return projectLogger.extend(moduleName);\n}\n"],"mappings":";AACA,OAAO,WAAW;AAElB,IAAM,eAAe,MAAM,UAAU;AAc9B,SAAS,oBAAoB,aAA+B;AACjE,SAAO,aAAa,OAAO,WAAW;AACxC;AAgBO,SAAS,mBACd,eACA,YACU;AACV,SAAO,cAAc,OAAO,UAAU;AACxC;","names":[]}
|
package/dist/chunk-RKRGAFXY.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";//# sourceMappingURL=chunk-RKRGAFXY.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/dist/chunk-RNEXSCNP.js
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var _chunkIZC266HSjs = require('./chunk-IZC266HS.js');
|
|
5
|
-
|
|
6
|
-
// src/fs.ts
|
|
7
|
-
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
8
|
-
var _os = require('os'); var _os2 = _interopRequireDefault(_os);
|
|
9
|
-
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
10
|
-
var _uuid = require('uuid'); var uuid = _interopRequireWildcard(_uuid);
|
|
11
|
-
async function readFile(filePath) {
|
|
12
|
-
try {
|
|
13
|
-
return await _fs2.default.promises.readFile(filePath, "utf8");
|
|
14
|
-
} catch (error) {
|
|
15
|
-
throw _chunkIZC266HSjs.wrapError.call(void 0, error, `Could not read file '${filePath}'`);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
async function writeFile(filePath, content) {
|
|
19
|
-
try {
|
|
20
|
-
await _fs2.default.promises.mkdir(_path2.default.dirname(filePath), { recursive: true });
|
|
21
|
-
await _fs2.default.promises.writeFile(filePath, content);
|
|
22
|
-
} catch (error) {
|
|
23
|
-
throw _chunkIZC266HSjs.wrapError.call(void 0, error, `Could not write file '${filePath}'`);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
async function readJsonFile(filePath, {
|
|
27
|
-
parser = JSON
|
|
28
|
-
} = {}) {
|
|
29
|
-
try {
|
|
30
|
-
const content = await _fs2.default.promises.readFile(filePath, "utf8");
|
|
31
|
-
return parser.parse(content);
|
|
32
|
-
} catch (error) {
|
|
33
|
-
throw _chunkIZC266HSjs.wrapError.call(void 0, error, `Could not read JSON file '${filePath}'`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
async function writeJsonFile(filePath, jsonValue, {
|
|
37
|
-
stringifier = JSON,
|
|
38
|
-
prettify = false
|
|
39
|
-
} = {}) {
|
|
40
|
-
try {
|
|
41
|
-
await _fs2.default.promises.mkdir(_path2.default.dirname(filePath), { recursive: true });
|
|
42
|
-
const json = prettify ? stringifier.stringify(jsonValue, null, " ") : stringifier.stringify(jsonValue);
|
|
43
|
-
await _fs2.default.promises.writeFile(filePath, json);
|
|
44
|
-
} catch (error) {
|
|
45
|
-
throw _chunkIZC266HSjs.wrapError.call(void 0, error, `Could not write JSON file '${filePath}'`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
async function fileExists(filePath) {
|
|
49
|
-
try {
|
|
50
|
-
const stats = await _fs2.default.promises.stat(filePath);
|
|
51
|
-
return stats.isFile();
|
|
52
|
-
} catch (error) {
|
|
53
|
-
if (_chunkIZC266HSjs.isErrorWithCode.call(void 0, error) && error.code === "ENOENT") {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
throw _chunkIZC266HSjs.wrapError.call(void 0, error, `Could not determine if file exists '${filePath}'`);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
async function directoryExists(directoryPath) {
|
|
60
|
-
try {
|
|
61
|
-
const stats = await _fs2.default.promises.stat(directoryPath);
|
|
62
|
-
return stats.isDirectory();
|
|
63
|
-
} catch (error) {
|
|
64
|
-
if (_chunkIZC266HSjs.isErrorWithCode.call(void 0, error) && error.code === "ENOENT") {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
throw _chunkIZC266HSjs.wrapError.call(void 0,
|
|
68
|
-
error,
|
|
69
|
-
`Could not determine if directory exists '${directoryPath}'`
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
async function ensureDirectoryStructureExists(directoryPath) {
|
|
74
|
-
try {
|
|
75
|
-
await _fs2.default.promises.mkdir(directoryPath, { recursive: true });
|
|
76
|
-
} catch (error) {
|
|
77
|
-
throw _chunkIZC266HSjs.wrapError.call(void 0,
|
|
78
|
-
error,
|
|
79
|
-
`Could not create directory structure '${directoryPath}'`
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
async function forceRemove(entryPath) {
|
|
84
|
-
try {
|
|
85
|
-
return await _fs2.default.promises.rm(entryPath, {
|
|
86
|
-
recursive: true,
|
|
87
|
-
force: true
|
|
88
|
-
});
|
|
89
|
-
} catch (error) {
|
|
90
|
-
throw _chunkIZC266HSjs.wrapError.call(void 0, error, `Could not remove file or directory '${entryPath}'`);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function createSandbox(projectName) {
|
|
94
|
-
const directoryPath = _path2.default.join(_os2.default.tmpdir(), projectName, uuid.v4());
|
|
95
|
-
return {
|
|
96
|
-
directoryPath,
|
|
97
|
-
async withinSandbox(test) {
|
|
98
|
-
if (await directoryExists(directoryPath)) {
|
|
99
|
-
throw new Error(`${directoryPath} already exists. Cannot continue.`);
|
|
100
|
-
}
|
|
101
|
-
await ensureDirectoryStructureExists(directoryPath);
|
|
102
|
-
try {
|
|
103
|
-
await test({ directoryPath });
|
|
104
|
-
} finally {
|
|
105
|
-
await forceRemove(directoryPath);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
exports.readFile = readFile; exports.writeFile = writeFile; exports.readJsonFile = readJsonFile; exports.writeJsonFile = writeJsonFile; exports.fileExists = fileExists; exports.directoryExists = directoryExists; exports.ensureDirectoryStructureExists = ensureDirectoryStructureExists; exports.forceRemove = forceRemove; exports.createSandbox = createSandbox;
|
|
122
|
-
//# sourceMappingURL=chunk-RNEXSCNP.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/fs.ts"],"names":[],"mappings":";;;;;;AAGA,OAAO,QAAQ;AACf,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,YAAY,UAAU;AAuBtB,eAAsB,SAAS,UAAmC;AAChE,MAAI;AACF,WAAO,MAAM,GAAG,SAAS,SAAS,UAAU,MAAM;AAAA,EACpD,SAAS,OAAO;AACd,UAAM,UAAU,OAAO,wBAAwB,QAAQ,GAAG;AAAA,EAC5D;AACF;AAUA,eAAsB,UACpB,UACA,SACe;AACf,MAAI;AACF,UAAM,GAAG,SAAS,MAAM,KAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAK,CAAC;AACnE,UAAM,GAAG,SAAS,UAAU,UAAU,OAAO;AAAA,EAC/C,SAAS,OAAO;AACd,UAAM,UAAU,OAAO,yBAAyB,QAAQ,GAAG;AAAA,EAC7D;AACF;AAiBA,eAAsB,aACpB,UACA;AAAA,EACE,SAAS;AACX,IAMI,CAAC,GACW;AAChB,MAAI;AACF,UAAM,UAAU,MAAM,GAAG,SAAS,SAAS,UAAU,MAAM;AAC3D,WAAO,OAAO,MAAM,OAAO;AAAA,EAC7B,SAAS,OAAO;AACd,UAAM,UAAU,OAAO,6BAA6B,QAAQ,GAAG;AAAA,EACjE;AACF;AAuBA,eAAsB,cACpB,UACA,WACA;AAAA,EACE,cAAc;AAAA,EACd,WAAW;AACb,IAKI,CAAC,GACU;AACf,MAAI;AACF,UAAM,GAAG,SAAS,MAAM,KAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAK,CAAC;AACnE,UAAM,OAAO,WACT,YAAY,UAAU,WAAW,MAAM,IAAI,IAC3C,YAAY,UAAU,SAAS;AACnC,UAAM,GAAG,SAAS,UAAU,UAAU,IAAI;AAAA,EAC5C,SAAS,OAAO;AACd,UAAM,UAAU,OAAO,8BAA8B,QAAQ,GAAG;AAAA,EAClE;AACF;AASA,eAAsB,WAAW,UAAoC;AACnE,MAAI;AACF,UAAM,QAAQ,MAAM,GAAG,SAAS,KAAK,QAAQ;AAC7C,WAAO,MAAM,OAAO;AAAA,EACtB,SAAS,OAAO;AACd,QAAI,gBAAgB,KAAK,KAAK,MAAM,SAAS,UAAU;AACrD,aAAO;AAAA,IACT;AAEA,UAAM,UAAU,OAAO,uCAAuC,QAAQ,GAAG;AAAA,EAC3E;AACF;AASA,eAAsB,gBAAgB,eAAyC;AAC7E,MAAI;AACF,UAAM,QAAQ,MAAM,GAAG,SAAS,KAAK,aAAa;AAClD,WAAO,MAAM,YAAY;AAAA,EAC3B,SAAS,OAAO;AACd,QAAI,gBAAgB,KAAK,KAAK,MAAM,SAAS,UAAU;AACrD,aAAO;AAAA,IACT;AAEA,UAAM;AAAA,MACJ;AAAA,MACA,4CAA4C,aAAa;AAAA,IAC3D;AAAA,EACF;AACF;AASA,eAAsB,+BACpB,eACe;AACf,MAAI;AACF,UAAM,GAAG,SAAS,MAAM,eAAe,EAAE,WAAW,KAAK,CAAC;AAAA,EAC5D,SAAS,OAAO;AACd,UAAM;AAAA,MACJ;AAAA,MACA,yCAAyC,aAAa;AAAA,IACxD;AAAA,EACF;AACF;AASA,eAAsB,YAAY,WAAkC;AAClE,MAAI;AACF,WAAO,MAAM,GAAG,SAAS,GAAG,WAAW;AAAA,MACrC,WAAW;AAAA,MACX,OAAO;AAAA,IACT,CAAC;AAAA,EACH,SAAS,OAAO;AACd,UAAM,UAAU,OAAO,uCAAuC,SAAS,GAAG;AAAA,EAC5E;AACF;AA0BO,SAAS,cAAc,aAAkC;AAC9D,QAAM,gBAAgB,KAAK,KAAK,GAAG,OAAO,GAAG,aAAkB,QAAG,CAAC;AAEnE,SAAO;AAAA,IACL;AAAA,IACA,MAAM,cACJ,MACA;AACA,UAAI,MAAM,gBAAgB,aAAa,GAAG;AACxC,cAAM,IAAI,MAAM,GAAG,aAAa,mCAAmC;AAAA,MACrE;AAEA,YAAM,+BAA+B,aAAa;AAElD,UAAI;AACF,cAAM,KAAK,EAAE,cAAc,CAAC;AAAA,MAC9B,UAAE;AACA,cAAM,YAAY,aAAa;AAAA,MACjC;AAAA,IACF;AAAA,EACF;AACF","sourcesContent":["// This file is intended to be used only in a Node.js context.\n/* eslint-disable import/no-nodejs-modules */\n\nimport fs from 'fs';\nimport os from 'os';\nimport path from 'path';\nimport * as uuid from 'uuid';\n\nimport { isErrorWithCode, wrapError } from './errors';\nimport type { Json } from './json';\n\n/**\n * Information about the file sandbox provided to tests that need temporary\n * access to the filesystem.\n */\nexport type FileSandbox = {\n directoryPath: string;\n withinSandbox: (\n test: (args: { directoryPath: string }) => Promise<void>,\n ) => Promise<void>;\n};\n\n/**\n * Read the file at the given path, assuming its content is encoded as UTF-8.\n *\n * @param filePath - The path to the file.\n * @returns The content of the file.\n * @throws An error with a stack trace if reading fails in any way.\n */\nexport async function readFile(filePath: string): Promise<string> {\n try {\n return await fs.promises.readFile(filePath, 'utf8');\n } catch (error) {\n throw wrapError(error, `Could not read file '${filePath}'`);\n }\n}\n\n/**\n * Write content to the file at the given path, creating the directory structure\n * for the file automatically if necessary.\n *\n * @param filePath - The path to the file.\n * @param content - The new content of the file.\n * @throws An error with a stack trace if writing fails in any way.\n */\nexport async function writeFile(\n filePath: string,\n content: string,\n): Promise<void> {\n try {\n await fs.promises.mkdir(path.dirname(filePath), { recursive: true });\n await fs.promises.writeFile(filePath, content);\n } catch (error) {\n throw wrapError(error, `Could not write file '${filePath}'`);\n }\n}\n\n/**\n * Read the assumed JSON file at the given path, attempts to parse it, and\n * get the resulting object. Supports a custom parser (in case you want to\n * use the [JSON5](https://www.npmjs.com/package/json5) package instead).\n *\n * @param filePath - The path segments pointing to the JSON file. Will be passed\n * to path.join().\n * @param options - Options to this function.\n * @param options.parser - The parser object to use. Defaults to `JSON`.\n * @param options.parser.parse - A function that parses JSON data.\n * @returns The object corresponding to the parsed JSON file, typed against the\n * struct.\n * @throws An error with a stack trace if reading fails in any way, or if the\n * parsed value is not a plain object.\n */\nexport async function readJsonFile<Value extends Json>(\n filePath: string,\n {\n parser = JSON,\n }: {\n parser?: {\n parse: (\n text: Parameters<typeof JSON.parse>[0],\n ) => ReturnType<typeof JSON.parse>;\n };\n } = {},\n): Promise<Value> {\n try {\n const content = await fs.promises.readFile(filePath, 'utf8');\n return parser.parse(content);\n } catch (error) {\n throw wrapError(error, `Could not read JSON file '${filePath}'`);\n }\n}\n\n/**\n * Attempt to write the given JSON-like value to the file at the given path,\n * creating the directory structure for the file automatically if necessary.\n * Adds a newline to the end of the file. Supports a custom parser (in case you\n * want to use the [JSON5](https://www.npmjs.com/package/json5) package\n * instead).\n *\n * @param filePath - The path to write the JSON file to, including the file\n * itself.\n * @param jsonValue - The JSON-like value to write to the file. Make sure that\n * JSON.stringify can handle it.\n * @param options - The options to this function.\n * @param options.prettify - Whether to format the JSON as it is turned into a\n * string such that it is broken up into separate lines (using 2 spaces as\n * indentation).\n * @param options.stringifier - The stringifier to use. Defaults to `JSON`.\n * @param options.stringifier.stringify - A function that stringifies JSON.\n * @returns The object corresponding to the parsed JSON file, typed against the\n * struct.\n * @throws An error with a stack trace if writing fails in any way.\n */\nexport async function writeJsonFile(\n filePath: string,\n jsonValue: Json,\n {\n stringifier = JSON,\n prettify = false,\n }: {\n stringifier?: {\n stringify: typeof JSON.stringify;\n };\n prettify?: boolean;\n } = {},\n): Promise<void> {\n try {\n await fs.promises.mkdir(path.dirname(filePath), { recursive: true });\n const json = prettify\n ? stringifier.stringify(jsonValue, null, ' ')\n : stringifier.stringify(jsonValue);\n await fs.promises.writeFile(filePath, json);\n } catch (error) {\n throw wrapError(error, `Could not write JSON file '${filePath}'`);\n }\n}\n\n/**\n * Test the given path to determine whether it represents a file.\n *\n * @param filePath - The path to a (supposed) file on the filesystem.\n * @returns A promise for true if the file exists or false otherwise.\n * @throws An error with a stack trace if reading fails in any way.\n */\nexport async function fileExists(filePath: string): Promise<boolean> {\n try {\n const stats = await fs.promises.stat(filePath);\n return stats.isFile();\n } catch (error) {\n if (isErrorWithCode(error) && error.code === 'ENOENT') {\n return false;\n }\n\n throw wrapError(error, `Could not determine if file exists '${filePath}'`);\n }\n}\n\n/**\n * Test the given path to determine whether it represents a directory.\n *\n * @param directoryPath - The path to a (supposed) directory on the filesystem.\n * @returns A promise for true if the file exists or false otherwise.\n * @throws An error with a stack trace if reading fails in any way.\n */\nexport async function directoryExists(directoryPath: string): Promise<boolean> {\n try {\n const stats = await fs.promises.stat(directoryPath);\n return stats.isDirectory();\n } catch (error) {\n if (isErrorWithCode(error) && error.code === 'ENOENT') {\n return false;\n }\n\n throw wrapError(\n error,\n `Could not determine if directory exists '${directoryPath}'`,\n );\n }\n}\n\n/**\n * Create the given directory along with any directories leading up to the\n * directory, or do nothing if the directory already exists.\n *\n * @param directoryPath - The path to the desired directory.\n * @throws An error with a stack trace if reading fails in any way.\n */\nexport async function ensureDirectoryStructureExists(\n directoryPath: string,\n): Promise<void> {\n try {\n await fs.promises.mkdir(directoryPath, { recursive: true });\n } catch (error) {\n throw wrapError(\n error,\n `Could not create directory structure '${directoryPath}'`,\n );\n }\n}\n\n/**\n * Remove the given file or directory if it exists, or do nothing if it does\n * not.\n *\n * @param entryPath - The path to the file or directory.\n * @throws An error with a stack trace if removal fails in any way.\n */\nexport async function forceRemove(entryPath: string): Promise<void> {\n try {\n return await fs.promises.rm(entryPath, {\n recursive: true,\n force: true,\n });\n } catch (error) {\n throw wrapError(error, `Could not remove file or directory '${entryPath}'`);\n }\n}\n\n/**\n * Construct a sandbox object which can be used in tests that need temporary\n * access to the filesystem.\n *\n * @param projectName - The name of the project.\n * @returns The sandbox object. This contains a `withinSandbox` function which\n * can be used in tests (see example).\n * @example\n * ```typescript\n * const { withinSandbox } = createSandbox('utils');\n *\n * // ... later ...\n *\n * it('does something with the filesystem', async () => {\n * await withinSandbox(async ({ directoryPath }) => {\n * await fs.promises.writeFile(\n * path.join(directoryPath, 'some-file'),\n * 'some content',\n * 'utf8'\n * );\n * })\n * });\n * ```\n */\nexport function createSandbox(projectName: string): FileSandbox {\n const directoryPath = path.join(os.tmpdir(), projectName, uuid.v4());\n\n return {\n directoryPath,\n async withinSandbox(\n test: (args: { directoryPath: string }) => Promise<void>,\n ) {\n if (await directoryExists(directoryPath)) {\n throw new Error(`${directoryPath} already exists. Cannot continue.`);\n }\n\n await ensureDirectoryStructureExists(directoryPath);\n\n try {\n await test({ directoryPath });\n } finally {\n await forceRemove(directoryPath);\n }\n },\n };\n}\n"]}
|
package/dist/chunk-ROQSKDP5.mjs
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
assertStruct
|
|
3
|
-
} from "./chunk-74DGVJVE.mjs";
|
|
4
|
-
|
|
5
|
-
// src/versions.ts
|
|
6
|
-
import {
|
|
7
|
-
gt as gtSemver,
|
|
8
|
-
gtr as gtrSemver,
|
|
9
|
-
satisfies as satisfiesSemver,
|
|
10
|
-
valid as validSemVerVersion,
|
|
11
|
-
validRange as validSemVerRange
|
|
12
|
-
} from "semver";
|
|
13
|
-
import { is, refine, string } from "superstruct";
|
|
14
|
-
var VersionStruct = refine(
|
|
15
|
-
string(),
|
|
16
|
-
"Version",
|
|
17
|
-
(value) => {
|
|
18
|
-
if (validSemVerVersion(value) === null) {
|
|
19
|
-
return `Expected SemVer version, got "${value}"`;
|
|
20
|
-
}
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
);
|
|
24
|
-
var VersionRangeStruct = refine(
|
|
25
|
-
string(),
|
|
26
|
-
"Version range",
|
|
27
|
-
(value) => {
|
|
28
|
-
if (validSemVerRange(value) === null) {
|
|
29
|
-
return `Expected SemVer range, got "${value}"`;
|
|
30
|
-
}
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
);
|
|
34
|
-
function isValidSemVerVersion(version) {
|
|
35
|
-
return is(version, VersionStruct);
|
|
36
|
-
}
|
|
37
|
-
function isValidSemVerRange(versionRange) {
|
|
38
|
-
return is(versionRange, VersionRangeStruct);
|
|
39
|
-
}
|
|
40
|
-
function assertIsSemVerVersion(version) {
|
|
41
|
-
assertStruct(version, VersionStruct);
|
|
42
|
-
}
|
|
43
|
-
function assertIsSemVerRange(range) {
|
|
44
|
-
assertStruct(range, VersionRangeStruct);
|
|
45
|
-
}
|
|
46
|
-
function gtVersion(version1, version2) {
|
|
47
|
-
return gtSemver(version1, version2);
|
|
48
|
-
}
|
|
49
|
-
function gtRange(version, range) {
|
|
50
|
-
return gtrSemver(version, range);
|
|
51
|
-
}
|
|
52
|
-
function satisfiesVersionRange(version, versionRange) {
|
|
53
|
-
return satisfiesSemver(version, versionRange, {
|
|
54
|
-
includePrerelease: true
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export {
|
|
59
|
-
VersionStruct,
|
|
60
|
-
VersionRangeStruct,
|
|
61
|
-
isValidSemVerVersion,
|
|
62
|
-
isValidSemVerRange,
|
|
63
|
-
assertIsSemVerVersion,
|
|
64
|
-
assertIsSemVerRange,
|
|
65
|
-
gtVersion,
|
|
66
|
-
gtRange,
|
|
67
|
-
satisfiesVersionRange
|
|
68
|
-
};
|
|
69
|
-
//# sourceMappingURL=chunk-ROQSKDP5.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/versions.ts"],"sourcesContent":["import {\n gt as gtSemver,\n gtr as gtrSemver,\n satisfies as satisfiesSemver,\n valid as validSemVerVersion,\n validRange as validSemVerRange,\n} from 'semver';\nimport type { Struct } from 'superstruct';\nimport { is, refine, string } from 'superstruct';\n\nimport { assertStruct } from './assert';\nimport type { Opaque } from './opaque';\n\n/**\n * {@link https://codemix.com/opaque-types-in-javascript/ Opaque} type for SemVer ranges.\n *\n * @example Use {@link assertIsSemVerRange} and {@link isValidSemVerRange} to cast to proper type.\n * ```typescript\n * const unsafeRange: string = dataFromUser();\n * assertIsSemVerRange(unsafeRange);\n * unsafeRange\n * // ^? SemVerRange\n * ```\n * @example If you know what you're doing and want to side-step type safety, casting from a string works correctly.\n * ```typescript\n * const unsafeRange: string = dataFromUser();\n * unsafeRange as SemVerRange;\n * // ^? SemVerRange\n * ```\n * @see {@link assertIsSemVerRange}\n * @see {@link isValidSemVerRange}\n */\nexport type SemVerRange = Opaque<string, typeof semVerRange>;\ndeclare const semVerRange: unique symbol;\n\n/**\n * {@link https://codemix.com/opaque-types-in-javascript/ Opaque} type for singular SemVer version.\n *\n * @example Use {@link assertIsSemVerVersion} and {@link isValidSemVerVersion} to cast to proper type.\n * ```typescript\n * const unsafeVersion: string = dataFromUser();\n * assertIsSemVerVersion(unsafeRange);\n * unsafeVersion\n * // ^? SemVerVersion\n * ```\n * @example If you know what you're doing and want to side-step type safety, casting from a string works correctly.\n * ```typescript\n * const unsafeVersion: string = dataFromUser();\n * unsafeRange as SemVerVersion;\n * // ^? SemVerVersion\n * ```\n * @see {@link assertIsSemVerVersion}\n * @see {@link isValidSemVerVersion}\n */\nexport type SemVerVersion = Opaque<string, typeof semVerVersion>;\ndeclare const semVerVersion: unique symbol;\n\n/**\n * A struct for validating a version string.\n */\nexport const VersionStruct = refine<SemVerVersion, null>(\n string() as unknown as Struct<SemVerVersion, null>,\n 'Version',\n (value) => {\n if (validSemVerVersion(value) === null) {\n return `Expected SemVer version, got \"${value}\"`;\n }\n return true;\n },\n);\n\nexport const VersionRangeStruct = refine<SemVerRange, null>(\n string() as unknown as Struct<SemVerRange, null>,\n 'Version range',\n (value) => {\n if (validSemVerRange(value) === null) {\n return `Expected SemVer range, got \"${value}\"`;\n }\n return true;\n },\n);\n\n/**\n * Checks whether a SemVer version is valid.\n *\n * @param version - A potential version.\n * @returns `true` if the version is valid, and `false` otherwise.\n */\nexport function isValidSemVerVersion(\n version: unknown,\n): version is SemVerVersion {\n return is(version, VersionStruct);\n}\n\n/**\n * Checks whether a SemVer version range is valid.\n *\n * @param versionRange - A potential version range.\n * @returns `true` if the version range is valid, and `false` otherwise.\n */\nexport function isValidSemVerRange(\n versionRange: unknown,\n): versionRange is SemVerRange {\n return is(versionRange, VersionRangeStruct);\n}\n\n/**\n * Asserts that a value is a valid concrete SemVer version.\n *\n * @param version - A potential SemVer concrete version.\n */\nexport function assertIsSemVerVersion(\n version: unknown,\n): asserts version is SemVerVersion {\n assertStruct(version, VersionStruct);\n}\n\n/**\n * Asserts that a value is a valid SemVer range.\n *\n * @param range - A potential SemVer range.\n */\nexport function assertIsSemVerRange(\n range: unknown,\n): asserts range is SemVerRange {\n assertStruct(range, VersionRangeStruct);\n}\n\n/**\n * Checks whether a SemVer version is greater than another.\n *\n * @param version1 - The left-hand version.\n * @param version2 - The right-hand version.\n * @returns `version1 > version2`.\n */\nexport function gtVersion(\n version1: SemVerVersion,\n version2: SemVerVersion,\n): boolean {\n return gtSemver(version1, version2);\n}\n\n/**\n * Checks whether a SemVer version is greater than all possibilities in a range.\n *\n * @param version - A SemvVer version.\n * @param range - The range to check against.\n * @returns `version > range`.\n */\nexport function gtRange(version: SemVerVersion, range: SemVerRange): boolean {\n return gtrSemver(version, range);\n}\n\n/**\n * Returns whether a SemVer version satisfies a SemVer range.\n *\n * @param version - The SemVer version to check.\n * @param versionRange - The SemVer version range to check against.\n * @returns Whether the version satisfied the version range.\n */\nexport function satisfiesVersionRange(\n version: SemVerVersion,\n versionRange: SemVerRange,\n): boolean {\n return satisfiesSemver(version, versionRange, {\n includePrerelease: true,\n });\n}\n"],"mappings":";;;;;AAAA;AAAA,EACE,MAAM;AAAA,EACN,OAAO;AAAA,EACP,aAAa;AAAA,EACb,SAAS;AAAA,EACT,cAAc;AAAA,OACT;AAEP,SAAS,IAAI,QAAQ,cAAc;AAoD5B,IAAM,gBAAgB;AAAA,EAC3B,OAAO;AAAA,EACP;AAAA,EACA,CAAC,UAAU;AACT,QAAI,mBAAmB,KAAK,MAAM,MAAM;AACtC,aAAO,iCAAiC,KAAK;AAAA,IAC/C;AACA,WAAO;AAAA,EACT;AACF;AAEO,IAAM,qBAAqB;AAAA,EAChC,OAAO;AAAA,EACP;AAAA,EACA,CAAC,UAAU;AACT,QAAI,iBAAiB,KAAK,MAAM,MAAM;AACpC,aAAO,+BAA+B,KAAK;AAAA,IAC7C;AACA,WAAO;AAAA,EACT;AACF;AAQO,SAAS,qBACd,SAC0B;AAC1B,SAAO,GAAG,SAAS,aAAa;AAClC;AAQO,SAAS,mBACd,cAC6B;AAC7B,SAAO,GAAG,cAAc,kBAAkB;AAC5C;AAOO,SAAS,sBACd,SACkC;AAClC,eAAa,SAAS,aAAa;AACrC;AAOO,SAAS,oBACd,OAC8B;AAC9B,eAAa,OAAO,kBAAkB;AACxC;AASO,SAAS,UACd,UACA,UACS;AACT,SAAO,SAAS,UAAU,QAAQ;AACpC;AASO,SAAS,QAAQ,SAAwB,OAA6B;AAC3E,SAAO,UAAU,SAAS,KAAK;AACjC;AASO,SAAS,sBACd,SACA,cACS;AACT,SAAO,gBAAgB,SAAS,cAAc;AAAA,IAC5C,mBAAmB;AAAA,EACrB,CAAC;AACH;","names":[]}
|
package/dist/chunk-RRYOWRCV.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=chunk-RRYOWRCV.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|