Meta tweaks

This commit is contained in:
Sindre Sorhus 2023-05-30 21:13:40 +07:00
parent 888e145c5a
commit 65404fbd8e
3 changed files with 35 additions and 15 deletions

View file

@ -52,18 +52,18 @@
],
"devDependencies": {
"@sindresorhus/tsconfig": "^3.0.1",
"@types/jsdom": "^20.0.0",
"@types/node": "^18.11.0",
"@types/jsdom": "^21.1.1",
"@types/node": "^20.2.5",
"@types/zen-observable": "^0.8.3",
"ava": "^4.3.3",
"ava": "^5.3.0",
"del-cli": "^5.0.0",
"jsdom": "^20.0.1",
"rxjs": "^7.5.7",
"rxjs": "^7.8.1",
"tempy": "^3.0.0",
"ts-node": "^10.9.1",
"typescript": "~4.8.4",
"xo": "^0.52.4",
"zen-observable": "^0.8.15"
"typescript": "^5.0.4",
"xo": "^0.54.2",
"zen-observable": "^0.10.0"
},
"sideEffects": false,
"ava": {

View file

@ -105,20 +105,34 @@ function is(value: unknown): TypeName {
}
switch (typeof value) {
case 'undefined':
case 'undefined': {
return 'undefined';
case 'string':
}
case 'string': {
return 'string';
case 'number':
}
case 'number': {
return Number.isNaN(value) ? 'NaN' : 'number';
case 'boolean':
}
case 'boolean': {
return 'boolean';
case 'function':
}
case 'function': {
return 'Function';
case 'bigint':
}
case 'bigint': {
return 'bigint';
case 'symbol':
}
case 'symbol': {
return 'symbol';
}
default:
}
@ -179,6 +193,7 @@ is.array = <T = unknown>(value: unknown, assertion?: (value: T) => value is T):
return true;
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
return value.every(element => assertion(element));
};
@ -251,6 +266,7 @@ is.sharedArrayBuffer = isObjectOfType<SharedArrayBuffer>('SharedArrayBuffer');
is.dataView = isObjectOfType<DataView>('DataView');
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
is.enumCase = <T = unknown>(value: unknown, targetEnum: T): boolean => Object.values(targetEnum as any).includes(value as string);
is.directInstanceOf = <T>(instance: unknown, class_: Class<T>): instance is T => Object.getPrototypeOf(instance) === class_.prototype;

View file

@ -603,7 +603,7 @@ const testType = (t: ExecutionContext, type: string, exclude?: string[]) => {
for (const fixture of fixtures) {
assertIs(testIs(fixture), `Value: ${inspect(fixture)}`);
const valueType = typeDescription ? typeDescription : typename;
const valueType = typeDescription ?? typename;
if (isTypeUnderTest) {
t.notThrows(() => {
@ -1611,6 +1611,7 @@ test('is.any', t => {
t.false(is.any([is.boolean, is.number], 'unicorns', [], new Map()));
t.throws(() => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
is.any(null as any, true);
});
@ -1635,6 +1636,7 @@ test('is.any', t => {
});
t.throws(() => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
assert.any(null as any, true);
});
@ -1673,6 +1675,7 @@ test('is.all', t => {
t.true(is.all(is.array, ['1'], ['2']));
t.throws(() => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
is.all(null as any, true);
});
@ -1697,6 +1700,7 @@ test('is.all', t => {
});
t.throws(() => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
assert.all(null as any, true);
});