Small u8aToU8a optimizations (#1498)

* Small u8aToU8a optimizations

* Slight order adjustments

* Adjust
This commit is contained in:
Jaco
2022-05-24 16:42:58 +03:00
committed by GitHub
parent bce5553a4b
commit a4256de444
10 changed files with 55 additions and 22 deletions
+4 -1
View File
@@ -6,10 +6,13 @@ import { stringToU8a } from '..';
const RUSS_HELLO = new Uint8Array([208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130, 44, 32, 208, 188, 208, 184, 209, 128, 33]);
describe('stringToU8a', (): void => {
it('decodes to an empty string for undefined', (): void => {
it('decodes to an empty string for undefined/null', (): void => {
expect(
stringToU8a()
).toEqual(new Uint8Array());
expect(
stringToU8a(null)
).toEqual(new Uint8Array());
});
it('encodes the string correctly', (): void => {
+1 -2
View File
@@ -21,8 +21,7 @@ const encoder = new TextEncoder();
* stringToU8a('hello'); // [0x68, 0x65, 0x6c, 0x6c, 0x6f]
* ```
*/
// eslint-disable-next-line @typescript-eslint/ban-types
export function stringToU8a (value?: AnyString): Uint8Array {
export function stringToU8a (value?: AnyString | null): Uint8Array {
return value
? encoder.encode(value.toString())
: new Uint8Array();