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

Discriminate better with numericString #178

Merged
merged 1 commit into from
May 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ is.boolean = (value: unknown): value is boolean => value === true || value === f

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

is.numericString = (value: unknown): value is string =>
is.numericString = (value: unknown): value is `${number}` =>
is.string(value) && !is.emptyStringOrWhitespace(value) && !Number.isNaN(Number(value));

is.array = <T = unknown>(value: unknown, assertion?: (value: T) => value is T): value is T[] => {
Expand Down Expand Up @@ -502,7 +502,7 @@ type Assert = {
class_: (value: unknown) => asserts value is Class;
boolean: (value: unknown) => asserts value is boolean;
symbol: (value: unknown) => asserts value is symbol;
numericString: (value: unknown) => asserts value is string;
numericString: (value: unknown) => asserts value is `${number}`;
array: <T = unknown>(value: unknown, assertion?: (element: unknown) => asserts element is T) => asserts value is T[];
buffer: (value: unknown) => asserts value is Buffer;
blob: (value: unknown) => asserts value is Blob;
Expand Down Expand Up @@ -600,7 +600,7 @@ export const assert: Assert = {
class_: (value: unknown): asserts value is Class => assertType(is.class_(value), AssertionTypeDescription.class_, value),
boolean: (value: unknown): asserts value is boolean => assertType(is.boolean(value), 'boolean', value),
symbol: (value: unknown): asserts value is symbol => assertType(is.symbol(value), 'symbol', value),
numericString: (value: unknown): asserts value is string => assertType(is.numericString(value), AssertionTypeDescription.numericString, value),
numericString: (value: unknown): asserts value is `${number}` => assertType(is.numericString(value), AssertionTypeDescription.numericString, value),
array: <T = unknown>(value: unknown, assertion?: (element: unknown) => asserts element is T): asserts value is T[] => { // eslint-disable-line object-shorthand
const assert: (condition: boolean, description: string, value: unknown) => asserts condition = assertType;
assert(is.array(value), 'Array', value);
Expand Down