Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add is.propertyKey #138

Merged
merged 9 commits into from Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions source/index.ts
Expand Up @@ -150,6 +150,8 @@ is.string = isOfType<string>('string');
const isNumberType = isOfType<number>('number');
is.number = (value: unknown): value is number => isNumberType(value) && !is.nan(value);

is.propertyKey = (value: unknown): value is PropertyKey => is.any([is.string, is.number, is.symbol], value);
PopGoesTheWza marked this conversation as resolved.
Show resolved Hide resolved

is.bigint = isOfType<bigint>('bigint');

// eslint-disable-next-line @typescript-eslint/ban-types
Expand Down Expand Up @@ -448,6 +450,7 @@ interface Assert {
undefined: (value: unknown) => asserts value is undefined;
string: (value: unknown) => asserts value is string;
number: (value: unknown) => asserts value is number;
propertyKey: (value: unknown) => asserts value is PropertyKey;
bigint: (value: unknown) => asserts value is bigint;
// eslint-disable-next-line @typescript-eslint/ban-types
function_: (value: unknown) => asserts value is Function;
Expand Down Expand Up @@ -538,6 +541,8 @@ export const assert: Assert = {
undefined: (value: unknown): asserts value is undefined => assertType(is.undefined(value), 'undefined', value),
string: (value: unknown): asserts value is string => assertType(is.string(value), 'string', value),
number: (value: unknown): asserts value is number => assertType(is.number(value), 'number', value),
// ? Is an AssertionTypeDescription.propertyKey entry necessary?
PopGoesTheWza marked this conversation as resolved.
Show resolved Hide resolved
propertyKey: (value: unknown): asserts value is number => assertType(is.propertyKey(value), 'PropertyKey', value),
bigint: (value: unknown): asserts value is bigint => assertType(is.bigint(value), 'bigint', value),
// eslint-disable-next-line @typescript-eslint/ban-types
function_: (value: unknown): asserts value is Function => assertType(is.function_(value), 'Function', value),
Expand Down
7 changes: 7 additions & 0 deletions test/test.ts
Expand Up @@ -613,6 +613,13 @@ test('is.number', t => {
testType(t, 'number', ['integer', 'safeInteger', 'infinite']);
});

test('is.propertyKey', t => {
// ??? Unsure what is the correct syntax to `testType` multiple types. Also are the exclusion relevant?
PopGoesTheWza marked this conversation as resolved.
Show resolved Hide resolved
testType(t, 'string', ['emptyString', 'numericString']);
testType(t, 'number', ['nan', 'integer', 'safeInteger', 'infinite']);
testType(t, 'symbol');
});

test('is.bigint', t => {
testType(t, 'bigint');
});
Expand Down