Converts tests to TypeScript (#300)

This commit is contained in:
Jaco Greeff
2019-02-14 10:48:08 +01:00
committed by GitHub
parent 2a14a8b553
commit 1e6eb2c283
158 changed files with 89 additions and 183 deletions
+1 -2
View File
@@ -6,7 +6,6 @@ import hasPrefix from './hasPrefix';
/**
* @name hexAddPrefix
* @signature hexAddPrefix (value: ?string): string
* @summary Adds the `0x` prefix to string values.
* @description
* Returns a `0x` prefixed string from the input value. If the input is already prefixed, it is returned unchanged.
@@ -19,7 +18,7 @@ import hasPrefix from './hasPrefix';
* console.log('With prefix', hexAddPrefix('0a0b12')); // => 0x0a0b12
* ```
*/
export default function hexAddPrefix (value: string | null | undefined): string {
export default function hexAddPrefix (value?: string | null): string {
if (value && hasPrefix(value)) {
return value;
}
-1
View File
@@ -7,7 +7,6 @@ import hexStripPrefix from './stripPrefix';
/**
* @name hexFixLength
* @signature hexFixLength (value: string, bitLength: number = -1, withPadding: boolean = false): string
* @summary Shifts a hex string to a specific bitLength
* @description
* Returns a `0x` prefixed string with the specified number of bits contained in the return value. (If bitLength is -1, length checking is not done). Values with more bits are trimmed to the specified length. Input values with less bits are returned as-is by default. When `withPadding` is set, shorter values are padded with `0`.
@@ -25,7 +25,7 @@ describe('hexHasPrefix', () => {
it('returns false when non-string value supplied', () => {
expect(
hexHasPrefix(false)
hexHasPrefix(false as any)
).toEqual(false);
});
});
+1 -2
View File
@@ -6,7 +6,6 @@ import isHex from '../is/hex';
/**
* @name hexHasPrefix
* @signature hexHasPrefix (value: ?string): boolean
* @summary Tests for the existence of a `0x` prefix.
* @description
* Checks for a valid hex input value and if the start matched `0x`
@@ -19,6 +18,6 @@ import isHex from '../is/hex';
* console.log('has prefix', hexHasPrefix('0x1234')); // => true
* ```
*/
export default function hexHasPrefix (value: string | null | undefined): boolean {
export default function hexHasPrefix (value?: string | null): boolean {
return !!(value && isHex(value, -1, true) && value.substr(0, 2) === '0x');
}
+1 -2
View File
@@ -8,7 +8,6 @@ const UNPREFIX_HEX_REGEX = /^[a-fA-F0-9]+$/;
/**
* @name hexStripPrefix
* @signature hexStripPrefix (value: ?string): string
* @summary Strips any leading `0x` prefix.
* @description
* Tests for the existence of a `0x` prefix, and returns the value without the prefix. Un-prefixed values are returned as-is.
@@ -21,7 +20,7 @@ const UNPREFIX_HEX_REGEX = /^[a-fA-F0-9]+$/;
* console.log('stripped', hexStripPrefix('0x1234')); // => 1234
* ```
*/
export default function hexStripPrefix (value: string | null | undefined): string {
export default function hexStripPrefix (value?: string | null): string {
if (!value) {
return '';
}
-1
View File
@@ -16,7 +16,6 @@ function reverse (value: string): string {
/**
* @name hexToBn
* @signature hexToBn (value?: string, _options: ToBnOptions | boolean = { isLe: false, isNegative: false }): BN
* @summary Creates a BN.js bignumber object from a hex string.
* @description
* `null` inputs returns a `BN(0)` result. Hex input values return the actual value converted to a BN. Anything that is not a hex string (including the `0x` prefix) throws an error.
+1 -2
View File
@@ -6,7 +6,6 @@ import hexToBn from './toBn';
/**
* @name hexToNumber
* @signature hexToNumber (value?: string): number
* @summary Creates a Number value from a Buffer object.
* @description
* `null` inputs returns an NaN result, `hex` values return the actual value as a `Number`.
@@ -19,7 +18,7 @@ import hexToBn from './toBn';
* hexToNumber('0x1234'); // => 0x1234
* ```
*/
export default function hexToNumber (value?: string): number {
export default function hexToNumber (value?: string | null): number {
if (!value) {
return NaN;
}
-1
View File
@@ -8,7 +8,6 @@ import hexStripPrefix from './stripPrefix';
/**
* @name hexToU8a
* @signature hexToU8a (value?: string, bitLength: number = -1): Uint8Array
* @summary Creates a Buffer object from a hex string.
* @description
* `null` inputs returns an empty `Uint8Array` result. Hex input values return the actual bytes value converted to a Uint8Array. Anything that is not a hex string (including the `0x` prefix) throws an error.