I am trying to encode/decode a string with base64. Does coffeescript have any inbuilt support for this ? I found this library: https://github.com/carlcalderon/Base64.coffee .
Is there a better way to do it in Coffeescript ?
I am trying to encode/decode a string with base64. Does coffeescript have any inbuilt support for this ? I found this library: https://github.com/carlcalderon/Base64.coffee .
Is there a better way to do it in Coffeescript ?
You don't need to use libraries written in CoffeeScript just because you're using CoffeeScript.
CoffeeScript compiles to JavaScript. Therefore, any JavaScript library can be used!
If you are using node, the Buffer package can help you. Please refer to this discussion: How to do Base64 encoding in node.js? An example:
> console.log(new Buffer("Hello World").toString('base64'));
SGVsbG8gV29ybGQ=
> console.log(new Buffer("SGVsbG8gV29ybGQ=", 'base64').toString('ascii'))
Hello World
If you are on the browser, though, you can use any base64 library. This one looks relatively alive and well: https://github.com/dankogai/js-base64
<script src="base64.js"></script>
<script>
Base64.encode('dankogai'); // ZGFua29nYWk=
</script>