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,4 +1,3 @@
|
||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- '10'
|
- '10'
|
||||||
- '8'
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
},
|
},
|
||||||
"main": "dist",
|
"main": "dist",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8"
|
"node": ">=10"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "del dist && tsc",
|
"build": "del dist && tsc",
|
||||||
|
|
@ -80,6 +80,11 @@
|
||||||
"extensions": [
|
"extensions": [
|
||||||
"ts"
|
"ts"
|
||||||
],
|
],
|
||||||
|
"globals": [
|
||||||
|
"BigInt",
|
||||||
|
"BigInt64Array",
|
||||||
|
"BigUint64Array"
|
||||||
|
],
|
||||||
"rules": {
|
"rules": {
|
||||||
"@typescript-eslint/explicit-function-return-type": "off"
|
"@typescript-eslint/explicit-function-return-type": "off"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,6 @@
|
||||||
/// <reference lib="es2017"/>
|
/// <reference lib="esnext"/>
|
||||||
/// <reference lib="esnext.asynciterable"/>
|
|
||||||
/// <reference lib="dom"/>
|
/// <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 type Class<T = unknown> = new (...args: any[]) => T;
|
||||||
|
|
||||||
export const enum TypeName {
|
export const enum TypeName {
|
||||||
|
|
@ -14,6 +9,7 @@ export const enum TypeName {
|
||||||
undefined = 'undefined',
|
undefined = 'undefined',
|
||||||
string = 'string',
|
string = 'string',
|
||||||
number = 'number',
|
number = 'number',
|
||||||
|
bigint = 'BigInt',
|
||||||
symbol = 'symbol',
|
symbol = 'symbol',
|
||||||
Function = 'Function',
|
Function = 'Function',
|
||||||
Generator = 'Generator',
|
Generator = 'Generator',
|
||||||
|
|
@ -39,6 +35,8 @@ export const enum TypeName {
|
||||||
Uint32Array = 'Uint32Array',
|
Uint32Array = 'Uint32Array',
|
||||||
Float32Array = 'Float32Array',
|
Float32Array = 'Float32Array',
|
||||||
Float64Array = 'Float64Array',
|
Float64Array = 'Float64Array',
|
||||||
|
BigInt64Array = 'BigInt64Array',
|
||||||
|
BigUint64Array = 'BigUint64Array',
|
||||||
ArrayBuffer = 'ArrayBuffer',
|
ArrayBuffer = 'ArrayBuffer',
|
||||||
SharedArrayBuffer = 'SharedArrayBuffer',
|
SharedArrayBuffer = 'SharedArrayBuffer',
|
||||||
DataView = 'DataView',
|
DataView = 'DataView',
|
||||||
|
|
@ -77,6 +75,8 @@ function is(value: unknown): TypeName {
|
||||||
return TypeName.string;
|
return TypeName.string;
|
||||||
case 'number':
|
case 'number':
|
||||||
return TypeName.number;
|
return TypeName.number;
|
||||||
|
case 'bigint':
|
||||||
|
return TypeName.bigint;
|
||||||
case 'symbol':
|
case 'symbol':
|
||||||
return TypeName.symbol;
|
return TypeName.symbol;
|
||||||
default:
|
default:
|
||||||
|
|
@ -115,6 +115,7 @@ const isObject = (value: unknown): value is object => typeof value === 'object';
|
||||||
is.undefined = isOfType<undefined>('undefined');
|
is.undefined = isOfType<undefined>('undefined');
|
||||||
is.string = isOfType<string>('string');
|
is.string = isOfType<string>('string');
|
||||||
is.number = isOfType<number>('number');
|
is.number = isOfType<number>('number');
|
||||||
|
is.bigint = isOfType<bigint>('bigint');
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
is.function_ = isOfType<Function>('function');
|
is.function_ = isOfType<Function>('function');
|
||||||
|
|
@ -175,6 +176,8 @@ is.int32Array = isObjectOfType<Int32Array>(TypeName.Int32Array);
|
||||||
is.uint32Array = isObjectOfType<Uint32Array>(TypeName.Uint32Array);
|
is.uint32Array = isObjectOfType<Uint32Array>(TypeName.Uint32Array);
|
||||||
is.float32Array = isObjectOfType<Float32Array>(TypeName.Float32Array);
|
is.float32Array = isObjectOfType<Float32Array>(TypeName.Float32Array);
|
||||||
is.float64Array = isObjectOfType<Float64Array>(TypeName.Float64Array);
|
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.arrayBuffer = isObjectOfType<ArrayBuffer>(TypeName.ArrayBuffer);
|
||||||
is.sharedArrayBuffer = isObjectOfType<SharedArrayBuffer>(TypeName.SharedArrayBuffer);
|
is.sharedArrayBuffer = isObjectOfType<SharedArrayBuffer>(TypeName.SharedArrayBuffer);
|
||||||
|
|
@ -189,7 +192,7 @@ is.urlString = (value: unknown): value is string => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new URLGlobal(value); // eslint-disable-line no-new
|
new URL(value); // eslint-disable-line no-new
|
||||||
return true;
|
return true;
|
||||||
} catch {
|
} catch {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
26
test/test.ts
26
test/test.ts
|
|
@ -2,7 +2,6 @@ import fs from 'fs';
|
||||||
import net from 'net';
|
import net from 'net';
|
||||||
import Stream from 'stream';
|
import Stream from 'stream';
|
||||||
import util from 'util';
|
import util from 'util';
|
||||||
import {URL} from 'url';
|
|
||||||
import tempy from 'tempy';
|
import tempy from 'tempy';
|
||||||
import test, {ExecutionContext} from 'ava';
|
import test, {ExecutionContext} from 'ava';
|
||||||
import {JSDOM} from 'jsdom';
|
import {JSDOM} from 'jsdom';
|
||||||
|
|
@ -69,6 +68,17 @@ const types = new Map<string, Test>([
|
||||||
],
|
],
|
||||||
typename: TypeName.number
|
typename: TypeName.number
|
||||||
}],
|
}],
|
||||||
|
['bigint', {
|
||||||
|
is: is.bigint,
|
||||||
|
fixtures: [
|
||||||
|
1n,
|
||||||
|
0n,
|
||||||
|
-0n,
|
||||||
|
// eslint-disable-next-line new-cap
|
||||||
|
BigInt('1234')
|
||||||
|
],
|
||||||
|
typename: TypeName.bigint
|
||||||
|
}],
|
||||||
['boolean', {
|
['boolean', {
|
||||||
is: is.boolean,
|
is: is.boolean,
|
||||||
fixtures: [
|
fixtures: [
|
||||||
|
|
@ -311,6 +321,20 @@ const types = new Map<string, Test>([
|
||||||
],
|
],
|
||||||
typename: TypeName.Float64Array
|
typename: TypeName.Float64Array
|
||||||
}],
|
}],
|
||||||
|
['bigint64Array', {
|
||||||
|
is: is.bigint64Array,
|
||||||
|
fixtures: [
|
||||||
|
new BigInt64Array()
|
||||||
|
],
|
||||||
|
typename: TypeName.BigInt64Array
|
||||||
|
}],
|
||||||
|
['biguint64Array', {
|
||||||
|
is: is.biguint64Array,
|
||||||
|
fixtures: [
|
||||||
|
new BigUint64Array()
|
||||||
|
],
|
||||||
|
typename: TypeName.BigUint64Array
|
||||||
|
}],
|
||||||
['arrayBuffer', {
|
['arrayBuffer', {
|
||||||
is: is.arrayBuffer,
|
is: is.arrayBuffer,
|
||||||
fixtures: [
|
fixtures: [
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@
|
||||||
"extends": "@sindresorhus/tsconfig",
|
"extends": "@sindresorhus/tsconfig",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "dist",
|
"outDir": "dist",
|
||||||
"target": "es2017",
|
"target": "esnext",
|
||||||
"lib": [
|
"lib": [
|
||||||
"es2017",
|
"es2017",
|
||||||
"esnext.asynciterable",
|
"esnext",
|
||||||
"dom"
|
"dom"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue