@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/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
- }
@@ -1,7 +0,0 @@
1
- import { isString } from '@xylabs/typeof'
2
-
3
- import { hexFromHexString } from './from/index.ts'
4
-
5
- export const isHexZero = (value?: string) => {
6
- return isString(value) ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined
7
- }
package/src/hex/legacy.ts DELETED
@@ -1,3 +0,0 @@
1
- export const toHexLegacy = (buffer: ArrayBuffer) => {
2
- return [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, '0')).join('')
3
- }
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
- }
@@ -1,5 +0,0 @@
1
- import { type Hex, hexFromHexString } from './hex/index.ts'
2
-
3
- export function hexToBigInt(hex: Hex): bigint {
4
- return BigInt(hexFromHexString(hex, { prefix: true }))
5
- }
package/src/index.ts DELETED
@@ -1,7 +0,0 @@
1
- export * from './address/index.ts'
2
- export * from './ethAddress.ts'
3
- export * from './hash/index.ts'
4
- export * from './hex/index.ts'
5
- export * from './HexRegEx.ts'
6
- export * from './hexToBigInt.ts'
7
- export * from './zod.ts'
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))