@xylabs/hex 5.0.79 → 5.0.81
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/README.md +566 -57
- package/dist/neutral/index.mjs +1 -1
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +6 -9
- package/src/HexRegEx.ts +0 -10
- package/src/address/AddressTransformZod.ts +0 -26
- package/src/address/AddressValidationZod.ts +0 -12
- package/src/address/address.ts +0 -16
- package/src/address/as.ts +0 -37
- package/src/address/index.ts +0 -6
- package/src/address/is.ts +0 -14
- package/src/address/to.ts +0 -18
- package/src/ethAddress.ts +0 -70
- package/src/hash/as.ts +0 -24
- package/src/hash/hash.ts +0 -25
- package/src/hash/index.ts +0 -4
- package/src/hash/is.ts +0 -6
- package/src/hash/zod.ts +0 -8
- package/src/hex/as.ts +0 -24
- package/src/hex/from/from.ts +0 -31
- package/src/hex/from/fromArrayBuffer.ts +0 -13
- package/src/hex/from/fromBigInt.ts +0 -13
- package/src/hex/from/fromHexString.ts +0 -20
- package/src/hex/from/fromNumber.ts +0 -6
- package/src/hex/from/index.ts +0 -5
- package/src/hex/hex.ts +0 -17
- package/src/hex/index.ts +0 -8
- package/src/hex/is.ts +0 -16
- package/src/hex/isHexZero.ts +0 -7
- package/src/hex/legacy.ts +0 -3
- package/src/hex/nibble.ts +0 -11
- package/src/hex/to.ts +0 -13
- package/src/hexToBigInt.ts +0 -5
- package/src/index.ts +0 -7
- package/src/zod.ts +0 -7
package/src/hex/is.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { HexRegEx, HexRegExWithPrefix } from '../HexRegEx.ts'
|
|
2
|
-
import type { Hex, HexConfig } from './hex.ts'
|
|
3
|
-
import { bitsToNibbles } from './nibble.ts'
|
|
4
|
-
|
|
5
|
-
export const isHex = (value: unknown, config?: HexConfig): value is Hex => {
|
|
6
|
-
// Is it a string?
|
|
7
|
-
if (typeof value !== 'string') return false
|
|
8
|
-
|
|
9
|
-
const valueCharLength = config?.prefix ? value.length - 2 : value.length
|
|
10
|
-
|
|
11
|
-
// If a bitLength specified, does it conform?
|
|
12
|
-
if (config?.bitLength !== undefined && valueCharLength !== bitsToNibbles(config?.bitLength)) return false
|
|
13
|
-
|
|
14
|
-
// Does it only has hex values?
|
|
15
|
-
return config?.prefix ? HexRegExWithPrefix.test(value) : HexRegEx.test(value)
|
|
16
|
-
}
|
package/src/hex/isHexZero.ts
DELETED
package/src/hex/legacy.ts
DELETED
package/src/hex/nibble.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// determine the number of nibbles for a given number of bits
|
|
2
|
-
export const bitsToNibbles = (value: number): number => {
|
|
3
|
-
const nibbles = value >> 2
|
|
4
|
-
if (value !== nibbles << 2) throw new Error('Bits for nibbles must multiple of 4')
|
|
5
|
-
return nibbles
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
// determine the number of nibbles for a given number of bits
|
|
9
|
-
export const nibblesToBits = (value: number): number => {
|
|
10
|
-
return value << 2
|
|
11
|
-
}
|
package/src/hex/to.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { hexFrom } from './from/index.ts'
|
|
2
|
-
import type { HexConfig } from './hex.ts'
|
|
3
|
-
|
|
4
|
-
/** takes any value and tries our best to convert it to a hex string */
|
|
5
|
-
export const toHex = (
|
|
6
|
-
/** Supported types are string, number, bigint, and ArrayBuffer */
|
|
7
|
-
value: string | number | bigint | ArrayBufferLike,
|
|
8
|
-
/** Configuration of output format and validation */
|
|
9
|
-
config: HexConfig = {},
|
|
10
|
-
) => {
|
|
11
|
-
const { prefix = false } = config
|
|
12
|
-
return hexFrom(value, { prefix, ...config })
|
|
13
|
-
}
|
package/src/hexToBigInt.ts
DELETED
package/src/index.ts
DELETED
package/src/zod.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import * as z from 'zod'
|
|
2
|
-
|
|
3
|
-
import { toHex } from './hex/index.ts'
|
|
4
|
-
import { hexToBigInt } from './hexToBigInt.ts'
|
|
5
|
-
|
|
6
|
-
export const BigIntToJsonZod = z.bigint().nonnegative().transform(x => toHex(x))
|
|
7
|
-
export const JsonToBigIntZod = z.string().transform(x => toHex(x)).transform(x => hexToBigInt(x))
|