Copy To functionality for notebooks (#141)

* Add Copy To functionality for notebooks

* Fix formatting

* Fix linting errors

* Fixes

* Fix build failure

* Rebase and address feedback

* Increase test coverage
This commit is contained in:
Tanuj Mittal
2020-08-11 09:27:57 -07:00
committed by GitHub
parent 7a3e54d43e
commit 5886db81e9
18 changed files with 530 additions and 36 deletions

View File

@@ -0,0 +1,11 @@
import * as Base64Utils from "./Base64Utils";
describe("Base64Utils", () => {
describe("utf8ToB64", () => {
it("should convert utf8 to base64", () => {
expect(Base64Utils.utf8ToB64("abcd")).toEqual(btoa("abcd"));
expect(Base64Utils.utf8ToB64("小飼弾")).toEqual("5bCP6aO85by+");
expect(Base64Utils.utf8ToB64("à mon hôpital préféré")).toEqual("w6AgbW9uIGjDtHBpdGFsIHByw6lmw6lyw6k=");
});
});
});

7
src/Utils/Base64Utils.ts Normal file
View File

@@ -0,0 +1,7 @@
export const utf8ToB64 = (utf8Str: string): string => {
return btoa(
encodeURIComponent(utf8Str).replace(/%([0-9A-F]{2})/g, (_, args) => {
return String.fromCharCode(parseInt(args, 16));
})
);
};