[CI Skip] 0.7.1

This commit is contained in:
Travis CI
2017-12-11 19:40:48 +00:00
parent 77fccc3760
commit b659622384
5 changed files with 71 additions and 12 deletions
+1
View File
@@ -2,6 +2,7 @@
Utility methods for this package are split into groups
- [array](array.md) Utility methods that operates on arrays
- [bn](bn.md) Utility methods to convert to and from `BN` objects
- [buffer](buffer.md) Utility methods to convert to and from `Buffer` objects
- [ext](ext.md) Extensions to basic classes
+23
View File
@@ -0,0 +1,23 @@
# array
Utility methods that operates on arrays
- [arrayFilter](#arrayfilter) Filters undefined and (optionally) null values from an array
## arrayFilter
Filters undefined and (optionally) null values from an array
```js
arrayFilter (array: Array<any>, allowNulls: boolean = true): Array<any>
```
Returns a new array with all `undefined` values removed. Optionally, when `allowNulls = false`, it removes the `null` values as well
```js
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, '']
```
+45 -4
View File
@@ -8,8 +8,10 @@ Type checking utilities
- [isFunction](#isfunction) Tests for a `function`.
- [isHex](#ishex) Tests for a hex string.
- [isInstanceOf](#isinstanceof) Tests for a instance of a class.
- [isIp](#isip) Tests if the value is a valid IP address
- [isNull](#isnull) Tests for a `null` values.
- [isNumber](#isnumber) Tests for a JavaScript number.
- [isObject](#isobject) Tests for an `object`.
- [isString](#isstring) Tests for a string.
- [isUint8Array](#isuint8array) Tests for a `Uint8Array` object instance.
- [isUndefined](#isundefined) Tests for a `undefined` values.
@@ -88,16 +90,17 @@ console.log('isFunction', isFunction(() => false)); // => true
Tests for a hex string.
```js
isHex (value: any): boolean
isHex (value: any, bitLength: number = -1): boolean
```
Checks to see if the input value is a `0x` prefixed hex string.
Checks to see if the input value is a `0x` prefixed hex string. Optionally (`bitLength` !== -1) checks to see if the bitLength is correct.
```js
import { isHex } from '@polkadot/util';
console.log('isHex', isHex('0x1234')); // => true
isHex('0x1234'); // => true
isHex('0x1234', 8); // => false
```
## isInstanceOf
@@ -114,7 +117,27 @@ Checks to see if the input value is an instance of the test class.
```js
import { isInstanceOf } from '@polkadot/util';
console.log('isinstanceOf', isInstanceOf(new Array(0), Array)); // => true
console.log('isInstanceOf', isInstanceOf(new Array(0), Array)); // => true
```
## isIp
Tests if the value is a valid IP address
```js
isIp (value: any, type?: 'v4' | 'v6'): boolean
```
Checks to see if the value is a valid IP address. Optionally check for either v4/v6
```js
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
```
## isNull
@@ -151,6 +174,24 @@ import { isNumber } from '@polkadot/util';
console.log('isNumber', isNumber(1234)); // => true
```
## isObject
Tests for an `object`.
```js
isObject (value: any): boolean
```
Checks to see if the input value is a JavaScript object.
```js
import { isObject } from '@polkadot/util';
isObject({}); // => true
isObject('something'); // => false
```
## isString
Tests for a string.