src: Implement BigInt support, remove nodejs 8
This commit is contained in:
parent
373605e40d
commit
8d979dd8a5
5 changed files with 43 additions and 12 deletions
|
|
@ -1,11 +1,6 @@
|
|||
/// <reference lib="es2017"/>
|
||||
/// <reference lib="esnext.asynciterable"/>
|
||||
/// <reference lib="esnext"/>
|
||||
/// <reference lib="dom"/>
|
||||
|
||||
// TODO: Use the `URL` global when targeting Node.js 10
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
const URLGlobal = typeof URL === 'undefined' ? require('url').URL : URL;
|
||||
|
||||
export type Class<T = unknown> = new (...args: any[]) => T;
|
||||
|
||||
export const enum TypeName {
|
||||
|
|
@ -14,6 +9,7 @@ export const enum TypeName {
|
|||
undefined = 'undefined',
|
||||
string = 'string',
|
||||
number = 'number',
|
||||
bigint = 'BigInt',
|
||||
symbol = 'symbol',
|
||||
Function = 'Function',
|
||||
Generator = 'Generator',
|
||||
|
|
@ -39,6 +35,8 @@ export const enum TypeName {
|
|||
Uint32Array = 'Uint32Array',
|
||||
Float32Array = 'Float32Array',
|
||||
Float64Array = 'Float64Array',
|
||||
BigInt64Array = 'BigInt64Array',
|
||||
BigUint64Array = 'BigUint64Array',
|
||||
ArrayBuffer = 'ArrayBuffer',
|
||||
SharedArrayBuffer = 'SharedArrayBuffer',
|
||||
DataView = 'DataView',
|
||||
|
|
@ -77,6 +75,8 @@ function is(value: unknown): TypeName {
|
|||
return TypeName.string;
|
||||
case 'number':
|
||||
return TypeName.number;
|
||||
case 'bigint':
|
||||
return TypeName.bigint;
|
||||
case 'symbol':
|
||||
return TypeName.symbol;
|
||||
default:
|
||||
|
|
@ -115,6 +115,7 @@ const isObject = (value: unknown): value is object => typeof value === 'object';
|
|||
is.undefined = isOfType<undefined>('undefined');
|
||||
is.string = isOfType<string>('string');
|
||||
is.number = isOfType<number>('number');
|
||||
is.bigint = isOfType<bigint>('bigint');
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
is.function_ = isOfType<Function>('function');
|
||||
|
|
@ -175,6 +176,8 @@ is.int32Array = isObjectOfType<Int32Array>(TypeName.Int32Array);
|
|||
is.uint32Array = isObjectOfType<Uint32Array>(TypeName.Uint32Array);
|
||||
is.float32Array = isObjectOfType<Float32Array>(TypeName.Float32Array);
|
||||
is.float64Array = isObjectOfType<Float64Array>(TypeName.Float64Array);
|
||||
is.bigint64Array = isObjectOfType<BigInt64Array>(TypeName.BigInt64Array);
|
||||
is.biguint64Array = isObjectOfType<BigUint64Array>(TypeName.BigUint64Array);
|
||||
|
||||
is.arrayBuffer = isObjectOfType<ArrayBuffer>(TypeName.ArrayBuffer);
|
||||
is.sharedArrayBuffer = isObjectOfType<SharedArrayBuffer>(TypeName.SharedArrayBuffer);
|
||||
|
|
@ -189,7 +192,7 @@ is.urlString = (value: unknown): value is string => {
|
|||
}
|
||||
|
||||
try {
|
||||
new URLGlobal(value); // eslint-disable-line no-new
|
||||
new URL(value); // eslint-disable-line no-new
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue