Use isChildClass & isBigInt from @polkadot/util (#1924)

* Use isChildClass & isBigInt from @polkadot/util

* Allow never

* Bumps

* Common 2.5.1

* Fix overrides

* Remove gh-pages script (in dev)
This commit is contained in:
Jaco Greeff
2020-02-22 17:02:03 +01:00
committed by GitHub
parent 2a16b04420
commit 196a0891b8
17 changed files with 92 additions and 115 deletions
+3 -3
View File
@@ -28,15 +28,15 @@
"dependencies": {
"@babel/runtime": "^7.8.4",
"@polkadot/metadata": "1.4.0-beta.29",
"@polkadot/util": "^2.4.1",
"@polkadot/util-crypto": "^2.4.1",
"@polkadot/util": "^2.5.1",
"@polkadot/util-crypto": "^2.5.1",
"@types/bn.js": "^4.11.6",
"bn.js": "^5.1.1",
"memoizee": "^0.4.14",
"rxjs": "^6.5.4"
},
"devDependencies": {
"@polkadot/keyring": "^2.4.1",
"@polkadot/keyring": "^2.5.1",
"@types/memoizee": "^0.4.3"
}
}
+1 -8
View File
@@ -15,11 +15,6 @@ export type UIntBitLength = 8 | 16 | 32 | 64 | 128 | 256;
export const DEFAULT_UINT_BITS = 64;
// TODO Impot this from util once supported there
export function isBigInt (value: any): value is BigInt {
return typeof value === 'bigint';
}
/**
* @name AbstractInt
* @ignore
@@ -56,10 +51,8 @@ export default abstract class AbstractInt extends BN implements Codec {
return hexToBn(value, { isLe: false, isNegative }).toString();
} else if (isU8a(value)) {
return AbstractInt.decodeAbstracIntU8a(value, bitLength, isNegative);
} else if (isBigInt(value)) {
return value.toString();
} else if (isString(value)) {
return new BN(value, 10).toString();
return new BN(value.toString(), 10).toString();
}
return bnToBn(value).toString();
+3 -5
View File
@@ -5,11 +5,11 @@
import { AnyNumber, Codec, Constructor, ICompact, InterfaceTypes, Registry } from '../types';
import BN from 'bn.js';
import { compactAddLength, compactFromU8a, compactStripLength, compactToU8a, isBn, isNumber, isString } from '@polkadot/util';
import { compactAddLength, compactFromU8a, compactStripLength, compactToU8a, isBigInt, isBn, isNumber, isString } from '@polkadot/util';
import { DEFAULT_BITLENGTH } from '@polkadot/util/compact/defaults';
import { typeToConstructor } from './utils';
import { UIntBitLength, isBigInt } from './AbstractInt';
import { UIntBitLength } from './AbstractInt';
import Base from './Base';
export interface CompactEncodable extends Codec {
@@ -60,9 +60,7 @@ export default class Compact<T extends CompactEncodable> extends Base<T> impleme
public static decodeCompact<T extends CompactEncodable> (registry: Registry, Type: Constructor<T>, value: Compact<T> | AnyNumber): CompactEncodable {
if (value instanceof Compact) {
return new Type(registry, value.raw);
} else if (isBigInt(value)) {
return new Type(registry, value.toString());
} else if (isString(value) || isNumber(value) || isBn(value)) {
} else if (isString(value) || isNumber(value) || isBn(value) || isBigInt(value)) {
return new Type(registry, value);
}
+2 -8
View File
@@ -4,20 +4,14 @@
import { Codec, Constructor } from '../types';
import { isChildClass } from '@polkadot/util';
import Struct from '../codec/Struct';
import Text from '../primitive/Text';
import U32 from '../primitive/U32';
import Unconstructable from '../primitive/Unconstructable';
import { TypeRegistry } from './registry';
// Copied from interfacesTs
function isChildClass (Parent: Constructor<any>, Child?: Constructor<any>): boolean {
return Child
// eslint-disable-next-line no-prototype-builtins
? Parent === Child || Parent.isPrototypeOf(Child)
: false;
}
describe('TypeRegistry', (): void => {
const registry = new TypeRegistry();
+1 -2
View File
@@ -5,11 +5,10 @@
import { AnyNumber, Registry } from '../types';
import BN from 'bn.js';
import { bnToBn, isBn, isNumber, isU8a, isHex } from '@polkadot/util';
import { bnToBn, isBn, isBigInt, isNumber, isU8a, isHex } from '@polkadot/util';
import { decodeAddress, encodeAddress } from '@polkadot/util-crypto';
import { createType } from '../create';
import { isBigInt } from '../codec/AbstractInt';
import U32 from '../primitive/U32';
export const ENUMSET_SIZE = new BN(64);