From 696570935164a37906638cfed3581c9d5f22ff21 Mon Sep 17 00:00:00 2001 From: Jaco Date: Fri, 19 Nov 2021 10:35:05 +0100 Subject: [PATCH] Drop unused BigInt class extension (#1210) --- packages/util/src/bi/class.spec.ts | 69 ------------------------------ packages/util/src/bi/class.ts | 22 ---------- packages/util/src/bi/index.ts | 1 - 3 files changed, 92 deletions(-) delete mode 100644 packages/util/src/bi/class.spec.ts delete mode 100644 packages/util/src/bi/class.ts diff --git a/packages/util/src/bi/class.spec.ts b/packages/util/src/bi/class.spec.ts deleted file mode 100644 index 3c94ba016..000000000 --- a/packages/util/src/bi/class.spec.ts +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2017-2021 @polkadot/util authors & contributors -// SPDX-License-Identifier: Apache-2.0 - -import { isBigInt } from '../is'; -import { BigIntClass } from '.'; - -describe('BigIntClass', (): void => { - it('has the correct valueOf', (): void => { - expect( - typeof new BigIntClass(0).valueOf() - ).toEqual('bigint'); - }); - - it('has the correct instanceof', (): void => { - expect( - isBigInt(new BigIntClass(0)) - ).toEqual(true); - }); - - it('has a top-level toString method', (): void => { - const test = new BigIntClass(16); - - expect(test.toString()).toEqual('16'); - expect(test.toString(16)).toEqual('10'); - }); - - it('cane be added together', (): void => { - expect(new BigIntClass(16) + new BigIntClass(10)).toEqual(26n); - }); - - it('has the correct type for inherited', (): void => { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - class Test extends BigIntClass implements BigInt { - } - - expect(isBigInt(new Test(0x16))).toEqual(true); - }); - - it('inhertited class has own methods', (): void => { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - class Test extends BigIntClass { - toHex (): string { - return `0x${(this as unknown as bigint).toString(16)}`; - } - } - - expect(new Test(0x16).toHex()).toEqual('0x16'); - }); - - it('inhertited class still acts like bigint', (): void => { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - class Test extends BigIntClass { - // nothing - } - - const test = new Test(0x16n); - - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - expect(test.toString(16)).toEqual('16'); - - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - expect(test * 2n).toEqual(44n); - }); -}); diff --git a/packages/util/src/bi/class.ts b/packages/util/src/bi/class.ts deleted file mode 100644 index 440d174e3..000000000 --- a/packages/util/src/bi/class.ts +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2017-2021 @polkadot/util authors & contributors -// SPDX-License-Identifier: Apache-2.0 - -import type { IBigIntConstructor } from '../types'; - -// See https://stackoverflow.com/questions/58207487/extend-object-wrappers-for-modern-primitives - -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-ignore -export class BigIntImpl extends BigInt implements BigInt { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - constructor (value: string | number | bigint | boolean): bigint { - const self = Object(BigInt(value)) as bigint; - - Object.setPrototypeOf(self, new.target.prototype); - - return self; - } -} - -export const BigIntClass = BigIntImpl as IBigIntConstructor; diff --git a/packages/util/src/bi/index.ts b/packages/util/src/bi/index.ts index d37ac6a8a..d454f05a2 100644 --- a/packages/util/src/bi/index.ts +++ b/packages/util/src/bi/index.ts @@ -7,7 +7,6 @@ export * from './consts'; -export { BigIntClass } from './class'; export { biSqrt } from './sqrt'; export { biToBigInt } from './toBigInt'; export { biMax } from './max';