Require Node.js 10

This commit is contained in:
Sindre Sorhus 2019-11-07 15:56:02 +07:00
parent 0cc82c583e
commit af6b03d67f
5 changed files with 87 additions and 102 deletions

View file

@ -2,4 +2,3 @@ language: node_js
node_js: node_js:
- '12' - '12'
- '10' - '10'
- '8'

View file

@ -11,7 +11,7 @@
}, },
"main": "dist", "main": "dist",
"engines": { "engines": {
"node": ">=8" "node": ">=10"
}, },
"scripts": { "scripts": {
"build": "del dist && tsc", "build": "del dist && tsc",
@ -46,9 +46,9 @@
"types" "types"
], ],
"devDependencies": { "devDependencies": {
"@sindresorhus/tsconfig": "^0.4.0", "@sindresorhus/tsconfig": "^0.6.0",
"@types/jsdom": "^12.2.4", "@types/jsdom": "^12.2.4",
"@types/node": "^12.0.10", "@types/node": "^12.12.6",
"@types/zen-observable": "^0.8.0", "@types/zen-observable": "^0.8.0",
"@typescript-eslint/eslint-plugin": "^1.11.0", "@typescript-eslint/eslint-plugin": "^1.11.0",
"@typescript-eslint/parser": "^1.11.0", "@typescript-eslint/parser": "^1.11.0",
@ -60,7 +60,7 @@
"tempy": "^0.3.0", "tempy": "^0.3.0",
"ts-node": "^8.3.0", "ts-node": "^8.3.0",
"typescript": "^3.4.1", "typescript": "^3.4.1",
"xo": "^0.24.0", "xo": "^0.25.3",
"zen-observable": "^0.8.8" "zen-observable": "^0.8.8"
}, },
"types": "dist", "types": "dist",
@ -86,8 +86,6 @@
"BigUint64Array" "BigUint64Array"
], ],
"rules": { "rules": {
"import/first": "off",
"import/newline-after-import": "off",
"@typescript-eslint/promise-function-async": "off", "@typescript-eslint/promise-function-async": "off",
"@typescript-eslint/no-empty-function": "off", "@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/explicit-function-return-type": "off" "@typescript-eslint/explicit-function-return-type": "off"

View file

@ -1,9 +1,6 @@
/// <reference lib="esnext"/> /// <reference lib="es2018"/>
/// <reference lib="dom"/> /// <reference lib="dom"/>
// TODO: Use the `URL` global when targeting Node.js 10
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 {
@ -194,7 +191,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;
@ -219,7 +216,14 @@ const primitiveTypeOfTypes = new Set([
]); ]);
// TODO: This should be able to be `not object` when the `not` operator is out // TODO: This should be able to be `not object` when the `not` operator is out
export type Primitive = null | undefined | string | number | bigint | boolean | symbol; export type Primitive =
| null
| undefined
| string
| number
| bigint
| boolean
| symbol;
is.primitive = (value: unknown): value is Primitive => is.null_(value) || primitiveTypeOfTypes.has(typeof value); is.primitive = (value: unknown): value is Primitive => is.null_(value) || primitiveTypeOfTypes.has(typeof value);
@ -251,7 +255,18 @@ const typedArrayTypes = new Set([
TypeName.BigUint64Array TypeName.BigUint64Array
]); ]);
export type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array; export type TypedArray =
| Int8Array
| Uint8Array
| Uint8ClampedArray
| Int16Array
| Uint16Array
| Int32Array
| Uint32Array
| Float32Array
| Float64Array
| BigInt64Array
| BigUint64Array;
is.typedArray = (value: unknown): value is TypedArray => { is.typedArray = (value: unknown): value is TypedArray => {
const objectType = getObjectType(value); const objectType = getObjectType(value);

View file

@ -9,10 +9,6 @@ import {Subject, Observable} from 'rxjs';
import ZenObservable = require('zen-observable'); import ZenObservable = require('zen-observable');
import is, {TypeName} from '../source'; import is, {TypeName} from '../source';
const URLGlobal = typeof URL === 'undefined' ? require('url').URL : URL;
const isNode10orHigher = Number(process.versions.node.split('.')[0]) >= 10;
class PromiseSubclassFixture<T> extends Promise<T> {} class PromiseSubclassFixture<T> extends Promise<T> {}
class ErrorSubclassFixture extends Error {} class ErrorSubclassFixture extends Error {}
@ -70,18 +66,17 @@ const types = new Map<string, Test>([
], ],
typename: TypeName.number typename: TypeName.number
}], }],
// TODO: Nodejs 10 only ['bigint', {
// ['bigint', { is: is.bigint,
// is: is.bigint, fixtures: [
// fixtures: [ // Disabled until TS supports it for an ESnnnn target.
// 1n, // 1n,
// 0n, // 0n,
// -0n, // -0n,
// // eslint-disable-next-line new-cap BigInt('1234')
// BigInt('1234') ],
// ], typename: TypeName.bigint
// typename: TypeName.bigint }],
// }],
['boolean', { ['boolean', {
is: is.boolean, is: is.boolean,
fixtures: [ fixtures: [
@ -151,7 +146,7 @@ const types = new Map<string, Test>([
is: is.regExp, is: is.regExp,
fixtures: [ fixtures: [
/\w/, /\w/,
new RegExp('\\w') new RegExp('\\w') // eslint-disable-line prefer-regex-literals
], ],
typename: TypeName.RegExp typename: TypeName.RegExp
}], }],
@ -324,21 +319,20 @@ const types = new Map<string, Test>([
], ],
typename: TypeName.Float64Array typename: TypeName.Float64Array
}], }],
// TODO: Nodejs 10 only ['bigInt64Array', {
// ['bigInt64Array', { is: is.bigInt64Array,
// is: is.bigInt64Array, fixtures: [
// fixtures: [ new BigInt64Array()
// new BigInt64Array() ],
// ], typename: TypeName.BigInt64Array
// typename: TypeName.BigInt64Array }],
// }], ['bigUint64Array', {
// ['bigUint64Array', { is: is.bigUint64Array,
// is: is.bigUint64Array, fixtures: [
// fixtures: [ new BigUint64Array()
// new BigUint64Array() ],
// ], typename: TypeName.BigUint64Array
// typename: TypeName.BigUint64Array }],
// }],
['arrayBuffer', { ['arrayBuffer', {
is: is.arrayBuffer, is: is.arrayBuffer,
fixtures: [ fixtures: [
@ -496,10 +490,9 @@ test('is.number', t => {
testType(t, 'number', ['integer', 'safeInteger', 'infinite']); testType(t, 'number', ['integer', 'safeInteger', 'infinite']);
}); });
// TODO: Nodejs 10 only test('is.bigint', t => {
// test('is.bigint', t => { testType(t, 'bigint');
// testType(t, 'bigint'); });
// });
test('is.boolean', t => { test('is.boolean', t => {
testType(t, 'boolean'); testType(t, 'boolean');
@ -629,14 +622,13 @@ test('is.float64Array', t => {
testType(t, 'float64Array'); testType(t, 'float64Array');
}); });
// TODO: Nodejs 10 only test('is.bigInt64Array', t => {
// test('is.bigInt64Array', t => { testType(t, 'bigInt64Array');
// testType(t, 'bigInt64Array'); });
// });
// test('is.bigUint64Array', t => { test('is.bigUint64Array', t => {
// testType(t, 'bigUint64Array'); testType(t, 'bigUint64Array');
// }); });
test('is.arrayBuffer', t => { test('is.arrayBuffer', t => {
testType(t, 'arrayBuffer'); testType(t, 'arrayBuffer');
@ -658,7 +650,7 @@ test('is.directInstanceOf', t => {
}); });
test('is.urlInstance', t => { test('is.urlInstance', t => {
const url = new URLGlobal('https://example.com'); const url = new URL('https://example.com');
t.true(is.urlInstance(url)); t.true(is.urlInstance(url));
t.false(is.urlInstance({})); t.false(is.urlInstance({}));
t.false(is.urlInstance(undefined)); t.false(is.urlInstance(undefined));
@ -668,7 +660,7 @@ test('is.urlInstance', t => {
test('is.urlString', t => { test('is.urlString', t => {
const url = 'https://example.com'; const url = 'https://example.com';
t.true(is.urlString(url)); t.true(is.urlString(url));
t.false(is.urlString(new URLGlobal(url))); t.false(is.urlString(new URL(url)));
t.false(is.urlString({})); t.false(is.urlString({}));
t.false(is.urlString(undefined)); t.false(is.urlString(undefined));
t.false(is.urlString(null)); t.false(is.urlString(null));
@ -681,13 +673,9 @@ test('is.truthy', t => {
t.true(is.truthy(Symbol('🦄'))); t.true(is.truthy(Symbol('🦄')));
t.true(is.truthy(true)); t.true(is.truthy(true));
t.true(is.truthy(1)); t.true(is.truthy(1));
// Disabled until TS supports it for an ESnnnn target.
// TODO: Nodejs 10 only // t.true(is.truthy(1n));
// if (isNode10orHigher) { t.true(is.truthy(BigInt(1)));
// t.true(is.truthy(1n));
// // eslint-disable-next-line new-cap
// t.true(is.truthy(BigInt(1)));
// }
}); });
test('is.falsy', t => { test('is.falsy', t => {
@ -697,13 +685,9 @@ test('is.falsy', t => {
t.true(is.falsy(null)); t.true(is.falsy(null));
t.true(is.falsy(undefined)); t.true(is.falsy(undefined));
t.true(is.falsy(NaN)); t.true(is.falsy(NaN));
// Disabled until TS supports it for an ESnnnn target.
// TODO: Nodejs 10 only // t.true(is.falsy(0n));
// if (isNode10orHigher) { t.true(is.falsy(BigInt(0)));
// t.true(is.falsy(0n));
// // eslint-disable-next-line new-cap
// t.true(is.falsy(BigInt(0)));
// }
}); });
test('is.nan', t => { test('is.nan', t => {
@ -725,13 +709,10 @@ test('is.primitive', t => {
true, true,
false, false,
Symbol('🦄') Symbol('🦄')
// Disabled until TS supports it for an ESnnnn target.
// 6n
]; ];
// TODO: Nodejs 10 only
// if (isNode10orHigher) {
// primitives.push(6n);
// }
for (const el of primitives) { for (const el of primitives) {
t.true(is.primitive(el)); t.true(is.primitive(el));
} }
@ -764,20 +745,18 @@ test('is.iterable', t => {
t.false(is.iterable({})); t.false(is.iterable({}));
}); });
if (isNode10orHigher) { test('is.asyncIterable', t => {
test('is.asyncIterable', t => { t.true(is.asyncIterable({
t.true(is.asyncIterable({ [Symbol.asyncIterator]: () => {}
[Symbol.asyncIterator]: () => {} }));
}));
t.false(is.asyncIterable(null)); t.false(is.asyncIterable(null));
t.false(is.asyncIterable(undefined)); t.false(is.asyncIterable(undefined));
t.false(is.asyncIterable(0)); t.false(is.asyncIterable(0));
t.false(is.asyncIterable(NaN)); t.false(is.asyncIterable(NaN));
t.false(is.asyncIterable(Infinity)); t.false(is.asyncIterable(Infinity));
t.false(is.asyncIterable({})); t.false(is.asyncIterable({}));
}); });
}
test('is.class', t => { test('is.class', t => {
class Foo {} // eslint-disable-line @typescript-eslint/no-extraneous-class class Foo {} // eslint-disable-line @typescript-eslint/no-extraneous-class
@ -801,17 +780,11 @@ test('is.typedArray', t => {
new Int32Array(), new Int32Array(),
new Uint32Array(), new Uint32Array(),
new Float32Array(), new Float32Array(),
new Float64Array() new Float64Array(),
new BigInt64Array(),
new BigUint64Array()
]; ];
// TODO: Nodejs 10 only
// if (isNode10orHigher) {
// typedArrays.push(
// new BigInt64Array(),
// new BigUint64Array()
// );
// }
for (const item of typedArrays) { for (const item of typedArrays) {
t.true(is.typedArray(item)); t.true(is.typedArray(item));
} }

View file

@ -2,9 +2,9 @@
"extends": "@sindresorhus/tsconfig", "extends": "@sindresorhus/tsconfig",
"compilerOptions": { "compilerOptions": {
"outDir": "dist", "outDir": "dist",
"target": "es2017", "target": "es2018",
"lib": [ "lib": [
"esnext", "es2018",
"dom" "dom"
] ]
}, },