Add is.numericString()

This commit is contained in:
Itai Steinherz 2018-10-24 23:56:35 +03:00
parent c983ffa4cd
commit b407e383f8
No known key found for this signature in database
GPG key ID: BE977733D203B00A
2 changed files with 12 additions and 1 deletions

View file

@ -135,10 +135,13 @@ namespace is { // tslint:disable-line:no-namespace
export const symbol = isOfType<Symbol>('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<any> => !nullOrUndefined(value) && function_(value[Symbol.iterator]);
export const asyncIterable = (value: any): value is AsyncIterableIterator<any> => !nullOrUndefined(value) && function_(value[Symbol.asyncIterator]);

View file

@ -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']);
});