Use u8a.toString as u8aToString (#93)

* Use u8a.toString as u8aToString

* Fix lint
This commit is contained in:
Jaco Greeff
2018-02-20 14:37:28 +01:00
committed by GitHub
parent 31d396d8eb
commit ff5396e2ec
2 changed files with 4 additions and 10 deletions
+2 -8
View File
@@ -12,18 +12,12 @@
@example
import { u8aToString } from '@polkadot/util';
u8aToString(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f])); // hello
u8aToString(new Uint8Array([21,23,45,67])); // 21,23,45,67
*/
module.exports = function u8aToString (value?: Uint8Array): string {
if (!value || !value.length) {
return '';
}
return value
.reduce((result, ch) => {
result.push(String.fromCharCode(ch));
return result;
}, [])
.join('');
return value.toString();
};
+2 -2
View File
@@ -20,8 +20,8 @@ describe('u8aToString', () => {
it('decodes the buffer correctly', () => {
expect(
u8aToString(
new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f])
new Uint8Array([21, 23, 45, 67])
)
).toEqual('hello');
).toEqual('21,23,45,67');
});
});