Small u8aToU8a optimizations (#1498)
* Small u8aToU8a optimizations * Slight order adjustments * Adjust
This commit is contained in:
@@ -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 => {
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user