cafe-utility 32.2.0 → 33.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/index.d.ts +3 -1
- package/index.js +3 -2
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -109,8 +109,10 @@ declare function asHexString(
|
|
|
109
109
|
options?: {
|
|
110
110
|
name?: string
|
|
111
111
|
byteLength?: number
|
|
112
|
+
uneven?: boolean
|
|
113
|
+
strictPrefix?: boolean
|
|
112
114
|
}
|
|
113
|
-
): string
|
|
115
|
+
): `0x${string}`
|
|
114
116
|
declare function asSafeString(
|
|
115
117
|
string: any,
|
|
116
118
|
options?: {
|
package/index.js
CHANGED
|
@@ -373,10 +373,11 @@ function asString(n, e) {
|
|
|
373
373
|
}
|
|
374
374
|
function asHexString(n, e) {
|
|
375
375
|
if (!isHexString(n)) throw new TypeError(`Expected hex string${e?.name ? ` for ${e.name}` : ''}, got: ` + n)
|
|
376
|
+
if (e?.strictPrefix && !n.startsWith('0x')) throw new TypeError(`Expected hex string with 0x prefix${e?.name ? ` for ${e.name}` : ''}, got: ` + n)
|
|
376
377
|
const t = n.replace(/^0x/, '')
|
|
377
|
-
if (t.length % 2 !== 0) throw RangeError(`Expected even number of hex digits${e?.name ? ` for ${e.name}` : ''}; got: ` + n)
|
|
378
|
+
if (t.length % 2 !== 0 && !e?.uneven) throw RangeError(`Expected even number of hex digits${e?.name ? ` for ${e.name}` : ''}; got: ` + n)
|
|
378
379
|
if (e && e.byteLength && t.length !== e.byteLength * 2) throw RangeError(`Expected hex string${e?.name ? ` for ${e.name}` : ''} of byte length ${e.byteLength}; got: ` + t)
|
|
379
|
-
return t
|
|
380
|
+
return `0x${t}`
|
|
380
381
|
}
|
|
381
382
|
function asSafeString(n, e) {
|
|
382
383
|
if (
|