diff --git a/source/index.ts b/source/index.ts index 3ae4dd1..47727a4 100644 --- a/source/index.ts +++ b/source/index.ts @@ -135,10 +135,13 @@ namespace is { // tslint:disable-line:no-namespace export const symbol = isOfType('symbol'); // tslint:enable:variable-name + export const nullOrUndefined = (value: any): value is null | undefined => null_(value) || undefined(value); + export const numericString = (value: any): value is String => + !Number.isNaN(Number(value)) && !nullOrUndefined(value); + export const array = Array.isArray; export const buffer = isBuffer; - export const nullOrUndefined = (value: any): value is null | undefined => null_(value) || undefined(value); export const object = (value: any): value is object => !nullOrUndefined(value) && (function_(value) || isObject(value)); export const iterable = (value: any): value is IterableIterator => !nullOrUndefined(value) && function_(value[Symbol.iterator]); export const asyncIterable = (value: any): value is AsyncIterableIterator => !nullOrUndefined(value) && function_(value[Symbol.asyncIterator]); diff --git a/source/tests/test.ts b/source/tests/test.ts index 66c3c9e..1199430 100644 --- a/source/tests/test.ts +++ b/source/tests/test.ts @@ -426,6 +426,14 @@ test('is.symbol', t => { testType(t, 'symbol'); }); +test('is.numericString', t => { + t.true(m.numericString('5')); + t.true(m.numericString('-3.2')); + t.true(m.numericString('Infinity')); + t.false(m.numericString(undefined)); + t.false(m.numericString(null)); +}); + test('is.array', t => { testType(t, 'array', ['emptyArray']); });