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

fix(3699): Amend isNumeric typings and add unit test #4054

Merged
merged 1 commit into from Aug 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 18 additions & 0 deletions spec/util/IsNumeric-spec.ts
@@ -0,0 +1,18 @@
import {expect} from 'chai';
import { isNumeric } from 'rxjs/util/isNumeric';

/** @test {isNumeric} */
describe('isNumeric', () => {
it('should cover the following numeric scenario', () => {
expect(isNumeric(' ')).to.be.false;
expect(isNumeric('\n')).to.be.false;
expect(isNumeric('\t')).to.be.false;

expect(isNumeric('0')).to.be.true;
expect(isNumeric(0)).to.be.true;
expect(isNumeric(-1)).to.be.true;
expect(isNumeric(-1.5)).to.be.true;
expect(isNumeric(6e6)).to.be.true;
expect(isNumeric('6e6')).to.be.true;
});
});
2 changes: 1 addition & 1 deletion src/internal/util/isNumeric.ts
@@ -1,6 +1,6 @@
import { isArray } from './isArray';

export function isNumeric(val: any): val is number {
export function isNumeric(val: any): val is number | string {
// parseFloat NaNs numeric-cast false positives (null|true|false|"")
// ...but misinterprets leading-number strings, particularly hex literals ("0x...")
// subtraction forces infinities to NaN
Expand Down