Add atob() and btoa() (#776)

This commit is contained in:
Kevin (Kun) "Kassimo" Qian 2018-09-20 15:53:29 -07:00 committed by Ryan Dahl
parent 52d415537b
commit 4d16d54ff8
4 changed files with 74 additions and 0 deletions

26
js/text_encoding_test.ts Normal file
View file

@ -0,0 +1,26 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
import { test, assert, assertEqual } from "./test_util.ts";
test(function atobSuccess() {
const text = "hello world";
const encoded = btoa(text);
assertEqual(encoded, "aGVsbG8gd29ybGQ=");
});
test(function btoaSuccess() {
const encoded = "aGVsbG8gd29ybGQ=";
const decoded = atob(encoded);
assertEqual(decoded, "hello world");
});
test(function btoaFailed() {
const text = "你好";
let err;
try {
btoa(text);
} catch (e) {
err = e;
}
assert(!!err);
assertEqual(err.name, "InvalidInput");
});