Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

miguelmota/to-hex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

to-hex

Convert values to hex string

License NPM version

Install

npm install to-hex

Getting started

const toHex = require('to-hex')
const BN = require('bn.js')

console.log(toHex('abc')) // '616263'
console.log(toHex(Buffer.from('abc'))) // '616263'
console.log(toHex('abc', { addPrefix: true })) // '0x616263'
console.log(toHex(256)) // '100'
console.log(toHex('256')) // '100'
console.log(toHex(256, { evenLength: true })) // '0100'
console.log(toHex(new BN(256))) // '100'
console.log(toHex('0x1', { size: 8 })) // '00000001'
console.log(toHex(null, { addPrefix: true, evenLength: true, default: '0' })) // '0x00'

// treat decimal strings as regular strings and not numbers
console.log(toHex('256', { autoDetectString:false })) // '323536'

Test

npm test

License

MIT