37 lines
815 B
TypeScript
37 lines
815 B
TypeScript
// Copyright 2017-2021 @polkadot/util authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import { u8aToU8a } from './toU8a';
|
|
|
|
function equals (a: Uint8Array, b: Uint8Array): boolean {
|
|
if (a.length !== b.length) {
|
|
return false;
|
|
}
|
|
|
|
for (let i = 0; i < a.length; i++) {
|
|
if (a[i] !== b[i]) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @name u8aEq
|
|
* @summary Compares two Uint8Arrays.
|
|
* @description
|
|
* For `UInt8Array` (or hex string) input values true if there is a match.
|
|
* @example
|
|
* <BR>
|
|
*
|
|
* ```javascript
|
|
* import { { u8aEq } from '@polkadot/util';
|
|
*
|
|
* u8aEq(new Uint8Array([0x68, 0x65]), new Uint8Array([0x68, 0x65])); // true
|
|
* ```
|
|
*/
|
|
export function u8aEq (a: Uint8Array | string, b: Uint8Array | string): boolean {
|
|
return equals(u8aToU8a(a), u8aToU8a(b));
|
|
}
|