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
|
||||
node_js:
|
||||
- '10'
|
||||
- '8'
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
},
|
||||
"main": "dist",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
"node": ">=10"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "del dist && tsc",
|
||||
|
|
@ -80,6 +80,11 @@
|
|||
"extensions": [
|
||||
"ts"
|
||||
],
|
||||
"globals": [
|
||||
"BigInt",
|
||||
"BigInt64Array",
|
||||
"BigUint64Array"
|
||||
],
|
||||
"rules": {
|
||||
"@typescript-eslint/explicit-function-return-type": "off"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
26
test/test.ts
26
test/test.ts
|
|
@ -2,7 +2,6 @@ import fs from 'fs';
|
|||
import net from 'net';
|
||||
import Stream from 'stream';
|
||||
import util from 'util';
|
||||
import {URL} from 'url';
|
||||
import tempy from 'tempy';
|
||||
import test, {ExecutionContext} from 'ava';
|
||||
import {JSDOM} from 'jsdom';
|
||||
|
|
@ -69,6 +68,17 @@ const types = new Map<string, Test>([
|
|||
],
|
||||
typename: TypeName.number
|
||||
}],
|
||||
['bigint', {
|
||||
is: is.bigint,
|
||||
fixtures: [
|
||||
1n,
|
||||
0n,
|
||||
-0n,
|
||||
// eslint-disable-next-line new-cap
|
||||
BigInt('1234')
|
||||
],
|
||||
typename: TypeName.bigint
|
||||
}],
|
||||
['boolean', {
|
||||
is: is.boolean,
|
||||
fixtures: [
|
||||
|
|
@ -311,6 +321,20 @@ const types = new Map<string, Test>([
|
|||
],
|
||||
typename: TypeName.Float64Array
|
||||
}],
|
||||
['bigint64Array', {
|
||||
is: is.bigint64Array,
|
||||
fixtures: [
|
||||
new BigInt64Array()
|
||||
],
|
||||
typename: TypeName.BigInt64Array
|
||||
}],
|
||||
['biguint64Array', {
|
||||
is: is.biguint64Array,
|
||||
fixtures: [
|
||||
new BigUint64Array()
|
||||
],
|
||||
typename: TypeName.BigUint64Array
|
||||
}],
|
||||
['arrayBuffer', {
|
||||
is: is.arrayBuffer,
|
||||
fixtures: [
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@
|
|||
"extends": "@sindresorhus/tsconfig",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"target": "es2017",
|
||||
"target": "esnext",
|
||||
"lib": [
|
||||
"es2017",
|
||||
"esnext.asynciterable",
|
||||
"esnext",
|
||||
"dom"
|
||||
]
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue