Move in ui-qr as react-qr (from apps) (#164)

This commit is contained in:
Jaco Greeff
2019-07-29 10:55:02 +02:00
committed by GitHub
parent 1de68ac029
commit 9664b72253
16 changed files with 778 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
// Copyright 2017-2019 @polkadot/react-qr authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
export function encodeNumber (value: number): Uint8Array {
return new Uint8Array([value >> 8, value & 256]);
}
export function encodeString (value: string): Uint8Array {
const u8a = new Uint8Array(value.length);
for (let i = 0; i < value.length; i++) {
u8a[i] = value.charCodeAt(i);
}
return u8a;
}
export function decodeString (value: Uint8Array): string {
return value.reduce((str, code): string => {
return str + String.fromCharCode(code);
}, '');
}