mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-04-22 06:47:57 +00:00
21 lines
542 B
JavaScript
21 lines
542 B
JavaScript
import { u8aConcatStrict } from '../u8a/index.js';
|
|
import { compactToU8a } from './toU8a.js';
|
|
/**
|
|
* @name compactAddLength
|
|
* @description Adds a length prefix to the input value
|
|
* @example
|
|
* <BR>
|
|
*
|
|
* ```javascript
|
|
* import { compactAddLength } from '@pezkuwi/util';
|
|
*
|
|
* console.log(compactAddLength(new Uint8Array([0xde, 0xad, 0xbe, 0xef]))); // Uint8Array([4 << 2, 0xde, 0xad, 0xbe, 0xef])
|
|
* ```
|
|
*/
|
|
export function compactAddLength(input) {
|
|
return u8aConcatStrict([
|
|
compactToU8a(input.length),
|
|
input
|
|
]);
|
|
}
|