Please see https://github.com/ianoxley/node-encdec.
(This repository is no longer actively maintained).
A small JavaScript library for base-xx encoding / decoding
License: MIT License
Please see https://github.com/ianoxley/node-encdec.
(This repository is no longer actively maintained).
Code that exhibits the bug:
var base24 = encdec('BCDFGHJKLMNPQRSTVWXZ1345');
base24.encode( 1 )
// Correctly encodes 1 to 'C'
// caches as {1 : 'C'}
base24.decode( '1' );
// Should decode to 20, but it returns 'C' due to cache
/* If done in reverse, {1 : 20} would have been cached and
base24.encode( 1 ) would have incorrectly returned 20
*/
If 0-9 do not map to themselves, they will be incorrectly cached.
Basically, I'm trying to work with zeroes, but it returns an empty string instead of the correct letter.
var base24 = encdec('BCDFGHJKLMNPQRSTVWXZ1345');
console.log( base24.encode(0) ); // Should return 'B', but returns ''
I had a look, and I think this occurs because encdec
checks num
as a boolean here, treating 0
as false
:
if (num) {
encode = alphabet[num] + encode;
}
Possible fix:
if (num>=0) {
encode = alphabet[num] + encode;
}
It's possible that this check isn't even necessary.
Hey Ian,
I noticed there wasn't a license associated with this project. Would you be willing to release it under a BSD style license so I can use it in one of my projects?
Jud
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.