From 3d0bf3e7cd596e7c7ceeb67aca33c725d6ab30a7 Mon Sep 17 00:00:00 2001 From: Arfat Salman Date: Mon, 13 Apr 2020 21:57:57 +0530 Subject: [PATCH] Fix #109: is.numericString behaves correctly on whitespaces --- source/index.ts | 2 +- test/test.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/source/index.ts b/source/index.ts index cd8af29..9c6d8cf 100644 --- a/source/index.ts +++ b/source/index.ts @@ -130,7 +130,7 @@ is.boolean = (value: unknown): value is boolean => value === true || value === f is.symbol = isOfType('symbol'); is.numericString = (value: unknown): value is string => - is.string(value) && value.length > 0 && !Number.isNaN(Number(value)); + is.string(value) && !is.emptyStringOrWhitespace(value) && !Number.isNaN(Number(value)); is.array = Array.isArray; is.buffer = (value: unknown): value is Buffer => (value as any)?.constructor?.isBuffer?.(value) ?? false; diff --git a/test/test.ts b/test/test.ts index 6d6a4ce..f540828 100644 --- a/test/test.ts +++ b/test/test.ts @@ -124,7 +124,8 @@ const types = new Map([ fixtures: [ '5', '-3.2', - 'Infinity' + 'Infinity', + '0x56' ], typename: TypeName.string, typeDescription: AssertionTypeDescription.numericString @@ -627,6 +628,8 @@ test('is.symbol', t => { test('is.numericString', t => { testType(t, 'numericString'); t.false(is.numericString('')); + t.false(is.numericString(' ')); + t.false(is.numericString(' \t\t\n')); t.false(is.numericString(1)); t.throws(() => { assert.numericString('');