@xylabs/hex 4.13.3 → 4.13.5

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.
@@ -1,94 +1,78 @@
1
- export declare type Address = Exclude<Hex, 'reserved-address-value'>;
2
-
3
- export declare function asAddress(value: unknown): Address | undefined;
4
-
5
- export declare function asAddress(value: unknown, assert: AssertConfig): Address;
6
-
7
- export declare function asHash(value: unknown): Hash | undefined;
8
-
9
- export declare function asHash(value: unknown, assert: AssertConfig): Hash;
10
-
11
- export declare function asHex(value: unknown): Hex | undefined;
12
-
13
- export declare function asHex(value: unknown, assert: AssertConfig): Hex;
14
-
15
- declare type AssertCallback = (value: unknown, message: string) => string | boolean;
16
-
17
- declare type AssertConfig = string | AssertCallback | boolean;
18
-
19
- export declare const bitsToNibbles: (value: number) => number;
20
-
21
- export declare type Hash = Exclude<Hex, 'reserved-hash-value'>;
22
-
23
- export declare type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
24
-
25
- export declare const HashBitLength: HashBitLength[];
26
-
27
- export declare type Hex = Exclude<Lowercase<string>, 'reserved-hex-value'>;
28
-
29
- /** Configuration of validation and output format */
30
- export declare interface HexConfig {
31
- bitLength?: number;
32
- byteSize?: number;
33
- prefix?: boolean;
34
- }
35
-
36
- /** Takes unknown value and tries our best to convert it to a hex string */
37
- export declare const hexFrom: (
38
- /** Supported types are string, number, bigint, and ArrayBuffer */
39
- value: string | number | bigint | ArrayBufferLike,
40
- /** Configuration of output format and validation */
41
- config?: HexConfig) => Hex;
42
-
43
- /** Convert an ArrayBuffer to a hex string */
44
- export declare const hexFromArrayBuffer: (
45
- /** The buffer to be converted */
46
- buffer: ArrayBufferLike,
47
- /** Configuration of output format and validation */
48
- config?: HexConfig) => Hex;
49
-
50
- /** Convert a bigint to a hex string */
51
- export declare const hexFromBigInt: (
52
- /** The bigint to be converted */
53
- value: bigint,
54
- /** Configuration of output format and validation */
55
- config?: HexConfig) => Hex;
56
-
57
- export declare const hexFromHexString: (value: string, config?: HexConfig) => Hex;
58
-
59
- export declare const hexFromNumber: (value: number, config?: HexConfig) => Hex;
60
-
61
- export declare const hexRegex: RegExp;
62
-
63
- export declare const hexRegexWithPrefix: RegExp;
64
-
65
- export declare function hexToBigInt(hex: Hex): bigint;
66
-
67
- export declare const isAddress: (value: unknown, config?: HexConfig) => value is Address;
68
-
69
- export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is Hash;
70
-
71
- export declare const isHashBitLength: (value: unknown) => value is HashBitLength;
72
-
73
- export declare const isHex: (value: unknown, config?: HexConfig) => value is Hex;
74
-
75
- export declare const isHexZero: (value?: string) => boolean | undefined;
76
-
77
- export declare const nibblesToBits: (value: number) => number;
78
-
79
- export declare const toAddress: (value: string | number | bigint | ArrayBufferLike, config?: HexConfig) => Lowercase<string>;
80
-
81
- /** takes any value and tries our best to convert it to a hex string */
82
- export declare const toHex: (
83
- /** Supported types are string, number, bigint, and ArrayBuffer */
84
- value: string | number | bigint | ArrayBufferLike,
85
- /** Configuration of output format and validation */
86
- config?: HexConfig) => Lowercase<string>;
87
-
88
- export declare const toHexLegacy: (buffer: ArrayBuffer) => string;
89
-
90
- export declare const ZERO_ADDRESS: Address;
91
-
92
- export declare const ZERO_HASH: Hash;
93
-
94
- export { }
1
+ type AssertCallback = (value: unknown, message: string) => string | boolean;
2
+ type AssertConfig = string | AssertCallback | boolean;
3
+
4
+ type Hex = Exclude<Lowercase<string>, 'reserved-hex-value'>;
5
+ /** Configuration of validation and output format */
6
+ interface HexConfig {
7
+ bitLength?: number;
8
+ byteSize?: number;
9
+ prefix?: boolean;
10
+ }
11
+
12
+ declare function asHex(value: unknown): Hex | undefined;
13
+ declare function asHex(value: unknown, assert: AssertConfig): Hex;
14
+
15
+ /** Takes unknown value and tries our best to convert it to a hex string */
16
+ declare const hexFrom: (
17
+ /** Supported types are string, number, bigint, and ArrayBuffer */
18
+ value: string | number | bigint | ArrayBufferLike,
19
+ /** Configuration of output format and validation */
20
+ config?: HexConfig) => Hex;
21
+
22
+ /** Convert an ArrayBuffer to a hex string */
23
+ declare const hexFromArrayBuffer: (
24
+ /** The buffer to be converted */
25
+ buffer: ArrayBufferLike,
26
+ /** Configuration of output format and validation */
27
+ config?: HexConfig) => Hex;
28
+
29
+ /** Convert a bigint to a hex string */
30
+ declare const hexFromBigInt: (
31
+ /** The bigint to be converted */
32
+ value: bigint,
33
+ /** Configuration of output format and validation */
34
+ config?: HexConfig) => Hex;
35
+
36
+ declare const hexFromHexString: (value: string, config?: HexConfig) => Hex;
37
+
38
+ declare const hexFromNumber: (value: number, config?: HexConfig) => Hex;
39
+
40
+ declare const isHex: (value: unknown, config?: HexConfig) => value is Hex;
41
+
42
+ declare const isHexZero: (value?: string) => boolean | undefined;
43
+
44
+ declare const toHexLegacy: (buffer: ArrayBuffer) => string;
45
+
46
+ declare const bitsToNibbles: (value: number) => number;
47
+ declare const nibblesToBits: (value: number) => number;
48
+
49
+ declare const hexRegex: RegExp;
50
+ declare const hexRegexWithPrefix: RegExp;
51
+
52
+ /** takes any value and tries our best to convert it to a hex string */
53
+ declare const toHex: (
54
+ /** Supported types are string, number, bigint, and ArrayBuffer */
55
+ value: string | number | bigint | ArrayBufferLike,
56
+ /** Configuration of output format and validation */
57
+ config?: HexConfig) => Lowercase<string>;
58
+
59
+ type Address = Exclude<Hex, 'reserved-address-value'>;
60
+ declare const ZERO_ADDRESS: Address;
61
+ declare const toAddress: (value: string | number | bigint | ArrayBufferLike, config?: HexConfig) => Lowercase<string>;
62
+ declare const isAddress: (value: unknown, config?: HexConfig) => value is Address;
63
+ declare function asAddress(value: unknown): Address | undefined;
64
+ declare function asAddress(value: unknown, assert: AssertConfig): Address;
65
+
66
+ declare const ZERO_HASH: Hash;
67
+ type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
68
+ declare const HashBitLength: HashBitLength[];
69
+ declare const isHashBitLength: (value: unknown) => value is HashBitLength;
70
+ type Hash = Exclude<Hex, 'reserved-hash-value'>;
71
+ declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is Hash;
72
+ declare function asHash(value: unknown): Hash | undefined;
73
+ declare function asHash(value: unknown, assert: AssertConfig): Hash;
74
+
75
+ declare function hexToBigInt(hex: Hex): bigint;
76
+
77
+ export { HashBitLength, ZERO_ADDRESS, ZERO_HASH, asAddress, asHash, asHex, bitsToNibbles, hexFrom, hexFromArrayBuffer, hexFromBigInt, hexFromHexString, hexFromNumber, hexRegex, hexRegexWithPrefix, hexToBigInt, isAddress, isHash, isHashBitLength, isHex, isHexZero, nibblesToBits, toAddress, toHex, toHexLegacy };
78
+ export type { Address, Hash, Hex, HexConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/hex",
3
- "version": "4.13.3",
3
+ "version": "4.13.5",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "keywords": [
6
6
  "hex",
@@ -39,12 +39,12 @@
39
39
  "packages/**/*"
40
40
  ],
41
41
  "dependencies": {
42
- "@xylabs/typeof": "^4.13.3"
42
+ "@xylabs/typeof": "^4.13.5"
43
43
  },
44
44
  "devDependencies": {
45
- "@xylabs/ts-scripts-yarn3": "^7.0.0-rc.7",
46
- "@xylabs/tsconfig": "^7.0.0-rc.7",
47
- "@xylabs/vitest-extended": "^4.13.3",
45
+ "@xylabs/ts-scripts-yarn3": "^7.0.0-rc.8",
46
+ "@xylabs/tsconfig": "^7.0.0-rc.8",
47
+ "@xylabs/vitest-extended": "^4.13.5",
48
48
  "typescript": "^5.8.3",
49
49
  "vitest": "^3.2.4"
50
50
  },