File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change
1
+ import { describe , it } from 'mocha' ;
2
+ import { expect } from 'chai' ;
3
+
4
+ import {
5
+ base64 ,
6
+ unbase64
7
+ } from '../base64' ;
8
+
9
+ var exampleUtf8 = 'Some examples: ❤😀' ;
10
+ var exampleBase64 = 'U29tZSBleGFtcGxlczog4p2k8J+YgA==' ;
11
+
12
+ describe ( 'base64 conversion' , ( ) => {
13
+ it ( 'converts from utf-8 to base64' , ( ) => {
14
+ return expect ( base64 ( exampleUtf8 ) ) . to . equal ( exampleBase64 ) ;
15
+ } ) ;
16
+
17
+ it ( 'converts from base64 to utf-8' , ( ) => {
18
+ return expect ( unbase64 ( exampleBase64 ) ) . to . equal ( exampleUtf8 ) ;
19
+ } ) ;
20
+ } ) ;
Original file line number Diff line number Diff line change 11
11
export type Base64String = string ;
12
12
13
13
export function base64 ( i : string ) : Base64String {
14
- return ( ( new Buffer ( i , 'ascii ' ) ) . toString ( 'base64' ) ) ;
14
+ return ( ( new Buffer ( i , 'utf8 ' ) ) . toString ( 'base64' ) ) ;
15
15
}
16
16
17
17
export function unbase64 ( i : Base64String ) : string {
18
- return ( ( new Buffer ( i , 'base64' ) ) . toString ( 'ascii ' ) ) ;
18
+ return ( ( new Buffer ( i , 'base64' ) ) . toString ( 'utf8 ' ) ) ;
19
19
}
You can’t perform that action at this time.
0 commit comments