Correct u8aConcat with hex inputs (#117)

* Correct u8aConcat with hex inputs

* Add test
This commit is contained in:
Jaco Greeff
2018-04-17 13:45:56 +02:00
committed by GitHub
parent ecff342416
commit 6da140a6d3
4 changed files with 19 additions and 6 deletions
+1 -1
View File
@@ -29,7 +29,7 @@
"test": "echo \"Tests only available from root wrapper\""
},
"devDependencies": {
"@polkadot/api-jsonrpc": "^0.8.11"
"@polkadot/api-jsonrpc": "^0.8.13"
},
"dependencies": {
"babel-runtime": "^6.26.0",
+3 -2
View File
@@ -19,13 +19,14 @@ const u8aToU8a = require('./toU8a');
new Uint8Array([4, 5, 6])
); // [1, 2, 3, 4, 5, 6]
*/
module.exports = function u8aConcat (...list: Array<Uint8Array | string>): Uint8Array {
module.exports = function u8aConcat (..._list: Array<Uint8Array | string>): Uint8Array {
const list: Array<Uint8Array> = _list.map(u8aToU8a);
const length = list.reduce((total, item) => total + item.length, 0);
const result = new Uint8Array(length);
let offset = 0;
return list.reduce((result, item) => {
result.set(u8aToU8a(item), offset);
result.set(item, offset);
offset += item.length;
return result;
+12
View File
@@ -16,4 +16,16 @@ describe('u8aConcat', () => {
new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9])
);
});
it('concatenates arrays & hex values', () => {
expect(
u8aConcat(
new Uint8Array([1, 2, 3, 4]),
'0x0506',
'0x070809'
)
).toEqual(
new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9])
);
});
});
+3 -3
View File
@@ -79,9 +79,9 @@
lodash "^4.2.0"
to-fast-properties "^2.0.0"
"@polkadot/api-jsonrpc@^0.8.11":
version "0.8.11"
resolved "https://registry.yarnpkg.com/@polkadot/api-jsonrpc/-/api-jsonrpc-0.8.11.tgz#9ff8dc38f026bac0bb8274836f4f68ba93aa090e"
"@polkadot/api-jsonrpc@^0.8.13":
version "0.8.13"
resolved "https://registry.yarnpkg.com/@polkadot/api-jsonrpc/-/api-jsonrpc-0.8.13.tgz#60a0241204cef405936b21e009970c5a7295d909"
dependencies:
babel-runtime "^6.26.0"