[CI Skip] 0.32.4

This commit is contained in:
Travis CI
2018-10-19 15:38:45 +00:00
parent 1fb1f9d743
commit d7b83e3d91
243 changed files with 17626 additions and 40 deletions
+39
View File
@@ -0,0 +1,39 @@
# Functions
<a id="arrayfilter"></a>
## arrayFilter
▸ **arrayFilter**(array: *`Array`<`any`>*, allowNulls?: *`boolean`*): `Array`<`any`>
*Defined in [array/filter.ts:24](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/array/filter.ts#L24)*
*__name__*: arrayFilter
*__signature__*: arrayFilter (array: Array, allowNulls: boolean = true): Array
*__summary__*: Filters undefined and (optionally) null values from an array
*__description__*: Returns a new array with all `undefined` values removed. Optionally, when `allowNulls = false`, it removes the `null` values as well
*__example__*:
```javascript
import { arrayFilter } from '@polkadot/util';
arrayFilter([0, void 0, true, null, false, '']); // [0, true, null, false, '']
arrayFilter([0, void 0, true, null, false, ''], false); // [0, true, false, '']
```
**Parameters:**
| Param | Type | Default value |
| ------ | ------ | ------ |
| array | `Array`<`any`> | - |
| `Default value` allowNulls | `boolean` | true |
**Returns:** `Array`<`any`>
___
+2
View File
@@ -0,0 +1,2 @@
+42
View File
@@ -0,0 +1,42 @@
# Functions
<a id="assert"></a>
## assert
▸ **assert**(test: *`any`*, message: * `string` &#124; `MessageFn`*, code?: *`number`*, data?: *`any`*): `boolean`
*Defined in [assert.ts:27](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/assert.ts#L27)*
*__name__*: assert
*__signature__*: assert (test: any, message: string | () => string, code: number = ExtError.CODES.ASSERT, data: any): void
*__summary__*: Checks for a valid test, if not ExtError is thrown.
*__description__*: Checks that `test` is a truthy value. If value is falsy (`null`, `undefined`, `false`, ...), it throws an ExtError with the supplied `message` and an optional `code` and `data`. When `test` passes, `true` is returned.
*__example__*:
```javascript
const { assert } from '@polkadot/util';
assert(true, 'True should be true'); // true returned
assert(false, 'False should not be true'); // ExtError thrown
assert(false, () => 'message'); // ExtError with 'message'
```
**Parameters:**
| Param | Type | Default value |
| ------ | ------ | ------ |
| test | `any` | - |
| message | `string` &#124; `MessageFn`| - |
| `Default value` code | `number` | ExtError.CODES.ASSERT |
| `Optional` data | `any` | - |
**Returns:** `boolean`
___
+2
View File
@@ -0,0 +1,2 @@
+2
View File
@@ -0,0 +1,2 @@
+39
View File
@@ -0,0 +1,39 @@
# Functions
<a id="bntobn"></a>
## bnToBn
▸ **bnToBn**(value?: * `BN` &#124; `number`*): `BN`
*Defined in [bn/toBn.ts:24](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/bn/toBn.ts#L24)*
*__name__*: bnToBn
*__signature__*: bnToBn (value?: BN : number): BN
*__summary__*: Creates a BN value from a BN.js bignumber or number input.
*__description__*: `null` inputs returns a `0x0` result, BN values returns the value, numnbers returns a BN representation.
*__example__*:
```javascript
import BN from 'bn.js';
import { bnToBn } from '@polkadot/util';
bnToBn(0x1234); // => BN(0x1234)
bnToBn(new BN(0x1234)); // => BN(0x1234)
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| `Optional` value | `BN` &#124; `number`|
**Returns:** `BN`
___
+39
View File
@@ -0,0 +1,39 @@
# Functions
<a id="bntohex"></a>
## bnToHex
▸ **bnToHex**(value?: * `BN` &#124; `number`*, bitLength?: *`number`*): `string`
*Defined in [bn/toHex.ts:28](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/bn/toHex.ts#L28)*
*__name__*: bnToHex
*__signature__*: bnToHex (value?: BN, bitLength: number = -1): string
*__summary__*: Creates a hex value from a BN.js bignumber object.
*__description__*: `null` inputs returns a `0x` result, BN values return the actual value as a `0x` prefixed hex value. Anything that is not a BN object throws an error. With `bitLength` set, it fixes the number to the specified length.
*__example__*:
```javascript
import BN from 'bn.js';
import { bnToHex } from '@polkadot/util';
bnToHex(new BN(0x123456)); // => '0x123456'
```
**Parameters:**
| Param | Type | Default value |
| ------ | ------ | ------ |
| `Optional` value | `BN` &#124; `number`| - |
| `Default value` bitLength | `number` | -1 |
**Returns:** `string`
___
+39
View File
@@ -0,0 +1,39 @@
# Functions
<a id="bntou8a"></a>
## bnToU8a
▸ **bnToU8a**(value: * `BN` &#124; `number`*, bitLength: *`number`*, isLe: *`boolean`*): `Uint8Array`
*Defined in [bn/toU8a.ts:26](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/bn/toU8a.ts#L26)*
*__name__*: bnToU8a
*__signature__*: bnToU8a (value?: BN | number, bitLength: number = -1, isLE: boolean = false): Uint8Array
*__summary__*: Creates a Uint8Array object from a BN.
*__description__*: `null`/`undefined`/`NaN` inputs returns an empty `Uint8Array` result. `BN` input values return the actual bytes value converted to a `Uint8Array`. Optionally convert using little-endian format if `isLE` is set.
*__example__*:
```javascript
import { bnToU8a } from '@polkadot/util';
bnToU8a(new BN(0x1234)); // => [0x12, 0x34]
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| value | `BN` &#124; `number`|
| bitLength | `number` |
| isLe | `boolean` |
**Returns:** `Uint8Array`
___
+2
View File
@@ -0,0 +1,2 @@
+37
View File
@@ -0,0 +1,37 @@
# Functions
<a id="buffertou8a"></a>
## bufferToU8a
▸ **bufferToU8a**(buffer?: * `Buffer` &#124; `number`[]*): `Uint8Array`
*Defined in [buffer/toU8a.ts:20](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/buffer/toU8a.ts#L20)*
*__name__*: bufferToU8a
*__signature__*: bufferToU8a (value?: Buffer): string
*__summary__*: Creates a Uint8Array value from a Buffer object.
*__description__*: `null` inputs returns an empty result, `Buffer` values return the actual value as a `Uint8Array`. Anything that is not a `Buffer` object throws an error.
*__example__*:
```javascript
import { bufferToU8a } from '@polkadot/util';
bufferToU8a(Buffer.from([1, 2, 3]));
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| `Optional` buffer | `Buffer` &#124; `number`[]|
**Returns:** `Uint8Array`
___
+10
View File
@@ -0,0 +1,10 @@
# Index
### Classes
* [ExtError](../classes/_ext_error_.exterror.md)
---
+2
View File
@@ -0,0 +1,2 @@
+37
View File
@@ -0,0 +1,37 @@
# Functions
<a id="hexaddprefix"></a>
## hexAddPrefix
▸ **hexAddPrefix**(value: * `string` &#124; `null` &#124; `undefined`*): `string`
*Defined in [hex/addPrefix.ts:22](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/hex/addPrefix.ts#L22)*
*__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__*:
```javascript
import { hexAddPrefix } from '@polkadot/util';
console.log('With prefix', hexAddPrefix('0a0b12')); // => 0x0a0b12
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| value | `string` &#124; `null` &#124; `undefined`|
**Returns:** `string`
___
+41
View File
@@ -0,0 +1,41 @@
# Functions
<a id="hexfixlength"></a>
## hexFixLength
▸ **hexFixLength**(value: *`string`*, bitLength?: *`number`*, withPadding?: *`boolean`*): `string`
*Defined in [hex/fixLength.ts:25](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/hex/fixLength.ts#L25)*
*__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__*:
```javascript
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
```
**Parameters:**
| Param | Type | Default value |
| ------ | ------ | ------ |
| value | `string` | - |
| `Default value` bitLength | `number` | -1 |
| `Default value` withPadding | `boolean` | false |
**Returns:** `string`
___
+37
View File
@@ -0,0 +1,37 @@
# Functions
<a id="hexhasprefix"></a>
## hexHasPrefix
▸ **hexHasPrefix**(value: * `string` &#124; `null` &#124; `undefined`*): `boolean`
*Defined in [hex/hasPrefix.ts:22](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/hex/hasPrefix.ts#L22)*
*__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__*:
```javascript
import { hexHasPrefix } from '@polkadot/util';
console.log('has prefix', hexHasPrefix('0x1234')); // => true
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| value | `string` &#124; `null` &#124; `undefined`|
**Returns:** `boolean`
___
+2
View File
@@ -0,0 +1,2 @@
+37
View File
@@ -0,0 +1,37 @@
# Functions
<a id="hexstripprefix"></a>
## hexStripPrefix
▸ **hexStripPrefix**(value: * `string` &#124; `null` &#124; `undefined`*): `string`
*Defined in [hex/stripPrefix.ts:24](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/hex/stripPrefix.ts#L24)*
*__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__*:
```javascript
import { hexStripPrefix } from '@polkadot/util';
console.log('stripped', hexStripPrefix('0x1234')); // => 1234
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| value | `string` &#124; `null` &#124; `undefined`|
**Returns:** `string`
___
+38
View File
@@ -0,0 +1,38 @@
# Functions
<a id="hextobn"></a>
## hexToBn
▸ **hexToBn**(_value?: * `undefined` &#124; `string`*, isLe?: *`boolean`*): `BN`
*Defined in [hex/toBn.ts:30](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/hex/toBn.ts#L30)*
*__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__*:
```javascript
import { hexToBn } from '@polkadot/util';
hexToBn('0x123480001f'); // => BN(0x123480001f)
```
**Parameters:**
| Param | Type | Default value |
| ------ | ------ | ------ |
| `Optional` _value | `undefined` &#124; `string`| - |
| `Default value` isLe | `boolean` | false |
**Returns:** `BN`
___
+37
View File
@@ -0,0 +1,37 @@
# Functions
<a id="hextonumber"></a>
## hexToNumber
▸ **hexToNumber**(value?: * `undefined` &#124; `string`*): `number`
*Defined in [hex/toNumber.ts:22](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/hex/toNumber.ts#L22)*
*__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__*:
```javascript
import { hexToNumber } from '@polkadot/util';
hexToNumber('0x1234'); // => 0x1234
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| `Optional` value | `undefined` &#124; `string`|
**Returns:** `number`
___
+39
View File
@@ -0,0 +1,39 @@
# Functions
<a id="hextou8a"></a>
## hexToU8a
▸ **hexToU8a**(_value?: * `string` &#124; `null`*, bitLength?: *`number`*): `Uint8Array`
*Defined in [hex/toU8a.ts:25](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/hex/toU8a.ts#L25)*
*__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__*:
```javascript
import { hexToU8a } from '@polkadot/util';
hexToU8a('0x80001f'); // Uint8Array([0x80, 0x00, 0x1f])
hexToU8a('0x80001f', 32); // Uint8Array([0x00, 0x80, 0x00, 0x1f])
```
**Parameters:**
| Param | Type | Default value |
| ------ | ------ | ------ |
| `Optional` _value | `string` &#124; `null`| - |
| `Default value` bitLength | `number` | -1 |
**Returns:** `Uint8Array`
___
+2
View File
@@ -0,0 +1,2 @@
+38
View File
@@ -0,0 +1,38 @@
# Functions
<a id="isbn"></a>
## isBn
▸ **isBn**(value: *`any`*): `boolean`
*Defined in [is/bn.ts:23](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/is/bn.ts#L23)*
*__name__*: isBn
*__signature__*: isBN (value: any): boolean
*__summary__*: Tests for a `BN` object instance.
*__description__*: Checks to see if the input object is an instance of `BN` (bn.js).
*__example__*:
```javascript
import BN from 'bn.js';
import { isBn } from '@polkadot/util';
console.log('isBn', isBn(new BN(1))); // => true
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| value | `any` |
**Returns:** `boolean`
___
+37
View File
@@ -0,0 +1,37 @@
# Functions
<a id="isboolean"></a>
## isBoolean
▸ **isBoolean**(value: *`any`*): `boolean`
*Defined in [is/boolean.ts:20](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/is/boolean.ts#L20)*
*__name__*: isBoolean
*__signature__*: isBoolean (value: any): boolean
*__summary__*: Tests for a boolean value.
*__description__*: Checks to see if the input value is a JavaScript boolean.
*__example__*:
```javascript
import { isBoolean } from '@polkadot/util';
isBoolean(false); // => true
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| value | `any` |
**Returns:** `boolean`
___
+37
View File
@@ -0,0 +1,37 @@
# Functions
<a id="isbuffer"></a>
## isBuffer
▸ **isBuffer**(value: *`any`*): `boolean`
*Defined in [is/buffer.ts:22](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/is/buffer.ts#L22)*
*__name__*: isBuffer
*__signature__*: isBuffer (value: any): boolean
*__summary__*: Tests for a `Buffer` object instance.
*__description__*: Checks to see if the input object is an instance of `Buffer`.
*__example__*:
```javascript
import { isBuffer } from '@polkadot/util';
console.log('isBuffer', isBuffer(Buffer.from([]))); // => true
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| value | `any` |
**Returns:** `boolean`
___
+37
View File
@@ -0,0 +1,37 @@
# Functions
<a id="iserror"></a>
## isError
▸ **isError**(value: *`any`*): `boolean`
*Defined in [is/error.ts:22](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/is/error.ts#L22)*
*__name__*: isError
*__signature__*: isError (value: any): boolean
*__summary__*: Tests for a `Error` object instance.
*__description__*: Checks to see if the input object is an instance of `Error`.
*__example__*:
```javascript
import { isError } from '@polkadot/util';
console.log('isError', isError(new Error('message'))); // => true
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| value | `any` |
**Returns:** `boolean`
___
+37
View File
@@ -0,0 +1,37 @@
# Functions
<a id="isfunction"></a>
## isFunction
▸ **isFunction**(value: *`any`*): `boolean`
*Defined in [is/function.ts:20](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/is/function.ts#L20)*
*__name__*: isFunction
*__signature__*: isFunction (value: any): boolean
*__summary__*: Tests for a `function`.
*__description__*: Checks to see if the input value is a JavaScript function.
*__example__*:
```javascript
import { isFunction } from '@polkadot/util';
isFunction(() => false); // => true
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| value | `any` |
**Returns:** `boolean`
___
+40
View File
@@ -0,0 +1,40 @@
# Functions
<a id="ishex"></a>
## isHex
▸ **isHex**(_value: *`any`*, bitLength?: *`number`*, ignoreLength?: *`boolean`*): `boolean`
*Defined in [is/hex.ts:25](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/is/hex.ts#L25)*
*__name__*: isHex
*__signature__*: isHex (value: any, bitLength: number = -1): boolean
*__summary__*: Tests for a hex string.
*__description__*: Checks to see if the input value is a `0x` prefixed hex string. Optionally (`bitLength` !== -1) checks to see if the bitLength is correct.
*__example__*:
```javascript
import { isHex } from '@polkadot/util';
isHex('0x1234'); // => true
isHex('0x1234', 8); // => false
```
**Parameters:**
| Param | Type | Default value |
| ------ | ------ | ------ |
| _value | `any` | - |
| `Default value` bitLength | `number` | -1 |
| `Default value` ignoreLength | `boolean` | false |
**Returns:** `boolean`
___
+2
View File
@@ -0,0 +1,2 @@
+38
View File
@@ -0,0 +1,38 @@
# Functions
<a id="isinstanceof"></a>
## isInstanceOf
▸ **isInstanceOf**(value: *`any`*, clazz: *`any`*): `boolean`
*Defined in [is/instanceOf.ts:20](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/is/instanceOf.ts#L20)*
*__name__*: isInstanceOf
*__signature__*: isInstanceOf (value: any, clazz: Class): boolean
*__summary__*: Tests for a instance of a class.
*__description__*: Checks to see if the input value is an instance of the test class.
*__example__*:
```javascript
import { isInstanceOf } from '@polkadot/util';
console.log('isInstanceOf', isInstanceOf(new Array(0), Array)); // => true
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| value | `any` |
| clazz | `any` |
**Returns:** `boolean`
___
+41
View File
@@ -0,0 +1,41 @@
# Functions
<a id="isip"></a>
## isIp
▸ **isIp**(value: *`string`*, type?: *`IpTypes`*): `boolean`
*Defined in [is/ip.ts:27](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/is/ip.ts#L27)*
*__name__*: isIp
*__signature__*: isIp (value: string, type?: 'v4' | 'v6'): boolean
*__summary__*: Tests if the value is a valid IP address
*__description__*: Checks to see if the value is a valid IP address. Optionally check for either v4/v6
*__example__*:
```javascript
import { isIp } from '@polkadot/util';
isIp('192.168.0.1')); // => true
isIp('1:2:3:4:5:6:7:8'); // => true
isIp('192.168.0.1', 'v6')); // => false
isIp('1:2:3:4:5:6:7:8', 'v4'); // => false
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| value | `string` |
| `Optional` type | `IpTypes` |
**Returns:** `boolean`
___
+37
View File
@@ -0,0 +1,37 @@
# Functions
<a id="isnull"></a>
## isNull
▸ **isNull**(value: *`any`*): `boolean`
*Defined in [is/null.ts:20](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/is/null.ts#L20)*
*__name__*: isNull
*__signature__*: isNull (value: any): boolean
*__summary__*: Tests for a `null` values.
*__description__*: Checks to see if the input value is `null`.
*__example__*:
```javascript
import { isNull } from '@polkadot/util';
console.log('isNull', isNull(null)); // => true
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| value | `any` |
**Returns:** `boolean`
___
+37
View File
@@ -0,0 +1,37 @@
# Functions
<a id="isnumber"></a>
## isNumber
▸ **isNumber**(value: *`any`*): `boolean`
*Defined in [is/number.ts:20](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/is/number.ts#L20)*
*__name__*: isNumber
*__signature__*: isNumber (value: any): boolean
*__summary__*: Tests for a JavaScript number.
*__description__*: Checks to see if the input value is a valid number.
*__example__*:
```javascript
import { isNumber } from '@polkadot/util';
console.log('isNumber', isNumber(1234)); // => true
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| value | `any` |
**Returns:** `boolean`
___
+38
View File
@@ -0,0 +1,38 @@
# Functions
<a id="isobject"></a>
## isObject
▸ **isObject**(value: *`any`*): `boolean`
*Defined in [is/object.ts:25](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/is/object.ts#L25)*
*__name__*: isObject
*__signature__*: isObject (value: any): boolean
*__summary__*: Tests for an `object`.
*__description__*: Checks to see if the input value is a JavaScript object.
*__example__*:
```javascript
import { isObject } from '@polkadot/util';
isObject({}); // => true
isObject('something'); // => false
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| value | `any` |
**Returns:** `boolean`
___
+37
View File
@@ -0,0 +1,37 @@
# Functions
<a id="isobservable"></a>
## isObservable
▸ **isObservable**(value: *`any`*): `boolean`
*Defined in [is/observable.ts:27](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/is/observable.ts#L27)*
*__name__*: isBObservable
*__signature__*: isObservable (value: any): boolean
*__summary__*: Tests for a `Observable` object instance.
*__description__*: Checks to see if the input object is an instance of `BN` (bn.js).
*__example__*:
```javascript
import { isObservable } from '@polkadot/util';
console.log('isObservable', isObservable(...));
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| value | `any` |
**Returns:** `boolean`
___
+37
View File
@@ -0,0 +1,37 @@
# Functions
<a id="isstring"></a>
## isString
▸ **isString**(value: *`any`*): `boolean`
*Defined in [is/string.ts:20](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/is/string.ts#L20)*
*__name__*: isString
*__signature__*: isString (value: any): boolean
*__summary__*: Tests for a string.
*__description__*: Checks to see if the input value is a JavaScript string.
*__example__*:
```javascript
import { isString } from '@polkadot/util';
console.log('isString', isString('test')); // => true
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| value | `any` |
**Returns:** `boolean`
___
+37
View File
@@ -0,0 +1,37 @@
# Functions
<a id="isu8a"></a>
## isU8a
▸ **isU8a**(value: *`any`*): `boolean`
*Defined in [is/u8a.ts:22](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/is/u8a.ts#L22)*
*__name__*: isU8a
*__signature__*: isU8a (value: any): boolean
*__summary__*: Tests for a `Uint8Array` object instance.
*__description__*: Checks to see if the input object is an instance of `Uint8Array`.
*__example__*:
```javascript
import { isUint8Array } from '@polkadot/util';
console.log('isU8a', isU8a([])); // => false
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| value | `any` |
**Returns:** `boolean`
___
+37
View File
@@ -0,0 +1,37 @@
# Functions
<a id="isundefined"></a>
## isUndefined
▸ **isUndefined**(value: *`any`*): `boolean`
*Defined in [is/undefined.ts:20](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/is/undefined.ts#L20)*
*__name__*: isUndefined
*__signature__*: isUndefined (value: any): boolean
*__summary__*: Tests for a `undefined` values.
*__description__*: Checks to see if the input value is `undefined`.
*__example__*:
```javascript
import { isUndefined } from '@polkadot/util';
console.log('isUndefined', isUndefined(void(0))); // => true
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| value | `any` |
**Returns:** `boolean`
___
+54
View File
@@ -0,0 +1,54 @@
# Functions
<a id="format"></a>
## format
▸ **format**(value: *`any`*): `any`
*Defined in [logger.ts:36](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/logger.ts#L36)*
**Parameters:**
| Param | Type |
| ------ | ------ |
| value | `any` |
**Returns:** `any`
___
<a id="logger"></a>
## logger
▸ **logger**(_type: *`string`*): `Logger`
*Defined in [logger.ts:105](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/logger.ts#L105)*
*__name__*: Logger
*__signature__*: logger (type: string): Logger
*__summary__*: Creates a consistent log interface for messages
*__description__*: Returns a `Logger` that has `.log`, `.error`, `.warn` and `.debug` (controlled with environment `DEBUG=typeA,typeB`) methods. Logging is done with a consistent prefix (type of logger, date) followed by the actual message using the underlying console.
*__example__*:
```javascript
const l from '@polkadot/util/logger')('test');
l.log('blah'); // <date> TEST: blah
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| _type | `string` |
**Returns:** `Logger`
___
+2
View File
@@ -0,0 +1,2 @@
+39
View File
@@ -0,0 +1,39 @@
# Functions
<a id="numbertohex"></a>
## numberToHex
▸ **numberToHex**(value?: * `undefined` &#124; `number`*, bitLength?: *`number`*): `string`
*Defined in [number/toHex.ts:25](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/number/toHex.ts#L25)*
*__name__*: numberToHex
*__signature__*: numberToHex (value?: number): string
*__summary__*: Creates a hex value from a number.
*__description__*: `null`/`undefined`/`NaN` inputs returns an empty `0x` result. `number` input values return the actual bytes value converted to a `hex`. With `bitLength` set, it converts the number to the equivalent size.
*__example__*:
```javascript
import { numberToHex } from '@polkadot/util';
numberToHex(0x1234); // => '0x1234'
numberToHex(0x1234, 32); // => 0x00001234
```
**Parameters:**
| Param | Type | Default value |
| ------ | ------ | ------ |
| `Optional` value | `undefined` &#124; `number`| - |
| `Default value` bitLength | `number` | -1 |
**Returns:** `string`
___
+38
View File
@@ -0,0 +1,38 @@
# Functions
<a id="numbertou8a"></a>
## numberToU8a
▸ **numberToU8a**(value?: * `undefined` &#124; `number`*, bitLength?: *`number`*): `Uint8Array`
*Defined in [number/toU8a.ts:23](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/number/toU8a.ts#L23)*
*__name__*: numberToU8a
*__signature__*: numberToU8a (value?: number, bitLenght: number = -1): Uint8Array
*__summary__*: Creates a Uint8Array object from a number.
*__description__*: `null`/`undefined`/`NaN` inputs returns an empty `Uint8Array` result. `number` input values return the actual bytes value converted to a `Uint8Array`. With `bitLength`, it converts the value to the equivalent size.
*__example__*:
```javascript
import { numberToU8a } from '@polkadot/util';
numberToU8a(0x1234); // => [0x12, 0x34]
```
**Parameters:**
| Param | Type | Default value |
| ------ | ------ | ------ |
| `Optional` value | `undefined` &#124; `number`| - |
| `Default value` bitLength | `number` | -1 |
**Returns:** `Uint8Array`
___
+40
View File
@@ -0,0 +1,40 @@
# Functions
<a id="promisify"></a>
## promisify
▸ **promisify**(self: *`any`*, fn: *`Function`*, ...params: *`Array`<`any`>*): `Promise`<`any`>
*Defined in [promisify.ts:21](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/promisify.ts#L21)*
*__name__*: promisify
*__signature__*: function promisify (this: ?Object, fn: Function, ...params: Array): Promise
*__summary__*: Wraps an async callback into a `Promise`
*__description__*: Wraps the supplied async function `fn` that has a standard JS callback `(error: Error, result: any)` into a `Promise`, passing the supplied parameters. When `error` is set, the Promise is rejected, else the Promise resolves with the `result` value.
*__example__*:
```javascript
const { promisify } from '@polkadot/util';
await promisify(null, ((a, cb) => cb(null, a), true); // resolves with `true`
await promisify(null, (cb) => cb(new Error('error!'))); // rejects with `error!`
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| self | `any` |
| fn | `Function` |
| `Rest` params | `Array`<`any`> |
**Returns:** `Promise`<`any`>
___
+2
View File
@@ -0,0 +1,2 @@
+2
View File
@@ -0,0 +1,2 @@
+37
View File
@@ -0,0 +1,37 @@
# Functions
<a id="stringlowerfirst"></a>
## stringLowerFirst
▸ **stringLowerFirst**(_value: *`string`*): `string`
*Defined in [string/lowerFirst.ts:23](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/string/lowerFirst.ts#L23)*
*__name__*: stringLowerFirst
*__signature__*: stringLowerFirst (_value: string): string
*__summary__*: Lowercase the first letter of a string
*__description__*: Lowercase the first letter of a string
*__example__*:
```javascript
import { stringLowerFirst } from '@polkadot/util';
stringLowerFirst('ABC'); // => 'aBC'
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| _value | `string` |
**Returns:** `string`
___
@@ -0,0 +1,2 @@
@@ -0,0 +1,2 @@
+38
View File
@@ -0,0 +1,38 @@
# Functions
<a id="stringshorten"></a>
## stringShorten
▸ **stringShorten**(_value: *`any`*, prefixLength?: *`number`*): `string`
*Defined in [string/shorten.ts:20](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/string/shorten.ts#L20)*
*__name__*: stringShorten
*__signature__*: stringShorten (value: any, prefixLength: number = 8): string
*__summary__*: Returns a string with maximum length
*__description__*: Checks the string against the `prefixLength`, if longer than dopuble this, shortens it by placing `..` in the middle of it
*__example__*:
```javascript
import { stringShorten } from '@polkadot/util';
stringShorten('1234567890', 2); // => 12..90
```
**Parameters:**
| Param | Type | Default value |
| ------ | ------ | ------ |
| _value | `any` | - |
| `Default value` prefixLength | `number` | 6 |
**Returns:** `string`
___
+37
View File
@@ -0,0 +1,37 @@
# Functions
<a id="stringtou8a"></a>
## stringToU8a
▸ **stringToU8a**(value?: * `undefined` &#124; `string`*): `Uint8Array`
*Defined in [string/toU8a.ts:24](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/string/toU8a.ts#L24)*
*__name__*: stringToU8a
*__signature__*: stringToU8a (value?: string): UInt8Array
*__summary__*: Creates a Uint8Array object from a utf-8 string.
*__description__*: String input values return the actual encoded `UInt8Array`. `null` or `undefined` values returns an empty encoded array.
*__example__*:
```javascript
import { stringToU8a } from '@polkadot/util';
stringToU8a('hello'); // [0x68, 0x65, 0x6c, 0x6c, 0x6f]
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| `Optional` value | `undefined` &#124; `string`|
**Returns:** `Uint8Array`
___
+37
View File
@@ -0,0 +1,37 @@
# Functions
<a id="stringupperfirst"></a>
## stringUpperFirst
▸ **stringUpperFirst**(_value: *`string`*): `string`
*Defined in [string/upperFirst.ts:23](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/string/upperFirst.ts#L23)*
*__name__*: stringUpperFirst
*__signature__*: stringUpperFirst (_value: string): string
*__summary__*: Lowercase the first letter of a string
*__description__*: Lowercase the first letter of a string
*__example__*:
```javascript
import { stringUpperFirst } from '@polkadot/util';
stringUpperFirst('abc'); // => 'Abc'
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| _value | `string` |
**Returns:** `string`
___
+22
View File
@@ -0,0 +1,22 @@
# Functions
<a id="syncify"></a>
## syncify
▸ **syncify**(promise: *`Promise`<`any`>*): `any`
*Defined in [syncify.ts:11](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/syncify.ts#L11)*
**Parameters:**
| Param | Type |
| ------ | ------ |
| promise | `Promise`<`any`> |
**Returns:** `any`
___
+40
View File
@@ -0,0 +1,40 @@
# Functions
<a id="u8aconcat"></a>
## u8aConcat
▸ **u8aConcat**(..._list: *`Array`< `Uint8Array` &#124; `string`>*): `Uint8Array`
*Defined in [u8a/concat.ts:25](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/u8a/concat.ts#L25)*
*__name__*: u8aConcat
*__signature__*: u8aConcat (...values: Array<Uint8Array | string>): Uint8Array
*__summary__*: Creates a concatenated Uint8Array from the inputs.
*__description__*: Concatenates the input arrays into a single `UInt8Array`.
*__example__*:
```javascript
import { u8aConcat } from '@polkadot/util';
u8aConcat(
new Uint8Array([1, 2, 3]),
new Uint8Array([4, 5, 6])
); // [1, 2, 3, 4, 5, 6]
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| `Rest` _list | `Array`< `Uint8Array` &#124; `string`> |
**Returns:** `Uint8Array`
___
+41
View File
@@ -0,0 +1,41 @@
# Functions
<a id="u8afixlength"></a>
## u8aFixLength
▸ **u8aFixLength**(value: *`Uint8Array`*, bitLength?: *`number`*, atStart?: *`boolean`*): `Uint8Array`
*Defined in [u8a/fixLength.ts:22](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/u8a/fixLength.ts#L22)*
*__name__*: u8aFixLength
*__signature__*: u8aFixLength (value: string, bitLength: number = -1, withPadding: boolean = false): string
*__summary__*: Shifts a Uint8Array to a specific bitLength
*__description__*: Returns a uint8Array 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.
*__example__*:
```javascript
import { u8aFixLength } from '@polkadot/util';
u8aFixLength('0x12') // => 0x12
u8aFixLength('0x12', 16) // => 0x0012
u8aFixLength('0x1234', 8) // => 0x12
```
**Parameters:**
| Param | Type | Default value |
| ------ | ------ | ------ |
| value | `Uint8Array` | - |
| `Default value` bitLength | `number` | -1 |
| `Default value` atStart | `boolean` | false |
**Returns:** `Uint8Array`
___
+2
View File
@@ -0,0 +1,2 @@
+38
View File
@@ -0,0 +1,38 @@
# Functions
<a id="u8atobn"></a>
## u8aToBn
▸ **u8aToBn**(value: *`Uint8Array`*, isLe: *`boolean`*): `BN`
*Defined in [u8a/toBn.ts:25](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/u8a/toBn.ts#L25)*
*__name__*: u8aToBn
*__signature__*: u8aToHex (value?: Uint8Array, isLe: boolean = false): BN
*__summary__*: Creates a BN from a Uint8Array object.
*__description__*: `UInt8Array` input values return the actual BN. `null` or `undefined` values returns an `0x0` value.
*__example__*:
```javascript
import { u8aToBn } from '@polkadot/util';
u8aToHex(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0xf])); // 0x68656c0f
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| value | `Uint8Array` |
| isLe | `boolean` |
**Returns:** `BN`
___
+37
View File
@@ -0,0 +1,37 @@
# Functions
<a id="u8atobuffer"></a>
## u8aToBuffer
▸ **u8aToBuffer**(value?: *`Uint8Array`*): `Buffer`
*Defined in [u8a/toBuffer.ts:20](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/u8a/toBuffer.ts#L20)*
*__name__*: u8aToBuffer
*__signature__*: u8aToBuffer (value?: UInt8Array): Buffer
*__summary__*: Creates a Buffer object from a hex string.
*__description__*: `null` inputs returns an empty `Buffer` result. `UInt8Array` input values return the actual bytes value converted to a `Buffer`. Anything that is not a `UInt8Array` throws an error.
*__example__*:
```javascript
import { u8aToBuffer } from '@polkadot/util';
console.log('Buffer', u8aToBuffer('0x123480001f'));
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| `Optional` value | `Uint8Array` |
**Returns:** `Buffer`
___
+39
View File
@@ -0,0 +1,39 @@
# Functions
<a id="u8atohex"></a>
## u8aToHex
▸ **u8aToHex**(value?: * `Uint8Array` &#124; `null`*, bitLength?: *`number`*, isPrefixed?: *`boolean`*): `string`
*Defined in [u8a/toHex.ts:20](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/u8a/toHex.ts#L20)*
*__name__*: u8aToHex
*__signature__*: u8aToHex (value?: UInt8Array): string
*__summary__*: Creates a hex string from a Uint8Array object.
*__description__*: `UInt8Array` input values return the actual hex string. `null` or `undefined` values returns an `0x` string.
*__example__*:
```javascript
import { u8aToHex } from '@polkadot/util';
u8aToHex(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0xf])); // 0x68656c0f
```
**Parameters:**
| Param | Type | Default value |
| ------ | ------ | ------ |
| `Optional` value | `Uint8Array` &#124; `null`| - |
| `Default value` bitLength | `number` | -1 |
| `Default value` isPrefixed | `boolean` | true |
**Returns:** `string`
___
+37
View File
@@ -0,0 +1,37 @@
# Functions
<a id="u8atostring"></a>
## u8aToString
▸ **u8aToString**(value?: *`Uint8Array`*): `string`
*Defined in [u8a/toString.ts:24](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/u8a/toString.ts#L24)*
*__name__*: u8aToString
*__signature__*: u8aToString (value?: UInt8Array): string
*__summary__*: Creates a utf-8 string from a Uint8Array object.
*__description__*: `UInt8Array` input values return the actual decoded utf-8 string. `null` or `undefined` values returns an empty string.
*__example__*:
```javascript
import { u8aToString } from '@polkadot/util';
u8aToString(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f])); // hello
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| `Optional` value | `Uint8Array` |
**Returns:** `string`
___
+38
View File
@@ -0,0 +1,38 @@
# Functions
<a id="u8atou8a"></a>
## u8aToU8a
▸ **u8aToU8a**(value?: * `Array`<`number`> &#124; `Buffer` &#124; `Uint8Array` &#124; `string` &#124; `null`*): `Uint8Array`
*Defined in [u8a/toU8a.ts:28](https://github.com/polkadot-js/common/blob/1fb1f9d/packages/util/src/u8a/toU8a.ts#L28)*
*__name__*: u8aToU8a
*__signature__*: u8aToU8a (value?: Array | Buffer | Uint8Array | string | null): Uint8Array
*__summary__*: Creates a Uint8Array value from a Uint8Array bignumber or hex input.
*__description__*: `null` inputs returns a `[]` result, Uint8Array values returns the value, hex strings returns a Uint8Array representation.
*__example__*:
```javascript
import { u8aToU8a } from '@polkadot/util';
u8aToU8a(new Uint8Array([0x12, 0x34]); // => Uint8Array([0x12, 0x34])
u8aToU8a(0x1234); // => Uint8Array([0x12, 0x34])
```
**Parameters:**
| Param | Type |
| ------ | ------ |
| `Optional` value | `Array`<`number`> &#124; `Buffer` &#124; `Uint8Array` &#124; `string` &#124; `null`|
**Returns:** `Uint8Array`
___