Update u8aConcat call signature (#105)

* Change u8aConcat calling format

* Simplify utilkeyring test harness
This commit is contained in:
Jaco Greeff
2018-03-08 16:21:37 +01:00
committed by GitHub
parent 83aa2784f7
commit 2279c9550e
12 changed files with 48 additions and 38 deletions
+6 -5
View File
@@ -5,20 +5,21 @@
/**
@name u8aConcat
@signature u8aConcat (values: Array<Uint8Array>): Uint8Array
@signature u8aConcat (...values: Array<Uint8Array>): Uint8Array
@summary Creates a concatenated Uint8Array from the inputs.
@description
Concatenates the input arrays into a single `UInt8Array`.
@example
import { u8aConcat } from '@polkadot/util';
u8aConcat([
u8aConcat(
new Uint8Array([1, 2, 3]),
new Uint8Array([4, 5, 6])
]); // [1, 2, 3, 4, 5, 6]
); // [1, 2, 3, 4, 5, 6]
*/
module.exports = function u8aConcat (list: Array<Uint8Array>): Uint8Array {
module.exports = function u8aConcat (...list: Array<Uint8Array>): Uint8Array {
const length = list.reduce((total, item) => total + item.length, 0);
const result = new Uint8Array(length);
let offset = 0;
return list.reduce((result, item) => {
@@ -26,5 +27,5 @@ module.exports = function u8aConcat (list: Array<Uint8Array>): Uint8Array {
offset += item.length;
return result;
}, new Uint8Array(length));
}, result);
};
+2 -2
View File
@@ -7,11 +7,11 @@ const { u8aConcat } = require('./index');
describe('u8aConcat', () => {
it('concatenates arrays', () => {
expect(
u8aConcat([
u8aConcat(
new Uint8Array([1, 2, 3, 4]),
new Uint8Array([5, 6]),
new Uint8Array([7, 8, 9])
])
)
).toEqual(
new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9])
);