From 2023e4266b669f7abf1731f1407d77d353c22e1c Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Tue, 1 Jan 2013 12:34:53 -0800 Subject: [PATCH] Add a utility to hexify a string. --- bin/hexify.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 bin/hexify.js diff --git a/bin/hexify.js b/bin/hexify.js new file mode 100755 index 0000000000..231ee8b684 --- /dev/null +++ b/bin/hexify.js @@ -0,0 +1,22 @@ +#!/usr/bin/node +// +// Returns hex of string. +// + +var stringToHex = function (s) { + return Array.prototype.map.call(s, function (c) { + var b = c.charCodeAt(0); + + return b < 16 ? "0" + b.toString(16) : b.toString(16); + }).join(""); +}; + +if (process.argv.length != 3) { + process.stderr.write("Usage: " + process.argv[1] + " string\n\nReturns hex of lowercasing string.\n"); + +} else { + + process.stdout.write(stringToHex(process.argv[2].toLowerCase()) + "\n"); +} + +// vim:sw=2:sts=2:ts=8:et