All files / src/utility utilityHelpers.noBuffer.ts

100% Statements 10/10
100% Branches 2/2
100% Functions 2/2
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1957x               57x 174x 147x     57x 73x 24x 24x    
import { Utils } from '@bsv/sdk'
 
/**
 * Coerce a value to a hex encoded string if currently a hex encoded string or number[]
 * @param val string or number[]. If string, encoding must be hex. If number[], each value must be 0..255.
 * @returns input val if it is a string; or if number[], converts byte values to hex
 * @publicbody
 */
export function asString(val: string | number[]): string {
  if (typeof val === 'string') return val
  return Utils.toHex(val)
}
 
export function asArray(val: string | number[]): number[] {
  if (Array.isArray(val)) return val
  let a: number[] = Utils.toArray(val, 'hex')
  return a
}