base32hex-js
v1.0.2
Published
A simple base32hex encode & decode library.
Downloads
3,950
Maintainers
Readme
Base32Hex-JS
A simple base32hex encode & decode library.
Sample Code
const Base32Hex = require(".")
random = () => Math.floor(Math.random() * 1000) + 1
dataset = []
for (let i = 0; i < 100; i++) dataset.push(String(random()))
console.log("Raw dataset\n", dataset)
//Base32Hex.encode(string, padding = true)
base32hexEncoded = dataset.map(d => Base32Hex.encode(String(d), false))
// Default is ASC order
base32hexEncoded = Base32Hex.sort(base32hexEncoded, false)
dataset.sort((a, b) => b - a)
console.log("Sorted dataset\n", dataset)
console.log("Encoded\n", base32hexEncoded)
base32hexDecoded = base32hexEncoded.map(e => Base32Hex.decode(e))
console.log("Decoded & sorted dataset\n", base32hexDecoded)
Output
Raw dataset
[
'47', '186', '255', '807', '409', '579', '932', '497',
'592', '403', '991', '632', '574', '889', '322', '683',
'303', '873', '2', '534', '306', '636', '202', '126',
'556', '303', '900', '638', '679', '551', '176', '925',
'217', '59', '257', '622', '836', '174', '598', '332',
'460', '178', '484', '749', '673', '104', '282', '496',
'129', '684', '886', '98', '90', '904', '580', '768',
'222', '653', '509', '465', '961', '359', '730', '4',
'696', '717', '551', '74', '451', '488', '540', '619',
'91', '745', '450', '299', '906', '631', '362', '355',
'343', '855', '228', '97', '50', '914', '850', '739',
'577', '810', '445', '214', '883', '409', '663', '298',
'494', '622', '564', '257'
]
Sorted dataset
[
'991', '961', '932', '925', '914', '906', '904', '900',
'889', '886', '883', '873', '855', '850', '836', '810',
'807', '768', '749', '745', '739', '730', '717', '696',
'684', '683', '679', '673', '663', '653', '638', '636',
'632', '631', '622', '622', '619', '598', '592', '580',
'579', '577', '574', '564', '556', '551', '551', '540',
'534', '509', '497', '496', '494', '488', '484', '465',
'460', '451', '450', '445', '409', '409', '403', '362',
'359', '355', '343', '332', '322', '306', '303', '303',
'299', '298', '282', '257', '257', '255', '228', '222',
'217', '214', '202', '186', '178', '176', '174', '129',
'126', '104', '98', '97', '91', '90', '74', '59',
'50', '47', '4', '2'
]
Encoded
[
'74SJ2', '74R32', '74PJ4', '74P3A', '74OJ8', '74O3C', '74O38',
'74O30', '70S3I', '70S3C', '70S36', '70RJ6', '70QJA', '70QJ0',
'70PJC', '70OJ0', '70O3E', '6SR3G', '6SQ3I', '6SQ3A', '6SPJI',
'6SPJ0', '6SOJE', '6OSJC', '6OS38', '6OS36', '6ORJI', '6ORJ6',
'6OR36', '6OQJ6', '6OPJG', '6OPJC', '6OPJ4', '6OPJ2', '6OP34',
'6OP34', '6OOJI', '6KSJG', '6KSJ4', '6KS30', '6KRJI', '6KRJE',
'6KRJ8', '6KR38', '6KQJC', '6KQJ2', '6KQJ2', '6KQ30', '6KPJ8',
'6KO3I', '6GSJE', '6GSJC', '6GSJ8', '6GS3G', '6GS38', '6GR3A',
'6GR30', '6GQJ2', '6GQJ0', '6GQ3A', '6GO3I', '6GO3I', '6GO36',
'6CR34', '6CQJI', '6CQJA', '6CQ36', '6CPJ4', '6CP34', '6CO3C',
'6CO36', '6CO36', '68SJI', '68SJG', '68S34', '68QJE', '68QJE',
'68QJA', '68P3G', '68P34', '68OJE', '68OJ8', '68O34', '64S3C',
'64RJG', '64RJC', '64RJ8', '64P3I', '64P3C', '64O38', '74S0',
'74RG', '74OG', '74O0', '6SQ0', '6KSG', '6KO0', '6GRG',
'6G', '68'
]
Decoded & sorted dataset
[
'991', '961', '932', '925', '914', '906', '904', '900',
'889', '886', '883', '873', '855', '850', '836', '810',
'807', '768', '749', '745', '739', '730', '717', '696',
'684', '683', '679', '673', '663', '653', '638', '636',
'632', '631', '622', '622', '619', '598', '592', '580',
'579', '577', '574', '564', '556', '551', '551', '540',
'534', '509', '497', '496', '494', '488', '484', '465',
'460', '451', '450', '445', '409', '409', '403', '362',
'359', '355', '343', '332', '322', '306', '303', '303',
'299', '298', '282', '257', '257', '255', '228', '222',
'217', '214', '202', '186', '178', '176', '174', '129',
'126', '104', '98', '97', '91', '90', '74', '59',
'50', '47', '4', '2'
]