Skip to content

Instantly share code, notes, and snippets.

@chrisabrams
Created March 26, 2018 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisabrams/3e0306a85e362501f757ed192d2b682d to your computer and use it in GitHub Desktop.
Save chrisabrams/3e0306a85e362501f757ed192d2b682d to your computer and use it in GitHub Desktop.
Basic buffer stuff for Node.js
function convertTo(type, data) {
switch(type) {
case 'hex':
case 'string':
return Buffer.from(data).toString('hex')
case 'buffer':
case 'Uint8Array':
return Buffer.from(data, 'hex')
}
}
module.exports = convertTo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment