@metamask/utils 6.2.0 → 7.0.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 +11 -1
- package/dist/cjs/assert.js +116 -0
- package/dist/cjs/assert.js.map +1 -0
- package/dist/cjs/base64.js +32 -0
- package/dist/cjs/base64.js.map +1 -0
- package/dist/cjs/bytes.js +255 -0
- package/dist/cjs/bytes.js.map +1 -0
- package/dist/cjs/checksum.js +17 -0
- package/dist/cjs/checksum.js.map +1 -0
- package/dist/cjs/coercers.js +96 -0
- package/dist/cjs/coercers.js.map +1 -0
- package/dist/cjs/collections.js +157 -0
- package/dist/cjs/collections.js.map +1 -0
- package/dist/cjs/encryption-types.js +6 -0
- package/dist/cjs/encryption-types.js.map +1 -0
- package/dist/cjs/hex.js +107 -0
- package/dist/cjs/hex.js.map +1 -0
- package/dist/cjs/index.js +36 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/json.js +263 -0
- package/dist/cjs/json.js.map +1 -0
- package/dist/cjs/keyring.js +6 -0
- package/dist/cjs/keyring.js.map +1 -0
- package/dist/cjs/logging.js +33 -0
- package/dist/cjs/logging.js.map +1 -0
- package/dist/cjs/misc.js +111 -0
- package/dist/cjs/misc.js.map +1 -0
- package/dist/cjs/number.js +52 -0
- package/dist/cjs/number.js.map +1 -0
- package/dist/cjs/opaque.js +8 -0
- package/dist/cjs/opaque.js.map +1 -0
- package/dist/cjs/time.js +63 -0
- package/dist/cjs/time.js.map +1 -0
- package/dist/cjs/transaction-types.js +6 -0
- package/dist/cjs/transaction-types.js.map +1 -0
- package/dist/cjs/versions.js +79 -0
- package/dist/cjs/versions.js.map +1 -0
- package/dist/{assert.js → esm/assert.js} +30 -35
- package/dist/esm/assert.js.map +1 -0
- package/dist/{base64.js → esm/base64.js} +10 -16
- package/dist/esm/base64.js.map +1 -0
- package/dist/{bytes.js → esm/bytes.js} +50 -93
- package/dist/esm/bytes.js.map +1 -0
- package/dist/esm/checksum.js +7 -0
- package/dist/esm/checksum.js.map +1 -0
- package/dist/{coercers.js → esm/coercers.js} +43 -52
- package/dist/esm/coercers.js.map +1 -0
- package/dist/esm/collections.js +140 -0
- package/dist/esm/collections.js.map +1 -0
- package/dist/esm/encryption-types.js +3 -0
- package/dist/esm/encryption-types.js.map +1 -0
- package/dist/esm/hex.js +108 -0
- package/dist/esm/hex.js.map +1 -0
- package/dist/{index.d.ts → esm/index.js} +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/json.js +301 -0
- package/dist/esm/json.js.map +1 -0
- package/dist/esm/keyring.js +3 -0
- package/dist/esm/keyring.js.map +1 -0
- package/dist/{logging.js → esm/logging.js} +5 -14
- package/dist/esm/logging.js.map +1 -0
- package/dist/{misc.js → esm/misc.js} +37 -42
- package/dist/esm/misc.js.map +1 -0
- package/dist/{number.js → esm/number.js} +18 -28
- package/dist/esm/number.js.map +1 -0
- package/dist/esm/opaque.js +5 -0
- package/dist/esm/opaque.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/time.js +53 -0
- package/dist/esm/time.js.map +1 -0
- package/dist/esm/transaction-types.js +3 -0
- package/dist/esm/transaction-types.js.map +1 -0
- package/dist/esm/versions.js +78 -0
- package/dist/esm/versions.js.map +1 -0
- package/dist/{assert.d.ts → types/assert.d.ts} +3 -2
- package/dist/types/assert.d.ts.map +1 -0
- package/dist/{base64.d.ts → types/base64.d.ts} +3 -2
- package/dist/types/base64.d.ts.map +1 -0
- package/dist/{bytes.d.ts → types/bytes.d.ts} +2 -1
- package/dist/types/bytes.d.ts.map +1 -0
- package/dist/{checksum.d.ts → types/checksum.d.ts} +1 -0
- package/dist/types/checksum.d.ts.map +1 -0
- package/dist/{coercers.d.ts → types/coercers.d.ts} +3 -2
- package/dist/types/coercers.d.ts.map +1 -0
- package/dist/{collections.d.ts → types/collections.d.ts} +1 -0
- package/dist/types/collections.d.ts.map +1 -0
- package/dist/{encryption-types.d.ts → types/encryption-types.d.ts} +1 -0
- package/dist/types/encryption-types.d.ts.map +1 -0
- package/dist/{hex.d.ts → types/hex.d.ts} +2 -1
- package/dist/types/hex.d.ts.map +1 -0
- package/dist/types/hex.test-d.d.ts +2 -0
- package/dist/types/hex.test-d.d.ts.map +1 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/{json.d.ts → types/json.d.ts} +3 -2
- package/dist/types/json.d.ts.map +1 -0
- package/dist/types/json.test-d.d.ts +2 -0
- package/dist/types/json.test-d.d.ts.map +1 -0
- package/dist/{keyring.d.ts → types/keyring.d.ts} +3 -2
- package/dist/types/keyring.d.ts.map +1 -0
- package/dist/{logging.d.ts → types/logging.d.ts} +2 -1
- package/dist/types/logging.d.ts.map +1 -0
- package/dist/{misc.d.ts → types/misc.d.ts} +13 -0
- package/dist/types/misc.d.ts.map +1 -0
- package/dist/types/misc.test-d.d.ts +2 -0
- package/dist/types/misc.test-d.d.ts.map +1 -0
- package/dist/{number.d.ts → types/number.d.ts} +1 -0
- package/dist/types/number.d.ts.map +1 -0
- package/dist/{opaque.d.ts → types/opaque.d.ts} +1 -0
- package/dist/types/opaque.d.ts.map +1 -0
- package/dist/{time.d.ts → types/time.d.ts} +1 -0
- package/dist/types/time.d.ts.map +1 -0
- package/dist/{transaction-types.d.ts → types/transaction-types.d.ts} +3 -2
- package/dist/types/transaction-types.d.ts.map +1 -0
- package/dist/{versions.d.ts → types/versions.d.ts} +3 -2
- package/dist/types/versions.d.ts.map +1 -0
- package/package.json +40 -20
- package/dist/__fixtures__/bytes.d.ts +0 -25
- package/dist/__fixtures__/bytes.js +0 -234
- package/dist/__fixtures__/bytes.js.map +0 -1
- package/dist/__fixtures__/coercions.d.ts +0 -5
- package/dist/__fixtures__/coercions.js +0 -22
- package/dist/__fixtures__/coercions.js.map +0 -1
- package/dist/__fixtures__/index.d.ts +0 -4
- package/dist/__fixtures__/index.js +0 -21
- package/dist/__fixtures__/index.js.map +0 -1
- package/dist/__fixtures__/json.d.ts +0 -1226
- package/dist/__fixtures__/json.js +0 -1491
- package/dist/__fixtures__/json.js.map +0 -1
- package/dist/__fixtures__/numbers.d.ts +0 -5
- package/dist/__fixtures__/numbers.js +0 -56
- package/dist/__fixtures__/numbers.js.map +0 -1
- package/dist/assert.js.map +0 -1
- package/dist/base64.js.map +0 -1
- package/dist/bytes.js.map +0 -1
- package/dist/checksum.js +0 -7
- package/dist/checksum.js.map +0 -1
- package/dist/coercers.js.map +0 -1
- package/dist/collections.js +0 -109
- package/dist/collections.js.map +0 -1
- package/dist/encryption-types.js +0 -3
- package/dist/encryption-types.js.map +0 -1
- package/dist/hex.js +0 -134
- package/dist/hex.js.map +0 -1
- package/dist/hex.test-d.d.ts +0 -1
- package/dist/hex.test-d.js +0 -16
- package/dist/hex.test-d.js.map +0 -1
- package/dist/index.js +0 -34
- package/dist/index.js.map +0 -1
- package/dist/json.js +0 -346
- package/dist/json.js.map +0 -1
- package/dist/json.test-d.d.ts +0 -1
- package/dist/json.test-d.js +0 -62
- package/dist/json.test-d.js.map +0 -1
- package/dist/keyring.js +0 -3
- package/dist/keyring.js.map +0 -1
- package/dist/logging.js.map +0 -1
- package/dist/misc.js.map +0 -1
- package/dist/misc.test-d.d.ts +0 -1
- package/dist/misc.test-d.js +0 -97
- package/dist/misc.test-d.js.map +0 -1
- package/dist/number.js.map +0 -1
- package/dist/opaque.js +0 -3
- package/dist/opaque.js.map +0 -1
- package/dist/time.js +0 -67
- package/dist/time.js.map +0 -1
- package/dist/transaction-types.js +0 -3
- package/dist/transaction-types.js.map +0 -1
- package/dist/versions.js +0 -95
- package/dist/versions.js.map +0 -1
package/dist/misc.test-d.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tsd_1 = require("tsd");
|
|
4
|
-
const misc_1 = require("./misc");
|
|
5
|
-
//=============================================================================
|
|
6
|
-
// isObject
|
|
7
|
-
//=============================================================================
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
9
|
-
const unknownValue = {};
|
|
10
|
-
(0, tsd_1.expectNotAssignable)(unknownValue);
|
|
11
|
-
if ((0, misc_1.isObject)(unknownValue)) {
|
|
12
|
-
(0, tsd_1.expectAssignable)(unknownValue);
|
|
13
|
-
}
|
|
14
|
-
// Does not interfere with satisfaction of static type
|
|
15
|
-
const constObjectType = { foo: 'foo' };
|
|
16
|
-
if ((0, misc_1.hasProperty)(constObjectType, 'foo')) {
|
|
17
|
-
(0, tsd_1.expectAssignable)(constObjectType);
|
|
18
|
-
}
|
|
19
|
-
//=============================================================================
|
|
20
|
-
// hasProperty
|
|
21
|
-
//=============================================================================
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
23
|
-
const unknownObject = {};
|
|
24
|
-
// Establish that `Object` is not accepted when a specific property is needed.
|
|
25
|
-
(0, tsd_1.expectNotAssignable)(unknownObject);
|
|
26
|
-
// Establish that `RuntimeObject` is not accepted when a specific property is needed.
|
|
27
|
-
if ((0, misc_1.isObject)(unknownObject)) {
|
|
28
|
-
(0, tsd_1.expectNotAssignable)(unknownObject);
|
|
29
|
-
}
|
|
30
|
-
// An object is accepted after `hasProperty` is used to prove that it has the required property.
|
|
31
|
-
if ((0, misc_1.isObject)(unknownObject) && (0, misc_1.hasProperty)(unknownObject, 'foo')) {
|
|
32
|
-
(0, tsd_1.expectAssignable)(unknownObject);
|
|
33
|
-
}
|
|
34
|
-
// An object is accepted after `hasProperty` is used to prove that it has all required properties.
|
|
35
|
-
if ((0, misc_1.isObject)(unknownObject) &&
|
|
36
|
-
(0, misc_1.hasProperty)(unknownObject, 'foo') &&
|
|
37
|
-
(0, misc_1.hasProperty)(unknownObject, 'bar')) {
|
|
38
|
-
(0, tsd_1.expectAssignable)(unknownObject);
|
|
39
|
-
}
|
|
40
|
-
// An object is not accepted after `hasProperty` has only been used to establish that some required properties exist.
|
|
41
|
-
if ((0, misc_1.isObject)(unknownObject) && (0, misc_1.hasProperty)(unknownObject, 'foo')) {
|
|
42
|
-
(0, tsd_1.expectNotAssignable)(unknownObject);
|
|
43
|
-
}
|
|
44
|
-
// Does not interfere with satisfaction of non-overlapping types
|
|
45
|
-
const overlappingTypesExample = { foo: 'foo', baz: 'baz' };
|
|
46
|
-
if ((0, misc_1.hasProperty)(overlappingTypesExample, 'foo')) {
|
|
47
|
-
(0, tsd_1.expectAssignable)(overlappingTypesExample);
|
|
48
|
-
}
|
|
49
|
-
const exampleErrorWithCode = new Error('test');
|
|
50
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
51
|
-
// @ts-ignore
|
|
52
|
-
exampleErrorWithCode.code = 999;
|
|
53
|
-
// Establish that trying to check for a custom property on an error results in failure
|
|
54
|
-
(0, tsd_1.expectNotAssignable)(exampleErrorWithCode);
|
|
55
|
-
// Using custom Error property is allowed after checking with `hasProperty`
|
|
56
|
-
if ((0, misc_1.hasProperty)(exampleErrorWithCode, 'code')) {
|
|
57
|
-
(0, tsd_1.expectType)(exampleErrorWithCode.code);
|
|
58
|
-
}
|
|
59
|
-
const hasPropertyInterfaceExample = { a: 0 };
|
|
60
|
-
(0, misc_1.hasProperty)(hasPropertyInterfaceExample, 'a');
|
|
61
|
-
// `hasProperty` is compatible with classes
|
|
62
|
-
class HasPropertyClassExample {
|
|
63
|
-
}
|
|
64
|
-
const hasPropertyClassExample = new HasPropertyClassExample();
|
|
65
|
-
(0, misc_1.hasProperty)(hasPropertyClassExample, 'a');
|
|
66
|
-
// It keeps the original type when defined.
|
|
67
|
-
const hasPropertyTypeExample = {};
|
|
68
|
-
if ((0, misc_1.hasProperty)(hasPropertyTypeExample, 'a')) {
|
|
69
|
-
(0, tsd_1.expectType)(hasPropertyTypeExample.a);
|
|
70
|
-
}
|
|
71
|
-
//=============================================================================
|
|
72
|
-
// RuntimeObject
|
|
73
|
-
//=============================================================================
|
|
74
|
-
// Valid runtime objects:
|
|
75
|
-
(0, tsd_1.expectAssignable)({});
|
|
76
|
-
(0, tsd_1.expectAssignable)({ foo: 'foo' });
|
|
77
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
78
|
-
(0, tsd_1.expectAssignable)({ 0: 'foo' });
|
|
79
|
-
(0, tsd_1.expectAssignable)({ [Symbol('foo')]: 'foo' });
|
|
80
|
-
// Invalid runtime objects:
|
|
81
|
-
(0, tsd_1.expectNotAssignable)(null);
|
|
82
|
-
(0, tsd_1.expectNotAssignable)(undefined);
|
|
83
|
-
(0, tsd_1.expectNotAssignable)('foo');
|
|
84
|
-
(0, tsd_1.expectNotAssignable)(0);
|
|
85
|
-
(0, tsd_1.expectNotAssignable)([]);
|
|
86
|
-
(0, tsd_1.expectNotAssignable)(new Date());
|
|
87
|
-
(0, tsd_1.expectNotAssignable)(() => 0);
|
|
88
|
-
(0, tsd_1.expectNotAssignable)(new Set());
|
|
89
|
-
(0, tsd_1.expectNotAssignable)(new Map());
|
|
90
|
-
(0, tsd_1.expectNotAssignable)(Symbol('test'));
|
|
91
|
-
const runtimeObjectInterfaceExample = { a: 0 };
|
|
92
|
-
(0, tsd_1.expectNotAssignable)(runtimeObjectInterfaceExample);
|
|
93
|
-
class RuntimeObjectClassExample {
|
|
94
|
-
}
|
|
95
|
-
const runtimeObjectClassExample = new RuntimeObjectClassExample();
|
|
96
|
-
(0, tsd_1.expectNotAssignable)(runtimeObjectClassExample);
|
|
97
|
-
//# sourceMappingURL=misc.test-d.js.map
|
package/dist/misc.test-d.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"misc.test-d.js","sourceRoot":"","sources":["../src/misc.test-d.ts"],"names":[],"mappings":";;AAAA,6BAAwE;AAExE,iCAA8D;AAE9D,+EAA+E;AAC/E,WAAW;AACX,+EAA+E;AAE/E,wDAAwD;AACxD,MAAM,YAAY,GAAG,EAAa,CAAC;AAEnC,IAAA,yBAAmB,EAAgB,YAAY,CAAC,CAAC;AAEjD,IAAI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,EAAE,CAAC,CAAC;AAE5D,2BAA2B;AAE3B,IAAA,yBAAmB,EAAgB,IAAI,CAAC,CAAC;AAEzC,IAAA,yBAAmB,EAAgB,SAAS,CAAC,CAAC;AAE9C,IAAA,yBAAmB,EAAgB,KAAK,CAAC,CAAC;AAE1C,IAAA,yBAAmB,EAAgB,CAAC,CAAC,CAAC;AAEtC,IAAA,yBAAmB,EAAgB,EAAE,CAAC,CAAC;AAEvC,IAAA,yBAAmB,EAAgB,IAAI,IAAI,EAAE,CAAC,CAAC;AAE/C,IAAA,yBAAmB,EAAgB,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;AAE5C,IAAA,yBAAmB,EAAgB,IAAI,GAAG,EAAE,CAAC,CAAC;AAE9C,IAAA,yBAAmB,EAAgB,IAAI,GAAG,EAAE,CAAC,CAAC;AAE9C,IAAA,yBAAmB,EAAgB,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;AAQnD,MAAM,6BAA6B,GAAkC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAC9E,IAAA,yBAAmB,EAAgB,6BAA6B,CAAC,CAAC;AAElE,MAAM,yBAAyB;CAE9B;AACD,MAAM,yBAAyB,GAAG,IAAI,yBAAyB,EAAE,CAAC;AAClE,IAAA,yBAAmB,EAAgB,yBAAyB,CAAC,CAAC","sourcesContent":["import { expectAssignable, expectNotAssignable, expectType } from 'tsd';\n\nimport { isObject, hasProperty, RuntimeObject } from './misc';\n\n//=============================================================================\n// isObject\n//=============================================================================\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nconst unknownValue = {} as unknown;\n\nexpectNotAssignable<RuntimeObject>(unknownValue);\n\nif (isObject(unknownValue)) {\n expectAssignable<RuntimeObject>(unknownValue);\n}\n\n// Does not interfere with satisfaction of static type\nconst constObjectType = { foo: 'foo' } as const;\nif (hasProperty(constObjectType, 'foo')) {\n expectAssignable<{ foo: 'foo' }>(constObjectType);\n}\n\n//=============================================================================\n// hasProperty\n//=============================================================================\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nconst unknownObject = {} as Object;\n\n// Establish that `Object` is not accepted when a specific property is needed.\nexpectNotAssignable<Record<'foo', unknown>>(unknownObject);\n\n// Establish that `RuntimeObject` is not accepted when a specific property is needed.\nif (isObject(unknownObject)) {\n expectNotAssignable<Record<'foo', unknown>>(unknownObject);\n}\n\n// An object is accepted after `hasProperty` is used to prove that it has the required property.\nif (isObject(unknownObject) && hasProperty(unknownObject, 'foo')) {\n expectAssignable<Record<'foo', unknown>>(unknownObject);\n}\n\n// An object is accepted after `hasProperty` is used to prove that it has all required properties.\nif (\n isObject(unknownObject) &&\n hasProperty(unknownObject, 'foo') &&\n hasProperty(unknownObject, 'bar')\n) {\n expectAssignable<Record<'foo' | 'bar', unknown>>(unknownObject);\n}\n\n// An object is not accepted after `hasProperty` has only been used to establish that some required properties exist.\nif (isObject(unknownObject) && hasProperty(unknownObject, 'foo')) {\n expectNotAssignable<Record<'foo' | 'bar', unknown>>(unknownObject);\n}\n\n// Does not interfere with satisfaction of non-overlapping types\nconst overlappingTypesExample = { foo: 'foo', baz: 'baz' };\nif (hasProperty(overlappingTypesExample, 'foo')) {\n expectAssignable<Record<'baz', unknown>>(overlappingTypesExample);\n}\n\nconst exampleErrorWithCode = new Error('test');\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nexampleErrorWithCode.code = 999;\n\n// Establish that trying to check for a custom property on an error results in failure\nexpectNotAssignable<{ code: any }>(exampleErrorWithCode);\n\n// Using custom Error property is allowed after checking with `hasProperty`\nif (hasProperty(exampleErrorWithCode, 'code')) {\n expectType<unknown>(exampleErrorWithCode.code);\n}\n\n// `hasProperty` is compatible with interfaces\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\ninterface HasPropertyInterfaceExample {\n a: number;\n}\nconst hasPropertyInterfaceExample: HasPropertyInterfaceExample = { a: 0 };\nhasProperty(hasPropertyInterfaceExample, 'a');\n\n// `hasProperty` is compatible with classes\nclass HasPropertyClassExample {\n a!: number;\n}\nconst hasPropertyClassExample = new HasPropertyClassExample();\nhasProperty(hasPropertyClassExample, 'a');\n\ntype HasPropertyTypeExample = {\n a?: number;\n};\n\n// It keeps the original type when defined.\nconst hasPropertyTypeExample: HasPropertyTypeExample = {};\nif (hasProperty(hasPropertyTypeExample, 'a')) {\n expectType<number | undefined>(hasPropertyTypeExample.a);\n}\n\n//=============================================================================\n// RuntimeObject\n//=============================================================================\n\n// Valid runtime objects:\n\nexpectAssignable<RuntimeObject>({});\n\nexpectAssignable<RuntimeObject>({ foo: 'foo' });\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexpectAssignable<RuntimeObject>({ 0: 'foo' });\n\nexpectAssignable<RuntimeObject>({ [Symbol('foo')]: 'foo' });\n\n// Invalid runtime objects:\n\nexpectNotAssignable<RuntimeObject>(null);\n\nexpectNotAssignable<RuntimeObject>(undefined);\n\nexpectNotAssignable<RuntimeObject>('foo');\n\nexpectNotAssignable<RuntimeObject>(0);\n\nexpectNotAssignable<RuntimeObject>([]);\n\nexpectNotAssignable<RuntimeObject>(new Date());\n\nexpectNotAssignable<RuntimeObject>(() => 0);\n\nexpectNotAssignable<RuntimeObject>(new Set());\n\nexpectNotAssignable<RuntimeObject>(new Map());\n\nexpectNotAssignable<RuntimeObject>(Symbol('test'));\n\n// The RuntimeObject type gets confused by interfaces. This interface is a valid object,\n// but it's incompatible with the RuntimeObject type.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\ninterface RuntimeObjectInterfaceExample {\n a: number;\n}\nconst runtimeObjectInterfaceExample: RuntimeObjectInterfaceExample = { a: 0 };\nexpectNotAssignable<RuntimeObject>(runtimeObjectInterfaceExample);\n\nclass RuntimeObjectClassExample {\n a!: number;\n}\nconst runtimeObjectClassExample = new RuntimeObjectClassExample();\nexpectNotAssignable<RuntimeObject>(runtimeObjectClassExample);\n"]}
|
package/dist/number.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"number.js","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F;;;;;;;;;;;;;;;GAeG;AACI,MAAM,WAAW,GAAG,CAAC,KAAa,EAAU,EAAE;IACnD,IAAA,uBAAiB,EAAC,KAAK,CAAC,CAAC;IAEzB,2EAA2E;IAC3E,OAAO,MAAM,CAAC,IAAA,WAAK,EAAC,KAAK,CAAC,CAAC,CAAC;AAC9B,CAAC,CAAC;AALW,QAAA,WAAW,eAKtB","sourcesContent":["import { assert } from './assert';\nimport { add0x, assertIsHexString } from './hex';\n\n/**\n * Convert a number to a hexadecimal string. This verifies that the number is a\n * non-negative safe integer.\n *\n * To convert a `bigint` to a hexadecimal string instead, use\n * {@link bigIntToHex}.\n *\n * @example\n * ```typescript\n * numberToHex(0); // '0x0'\n * numberToHex(1); // '0x1'\n * numberToHex(16); // '0x10'\n * ```\n * @param value - The number to convert to a hexadecimal string.\n * @returns The hexadecimal string, with the \"0x\"-prefix.\n * @throws If the number is not a non-negative safe integer.\n */\nexport const numberToHex = (value: number): string => {\n assert(typeof value === 'number', 'Value must be a number.');\n assert(value >= 0, 'Value must be a non-negative number.');\n assert(\n Number.isSafeInteger(value),\n 'Value is not a safe integer. Use `bigIntToHex` instead.',\n );\n\n return add0x(value.toString(16));\n};\n\n/**\n * Convert a `bigint` to a hexadecimal string. This verifies that the `bigint`\n * is a non-negative integer.\n *\n * To convert a number to a hexadecimal string instead, use {@link numberToHex}.\n *\n * @example\n * ```typescript\n * bigIntToHex(0n); // '0x0'\n * bigIntToHex(1n); // '0x1'\n * bigIntToHex(16n); // '0x10'\n * ```\n * @param value - The `bigint` to convert to a hexadecimal string.\n * @returns The hexadecimal string, with the \"0x\"-prefix.\n * @throws If the `bigint` is not a non-negative integer.\n */\nexport const bigIntToHex = (value: bigint): string => {\n assert(typeof value === 'bigint', 'Value must be a bigint.');\n assert(value >= 0, 'Value must be a non-negative bigint.');\n\n return add0x(value.toString(16));\n};\n\n/**\n * Convert a hexadecimal string to a number. This verifies that the string is a\n * valid hex string, and that the resulting number is a safe integer. Both\n * \"0x\"-prefixed and unprefixed strings are supported.\n *\n * To convert a hexadecimal string to a `bigint` instead, use\n * {@link hexToBigInt}.\n *\n * @example\n * ```typescript\n * hexToNumber('0x0'); // 0\n * hexToNumber('0x1'); // 1\n * hexToNumber('0x10'); // 16\n * ```\n * @param value - The hexadecimal string to convert to a number.\n * @returns The number.\n * @throws If the value is not a valid hexadecimal string, or if the resulting\n * number is not a safe integer.\n */\nexport const hexToNumber = (value: string): number => {\n assertIsHexString(value);\n\n // `parseInt` accepts values without the \"0x\"-prefix, whereas `Number` does\n // not. Using this is slightly faster than `Number(add0x(value))`.\n const numberValue = parseInt(value, 16);\n\n assert(\n Number.isSafeInteger(numberValue),\n 'Value is not a safe integer. Use `hexToBigInt` instead.',\n );\n\n return numberValue;\n};\n\n/**\n * Convert a hexadecimal string to a `bigint`. This verifies that the string is\n * a valid hex string. Both \"0x\"-prefixed and unprefixed strings are supported.\n *\n * To convert a hexadecimal string to a number instead, use {@link hexToNumber}.\n *\n * @example\n * ```typescript\n * hexToBigInt('0x0'); // 0n\n * hexToBigInt('0x1'); // 1n\n * hexToBigInt('0x10'); // 16n\n * ```\n * @param value - The hexadecimal string to convert to a `bigint`.\n * @returns The `bigint`.\n * @throws If the value is not a valid hexadecimal string.\n */\nexport const hexToBigInt = (value: string): bigint => {\n assertIsHexString(value);\n\n // The `BigInt` constructor requires the \"0x\"-prefix to parse a hex string.\n return BigInt(add0x(value));\n};\n"]}
|
package/dist/opaque.js
DELETED
package/dist/opaque.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"opaque.js","sourceRoot":"","sources":["../src/opaque.ts"],"names":[],"mappings":"","sourcesContent":["// We use a symbol property name instead of { _type: Brand }, because that would show up in IDE suggestions,\n// while internal symbols do not.\ndeclare const brand: unique symbol;\nexport type Opaque<Base, Brand extends symbol> = Base & { [brand]: Brand };\n"]}
|
package/dist/time.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.timeSince = exports.inMilliseconds = exports.Duration = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Common duration constants, in milliseconds.
|
|
6
|
-
*/
|
|
7
|
-
var Duration;
|
|
8
|
-
(function (Duration) {
|
|
9
|
-
/**
|
|
10
|
-
* A millisecond.
|
|
11
|
-
*/
|
|
12
|
-
Duration[Duration["Millisecond"] = 1] = "Millisecond";
|
|
13
|
-
/**
|
|
14
|
-
* A second, in milliseconds.
|
|
15
|
-
*/
|
|
16
|
-
Duration[Duration["Second"] = 1000] = "Second";
|
|
17
|
-
/**
|
|
18
|
-
* A minute, in milliseconds.
|
|
19
|
-
*/
|
|
20
|
-
Duration[Duration["Minute"] = 60000] = "Minute";
|
|
21
|
-
/**
|
|
22
|
-
* An hour, in milliseconds.
|
|
23
|
-
*/
|
|
24
|
-
Duration[Duration["Hour"] = 3600000] = "Hour";
|
|
25
|
-
/**
|
|
26
|
-
* A day, in milliseconds.
|
|
27
|
-
*/
|
|
28
|
-
Duration[Duration["Day"] = 86400000] = "Day";
|
|
29
|
-
/**
|
|
30
|
-
* A week, in milliseconds.
|
|
31
|
-
*/
|
|
32
|
-
Duration[Duration["Week"] = 604800000] = "Week";
|
|
33
|
-
/**
|
|
34
|
-
* A year, in milliseconds.
|
|
35
|
-
*/
|
|
36
|
-
Duration[Duration["Year"] = 31536000000] = "Year";
|
|
37
|
-
})(Duration = exports.Duration || (exports.Duration = {}));
|
|
38
|
-
const isNonNegativeInteger = (number) => Number.isInteger(number) && number >= 0;
|
|
39
|
-
const assertIsNonNegativeInteger = (number, name) => {
|
|
40
|
-
if (!isNonNegativeInteger(number)) {
|
|
41
|
-
throw new Error(`"${name}" must be a non-negative integer. Received: "${number}".`);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Calculates the millisecond value of the specified number of units of time.
|
|
46
|
-
*
|
|
47
|
-
* @param count - The number of units of time.
|
|
48
|
-
* @param duration - The unit of time to count.
|
|
49
|
-
* @returns The count multiplied by the specified duration.
|
|
50
|
-
*/
|
|
51
|
-
function inMilliseconds(count, duration) {
|
|
52
|
-
assertIsNonNegativeInteger(count, 'count');
|
|
53
|
-
return count * duration;
|
|
54
|
-
}
|
|
55
|
-
exports.inMilliseconds = inMilliseconds;
|
|
56
|
-
/**
|
|
57
|
-
* Gets the milliseconds since a particular Unix epoch timestamp.
|
|
58
|
-
*
|
|
59
|
-
* @param timestamp - A Unix millisecond timestamp.
|
|
60
|
-
* @returns The number of milliseconds elapsed since the specified timestamp.
|
|
61
|
-
*/
|
|
62
|
-
function timeSince(timestamp) {
|
|
63
|
-
assertIsNonNegativeInteger(timestamp, 'timestamp');
|
|
64
|
-
return Date.now() - timestamp;
|
|
65
|
-
}
|
|
66
|
-
exports.timeSince = timeSince;
|
|
67
|
-
//# sourceMappingURL=time.js.map
|
package/dist/time.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"time.js","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,IAAY,QAmCX;AAnCD,WAAY,QAAQ;IAClB;;OAEG;IACH,qDAAe,CAAA;IAEf;;OAEG;IACH,8CAAa,CAAA;IAEb;;OAEG;IACH,+CAAe,CAAA;IAEf;;OAEG;IACH,6CAAgB,CAAA;IAEhB;;OAEG;IACH,4CAAgB,CAAA;IAEhB;;OAEG;IACH,+CAAkB,CAAA;IAElB;;OAEG;IACH,iDAAqB,CAAA;AACvB,CAAC,EAnCW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAmCnB;AAED,MAAM,oBAAoB,GAAG,CAAC,MAAc,EAAE,EAAE,CAC9C,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC,CAAC;AAE1C,MAAM,0BAA0B,GAAG,CAAC,MAAc,EAAE,IAAY,EAAE,EAAE;IAClE,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,EAAE;QACjC,MAAM,IAAI,KAAK,CACb,IAAI,IAAI,gDAAgD,MAAM,IAAI,CACnE,CAAC;KACH;AACH,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,KAAa,EAAE,QAAkB;IAC9D,0BAA0B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC3C,OAAO,KAAK,GAAG,QAAQ,CAAC;AAC1B,CAAC;AAHD,wCAGC;AAED;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,SAAiB;IACzC,0BAA0B,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IACnD,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;AAChC,CAAC;AAHD,8BAGC","sourcesContent":["/**\n * Common duration constants, in milliseconds.\n */\nexport enum Duration {\n /**\n * A millisecond.\n */\n Millisecond = 1,\n\n /**\n * A second, in milliseconds.\n */\n Second = 1000, // Millisecond * 1000\n\n /**\n * A minute, in milliseconds.\n */\n Minute = 60_000, // Second * 60\n\n /**\n * An hour, in milliseconds.\n */\n Hour = 3_600_000, // Minute * 60\n\n /**\n * A day, in milliseconds.\n */\n Day = 86_400_000, // Hour * 24\n\n /**\n * A week, in milliseconds.\n */\n Week = 604_800_000, // Day * 7\n\n /**\n * A year, in milliseconds.\n */\n Year = 31_536_000_000, // Day * 365\n}\n\nconst isNonNegativeInteger = (number: number) =>\n Number.isInteger(number) && number >= 0;\n\nconst assertIsNonNegativeInteger = (number: number, name: string) => {\n if (!isNonNegativeInteger(number)) {\n throw new Error(\n `\"${name}\" must be a non-negative integer. Received: \"${number}\".`,\n );\n }\n};\n\n/**\n * Calculates the millisecond value of the specified number of units of time.\n *\n * @param count - The number of units of time.\n * @param duration - The unit of time to count.\n * @returns The count multiplied by the specified duration.\n */\nexport function inMilliseconds(count: number, duration: Duration): number {\n assertIsNonNegativeInteger(count, 'count');\n return count * duration;\n}\n\n/**\n * Gets the milliseconds since a particular Unix epoch timestamp.\n *\n * @param timestamp - A Unix millisecond timestamp.\n * @returns The number of milliseconds elapsed since the specified timestamp.\n */\nexport function timeSince(timestamp: number): number {\n assertIsNonNegativeInteger(timestamp, 'timestamp');\n return Date.now() - timestamp;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-types.js","sourceRoot":"","sources":["../src/transaction-types.ts"],"names":[],"mappings":"","sourcesContent":["import { Bytes } from './bytes';\nimport { Hex } from './hex';\n\nexport type Transaction =\n | LegacyTransaction\n | EIP2930Transaction\n | EIP1559Transaction;\n\nexport type SignedTransaction = Transaction & Signature;\n\nexport type Signature = {\n /**\n * EC signature parameter\n * 32 bytes long sequence.\n */\n r: Bytes;\n\n /**\n * EC signature parameter\n * Signature proof.\n * 32 bytes long sequence\n */\n s: Bytes;\n\n /**\n * Recovery identifier. It can be either 0x1b or 0x1c\n * 1 byte long sequence\n */\n yParity: Bytes;\n};\n\n/**\n * Base Ethereum Transaction\n */\nexport type BaseTransaction = {\n /**\n * Sequentially incrementing counter which indicates the transaction\n * number from the account\n */\n nonce: Bytes;\n\n /**\n * The address of the sender, that will be signing the transaction\n */\n from: Hex | Uint8Array;\n\n /**\n * The receiving address.\n * If an externally-owned account, the transaction will transfer value.\n * If a contract account, the transaction will execute the contract code.\n */\n to: Hex | Uint8Array;\n\n /**\n * The amount of Ether sent.\n */\n value: Bytes;\n\n /**\n * Maximum amount of gas units that this transaction can consume.\n */\n gasLimit: Bytes;\n\n /**\n * Arbitrary data.\n */\n data?: Bytes;\n};\n\n/**\n * Typed Ethereum Transaction\n */\nexport type TypedTransaction = BaseTransaction & {\n /**\n * Transaction type.\n */\n type: number;\n};\n\n/**\n * Ethereum Legacy Transaction\n * Reference: https://ethereum.org/en/developers/docs/transactions/\n */\nexport type LegacyTransaction = BaseTransaction & {\n /**\n * Transaction's gas price.\n */\n gasPrice: Bytes | null;\n};\n\n/**\n * EIP-2930 Transaction: Optional Access Lists\n * Reference: https://eips.ethereum.org/EIPS/eip-2930\n */\nexport type EIP2930Transaction = TypedTransaction & {\n /**\n * Transaction type.\n */\n type: 1;\n\n /**\n * Transaction chain ID\n */\n chainId: Bytes;\n\n /**\n * List of addresses and storage keys that the transaction plans to access\n */\n accessList:\n | { address: Hex; storageKeys: Hex[] }[]\n | { address: Uint8Array; storageKeys: Uint8Array[] }[];\n};\n\n/**\n * EIP-1559 Transaction: Fee market change for ETH 1.0 chain (Type-2)\n *\n * Reference: https://eips.ethereum.org/EIPS/eip-1559\n */\nexport type EIP1559Transaction = TypedTransaction & {\n /**\n * Transaction type.\n */\n type: 2;\n\n /**\n * Maximum fee to give to the miner\n */\n maxPriorityFeePerGas: Bytes;\n\n /**\n * Maximum total fee\n */\n maxFeePerGas: Bytes;\n};\n"]}
|
package/dist/versions.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.satisfiesVersionRange = exports.gtRange = exports.gtVersion = exports.assertIsSemVerRange = exports.assertIsSemVerVersion = exports.isValidSemVerRange = exports.isValidSemVerVersion = exports.VersionRangeStruct = exports.VersionStruct = void 0;
|
|
4
|
-
const semver_1 = require("semver");
|
|
5
|
-
const superstruct_1 = require("superstruct");
|
|
6
|
-
const assert_1 = require("./assert");
|
|
7
|
-
/**
|
|
8
|
-
* A struct for validating a version string.
|
|
9
|
-
*/
|
|
10
|
-
exports.VersionStruct = (0, superstruct_1.refine)((0, superstruct_1.string)(), 'Version', (value) => {
|
|
11
|
-
if ((0, semver_1.valid)(value) === null) {
|
|
12
|
-
return `Expected SemVer version, got "${value}"`;
|
|
13
|
-
}
|
|
14
|
-
return true;
|
|
15
|
-
});
|
|
16
|
-
exports.VersionRangeStruct = (0, superstruct_1.refine)((0, superstruct_1.string)(), 'Version range', (value) => {
|
|
17
|
-
if ((0, semver_1.validRange)(value) === null) {
|
|
18
|
-
return `Expected SemVer range, got "${value}"`;
|
|
19
|
-
}
|
|
20
|
-
return true;
|
|
21
|
-
});
|
|
22
|
-
/**
|
|
23
|
-
* Checks whether a SemVer version is valid.
|
|
24
|
-
*
|
|
25
|
-
* @param version - A potential version.
|
|
26
|
-
* @returns `true` if the version is valid, and `false` otherwise.
|
|
27
|
-
*/
|
|
28
|
-
function isValidSemVerVersion(version) {
|
|
29
|
-
return (0, superstruct_1.is)(version, exports.VersionStruct);
|
|
30
|
-
}
|
|
31
|
-
exports.isValidSemVerVersion = isValidSemVerVersion;
|
|
32
|
-
/**
|
|
33
|
-
* Checks whether a SemVer version range is valid.
|
|
34
|
-
*
|
|
35
|
-
* @param versionRange - A potential version range.
|
|
36
|
-
* @returns `true` if the version range is valid, and `false` otherwise.
|
|
37
|
-
*/
|
|
38
|
-
function isValidSemVerRange(versionRange) {
|
|
39
|
-
return (0, superstruct_1.is)(versionRange, exports.VersionRangeStruct);
|
|
40
|
-
}
|
|
41
|
-
exports.isValidSemVerRange = isValidSemVerRange;
|
|
42
|
-
/**
|
|
43
|
-
* Asserts that a value is a valid concrete SemVer version.
|
|
44
|
-
*
|
|
45
|
-
* @param version - A potential SemVer concrete version.
|
|
46
|
-
*/
|
|
47
|
-
function assertIsSemVerVersion(version) {
|
|
48
|
-
(0, assert_1.assertStruct)(version, exports.VersionStruct);
|
|
49
|
-
}
|
|
50
|
-
exports.assertIsSemVerVersion = assertIsSemVerVersion;
|
|
51
|
-
/**
|
|
52
|
-
* Asserts that a value is a valid SemVer range.
|
|
53
|
-
*
|
|
54
|
-
* @param range - A potential SemVer range.
|
|
55
|
-
*/
|
|
56
|
-
function assertIsSemVerRange(range) {
|
|
57
|
-
(0, assert_1.assertStruct)(range, exports.VersionRangeStruct);
|
|
58
|
-
}
|
|
59
|
-
exports.assertIsSemVerRange = assertIsSemVerRange;
|
|
60
|
-
/**
|
|
61
|
-
* Checks whether a SemVer version is greater than another.
|
|
62
|
-
*
|
|
63
|
-
* @param version1 - The left-hand version.
|
|
64
|
-
* @param version2 - The right-hand version.
|
|
65
|
-
* @returns `version1 > version2`.
|
|
66
|
-
*/
|
|
67
|
-
function gtVersion(version1, version2) {
|
|
68
|
-
return (0, semver_1.gt)(version1, version2);
|
|
69
|
-
}
|
|
70
|
-
exports.gtVersion = gtVersion;
|
|
71
|
-
/**
|
|
72
|
-
* Checks whether a SemVer version is greater than all possibilities in a range.
|
|
73
|
-
*
|
|
74
|
-
* @param version - A SemvVer version.
|
|
75
|
-
* @param range - The range to check against.
|
|
76
|
-
* @returns `version > range`.
|
|
77
|
-
*/
|
|
78
|
-
function gtRange(version, range) {
|
|
79
|
-
return (0, semver_1.gtr)(version, range);
|
|
80
|
-
}
|
|
81
|
-
exports.gtRange = gtRange;
|
|
82
|
-
/**
|
|
83
|
-
* Returns whether a SemVer version satisfies a SemVer range.
|
|
84
|
-
*
|
|
85
|
-
* @param version - The SemVer version to check.
|
|
86
|
-
* @param versionRange - The SemVer version range to check against.
|
|
87
|
-
* @returns Whether the version satisfied the version range.
|
|
88
|
-
*/
|
|
89
|
-
function satisfiesVersionRange(version, versionRange) {
|
|
90
|
-
return (0, semver_1.satisfies)(version, versionRange, {
|
|
91
|
-
includePrerelease: true,
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
exports.satisfiesVersionRange = satisfiesVersionRange;
|
|
95
|
-
//# sourceMappingURL=versions.js.map
|
package/dist/versions.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"versions.js","sourceRoot":"","sources":["../src/versions.ts"],"names":[],"mappings":";;;AAAA,mCAMgB;AAChB,6CAAyD;AAEzD,qCAAwC;AA+CxC;;GAEG;AACU,QAAA,aAAa,GAAG,IAAA,oBAAM,EACjC,IAAA,oBAAM,GAA4C,EAClD,SAAS,EACT,CAAC,KAAK,EAAE,EAAE;IACR,IAAI,IAAA,cAAkB,EAAC,KAAK,CAAC,KAAK,IAAI,EAAE;QACtC,OAAO,iCAAiC,KAAK,GAAG,CAAC;KAClD;IACD,OAA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O,EAAE,YAAY,EAAE;QAC5C,iBAAiB,EAAE,IAAI;KACxB,CAAC,CAAC;AACL,CAAC;AAPD,sDAOC","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 { is, refine, string, Struct } from 'superstruct';\n\nimport { assertStruct } from './assert';\nimport { 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"]}
|