项目作者: miguelmota

项目描述 :
Convert values to hex string
高级语言: JavaScript
项目地址: git://github.com/miguelmota/to-hex.git
创建时间: 2019-06-23T19:59:02Z
项目社区:https://github.com/miguelmota/to-hex

开源协议:MIT License

下载


to-hex

Convert values to hex string

License
NPM version

Install

  1. npm install to-hex

Getting started

  1. const toHex = require('to-hex')
  2. const BN = require('bn.js')
  3. console.log(toHex('abc')) // '616263'
  4. console.log(toHex(Buffer.from('abc'))) // '616263'
  5. console.log(toHex('abc', { addPrefix: true })) // '0x616263'
  6. console.log(toHex(256)) // '100'
  7. console.log(toHex('256')) // '100'
  8. console.log(toHex(256, { evenLength: true })) // '0100'
  9. console.log(toHex(new BN(256))) // '100'
  10. console.log(toHex('0x1', { size: 8 })) // '00000001'
  11. console.log(toHex(null, { addPrefix: true, evenLength: true, default: '0' })) // '0x00'
  12. // treat decimal strings as regular strings and not numbers
  13. console.log(toHex('256', { autoDetectString:false })) // '323536'

Test

  1. npm test

License

MIT