Drop unused BigInt class extension (#1210)

This commit is contained in:
Jaco
2021-11-19 11:35:05 +02:00
committed by GitHub
parent 1677d3eace
commit 6965709351
3 changed files with 0 additions and 92 deletions
-69
View File
@@ -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);
});
});
-22
View File
@@ -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;
-1
View File
@@ -7,7 +7,6 @@
export * from './consts';
export { BigIntClass } from './class';
export { biSqrt } from './sqrt';
export { biToBigInt } from './toBigInt';
export { biMax } from './max';