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
+11 -11
View File
@@ -5,17 +5,17 @@
import BN from 'bn.js';
/**
@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
import BN from 'bn.js';
import { isBn } from '@polkadot/util';
console.log('isBn', isBn(new BN(1))); // => true
*/
* @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
* import BN from 'bn.js';
* import { isBn } from '@polkadot/util';
*
* console.log('isBn', isBn(new BN(1))); // => true
*/
export default function isBn (value: any): value is BN {
return BN.isBN(value);
}
+10 -10
View File
@@ -3,16 +3,16 @@
// of the ISC license. See the LICENSE file for details.
/**
@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
import { isBoolean } from '@polkadot/util';
isBoolean(false); // => true
*/
* @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
* import { isBoolean } from '@polkadot/util';
*
* isBoolean(false); // => true
*/
export default function isBoolean (value: any): value is boolean {
return typeof value === 'boolean';
}
+10 -10
View File
@@ -5,16 +5,16 @@
import isInstanceOf from './instanceOf';
/**
@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
import { isBuffer } from '@polkadot/util';
console.log('isBuffer', isBuffer(Buffer.from([]))); // => true
*/
* @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
* import { isBuffer } from '@polkadot/util';
*
* console.log('isBuffer', isBuffer(Buffer.from([]))); // => true
*/
export default function isBuffer (value: any): value is Buffer {
return isInstanceOf(value, Buffer);
}
+10 -10
View File
@@ -5,16 +5,16 @@
import isInstanceOf from './instanceOf';
/**
@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
import { isError } from '@polkadot/util';
console.log('isError', isError(new Error('message'))); // => true
*/
* @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
* import { isError } from '@polkadot/util';
*
* console.log('isError', isError(new Error('message'))); // => true
*/
export default function isError (value: any): value is Error {
return isInstanceOf(value, Error);
}
+10 -10
View File
@@ -3,16 +3,16 @@
// of the ISC license. See the LICENSE file for details.
/**
@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
import { isFunction } from '@polkadot/util';
console.log('isFunction', isFunction(() => false)); // => true
*/
* @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
* import { isFunction } from '@polkadot/util';
*
* isFunction(() => false); // => true
*/
export default function isFunction (value: any): value is Function {
return typeof value === 'function';
}
+11 -11
View File
@@ -7,17 +7,17 @@ import isString from './string';
const HEX_REGEX = /^0x[a-fA-F0-9]+$/;
/**
@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
import { isHex } from '@polkadot/util';
isHex('0x1234'); // => true
isHex('0x1234', 8); // => false
*/
* @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
* import { isHex } from '@polkadot/util';
*
* isHex('0x1234'); // => true
* isHex('0x1234', 8); // => false
*/
export default function isHex (_value: any, bitLength: number = -1, ignoreLength: boolean = false): _value is string {
const value = (_value as string);
const isValidHex = value === '0x' || (isString(value) && HEX_REGEX.test(value));
+2 -2
View File
@@ -19,8 +19,8 @@ import isU8a from './u8a';
import isUndefined from './undefined';
/**
@summary Type checking utilities
*/
* @summary Type checking utilities
*/
export {
isBn,
isBoolean,
+10 -10
View File
@@ -3,16 +3,16 @@
// of the ISC license. See the LICENSE file for details.
/**
@name isInstanceOf
@signature isInstanceOf (value: any, clazz: Class<any>): 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
import { isInstanceOf } from '@polkadot/util';
console.log('isInstanceOf', isInstanceOf(new Array(0), Array)); // => true
*/
* @name isInstanceOf
* @signature isInstanceOf (value: any, clazz: Class<any>): 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
* import { isInstanceOf } from '@polkadot/util';
*
* console.log('isInstanceOf', isInstanceOf(new Array(0), Array)); // => true
*/
export default function isInstanceOf (value: any, clazz: any): boolean {
return value instanceof clazz;
}
+13 -13
View File
@@ -7,19 +7,19 @@ import ipRegex from 'ip-regex';
type IpTypes = 'v4' | 'v6';
/**
@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
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
*/
* @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
* 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
*/
export default function isIp (value: string, type?: IpTypes): boolean {
// FIXME @types/ip-regex defintions are outdated
if (type === 'v4') {
+10 -10
View File
@@ -3,16 +3,16 @@
// of the ISC license. See the LICENSE file for details.
/**
@name isNull
@signature isNull (value: any): boolean
@summary Tests for a `null` values.
@description
Checks to see if the input value is `null`.
@example
import { isNull } from '@polkadot/util';
console.log('isNull', isNull(null)); // => true
*/
* @name isNull
* @signature isNull (value: any): boolean
* @summary Tests for a `null` values.
* @description
* Checks to see if the input value is `null`.
* @example
* import { isNull } from '@polkadot/util';
*
* console.log('isNull', isNull(null)); // => true
*/
export default function isNull (value: any): value is null {
return value === null;
}
+10 -10
View File
@@ -3,16 +3,16 @@
// of the ISC license. See the LICENSE file for details.
/**
@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
import { isNumber } from '@polkadot/util';
console.log('isNumber', isNumber(1234)); // => true
*/
* @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
* import { isNumber } from '@polkadot/util';
*
* console.log('isNumber', isNumber(1234)); // => true
*/
export default function isNumber (value: any): value is number {
return typeof value === 'number';
}
+11 -11
View File
@@ -3,17 +3,17 @@
// of the ISC license. See the LICENSE file for details.
/**
@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
import { isObject } from '@polkadot/util';
isObject({}); // => true
isObject('something'); // => false
*/
* @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
* import { isObject } from '@polkadot/util';
*
* isObject({}); // => true
* isObject('something'); // => false
*/
export default function isObject (value: any): value is object {
return typeof value === 'object';
}
+10 -10
View File
@@ -6,16 +6,16 @@ import isFunction from './function';
import isObject from './object';
/**
@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
import { isObservable } from '@polkadot/util';
console.log('isObservable', isObservable(...));
*/
* @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
* import { isObservable } from '@polkadot/util';
*
* console.log('isObservable', isObservable(...));
*/
export default function isObservable (value: any): boolean {
return isObject(value) && isFunction((value as any).next);
}
+10 -10
View File
@@ -3,16 +3,16 @@
// of the ISC license. See the LICENSE file for details.
/**
@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
import { isString } from '@polkadot/util';
console.log('isString', isString('test')); // => true
*/
* @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
* import { isString } from '@polkadot/util';
*
* console.log('isString', isString('test')); // => true
*/
export default function isString (value: any): value is string {
return typeof value === 'string';
}
+10 -10
View File
@@ -5,16 +5,16 @@
import isInstanceOf from './instanceOf';
/**
@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
import { isUint8Array } from '@polkadot/util';
console.log('isU8a', isU8a([])); // => false
*/
* @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
* import { isUint8Array } from '@polkadot/util';
*
* console.log('isU8a', isU8a([])); // => false
*/
export default function isU8a (value: any): value is Uint8Array {
return isInstanceOf(value, Uint8Array);
}
+10 -10
View File
@@ -3,16 +3,16 @@
// of the ISC license. See the LICENSE file for details.
/**
@name isUndefined
@signature isUndefined (value: any): boolean
@summary Tests for a `undefined` values.
@description
Checks to see if the input value is `undefined`.
@example
import { isUndefined } from '@polkadot/util';
console.log('isUndefined', isUndefined(void(0))); // => true
*/
* @name isUndefined
* @signature isUndefined (value: any): boolean
* @summary Tests for a `undefined` values.
* @description
* Checks to see if the input value is `undefined`.
* @example
* import { isUndefined } from '@polkadot/util';
*
* console.log('isUndefined', isUndefined(void(0))); // => true
*/
export default function isUndefined (value: any): value is undefined {
return typeof value === 'undefined';
}