Add tslint (#151)

This commit is contained in:
Jaco Greeff
2018-06-27 10:15:46 +02:00
committed by GitHub
parent 499a877f15
commit 73477a2809
134 changed files with 989 additions and 884 deletions
+10 -10
View File
@@ -5,16 +5,16 @@
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.
@example
import { hexAddPrefix } from '@polkadot/util';
console.log('With prefix', hexAddPrefix('0a0b12')) // => 0x0a0b12
*/
* @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.
* @example
* import { hexAddPrefix } from '@polkadot/util';
*
* console.log('With prefix', hexAddPrefix('0a0b12')) // => 0x0a0b12
*/
export default function hexAddPrefix (value: string | null | undefined): string {
if (value && hasPrefix(value)) {
return value;
+12 -12
View File
@@ -6,18 +6,18 @@ import hexAddPrefix from './addPrefix';
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`.
@example
import { hexFixLength } from '@polkadot/util';
console.log('fixed', hexFixLength('0x12', 16)) // => 0x12
console.log('fixed', hexFixLength('0x12', 16, true)) // => 0x0012
console.log('fixed', hexFixLength('0x0012', 8)) // => 0x12
*/
* @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`.
* @example
* import { hexFixLength } from '@polkadot/util';
*
* console.log('fixed', hexFixLength('0x12', 16)) // => 0x12
* console.log('fixed', hexFixLength('0x12', 16, true)) // => 0x0012
* console.log('fixed', hexFixLength('0x0012', 8)) // => 0x12
*/
export default function hexFixLength (value: string, bitLength: number = -1, withPadding: boolean = false): string {
const strLength = Math.ceil(bitLength / 4);
const hexLength = strLength + 2;
+5 -5
View File
@@ -5,9 +5,9 @@
import hexFromBn from '../bn/toHex';
/**
@name hexFromBn
@signature hexFromBn (value?: BN): string
@summary Creates a hex value from a BN.js bignumber object.
@alias bn/toHex
*/
* @name hexFromBn
* @signature hexFromBn (value?: BN): string
* @summary Creates a hex value from a BN.js bignumber object.
* @alias bn/toHex
*/
export default hexFromBn;
+5 -5
View File
@@ -5,9 +5,9 @@
import hexFromNumber from '../number/toHex';
/**
@name hexFromNumber
@signature hexFromNumber (value?: number): string
@summary Creates a hex value from a number.
@alias number/toHex
*/
* @name hexFromNumber
* @signature hexFromNumber (value?: number): string
* @summary Creates a hex value from a number.
* @alias number/toHex
*/
export default hexFromNumber;
+10 -10
View File
@@ -5,16 +5,16 @@
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`
@example
import { hexHasPrefix } from '@polkadot/util';
console.log('has prefix', hexHasPrefix('0x1234')); // => true
*/
* @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`
* @example
* import { hexHasPrefix } from '@polkadot/util';
*
* console.log('has prefix', hexHasPrefix('0x1234')); // => true
*/
export default function hexHasPrefix (value: string | null | undefined): boolean {
return !!(value && isHex(value, -1, true) && value.substr(0, 2) === '0x');
}
+2 -2
View File
@@ -13,8 +13,8 @@ import hexToNumber from './toNumber';
import hexToU8a from './toU8a';
/**
@summary Internal utilities to create and test for hex values
*/
* @summary Internal utilities to create and test for hex values
*/
export {
hexAddPrefix,
hexFixLength,
+10 -10
View File
@@ -7,16 +7,16 @@ import hasPrefix from './hasPrefix';
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.
@example
import { hexStripPrefix } from '@polkadot/util';
console.log('stripped', hexStripPrefix('0x1234')); // => 1234
*/
* @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.
* @example
* import { hexStripPrefix } from '@polkadot/util';
*
* console.log('stripped', hexStripPrefix('0x1234')); // => 1234
*/
export default function hexStripPrefix (value: string | null | undefined): string {
if (!value) {
return '';
+10 -10
View File
@@ -13,16 +13,16 @@ function reverse (value: string): string {
}
/**
@name hexToBn
@signature hexToBn (value?: string, isLe: boolean = 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.
@example
import { hexToBn } from '@polkadot/util';
hexToBn('0x123480001f'); // => BN(0x123480001f)
*/
* @name hexToBn
* @signature hexToBn (value?: string, isLe: boolean = 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.
* @example
* import { hexToBn } from '@polkadot/util';
*
* hexToBn('0x123480001f'); // => BN(0x123480001f)
*/
export default function hexToBn (_value?: string, isLe: boolean = false): BN {
if (!_value) {
return new BN(0);
+10 -10
View File
@@ -5,16 +5,16 @@
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`.
@example
import { hexToNumber } from '@polkadot/util';
hexToNumber('0x1234'); // => 0x1234
*/
* @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`.
* @example
* import { hexToNumber } from '@polkadot/util';
*
* hexToNumber('0x1234'); // => 0x1234
*/
export default function hexToNumber (value?: string): number {
if (!value) {
return NaN;
+11 -11
View File
@@ -7,17 +7,17 @@ import isHex from '../is/hex';
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.
@example
import { hexToU8a } from '@polkadot/util';
hexToU8a('0x80001f'); // Uint8Array([0x80, 0x00, 0x1f])
hexToU8a('0x80001f', 32); // Uint8Array([0x00, 0x80, 0x00, 0x1f])
*/
* @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.
* @example
* import { hexToU8a } from '@polkadot/util';
*
* hexToU8a('0x80001f'); // Uint8Array([0x80, 0x00, 0x1f])
* hexToU8a('0x80001f', 32); // Uint8Array([0x00, 0x80, 0x00, 0x1f])
*/
export default function hexToU8a (_value?: string | null, bitLength: number = -1): Uint8Array {
if (!_value) {
return new Uint8Array([]);